Dispatch events from geo areas list view
This commit is contained in:
parent
83baa58aa6
commit
95d61c85e1
2 changed files with 41 additions and 0 deletions
40
app/javascript/new_design/champs/carte.js
Normal file
40
app/javascript/new_design/champs/carte.js
Normal 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();
|
||||||
|
});
|
|
@ -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';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue