define('application/widgets/detail/tabs/seasons', [
'rofl/widgets/container',
'application/widgets/filters/button',
'rofl/widgets/verticallist',
'application/widgets/detail/series/seasoncarousel'
], function (
Container,
Button,
VerticalList,
SeasonCarousel
) {
'use strict';
return Container.extend({
/**
* Initialises the widget.
*
* @param {Object} [data] - The data. Optional.
* @param {Object} [params] - Additional params.
*/
init: function init (data, params) {
init.base.call(this);
this.addClass('seasons-tab');
this._build(params);
if (data) {
this.setDataItem(data);
}
},
/**
* Builds the widget.
*
* @param {Object} [params] - Additional params.
* @private
*/
_build: function (params) {
var list = new VerticalList(),
isDropdown = params && params.isDropDown,
button = this._button = new Button({
isDropDown: isDropdown,
text: ''
}),
seasonCarousel = this._carousel = new SeasonCarousel();
button.addClass('icon-button');
// Set selected state for series with more than one season.
if (isDropdown) {
button.addClass('selected');
}
list.appendChildWidget(button);
list.appendChildWidget(seasonCarousel);
this.appendChildWidget(list);
},
/**
* Sets the data item.
*
* @param {Object} season - The season.
*/
setDataItem: function setDataItem (season) {
setDataItem.base.call(this, season);
this._button.setText(season.getTitle());
this._button.setDataItem(season.getTitle());
this._carousel.setDataItem(season.getItems());
},
/**
* Aligns the carousel.
*
* @param {number} [index] - The index to align to. Optional.
* @param {boolean} [setActive] - True if the active child widget should be set.
*/
alignCarousel: function (index, setActive) {
index = index || 0;
this._carousel.getCarousel().alignToIndex(index);
if (setActive) {
this._carousel.getCarousel().setActiveChildIndex(index);
}
},
/**
* Aligns the carousel to the next item.
*/
alignNext: function () {
this._carousel.getCarousel().alignNext();
},
/**
* Aligns the carousel to the previous item.
*/
alignPrevious: function () {
this._carousel.getCarousel().alignPrevious();
}
});
});