From 7f6f606a7cfccfb78122498f38b81ac34bd429b4 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 1 Mar 2013 17:08:23 -0500 Subject: [PATCH] extract preset fields --- index.html | 8 +- js/id/presets.js | 9 +- js/id/presets/preset.js | 10 +- presets/forms.json | 81 +++++++++ presets/presets.json | 386 +++------------------------------------- 5 files changed, 125 insertions(+), 369 deletions(-) create mode 100644 presets/forms.json diff --git a/index.html b/index.html index d65be30cb..210494597 100644 --- a/index.html +++ b/index.html @@ -160,7 +160,7 @@ - + @@ -190,7 +190,8 @@ var id = iD(); - iD.util.asyncMap(['keys.json', 'presets/presets.json', 'presets/defaults.json', 'presets/categories.json'], d3.json, function(err, data) { + iD.util.asyncMap(['keys.json', 'presets/presets.json', 'presets/defaults.json', + 'presets/categories.json', 'presets/forms.json'], d3.json, function(err, data) { id.connection() .keys(data[0]); @@ -198,7 +199,8 @@ .load({ presets: data[1], defaults: data[2], - categories: data[3] + categories: data[3], + forms: data[4] }); d3.select("#iD") diff --git a/js/id/presets.js b/js/id/presets.js index c73b9a088..690c4b87a 100644 --- a/js/id/presets.js +++ b/js/id/presets.js @@ -14,13 +14,18 @@ iD.presets = function(context) { form: [] }, all = iD.presets.Collection([iD.presets.Preset(other)]), - defaults = {}; + defaults = {}, + forms = {}; all.load = function(d) { + if (d.forms) { + forms = d.forms; + } + if (d.presets) { d.presets.forEach(function(d) { - all.collection.push(iD.presets.Preset(d)); + all.collection.push(iD.presets.Preset(d, forms)); }); } diff --git a/js/id/presets/preset.js b/js/id/presets/preset.js index 9264ac8b0..0978004c6 100644 --- a/js/id/presets/preset.js +++ b/js/id/presets/preset.js @@ -1,4 +1,12 @@ -iD.presets.Preset = function(preset) { +iD.presets.Preset = function(preset, forms) { + + preset.form = preset.form.map(function(f) { + if (typeof f === 'string') { + return forms[f]; + } else { + return f; + } + }); preset.matchType = function(entity, resolver) { return preset.match.type.indexOf(entity.geometry(resolver)) >= 0; diff --git a/presets/forms.json b/presets/forms.json new file mode 100644 index 000000000..30ccbbff6 --- /dev/null +++ b/presets/forms.json @@ -0,0 +1,81 @@ +{ + "cuisine": { + "key": "cuisine", + "type": "combo", + "indexed": true + }, + "internet_access": { + "key": "internet_access", + "title": "Internet Access", + "type": "select", + "options": ["yes", "no", "wlan", "wired", "terminal"] + }, + "building_area": { + "key": "building", + "type": "select", + "default": { "area": "yes" }, + "options": ["yes", "no"] + }, + "address": { + "type": "address", + "title": "Address" + }, + "operator": { + "key": "operator", + "type": "text" + }, + "religion": { + "key": "religion", + "type": "select", + "options": ["christian", "muslim", "buddhist", "jewish", "hindu", "shinto", "taoist"] + }, + "denomination": { + "key": "denomination", + "type": "combo" + }, + "building": { + "key": "building", + "type": "combo" + }, + "fee": { + "key": "fee", + "type": "select", + "options": ["yes", "no"] + }, + "access": { + "key": "access", + "type": "combo" + }, + "atm": { + "key": "atm", + "type": "select", + "options": ["yes", "no"] + }, + "shelter": { + "key": "shelter", + "type": "select", + "options": ["yes", "no"] + }, + "emergency": { + "key": "emergency", + "type": "select", + "options": ["yes", "no"] + }, + "oneway": { + "key": "oneway", + "type": "select", + "options": ["yes", "no"] + }, + "access": { + "key": "access", + "type": "combo" + }, + "maxspeed": { + "key": "maxspeed", + "type": "combo" + }, + "surface": { + "key": "surface", + "type": "combo" + } +} diff --git a/presets/presets.json b/presets/presets.json index 7f9d27782..0a91cedca 100644 --- a/presets/presets.json +++ b/presets/presets.json @@ -9,31 +9,7 @@ } }, "icon": "cafe", - "form": [ - { - "key": "cuisine", - "type": "combo", - "indexed": true - }, - { - "key": "internet_access", - "title": "Internet Access", - "type": "select", - "options": ["yes", "no", "wlan", "wired", "terminal"] - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["cuisine", "internet_access", "building_area", "address"] }, { "title": "Park", @@ -69,24 +45,7 @@ } }, "icon": "grocery", - "form": [ - { - "key": "operator", - "type": "text" - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["operator", "building_area", "address"] }, { "title": "Restaurant", @@ -98,24 +57,7 @@ } }, "icon": "restaurant", - "form": [ - { - "key": "cuisine", - "type": "combo" - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["cuisine", "building_area", "address"] }, { "title": "Place of worship", @@ -127,29 +69,7 @@ } }, "icon": "place-of-worship", - "form": [ - { - "key": "religion", - "type": "select", - "options": ["christian", "muslim", "buddhist", "jewish", "hindu", "shinto", "taoist"] - }, - { - "key": "denomination", - "type": "combo" - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["religion", "denomination", "building_area", "address"] }, { "title": "School", @@ -161,21 +81,7 @@ } }, "icon": "school", - "form": [ - { - "key": "operator", - "type": "text" - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"] - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["operator", "building", "address"] }, { "title": "Parking", @@ -187,21 +93,7 @@ } }, "icon": "parking", - "form": [ - { - "key": "fee", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["fee", "access", "address"] }, { "title": "Bank", @@ -213,25 +105,7 @@ } }, "icon": "bank", - "form": [ - { - "key": "atm", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["atm", "building_area", "address"] }, { "title": "Fast food", @@ -243,24 +117,7 @@ } }, "icon": "fast-food", - "form": [ - { - "key": "cuisine", - "type": "combo" - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["cuisine", "building_area", "address"] }, { "title": "Bar", @@ -272,20 +129,7 @@ } }, "icon": "bar", - "form": [ - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["building_area", "address"] }, { "title": "Bus stop", @@ -297,17 +141,7 @@ } }, "icon": "bus", - "form": [ - { - "key": "operator", - "type": "text" - }, - { - "key": "shelter", - "type": "select", - "options": ["yes", "no"] - } - ] + "form": ["operator", "shelter"] }, { "title": "Cinema", @@ -319,20 +153,7 @@ } }, "icon": "cinema", - "form": [ - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["building_area", "address"] }, { "title": "Hospital", @@ -344,25 +165,7 @@ } }, "icon": "hospital", - "form": [ - { - "key": "emergency", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "building", - "type": "select", - "options": ["yes", "no"], - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["emergency", "building_area", "address"] }, { "title": "River", @@ -386,21 +189,7 @@ } }, "icon": "highway-motorway", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Residential road", @@ -412,21 +201,7 @@ } }, "icon": "highway-residential", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Primary Road", @@ -438,21 +213,7 @@ } }, "icon": "highway-primary", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Secondary Road", @@ -464,21 +225,7 @@ } }, "icon": "highway-secondary", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Tertiary Road", @@ -490,21 +237,7 @@ } }, "icon": "highway-tertiary", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Service Road", @@ -516,21 +249,7 @@ } }, "icon": "highway-service", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Rail", @@ -554,21 +273,7 @@ } }, "icon": "highway-trunk", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Foot path", @@ -580,21 +285,7 @@ } }, "icon": "highway-footway", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": [] }, { "title": "Cycle path", @@ -606,21 +297,7 @@ } }, "icon": "highway-cycleway", - "form": [ - { - "key": "oneway", - "type": "select", - "options": ["yes", "no"] - }, - { - "key": "access", - "type": "combo" - }, - { - "key": "maxspeed", - "type": "combo" - } - ] + "form": ["oneway", "access", "maxspeed"] }, { "title": "Basketball court", @@ -633,12 +310,7 @@ } }, "icon": "basketball", - "form": [ - { - "key": "surface", - "type": "combo" - } - ] + "form": ["surface"] }, { "title": "Building", @@ -650,18 +322,6 @@ } }, "icon": "warehouse", - "form": [ - { - "key": "building", - "type": "combo", - "default": { - "area": "yes" - } - }, - { - "type": "address", - "title": "Address" - } - ] + "form": ["building", "address"] } ]