diff --git a/umap/static/umap/js/modules/autocomplete.js b/umap/static/umap/js/modules/autocomplete.js index e6e55b92..48c0cdaa 100644 --- a/umap/static/umap/js/modules/autocomplete.js +++ b/umap/static/umap/js/modules/autocomplete.js @@ -222,12 +222,16 @@ export class BaseAutocomplete { } export class BaseAjax extends BaseAutocomplete { - URL = '/foobar/?q={q}' constructor(el, options) { super(el, options) + this.setUrl() this.initRequest() } + setUrl() { + this.url = this.options?.url + } + initRequest() { this.request = new Request() } @@ -248,7 +252,7 @@ export class BaseAjax extends BaseAutocomplete { if (val === this.cache) return else this.cache = val val = val.toLowerCase() - const url = Util.template(this.URL, { q: encodeURIComponent(val) }) + const url = Util.template(this.url, { q: encodeURIComponent(val) }) this.handleResults(await this._search(url)) } @@ -261,7 +265,10 @@ export class BaseAjax extends BaseAutocomplete { } class BaseServerAjax extends BaseAjax { - URL = '/agnocomplete/AutocompleteUser/?q={q}' + setUrl() { + this.url = '/agnocomplete/AutocompleteUser/?q={q}' + } + initRequest() { this.server = new ServerRequest() } diff --git a/umap/static/umap/js/modules/importers/communesfr.js b/umap/static/umap/js/modules/importers/communesfr.js index 5fa3ee62..845c2125 100644 --- a/umap/static/umap/js/modules/importers/communesfr.js +++ b/umap/static/umap/js/modules/importers/communesfr.js @@ -2,8 +2,6 @@ import { DomUtil } from '../../../vendors/leaflet/leaflet-src.esm.js' import { BaseAjax, SingleMixin } from '../autocomplete.js' class Autocomplete extends SingleMixin(BaseAjax) { - URL = 'https://geo.api.gouv.fr/communes?nom={q}&limit=5' - createResult(item) { return super.createResult({ value: item.code, @@ -26,6 +24,7 @@ export class Importer { textContent: "Importer les contours d'une commune française.", }) const options = { + url: 'https://geo.api.gouv.fr/communes?nom={q}&limit=5', on_select: (choice) => { importer.url = `https://geo.api.gouv.fr/communes?code=${choice.item.value}&format=geojson&geometry=contour` importer.format = 'geojson' diff --git a/umap/static/umap/js/modules/importers/geodatamine.js b/umap/static/umap/js/modules/importers/geodatamine.js index ea7efac4..0a46b828 100644 --- a/umap/static/umap/js/modules/importers/geodatamine.js +++ b/umap/static/umap/js/modules/importers/geodatamine.js @@ -21,8 +21,6 @@ const TEMPLATE = ` ` class Autocomplete extends SingleMixin(BaseAjax) { - URL = 'https://geodatamine.fr/boundaries/search?text={q}' - createResult(item) { return super.createResult({ value: item.id, @@ -58,6 +56,7 @@ export class Importer { } const asPoint = container.querySelector('[name=aspoint]') this.autocomplete = new Autocomplete(container, { + url: `${this.baseUrl}/boundaries/search?text={q}`, on_select: (choice) => { boundary = choice.item.value },