define('application/widgets/uibuilder/hero', [
'rofl/widgets/container',
'rofl/widgets/label',
'rofl/widgets/button',
'rofl/widgets/horizontallist',
'application/widgets/detail/buttons/play',
'application/widgets/detail/buttons/info',
'antie/runtimecontext'
], function (
Container,
Label,
Button,
HorizontalList,
PlayButton,
InfoButton,
RuntimeContext
) {
'use strict';
var layout = RuntimeContext.getCurrentApplication().getLayout();
return Container.extend({
/**
* Initialises the Hero widget.
*
* @param {Object} data - The Hero model.
* @param {Object} heroParams - Params for hero widget.
*/
init: function init (data, heroParams) {
var id = heroParams.id || 'hero';
init.base.call(this, id);
this.addClass('hero');
this.setDataItem(data);
this._buildHero(data, heroParams);
},
/**
* Builds the hero.
*
* @param {Object} data - The Hero model.
* @private
*/
_buildHero: function (data) {
this._buildImage();
this._buildGradients();
this._buildTitles(data);
this._buildActionList(data);
},
/**
* Builds the action list.
*
* @param {Object} data - The Hero model.
* @private
*/
_buildActionList: function (data) {
var list = this._list = new HorizontalList(),
infoButton = new InfoButton(),
playButton;
// Set the play button only if the hero is not a group of bundles(episodes).
if (data._item.getContentType() !== 'GROUP_OF_BUNDLES') {
playButton = new PlayButton();
list.appendChildWidget(playButton);
}
list.appendChildWidget(infoButton);
this.appendChildWidget(list);
},
/**
* Builds the image.
*
* @private
*/
_buildImage: function () {
var image = this._image = new Container();
image.addClass('image');
this.appendChildWidget(image);
},
/**
* Builds the gradients.
*
* @private
*/
_buildGradients: function () {
var topGradient = new Container();
topGradient.addClass('top-gradient');
this.appendChildWidget(topGradient);
},
/**
* Builds the titles.
*
* @param {Object} data - The Hero model.
* @private
*/
_buildTitles: function (data) {
var title = this._title = new Label(data.getItem().getTitle()),
subtitle = this._subtitle = new Label(data.getTitle());
title.addClass('title');
subtitle.addClass('subtitle');
this.appendChildWidget(subtitle);
this.appendChildWidget(title);
},
/**
* Renders the widget.
*
* @param {Object} device - The device.
* @returns {Object} - The output element.
*/
render: function render (device) {
var outputElement = render.base.call(this, device),
data = this.getDataItem();
if (!this.rendered) {
this.rendered = true;
if (this._image) {
this._image.setStyleTo(
'backgroundImage',
'url(' + data.getItem().getImage('manual', {
width: Math.round(layout.hero.width),
height: Math.round(layout.hero.height)
}) + ')');
}
}
return outputElement;
},
/**
* Sets focus to the action. Will set focus to the last focused button.
*
* @param {number} index - The index to focus.
*/
focusAction: function (index) {
if (this._list) {
this._list.getChildWidgetByIndex(index).focus();
} else {
this._carousel.focus();
}
},
/**
* Sets focus to the action. Will set focus to the last focused button.
*
* @returns {number} Returns the child widget count.
*/
getButtonCount: function () {
if (this._list) {
return this._list.getChildWidgetCount();
}
return 0;
},
/**
* Sets active child to the action.
*
* @param {number} index - The index to set active.
*/
setButtonActiveChildIndex: function (index) {
if (this._list) {
this._list.setActiveChildIndex(index);
}
}
});
});