mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Handle form submissions
This commit is contained in:
parent
e3f85414fa
commit
0c41cc7c77
@ -715,6 +715,10 @@ function getFormFieldValue(name, field, options) {
|
|||||||
// Find the HTML element
|
// Find the HTML element
|
||||||
var el = $(options.modal).find(`#id_${name}`);
|
var el = $(options.modal).find(`#id_${name}`);
|
||||||
|
|
||||||
|
if (!el) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var value = null;
|
var value = null;
|
||||||
|
|
||||||
switch (field.type) {
|
switch (field.type) {
|
||||||
|
@ -28,6 +28,9 @@ function adjustStock(items, options={}) {
|
|||||||
var formTitle = 'Form Title Here';
|
var formTitle = 'Form Title Here';
|
||||||
var actionTitle = null;
|
var actionTitle = null;
|
||||||
|
|
||||||
|
// API url
|
||||||
|
var url = null;
|
||||||
|
|
||||||
var specifyLocation = false;
|
var specifyLocation = false;
|
||||||
var allowSerializedStock = false;
|
var allowSerializedStock = false;
|
||||||
|
|
||||||
@ -37,18 +40,22 @@ function adjustStock(items, options={}) {
|
|||||||
actionTitle = '{% trans "Move" %}';
|
actionTitle = '{% trans "Move" %}';
|
||||||
specifyLocation = true;
|
specifyLocation = true;
|
||||||
allowSerializedStock = true;
|
allowSerializedStock = true;
|
||||||
|
url = '{% url "api-stock-transfer" %}';
|
||||||
break;
|
break;
|
||||||
case 'count':
|
case 'count':
|
||||||
formTitle = '{% trans "Count Stock" %}';
|
formTitle = '{% trans "Count Stock" %}';
|
||||||
actionTitle = '{% trans "Count" %}';
|
actionTitle = '{% trans "Count" %}';
|
||||||
|
url = '{% url "api-stock-count" %}';
|
||||||
break;
|
break;
|
||||||
case 'take':
|
case 'take':
|
||||||
formTitle = '{% trans "Remove Stock" %}';
|
formTitle = '{% trans "Remove Stock" %}';
|
||||||
actionTitle = '{% trans "Take" %}';
|
actionTitle = '{% trans "Take" %}';
|
||||||
|
url = '{% url "api-stock-remove" %}';
|
||||||
break;
|
break;
|
||||||
case 'add':
|
case 'add':
|
||||||
formTitle = '{% trans "Add Stock" %}';
|
formTitle = '{% trans "Add Stock" %}';
|
||||||
actionTitle = '{% trans "Add" %}';
|
actionTitle = '{% trans "Add" %}';
|
||||||
|
url = '{% url "api-stock-add" %}';
|
||||||
break;
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
formTitle = '{% trans "Delete Stock" %}';
|
formTitle = '{% trans "Delete Stock" %}';
|
||||||
@ -156,7 +163,7 @@ function adjustStock(items, options={}) {
|
|||||||
buttons += `</div>`;
|
buttons += `</div>`;
|
||||||
|
|
||||||
html += `
|
html += `
|
||||||
<tr id='stock_item_${pk}'>
|
<tr id='stock_item_${pk}' class='stock-item-row'>
|
||||||
<td id='part_${pk}'><img src='${image}' class='hover-img-thumb'> ${item.part_detail.full_name}</td>
|
<td id='part_${pk}'><img src='${image}' class='hover-img-thumb'> ${item.part_detail.full_name}</td>
|
||||||
<td id='stock_${pk}'>${quantity}${status}</td>
|
<td id='stock_${pk}'>${quantity}${status}</td>
|
||||||
<td id='location_${pk}'>${location}</td>
|
<td id='location_${pk}'>${location}</td>
|
||||||
@ -192,7 +199,7 @@ function adjustStock(items, options={}) {
|
|||||||
api_url: `/api/stock/location/`,
|
api_url: `/api/stock/location/`,
|
||||||
model: 'stocklocation',
|
model: 'stocklocation',
|
||||||
},
|
},
|
||||||
note: {
|
notes: {
|
||||||
label: '{% trans "Notes" %}',
|
label: '{% trans "Notes" %}',
|
||||||
help_text: '{% trans "Stock transaction notes" %}',
|
help_text: '{% trans "Stock transaction notes" %}',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
@ -209,8 +216,48 @@ function adjustStock(items, options={}) {
|
|||||||
confirm: true,
|
confirm: true,
|
||||||
confirmMessage: '{% trans "Confirm stock adjustment" %}',
|
confirmMessage: '{% trans "Confirm stock adjustment" %}',
|
||||||
modal: modal,
|
modal: modal,
|
||||||
onSubmit: function(fields, options) {
|
onSubmit: function(fields, opts) {
|
||||||
console.log("submit!");
|
|
||||||
|
// Data to transmit
|
||||||
|
var data = {
|
||||||
|
items: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add values for each selected stock item
|
||||||
|
items.forEach(function(item) {
|
||||||
|
|
||||||
|
var q = getFormFieldValue(item.pk, {}, {modal: modal});
|
||||||
|
|
||||||
|
data.items.push({pk: item.pk, quantity: q})
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add in extra field data
|
||||||
|
for (field_name in extraFields) {
|
||||||
|
data[field_name] = getFormFieldValue(
|
||||||
|
field_name,
|
||||||
|
fields[field_name],
|
||||||
|
{
|
||||||
|
modal: modal,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
inventreePut(
|
||||||
|
url,
|
||||||
|
data,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
success: function(response, status) {
|
||||||
|
|
||||||
|
// Destroy the modal window
|
||||||
|
$(modal).modal('hide');
|
||||||
|
|
||||||
|
if (options.onSuccess) {
|
||||||
|
options.onSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -957,6 +1004,9 @@ function loadStockTable(table, options) {
|
|||||||
|
|
||||||
adjustStock(items, {
|
adjustStock(items, {
|
||||||
action: action,
|
action: action,
|
||||||
|
onSuccess: function() {
|
||||||
|
$('#stock-table').bootstrapTable('refresh');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user