UNPKG

@signatu/policy

Version:
79 lines 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var PolicyElementType; (function (PolicyElementType) { PolicyElementType["Policy"] = "Policy"; PolicyElementType["PolicyTitle"] = "PolicyTitle"; PolicyElementType["PolicySection"] = "PolicySection"; PolicyElementType["PolicyClause"] = "PolicyClause"; PolicyElementType["PolicyClauseGroup"] = "PolicyClauseGroup"; PolicyElementType["PolicyController"] = "PolicyController"; PolicyElementType["PolicyDataProcessing"] = "PolicyDataProcessing"; })(PolicyElementType = exports.PolicyElementType || (exports.PolicyElementType = {})); var PolicyElement = /** @class */ (function () { function PolicyElement(type, masterText) { this.type = type; // Node interface this.parent = null; this.children = []; // Controlled English master text for the Policy Element. this.content = []; this.userInput = []; /** We use a get() property in PolicyDataProcessing, so we need to conditionally set this here */ if (masterText) { this.masterText = masterText; } } ; PolicyElement.prototype.getContentForLanguage = function (language) { return this.content.filter(function (c) { return c.language.equals(language); }); }; PolicyElement.prototype.addContent = function (content) { this.content.push(content); }; PolicyElement.prototype.addChild = function (element) { element.parent = this; this.children.push(element); }; // Traverse the tree and set the numbering id's for children PolicyElement.prototype.number = function (startId) { if (startId === void 0) { startId = "1"; } var prefix = startId; this.elementId = startId; this.children.forEach(function (e, idx) { e.number(prefix + "." + (idx + 1)); }); }; // Serialization. fromJSON() must be implemented in the extended classes PolicyElement.prototype.toJSON = function () { // console.log("processing", this); // We don't want to just copy the properties because the JSON format // is an interface and we cannot do interface changes without prope thought. var json = { elementId: this.elementId, masterText: this.masterText, type: this.type, ref: this.ref }; if (this.content.length > 0) { json.content = []; this.content.forEach(function (c) { json.content.push(c.toJSON()); }); } if (this.children.length > 0) { json.children = []; this.children.forEach(function (c) { json.children.push(c.toJSON()); }); } this.userInput.forEach(function (ui) { json.userInput = json.userInput || []; json.userInput.push(ui.toJSON()); }); return json; }; return PolicyElement; }()); exports.PolicyElement = PolicyElement; //# sourceMappingURL=policyElement.js.map