define('application/widgets/detail/series/seasoncarousel', [
'rofl/widgets/carousel',
'application/widgets/guide/pointerhorizontalcontainer',
'rofl/widgets/container',
'application/widgets/pointerselectablebutton',
'antie/widgets/carousel/strips/cullingstrip',
'antie/runtimecontext',
'antie/widgets/carousel/keyhandlers/activatefirsthandler',
'application/widgets/guide/horizontalcarouselaligner',
'rofl/lib/utils',
'application/formatters/vodasset',
'rofl/lib/l10n'
], function (
Carousel,
HorizontalList,
Container,
SelectableButton,
CullingStrip,
RuntimeContext,
KeyHandler,
Aligner,
Utils,
EpisodeFormatter,
L10N
) {
'use strict';
var layout = RuntimeContext.getCurrentApplication().getLayout(),
l10n = L10N.getInstance();
return HorizontalList.extend({
/**
* Initialises the widget.
*/
init: function init () {
init.base.call(this);
},
/**
* Builds the widget.
*
* @private
*/
_build: function () {
var carousel = this._carousel = this._createCarousel();
this.appendChildWidget(carousel);
},
/**
* Creates the carousel.
*
* @returns {Object} - The carousel.
* @private
*/
_createCarousel: function () {
var carousel = this._carousel = new Carousel('', Carousel.orientations.HORIZONTAL),
keyHandler = new KeyHandler(),
aligner = new Aligner(carousel.getMask());
aligner.setNumberOfItemsVisibleOnScreen(3);
carousel.setWidgetStrip(CullingStrip);
carousel.setMaskLength(layout.seasons.carouselWidth);
carousel.setAligner(aligner);
carousel.setContinuousListener(true);
keyHandler.setAnimationOptions({
duration: 300,
easing: 'easeInOut',
fps: 60,
skipAnim: false
});
keyHandler.attach(carousel);
this.appendChildWidget(carousel);
return carousel;
},
/**
* Sets the data item.
*
* @param {Object} items - The items.
*/
setDataItem: function (items) {
var carousel = this._carousel,
episodeFormatter,
formatterParams;
if (carousel.getChildWidgetCount()) {
carousel.alignToIndex(0, {skipAnim: true});
}
carousel.removeAll();
Utils.each(items, function (item) {
var year = item.getYear(),
duration = item.getDuration(),
durationText = '',
minutes,
hours;
hours = Math.floor(duration / 3600);
duration = duration - hours * 3600;
minutes = Math.floor(duration / 60);
if (hours) {
durationText += hours + l10n.get('hours') + ' ';
}
if (minutes) {
durationText += minutes + l10n.get('minutes');
}
episodeFormatter = new EpisodeFormatter();
formatterParams = {
subTitle: year + ' | ' + durationText,
gradient: true,
width: layout.seasons.assetWidth,
height: layout.seasons.assetHeight
};
carousel.append(episodeFormatter.format(item, formatterParams), layout.seasons.assetWidth);
});
},
/**
* Overrides pointerhorizontalcontainer's onSelect method so that detail series can manage the event.
**/
_onSelect: function () {
},
/**
* Returns the carousel.
*
* @returns {Object} - The carousel.
*/
getCarousel: function () {
return this._carousel;
}
});
});