"use strict"; /** * Value object for event item. * * @author Igor Samulenko * @constructor */ function EventVO() { // simple fields this.messageId = ''; this.eventType = ''; this.labelTemplate = ''; this.title = ''; this.priority = ''; this.startDate = null; this.endDate = null; this.summary = ''; this.description = ''; this.classId = ''; // complex fields this.entities = []; this.recipients = []; } /** * Setup inheritance chain. */ EventVO.prototype = Object.create(BaseVO.prototype); EventVO.prototype.constructor = EventVO; /** * Constants section. * Read-only state will be enforced later. */ EventVO.prototype.INCIDENT_CREATE = 'incident-create'; EventVO.prototype.PRIORITY_CHANGE = 'priority-change'; EventVO.prototype.STATUS_CHANGE = 'status-change'; EventVO.prototype.SLA_CHANGE = 'sla-change'; EventVO.prototype.SLA_MET = 'sla-met'; EventVO.prototype.OUTAGE_CHANGE = 'outage-change'; EventVO.prototype.ASSIGNMENT_CHANGE = 'assignment-change'; EventVO.prototype.GENERIC_UPDATE = 'generic-update'; EventVO.prototype.EMAIL = 'email-worknote'; EventVO.prototype.RICH_EMAIL = 'email-richText-worknote'; EventVO.prototype.FLAG = 'ka-flagged'; EventVO.prototype.UNFLAG = 'ka-unflagged'; EventVO.prototype.RELATED_CHANGE = 'related-change'; EventVO.prototype.UNRELATED_CHANGE = 'unrelated-change'; EventVO.prototype.LOCATION_CHANGE = 'region-change'; EventVO.prototype.OWNERSHIP_CHANGE = 'ownership-change'; EventVO.prototype.VENDOR_CREATE_ITSM_TICKET = 'vendor-create-itsm-ticket'; EventVO.prototype.VENDOR_CREATE = 'vendor-create'; EventVO.prototype.VENDOR_CREATE_V2 = 'vendor-create-v2'; EventVO.prototype.VENDOR_NOTE = 'vendor-note'; EventVO.prototype.VENDOR_NOTE_V2 = 'vendor-note-v2'; EventVO.prototype.VENDOR_STATUS_CHANGE = 'vendor-status-change'; EventVO.prototype.VENDOR_STATUS_CHANGE_V2 = 'vendor-status-change-v2'; EventVO.prototype.TASK_RELATION = 'task-relation'; EventVO.prototype.TASK_MANUAL = 'Manual'; EventVO.prototype.TASK_AUTOMATIC = 'Automatic'; /** * @override * @return {Array} */ EventVO.prototype.getProps = function () { return BaseVO.prototype.getProps().concat('messageId', 'eventType', 'labelTemplate', 'title', 'priority', 'startDate', 'endDate', 'entities', 'recipients', 'summary', 'description', 'classId'); }; /** * @override */ EventVO.prototype.postBuild = function () { this.entities = this.entities.map(function (item) { return new EntityVO().build(item); }); this.recipients = this.recipients.map(function (item) { return new EntityVO().build(item); }); // server sends this value in seconds if (this.startDate) { this.startDate = new Date(this.startDate * 1000); this.startDateHumanized = moment(this.startDate).calendar(); } // server sends this value in seconds if (this.endDate) { this.endDate = new Date(this.endDate * 1000); this.endDateHumanized = moment(this.endDate).calendar(); } }; /** * Returns true if item is a SLA change event. * @returns {Boolean} */ EventVO.prototype.isSlaChange = function () { return this.eventType === EventVO.prototype.SLA_CHANGE; }; /** * Returns true if item is a SLA met event. * @returns {Boolean} */ EventVO.prototype.isSlaMet = function () { return this.eventType === EventVO.prototype.SLA_MET; }; /** * Returns class specifier for feed item. * For ex., 'priority-change-high' * * @param {String} entityType * @returns {String} */ EventVO.prototype.getEventSpecifier = function () { var specifier = this.eventType; var filteredEntities = this.entities.filter(function (item) { return specifier.indexOf(item.type) > -1; }); if (filteredEntities.length) { specifier += '-' + filteredEntities[0].entityId; } return specifier; };