diff --git a/app/controllers/price_lists_controller.rb b/app/controllers/price_lists_controller.rb index 44266f0e0..5ea61ff1e 100644 --- a/app/controllers/price_lists_controller.rb +++ b/app/controllers/price_lists_controller.rb @@ -41,7 +41,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/price_lists.js b/app/javascript/price_lists.js index 682d346f8..0a02c145e 100644 --- a/app/javascript/price_lists.js +++ b/app/javascript/price_lists.js @@ -1,18 +1,19 @@ import Vue from 'vue/dist/vue.esm'; +import * as bootstrap from 'bootstrap'; import api from './api/axiosInstance'; document.addEventListener('turbo:load', () => { const element = document.getElementById('pricelists-container'); - if (element != null) { + if (element != null && !element.__vue__) { const priceLists = JSON.parse(element.dataset.priceLists); const products = JSON.parse(element.dataset.products); products.forEach(p => p.editing = false); - new Vue({ + const app = new Vue({ el: element, data: () => { - return { priceLists: priceLists, products: products, showArchived: false, errors: [] }; + return { priceLists: priceLists, products: products, showArchived: false, errors: [], currentlyEditingPriceList: null }; }, computed: { filteredPriceLists: function() { @@ -141,6 +142,11 @@ document.addEventListener('turbo:load', () => { } }, + editPriceList: function(priceList) { + this.currentlyEditingPriceList = { ...priceList }; + bootstrap.Modal.getOrCreateInstance('#editPriceListModal').show(); + }, + archivePriceList: function(priceList) { api.post(`/price_lists/${priceList.id}/archive`, {}).then((response) => { priceList.archived_at = response.data; @@ -176,5 +182,27 @@ document.addEventListener('turbo:load', () => { }, } }); + + const editModalElement = document.getElementById('editPriceListModal'); + if (editModalElement && !editModalElement.__vue__) { + new Vue({ + el: editModalElement, + computed: { + url() { + return '/price_lists/' + app.currentlyEditingPriceList?.id; + }, + name: { + get() { + return app.currentlyEditingPriceList?.name || ''; + }, + set(value) { + if (app.currentlyEditingPriceList) { + app.currentlyEditingPriceList.name = value; + } + } + } + } + }); + } } }); \ No newline at end of file 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..2915e6c68 --- /dev/null +++ b/app/views/price_lists/_edit_modal.html.erb @@ -0,0 +1,30 @@ + diff --git a/app/views/price_lists/_modal.html.erb b/app/views/price_lists/_modal.html.erb index a0ef39f8b..e4066240b 100644 --- a/app/views/price_lists/_modal.html.erb +++ b/app/views/price_lists/_modal.html.erb @@ -1,9 +1,9 @@ -