'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI * (C) Copyright IBM Corp. 2017 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['gemini/lib/@waca/dashboard-common/dist/core/Collection', './EpisodeActEntry'], function (Collection, EpisodeActEntry) { var EpisodeActs; EpisodeActs = Collection.extend({ modelClass: EpisodeActEntry, init: function init() { EpisodeActs.inherited('init', this, arguments); }, /* * A highlight payload is an array of columns. * This method updates the array to add or remove columns based on the exemplar provided * * Columns in payload and not in blankPayloadExemplar are removed * Columns in payloadEntryExemplar and not in paload are added. * * @param {Object} blankPayloadExemplar blank in the sense that it contains the default 'includes all' highlight * { * columnId: id of the column * // other properties we should not look at here. like values * } */ updateHighlightPayloadColumns: function updateHighlightPayloadColumns(blankPayloadExemplar, options) { options = options || {}; var values = []; var prevValues = []; this.filter(function (act) { return act.action === 'highlight'; }).forEach(function (act) { // copy the array so that we can do a correct undo/redo operation later. // I.e we only change the copy. var payloadCopy = act.payload.slice(); var containsColumn = function containsColumn(array, columnId) { return array.find(function (entry) { return entry.columnId === columnId; }); }; // if it's in 'new' and not in 'existing' it needs to be added. blankPayloadExemplar.forEach(function (item) { if (!containsColumn(payloadCopy, item.columnId)) { // add a deep copy of the item since we might be adding it to multiple highlights. var itemCopy = JSON.parse(JSON.stringify(item)); payloadCopy.push(itemCopy); } }); // if it's in 'existing' and not in 'new' it needs to be removed. payloadCopy = payloadCopy.filter(function (item) { return containsColumn(blankPayloadExemplar, item.columnId); }); values.push({ id: act.id, payload: payloadCopy }); prevValues.push({ id: act.id, payload: act.payload }); }); //do we want a unique event? this._updateAndTriggerEvent('change:payload', values, prevValues, options); }, _updateAndTriggerEvent: function _updateAndTriggerEvent(name, values, prevValues, options) { // values should be an array of sub models (sub as in id and some properties) this.set(values, { remove: false, merge: true, silent: true }); var event = { name: name, eventName: name, collection: this, value: values, prevValue: prevValues, options: options, data: options.payloadData, sender: options.sender ? options.sender : this, senderContext: { applyFn: function (value, sender) { this.set(value, { remove: false, merge: true, silent: true }); this.trigger(name, Object.assign({}, options, { sender: sender })); }.bind(this) } }; this.trigger(name, event); } }); return EpisodeActs; }); //# sourceMappingURL=EpisodeActs.js.map