mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Starting work on "secondary modal" functionality
This commit is contained in:
parent
291149d733
commit
2e3bfd18cc
@ -881,16 +881,51 @@ function initializeRelatedFields(fields, options) {
|
|||||||
*/
|
*/
|
||||||
function addSecondaryModal(name, field, options) {
|
function addSecondaryModal(name, field, options) {
|
||||||
|
|
||||||
|
var secondary = field.secondary;
|
||||||
|
|
||||||
var html = `
|
var html = `
|
||||||
<span style='float: right;'>
|
<span style='float: right;'>
|
||||||
<div type='button' class='btn btn-primary btn-secondary' title='${field.secondary.title || field.secondary.label}' id='btn-new-${name}'>
|
<div type='button' class='btn btn-primary btn-secondary' title='${secondary.title || secondary.label}' id='btn-new-${name}'>
|
||||||
${field.secondary.label}
|
${secondary.label || secondary.title}
|
||||||
</div>
|
</div>
|
||||||
</span>`;
|
</span>`;
|
||||||
|
|
||||||
$(options.modal).find(`label[for="id_${name}"]`).append(html);
|
$(options.modal).find(`label[for="id_${name}"]`).append(html);
|
||||||
|
|
||||||
// TODO: Launch a callback
|
// TODO: Launch a callback
|
||||||
|
$(options.modal).find(`#btn-new-${name}`).click(function() {
|
||||||
|
|
||||||
|
if (secondary.callback) {
|
||||||
|
// A "custom" callback can be specified for the button
|
||||||
|
secondary.callback(field, options);
|
||||||
|
} else if (secondary.api_url) {
|
||||||
|
// By default, a new modal form is created, with the parameters specified
|
||||||
|
// The parameters match the "normal" form creation parameters
|
||||||
|
|
||||||
|
secondary.onSuccess = function(data, opts) {
|
||||||
|
|
||||||
|
// Add a new "option" to the existing field
|
||||||
|
// TODO: Refactor this
|
||||||
|
|
||||||
|
var select = $(options.modal).find(`#id_${name}`);
|
||||||
|
|
||||||
|
var option = new Option(name, data.pk, true, true);
|
||||||
|
|
||||||
|
option.instance = data;
|
||||||
|
|
||||||
|
select.append(option).trigger('change');
|
||||||
|
|
||||||
|
select.trigger({
|
||||||
|
type: 'select2:select',
|
||||||
|
params: {
|
||||||
|
data: data,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
constructForm(secondary.api_url, secondary);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user