define('application/widgets/player/warningbox', [
'rofl/widgets/container',
'rofl/widgets/label',
'rofl/lib/utils'
], function (
Container,
Label,
Utils
) {
'use strict';
var WarningBox = Container.extend({
/**
* Initialises the progress widget.
*
* @param {Object} data - Passed as config to widget.
*/
init: function init (data) {
init.base.call(this, 'warningbox');
data = data || {};
this._create();
this.setIcon(data.icon || '');
this.setText(data.text || '');
},
/**
* Creates warning box.
*/
_create: function () {
this._icon = new Label({ text: '', classNames: ['warningicon'] });
this._text = new Label({ text: '', classNames: ['warningtext'] });
this.appendChildWidget(this._icon);
this.appendChildWidget(this._text);
},
/**
* Creates and returns an icon Label.
*
* @param {string} icon - Icon set from data.
*/
setIcon: function (icon) {
this._icon.addClass(icon);
},
/**
* Creates and returns an text Label.
*
* @param {string} text - Text set from data.
*/
setText: function (text) {
this._text.setText(text);
},
/**
* Shows the Warning Box and after 5s disappears.
*
* @param {Object} config - The display config. Contains icon and text.
*/
show: function show (config) {
clearTimeout(this._hideTimeout);
if (config.happy && !this.hasClass('happy')) {
this.addClass('happy');
} else if (!config.happy && this.hasClass('happy')) {
this.removeClass('happy');
}
this.setIcon(config.icon || '');
this.setText(config.text || '');
show.base.call(this);
this._hideTimeout = setTimeout(Utils.bind(this.hide, this), 5000);
}
});
return WarningBox;
});