demarches-normaliennes/app/javascript/controllers/geo_area_controller.tsx
2022-04-22 10:24:39 +02:00

31 lines
781 B
TypeScript

import { ApplicationController } from './application_controller';
export class GeoAreaController extends ApplicationController {
static values = {
id: Number
};
static targets = ['description'];
declare readonly idValue: number;
declare readonly descriptionTarget: HTMLInputElement;
onFocus() {
this.globalDispatch('map:feature:focus', { id: this.idValue });
}
onClick(event: MouseEvent) {
event.preventDefault();
this.globalDispatch('map:feature:focus', { id: this.idValue });
}
onInput() {
this.debounce(this.updateDescription, 200);
}
private updateDescription(): void {
this.globalDispatch('map:feature:update', {
id: this.idValue,
properties: { description: this.descriptionTarget.value.trim() }
});
}
}