"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FieldSettings = require("./FieldSettings");
class ControlSchema {
}
exports.ControlSchema = ControlSchema;
class ControlMapper {
constructor(_repository, ControlBaseType, _clientControlSettingsFactory, _defaultControlType, _defaultFieldSettingControlType) {
this._repository = _repository;
this.ControlBaseType = ControlBaseType;
this._clientControlSettingsFactory = _clientControlSettingsFactory;
this._defaultControlType = _defaultControlType;
this._defaultFieldSettingControlType = _defaultFieldSettingControlType;
this._contentTypeControlMaps = [];
this._fieldSettingDefaults = [];
this._contentTypeBoundfieldSettings = [];
this._fieldSettingBoundClientSettingFactories = [];
}
getTypeSchema(contentType, actionName) {
const schema = this._repository.GetSchema(contentType);
if (actionName) {
schema.FieldSettings = schema.FieldSettings.filter((s) => {
switch (actionName) {
case 'new':
return s.VisibleNew === FieldSettings.FieldVisibility.Show;
case 'edit':
return s.VisibleEdit === FieldSettings.FieldVisibility.Show;
case 'view':
return s.VisibleBrowse === FieldSettings.FieldVisibility.Show;
}
});
}
return schema;
}
MapContentTypeToControl(contentType, control) {
this._contentTypeControlMaps[contentType.name] = control;
return this;
}
GetControlForContentType(contentType) {
return this._contentTypeControlMaps[contentType.name] || this._defaultControlType;
}
SetupFieldSettingDefault(fieldSetting, setupControl) {
this._fieldSettingDefaults[fieldSetting.name] = setupControl;
return this;
}
GetControlForFieldSetting(fieldSetting) {
const fieldSettingSetup = this._fieldSettingDefaults[fieldSetting.Type];
return fieldSettingSetup && fieldSettingSetup(fieldSetting) || this._defaultFieldSettingControlType;
}
SetupFieldSettingForControl(contentType, fieldName, setupControl, fieldSetting) {
this._contentTypeBoundfieldSettings[`${contentType.name}-${fieldName}`] = setupControl;
return this;
}
GetControlForContentField(contentType, fieldName, actionName) {
const fieldSetting = this.getTypeSchema(contentType, actionName).FieldSettings.filter((s) => s.Name === fieldName)[0];
if (this._contentTypeBoundfieldSettings[`${contentType.name}-${fieldName}`]) {
return this._contentTypeBoundfieldSettings[`${contentType.name}-${fieldName}`](fieldSetting);
}
else {
return this.GetControlForFieldSetting(fieldSetting);
}
}
SetClientControlFactory(fieldSettingType, factoryMethod) {
this._fieldSettingBoundClientSettingFactories[fieldSettingType.name] = factoryMethod;
return this;
}
CreateClientSetting(fieldSetting) {
const factoryMethod = this._fieldSettingBoundClientSettingFactories[fieldSetting.Type] || this._clientControlSettingsFactory;
return factoryMethod(fieldSetting);
}
GetFullSchemaForContentType(contentType, actionName) {
const schema = this.getTypeSchema(contentType, actionName);
const mappings = schema.FieldSettings.map((f) => {
const clientSetting = this.CreateClientSetting(f);
const control = this.GetControlForContentField(contentType, f.Name, actionName);
return {
FieldSettings: f,
ClientSettings: clientSetting,
ControlType: control
};
});
return {
Schema: schema,
ContentTypeControl: this.GetControlForContentType(contentType),
FieldMappings: mappings
};
}
GetFullSchemaForContent(content, actionName) {
return this.GetFullSchemaForContentType(content.constructor, actionName);
}
}
exports.ControlMapper = ControlMapper;
//# sourceMappingURL=ControlMapper.js.map |