define('application/widgets/player/miniepg/nextprogram', [
'rofl/widgets/container',
'rofl/widgets/label',
'rofl/widgets/image',
'rofl/lib/l10n',
'application/utils'
], function (
Container,
Label,
Image,
L10N,
AppUtils
) {
'use strict';
var l10n = L10N.getInstance();
return Container.extend({
/**
* Initialises the widget.
*
* @param {Object} [data] - The data to be set.
*/
init: function init (data) {
init.base.call(this);
this.addClass('nextprogram');
this._build();
if (data) {
this.setDataItem(data);
}
},
/**
* Builds the widget.
*
* @private
*/
_build: function () {
var helper = new Container();
helper.addClass('v-align-helper');
this._logo = this.appendChildWidget(new Image(''));
this._logo.addClass('logo');
this._logo.insertChildWidget(0, helper);
this._title = this.appendChildWidget(new Label({
text: '',
classNames: 'title'
}));
this._subtitle = this.appendChildWidget(new Label({
text: '',
classNames: 'subtitle'
}));
},
/**
* Sets the data item.
*
* @param {Object} item - The item.
*/
setData: function (item) {
var title = item.getTitleBrief(),
subtitle = new Date(item.getStartTime() * 1000).format('H:i')
+ ' | ' + Math.floor(item.getDuration() / 60) + 'm';
this._logo.setSrc(item.getChannel().getImage('128'));
if (AppUtils.isBroadcastLocked(item)) {
if (!AppUtils.showLockedTitle()) {
title = l10n.get('asset.locked');
}
this._isLocked = true;
}
this._title.setText(title);
this._subtitle.setText(subtitle);
},
/**
* Renders the widget.
*
* @param {Object} device - The device.
* @returns {Object} - The output element.
*/
render: function render (device) {
var outputElement;
if (this.rendered) {
return this.outputElement;
}
this.rendered = true;
outputElement = render.base.call(this, device);
this.setData(this.getDataItem());
return outputElement;
},
/**
* Unlocks the asset.
*/
unlock: function () {
if (this.rendered && this._isLocked) {
this._isLocked = false;
this._title.setText(this.getDataItem().getTitleBrief());
}
},
/**
* Locks the asset.
*/
lock: function () {
if (this.rendered && !this._isLocked) {
if (AppUtils.isBroadcastLocked(this.getDataItem())) {
if (!AppUtils.showLockedTitle()) {
this._title.setText(l10n.get('asset.locked'));
}
this._isLocked = true;
}
}
}
});
});