From b0458b9d7add7ea0cf6ad8151c5d5d979732b3e2 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 18 Oct 2012 17:59:27 -0400 Subject: [PATCH] UI touches, reworking presets --- css/app.css | 23 +++++++++++ index.html | 13 +------ js/iD/Controller.js | 7 ---- js/iD/Util.js | 18 +++++++++ js/iD/controller/edit/EditBaseState.js | 27 +++++++++++++ presets/{nodes.json => node.json} | 0 presets/{ways.json => way.json} | 54 +++++++++++++++++++------- 7 files changed, 110 insertions(+), 32 deletions(-) rename presets/{nodes.json => node.json} (100%) rename presets/{ways.json => way.json} (61%) diff --git a/css/app.css b/css/app.css index 2ecf010f9..7f210c175 100644 --- a/css/app.css +++ b/css/app.css @@ -147,6 +147,8 @@ polyline { width:300px; background:#fff; box-shadow:1px 1px 3px #111; + max-height:300px; + overflow:auto; } .edit-pane h2 { @@ -191,3 +193,24 @@ polyline { .edit-pane table td input { width:140px; } + +.presets h3 { + padding: 5px; + font: normal 13px/15px Helvetica, Arial, sans-serif; + text-align:center; + margin: 0; +} + +.presets a.preset-option { + text-decoration:none; + display:block; + background:#eee; + padding:5px; + border-top:1px solid #ccc; +} + +.presets a.preset-option span { + display:block; + color: #888; + font: normal 11px/15px Helvetica, Arial, sans-serif; +} diff --git a/index.html b/index.html index 23ac6da76..71eca28b3 100755 --- a/index.html +++ b/index.html @@ -71,10 +71,6 @@ require(["dojo/dom-geometry","dojo/dom-class","dojo/on","dojo/dom","dojo/Evented // Set initial controllerState controller.setState(new iD.controller.edit.NoSelection()); - // Load presets - controller.setTagPresets('way', 'presets/ways.json'); - controller.setTagPresets('node', 'presets/nodes.json'); - // Load data map.download(); } @@ -155,14 +151,7 @@ require(["dojo/dom-geometry","dojo/dom-class","dojo/on","dojo/dom","dojo/Evented Presets Tags -
- -
+
diff --git a/js/iD/Controller.js b/js/iD/Controller.js index db7a2f2da..f763ad3d4 100755 --- a/js/iD/Controller.js +++ b/js/iD/Controller.js @@ -9,14 +9,12 @@ declare("iD.Controller", [Evented], { map: null, // current Map stepper: null, // current StepPane undoStack: null, // main undoStack - presets: null, // tag presets editorCache: null, // cache of tag editor objects, means we don't have to repeatedly load them constructor:function(map) { // summary: The Controller marshalls ControllerStates and passes events to them. this.map = map; this.undoStack = new iD.actions.UndoStack(); - this.presets = {}; this.editorCache = {}; }, @@ -25,11 +23,6 @@ declare("iD.Controller", [Evented], { this.stepper = stepper; }, - setTagPresets:function(type, url) { - // summary: Load and store a JSON tag preset file. - this.presets[type] = new iD.tags.PresetList(type,url); - }, - setState:function(newState) { // summary: Enter a new ControllerState, firing exitState on the old one, and enterState on the new one. if (newState === this.state) { return; } diff --git a/js/iD/Util.js b/js/iD/Util.js index 60e47a297..0dbbd0860 100644 --- a/js/iD/Util.js +++ b/js/iD/Util.js @@ -26,3 +26,21 @@ iD.Util.friendlyName = function(entity) { return n.length === 0 ? 'unknown' : n.join('; '); }; + +iD.Util._presets = {}; + +iD.Util.presets = function(type, callback) { + if (iD.Util._presets[type]) return callback(iD.Util._presets[type]); + $.ajax({ + url: 'presets/' + type + '.json', + dataType: "json", + error: function() { + if (typeof console !== 'undefined') console.error(arguments); + }, + success: function(resp) { + console.log(resp); + iD.Util._presets[type] = resp; + return callback(resp); + } + }); +}; diff --git a/js/iD/controller/edit/EditBaseState.js b/js/iD/controller/edit/EditBaseState.js index db9b4ec2a..decde3c1e 100644 --- a/js/iD/controller/edit/EditBaseState.js +++ b/js/iD/controller/edit/EditBaseState.js @@ -35,6 +35,32 @@ declare("iD.controller.edit.EditBaseState", [iD.controller.ControllerState], { return e.preventDefault(); }); $('.edit-pane a.tab:first').click(); + + var $presets = $('.edit-pane .presets'); + // Build presets panel + iD.Util.presets(entity.entityType, function(presets) { + $presets.empty(); + console.log(presets); + _.each(presets, function(pre, category) { + $('

') + .text(category) + .appendTo($presets); + _.each(pre, function(set) { + var a = $('') + .text(set.name) + .attr({ + 'class': 'preset-option', + 'href': '#' + }) + .appendTo($presets); + $('') + .text(set.description) + .appendTo(a); + }); + }); + }); + + // Build tag panel $('.edit-pane .tags tbody').empty(); _.each(entity.tags, function(value, key) { var tr = $('').appendTo( @@ -52,6 +78,7 @@ declare("iD.controller.edit.EditBaseState", [iD.controller.ControllerState], { $('').append(keyfield).appendTo(tr); $('').append(valuefield).appendTo(tr); }); + $('.edit-pane a[href=#close]').click(this.closeEditorTooltip); }, diff --git a/presets/nodes.json b/presets/node.json similarity index 100% rename from presets/nodes.json rename to presets/node.json diff --git a/presets/ways.json b/presets/way.json similarity index 61% rename from presets/ways.json rename to presets/way.json index 2eb2bee12..819ea3979 100644 --- a/presets/ways.json +++ b/presets/way.json @@ -1,6 +1,8 @@ { - "Roads": { - "Motorway": { + "Roads": [ + { + "name": "Motorway", + "description": "a large highway, linking states or provinces", "tags": { "highway": "motorway" }, @@ -15,7 +17,9 @@ "road" ] }, - "Trunk road": { + { + "name": "Trunk road", + "description": "a highway, linking states or provinces", "tags": { "highway": "secondary" }, @@ -26,7 +30,9 @@ "bus" ] }, - "Primary road": { + { + "name": "Primary road", + "description": "a highway linking large towns", "tags": { "highway": "primary" }, @@ -37,7 +43,9 @@ "bus" ] }, - "Secondary road": { + { + "name": "Secondary road", + "description": "Multi-lane roads that lead to residential roads. Usually they have stop lights and feed in to larger streets.", "tags": { "highway": "secondary" }, @@ -48,7 +56,9 @@ "bus" ] }, - "Tertiary road": { + { + "name": "Tertiary road", + "description": "Roads that connect to residential roads. Typically feature stop lights and connect to larger streets.", "tags": { "highway": "tertiary" }, @@ -59,7 +69,22 @@ "bus" ] }, - "Minor road": { + { + "name": "Residential", + "description": "a typically paved road that connects other roads to housing, and usually to driveways", + "tags": { + "highway": "residential" + }, + "icon": "ways/highway__unclassified.png", + "editors": [ + "road", + "cycling", + "bus" + ] + }, + { + "name": "Minor road", + "description": "Minor connecting roads", "tags": { "highway": "unclassified" }, @@ -70,9 +95,10 @@ "bus" ] } - }, - "Railways": { - "Railway": { + ], + "Railways": [ + { + "name": "Railway", "tags": { "railway": "rail" }, @@ -81,7 +107,8 @@ "rail" ] }, - "Disused tracks": { + { + "name": "Disused tracks", "tags": { "railway": "disused" }, @@ -90,7 +117,8 @@ "rail" ] }, - "Abandoned trackbed": { + { + "name": "Abandoned trackbed", "tags": { "railway": "abandoned" }, @@ -99,5 +127,5 @@ "rail" ] } - } + ] }