diff --git a/lib/location/decorate.mjs b/lib/location/decorate.mjs index ce0bb7da9d..997828f44e 100644 --- a/lib/location/decorate.mjs +++ b/lib/location/decorate.mjs @@ -7,6 +7,7 @@ export default location => { removeCallbacks: [], trash, update, + syncFields, mvt_cache, updateCallbacks: [], }) @@ -64,42 +65,23 @@ async function update() { }); await this.mvt_cache() - - let dependents = this.infoj - .filter(entry => typeof entry.newValue !== 'undefined') - .filter(entry => entry.dependents && entry.dependents.length) - .map(entry => entry.dependents) - .flat() - this.infoj + // Update entry.values with newValues. + // Return dependents from updated entries. + const dependents = this.infoj .filter(entry => typeof entry.newValue !== 'undefined') - .forEach(entry => { + .map(entry => { entry.value = entry.newValue; delete entry.newValue; + return entry.dependents }) - - if (dependents.length) { - - const response = await mapp.utils.xhr( - `${this.layer.mapview.host}/api/location/get?` + - mapp.utils.paramString({ - locale: this.layer.mapview.locale.key, - layer: this.layer.key, - table: this.table, - id: this.id, - fields: [...new Set(dependents)].join(), - }) - ); - - this.infoj - .filter(entry => typeof response[entry.field] !== 'undefined') - .forEach(entry => { - entry.value = response[entry.field]; - }) + .flat() + .filter(dependents => dependents !== undefined) - } + // sync dependent fields + if (dependents.length) await this.syncFields([...new Set(dependents)]) // Reload layer. this.layer.reload() @@ -107,6 +89,26 @@ async function update() { this.updateCallbacks?.forEach(fn => typeof fn === 'function' && fn(this)) } +async function syncFields(fields) { + + const response = await mapp.utils.xhr( + `${this.layer.mapview.host}/api/location/get?` + + mapp.utils.paramString({ + locale: this.layer.mapview.locale.key, + layer: this.layer.key, + table: this.table, + id: this.id, + fields: fields.join(), + }) + ); + + this.infoj + .filter(entry => typeof response[entry.field] !== 'undefined') + .forEach(entry => { + entry.value = response[entry.field]; + }) +} + function flyTo (maxZoom) { const sourceVector = new ol.source.Vector(); diff --git a/lib/ui/locations/entries/boolean.mjs b/lib/ui/locations/entries/boolean.mjs index 3b8085c868..a464c0fdae 100644 --- a/lib/ui/locations/entries/boolean.mjs +++ b/lib/ui/locations/entries/boolean.mjs @@ -1,21 +1,28 @@ export default entry => { - const chkbox = mapp.ui.elements.chkbox({ - label: entry.label || entry.title, - checked: entry.value, - disabled: !entry.edit, - onchange: (checked) => { + if (entry.edit) { - entry.newValue = checked - entry.location.view?.dispatchEvent( - new CustomEvent('valChange', { - detail: entry - })) + return mapp.ui.elements.chkbox({ + label: entry.label || entry.title, + checked: entry.newValue !== undefined ? entry.newValue: entry.value, + disabled: !entry.edit, + onchange: (checked) => { - } - }) + entry.newValue = checked + entry.location.view?.dispatchEvent( + new CustomEvent('valChange', { + detail: entry + })) + + } + }) - const node = mapp.utils.html.node`${chkbox}` + } - return node + const icon = `mask-icon ${entry.value? 'done': 'close'}` + + return mapp.utils.html.node` +