Add support for defaults

Defaults are stripped if unchanged,
when switching to a different preset.
This commit is contained in:
Ansis Brammanis
2013-02-21 17:50:32 -05:00
parent f723cbab65
commit 11f97c8da0
3 changed files with 32 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ iD.ui.preset = function() {
taginfo = iD.taginfo(),
context,
entity,
type,
hidden,
sections,
exttags,
@@ -42,13 +43,14 @@ iD.ui.preset = function() {
// generate form fields for a given field.
function input(d) {
var i, wrap;
var i, wrap,
default_ = d['default'] && d['default'][type];
switch (d.type) {
case 'text':
i = this.append('input')
.attr('type', 'text')
.attr('id', 'input-' + d.key)
.attr('placeholder', d['default'] || '');
.attr('placeholder', default_ || '');
break;
case 'tel':
i = this.append('input')
@@ -73,7 +75,7 @@ iD.ui.preset = function() {
.attr('type', 'checkbox')
.attr('id', 'input-' + d.key)
.each(function() {
if (d['default']) {
if (default_) {
this.attr('checked', 'checked');
}
});
@@ -87,6 +89,7 @@ iD.ui.preset = function() {
value: d
};
})));
if (default_) i.property('value', default_);
break;
case 'combo':
var combobox = d3.combobox();
@@ -173,6 +176,7 @@ iD.ui.preset = function() {
presets.entity = function(_) {
if (!arguments.length) return entity;
entity = _;
type = entity.type === 'node' ? entity.type : entity.geometry();
return presets;
};

View File

@@ -15,10 +15,24 @@ iD.ui.TagEditor = function() {
function tageditor(selection, preset) {
entity = selection.datum();
var type = entity.type === 'node' ? entity.type : entity.geometry();
if (preset) {
if (presetMatch) tags = _.omit(tags, _.keys(presetMatch.match.tags));
tags = _.extend(_.omit(tags), preset.match.tags);
if (presetMatch) {
// Strip preset's match tags
tags = _.omit(tags, _.keys(presetMatch.match.tags));
// Strip preset's default tags
for (var i in presetMatch.form) {
var field = presetMatch.form[i];
if (field['default'] && field['default'][type] == tags[field.key]) {
delete tags[field.key];
}
}
}
// Add new preset's match tags
tags = _.extend(tags, preset.match.tags);
}
presetMatch = preset || presetMatch || presetData.matchTags(entity);
@@ -115,8 +129,6 @@ iD.ui.TagEditor = function() {
}
function drawHead(selection) {
var entity = selection.datum();
var h2 = selection.append('h2');
h2.append('span')

View File

@@ -10,6 +10,15 @@
},
"icon": "cafe",
"form": [
{
"key": "building",
"type": "select",
"options": ["yes", "no"],
"default": {
"area": "yes",
"node": "no"
}
},
{
"key": "internet_access",
"title": "Internet Access",