universal presets

presets with universal=true show up for
any preset if the key is present
This commit is contained in:
Ansis Brammanis
2013-03-12 19:19:10 -04:00
parent ca1a7cf7f6
commit 831b67beae
9 changed files with 39 additions and 5 deletions
-1
View File
@@ -28,7 +28,6 @@ fs.writeFileSync('data/presets/presets.json', JSON.stringify(
fs.writeFileSync('data/data.js', 'iD.data = ' + JSON.stringify({
deprecated: r('deprecated.json'),
discarded: r('discarded.json'),
imagery: r('imagery.json'),
keys: r('keys.json'),
imagery: r('imagery.json'),
presets: {
+2 -1
View File
@@ -5,5 +5,6 @@
"addr:housenumber",
"addr:street",
"addr:city"
]
],
"universal": true
}
+3 -2
View File
@@ -1,4 +1,5 @@
{
"key": "ele",
"type": "number"
}
"type": "number",
"universal": true
}
+5
View File
@@ -0,0 +1,5 @@
{
"key": "source",
"type": "text",
"universal": true
}
+5
View File
@@ -0,0 +1,5 @@
{
"key": "phone",
"type": "tel",
"universal": true
}
+5
View File
@@ -0,0 +1,5 @@
{
"key": "website",
"type": "url",
"universal": true
}
+5
View File
@@ -0,0 +1,5 @@
{
"key": "wikipedia",
"type": "text",
"universal": true
}
+7
View File
@@ -15,6 +15,7 @@ iD.presets = function(context) {
all = iD.presets.Collection([iD.presets.Preset(other)]),
defaults = { area: all, line: all, point: all, vertex: all },
forms = {},
universal = [],
recent = iD.presets.Collection([]);
all.load = function(d) {
@@ -22,6 +23,7 @@ iD.presets = function(context) {
if (d.forms) {
_.forEach(d.forms, function(d, id) {
forms[id] = iD.presets.Form(d, id);
if (d.universal) universal.push(forms[id]);
});
}
@@ -31,6 +33,7 @@ iD.presets = function(context) {
});
}
if (d.categories) {
d.categories.forEach(function(d) {
all.collection.push(iD.presets.Category(d, all));
@@ -50,6 +53,10 @@ iD.presets = function(context) {
return all;
};
all.universal = function() {
return universal;
};
all.defaults = function(entity, n) {
var rec = recent.matchGeometry(entity, context.graph()).collection.slice(0, 4),
def = _.uniq(rec.concat(defaults[entity.geometry(context.graph())].collection)).slice(0, n - 1);
+7 -1
View File
@@ -46,7 +46,7 @@ iD.ui.preset = function(context) {
.enter()
.append('button')
.attr('class', 'preset-add-form')
.attr('title', function(d) { return d.title || d.key; })
.attr('title', function(d) { return d.label(); })
.on('click', addForm)
.append('span')
.attr('class', function(d) { return 'icon ' + d.icon; });
@@ -105,6 +105,12 @@ iD.ui.preset = function(context) {
}
});
context.presets().universal().forEach(function(p) {
if (haveKey(p.key) || _.any(p.keys, haveKey)) {
draw(formwrap, [p]);
}
});
event.setTags(tags);
return presets;
};