diff --git a/inventory/static/js/combobox.js b/inventory/static/js/combobox.js index 558b037..1fc160a 100644 --- a/inventory/static/js/combobox.js +++ b/inventory/static/js/combobox.js @@ -36,6 +36,8 @@ function ComboBox(cfg) { const id = this.editingOption.value; const ok = await this._post(this.editUrl, { id, name }); if (ok) this.editingOption.textContent = name; + + this.$dispatch('combobox:item-edited', { id, name, ...this.editingOption.dataset }); } else if (this.createUrl) { const data = await this._post(this.createUrl, { name }, true); const id = (data && data.id) ? data.id : ('temp-' + Math.random().toString(36).slice(2)); diff --git a/inventory/templates/settings.html b/inventory/templates/settings.html index f6717dc..c469c3f 100644 --- a/inventory/templates/settings.html +++ b/inventory/templates/settings.html @@ -239,5 +239,19 @@ const roomEditorModal = new bootstrap.Modal(document.getElementById('roomEditor')); roomEditorModal.show(); }); + + container.addEventListener('combobox:item-edited', (e) => { + if (container.id !== 'room-container') return; + + const { id, name, area_id, function_id } = e.detail; + console.log(id, name, area_id, function_id) + const prep = new CustomEvent('roomEditor:prepare', { + detail: { id, name, sectionId: area_id, functionId: function_id } + }); + document.getElementById('roomEditor').dispatchEvent(prep); + + const roomEditorModal = new bootstrap.Modal(document.getElementById('roomEditor')); + roomEditorModal.show(); + }); })(); {% endblock %} \ No newline at end of file