1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

added command support to toolbar.

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

View File

@ -0,0 +1,11 @@
"use strict";
define(['app'], function () {
NzbDrone.Commands.Execute = function (name) {
return $.ajax({
type: 'POST',
url : NzbDrone.Constants.ApiRoot + '/command',
data: JSON.stringify({command: name})
});
};
});

View File

@ -149,12 +149,23 @@ define([
{
title : 'RSS Sync',
icon : 'icon-rss',
command: 'rsssync'
command : 'rsssync',
successMessage: 'RSS Sync Completed',
errorMessage : 'RSS Sync Failed!'
},
{
title : 'Update Library',
icon : 'icon-refresh',
command: 'updatelibrary'
command : 'updatelibrary',
successMessage: 'Library was updated!',
errorMessage : 'Library update failed!'
},
{
title : 'Test Action',
icon : 'icon-asterisk',
command : 'test',
successMessage: 'Test Completed',
errorMessage : 'Test Failed!'
}
]
};

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();
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}}

View File

@ -30,32 +30,49 @@ define('app', function () {
window.NzbDrone = new Backbone.Marionette.Application();
window.NzbDrone.Config = {};
window.NzbDrone.Series = {};
window.NzbDrone.Series.Index = {};
window.NzbDrone.Series.Index.Table = {};
window.NzbDrone.Series.Index.List = {};
window.NzbDrone.Series.Index.Posters = {};
window.NzbDrone.Series.Edit = {};
window.NzbDrone.Series.Delete = {};
window.NzbDrone.Series.Details = {};
window.NzbDrone.AddSeries = {};
window.NzbDrone.AddSeries.New = {};
window.NzbDrone.AddSeries.Existing = {};
window.NzbDrone.AddSeries.RootFolders = {};
window.NzbDrone.Series = {
Index : {
Table : {},
List : {},
Posters: {}
},
Edit : {},
Delete : {},
Details: {}
};
window.NzbDrone.AddSeries = {
New : {},
Existing : {},
RootFolders: {}
};
window.NzbDrone.Quality = {};
window.NzbDrone.Shared = {};
window.NzbDrone.Shared.Toolbar = {};
window.NzbDrone.Commands = {};
window.NzbDrone.Shared = {
Toolbar : {},
Messenger: {}
};
window.NzbDrone.Calendar = {};
window.NzbDrone.Settings = {};
window.NzbDrone.Settings.Naming = {};
window.NzbDrone.Settings.Quality = {};
window.NzbDrone.Settings.Quality.Size = {};
window.NzbDrone.Settings.Quality.Profile = {};
window.NzbDrone.Settings.Indexers = {};
window.NzbDrone.Settings.DownloadClient = {};
window.NzbDrone.Settings.Notifications = {};
window.NzbDrone.Settings.System = {};
window.NzbDrone.Settings.Misc = {};
window.NzbDrone.Settings = {
Naming : {},
Quality : {
Size : {},
Profile: {}
},
Indexers : {},
DownloadClient: {},
Notifications : {},
System : {},
Misc : {}
};
window.NzbDrone.Missing = {};
window.NzbDrone.History = {};