From fc79848c8925b032d6139e1a4d0fa1e9208c3782 Mon Sep 17 00:00:00 2001 From: Ellen Wittingen Date: Fri, 12 Apr 2024 12:11:50 +0200 Subject: [PATCH 1/2] added modal for editing a pricelists name --- app/controllers/price_lists_controller.rb | 2 +- app/javascript/packs/price_lists.js | 22 ++++++++++++++++++-- app/views/price_lists/_edit_modal.html.erb | 23 +++++++++++++++++++++ app/views/price_lists/_modal.html.erb | 4 ++-- app/views/price_lists/index.html.erb | 24 ++++++++++++++-------- 5 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 app/views/price_lists/_edit_modal.html.erb diff --git a/app/controllers/price_lists_controller.rb b/app/controllers/price_lists_controller.rb index 6a1a02ec3..02fa43cbf 100644 --- a/app/controllers/price_lists_controller.rb +++ b/app/controllers/price_lists_controller.rb @@ -40,7 +40,7 @@ def update else flash[:error] = "Prijslijst wijzigen mislukt; #{@price_list.errors.full_messages.join(', ')}" end - redirect_to @price_list + redirect_to price_lists_path end def archive diff --git a/app/javascript/packs/price_lists.js b/app/javascript/packs/price_lists.js index 7585ec79d..5c78c0735 100644 --- a/app/javascript/packs/price_lists.js +++ b/app/javascript/packs/price_lists.js @@ -16,10 +16,10 @@ document.addEventListener('turbolinks:load', () => { // Make sure property exists before Vue sees the data products.forEach(p => p.editing = false); - new Vue({ + const app = new Vue({ el: element, data: () => { - return { priceLists: priceLists, products: products, showArchived: false }; + return { priceLists: priceLists, products: products, showArchived: false, currentlyEditingPriceList: null }; }, computed: { filteredPriceLists: function() { @@ -133,6 +133,12 @@ document.addEventListener('turbolinks:load', () => { return products; }, + editPriceList: function(priceList) { + this.currentlyEditingPriceList = priceList; + /* eslint-disable no-undef */ + bootstrap.Modal.getOrCreateInstance('#editPriceListModal').show(); + }, + archivePriceList: function(priceList) { this.$http.post(`/price_lists/${priceList.id}/archive`, {}).then((response) => { priceList.archived_at = response.data; @@ -154,5 +160,17 @@ document.addEventListener('turbolinks:load', () => { }, } }); + + new Vue({ + el: document.getElementById('editPriceListModal'), + computed: { + url() { + return '/price_lists/' + app.currentlyEditingPriceList?.id; + }, + name() { + return app.currentlyEditingPriceList?.name; + }, + } + }); } }); diff --git a/app/views/price_lists/_edit_modal.html.erb b/app/views/price_lists/_edit_modal.html.erb new file mode 100644 index 000000000..fb2499b1f --- /dev/null +++ b/app/views/price_lists/_edit_modal.html.erb @@ -0,0 +1,23 @@ + diff --git a/app/views/price_lists/_modal.html.erb b/app/views/price_lists/_modal.html.erb index a0ef39f8b..14f69e16c 100644 --- a/app/views/price_lists/_modal.html.erb +++ b/app/views/price_lists/_modal.html.erb @@ -1,9 +1,9 @@ -