mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Add reverser button to onewayCheck field
This commit is contained in:
+46
-10
@@ -1,12 +1,14 @@
|
||||
import * as d3 from 'd3';
|
||||
import { utilRebind } from '../../util/rebind';
|
||||
import { t } from '../../util/locale';
|
||||
import { osmOneWayTags } from '../../osm/index';
|
||||
import { actionReverse } from '../../actions';
|
||||
import { osmOneWayTags } from '../../osm';
|
||||
|
||||
export { uiFieldCheck as uiFieldDefaultCheck };
|
||||
export { uiFieldCheck as uiFieldOnewayCheck };
|
||||
|
||||
|
||||
export function uiFieldCheck(field) {
|
||||
export function uiFieldCheck(field, context) {
|
||||
var dispatch = d3.dispatch('change'),
|
||||
options = field.strings && field.strings.options,
|
||||
values = [],
|
||||
@@ -14,7 +16,10 @@ export function uiFieldCheck(field) {
|
||||
input = d3.select(null),
|
||||
text = d3.select(null),
|
||||
label = d3.select(null),
|
||||
entity, value;
|
||||
reverser = d3.select(null),
|
||||
impliedYes = (field.id === 'oneway_yes'),
|
||||
entity,
|
||||
value;
|
||||
|
||||
if (options) {
|
||||
for (var k in options) {
|
||||
@@ -24,7 +29,7 @@ export function uiFieldCheck(field) {
|
||||
} else {
|
||||
values = [undefined, 'yes'];
|
||||
texts = [t('inspector.unknown'), t('inspector.check.yes')];
|
||||
if (field.type === 'check') {
|
||||
if (field.type !== 'defaultCheck') {
|
||||
values.push('no');
|
||||
texts.push(t('inspector.check.no'));
|
||||
}
|
||||
@@ -32,11 +37,12 @@ export function uiFieldCheck(field) {
|
||||
|
||||
|
||||
var check = function(selection) {
|
||||
// hack: pretend oneway field is a oneway_yes field
|
||||
// hack: pretend `oneway` field is a `oneway_yes` field
|
||||
// where implied oneway tag exists (e.g. `junction=roundabout`) #2220, #1841
|
||||
if (field.id === 'oneway') {
|
||||
for (var key in entity.tags) {
|
||||
if (key in osmOneWayTags && (entity.tags[key] in osmOneWayTags[key])) {
|
||||
impliedYes = true;
|
||||
texts[0] = t('presets.fields.oneway_yes.options.undefined');
|
||||
break;
|
||||
}
|
||||
@@ -54,7 +60,7 @@ export function uiFieldCheck(field) {
|
||||
|
||||
enter
|
||||
.append('input')
|
||||
.property('indeterminate', field.type === 'check')
|
||||
.property('indeterminate', field.type !== 'defaultCheck')
|
||||
.attr('type', 'checkbox')
|
||||
.attr('id', 'preset-input-' + field.id);
|
||||
|
||||
@@ -63,9 +69,20 @@ export function uiFieldCheck(field) {
|
||||
.text(texts[0])
|
||||
.attr('class', 'value');
|
||||
|
||||
if (field.type === 'onewayCheck') {
|
||||
var isHidden = !(value === 'yes' || (impliedYes && !value));
|
||||
enter
|
||||
.append('a')
|
||||
.attr('id', 'preset-input-' + field.id + '-reverser')
|
||||
.attr('class', 'reverser button' + (isHidden ? ' hide' : ''))
|
||||
.text(t('inspector.check.reverser'))
|
||||
.attr('href', '#');
|
||||
}
|
||||
|
||||
label = label.merge(enter);
|
||||
input = label.selectAll('input');
|
||||
text = label.selectAll('span.value');
|
||||
reverser = label.selectAll('.reverser');
|
||||
|
||||
input
|
||||
.on('click', function() {
|
||||
@@ -74,6 +91,16 @@ export function uiFieldCheck(field) {
|
||||
dispatch.call('change', this, t);
|
||||
d3.event.stopPropagation();
|
||||
});
|
||||
|
||||
reverser
|
||||
.on('click', function() {
|
||||
d3.event.preventDefault();
|
||||
d3.event.stopPropagation();
|
||||
context.perform(
|
||||
actionReverse(entity.id),
|
||||
t('operations.reverse.annotation')
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -86,10 +113,19 @@ export function uiFieldCheck(field) {
|
||||
|
||||
check.tags = function(tags) {
|
||||
value = tags[field.key];
|
||||
input.property('indeterminate', field.type === 'check' && !value);
|
||||
input.property('checked', value === 'yes');
|
||||
text.text(texts[values.indexOf(value)]);
|
||||
label.classed('set', !!value);
|
||||
|
||||
input
|
||||
.property('indeterminate', field.type !== 'defaultCheck' && !value)
|
||||
.property('checked', value === 'yes');
|
||||
|
||||
text
|
||||
.text(texts[values.indexOf(value)]);
|
||||
|
||||
label
|
||||
.classed('set', !!value);
|
||||
|
||||
reverser
|
||||
.classed('hide', !(value === 'yes' || (impliedYes && !value)));
|
||||
};
|
||||
|
||||
|
||||
|
||||
+13
-11
@@ -14,7 +14,8 @@ export * from './wikipedia';
|
||||
|
||||
import {
|
||||
uiFieldCheck,
|
||||
uiFieldDefaultCheck
|
||||
uiFieldDefaultCheck,
|
||||
uiFieldOnewayCheck
|
||||
} from './check';
|
||||
|
||||
import {
|
||||
@@ -47,22 +48,23 @@ export var uiFields = {
|
||||
access: uiFieldAccess,
|
||||
address: uiFieldAddress,
|
||||
check: uiFieldCheck,
|
||||
defaultCheck: uiFieldDefaultCheck,
|
||||
combo: uiFieldCombo,
|
||||
typeCombo: uiFieldTypeCombo,
|
||||
cycleway: uiFieldCycleway,
|
||||
defaultCheck: uiFieldDefaultCheck,
|
||||
email: uiFieldEmail,
|
||||
lanes: uiFieldLanes,
|
||||
localized: uiFieldLocalized,
|
||||
maxspeed: uiFieldMaxspeed,
|
||||
multiCombo: uiFieldMultiCombo,
|
||||
networkCombo: uiFieldNetworkCombo,
|
||||
cycleway: uiFieldCycleway,
|
||||
text: uiFieldText,
|
||||
url: uiFieldUrl,
|
||||
number: uiFieldNumber,
|
||||
email: uiFieldEmail,
|
||||
tel: uiFieldTel,
|
||||
localized: uiFieldLocalized,
|
||||
lanes: uiFieldLanes,
|
||||
maxspeed: uiFieldMaxspeed,
|
||||
onewayCheck: uiFieldOnewayCheck,
|
||||
radio: uiFieldRadio,
|
||||
restrictions: uiFieldRestrictions,
|
||||
tel: uiFieldTel,
|
||||
text: uiFieldText,
|
||||
textarea: uiFieldTextarea,
|
||||
typeCombo: uiFieldTypeCombo,
|
||||
url: uiFieldUrl,
|
||||
wikipedia: uiFieldWikipedia
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user