move the stateful stuff to Deluge.js before any other js has executed
This commit is contained in:
parent
d075ac888e
commit
3f8abf1e34
|
@ -1,25 +1,25 @@
|
||||||
/*
|
/*
|
||||||
Script: deluge-ui.js
|
Script: Deluge.UI.js
|
||||||
The core ui module that builds up the ui layout and controls the polling
|
The core ui module that builds up the ui layout and controls the polling
|
||||||
of the server.
|
of the server.
|
||||||
|
|
||||||
Copyright:
|
Copyright:
|
||||||
(C) Damien Churchill 2009 <damoxc@gmail.com>
|
(C) Damien Churchill 2009 <damoxc@gmail.com>
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
the Free Software Foundation; either version 3, or (at your option)
|
||||||
any later version.
|
any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, write to:
|
along with this program. If not, write to:
|
||||||
The Free Software Foundation, Inc.,
|
The Free Software Foundation, Inc.,
|
||||||
51 Franklin Street, Fifth Floor
|
51 Franklin Street, Fifth Floor
|
||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
In addition, as a special exception, the copyright holders give
|
In addition, as a special exception, the copyright holders give
|
||||||
permission to link the code of portions of this program with the OpenSSL
|
permission to link the code of portions of this program with the OpenSSL
|
||||||
|
@ -40,163 +40,160 @@ Copyright:
|
||||||
*/
|
*/
|
||||||
Deluge.UI = {
|
Deluge.UI = {
|
||||||
|
|
||||||
cookies: new Ext.state.CookieProvider(),
|
errorCount: 0,
|
||||||
|
|
||||||
errorCount: 0,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Create all the interface components, the json-rpc client
|
|
||||||
* and set up various events that the UI will utilise.
|
|
||||||
*/
|
|
||||||
initialize: function() {
|
|
||||||
Ext.state.Manager.setProvider(this.cookies);
|
|
||||||
this.MainPanel = new Ext.Panel({
|
|
||||||
id: 'mainPanel',
|
|
||||||
iconCls: 'x-deluge-main-panel',
|
|
||||||
title: 'Deluge',
|
|
||||||
layout: 'border',
|
|
||||||
tbar: Deluge.Toolbar,
|
|
||||||
items: [
|
|
||||||
Deluge.Sidebar,
|
|
||||||
Deluge.Details,
|
|
||||||
Deluge.Torrents
|
|
||||||
],
|
|
||||||
bbar: Deluge.Statusbar
|
|
||||||
});
|
|
||||||
|
|
||||||
this.Viewport = new Ext.Viewport({
|
/**
|
||||||
layout: 'fit',
|
* @description Create all the interface components, the json-rpc client
|
||||||
items: [this.MainPanel]
|
* and set up various events that the UI will utilise.
|
||||||
});
|
*/
|
||||||
|
initialize: function() {
|
||||||
Deluge.Events.on("connect", this.onConnect, this);
|
this.MainPanel = new Ext.Panel({
|
||||||
Deluge.Events.on("disconnect", this.onDisconnect, this);
|
id: 'mainPanel',
|
||||||
Deluge.Client = new Ext.ux.util.RpcClient({
|
iconCls: 'x-deluge-main-panel',
|
||||||
url: '/json'
|
title: 'Deluge',
|
||||||
});
|
layout: 'border',
|
||||||
|
tbar: Deluge.Toolbar,
|
||||||
|
items: [
|
||||||
|
Deluge.Sidebar,
|
||||||
|
Deluge.Details,
|
||||||
|
Deluge.Torrents
|
||||||
|
],
|
||||||
|
bbar: Deluge.Statusbar
|
||||||
|
});
|
||||||
|
|
||||||
for (var plugin in Deluge.Plugins) {
|
this.Viewport = new Ext.Viewport({
|
||||||
plugin = Deluge.Plugins[plugin];
|
layout: 'fit',
|
||||||
plugin.enable();
|
items: [this.MainPanel]
|
||||||
}
|
});
|
||||||
|
|
||||||
Deluge.Client.on('connected', function(e) {
|
Deluge.Events.on("connect", this.onConnect, this);
|
||||||
Deluge.Login.show();
|
Deluge.Events.on("disconnect", this.onDisconnect, this);
|
||||||
Deluge.Events.start();
|
Deluge.Client = new Ext.ux.util.RpcClient({
|
||||||
Deluge.Events.on('PluginEnabledEvent', this.onPluginEnabled, this);
|
url: '/json'
|
||||||
Deluge.Events.on('PluginDisabledEvent', this.onPluginDisabled, this);
|
});
|
||||||
}, this, {single: true});
|
|
||||||
|
for (var plugin in Deluge.Plugins) {
|
||||||
this.update = this.update.bind(this);
|
plugin = Deluge.Plugins[plugin];
|
||||||
},
|
plugin.enable();
|
||||||
|
}
|
||||||
update: function() {
|
|
||||||
var filters = Deluge.Sidebar.getFilters();
|
Deluge.Client.on('connected', function(e) {
|
||||||
Deluge.Client.web.update_ui(Deluge.Keys.Grid, filters, {
|
Deluge.Login.show();
|
||||||
success: this.onUpdate,
|
Deluge.Events.start();
|
||||||
failure: this.onUpdateError,
|
Deluge.Events.on('PluginEnabledEvent', this.onPluginEnabled, this);
|
||||||
scope: this
|
Deluge.Events.on('PluginDisabledEvent', this.onPluginDisabled, this);
|
||||||
});
|
}, this, {single: true});
|
||||||
Deluge.Details.update();
|
|
||||||
Deluge.Client.web.connected({
|
this.update = this.update.bind(this);
|
||||||
success: this.onConnectedCheck,
|
},
|
||||||
scope: this
|
|
||||||
});
|
update: function() {
|
||||||
},
|
var filters = Deluge.Sidebar.getFilters();
|
||||||
|
Deluge.Client.web.update_ui(Deluge.Keys.Grid, filters, {
|
||||||
onConnectedCheck: function(connected) {
|
success: this.onUpdate,
|
||||||
if (!connected) {
|
failure: this.onUpdateError,
|
||||||
Deluge.Events.fire('disconnect');
|
scope: this
|
||||||
}
|
});
|
||||||
},
|
Deluge.Details.update();
|
||||||
|
Deluge.Client.web.connected({
|
||||||
onUpdateError: function(error) {
|
success: this.onConnectedCheck,
|
||||||
if (this.errorCount == 2) {
|
scope: this
|
||||||
Ext.MessageBox.show({
|
});
|
||||||
title: 'Lost Connection',
|
},
|
||||||
msg: 'The connection to the webserver has been lost!',
|
|
||||||
buttons: Ext.MessageBox.OK,
|
onConnectedCheck: function(connected) {
|
||||||
icon: Ext.MessageBox.ERROR
|
if (!connected) {
|
||||||
});
|
Deluge.Events.fire('disconnect');
|
||||||
}
|
}
|
||||||
this.errorCount++;
|
},
|
||||||
},
|
|
||||||
|
onUpdateError: function(error) {
|
||||||
/**
|
if (this.errorCount == 2) {
|
||||||
* @static
|
Ext.MessageBox.show({
|
||||||
* @private
|
title: 'Lost Connection',
|
||||||
* Updates the various components in the interface.
|
msg: 'The connection to the webserver has been lost!',
|
||||||
*/
|
buttons: Ext.MessageBox.OK,
|
||||||
onUpdate: function(data) {
|
icon: Ext.MessageBox.ERROR
|
||||||
Deluge.Torrents.update(data['torrents']);
|
});
|
||||||
Deluge.Statusbar.update(data['stats']);
|
}
|
||||||
Deluge.Sidebar.update(data['filters']);
|
this.errorCount++;
|
||||||
this.errorCount = 0;
|
},
|
||||||
},
|
|
||||||
|
/**
|
||||||
/**
|
* @static
|
||||||
* @static
|
* @private
|
||||||
* @private
|
* Updates the various components in the interface.
|
||||||
* Start the Deluge UI polling the server and update the interface.
|
*/
|
||||||
*/
|
onUpdate: function(data) {
|
||||||
onConnect: function() {
|
Deluge.Torrents.update(data['torrents']);
|
||||||
if (!this.running) {
|
Deluge.Statusbar.update(data['stats']);
|
||||||
this.running = setInterval(this.update, 2000);
|
Deluge.Sidebar.update(data['filters']);
|
||||||
this.update();
|
this.errorCount = 0;
|
||||||
}
|
},
|
||||||
},
|
|
||||||
|
/**
|
||||||
/**
|
* @static
|
||||||
* @static
|
* @private
|
||||||
* @private
|
* Start the Deluge UI polling the server and update the interface.
|
||||||
*/
|
*/
|
||||||
onDisconnect: function() {
|
onConnect: function() {
|
||||||
this.stop();
|
if (!this.running) {
|
||||||
},
|
this.running = setInterval(this.update, 2000);
|
||||||
|
this.update();
|
||||||
onPluginEnabled: function(pluginName) {
|
}
|
||||||
Deluge.Client.web.get_plugin_resources(pluginName, {
|
},
|
||||||
success: this.onGotPluginResources,
|
|
||||||
scope: this
|
/**
|
||||||
})
|
* @static
|
||||||
},
|
* @private
|
||||||
|
*/
|
||||||
onGotPluginResources: function(resources) {
|
onDisconnect: function() {
|
||||||
var scripts = (Deluge.debug) ? resources.debug_scripts : resources.scripts;
|
this.stop();
|
||||||
Ext.each(scripts, function(script) {
|
},
|
||||||
Ext.ux.JSLoader({
|
|
||||||
url: script,
|
onPluginEnabled: function(pluginName) {
|
||||||
onLoad: this.onPluginLoaded,
|
Deluge.Client.web.get_plugin_resources(pluginName, {
|
||||||
pluginName: resources.name
|
success: this.onGotPluginResources,
|
||||||
});
|
scope: this
|
||||||
}, this);
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
onPluginDisabled: function(pluginName) {
|
onGotPluginResources: function(resources) {
|
||||||
Deluge.Plugins[pluginName].disable();
|
var scripts = (Deluge.debug) ? resources.debug_scripts : resources.scripts;
|
||||||
},
|
Ext.each(scripts, function(script) {
|
||||||
|
Ext.ux.JSLoader({
|
||||||
onPluginLoaded: function(options) {
|
url: script,
|
||||||
// This could happen if the plugin has multiple scripts
|
onLoad: this.onPluginLoaded,
|
||||||
if (!Deluge.Plugins[options.pluginName]) return;
|
pluginName: resources.name
|
||||||
|
});
|
||||||
// Enable the plugin
|
}, this);
|
||||||
Deluge.Plugins[options.pluginName].enable();
|
},
|
||||||
},
|
|
||||||
|
onPluginDisabled: function(pluginName) {
|
||||||
/**
|
Deluge.Plugins[pluginName].disable();
|
||||||
* @static
|
},
|
||||||
* Stop the Deluge UI polling the server and clear the interface.
|
|
||||||
*/
|
onPluginLoaded: function(options) {
|
||||||
stop: function() {
|
// This could happen if the plugin has multiple scripts
|
||||||
if (this.running) {
|
if (!Deluge.Plugins[options.pluginName]) return;
|
||||||
clearInterval(this.running);
|
|
||||||
this.running = false;
|
// Enable the plugin
|
||||||
Deluge.Torrents.getStore().loadData([]);
|
Deluge.Plugins[options.pluginName].enable();
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @static
|
||||||
|
* Stop the Deluge UI polling the server and clear the interface.
|
||||||
|
*/
|
||||||
|
stop: function() {
|
||||||
|
if (this.running) {
|
||||||
|
clearInterval(this.running);
|
||||||
|
this.running = false;
|
||||||
|
Deluge.Torrents.getStore().loadData([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ext.onReady(function(e) {
|
Ext.onReady(function(e) {
|
||||||
Deluge.UI.initialize();
|
Deluge.UI.initialize();
|
||||||
});
|
});
|
|
@ -31,8 +31,12 @@ Copyright:
|
||||||
statement from all source files in the program, then also delete it here.
|
statement from all source files in the program, then also delete it here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Create the namespace Ext.deluge
|
||||||
Ext.namespace('Ext.deluge');
|
Ext.namespace('Ext.deluge');
|
||||||
|
|
||||||
|
// Setup the state manager
|
||||||
|
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
/* Add some helper functions to Ext */
|
/* Add some helper functions to Ext */
|
||||||
Ext.apply(Function.prototype, {
|
Ext.apply(Function.prototype, {
|
||||||
|
|
Loading…
Reference in New Issue