mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-13 16:43:58 -07:00
added command support to toolbar.
This commit is contained in:
parent
a816a83f3a
commit
c8a48d5df3
6 changed files with 136 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
|||
"use strict";
|
||||
define(['app', 'Config'], function () {
|
||||
define(['app', 'Config', 'Commands/CommandController', 'Shared/Messenger'], function () {
|
||||
|
||||
NzbDrone.Shared.Toolbar.ButtonView = Backbone.Marionette.ItemView.extend({
|
||||
template : 'Shared/Toolbar/ButtonTemplate',
|
||||
|
@ -9,9 +9,14 @@ define(['app', 'Config'], function () {
|
|||
'click': 'onClick'
|
||||
},
|
||||
|
||||
ui: {
|
||||
icon: '.x-icon'
|
||||
},
|
||||
|
||||
|
||||
initialize: function () {
|
||||
this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key');
|
||||
this.idle = true;
|
||||
},
|
||||
|
||||
onRender: function () {
|
||||
|
@ -22,16 +27,45 @@ define(['app', 'Config'], function () {
|
|||
},
|
||||
|
||||
onClick: function () {
|
||||
this.invokeRoute();
|
||||
this.invokeCallback();
|
||||
this.invokeCommand();
|
||||
if (this.idle) {
|
||||
this.invokeCallback();
|
||||
this.invokeRoute();
|
||||
this.invokeCommand();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
invokeCommand: function () {
|
||||
var command = this.model.get('command');
|
||||
if (command) {
|
||||
window.alert(command);
|
||||
this.idle = false;
|
||||
this.$el.addClass('disabled');
|
||||
this.ui.icon.addClass('icon-spinner icon-spin');
|
||||
|
||||
var self = this;
|
||||
var commandPromise = NzbDrone.Commands.Execute(command);
|
||||
commandPromise.done(function () {
|
||||
if (self.model.get('successMessage')) {
|
||||
NzbDrone.Shared.Messenger.show({
|
||||
message: self.model.get('successMessage')
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
commandPromise.fail(function () {
|
||||
if (self.model.get('errorMessage')) {
|
||||
NzbDrone.Shared.Messenger.show({
|
||||
message: self.model.get('errorMessage'),
|
||||
type : 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
commandPromise.always(function () {
|
||||
self.$el.removeClass('disabled');
|
||||
self.ui.icon.removeClass('icon-spinner icon-spin');
|
||||
self.idle = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue