uiField now dispatches own events

This commit is contained in:
Bryan Housel
2017-08-03 11:28:10 -04:00
parent 6fe1efaf35
commit 7076bcef16
2 changed files with 16 additions and 6 deletions
+5 -3
View File
@@ -4,10 +4,12 @@ import { textDirection } from '../util/locale';
import { svgIcon } from '../svg';
import { uiFields } from './fields';
import { uiTagReference } from './tag_reference';
import { utilRebind } from '../util';
export function uiField(context, dispatch, presetField, entity, show) {
var field = _.clone(presetField),
export function uiField(context, presetField, entity, show) {
var dispatch = d3.dispatch('change'),
field = _.clone(presetField),
tags;
@@ -157,6 +159,6 @@ export function uiField(context, dispatch, presetField, entity, show) {
};
return field;
return utilRebind(field, dispatch, 'on');
}
+11 -3
View File
@@ -47,24 +47,32 @@ export function uiPresetEditor(context) {
preset.fields.forEach(function(field) {
if (field.matchGeometry(geometry)) {
fieldsArr.push(
uiField(context, dispatch, field, entity, true).tags(tags)
uiField(context, field, entity, true)
);
}
});
if (entity.isHighwayIntersection(context.graph()) && presets.field('restrictions')) {
fieldsArr.push(
uiField(context, dispatch, presets.field('restrictions'), entity, true).tags(tags)
uiField(context, presets.field('restrictions'), entity, true)
);
}
presets.universal().forEach(function(field) {
if (preset.fields.indexOf(field) === -1) {
fieldsArr.push(
uiField(context, dispatch, field, entity).tags(tags)
uiField(context, field, entity)
);
}
});
fieldsArr.forEach(function(field) {
field
.tags(tags)
.on('change', function(t, onInput) {
dispatch.call('change', field, t, onInput);
});
});
}
var shown = fieldsArr.filter(function(field) { return field.isShown(); }),