define('application/components/modals/bingewatching', [
'application/components/modals/abstract',
'rofl/widgets/container',
'rofl/widgets/label',
'rofl/lib/utils',
'application/widgets/detail/iconbutton',
'rofl/widgets/verticallist',
'application/widgets/bingewatch',
'antie/events/keyevent',
'rofl/analytics/web/google'
], function (
Abstract,
Container,
Label,
Utils,
Button,
VerticalList,
Bingewatch,
KeyEvent,
GoogleAnaltyics
) {
'use strict';
var GA = GoogleAnaltyics.getInstance();
return Abstract.extend({
/**
* Initialises the component.
*/
init: function init () {
this._callbackBound = Utils.bind(this._onTimeout, this);
init.base.call(this, 'bingewatch');
},
/**
* Builds the component.
*
* @private
*/
_createModal: function () {
this._list = this.appendChildWidget(new VerticalList());
this._bingewatchCountdown = this._list.appendChildWidget(new Bingewatch({
callback: this._callbackBound
}));
},
/**
* Keydown event.
*
* @param {Object} e - The event data.
* @private
*/
_onKeyDown: function (e) {
e.preventDefault();
e.stopPropagation();
switch (e.keyCode) {
case KeyEvent.VK_BACK:
this._back();
break;
case KeyEvent.VK_LEFT:
this._backButton.focus();
break;
case KeyEvent.VK_RIGHT:
this._bingewatchCountdown.focus();
break;
}
},
/**
* Select event.
*
* @param {Object} e - The event data.
* @private
*/
_onSelect: function (e) {
var target = e.target;
if (target.id === 'back-button') {
this._back();
} else if (target.id === 'binge') {
this._bingewatchCountdown.stop();
this._onTimeout();
}
},
/**
* BeforeShow event.
*
* @param {Object} e - The event data.
*/
onBeforeShow: function (e) {
var episode = e.args.episode;
this._cancelCallback = e.args.cancelCallback;
this._successCallback = e.args.successCallback;
this._episode = episode;
this._bingewatchCountdown.focus();
this._bingewatchCountdown.setEpisode(episode);
},
/**
* AfterShow event.
*/
onAfterShow: function () {
this._bingewatchCountdown.start();
},
/**
* Bingewatch countdown timeout.
*
* @private
*/
_onTimeout: function () {
GA.onEvent('Action', 'Bingewatching', {
eventLabel: 'Play'
});
this.parentWidget.back();
if (this._successCallback) {
this._successCallback(this._episode);
}
},
/**
* Back functionality.
*
* @private
*/
_back: function () {
GA.onEvent('Action', 'Bingewatching', {
eventLabel: 'Return'
});
this._bingewatchCountdown.stop();
this.parentWidget.back();
this._cancelCallback();
}
});
});