mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -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
27
UI/Shared/Messenger.js
Normal file
27
UI/Shared/Messenger.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
define(['app'], function () {
|
||||
NzbDrone.Shared.Messenger = {
|
||||
show: function (options) {
|
||||
|
||||
if (!options.type) {
|
||||
options.type = 'info';
|
||||
}
|
||||
|
||||
if (!options.hideAfter) {
|
||||
switch (options.type) {
|
||||
case 'info':
|
||||
options.hideAfter = 5;
|
||||
break;
|
||||
case 'error':
|
||||
options.hideAfter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return window.Messenger().post({
|
||||
message : options.message,
|
||||
type : options.type,
|
||||
showCloseButton: true,
|
||||
hideAfter : options.hideAfter
|
||||
});
|
||||
}};
|
||||
});
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
<i class="{{icon}}"/> {{title}}
|
||||
<i class="{{icon}} x-icon"/> {{title}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue