UNPKG

angular2-schema-form

Version:

Angular2 Schema Form (DISCLAIMER: it is not related to angular-schema-form)

72 lines (71 loc) 2.99 kB
import { PropertyGroup } from './formproperty'; import { NumberProperty } from './numberproperty'; import { StringProperty } from './stringproperty'; import { BooleanProperty } from './booleanproperty'; import { ObjectProperty } from './objectproperty'; import { ArrayProperty } from './arrayproperty'; var FormPropertyFactory = (function () { function FormPropertyFactory(schemaValidatorFactory, validatorRegistry) { this.schemaValidatorFactory = schemaValidatorFactory; this.validatorRegistry = validatorRegistry; } FormPropertyFactory.prototype.createProperty = function (schema, parent, propertyId) { if (parent === void 0) { parent = null; } var newProperty = null; var path = ''; if (parent) { path += parent.path; if (parent.parent !== null) { path += '/'; } if (parent.type === 'object') { path += propertyId; } else if (parent.type === 'array') { path += '*'; } else { throw 'Instanciation of a FormProperty with an unknown parent type: ' + parent.type; } } else { path = '/'; } if (schema.$ref) { var refSchema = this.schemaValidatorFactory.getSchema(parent.root.schema, schema.$ref); newProperty = this.createProperty(refSchema, parent, path); } else { switch (schema.type) { case 'integer': case 'number': newProperty = new NumberProperty(this.schemaValidatorFactory, this.validatorRegistry, schema, parent, path); break; case 'string': newProperty = new StringProperty(this.schemaValidatorFactory, this.validatorRegistry, schema, parent, path); break; case 'boolean': newProperty = new BooleanProperty(this.schemaValidatorFactory, this.validatorRegistry, schema, parent, path); break; case 'object': newProperty = new ObjectProperty(this, this.schemaValidatorFactory, this.validatorRegistry, schema, parent, path); break; case 'array': newProperty = new ArrayProperty(this, this.schemaValidatorFactory, this.validatorRegistry, schema, parent, path); break; default: throw new TypeError("Undefined type " + schema.type); } } if (newProperty instanceof PropertyGroup) { this.initializeRoot(newProperty); } return newProperty; }; FormPropertyFactory.prototype.initializeRoot = function (rootProperty) { rootProperty.reset(null, true); rootProperty._bindVisibility(); }; return FormPropertyFactory; }()); export { FormPropertyFactory };