mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
adding in cstm action buttons function
This commit is contained in:
parent
09fe9ccf11
commit
f73863ea51
@ -377,6 +377,15 @@ function modalSubmit(modal, callback) {
|
|||||||
$(modal).on('click', '#modal-form-submit', function() {
|
$(modal).on('click', '#modal-form-submit', function() {
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(modal).on('click', '.modal-form-button', function() {
|
||||||
|
// Append data to form
|
||||||
|
var name = $(this).attr('name');
|
||||||
|
var value = $(this).attr('value');
|
||||||
|
var input = '<input id="id_act-btn_' + name + '" type="hidden" name="act-btn_' + name + '" value="' + value + '">';
|
||||||
|
$('.js-modal-form').append(input);
|
||||||
|
callback();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -659,6 +668,25 @@ function attachSecondaries(modal, secondaries) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insertActionButton(modal, options) {
|
||||||
|
/* Insert a custom submition button */
|
||||||
|
|
||||||
|
var html = "<span style='float: right;'>";
|
||||||
|
html += "<button name='" + options.name + "' type='submit' class='btn btn-default modal-form-button'";
|
||||||
|
html += " value='" + options.name + "'>" + options.title + "</button>";
|
||||||
|
html += "</span>";
|
||||||
|
|
||||||
|
$(modal).find('#modal-footer-buttons').append(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachButtons(modal, buttons) {
|
||||||
|
/* Attach a provided list of buttons */
|
||||||
|
|
||||||
|
for (var i = 0; i < buttons.length; i++) {
|
||||||
|
insertActionButton(modal, buttons[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function attachFieldCallback(modal, callback) {
|
function attachFieldCallback(modal, callback) {
|
||||||
/* Attach a 'callback' function to a given field in the modal form.
|
/* Attach a 'callback' function to a given field in the modal form.
|
||||||
@ -808,6 +836,9 @@ function launchModalForm(url, options = {}) {
|
|||||||
var submit_text = options.submit_text || '{% trans "Submit" %}';
|
var submit_text = options.submit_text || '{% trans "Submit" %}';
|
||||||
var close_text = options.close_text || '{% trans "Close" %}';
|
var close_text = options.close_text || '{% trans "Close" %}';
|
||||||
|
|
||||||
|
// Clean custom action buttons
|
||||||
|
$(modal).find('#modal-footer-buttons').html('');
|
||||||
|
|
||||||
// Form the ajax request to retrieve the django form data
|
// Form the ajax request to retrieve the django form data
|
||||||
ajax_data = {
|
ajax_data = {
|
||||||
url: url,
|
url: url,
|
||||||
@ -852,6 +883,10 @@ function launchModalForm(url, options = {}) {
|
|||||||
handleModalForm(url, options);
|
handleModalForm(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.buttons) {
|
||||||
|
attachButtons(modal, options.buttons);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$(modal).modal('hide');
|
$(modal).modal('hide');
|
||||||
showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}');
|
showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}');
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='modal-footer'>
|
<div class='modal-footer'>
|
||||||
|
<div id='modal-footer-buttons'></div>
|
||||||
<button type='button' class='btn btn-default' id='modal-form-close' data-dismiss='modal'>{% trans "Close" %}</button>
|
<button type='button' class='btn btn-default' id='modal-form-close' data-dismiss='modal'>{% trans "Close" %}</button>
|
||||||
<button type='button' class='btn btn-primary' id='modal-form-submit'>{% trans "Submit" %}</button>
|
<button type='button' class='btn btn-primary' id='modal-form-submit'>{% trans "Submit" %}</button>
|
||||||
</div>
|
</div>
|
||||||
@ -49,6 +50,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='modal-footer'>
|
<div class='modal-footer'>
|
||||||
|
<div id='modal-footer-buttons'></div>
|
||||||
<button type='button' class='btn btn-default' id='modal-form-close' data-dismiss='modal'>{% trans "Close" %}</button>
|
<button type='button' class='btn btn-default' id='modal-form-close' data-dismiss='modal'>{% trans "Close" %}</button>
|
||||||
<button type='button' class='btn btn-primary' id='modal-form-submit'>{% trans "Submit" %}</button>
|
<button type='button' class='btn btn-primary' id='modal-form-submit'>{% trans "Submit" %}</button>
|
||||||
</div>
|
</div>
|
||||||
@ -69,6 +71,7 @@
|
|||||||
<div class='modal-form-content'>
|
<div class='modal-form-content'>
|
||||||
</div>
|
</div>
|
||||||
<div class='modal-footer'>
|
<div class='modal-footer'>
|
||||||
|
<div id='modal-footer-buttons'></div>
|
||||||
<button type='button' class='btn btn-default' id='modal-form-cancel' data-dismiss='modal'>{% trans "Cancel" %}</button>
|
<button type='button' class='btn btn-default' id='modal-form-cancel' data-dismiss='modal'>{% trans "Cancel" %}</button>
|
||||||
<button type='button' class='btn btn-primary' id='modal-form-accept'>{% trans "Accept" %}</button>
|
<button type='button' class='btn btn-primary' id='modal-form-accept'>{% trans "Accept" %}</button>
|
||||||
</div>
|
</div>
|
||||||
@ -90,6 +93,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class='modal-footer'>
|
<div class='modal-footer'>
|
||||||
|
<div id='modal-footer-buttons'></div>
|
||||||
<button type='button' class='btn btn-default' data-dismiss='modal'>{% trans "Close" %}</button>
|
<button type='button' class='btn btn-default' data-dismiss='modal'>{% trans "Close" %}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user