mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-26 19:07:40 +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:
		| @@ -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); | ||||||
|   | |||||||
| @@ -187,8 +187,7 @@ 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. | ||||||
|  * For each element, we pass the element to the supplied functions, |  * For each element, we pass the element to the supplied functions, | ||||||
| @@ -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,15 +226,14 @@ 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: | ||||||
|  * - fieldName: The name of the target field |  * - fieldName: The name of the target field | ||||||
|  * - 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,17 +260,16 @@ 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. | ||||||
|  * |  * | ||||||
|  * Args: |  * Args: | ||||||
| @@ -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,14 +316,14 @@ 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: | ||||||
|  * - fieldName: The name of the field |  * - fieldName: The name of the field | ||||||
|  * - 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,17 +356,17 @@ 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. | ||||||
|     This splits the search term by the space ' ' character and matches each segment. | This splits the search term by the space ' ' character and matches each segment. | ||||||
|     Segments can appear out of order and are not case sensitive | Segments can appear out of order and are not case sensitive | ||||||
|  |  | ||||||
|     Args: | Args: | ||||||
|     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,26 +411,25 @@ function attachSelect(modal) { | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /* Attach 'switch' functionality to any checkboxes on the form */ | ||||||
| function attachBootstrapCheckbox(modal) { | function attachBootstrapCheckbox(modal) { | ||||||
|     /* Attach 'switch' functionality to any checkboxes on the form */ |  | ||||||
|  |  | ||||||
|     $(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() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user