diff --git a/Makefile b/Makefile index 5aabf9bb8..9752cec70 100644 --- a/Makefile +++ b/Makefile @@ -232,7 +232,6 @@ dist/iD.js: \ js/id/ui/preset/address.js \ js/id/ui/preset/check.js \ js/id/ui/preset/combo.js \ - js/id/ui/preset/multiselect.js \ js/id/ui/preset/cycleway.js \ js/id/ui/preset/input.js \ js/id/ui/preset/localized.js \ diff --git a/data/presets.yaml b/data/presets.yaml index 572c41e69..16690691d 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -773,7 +773,7 @@ en: railway: # 'railway=*' label: Type - recycling/recycling_choices: + recycling_accepts: # 'recycling:=*' label: Accepts ref: diff --git a/data/presets/fields.json b/data/presets/fields.json index 0a88d5232..d6ac0a9b9 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -653,7 +653,7 @@ }, "internet_access": { "key": "internet_access", - "type": "multiselect", + "type": "combo", "label": "Internet Access", "strings": { "options": { @@ -1020,9 +1020,9 @@ "type": "typeCombo", "label": "Type" }, - "recycling/recycling_choices": { + "recycling_accepts": { "key": "recycling:", - "type": "multiselect", + "type": "multiCombo", "label": "Accepts" }, "ref": { @@ -1234,7 +1234,7 @@ }, "sport_ice": { "key": "sport", - "type": "multiselect", + "type": "combo", "label": "Sport", "options": [ "skating", diff --git a/data/presets/fields/internet_access.json b/data/presets/fields/internet_access.json index ec5ca1f7c..a628dfd5f 100644 --- a/data/presets/fields/internet_access.json +++ b/data/presets/fields/internet_access.json @@ -1,6 +1,6 @@ { "key": "internet_access", - "type": "multiselect", + "type": "combo", "label": "Internet Access", "strings": { "options": { diff --git a/data/presets/fields/recycling/recycling_choices.json b/data/presets/fields/recycling_accepts.json similarity index 65% rename from data/presets/fields/recycling/recycling_choices.json rename to data/presets/fields/recycling_accepts.json index 57398e714..0866f7884 100644 --- a/data/presets/fields/recycling/recycling_choices.json +++ b/data/presets/fields/recycling_accepts.json @@ -1,5 +1,5 @@ { "key": "recycling:", - "type": "multiselect", + "type": "multiCombo", "label": "Accepts" } diff --git a/data/presets/fields/sport_ice.json b/data/presets/fields/sport_ice.json index 1d42d5fb8..7e5133bf9 100644 --- a/data/presets/fields/sport_ice.json +++ b/data/presets/fields/sport_ice.json @@ -1,6 +1,6 @@ { "key": "sport", - "type": "multiselect", + "type": "combo", "label": "Sport", "options": [ "skating", diff --git a/data/presets/presets.json b/data/presets/presets.json index 3b1318b06..1cc17d080 100644 --- a/data/presets/presets.json +++ b/data/presets/presets.json @@ -1581,7 +1581,7 @@ "fields": [ "operator", "address", - "recycling/recycling_choices" + "recycling_accepts" ], "geometry": [ "point", diff --git a/data/presets/presets/amenity/recycling.json b/data/presets/presets/amenity/recycling.json index 23865fe5e..2cabff15b 100644 --- a/data/presets/presets/amenity/recycling.json +++ b/data/presets/presets/amenity/recycling.json @@ -3,7 +3,7 @@ "fields": [ "operator", "address", - "recycling/recycling_choices" + "recycling_accepts" ], "geometry": [ "point", diff --git a/dist/locales/en.json b/dist/locales/en.json index cdca08f78..d1075f0e1 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1281,7 +1281,7 @@ "railway": { "label": "Type" }, - "recycling/recycling_choices": { + "recycling_accepts": { "label": "Accepts" }, "ref": { diff --git a/index.html b/index.html index fc67bc970..80d184a2f 100644 --- a/index.html +++ b/index.html @@ -129,7 +129,6 @@ - diff --git a/js/id/ui/preset/multiselect.js b/js/id/ui/preset/multiselect.js deleted file mode 100644 index c0d5db19f..000000000 --- a/js/id/ui/preset/multiselect.js +++ /dev/null @@ -1,198 +0,0 @@ -iD.ui.preset.multiselect = function(field, context) { - var dispatch = d3.dispatch('init', 'change'), - optstrings = field.strings && field.strings.options, - optarray = field.options, - strings = {}, - multiselectContainer, - combobox, - comboboxData, - input, - isInitialized; - - // ensure field.key ends with a ':' - if (field.key.match(/.*:$/) === null) { - field.key += ':'; - } - - function getOptStringKey(val) { - if (optstrings) { - var match = _.find(strings, function(o) { - return o.value === val; - }); - return match && match.key; - } - } - - function getOptStringVal(key) { - if (optstrings) { - var match = _.find(strings, function(o) { - return o.key === key; - }); - return match && match.value; - } - } - - function objectDifference(a, b) { - var bObj = {}; - b.forEach(function(obj){ - bObj[obj.key] = obj; - }); - // Return all elements in a, unless in b - return a.filter(function(obj) { - return !(obj.key in bObj); - }); - } - - function multiselect(selection) { - isInitialized = false; - combobox = d3.combobox().minItems(1); - - multiselectContainer = selection.selectAll('ul').data([0]); - - multiselectContainer.enter() - .append('ul') - .on('click', function() { - window.setTimeout(function(){input.node().focus();}, 100); - }) - .attr('class', 'form-field-multiselect'); - - input = multiselectContainer.selectAll('input') - .data([0]); - - var enter = input.enter() - .append('input') - .attr('type', 'text') - .attr('id', 'preset-input-' + field.id); - - if (optstrings) { enter.attr('readonly', 'readonly'); } - - input - .call(function() {combobox(input, selection);}) - .on('change', change) - .on('blur', change) - .on('focus', function() {multiselectContainer.classed('active', true);}) - .each(function() { - if (optstrings) { - strings = Object.keys(optstrings).map(function(k) { - return { - key: k, - value: field.t('options.' + k, { 'default': optstrings[k] }) - }; - }); - dispatch.init(); - isInitialized = true; - } else if (optarray) { - strings = optarray.map(function(k) {return {key: k, value: k};}); - dispatch.init(); - isInitialized = true; - } else if (context.taginfo()) { - context.taginfo().multikeys({query: field.key}, function(err, data) { - if (!err) { - strings = data.map(function(k) { - var d = k.value.replace(field.key, ''); - return { - key: d, - value: d - }; - }); - dispatch.init(); - isInitialized = true; - } - }); - } - }); - } - - function updateStrings(tagsData) { - comboboxData = objectDifference(strings, tagsData); - combobox.data(comboboxData.map(comboValues)); - input.attr('placeholder', (field.placeholder() || t('inspector.add')) + '…'); - } - - function update(data) { - var chips = multiselectContainer.selectAll('.chips').data(data); - - var enter = chips.enter() - .insert('li', 'input') - .attr('class', 'chips'); - - enter.append('span'); - enter.append('a'); - - chips.select('span').text(function(d) {return d.value;}); - - chips.select('a') - .on('click', removeKey) - .attr('class', 'remove') - .text('×'); - - chips.exit().remove(); - } - - function comboValues(d) { - return { - value: d.value, - title: d.value - }; - } - - function change() { - multiselectContainer.classed('active', false); - var key = getOptStringKey(input.value()) || input.value(); - if (key && key !== '') { - var t = {}; - t[field.key + key] = 'yes'; - input.value(''); - field.keys.push(field.key + key); - dispatch.change(t); - } - } - - function removeKey(d) { - d3.event.stopPropagation(); - var t = {}; - t[field.key + d.key] = undefined; - dispatch.change(t); - } - - multiselect.tags = function(tags) { - var tagsData = []; - Object.keys(tags).forEach(function(d) { - if (d.indexOf(field.key) > -1 && tags[d] === 'yes') { - var datum = d.replace(field.key, ''); - - if (!optstrings) { - return tagsData.push({ - key: datum, - value: datum - }); - } - // discards any pair not found in optstrings - if (optstrings && getOptStringVal(datum)) { - return tagsData.push({ - key: datum, - value: getOptStringVal(datum) - }); - } - } - }); - - field.keys = _.map(_.pluck(tagsData, 'key'), function(v) { return field.key + v; }); - - update(tagsData); - - if (isInitialized) { - updateStrings(tagsData); - } else { - dispatch.on('init', function () { - updateStrings(tagsData); - }); - } - }; - - multiselect.focus = function() { - input.node().focus(); - }; - - return d3.rebind(multiselect, dispatch, 'on'); -};