define('application/widgets/uibuilder/filter', [
'rofl/widgets/container',
'rofl/widgets/label',
'rofl/widgets/button',
'rofl/widgets/horizontallist',
'application/widgets/filters/button'
], function (
Container,
Label,
Button,
HorizontalList,
FilterButton
) {
'use strict';
return Container.extend({
/**
* Initialises the Filter widget.
*
* @param {Object} data - The Filter model.
*/
init: function init (data) {
init.base.call(this);
this.addClass('filter-widget');
this.setDataItem(data);
this._buildFilterList();
this._buildFilter(data);
},
/**
* Builds the filter container.
*
* @private
*/
_buildFilterList: function () {
var filtersList = this._filtersList = new HorizontalList();
this.appendChildWidget(filtersList);
},
/**
* Builds the filter.
*
* @param {Object} data - The Filter model.
* @private
*/
_buildFilter: function (data) {
switch (data.type) {
case 'genre':
this._buildGenreButton();
break;
case 'sort':
this._buildSortButton(data);
break;
case 'filter':
this._buildFilterButton();
break;
}
},
/**
* Builds the genre button.
*
* @private
*/
_buildGenreButton: function () {
var genreFiltersButton = this._genreButton = new FilterButton(this.getDataItem());
this._filtersList.appendChildWidget(genreFiltersButton);
},
/**
* Builds the sort button.
*
* @private
*/
_buildFilterButton: function () {
var commonFiltersButton = this._filterButton = new FilterButton(this.getDataItem());
this._filterButton.setIcon('icon-filter-1');
this._filtersList.appendChildWidget(commonFiltersButton);
},
/**
* Builds the sort button.
*
* @param {Object} data - The Filter model.
* @private
*/
_buildSortButton: function (data) {
var sortFiltersButton = this._sortButton = new FilterButton(this.getDataItem()),
filterIcon = data.icon || 'icon-sort';
this._sortButton.setIcon(filterIcon);
this._filtersList.appendChildWidget(sortFiltersButton);
},
/**
* Get the genre filter button.
*
* @returns {Object} - Genre filter button widget.
*/
getGenreButton: function () {
return this._genreButton;
},
/**
* Get the common filter button.
*
* @returns {Object} - Commong filter button widget.
*/
getFilterButton: function () {
return this._filterButton;
},
/**
* Get the sort filter button.
*
* @returns {Object} - Sort filter button widget.
*/
getSortButton: function () {
return this._sortButton;
}
});
});