From f73863ea517dd74c6de5ee38ac7c1a2e093cd661 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 7 May 2021 07:18:13 +0200 Subject: [PATCH] adding in cstm action buttons function --- InvenTree/templates/js/modals.js | 35 ++++++++++++++++++++++++++++++++ InvenTree/templates/modals.html | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/InvenTree/templates/js/modals.js b/InvenTree/templates/js/modals.js index 004e81c000..8d34d790d8 100644 --- a/InvenTree/templates/js/modals.js +++ b/InvenTree/templates/js/modals.js @@ -377,6 +377,15 @@ function modalSubmit(modal, callback) { $(modal).on('click', '#modal-form-submit', function() { callback(); }); + + $(modal).on('click', '.modal-form-button', function() { + // Append data to form + var name = $(this).attr('name'); + var value = $(this).attr('value'); + var input = ''; + $('.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 = ""; + html += ""; + html += ""; + + $(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) { /* 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 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 ajax_data = { url: url, @@ -852,6 +883,10 @@ function launchModalForm(url, options = {}) { handleModalForm(url, options); } + if (options.buttons) { + attachButtons(modal, options.buttons); + } + } else { $(modal).modal('hide'); showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}'); diff --git a/InvenTree/templates/modals.html b/InvenTree/templates/modals.html index 9850f482c5..e394b28314 100644 --- a/InvenTree/templates/modals.html +++ b/InvenTree/templates/modals.html @@ -25,6 +25,7 @@ @@ -49,6 +50,7 @@ @@ -69,6 +71,7 @@ @@ -90,6 +93,7 @@