added command support to toolbar.

This commit is contained in:
kay.one 2013-05-11 16:39:32 -07:00
commit c8a48d5df3
6 changed files with 136 additions and 36 deletions

27
UI/Shared/Messenger.js Normal file
View 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
});
}};
});

View file

@ -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;
});
}
},

View file

@ -1 +1 @@
<i class="{{icon}}"/> {{title}}
<i class="{{icon}} x-icon"/> {{title}}