Fix up defaultcheck field type

It now works as determinate checkbox, where a checked
state produces *=yes and an unchecked state produces no
tag.
This commit is contained in:
John Firebaugh
2014-04-15 16:30:21 -07:00
parent 7b958cc1eb
commit 95edc5ff03
4 changed files with 13 additions and 39 deletions

View File

@@ -63,9 +63,10 @@ In which `type` is the fields's type. Valid field types are
* textarea
* radio
* combo
* check
* address
* defaultcheck - a checkbox that can be yes, no, or null - not filled
* check - a tri-state checkbox: yes, no, or unknown (no tag)
* defaultcheck - a boolean checkbox where checked produces a `*=yes` tag and
unchecked produces no tag
The `key` property names the OSM key that the field will edit. Alternatively, for
compound fields like `address`, you can specify an array of keys in the `keys`

View File

@@ -114,7 +114,6 @@
<script src='js/id/ui/preset/address.js'></script>
<script src='js/id/ui/preset/check.js'></script>
<script src='js/id/ui/preset/combo.js'></script>
<script src='js/id/ui/preset/defaultcheck.js'></script>
<script src='js/id/ui/preset/input.js'></script>
<script src='js/id/ui/preset/localized.js'></script>
<script src='js/id/ui/preset/maxspeed.js'></script>

View File

@@ -1,6 +1,9 @@
iD.ui.preset.check = function(field) {
iD.ui.preset.check =
iD.ui.preset.defaultcheck = function(field) {
var event = d3.dispatch('change'),
values = [undefined, 'yes', 'no'],
values = field.type === 'check' ?
[undefined, 'yes', 'no'] :
[undefined, 'yes'],
value,
box,
text,
@@ -16,7 +19,7 @@ iD.ui.preset.check = function(field) {
.attr('class', 'preset-input-wrap');
enter.append('input')
.property('indeterminate', true)
.property('indeterminate', field.type === 'check')
.attr('type', 'checkbox')
.attr('id', 'preset-input-' + field.id);
@@ -27,7 +30,7 @@ iD.ui.preset.check = function(field) {
box = label.select('input')
.on('click', function() {
var t = {};
t[field.key] = values[(values.indexOf(value) + 1) % 3];
t[field.key] = values[(values.indexOf(value) + 1) % values.length];
event.change(t);
d3.event.stopPropagation();
});
@@ -37,9 +40,10 @@ iD.ui.preset.check = function(field) {
check.tags = function(tags) {
value = tags[field.key];
box.property('indeterminate', !value);
box.property('indeterminate', field.type === 'check' && !value);
box.property('checked', value === 'yes');
text.text(value ? t('inspector.check.' + value, {default: value}) : t('inspector.unknown'));
text.text(value ? t('inspector.check.' + value, {default: value}) :
field.type === 'check' ? t('inspector.unknown') : t('inspector.check.no'));
label.classed('set', !!value);
};

View File

@@ -1,30 +0,0 @@
iD.ui.preset.defaultcheck = function(field) {
var event = d3.dispatch('change'),
input;
function check(selection) {
input = selection.selectAll('input')
.data([0]);
input.enter().append('input')
.attr('type', 'checkbox')
.attr('id', 'preset-input-' + field.id);
input
.on('change', function() {
var t = {};
t[field.key] = input.property('checked') ? field.value || 'yes' : undefined;
event.change(t);
});
}
check.tags = function(tags) {
input.property('checked', !!tags[field.key] && tags[field.key] !== 'no');
};
check.focus = function() {
input.node().focus();
};
return d3.rebind(check, event, 'on');
};