1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/UI/Shared/Toolbar/Button/ButtonView.js

89 lines
2.3 KiB
JavaScript
Raw Normal View History

2013-06-22 09:24:24 +03:00
'use strict';
define(
[
'app',
'marionette',
2013-09-11 09:33:47 +03:00
'Commands/CommandController',
'Shared/Actioneer'
], function (App, Marionette, CommandController, Actioneer) {
return Marionette.ItemView.extend({
template : 'Shared/Toolbar/ButtonTemplate',
className: 'btn',
events: {
'click': 'onClick'
},
initialize: function () {
this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key');
},
onRender: function () {
if (this.model.get('active')) {
this.$el.addClass('active');
this.invokeCallback();
}
2013-06-29 02:19:00 +03:00
2013-09-11 09:33:47 +03:00
if (!this.model.get('title')) {
2013-06-29 02:19:00 +03:00
this.$el.addClass('btn-icon-only');
}
2013-09-11 09:33:47 +03:00
var command = this.model.get('command');
if (command) {
Actioneer.bindToCommand({
command: {name: command},
element: this.$el
});
}
},
onClick: function () {
2013-09-11 09:33:47 +03:00
if (this.$el.hasClass('disabled')) {
return;
}
2013-09-11 09:33:47 +03:00
this.invokeCallback();
this.invokeRoute();
this.invokeCommand();
},
invokeCommand: function () {
var command = this.model.get('command');
if (command) {
2013-09-11 09:33:47 +03:00
CommandController.Execute(command);
}
},
invokeRoute: function () {
var route = this.model.get('route');
if (route) {
require(
[
'Router'
], function () {
App.Router.navigate(route, {trigger: true});
2013-05-12 02:39:32 +03:00
});
}
},
2013-05-11 23:51:32 +03:00
invokeCallback: function () {
2013-05-11 23:51:32 +03:00
if (!this.model.ownerContext) {
throw 'ownerContext must be set.';
}
2013-05-11 23:51:32 +03:00
var callback = this.model.get('callback');
if (callback) {
callback.call(this.model.ownerContext);
}
}
});
2013-05-11 23:51:32 +03:00
});