diff --git a/index.html b/index.html index fae1fc940..5caa49254 100644 --- a/index.html +++ b/index.html @@ -31,6 +31,7 @@ + @@ -71,6 +72,7 @@ + @@ -133,10 +135,13 @@
diff --git a/js/id/connection.js b/js/id/connection.js index 0460b09ab..07cd332b7 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -5,6 +5,7 @@ iD.Connection = function() { connection = {}, user = {}, version, + presetData, keys, inflight = {}, loadedTiles = {}, @@ -314,6 +315,12 @@ iD.Connection = function() { return connection; }; + connection.presetData = function(_) { + if (!arguments.length) return presetData; + presetData = _; + return connection; + }; + connection.authenticate = function(callback) { function done(err, res) { event.auth(); diff --git a/js/id/modes/select.js b/js/id/modes/select.js index ad06bda35..3b1fca4b2 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -24,7 +24,9 @@ iD.modes.Select = function(entity, initial) { history = map.history(), surface = mode.map.surface; - inspector.graph(graph); + inspector + .graph(graph) + .presetData(map.connection().presetData()); behaviors = [ iD.behavior.Hover(), diff --git a/js/id/presets.js b/js/id/presets.js new file mode 100644 index 000000000..694f7cae4 --- /dev/null +++ b/js/id/presets.js @@ -0,0 +1,18 @@ +iD.presetData = function() { + var presets = {}, + data = []; + + presets.data = function(_) { + if (!arguments.length) return data; + data = _; + return presets; + }; + + presets.match = function(entity) { + return data.filter(function(d) { + return _.contains(d.match.type, entity.type); + }); + }; + + return presets; +}; diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index 9612cadd9..bd099d35a 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -1,6 +1,7 @@ iD.ui.inspector = function() { var event = d3.dispatch('changeTags', 'close'), taginfo = iD.taginfo(), + presetData, initial = false, graph, tagList; @@ -8,6 +9,8 @@ iD.ui.inspector = function() { function inspector(selection) { var entity = selection.datum(); + var possiblePresets = presetData.match(entity); + var inspector = selection.append('div') .attr('class','inspector content'); @@ -21,6 +24,14 @@ iD.ui.inspector = function() { var inspectorwrap = inspectorbody.append('div') .attr('class', 'inspector-inner tag-wrap fillL2'); + if (possiblePresets.length) { + var inspectorpreset = inspectorwrap.append('div') + .attr('class', 'inspector-preset') + .call(iD.ui.preset() + .preset(possiblePresets[0])); + } + + inspectorwrap.append('h4') .text(t('edit_tags')); @@ -275,6 +286,11 @@ iD.ui.inspector = function() { return inspector; }; + inspector.presetData = function(_) { + presetData = _; + return inspector; + }; + inspector.graph = function(_) { graph = _; return inspector; diff --git a/js/id/ui/preset.js b/js/id/ui/preset.js new file mode 100644 index 000000000..beac0d8f3 --- /dev/null +++ b/js/id/ui/preset.js @@ -0,0 +1,63 @@ +iD.ui.preset = function() { + var preset; + + // generate form fields for a given field. + function input(d) { + switch (d.type) { + + case 'tel': + this.append('input') + .attr('type', 'tel') + .attr('placeholder', '1-555-555-5555'); + break; + + case 'email': + this.append('input') + .attr('type', 'email') + .attr('placeholder', 'email@domain.com'); + break; + + case 'url': + this.append('input') + .attr('type', 'url') + .attr('placeholder', 'http://example.com/'); + break; + + case 'select': + var select = this.append('select'); + var options = d.option.slice(); + options.unshift(''); + select.selectAll('option') + .data(options) + .enter() + .append('option') + .text(String); + break; + } + } + + function presets(selection) { + var sections = selection.selectAll('div.preset-section') + .data(preset.form) + .enter() + .append('div') + .attr('class', 'preset-section'); + + sections.each(function(d) { + var s = d3.select(this); + + s.append('h4') + .text(d.title || d.tag); + + input.call(s, d); + }); + } + + presets.preset = function(_) { + if (!arguments.length) return preset; + preset = _; + return presets; + }; + + return presets; +}; diff --git a/presets/josm.xml b/presets/josm.xml new file mode 100755 index 000000000..c6d8952fc --- /dev/null +++ b/presets/josm.xml @@ -0,0 +1,5819 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/presets/presets.json b/presets/presets.json new file mode 100644 index 000000000..af7efaaa5 --- /dev/null +++ b/presets/presets.json @@ -0,0 +1,58 @@ +[ + { + "name": "highway", + "match": { + "type": ["line"], + "tags": { + "highway": "*" + } + }, + "form": [ + { + "tag": "highway", + "title": "Highway Type", + "type": "select", + "option": ["primary", "secondary", "tertiary"] + } + ] + }, + { + "name": "cafe", + "match": { + "type": ["node", "area"], + "tags": { + "amenity": "cafe" + } + }, + "form": [ + { + "tag": "phone", + "type": "tel" + }, + { + "tag": "fax", + "type": "tel" + }, + { + "tag": "website", + "type": "url" + }, + { + "tag": "email", + "type": "email" + }, + { + "tag": "internet_access", + "title": "Internet Access", + "type": "select", + "option": ["yes", "wlan","wired","terminal","no"] + }, + { + "tag": "internet_access:fee", + "title": "Internet Access Fee", + "type": "select", + "option": ["yes", "no"] + } + ] + } +]