1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2025-03-06 19:59:36 +00:00
Radarr/UI/Shared/Toolbar/ToolbarLayout.js

98 lines
3.1 KiB
JavaScript
Raw Normal View History

2013-06-21 23:24:24 -07:00
'use strict';
2013-06-20 22:19:41 -07:00
define(
[
'marionette',
2013-06-23 21:28:18 -07:00
'Shared/Toolbar/ButtonCollection',
'Shared/Toolbar/ButtonModel',
'Shared/Toolbar/Radio/RadioButtonCollectionView',
'Shared/Toolbar/Button/ButtonCollectionView'
], function (Marionette, ButtonCollection, ButtonModel, RadioButtonCollectionView, ButtonCollectionView) {
return Marionette.Layout.extend({
2013-06-20 22:19:41 -07:00
template: 'Shared/Toolbar/ToolbarLayoutTemplate',
regions: {
left_1 : '.x-toolbar-left-1',
left_2 : '.x-toolbar-left-2',
right_1: '.x-toolbar-right-1',
right_2: '.x-toolbar-right-2'
},
initialize: function (options) {
if (!options) {
throw 'options needs to be passed';
}
2013-06-20 22:19:41 -07:00
if (!options.context) {
throw 'context needs to be passed';
}
2013-06-20 22:19:41 -07:00
this.left = options.left;
this.right = options.right;
this.toolbarContext = options.context;
},
2013-06-20 22:19:41 -07:00
onShow: function () {
if (this.left) {
_.each(this.left, this._showToolbarLeft, this);
}
if (this.right) {
_.each(this.right, this._showToolbarRight, this);
}
},
2013-06-20 22:19:41 -07:00
_showToolbarLeft: function (element, index) {
this._showToolbar(element, index, 'left');
},
2013-06-20 22:19:41 -07:00
_showToolbarRight: function (element, index) {
this._showToolbar(element, index, 'right');
},
2013-06-20 22:19:41 -07:00
_showToolbar: function (buttonGroup, index, position) {
2013-06-23 21:28:18 -07:00
var groupCollection = new ButtonCollection();
2013-06-20 22:19:41 -07:00
_.each(buttonGroup.items, function (button) {
2013-06-20 22:19:41 -07:00
if (buttonGroup.storeState && !button.key) {
throw 'must provide key for all buttons when storSstate is enabled';
}
2013-06-23 21:28:18 -07:00
var model = new ButtonModel(button);
2013-06-20 22:19:41 -07:00
model.set('menuKey', buttonGroup.menuKey);
model.ownerContext = this.toolbarContext;
groupCollection.add(model);
2013-06-20 22:19:41 -07:00
}, this);
2013-06-20 22:19:41 -07:00
var buttonGroupView;
2013-06-20 22:19:41 -07:00
switch (buttonGroup.type) {
case 'radio':
{
2013-06-23 21:28:18 -07:00
buttonGroupView = new RadioButtonCollectionView({
collection: groupCollection,
menu : buttonGroup
});
2013-06-20 22:19:41 -07:00
break;
}
default :
{
2013-06-23 21:28:18 -07:00
buttonGroupView = new ButtonCollectionView({
collection: groupCollection,
menu : buttonGroup
});
2013-06-20 22:19:41 -07:00
break;
}
2013-05-11 13:51:32 -07:00
}
2013-06-20 22:19:41 -07:00
this[position + '_' + (index + 1).toString()].show(buttonGroupView);
}
});
});