123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Storytelling
- * (C) Copyright IBM Corp. 2017, 2018
- * 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/Model', './EpisodeActs', 'underscore'], function (Model, EpisodeActs, _) {
- var TimelineEpisodeEntry = Model.extend({
- nestedCollections: { acts: EpisodeActs },
- whitelistAttrs: ['id', 'type', 'title', 'acts'],
- _default_entrance: {
- timer: 0,
- action: 'show'
- },
- _default_exit: {
- timer: 5000,
- action: 'hide'
- },
- //should match _endBufferTime in TimeQueue
- _endBufferTime: 200,
- init: function init() {
- TimelineEpisodeEntry.inherited('init', this, arguments);
- //we don't allow empty episodes so we silently add the default entry and exit acts.
- if (!this.acts) {
- this.set({
- 'acts': [this._default_entrance, this._default_exit]
- }, { silent: true });
- }
- },
- // Note that callers must go through TimelineController.updateTimelineDuration
- // if they do not desire the model updates to be silent.
- // The latter was optimized to trigger the necessary events once for the
- // whole collection rather than once per updated act timer.
- updateDuration: function updateDuration(start, end, options) {
- // we enforce _endBufferTime to be the minimum duration.
- // also we prevent the end from getting to be before the start.
- if (end <= start + this._endBufferTime) {
- end = start + this._endBufferTime;
- }
- options = _.clone(options) || {};
- _.extend(options, {
- 'add': false,
- 'remove': false,
- 'merge': true,
- 'silent': true
- });
- var entranceAct = this.getEntranceAct();
- var exitAct = this.getExitAct();
- var acts = [];
- this.acts.each(function (act) {
- var timer = act.timer;
- if (act.id === entranceAct.id) {
- timer = start < 0 ? 0 : start;
- } else if (act.id === exitAct.id) {
- timer = end;
- } else {
- // if the duration is the same (I.e we are moving things) we attempt to preserve the relative positions
- if (options.isMove) {
- timer = act.timer - entranceAct.timer + start;
- }
- // limit the non end/start values to be within the end/start
- timer = Math.max(timer, start + 1);
- timer = Math.min(timer, end - 1);
- }
- acts.push({
- id: act.id,
- timer: timer
- });
- });
- this.acts.set(acts, options);
- },
- getEntranceAct: function getEntranceAct() {
- return this.acts.min(function (act) {
- return act.timer;
- });
- },
- getExitAct: function getExitAct() {
- return this.acts.max(function (act) {
- return act.timer;
- });
- },
- getDuration: function getDuration() {
- return this.getExitAct().timer - this.getEntranceAct().timer;
- },
- touchesEnd: function touchesEnd(duration) {
- // Touches the end if the exit act is within _endBufferTime of duration.
- return duration - this._endBufferTime < this.getExitAct().timer;
- },
- touchesStart: function touchesStart() {
- // Touches the start if the entrance act is within _endBufferTime of the start
- return this.getEntranceAct().timer - this._endBufferTime < 0;
- }
- });
- return TimelineEpisodeEntry;
- });
- //# sourceMappingURL=TimelineEpisodeEntry.js.map
|