Toot toot all aboard the refactor tractor

- launchModalForm now accepts a 'secondary' parameter which is a list of secondary modals to attach
This commit is contained in:
Oliver Walters 2019-05-14 23:27:45 +10:00
parent 97c4e5acbf
commit 9d50f2a6ac
3 changed files with 46 additions and 39 deletions

View File

@ -90,25 +90,20 @@
category: {{ category.id }}
{% endif %}
},
after_render: function(modal, response) {
attachSecondaryModal(modal,
{
field: 'category',
label: 'New Category',
title: 'Create new Part Category',
url: "{% url 'category-create' %}",
}
);
attachSecondaryModal(modal,
{
field: 'default_location',
label: 'New Location',
title: 'Create new Stock Location',
url: "{% url 'stock-location-create' %}",
}
);
}
secondary: [
{
field: 'category',
label: 'New Category',
title: 'Create new Part Category',
url: "{% url 'category-create' %}",
},
{
field: 'default_location',
label: 'New Location',
title: 'Create new Stock Location',
url: "{% url 'stock-location-create' %}",
}
]
}
);
});

View File

@ -420,6 +420,15 @@ function attachSecondaryModal(modal, options) {
}
function attachSecondaries(modal, secondaries) {
/* Attach a provided list of secondary modals */
for (var i = 0; i < secondaries.length; i++) {
attachSecondaryModal(modal, secondaries[i]);
}
}
function handleModalForm(url, options) {
/* Update a modal form after data are received from the server.
* Manages POST requests until the form is successfully submitted.
@ -471,6 +480,10 @@ function handleModalForm(url, options) {
if (options.after_render) {
options.after_render(modal, response);
}
if (options.secondary) {
attachSecondaries(modal, options.secondary);
}
}
else {
$(modal).modal('hide');
@ -514,6 +527,7 @@ function launchModalForm(url, options = {}) {
* close_text - Text for the close button (default = 'Close')
* no_post - If true, only display form data, hide submit button, and disallow POST
* after_render - Callback function to run after form is rendered
* secondary - List of secondary modals to attach
*/
var modal = options.modal || '#modal-form';
@ -550,6 +564,10 @@ function launchModalForm(url, options = {}) {
options.after_render(modal, response);
}
if (options.secondary) {
attachSecondaries(modal, options.secondary);
}
if (options.no_post) {
modalShowSubmitButton(modal, false);
} else {

View File

@ -124,26 +124,20 @@
location: {{ location.id }}
{% endif %}
},
after_render: function(modal, response) {
attachSecondaryModal(modal,
{
field: 'part',
label: 'New Part',
title: 'Create New Part',
url: "{% url 'part-create' %}",
}
);
attachSecondaryModal(modal,
{
field: 'location',
label: 'New Location',
title: 'Create New Location',
url: "{% url 'stock-location-create' %}",
}
);
}
secondary: [
{
field: 'part',
label: 'New Part',
title: 'Create New Part',
url: "{% url 'part-create' %}",
},
{
field: 'location',
label: 'New Location',
title: 'Create New Location',
url: "{% url 'stock-location-create' %}",
}
]
});