From 70bf9ea92f5e5565d78dfc02a733e0a4a60f964f Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 7 Oct 2020 17:44:44 +0200 Subject: [PATCH] remove unused select2 code --- app/javascript/new_design/select2.js | 95 ---------------------------- 1 file changed, 95 deletions(-) diff --git a/app/javascript/new_design/select2.js b/app/javascript/new_design/select2.js index e92aad0ce..e69e1c92e 100644 --- a/app/javascript/new_design/select2.js +++ b/app/javascript/new_design/select2.js @@ -1,8 +1,5 @@ import $ from 'jquery'; import 'select2'; -import { isNumeric } from '@utils'; - -const { api_geo_url, api_adresse_url } = gon.autocomplete || {}; const language = { errorLoading: function () { @@ -50,94 +47,6 @@ const baseOptions = { width: '100%' }; -const baseAjaxOptions = { - delay: 250, - timeout: 10 * 1000, // 10 sec - cache: true, - data({ term: nom }) { - return { - nom, - fields: 'nom,code' - }; - }, - processResults(data) { - return { - results: data.map(({ nom }) => ({ id: nom, text: nom })) - }; - } -}; - -const regionsOptions = { - ...baseOptions, - minimumInputLength: 2, - ajax: { url: `${api_geo_url}/regions`, ...baseAjaxOptions } -}; - -const communesOptions = { - ...baseOptions, - minimumInputLength: 2, - ajax: { url: `${api_geo_url}/communes`, ...baseAjaxOptions } -}; - -const etranger99 = { id: '99 - Étranger', text: '99 - Étranger' }; -const departementsOptions = { - ...baseOptions, - minimumInputLength: 1, - ajax: { - ...baseAjaxOptions, - url: `${api_geo_url}/departements`, - data({ term }) { - const data = { fields: 'nom,code' }; - - if (isNumeric(term)) { - data.code = term.trim().padStart(2, '0'); - } else { - data.nom = term; - } - - return data; - }, - processResults(data) { - return { - results: data - .map(({ nom, code }) => ({ - id: `${code} - ${nom}`, - text: `${code} - ${nom}` - })) - .concat([etranger99]) - }; - } - } -}; - -const adresseOptions = { - ...baseOptions, - minimumInputLength: 2, - ajax: { - ...baseAjaxOptions, - url: `${api_adresse_url}/search`, - data({ term: q }) { - return { - q, - limit: 5 - }; - }, - processResults(data) { - let r = data.features.map(({ properties: { label }, geometry }) => ({ - id: label, - text: label, - geometry - })); - // Allow the user to select an arbitrary address missing from the results, - // by adding the plain-text query to the list of results. - r.unshift({ id: data.query, text: data.query }); - return { - results: r - }; - } - } -}; - const templateOption = ({ text }) => $( `${text}` @@ -145,10 +54,6 @@ const templateOption = ({ text }) => addEventListener('ds:page:update', () => { $('select.select2').select2(baseOptions); - $('select.select2.departements').select2(departementsOptions); - $('select.select2.regions').select2(regionsOptions); - $('select.select2.communes').select2(communesOptions); - $('select.select2.adresse').select2(adresseOptions); $('.columns-form select.select2-limited').select2({ width: '300px',