Files
iD/modules/presets/field.js
Bryan Housel 0fe766d9a4 WIP on external presets
- preset data is no longer bundled into iD.js
- some code pathways commented out re: external presets
- many changes so that tests can run without presets at start, or async
- still need to make sure fallbacks are always there (point, line, area, etc)
2020-02-05 09:38:26 -05:00

34 lines
1.0 KiB
JavaScript

import { t } from '../util/locale';
import { utilSafeClassName } from '../util/util';
export function presetField(fieldID, field) {
let _this = Object.assign({}, field); // shallow copy
_this.id = fieldID;
// for use in classes, element ids, css selectors
_this.safeid = utilSafeClassName(fieldID);
_this.matchGeometry = (geom) => !_this.geometry || _this.geometry === geom;
_this.matchAllGeometry = (geometries) => {
return !_this.geometry || geometries.every(geom => _this.geometry.indexOf(geom) !== -1);
};
_this.t = (scope, options) => t(`presets.fields.${fieldID}.${scope}`, options);
_this.label = () => _this.overrideLabel || _this.t('label', { 'default': fieldID });
const _placeholder = _this.placeholder;
_this.placeholder = () => _this.t('placeholder', { 'default': _placeholder });
_this.originalTerms = (_this.terms || []).join();
_this.terms = () => _this.t('terms', { 'default': _this.originalTerms })
.toLowerCase().trim().split(/\s*,+\s*/);
return _this;
}