define('application/widgets/player/programdetails', [
'rofl/widgets/container',
'rofl/widgets/label',
'rofl/lib/l10n',
'rofl/lib/utils',
'antie/runtimecontext'
], function (
Container,
Label,
L10N,
Utils,
RuntimeContext
) {
'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'
},
application = RuntimeContext.getCurrentApplication(),
layout = application.getLayout(),
descriptionLayout = layout.player.description,
DESCRIPTION_LINE_LIMIT = 7;
return Container.extend({
/**
* Initialises the widget.
*
* @param {Object} data - The data.
*/
init: function init (data) {
init.base.call(this);
this.addClass('program-details');
this._build();
if (data) {
this.setDataItem(data);
}
},
/**
* Builds the widget.
*
* @private
*/
_build: function () {
var descriptionContainer = this._descriptionContainer = new Container(),
description = this._description = new Label(''),
list = this._list = new Container();
description.setWidth(descriptionLayout.width);
description.setMaximumLines(DESCRIPTION_LINE_LIMIT);
description.setTruncationMode(Label.TRUNCATION_MODE_RIGHT_ELLIPSIS);
descriptionContainer.appendChildWidget(description);
descriptionContainer.addClass('description');
description.addClass('info-tab-description');
this._buildVideoRatings();
list.addClass('metadata');
list.appendChildWidget(this._buildPeopleList('actors'));
list.appendChildWidget(this._buildPeopleList('directors'));
list.appendChildWidget(this._buildPeopleList('genres'));
this.appendChildWidget(descriptionContainer);
this.appendChildWidget(list);
},
/**
* Builds the people list.
*
* @param {string} type - The type.
* @returns {Object} - The list.
* @private
*/
_buildPeopleList: function (type) {
var container = new Container(),
title = new Label(l10n.get(type)),
list = new Container();
title.addClass(['title', type]);
container.addClass([type, 'metadata-content']);
list.addClass('metadata-list');
container.appendChildWidget(title);
container.appendChildWidget(list);
this['_metadataList' + type] = list;
return container;
},
/**
* Builds the icons list.
*/
_buildVideoRatings: function () {
var videoRatings = this._videoRatings = new Container();
videoRatings.addClass('video-ratings');
this._descriptionContainer.appendChildWidget(videoRatings);
},
/**
* Sets the requested program details.
*
* @param {Object} programDetails - The requested program's details.
*/
setDataItem: function (programDetails) {
var list = this._videoRatings,
descriptionData = programDetails.getDescription(),
listData = [
{
type: 'actors',
metadata: programDetails.getActors()
},
{
type: 'directors',
metadata: programDetails.getDirectors()
},
{
type: 'genres',
metadata: programDetails.getGenres()
}
],
ratingsData = [programDetails.getAgeRating()].concat(programDetails.getVideoRatings());
this._description.setText(descriptionData);
Utils.each(listData, function (data) {
this._addMetadata(data);
}, this);
list.removeChildWidgets();
Utils.each(ratingsData, function (rating) {
list.appendChildWidget(this._createVideoRating(rating));
}, this);
},
/**
* Adds people to the widget.
*
* @param {Object} data - The data.
* @private
*/
_addMetadata: function (data) {
var list = this['_metadataList' + data.type];
list.removeChildWidgets();
if (data.metadata.length) {
list.parentWidget.addClass('show');
} else {
list.parentWidget.removeClass('show');
}
Utils.each(data.metadata, function (metadata) {
list.appendChildWidget(new Label(metadata));
});
},
/**
* 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'] });
},
/**
* Checks if program details info is expanded.
*
* @returns {boolean} - True if program details info is expanded.
*/
isExpanded: function () {
return this.hasClass('expand');
}
});
});