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:
parent
a816a83f3a
commit
c8a48d5df3
11
UI/Commands/CommandController.js
Normal file
11
UI/Commands/CommandController.js
Normal 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})
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
@ -149,12 +149,23 @@ define([
|
|||||||
{
|
{
|
||||||
title : 'RSS Sync',
|
title : 'RSS Sync',
|
||||||
icon : 'icon-rss',
|
icon : 'icon-rss',
|
||||||
command: 'rsssync'
|
command : 'rsssync',
|
||||||
|
successMessage: 'RSS Sync Completed',
|
||||||
|
errorMessage : 'RSS Sync Failed!'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title : 'Update Library',
|
title : 'Update Library',
|
||||||
icon : 'icon-refresh',
|
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
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";
|
"use strict";
|
||||||
define(['app', 'Config'], function () {
|
define(['app', 'Config', 'Commands/CommandController', 'Shared/Messenger'], function () {
|
||||||
|
|
||||||
NzbDrone.Shared.Toolbar.ButtonView = Backbone.Marionette.ItemView.extend({
|
NzbDrone.Shared.Toolbar.ButtonView = Backbone.Marionette.ItemView.extend({
|
||||||
template : 'Shared/Toolbar/ButtonTemplate',
|
template : 'Shared/Toolbar/ButtonTemplate',
|
||||||
@ -9,9 +9,14 @@ define(['app', 'Config'], function () {
|
|||||||
'click': 'onClick'
|
'click': 'onClick'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ui: {
|
||||||
|
icon: '.x-icon'
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key');
|
this.storageKey = this.model.get('menuKey') + ':' + this.model.get('key');
|
||||||
|
this.idle = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
onRender: function () {
|
onRender: function () {
|
||||||
@ -22,16 +27,45 @@ define(['app', 'Config'], function () {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onClick: function () {
|
onClick: function () {
|
||||||
this.invokeRoute();
|
if (this.idle) {
|
||||||
this.invokeCallback();
|
this.invokeCallback();
|
||||||
|
this.invokeRoute();
|
||||||
this.invokeCommand();
|
this.invokeCommand();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
invokeCommand: function () {
|
invokeCommand: function () {
|
||||||
var command = this.model.get('command');
|
var command = this.model.get('command');
|
||||||
if (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}}
|
||||||
|
65
UI/app.js
65
UI/app.js
@ -30,32 +30,49 @@ define('app', function () {
|
|||||||
|
|
||||||
window.NzbDrone = new Backbone.Marionette.Application();
|
window.NzbDrone = new Backbone.Marionette.Application();
|
||||||
window.NzbDrone.Config = {};
|
window.NzbDrone.Config = {};
|
||||||
window.NzbDrone.Series = {};
|
|
||||||
window.NzbDrone.Series.Index = {};
|
window.NzbDrone.Series = {
|
||||||
window.NzbDrone.Series.Index.Table = {};
|
Index : {
|
||||||
window.NzbDrone.Series.Index.List = {};
|
Table : {},
|
||||||
window.NzbDrone.Series.Index.Posters = {};
|
List : {},
|
||||||
window.NzbDrone.Series.Edit = {};
|
Posters: {}
|
||||||
window.NzbDrone.Series.Delete = {};
|
|
||||||
window.NzbDrone.Series.Details = {};
|
},
|
||||||
window.NzbDrone.AddSeries = {};
|
Edit : {},
|
||||||
window.NzbDrone.AddSeries.New = {};
|
Delete : {},
|
||||||
window.NzbDrone.AddSeries.Existing = {};
|
Details: {}
|
||||||
window.NzbDrone.AddSeries.RootFolders = {};
|
};
|
||||||
|
|
||||||
|
window.NzbDrone.AddSeries = {
|
||||||
|
New : {},
|
||||||
|
Existing : {},
|
||||||
|
RootFolders: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
window.NzbDrone.Quality = {};
|
window.NzbDrone.Quality = {};
|
||||||
window.NzbDrone.Shared = {};
|
|
||||||
window.NzbDrone.Shared.Toolbar = {};
|
window.NzbDrone.Commands = {};
|
||||||
|
|
||||||
|
window.NzbDrone.Shared = {
|
||||||
|
Toolbar : {},
|
||||||
|
Messenger: {}
|
||||||
|
};
|
||||||
window.NzbDrone.Calendar = {};
|
window.NzbDrone.Calendar = {};
|
||||||
window.NzbDrone.Settings = {};
|
|
||||||
window.NzbDrone.Settings.Naming = {};
|
window.NzbDrone.Settings = {
|
||||||
window.NzbDrone.Settings.Quality = {};
|
Naming : {},
|
||||||
window.NzbDrone.Settings.Quality.Size = {};
|
Quality : {
|
||||||
window.NzbDrone.Settings.Quality.Profile = {};
|
Size : {},
|
||||||
window.NzbDrone.Settings.Indexers = {};
|
Profile: {}
|
||||||
window.NzbDrone.Settings.DownloadClient = {};
|
},
|
||||||
window.NzbDrone.Settings.Notifications = {};
|
Indexers : {},
|
||||||
window.NzbDrone.Settings.System = {};
|
DownloadClient: {},
|
||||||
window.NzbDrone.Settings.Misc = {};
|
Notifications : {},
|
||||||
|
System : {},
|
||||||
|
Misc : {}
|
||||||
|
};
|
||||||
|
|
||||||
window.NzbDrone.Missing = {};
|
window.NzbDrone.Missing = {};
|
||||||
window.NzbDrone.History = {};
|
window.NzbDrone.History = {};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user