kentico-cloud-delivery
Version:
Official Kentico Cloud Delivery SDK
221 lines • 8.03 kB
JavaScript
"use strict";
exports.__esModule = true;
var field_models_1 = require("./field-models");
var field_type_1 = require("./field-type");
var Fields;
(function (Fields) {
var TextField = /** @class */ (function () {
/**
* Represents text field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {string} value - Value of the field
*/
function TextField(name, value) {
this.name = name;
this.value = value;
/**
* Type of the field
*/
this.type = field_type_1.FieldType.Text;
this.text = this.value;
}
return TextField;
}());
Fields.TextField = TextField;
var MultipleChoiceField = /** @class */ (function () {
/**
* Represents multiple choice field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {string} value - Value of the field
*/
function MultipleChoiceField(name, value) {
var _this = this;
this.name = name;
this.value = value;
/**
* Multiple choice options
*/
this.options = [];
/**
* Type of the field
*/
this.type = field_type_1.FieldType.MultipleChoice;
if (this.value && Array.isArray(this.value)) {
this.value.forEach(function (option) {
var optionTemp = option;
_this.options.push(new field_models_1.FieldModels.MultipleChoiceOption(optionTemp.name, optionTemp.codename));
});
}
}
return MultipleChoiceField;
}());
Fields.MultipleChoiceField = MultipleChoiceField;
var DateTimeField = /** @class */ (function () {
/**
* Represents date time field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {string} value - Value of the field
*/
function DateTimeField(name, value) {
this.name = name;
this.value = value;
/**
* Type of the field
*/
this.type = field_type_1.FieldType.DateTime;
this.datetime = new Date(value);
}
return DateTimeField;
}());
Fields.DateTimeField = DateTimeField;
var RichTextField = /** @class */ (function () {
/**
* Represents rich text field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {string} value - Value of the field
* @param {() => string} resolveHtml - Function that resolves HTML
* @param {Link[]} links - Links for this rich text field
*/
function RichTextField(name, value, data) {
this.name = name;
this.value = value;
/**
* Type of the field
*/
this.type = field_type_1.FieldType.RichText;
/**
* Links
*/
this.links = [];
Object.assign(this, data);
}
RichTextField.prototype.getHtml = function () {
// check if html was already resolved
if (this.resolvedHtml) {
return this.resolvedHtml;
}
this.resolvedHtml = this.resolveHtml();
return this.resolvedHtml;
};
return RichTextField;
}());
Fields.RichTextField = RichTextField;
var NumberField = /** @class */ (function () {
/**
* Represents number field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {string} value - Value of the field
*/
function NumberField(name, value) {
this.name = name;
this.value = value;
/**
* Type of the field
*/
this.type = field_type_1.FieldType.Number;
this.number = value;
}
return NumberField;
}());
Fields.NumberField = NumberField;
var AssetsField = /** @class */ (function () {
/**
* Represents asset field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {any} value - Value of the field
*/
function AssetsField(name, value) {
var _this = this;
this.name = name;
this.value = value;
/**
* Type of the field
*/
this.type = field_type_1.FieldType.Asset;
/**
* List of assets used in this field
*/
this.assets = [];
if (!value) {
throw Error("Cannot bind assets field because no value was provided");
}
if (!Array.isArray(value)) {
throw Error("Cannot bind assets because the provided value is not an array");
}
this.value.forEach(function (asset) {
_this.assets.push(new field_models_1.FieldModels.AssetModel(asset.name, asset.type, asset.size, asset.description, asset.url));
});
}
return AssetsField;
}());
Fields.AssetsField = AssetsField;
var UrlSlugField = /** @class */ (function () {
/**
* Represents URL slug field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {string} value - Value of the field
* @param {() => string | undefined} resolveUrl - Function to get url of the link
*/
function UrlSlugField(name, value, data) {
this.name = name;
this.value = value;
/**
* Type of the field
*/
this.type = field_type_1.FieldType.UrlSlug;
Object.assign(this, data);
}
UrlSlugField.prototype.getUrl = function () {
if (this.resolvedUrl) {
return this.resolvedUrl;
}
this.resolvedUrl = this.resolveUrl();
return this.resolvedUrl;
};
return UrlSlugField;
}());
Fields.UrlSlugField = UrlSlugField;
var TaxonomyField = /** @class */ (function () {
/**
* Represents number field of Kentico Cloud item
* @constructor
* @param {string} name - Name of the field
* @param {string} value - Value of the field
* @param {string | undefined} taxonomyGroup - Codename of the taxonomy group
*/
function TaxonomyField(name, value, taxonomyGroup) {
var _this = this;
this.name = name;
this.value = value;
this.taxonomyGroup = taxonomyGroup;
/**
* Type of the field
*/
this.type = field_type_1.FieldType.Taxonomy;
/**
* List of assigned taxonomy terms
*/
this.taxonomyTerms = [];
if (!value) {
throw Error("Cannot map taxonomy field because no value was provided");
}
if (!Array.isArray(value)) {
throw Error("Cannot get taxonomy field because the provided value is not an array");
}
var taxonomyList = value;
taxonomyList.forEach(function (term) {
_this.taxonomyTerms.push(new field_models_1.FieldModels.TaxonomyTerm(term.name, term.codename));
});
}
return TaxonomyField;
}());
Fields.TaxonomyField = TaxonomyField;
})(Fields = exports.Fields || (exports.Fields = {}));
//# sourceMappingURL=field-types.js.map