Merge branch 'sidebar' of github.com:systemed/iD into sidebar

This commit is contained in:
Saman Bemel-Benrud
2013-05-28 15:59:19 -04:00
11 changed files with 54 additions and 37 deletions

View File

@@ -69,10 +69,17 @@ function generateFields() {
validate(file, field, fieldSchema);
translations.fields[id] = {label: field.label};
var t = translations.fields[id] = {
label: field.label
};
if (field.placeholder) {
t.placeholder = field.placeholder;
}
if (field.strings) {
for (var i in field.strings) {
translations.fields[id][i] = field.strings[i];
t[i] = field.strings[i];
}
}

View File

@@ -211,6 +211,7 @@ en:
label: Type
website:
label: Website
placeholder: "http://example.com/"
wetland:
label: Type
wheelchair:

View File

@@ -655,7 +655,8 @@
"label": "Type"
},
"website": {
"label": "Website"
"label": "Website",
"placeholder": "http://example.com/"
},
"wetland": {
"label": "Type"

View File

@@ -15,5 +15,10 @@ iD.presets.Field = function(id, field) {
return field.t('label', {'default': id});
};
var placeholder = field.placeholder;
field.placeholder = function() {
return field.t('placeholder', {'default': placeholder});
};
return field;
};

View File

@@ -6,8 +6,6 @@ iD.ui.Inspector = function(context) {
newFeature = false;
function inspector(selection) {
selection.style('display', 'block');
var $wrap = selection.selectAll('.panewrap')
.data([0]);

View File

@@ -14,7 +14,7 @@ iD.ui.preset.url = function(field) {
input.enter().append('input')
.attr('type', field.type)
.attr('id', 'preset-input-' + field.id)
.attr('placeholder', field.placeholder || '');
.attr('placeholder', field.placeholder());
input
.on('blur', change)

View File

@@ -12,7 +12,7 @@ iD.ui.preset.localized = function(field, context) {
.attr('type', 'text')
.attr('id', 'preset-input-' + field.id)
.attr('class', 'localized-main')
.attr('placeholder', field.placeholder || '');
.attr('placeholder', field.placeholder());
input
.on('blur', change)
@@ -40,6 +40,7 @@ iD.ui.preset.localized = function(field, context) {
}
function addBlank() {
d3.event.preventDefault();
var data = localizedInputs.selectAll('div.entry').data();
data.push({ lang: '', value: '' });
localizedInputs.call(render, data);

View File

@@ -9,7 +9,7 @@ iD.ui.preset.textarea = function(field) {
input.enter().append('textarea')
.attr('id', 'preset-input-' + field.id)
.attr('placeholder', field.placeholder || '')
.attr('placeholder', field.placeholder())
.attr('maxlength', 255);
input

View File

@@ -19,10 +19,21 @@ function t(s, o, loc) {
if (o) for (var k in o) rep = rep.replace('{' + k + '}', o[k]);
return rep;
} else {
var missing = 'Missing translation: ' + s;
if (typeof console !== "undefined") console.error(missing);
if (loc !== 'en') return t(s, o, 'en');
if (o && 'default' in o) return o['default'];
return missing;
function missing() {
var missing = 'Missing ' + loc + ' translation: ' + s;
if (typeof console !== "undefined") console.error(missing);
return missing;
}
if (loc !== 'en') {
missing();
return t(s, o, 'en');
}
if (o && 'default' in o) {
return o['default'];
}
return missing();
}
}

View File

@@ -64,7 +64,7 @@ describe("iD.behavior.Hover", function() {
it("replaces the .hover class with .hover-suppressed", function () {
container.append('span').attr('class', 'hover');
container.call(iD.behavior.Hover().altDisables(true));
container.call(iD.behavior.Hover(context).altDisables(true));
happen.keydown(document, {keyCode: 18});
expect(container.selectAll('.hover')[0]).to.have.length(0);
@@ -76,7 +76,7 @@ describe("iD.behavior.Hover", function() {
it("replaces the .hover-suppressed class with .hover", function () {
container.append('span').attr('class', 'hover-suppressed');
container.call(iD.behavior.Hover().altDisables(true));
container.call(iD.behavior.Hover(context).altDisables(true));
happen.keyup(document, {keyCode: 18});
expect(container.selectAll('.hover')[0]).to.have.length(1);

View File

@@ -1,38 +1,29 @@
describe('iD.ui.RawTagEditor', function() {
var taglist, element,
tags = {highway: 'residential'},
entity, context;
function render() {
taglist = iD.ui.RawTagEditor(context, entity);
function render(tags) {
taglist = iD.ui.RawTagEditor(context)
.entityID(entity.id)
.preset({isFallback: function() { return false; }})
.tags(tags);
element = d3.select('body')
.append('div')
.call(taglist);
taglist.tags(entity.tags);
}
beforeEach(function () {
entity = iD.Entity({type: 'node', id: "n12345", tags: tags});
entity = iD.Node({id: "n12345"});
context = iD();
render();
context.history().merge({n12345: entity});
render({highway: 'residential'});
});
afterEach(function () {
element.remove();
});
describe("#tags", function () {
it("returns the current tags", function () {
expect(taglist.tags()).to.eql(tags);
});
it("returns updated tags when input values have changed", function () {
element.selectAll("input.key").property('value', 'k');
element.selectAll("input.value").property('value', 'v');
expect(taglist.tags()).to.eql({k: 'v'});
});
});
it("creates input elements for each key-value pair", function () {
expect(element.selectAll("input[value=highway]")).not.to.be.empty;
expect(element.selectAll("input[value=residential]")).not.to.be.empty;
@@ -40,8 +31,7 @@ describe('iD.ui.RawTagEditor', function() {
it("creates a pair of empty input elements if the entity has no tags", function () {
element.remove();
entity = entity.update({tags: {}});
render();
render({});
expect(element.select('.tag-list').selectAll("input.value").property('value')).to.be.empty;
expect(element.select('.tag-list').selectAll("input.key").property('value')).to.be.empty;
});
@@ -52,9 +42,12 @@ describe('iD.ui.RawTagEditor', function() {
expect(element.select('.tag-list').selectAll("input")[0][3].value).to.be.empty;
});
it("removes tags when clicking the remove button", function () {
it("removes tags when clicking the remove button", function (done) {
taglist.on('change', function(tags) {
expect(tags).to.eql({highway: undefined});
done();
});
element.selectAll("button.remove").trigger('click');
expect(taglist.tags()).to.eql({});
});
it("adds tags when pressing the TAB key on last input.value", function () {