2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Scan in items fix (#4738)

* Clean up comments

* Bug fix

- Pass options.modal through if provided when creating new barcodeDialog

* Fix for scanning from item context into location
This commit is contained in:
Oliver 2023-05-01 23:50:20 +10:00 committed by GitHub
parent ad4acef459
commit be856c3682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 93 additions and 88 deletions

View File

@ -170,7 +170,7 @@ function postBarcodeData(barcode_data, options={}) {
if (options.onError400) { if (options.onError400) {
options.onError400(xhr.responseJSON, options); options.onError400(xhr.responseJSON, options);
} else { } else {
console.log(xhr); console.error(xhr);
data = xhr.responseJSON || {}; data = xhr.responseJSON || {};
showBarcodeMessage(modal, data.error || '{% trans "Server error" %}'); showBarcodeMessage(modal, data.error || '{% trans "Server error" %}');
} }
@ -279,7 +279,7 @@ function getBarcodeData(modal) {
*/ */
function barcodeDialog(title, options={}) { function barcodeDialog(title, options={}) {
var modal = createNewModal(); var modal = options.modal || createNewModal();
options.modal = modal; options.modal = modal;
@ -571,7 +571,7 @@ function barcodeCheckInStockItems(location_id, options={}) {
}); });
} }
var table = `<div class='container' id='items-table-div' style='width: 80%; float: left;'></div>`; var table = `<div class='container' id='items-table-div' style='float: left;'></div>`;
// Extra form fields // Extra form fields
var extra = makeNotesField(); var extra = makeNotesField();
@ -589,6 +589,7 @@ function barcodeCheckInStockItems(location_id, options={}) {
onShow: function() { onShow: function() {
}, },
extraFields: extra, extraFields: extra,
modal: modal,
onSubmit: function() { onSubmit: function() {
// Called when the 'check-in' button is pressed // Called when the 'check-in' button is pressed
@ -776,6 +777,7 @@ function scanItemsIntoLocation(item_list, options={}) {
{ {
headerContent: header, headerContent: header,
extraFields: extra, extraFields: extra,
modal: modal,
preShow: function() { preShow: function() {
modalSetSubmitText(modal, '{% trans "Check In" %}'); modalSetSubmitText(modal, '{% trans "Check In" %}');
modalEnable(modal, false); modalEnable(modal, false);

View File

@ -187,7 +187,6 @@ function makeOption(text, value, title) {
return html; return html;
} }
function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
/* /*
* Programatically generate a list of <option> elements, * Programatically generate a list of <option> elements,
* from the (assumed array) of elements. * from the (assumed array) of elements.
@ -200,6 +199,7 @@ function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
* - valueFunc: optional function which takes an element and generates the value * - valueFunc: optional function which takes an element and generates the value
* - titleFunc: optional function which takes an element and generates a title * - titleFunc: optional function which takes an element and generates a title
*/ */
function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
var options = []; var options = [];
@ -226,7 +226,6 @@ function makeOptionsList(elements, textFunc, valueFunc, titleFunc) {
} }
function setFieldOptions(fieldName, optionList, options={}) {
/* Set the options for a <select> field. /* Set the options for a <select> field.
* *
* Args: * Args:
@ -234,7 +233,7 @@ function setFieldOptions(fieldName, optionList, options={}) {
* - Options: List of formatted <option> strings * - Options: List of formatted <option> strings
* - append: If true, options will be appended, otherwise will replace existing options. * - append: If true, options will be appended, otherwise will replace existing options.
*/ */
function setFieldOptions(fieldName, optionList, options={}) {
var append = options.append || false; var append = options.append || false;
@ -261,16 +260,15 @@ function setFieldOptions(fieldName, optionList, options={}) {
} }
function clearFieldOptions(fieldName) {
/** /**
* Clear (emtpy) the options list for a particular field * Clear (emtpy) the options list for a particular field
*/ */
function clearFieldOptions(fieldName) {
setFieldOptions(fieldName, []); setFieldOptions(fieldName, []);
} }
function reloadFieldOptions(fieldName, options) {
/* Reload the options for a given field, /* Reload the options for a given field,
* using an AJAX request. * using an AJAX request.
* *
@ -283,6 +281,7 @@ function reloadFieldOptions(fieldName, options) {
* -- text: A function which takes a returned option and returns the 'text' * -- text: A function which takes a returned option and returns the 'text'
* -- title: A function which takes a returned option and returns the 'title' (optional!) * -- title: A function which takes a returned option and returns the 'title' (optional!)
*/ */
function reloadFieldOptions(fieldName, options) {
inventreeGet(options.url, options.params, { inventreeGet(options.url, options.params, {
success: function(response) { success: function(response) {
@ -317,7 +316,6 @@ function reloadFieldOptions(fieldName, options) {
} }
function enableField(fieldName, enabled, options={}) {
/* Enable (or disable) a particular field in a modal. /* Enable (or disable) a particular field in a modal.
* *
* Args: * Args:
@ -325,6 +323,7 @@ function enableField(fieldName, enabled, options={}) {
* - enabled: boolean enabled / disabled status * - enabled: boolean enabled / disabled status
* - options: * - options:
*/ */
function enableField(fieldName, enabled, options={}) {
var modal = options.modal || '#modal-form'; var modal = options.modal || '#modal-form';
@ -357,7 +356,6 @@ function getFieldValue(fieldName, options={}) {
} }
function partialMatcher(params, data) {
/* Replacement function for the 'matcher' parameter for a select2 dropdown. /* Replacement function for the 'matcher' parameter for a select2 dropdown.
Intead of performing an exact match search, a partial match search is performed. Intead of performing an exact match search, a partial match search is performed.
@ -368,6 +366,7 @@ function partialMatcher(params, data) {
params.term : search query params.term : search query
data.text : text to match data.text : text to match
*/ */
function partialMatcher(params, data) {
// Quickly check for an empty search query // Quickly check for an empty search query
if ($.trim(params.term) == '') { if ($.trim(params.term) == '') {
@ -395,10 +394,10 @@ function partialMatcher(params, data) {
} }
function attachSelect(modal) {
/* Attach 'select2' functionality to any drop-down list in the modal. /* Attach 'select2' functionality to any drop-down list in the modal.
* Provides search filtering for dropdown items * Provides search filtering for dropdown items
*/ */
function attachSelect(modal) {
$(modal + ' .select').select2({ $(modal + ' .select').select2({
dropdownParent: $(modal), dropdownParent: $(modal),
@ -412,25 +411,24 @@ function attachSelect(modal) {
} }
function attachBootstrapCheckbox(modal) {
/* Attach 'switch' functionality to any checkboxes on the form */ /* Attach 'switch' functionality to any checkboxes on the form */
function attachBootstrapCheckbox(modal) {
$(modal + ' .checkboxinput').addClass('form-check-input'); $(modal + ' .checkboxinput').addClass('form-check-input');
$(modal + ' .checkboxinput').wrap(`<div class='form-check form-switch'></div>`); $(modal + ' .checkboxinput').wrap(`<div class='form-check form-switch'></div>`);
} }
function loadingMessageContent() {
/* Render a 'loading' message to display in a form /* Render a 'loading' message to display in a form
* when waiting for a response from the server * when waiting for a response from the server
*/ */
function loadingMessageContent() {
// TODO - This can be made a lot better // TODO - This can be made a lot better
return `<span class='glyphicon glyphicon-refresh glyphicon-refresh-animate'></span> {% trans 'Waiting for server...' %}`; return `<span class='glyphicon glyphicon-refresh glyphicon-refresh-animate'></span> {% trans 'Waiting for server...' %}`;
} }
function afterForm(response, options) {
/* afterForm is called after a form is successfully submitted, /* afterForm is called after a form is successfully submitted,
* and the form is dismissed. * and the form is dismissed.
* Used for general purpose functionality after form submission: * Used for general purpose functionality after form submission:
@ -440,6 +438,7 @@ function afterForm(response, options) {
* - Redirect the browser to a different URL * - Redirect the browser to a different URL
* - Reload the page * - Reload the page
*/ */
function afterForm(response, options) {
// Should we show alerts immediately or cache them? // Should we show alerts immediately or cache them?
var cache = (options.follow && response.url) || var cache = (options.follow && response.url) ||
@ -475,9 +474,9 @@ function afterForm(response, options) {
} }
} }
function modalShowSubmitButton(modal, show=true) {
/* Show (or hide) the 'Submit' button for the given modal form /* Show (or hide) the 'Submit' button for the given modal form
*/ */
function modalShowSubmitButton(modal, show=true) {
if (show) { if (show) {
$(modal).find('#modal-form-submit').show(); $(modal).find('#modal-form-submit').show();
@ -487,29 +486,31 @@ function modalShowSubmitButton(modal, show=true) {
} }
function modalEnable(modal, enable=true) {
/* Enable (or disable) modal form elements to prevent user input /* Enable (or disable) modal form elements to prevent user input
*/ */
function modalEnable(modal, enable=true) {
// Enable or disable the submit button // Enable or disable the submit button
$(modal).find('#modal-form-submit').prop('disabled', !enable); $(modal).find('#modal-form-submit').prop('disabled', !enable);
} }
function modalSetTitle(modal, title='') {
/* Update the title of a modal form /* Update the title of a modal form
*/ */
function modalSetTitle(modal, title='') {
$(modal + ' #modal-title').html(title); $(modal + ' #modal-title').html(title);
} }
function modalSetContent(modal, content='') {
/* Update the content panel of a modal form /* Update the content panel of a modal form
*/ */
function modalSetContent(modal, content='') {
$(modal).find('.modal-form-content').html(content); $(modal).find('.modal-form-content').html(content);
} }
/* Set the text of the "submit" button of a modal form
*/
function modalSetSubmitText(modal, text) { function modalSetSubmitText(modal, text) {
if (text) { if (text) {
$(modal).find('#modal-form-submit').html(text); $(modal).find('#modal-form-submit').html(text);
@ -517,6 +518,8 @@ function modalSetSubmitText(modal, text) {
} }
/* Set the text of the "close" button of a modal form
*/
function modalSetCloseText(modal, text) { function modalSetCloseText(modal, text) {
if (text) { if (text) {
$(modal).find('#modal-form-close').html(text); $(modal).find('#modal-form-close').html(text);
@ -524,27 +527,27 @@ function modalSetCloseText(modal, text) {
} }
function modalSetButtonText(modal, submit_text, close_text) {
/* Set the button text for a modal form /* Set the button text for a modal form
* *
* submit_text - text for the form submit button * submit_text - text for the form submit button
* close_text - text for the form dismiss button * close_text - text for the form dismiss button
*/ */
function modalSetButtonText(modal, submit_text, close_text) {
modalSetSubmitText(modal, submit_text); modalSetSubmitText(modal, submit_text);
modalSetCloseText(modal, close_text); modalSetCloseText(modal, close_text);
} }
function closeModal(modal='#modal-form') {
/* Dismiss (hide) a modal form /* Dismiss (hide) a modal form
*/ */
function closeModal(modal='#modal-form') {
$(modal).modal('hide'); $(modal).modal('hide');
} }
function modalSubmit(modal, callback) {
/* Perform the submission action for the modal form /* Perform the submission action for the modal form
*/ */
function modalSubmit(modal, callback) {
$(modal).off('click', '#modal-form-submit'); $(modal).off('click', '#modal-form-submit');
$(modal).on('click', '#modal-form-submit', function() { $(modal).on('click', '#modal-form-submit', function() {