Updates to build forms / etc

This commit is contained in:
Oliver Walters 2020-10-20 22:37:21 +11:00
parent 2df0f03a9a
commit 2e4613e702
4 changed files with 63 additions and 14 deletions

View File

@ -134,6 +134,32 @@ function reloadFieldOptions(fieldName, options) {
}
function enableField(fieldName, enabled, options={}) {
/* Enable (or disable) a particular field in a modal.
*
* Args:
* - fieldName: The name of the field
* - enabled: boolean enabled / disabled status
* - options:
*/
var modal = options.modal || '#modal-form';
var field = getFieldByName(modal, fieldName);
field.prop("disabled", !enabled);
}
function clearField(fieldName, options={}) {
var modal = options.modal || '#modal-form';
var field = getFieldByName(modal, fieldName);
field.val("");
}
function partialMatcher(params, data) {
/* Replacement function for the 'matcher' parameter for a select2 dropdown.

View File

@ -40,12 +40,7 @@ InvenTree | {% trans "Build Orders" %}
$("#collapse-item-active").collapse().show();
$("#new-build").click(function() {
launchModalForm(
"{% url 'build-create' %}",
{
follow: true,
}
);
newBuildOrder();
});
loadBuildTable($("#build-table"), {

View File

@ -29,12 +29,9 @@
{% block js_ready %}
{{ block.super }}
$("#start-build").click(function() {
launchModalForm(
"{% url 'build-create' %}",
{
follow: true,
newBuildOrder({
data: {
part: {{ part.id }}
part: {{ part.id }},
}
});
});

View File

@ -1,6 +1,37 @@
{% load i18n %}
{% load inventree_extras %}
function newBuildOrder(options={}) {
/* Launch modal form to create a new BuildOrder.
*/
launchModalForm(
"{% url 'build-create' %}",
{
follow: true,
data: options.data || {},
callback: [
{
field: 'part',
action: function(value) {
inventreeGet(
`/api/part/${value}/`, {},
{
success: function(response) {
//enableField('serial_numbers', response.trackable);
//clearField('serial_numbers');
}
}
);
},
}
],
}
)
}
function loadBuildTable(table, options) {
// Display a table of Build objects