UNPKG

angular2-schema-form

Version:

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

83 lines (82 loc) 3.43 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { PropertyGroup } from './formproperty'; var ObjectProperty = (function (_super) { __extends(ObjectProperty, _super); function ObjectProperty(formPropertyFactory, schemaValidatorFactory, validatorRegistry, schema, parent, path) { var _this = _super.call(this, schemaValidatorFactory, validatorRegistry, schema, parent, path) || this; _this.formPropertyFactory = formPropertyFactory; _this.propertiesId = []; _this.createProperties(); return _this; } ObjectProperty.prototype.setValue = function (value, onlySelf) { for (var propertyId in value) { if (value.hasOwnProperty(propertyId)) { this.properties[propertyId].setValue(value[propertyId], true); } } this.updateValueAndValidity(onlySelf, true); }; ObjectProperty.prototype.reset = function (value, onlySelf) { if (onlySelf === void 0) { onlySelf = true; } value = value || this.schema.default || {}; this.resetProperties(value); this.updateValueAndValidity(onlySelf, true); }; ObjectProperty.prototype.resetProperties = function (value) { for (var propertyId in this.schema.properties) { if (this.schema.properties.hasOwnProperty(propertyId)) { this.properties[propertyId].reset(value[propertyId], true); } } }; ObjectProperty.prototype.createProperties = function () { this.properties = {}; this.propertiesId = []; for (var propertyId in this.schema.properties) { if (this.schema.properties.hasOwnProperty(propertyId)) { var propertySchema = this.schema.properties[propertyId]; this.properties[propertyId] = this.formPropertyFactory.createProperty(propertySchema, this, propertyId); this.propertiesId.push(propertyId); } } }; ObjectProperty.prototype._hasValue = function () { return !!Object.keys(this.value).length; }; ObjectProperty.prototype._updateValue = function () { this.reduceValue(); }; ObjectProperty.prototype._runValidation = function () { var _this = this; _super.prototype._runValidation.call(this); if (this._errors) { this._errors.forEach(function (error) { var prop = _this.searchProperty(error.path.slice(1)); if (prop) { prop.extendErrors(error); } }); } }; ObjectProperty.prototype.reduceValue = function () { var value = {}; this.forEachChild(function (property, propertyId) { if (property.visible && property._hasValue()) { value[propertyId] = property.value; } }); this._value = value; }; return ObjectProperty; }(PropertyGroup)); export { ObjectProperty };