Modal fixes

This commit is contained in:
Oliver Walters 2022-05-03 14:00:43 +10:00
parent 8cd8581dbf
commit 141b764b94
4 changed files with 26 additions and 20 deletions

View File

@ -246,7 +246,7 @@ class PurchaseOrderLineItemSerializer(InvenTreeModelSerializer):
total_price = serializers.FloatField(read_only=True)
part_detail = PartBriefSerializer(source='get_base_part', many=False, read_only=True)
supplier_part_detail = SupplierPartSerializer(source='part', many=False, read_only=True)
purchase_price = InvenTreeMoneySerializer(

View File

@ -129,7 +129,7 @@ function constructBomUploadTable(data, options={}) {
var modal = createNewModal({
title: '{% trans "Row Data" %}',
cancelText: '{% trans "Close" %}',
closeText: '{% trans "Close" %}',
hideSubmitButton: true
});
@ -617,7 +617,7 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
},
},
preFormContent: html,
cancelText: '{% trans "Close" %}',
closeText: '{% trans "Close" %}',
submitText: '{% trans "Add Substitute" %}',
title: '{% trans "Edit BOM Item Substitutes" %}',
afterRender: function(fields, opts) {

View File

@ -85,12 +85,25 @@ function createNewModal(options={}) {
var modal_name = `#modal-form-${id}`;
// Callback *after* the modal has been rendered
$(modal_name).on('shown.bs.modal', function() {
$(modal_name + ' .modal-form-content').scrollTop(0);
if (options.focus) {
getFieldByName(modal_name, options.focus).focus();
}
// Steal keyboard focus
$(modal_name).focus();
if (options.hideCloseButton) {
$(modal_name).find('#modal-form-cancel').hide();
}
if (options.preventSubmit || options.hideSubmitButton) {
$(modal_name).find('#modal-form-submit').hide();
}
});
// Automatically remove the modal when it is deleted!
@ -102,8 +115,11 @@ function createNewModal(options={}) {
$(modal_name).on('keydown', 'input', function(event) {
if (event.keyCode == 13) {
event.preventDefault();
// Simulate a click on the 'Submit' button
$(modal_name).find('#modal-form-submit').click();
if (!options.preventSubmit) {
// Simulate a click on the 'Submit' button
$(modal_name).find('#modal-form-submit').click();
}
return false;
}
@ -117,18 +133,7 @@ function createNewModal(options={}) {
// Set labels based on supplied options
modalSetTitle(modal_name, options.title || '{% trans "Form Title" %}');
modalSetSubmitText(modal_name, options.submitText || '{% trans "Submit" %}');
modalSetCloseText(modal_name, options.cancelText || '{% trans "Cancel" %}');
if (options.hideSubmitButton) {
$(modal_name).find('#modal-form-submit').hide();
}
if (options.hideCloseButton) {
$(modal_name).find('#modal-form-cancel').hide();
}
// Steal keyboard focus
$(modal_name).focus();
modalSetCloseText(modal_name, options.closeText || '{% trans "Cancel" %}');
// Return the "name" of the modal
return modal_name;
@ -581,7 +586,7 @@ function showAlertDialog(title, content, options={}) {
var modal = createNewModal({
title: title,
cancelText: '{% trans "Close" %}',
closeText: '{% trans "Close" %}',
hideSubmitButton: true,
});
@ -607,7 +612,7 @@ function showQuestionDialog(title, content, options={}) {
var modal = createNewModal({
title: title,
submitText: options.accept_text || '{% trans "Accept" %}',
cancelText: options.cancel_text || '{% trans "Cancel" %}',
closeText: options.cancel_text || '{% trans "Cancel" %}',
});
modalSetContent(modal, content);

View File

@ -625,7 +625,8 @@ function orderParts(parts_list, options={}) {
constructFormBody({}, {
preFormContent: html,
title: '{% trans "Order Parts" %}',
hideSubmitButton: true,
preventSubmit: true,
closeText: '{% trans "Close" %}',
afterRender: function(fields, opts) {
// TODO
parts.forEach(function(part) {