demarches-normaliennes/app/javascript/controllers/geo_area_controller.tsx

32 lines
781 B
TypeScript
Raw Normal View History

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() {
2023-06-06 15:54:03 +02:00
this.debounce(this.updateDescription, 500);
}
private updateDescription(): void {
this.globalDispatch('map:feature:update', {
id: this.idValue,
properties: { description: this.descriptionTarget.value.trim() }
});
}
}