diff --git a/inventory/models/rooms.py b/inventory/models/rooms.py index 0244a48..3360272 100644 --- a/inventory/models/rooms.py +++ b/inventory/models/rooms.py @@ -23,7 +23,6 @@ class Room(db.Model): inventory: Mapped[List['Inventory']] = relationship('Inventory', back_populates='location') users: Mapped[List['User']] = relationship('User', back_populates='location') - ui_label_attr = 'name' ui_eagerload = tuple() ui_extra_attrs = ('area_id', 'function_id') diff --git a/inventory/static/js/dropdown.js b/inventory/static/js/dropdown.js index bf204b2..682584c 100644 --- a/inventory/static/js/dropdown.js +++ b/inventory/static/js/dropdown.js @@ -97,6 +97,8 @@ function DropDown(cfg) { id: cfg.id, refreshUrl: cfg.refreshUrl, selectUrl: cfg.selectUrl, + recordId: cfg.recordId, // NEW + field: cfg.field, // NEW selectedId: null, selectedLabel: '', @@ -125,19 +127,21 @@ function DropDown(cfg) { if (button) { button.textContent = label || '-'; button.dataset.invValue = id; - button.classList.add("rounded-end-0"); - button.classList.add("border-end-0"); + button.classList.add("rounded-end-0", "border-end-0"); button.classList.remove("rounded-end"); } clear?.classList.toggle('d-none', !id); - if (this.selectUrl) { + if (this.selectUrl && this.recordId && this.field) { + const payload = { id: this.recordId }; + payload[this.field] = id ? parseInt(id) : null; + fetch(this.selectUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ id }) - }).catch(() => {}); + body: JSON.stringify(payload) + }).catch(() => { }); } }, @@ -153,12 +157,21 @@ function DropDown(cfg) { if (button) { button.textContent = '-'; button.removeAttribute('data-inv-value'); - - button.classList.remove("rounded-end-0"); - button.classList.remove("border-end-0"); + button.classList.remove("rounded-end-0", "border-end-0"); button.classList.add("rounded-end"); } clear?.classList.add('d-none'); + + if (this.selectUrl && this.recordId && this.field) { + const payload = { id: this.recordId }; + payload[this.field] = null; + fetch(this.selectUrl, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload) + }).catch(() => { }); + } + this.$dispatch('dropdown:cleared', {}); } }; diff --git a/inventory/templates/fragments/_dropdown_fragment.html b/inventory/templates/fragments/_dropdown_fragment.html index 9ca3e68..30ebf76 100644 --- a/inventory/templates/fragments/_dropdown_fragment.html +++ b/inventory/templates/fragments/_dropdown_fragment.html @@ -42,8 +42,7 @@ {% endmacro %} - -{% macro dynamic_dropdown(id, list = none, label = none, current_item = none, entry_link = none, enabled = true, refresh_url = none, select_url = none) %} +{% macro dynamic_dropdown(id, list = none, label = none, current_item = none, entry_link = none, enabled = true, refresh_url = none, select_url = none, record_id = none, field_name = none) %}