mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 17:52:55 +00:00
Add support for defaults
Defaults are stripped if unchanged, when switching to a different preset.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user