Dispatch events from geo areas list view

This commit is contained in:
Paul Chavard 2020-06-09 17:22:33 +02:00
parent 83baa58aa6
commit 95d61c85e1
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,40 @@
import { delegate, fire, debounce } from '@utils';
const inputHandlers = new Map();
addEventListener('ds:page:update', () => {
const inputs = document.querySelectorAll('.areas input[data-geo-area]');
for (const input of inputs) {
input.addEventListener('focus', (event) => {
const id = parseInt(event.target.dataset.geoArea);
fire(document, 'map:feature:focus', { id });
});
}
});
delegate('click', '.areas a[data-geo-area]', (event) => {
event.preventDefault();
const id = parseInt(event.target.dataset.geoArea);
fire(document, 'map:feature:focus', { id });
});
delegate('input', '.areas input[data-geo-area]', (event) => {
const id = parseInt(event.target.dataset.geoArea);
let handler = inputHandlers.get(id);
if (!handler) {
handler = debounce(() => {
const input = document.querySelector(`input[data-geo-area="${id}"]`);
if (input) {
fire(document, 'map:feature:update', {
id,
properties: { description: input.value.trim() }
});
}
}, 200);
inputHandlers.set(id, handler);
}
handler();
});

View file

@ -24,6 +24,7 @@ import '../new_design/support';
import '../new_design/dossiers/auto-save'; import '../new_design/dossiers/auto-save';
import '../new_design/dossiers/auto-upload'; import '../new_design/dossiers/auto-upload';
import '../new_design/champs/carte';
import '../new_design/champs/linked-drop-down-list'; import '../new_design/champs/linked-drop-down-list';
import '../new_design/champs/repetition'; import '../new_design/champs/repetition';