UNPKG

idea-toolbox

Version:
75 lines (74 loc) 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AttachmentSections = exports.AttachmentSection = exports.Attachment = void 0; const label_model_1 = require("./label.model"); const resource_model_1 = require("./resource.model"); /** * An attachment to stick to an entity. */ class Attachment extends resource_model_1.Resource { load(x) { super.load(x); this.attachmentId = this.clean(x.attachmentId, String); this.name = this.clean(x.name, String); this.format = this.clean(x.format, String); } safeLoad(newData, safeData) { super.safeLoad(newData, safeData); this.attachmentId = safeData.attachmentId; this.format = safeData.format; } validate() { const e = super.validate(); if (this.iE(this.attachmentId)) e.push('attachmentId'); if (this.iE(this.name)) e.push('name'); if (this.iE(this.format)) e.push('format'); return e; } /** * Get the filename (`name.format`) of the attachment. */ getFilename() { return this.name.concat('.', this.format); } } exports.Attachment = Attachment; /** * A section to group a list of attachments. */ class AttachmentSection extends resource_model_1.Resource { load(x, languages) { super.load(x); this.name = new label_model_1.Label(x.name, languages); this.description = new label_model_1.Label(x.description, languages); this.attachments = this.cleanArray(x.attachments, a => new Attachment(a)); } validate(languages) { const e = super.validate(); if (this.name.validate(languages).length) e.push('name'); return e; } } exports.AttachmentSection = AttachmentSection; /** * A block of reorderable sections each containing a list of attachments. * Use it when you need to organize the attachments in sections or categories. */ class AttachmentSections extends resource_model_1.Resource { load(x, languages) { super.load(x, languages); this.sectionsLegend = this.cleanArray(x.sectionsLegend, String); this.sections = {}; this.sectionsLegend.forEach(s => (this.sections[s] = new AttachmentSection(x.sections[s], languages))); } validate(languages) { const e = super.validate(); this.sectionsLegend.forEach(s => this.sections[s].validate(languages).forEach(es => e.push(`${s}.${es}`))); return e; } } exports.AttachmentSections = AttachmentSections;