mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Generecised launchModalForm
- Add 'options' e.g. redirect / data
This commit is contained in:
parent
784b0dec02
commit
507e3de05b
@ -50,15 +50,15 @@
|
|||||||
$("#create-cat").click(function() {
|
$("#create-cat").click(function() {
|
||||||
launchModalForm("#modal-form",
|
launchModalForm("#modal-form",
|
||||||
"{% url 'category-create' %}",
|
"{% url 'category-create' %}",
|
||||||
{category: {{ category.id }}
|
{data: {category: {{ category.id }}
|
||||||
});
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#create-part").click( function() {
|
$("#create-part").click( function() {
|
||||||
launchModalForm("#modal-form",
|
launchModalForm("#modal-form",
|
||||||
"{% url 'part-create' %}",
|
"{% url 'part-create' %}",
|
||||||
{category: {{ category.id }}
|
{data: {category: {{ category.id }}
|
||||||
});
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,18 +62,17 @@ function launchDeleteForm(modal, url, options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function launchModalForm(modal, url, data, options) {
|
function launchModalForm(modal, url, options) {
|
||||||
|
|
||||||
$(modal).on('shown.bs.modal', function () {
|
$(modal).on('shown.bs.modal', function () {
|
||||||
$(modal + ' .modal-form-content').scrollTop(0);
|
$(modal + ' .modal-form-content').scrollTop(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
$.ajax({
|
ajax_data = {
|
||||||
url: url, // Where to request the data from
|
url: url,
|
||||||
type: 'get', // GET request
|
type: 'get',
|
||||||
data: data, // Any additional context data (e.g. initial values)
|
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
beforeSend: function() {
|
beforeSend: function () {
|
||||||
$(modal).modal('show');
|
$(modal).modal('show');
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
@ -98,7 +97,15 @@ function launchModalForm(modal, url, data, options) {
|
|||||||
alert('Error requesting form data:\n' + thrownError);
|
alert('Error requesting form data:\n' + thrownError);
|
||||||
$(modal).modal('hide');
|
$(modal).modal('hide');
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Add in extra request data if provided
|
||||||
|
if (options.data) {
|
||||||
|
ajax_data.data = options.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the AJAX request
|
||||||
|
$.ajax(ajax_data);
|
||||||
|
|
||||||
$(modal).on('click', '#modal-form-submit', function() {
|
$(modal).on('click', '#modal-form-submit', function() {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user