define('application/widgets/filters/button', [
'application/widgets/pointerfocusablebutton',
'rofl/widgets/label'
], function (
Button,
Label
) {
'use strict';
return Button.extend({
/**
* Initialises the button.
*
* @param {Object} data - The filter data.
*/
init: function init (data) {
init.base.call(this, data.id);
this.addClass(['filter']);
if (data.classList) {
this.addClass(data.classList);
}
if (data.isDropDown) {
this.addClass('dropdown');
}
this._build(data);
},
/**
* Builds the widget.
*
* @param {Object} data - The widget data.
* @private
*/
_build: function (data) {
var label = this._label = new Label({ text: data.text || '' }),
icon = new Label({ text: '', classNames: ['icon-chevron-down', 'icon'] }),
helper = new Label({ text: '', classNames: ['v-align-helper'] });
this.appendChildWidget(helper);
this.appendChildWidget(label);
if (data.isDropDown) {
label.addClass('v-align-target');
icon.addClass('v-align-target');
this.appendChildWidget(icon);
}
},
/**
* Sets the text of the button.
*
* @param {string} text - The text to set.
*/
setText: function (text) {
this._label.setText(text);
},
/**
* Sets icon on button.
*
* @param {string} icon - Icon.
*/
setIcon: function (icon) {
this._label.addClass(icon);
this._label.addClass('icon-dropdown');
if (this._iconClass && icon !== this._iconClass) {
this._label.removeClass(this._iconClass);
this._label.removeClass('icon-dropdown');
}
this._iconClass = icon;
},
/**
* Returns the text.
*
* @returns {string} - The text.
*/
getText: function () {
return this._label.getText();
}
});
});