define('application/widgets/detail/series/header', [
'rofl/widgets/container',
'rofl/widgets/label',
'rofl/widgets/image',
'rofl/lib/l10n',
'rofl/lib/utils',
'application/widgets/detail/iconbutton',
'rofl/widgets/verticallist',
'rofl/widgets/horizontallist',
'application/widgets/detail/imdblabel'
], function (
Container,
Label,
Image,
L10N,
Utils,
IconButton,
VerticalList,
HorizontalList,
ImdbLabel
) {
'use strict';
var l10n = L10N.getInstance(),
VIDEO_RATINGS = {
G: 'icon-kijkwijzer-geweld-v2', // Geweld
A: 'icon-kijkwijzer-eng-v2', // Fear
S: 'icon-kijkwijzer-sex-v2', // Sex
D: 'icon-kijkwijzer-pesten-v2', // Discrimination
H: 'icon-kijkwijzer-drugs-v2', // Drugs or Alcohol use
T: 'icon-kijkwijzer-taal-v2', // Violent language,
'PC-6': 'icon-kijkwijzer-6-v2',
'PC-12': 'icon-kijkwijzer-12-v2',
'PC-16': 'icon-kijkwijzer-16-v2',
'PC-99': 'icon-kijkwijzer-al-v2'
};
return Container.extend({
/**
* Initialises the widget.
*/
init: function init () {
init.base.call(this);
this.addClass('series-header');
this._build();
},
/**
* Builds the widget.
*
* @private
*/
_build: function () {
var title = this._title = new Label(''),
subtitle = this._subtitle = new Label(''),
list = this._list = new VerticalList(),
buttonList = this._buttonList = new HorizontalList(),
seasons = this._seasons = new Label(''),
gradient = new Container(),
image = this._image = new Image(null, ''),
metadata = this._metadata = new Container();
title.addClass('title');
subtitle.addClass('subtitle');
seasons.addClass('seasons');
gradient.addClass('gradient');
metadata.addClass('metadata');
buttonList.addClass('buttons');
list.appendChildWidget(buttonList);
this.appendChildWidget(image);
this.appendChildWidget(gradient);
metadata.appendChildWidget(title);
metadata.appendChildWidget(seasons);
metadata.appendChildWidget(subtitle);
this._buildImdbRating();
this._buildVideoRatings();
this.appendChildWidget(metadata);
this.appendChildWidget(list);
},
/**
* Sets the data item.
*
* @param {Object} opts - The opts.
*/
setDataItem: function setDataItem (opts) {
var item = opts.item,
title = opts.title,
image = opts.image,
subtitle = opts.subtitle,
seasons = opts.seasons,
imdbRating = opts.imdbRating,
imdbRatingContainer = this._imdbRating,
list = this._videoRatings;
setDataItem.base.call(this, item);
this._title.setText(title);
this._subtitle.setText(subtitle);
if (seasons) {
if (seasons > 1) {
this._seasons.setText(l10n.get('seasons', {seasons: seasons}));
} else {
this._seasons.setText(l10n.get('season', {seasons: seasons}));
}
} else {
this._seasons.setText('');
}
this._image.setSrc(image);
Utils.each(opts.ratings, function (rating) {
list.appendChildWidget(this._createVideoRating(rating));
}, this);
if (imdbRating) {
imdbRatingContainer.removeChildWidgets();
imdbRatingContainer.appendChildWidget(new ImdbLabel({rating: imdbRating}));
} else {
imdbRatingContainer.removeChildWidgets();
}
},
/**
* Clears the widget.
*/
clear: function () {
this._image.setSrc('');
this._title.setText('');
this._subtitle.setText('');
this._seasons.setText('');
this._videoRatings.removeChildWidgets();
},
/**
* Creates a video rating label.
*
* @param {string} rating - The rating.
* @returns {Object} - The video rating label.
* @private
*/
_createVideoRating: function (rating) {
return new Label({ text: '', classNames: [VIDEO_RATINGS[rating], 'video-rating'] });
},
/**
* Builds the icons list.
*/
_buildVideoRatings: function () {
var videoRatings = this._videoRatings = new Container();
videoRatings.addClass('video-ratings');
this._metadata.appendChildWidget(videoRatings);
},
/**
* Builds the rating scale. (IMDB).
*/
_buildImdbRating: function () {
var userRating = this._imdbRating = new Container();
userRating.addClass('imdb-rating-container');
this._metadata.appendChildWidget(userRating);
}
});
});