"use strict"; /** * Value object for comment item. * * @author Igor Samulenko * @constructor */ function CommentVO() { this.message = ''; this.author = null; this.attachmentCount = 0; this.attachments = []; // derived fields this.title = ''; } /** * Setup inheritance chain. */ CommentVO.prototype = new BaseVO(); CommentVO.prototype.constructor = CommentVO; /** * @override * @return {Array} properties */ CommentVO.prototype.getProps = function () { return BaseVO.prototype.getProps().concat('message', 'author', 'attachmentCount', 'attachments'); }; /** * Returns true if item has attachments. * @returns {boolean} */ CommentVO.prototype.hasAttachments = function () { return this.attachmentCount > 0; }; CommentVO.prototype.postBuild = function () { this.author = new UserVO().build(this.author); this.title = this.author.getFullName(); // transform date to human readable string this.dateTitle = moment(this.createDate).calendar({ sameElse: 'lll' }); if (this.attachmentCount > 0) { this.attachments = this.attachments.map(function (item) { return new AttachmentVO().build(item); }); } };