define('application/widgets/detail/episodeitem', [
'rofl/widgets/button',
'rofl/widgets/label',
'application/widgets/detail/iconbutton',
'rofl/widgets/container',
'rofl/widgets/verticallist',
'rofl/widgets/horizontallist',
'application/widgets/infoblock',
'rofl/lib/l10n',
'application/widgets/detail/descriptioncontainer',
'application/models/production/recordings/record',
'application/utils'
], function (
Button,
Label,
IconButton,
Container,
VerticalList,
HorizontalList,
InfoBlock,
L10N,
Description,
Record,
AppUtils
) {
'use strict';
var l10n = L10N.getInstance();
return Container.extend({
/**
* Initialises the button.
*
* @param {string} [id] - The id. Optional.
* @param {Object} params - The params.
*/
init: function init (id, params) {
init.base.call(this, id);
this.addClass('episode-element');
this._build(params);
},
/**
* Builds the widget.
*
* @param {Object} params - The params.
* @private
*/
_build: function (params) {
this._buildToggle();
this._buildIcon();
this._buildEpisodeLabel(params.data);
this._buildLabel(params.data);
this._buildEpisodeMark(params);
this._buildDescription(params.data);
},
/**
* Builds the toggle.
*
* @private
*/
_buildToggle: function () {
var toggle = this._toggle = new Button();
toggle.addClass('toggle');
this.appendChildWidget(toggle);
},
/**
* Builds a search icon label.
*
* @private
*/
_buildIcon: function () {
var icon = new Label({ text: '', classNames: ['icon-unable-play-v2', 'element-icon'] });
this._toggle.appendChildWidget(icon);
},
/**
* Builds the label.
*
* @param {Object} data - The data item.
* @private
*/
_buildEpisodeLabel: function (data) {
var label,
text;
if (data instanceof Record) {
text = AppUtils.getDate(new Date(data.getStartTime() * 1000), new Date(data.getEndTime() * 1000));
} else {
text = l10n.get('details.episode_number', { number: data.getEpisodeNumber() });
}
label = new Label({ text: text, classNames: ['episodenum'] });
this._toggle.appendChildWidget(label);
},
/**
* Builds the label.
*
* @param {Object} data - The data.
* @private
*/
_buildLabel: function (data) {
var text = '',
label;
if (!(data instanceof Record)) {
text = AppUtils.getStreamDate(
new Date(data.getStartTime() * 1000),
new Date(data.getEndTime() * 1000));
}
label = new Label({ text: text, classNames: ['date'] });
this._toggle.appendChildWidget(label);
},
/**
* Builds the button.
*
* @param {Object} params - Params.
* @private
*/
_buildEpisodeMark: function (params) {
var episodemark;
if (params.live) {
episodemark = this._episodemark = new InfoBlock({
classname: 'icon-play-filled',
text: l10n.get('details.live')
});
episodemark.addClass(['no-border-button', 'live']);
}
if (params.catchup && !(params.data instanceof Record)) {
episodemark = this._episodemark = new InfoBlock({
classname: 'icon-play-filled',
text: l10n.get('details.catchup')
});
episodemark.addClass(['no-border-button', 'catchup']);
}
if (params.restricted && !params.live) {
episodemark = this._episodemark = new InfoBlock({
classname: 'icon-unable-play',
text: ''
});
}
if (episodemark) {
this._toggle.appendChildWidget(episodemark);
}
},
/**
* Builds the description.
*
* @param {Object} params - Params.
* @private
*/
_buildDescription: function (params) {
var description = this._description = new Description(params);
description.addClass('description');
this.appendChildWidget(description);
},
/**
* Gets the description.
*
* @returns {Object} Description.
* @private
*/
getDescription: function () {
return this._description;
},
/**
* Gets the toggle.
*
* @returns {Object} Toggle.
* @private
*/
getToggle: function () {
return this._toggle;
},
/**
* Enables the toggle.
*/
enable: function () {
this._toggle.setDisabled(true);
this._description.enable();
this._description.focus();
},
/**
* Disables the toggle.
*/
disable: function () {
this._description.disable();
this._toggle.setDisabled(false);
this.setActiveChildWidget(this._toggle);
},
/**
* Disposes the widget.
*/
dispose: function dispose () {
this._description.dispose();
dispose.base.call(this);
}
});
});