initial commit of the big javascript refactor
This commit is contained in:
parent
46a6576c68
commit
01bb9c4df5
|
@ -11,9 +11,13 @@
|
|||
<link rel="stylesheet" type="text/css" href="${base}${stylesheet}" />
|
||||
% endfor
|
||||
|
||||
<script type="text/javascript">
|
||||
${js_config}
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
deluge = {
|
||||
author: 'Damien Churchill <damoxc@gmail.com>',
|
||||
version: '${version}',
|
||||
config: ${js_config}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Javascript -->
|
||||
% for script in scripts:
|
||||
|
|
|
@ -500,5 +500,4 @@ Copyright:
|
|||
}
|
||||
}
|
||||
});
|
||||
deluge.connectionManager = new Deluge.ConnectionManager();
|
||||
})();
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
Script: Deluge.Details.js
|
||||
Contains all objects and functions related to the lower details panel and
|
||||
it's containing tabs.
|
||||
|
||||
Copyright:
|
||||
(C) Damien Churchill 2009-2010 <damoxc@gmail.com>
|
||||
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
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, write to:
|
||||
The Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the OpenSSL
|
||||
library.
|
||||
You must obey the GNU General Public License in all respects for all of
|
||||
the code used other than OpenSSL. If you modify file(s) with this
|
||||
exception, you may extend this exception to your version of the file(s),
|
||||
but you are not obligated to do so. If you do not wish to do so, delete
|
||||
this exception statement from your version. If you delete this exception
|
||||
statement from all source files in the program, then also delete it here.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
Ext.namespace('Deluge.details');
|
||||
Deluge.details.TabPanel = Ext.extend(Ext.TabPanel, {
|
||||
|
||||
constructor: function(config) {
|
||||
config = Ext.apply({
|
||||
region: 'south',
|
||||
id: 'torrentDetails',
|
||||
split: true,
|
||||
height: 220,
|
||||
minSize: 100,
|
||||
collapsible: true,
|
||||
margins: '0 5 5 5',
|
||||
activeTab: 0
|
||||
}, config);
|
||||
Deluge.details.TabPanel.superclass.constructor.call(this, config);
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
this.items.each(function(panel) {
|
||||
if (panel.clear) {
|
||||
panel.clear.defer(100, panel);
|
||||
panel.disable();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
update: function(tab) {
|
||||
var torrent = deluge.torrents.getSelected();
|
||||
if (!torrent) {
|
||||
this.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
this.items.each(function(tab) {
|
||||
if (tab.disabled) tab.enable();
|
||||
});
|
||||
|
||||
tab = tab || this.getActiveTab();
|
||||
if (tab.update) tab.update(torrent.id);
|
||||
},
|
||||
|
||||
/* Event Handlers */
|
||||
|
||||
// We need to add the events in onRender since Deluge.Torrents hasn't
|
||||
// been created yet.
|
||||
onRender: function(ct, position) {
|
||||
Deluge.details.TabPanel.superclass.onRender.call(this, ct, position);
|
||||
deluge.events.on('disconnect', this.clear, this);
|
||||
deluge.torrents.on('rowclick', this.onTorrentsClick, this);
|
||||
this.on('tabchange', this.onTabChange, this);
|
||||
|
||||
deluge.torrents.getSelectionModel().on('selectionchange', function(selModel) {
|
||||
if (!selModel.hasSelection()) this.clear();
|
||||
}, this);
|
||||
},
|
||||
|
||||
onTabChange: function(panel, tab) {
|
||||
this.update(tab);
|
||||
},
|
||||
|
||||
onTorrentsClick: function(grid, rowIndex, e) {
|
||||
this.update();
|
||||
}
|
||||
});
|
||||
deluge.details = new Deluge.details.TabPanel();
|
||||
})();
|
|
@ -91,7 +91,7 @@ Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
|
|||
})();
|
||||
|
||||
// Create the Deluge namespace
|
||||
Deluge = {
|
||||
Ext.apply(Deluge, {
|
||||
|
||||
// private
|
||||
progressTpl: '<div class="x-progress-wrap x-progress-renderered">' +
|
||||
|
@ -124,7 +124,7 @@ Deluge = {
|
|||
return String.format(Deluge.progressTpl, text, width, barWidth, textWidth);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Setup a space for plugins to insert themselves
|
||||
deluge.plugins = {};
|
||||
|
|
|
@ -338,5 +338,4 @@ Copyright:
|
|||
});
|
||||
}
|
||||
});
|
||||
deluge.editTrackers = new Deluge.EditTrackers();
|
||||
})();
|
|
@ -154,5 +154,3 @@ Deluge.LoginWindow = Ext.extend(Ext.Window, {
|
|||
this.passwordField.setRawValue('');
|
||||
}
|
||||
});
|
||||
|
||||
deluge.login = new Deluge.LoginWindow();
|
|
@ -49,6 +49,13 @@ deluge.ui = {
|
|||
* and set up various events that the UI will utilise.
|
||||
*/
|
||||
initialize: function() {
|
||||
deluge.add = new Deluge.add.AddWindow();
|
||||
deluge.details = new Deluge.details.DetailsPanel();
|
||||
deluge.connectionManager = new Deluge.ConnectionManager();
|
||||
deluge.editTrackers = new Deluge.EditTrackers();
|
||||
deluge.login = new Deluge.LoginWindow();
|
||||
deluge.preferences = new Deluge.preferences.PreferencesWindow();
|
||||
|
||||
this.MainPanel = new Ext.Panel({
|
||||
id: 'mainPanel',
|
||||
iconCls: 'x-deluge-main-panel',
|
|
@ -550,4 +550,3 @@ Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, {
|
|||
this.url.show();
|
||||
}
|
||||
});
|
||||
deluge.add = new Deluge.add.AddWindow();
|
|
@ -50,8 +50,7 @@ Deluge.data.Peer = Ext.data.Record.create([
|
|||
type: 'string'
|
||||
}, {
|
||||
name: 'ip',
|
||||
type: 'string',
|
||||
sortType: Deluge.data.SortTypes.asIPAddress
|
||||
type: 'string'
|
||||
}, {
|
||||
name: 'client',
|
||||
type: 'string'
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
Script: Deluge.Details.js
|
||||
Contains all objects and functions related to the lower details panel and
|
||||
it's containing tabs.
|
||||
|
||||
Copyright:
|
||||
(C) Damien Churchill 2009-2010 <damoxc@gmail.com>
|
||||
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
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, write to:
|
||||
The Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor
|
||||
Boston, MA 02110-1301, USA.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the OpenSSL
|
||||
library.
|
||||
You must obey the GNU General Public License in all respects for all of
|
||||
the code used other than OpenSSL. If you modify file(s) with this
|
||||
exception, you may extend this exception to your version of the file(s),
|
||||
but you are not obligated to do so. If you do not wish to do so, delete
|
||||
this exception statement from your version. If you delete this exception
|
||||
statement from all source files in the program, then also delete it here.
|
||||
*/
|
||||
|
||||
Ext.namespace('Deluge.details');
|
||||
Deluge.details.DetailsPanel = Ext.extend(Ext.TabPanel, {
|
||||
|
||||
region: 'south',
|
||||
id: 'torrentDetails',
|
||||
split: true,
|
||||
height: 220,
|
||||
minSize: 100,
|
||||
collapsible: true,
|
||||
margins: '0 5 5 5',
|
||||
activeTab: 0,
|
||||
|
||||
initComponent: function() {
|
||||
Deluge.details.DetailsPanel.superclass.initComponent.call(this);
|
||||
this.add(new Deluge.details.StatusTab());
|
||||
this.add(new Deluge.details.DetailsTab());
|
||||
this.add(new Deluge.details.FilesTab());
|
||||
this.add(new Deluge.details.PeersTab());
|
||||
this.add(new Deluge.details.OptionsTab());
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
this.items.each(function(panel) {
|
||||
if (panel.clear) {
|
||||
panel.clear.defer(100, panel);
|
||||
panel.disable();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
update: function(tab) {
|
||||
var torrent = deluge.torrents.getSelected();
|
||||
if (!torrent) {
|
||||
this.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
this.items.each(function(tab) {
|
||||
if (tab.disabled) tab.enable();
|
||||
});
|
||||
|
||||
tab = tab || this.getActiveTab();
|
||||
if (tab.update) tab.update(torrent.id);
|
||||
},
|
||||
|
||||
/* Event Handlers */
|
||||
|
||||
// We need to add the events in onRender since Deluge.Torrents hasn't
|
||||
// been created yet.
|
||||
onRender: function(ct, position) {
|
||||
Deluge.details.DetailsPanel.superclass.onRender.call(this, ct, position);
|
||||
deluge.events.on('disconnect', this.clear, this);
|
||||
deluge.torrents.on('rowclick', this.onTorrentsClick, this);
|
||||
this.on('tabchange', this.onTabChange, this);
|
||||
|
||||
deluge.torrents.getSelectionModel().on('selectionchange', function(selModel) {
|
||||
if (!selModel.hasSelection()) this.clear();
|
||||
}, this);
|
||||
},
|
||||
|
||||
onTabChange: function(panel, tab) {
|
||||
this.update(tab);
|
||||
},
|
||||
|
||||
onTorrentsClick: function(grid, rowIndex, e) {
|
||||
this.update();
|
||||
}
|
||||
});
|
|
@ -112,4 +112,3 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, {
|
|||
this.oldData = data;
|
||||
}
|
||||
});
|
||||
deluge.details.add(new Deluge.details.DetailsTab());
|
|
@ -216,5 +216,4 @@ Copyright:
|
|||
root.firstChild.expand();
|
||||
}
|
||||
});
|
||||
deluge.details.add(new Deluge.details.FilesTab());
|
||||
})();
|
|
@ -414,4 +414,3 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, {
|
|||
this.fields.stop_ratio.setDisabled(!stop_at_ratio);
|
||||
}
|
||||
});
|
||||
deluge.details.add(new Deluge.details.OptionsTab());
|
|
@ -150,5 +150,4 @@ Copyright:
|
|||
store.sort(sortState.field, sortState.direction);
|
||||
}
|
||||
});
|
||||
deluge.details.add(new Deluge.details.PeersTab());
|
||||
})();
|
|
@ -119,4 +119,3 @@ Deluge.details.StatusTab = Ext.extend(Ext.Panel, {
|
|||
this.progressBar.updateProgress(status.progress / 100.0, text);
|
||||
}
|
||||
});
|
||||
deluge.details.add(new Deluge.details.StatusTab());
|
|
@ -216,4 +216,3 @@ Deluge.preferences.Bandwidth = Ext.extend(Ext.form.FormPanel, {
|
|||
}));
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Bandwidth());
|
|
@ -86,4 +86,3 @@ Deluge.preferences.Cache = Ext.extend(Ext.form.FormPanel, {
|
|||
}));
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Cache());
|
|
@ -104,4 +104,3 @@ Deluge.preferences.Daemon = Ext.extend(Ext.form.FormPanel, {
|
|||
}));
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Daemon());
|
|
@ -155,4 +155,3 @@ Deluge.preferences.Downloads = Ext.extend(Ext.FormPanel, {
|
|||
Deluge.preferences.Downloads.superclass.onShow.call(this);
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Downloads());
|
|
@ -116,4 +116,3 @@ Deluge.preferences.Encryption = Ext.extend(Ext.form.FormPanel, {
|
|||
}));
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Encryption());
|
|
@ -262,4 +262,3 @@ Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, {
|
|||
this.certField.setDisabled(!checked);
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Interface());
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Script: deluge.preferences.Network.js
|
||||
Script: Deluge.preferences.Network.js
|
||||
The network preferences page.
|
||||
|
||||
Copyright:
|
||||
|
@ -38,15 +38,11 @@ Ext.namespace('Deluge.preferences');
|
|||
* @extends Ext.form.FormPanel
|
||||
*/
|
||||
Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
|
||||
constructor: function(config) {
|
||||
config = Ext.apply({
|
||||
border: false,
|
||||
title: _('Network'),
|
||||
layout: 'form'
|
||||
}, config);
|
||||
Deluge.preferences.Network.superclass.constructor.call(this, config);
|
||||
},
|
||||
|
||||
border: false,
|
||||
layout: 'form',
|
||||
title: _('Network'),
|
||||
|
||||
initComponent: function() {
|
||||
Deluge.preferences.Network.superclass.initComponent.call(this);
|
||||
var optMan = deluge.preferences.getOptionsManager();
|
||||
|
@ -76,7 +72,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
|
|||
}
|
||||
}));
|
||||
this.listenPorts = fieldset.add({
|
||||
xtype: 'uxspinnergroup',
|
||||
xtype: 'spinnergroup',
|
||||
name: 'listen_ports',
|
||||
fieldLabel: '',
|
||||
labelSeparator: '',
|
||||
|
@ -131,7 +127,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
|
|||
}
|
||||
}));
|
||||
this.outgoingPorts = fieldset.add({
|
||||
xtype: 'uxspinnergroup',
|
||||
xtype: 'spinnergroup',
|
||||
name: 'outgoing_ports',
|
||||
fieldLabel: '',
|
||||
labelSeparator: '',
|
||||
|
@ -236,4 +232,3 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
|
|||
}));
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Network());
|
|
@ -108,4 +108,3 @@ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, {
|
|||
}));
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Other());
|
|
@ -336,4 +336,3 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
|||
this.setInfo();
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Plugins());
|
|
@ -58,6 +58,8 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, {
|
|||
plain: true,
|
||||
resizable: false,
|
||||
|
||||
pages: {},
|
||||
|
||||
initComponent: function() {
|
||||
Deluge.preferences.PreferencesWindow.superclass.initComponent.call(this);
|
||||
|
||||
|
@ -104,10 +106,26 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, {
|
|||
this.addButton(_('Apply'), this.onApply, this);
|
||||
this.addButton(_('Ok'), this.onOk, this);
|
||||
|
||||
this.pages = {};
|
||||
this.optionsManager = new Deluge.OptionsManager();
|
||||
this.on('afterrender', this.onAfterRender, this);
|
||||
this.on('show', this.onShow, this);
|
||||
|
||||
this.initPages();
|
||||
},
|
||||
|
||||
initPages: function() {
|
||||
deluge.preferences = this;
|
||||
this.addPage(new Deluge.preferences.Downloads());
|
||||
//this.addPage(new Deluge.preferences.Network());
|
||||
this.addPage(new Deluge.preferences.Encryption());
|
||||
this.addPage(new Deluge.preferences.Bandwidth());
|
||||
this.addPage(new Deluge.preferences.Interface());
|
||||
this.addPage(new Deluge.preferences.Other());
|
||||
this.addPage(new Deluge.preferences.Daemon());
|
||||
this.addPage(new Deluge.preferences.Queue());
|
||||
this.addPage(new Deluge.preferences.Proxy());
|
||||
this.addPage(new Deluge.preferences.Cache());
|
||||
this.addPage(new Deluge.preferences.Plugins());
|
||||
},
|
||||
|
||||
onApply: function(e) {
|
||||
|
@ -142,6 +160,7 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, {
|
|||
var name = page.title;
|
||||
store.add([new PreferencesRecord({name: name})]);
|
||||
page['bodyStyle'] = 'margin: 5px';
|
||||
page.preferences = this;
|
||||
this.pages[name] = this.configPanel.add(page);
|
||||
return this.pages[name];
|
||||
},
|
||||
|
@ -211,4 +230,3 @@ Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, {
|
|||
this.hide();
|
||||
}
|
||||
});
|
||||
deluge.preferences = new Deluge.preferences.PreferencesWindow();
|
|
@ -236,4 +236,3 @@ Deluge.preferences.Proxy = Ext.extend(Ext.form.FormPanel, {
|
|||
this.fireEvent('change', this, newValues, oldValues);
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Proxy());
|
|
@ -223,4 +223,3 @@ Deluge.preferences.Queue = Ext.extend(Ext.form.FormPanel, {
|
|||
this.removeAtRatio.setDisabled(!checked);
|
||||
}
|
||||
});
|
||||
deluge.preferences.addPage(new Deluge.preferences.Queue());
|
|
@ -4,6 +4,8 @@
|
|||
* licensing@extjs.com
|
||||
* http://www.extjs.com/license
|
||||
*/
|
||||
Ext.ns('Ext.ux.tree');
|
||||
|
||||
/**
|
||||
* @class Ext.ux.tree.TreeGrid
|
||||
* @extends Ext.tree.TreePanel
|
||||
|
@ -404,4 +406,4 @@ Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
|
|||
}
|
||||
});
|
||||
|
||||
Ext.reg('treegrid', Ext.ux.tree.TreeGrid);
|
||||
Ext.reg('treegrid', Ext.ux.tree.TreeGrid);
|
||||
|
|
|
@ -38,6 +38,7 @@ import time
|
|||
import locale
|
||||
import shutil
|
||||
import urllib
|
||||
import fnmatch
|
||||
import gettext
|
||||
import hashlib
|
||||
import logging
|
||||
|
@ -240,7 +241,7 @@ class LookupResource(resource.Resource, component.Component):
|
|||
self.__paths = {}
|
||||
for directory in directories:
|
||||
self.addDirectory(directory)
|
||||
|
||||
|
||||
def addDirectory(self, directory, path=""):
|
||||
log.debug("Adding directory `%s` with path `%s`", directory, path)
|
||||
paths = self.__paths.setdefault(path, [])
|
||||
|
@ -267,7 +268,7 @@ class LookupResource(resource.Resource, component.Component):
|
|||
|
||||
filename = os.path.basename(request.path)
|
||||
for directory in self.__paths[path]:
|
||||
if filename in os.listdir(directory):
|
||||
if os.path.join(directory, filename):
|
||||
path = os.path.join(directory, filename)
|
||||
log.debug("Serving path: '%s'", path)
|
||||
mime_type = mimetypes.guess_type(path)
|
||||
|
@ -277,6 +278,131 @@ class LookupResource(resource.Resource, component.Component):
|
|||
request.setResponseCode(http.NOT_FOUND)
|
||||
return "<h1>404 - Not Found</h1>"
|
||||
|
||||
class ScriptResource(resource.Resource, component.Component):
|
||||
|
||||
def __init__(self):
|
||||
resource.Resource.__init__(self)
|
||||
component.Component.__init__(self, "Scripts")
|
||||
self.__scripts = {
|
||||
"normal": {
|
||||
"scripts": {},
|
||||
"order": []
|
||||
},
|
||||
"debug": {
|
||||
"scripts": {},
|
||||
"order": []
|
||||
},
|
||||
"dev": {
|
||||
"scripts": {},
|
||||
"order": []
|
||||
}
|
||||
}
|
||||
|
||||
def add_script(self, path, filepath, type=None):
|
||||
"""
|
||||
Adds a script or scripts to the script resource.
|
||||
|
||||
:param path: The path of the script (this supports globbing)
|
||||
:type path: string
|
||||
:param filepath: The physical location of the script
|
||||
:type filepath: string
|
||||
:keyword type: The type of script to add (normal, debug, dev)
|
||||
:param type: string
|
||||
"""
|
||||
if type not in ("dev", "debug", "normal"):
|
||||
type = "normal"
|
||||
|
||||
self.__scripts[type]["scripts"][path] = filepath
|
||||
self.__scripts[type]["order"].append(path)
|
||||
|
||||
def add_script_folder(self, path, filepath, type=None, recurse=True):
|
||||
"""
|
||||
Adds a folder of scripts to the script resource.
|
||||
|
||||
:param path: The path of the script (this supports globbing)
|
||||
:type path: string
|
||||
:param filepath: The physical location of the script
|
||||
:type filepath: string
|
||||
:keyword type: The type of script to add (normal, debug, dev)
|
||||
:param type: string
|
||||
:keyword recurse: Whether or not to recurse into other folders
|
||||
:param recurse: bool
|
||||
"""
|
||||
if type not in ("dev", "debug", "normal"):
|
||||
type = "normal"
|
||||
|
||||
self.__scripts[type]["scripts"][path] = (filepath, recurse)
|
||||
self.__scripts[type]["order"].append(path)
|
||||
|
||||
def get_scripts(self, type=None):
|
||||
"""
|
||||
Returns a list of the scripts that can be used for producing
|
||||
script tags.
|
||||
|
||||
:keyword type: The type of scripts to get (normal, debug, dev)
|
||||
:param type: string
|
||||
"""
|
||||
scripts = []
|
||||
if type not in ("dev", "debug", "normal"):
|
||||
type = 'normal'
|
||||
|
||||
_scripts = self.__scripts[type]["scripts"]
|
||||
_order = self.__scripts[type]["order"]
|
||||
|
||||
for path in _order:
|
||||
filepath = _scripts[path]
|
||||
|
||||
# this is a folder
|
||||
if isinstance(filepath, tuple):
|
||||
filepath, recurse = filepath
|
||||
if recurse:
|
||||
for dirpath, dirnames, filenames in os.walk(filepath, False):
|
||||
files = fnmatch.filter(filenames, "*.js")
|
||||
files.sort()
|
||||
dirpath = dirpath[len(filepath)+1:]
|
||||
if dirpath:
|
||||
scripts.extend(['js/' + path + '/' + dirpath + '/' + f for f in files])
|
||||
else:
|
||||
scripts.extend(['js/' + path + '/' + f for f in files])
|
||||
else:
|
||||
files = fnmatch.filter(os.listdir('.'), "*.js")
|
||||
else:
|
||||
scripts.append("js/" + path)
|
||||
return scripts
|
||||
|
||||
def getChild(self, path, request):
|
||||
if hasattr(request, "lookup_path"):
|
||||
request.lookup_path = os.path.join(request.lookup_path, path)
|
||||
else:
|
||||
request.lookup_path = path
|
||||
return self
|
||||
|
||||
def render(self, request):
|
||||
log.debug("Requested path: '%s'", request.lookup_path)
|
||||
|
||||
for type in ("dev", "debug", "normal"):
|
||||
scripts = self.__scripts[type]["scripts"]
|
||||
for pattern in scripts:
|
||||
if not request.lookup_path.startswith(pattern):
|
||||
continue
|
||||
|
||||
filepath = scripts[pattern]
|
||||
if isinstance(filepath, tuple):
|
||||
filepath = filepath[0]
|
||||
|
||||
path = filepath + request.lookup_path[len(pattern):]
|
||||
|
||||
if not os.path.isfile(path):
|
||||
continue
|
||||
|
||||
log.debug("Serving path: '%s'", path)
|
||||
mime_type = mimetypes.guess_type(path)
|
||||
request.setHeader("content-type", mime_type[0])
|
||||
return compress(open(path, "rb").read(), request)
|
||||
|
||||
request.setResponseCode(http.NOT_FOUND)
|
||||
return "<h1>404 - Not Found</h1>"
|
||||
|
||||
class TopLevel(resource.Resource):
|
||||
addSlash = True
|
||||
|
||||
|
@ -286,89 +412,6 @@ class TopLevel(resource.Resource):
|
|||
"css/deluge.css"
|
||||
]
|
||||
|
||||
__scripts = [
|
||||
"js/ext-base.js",
|
||||
"js/ext-all.js",
|
||||
"js/ext-extensions.js",
|
||||
"config.js",
|
||||
"gettext.js",
|
||||
"js/deluge-all.js"
|
||||
]
|
||||
|
||||
__debug_scripts = [
|
||||
"js/ext-base-debug.js",
|
||||
"js/ext-all-debug.js",
|
||||
"js/ext-extensions-debug.js",
|
||||
"config.js",
|
||||
"gettext.js",
|
||||
"js/deluge-all-debug.js"
|
||||
]
|
||||
|
||||
__dev_scripts = [
|
||||
"js/ext-base-debug.js",
|
||||
"js/ext-all-debug.js",
|
||||
"js/ext-extensions/BufferView.js",
|
||||
"js/ext-extensions/FileUploadField.js",
|
||||
"js/ext-extensions/JSLoader.js",
|
||||
"js/ext-extensions/Spinner.js",
|
||||
"js/ext-extensions/SpinnerField.js",
|
||||
"js/ext-extensions/StatusBar.js",
|
||||
"js/ext-extensions/ToggleField.js",
|
||||
"js/ext-extensions/TreeGridSorter.js",
|
||||
"js/ext-extensions/TreeGridColumnResizer.js",
|
||||
"js/ext-extensions/TreeGridNodeUI.js",
|
||||
"js/ext-extensions/TreeGridLoader.js",
|
||||
"js/ext-extensions/TreeGridColumns.js",
|
||||
"js/ext-extensions/TreeGridRenderColumn.js",
|
||||
"js/ext-extensions/TreeGrid.js",
|
||||
"gettext.js",
|
||||
"js/deluge-all/Deluge.js",
|
||||
"js/deluge-all/Deluge.Formatters.js",
|
||||
"js/deluge-all/Deluge.Menus.js",
|
||||
"js/deluge-all/Deluge.data.SortTypes.js",
|
||||
"js/deluge-all/Deluge.EventsManager.js",
|
||||
"js/deluge-all/Deluge.OptionsManager.js",
|
||||
"js/deluge-all/Deluge.MultiOptionsManager.js",
|
||||
"js/deluge-all/Deluge.data.Peer.js",
|
||||
"js/deluge-all/Deluge.data.Torrent.js",
|
||||
"js/deluge-all/Deluge.Add.js",
|
||||
"js/deluge-all/Deluge.Add.File.js",
|
||||
"js/deluge-all/Deluge.Add.Url.js",
|
||||
"js/deluge-all/Deluge.Add.Infohash.js",
|
||||
"js/deluge-all/Deluge.Client.js",
|
||||
"js/deluge-all/Deluge.ConnectionManager.js",
|
||||
"js/deluge-all/Deluge.Details.js",
|
||||
"js/deluge-all/Deluge.Details.Status.js",
|
||||
"js/deluge-all/Deluge.Details.Details.js",
|
||||
"js/deluge-all/Deluge.Details.Files.js",
|
||||
"js/deluge-all/Deluge.Details.Peers.js",
|
||||
"js/deluge-all/Deluge.Details.Options.js",
|
||||
"js/deluge-all/Deluge.EditTrackers.js",
|
||||
"js/deluge-all/Deluge.FileBrowser.js",
|
||||
"js/deluge-all/Deluge.Keys.js",
|
||||
"js/deluge-all/Deluge.Login.js",
|
||||
"js/deluge-all/Deluge.MoveStorage.js",
|
||||
"js/deluge-all/Deluge.Plugin.js",
|
||||
"js/deluge-all/Deluge.Preferences.js",
|
||||
"js/deluge-all/Deluge.Preferences.Downloads.js",
|
||||
#"js/deluge-all/Deluge.Preferences.Network.js",
|
||||
"js/deluge-all/Deluge.Preferences.Encryption.js",
|
||||
"js/deluge-all/Deluge.Preferences.Bandwidth.js",
|
||||
"js/deluge-all/Deluge.Preferences.Interface.js",
|
||||
"js/deluge-all/Deluge.Preferences.Other.js",
|
||||
"js/deluge-all/Deluge.Preferences.Daemon.js",
|
||||
"js/deluge-all/Deluge.Preferences.Queue.js",
|
||||
"js/deluge-all/Deluge.Preferences.Proxy.js",
|
||||
"js/deluge-all/Deluge.Preferences.Cache.js",
|
||||
"js/deluge-all/Deluge.Preferences.Plugins.js",
|
||||
"js/deluge-all/Deluge.Remove.js",
|
||||
"js/deluge-all/Deluge.Sidebar.js",
|
||||
"js/deluge-all/Deluge.Statusbar.js",
|
||||
"js/deluge-all/Deluge.Toolbar.js",
|
||||
"js/deluge-all/Deluge.Torrents.js",
|
||||
"js/deluge-all/Deluge.UI.js"
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
resource.Resource.__init__(self)
|
||||
self.putChild("css", LookupResource("Css", rpath("css")))
|
||||
|
@ -377,10 +420,26 @@ class TopLevel(resource.Resource):
|
|||
self.putChild("icons", LookupResource("Icons", rpath("icons")))
|
||||
self.putChild("images", LookupResource("Images", rpath("images")))
|
||||
|
||||
# Add the javascript resource with the development paths
|
||||
js = LookupResource("Javascript", rpath("js"))
|
||||
js.addDirectory(rpath("js", "ext-extensions"), "ext-extensions")
|
||||
js.addDirectory(rpath("js", "deluge-all"), "deluge-all")
|
||||
js = ScriptResource()
|
||||
|
||||
# configure the dev scripts
|
||||
js.add_script("ext-base.js", rpath("js", "ext-base-debug.js"), "dev")
|
||||
js.add_script("ext-all.js", rpath("js", "ext-all-debug.js"), "dev")
|
||||
js.add_script_folder("ext-extensions", rpath("js", "ext-extensions"), "dev")
|
||||
js.add_script_folder("deluge-all", rpath("js", "deluge-all"), "dev")
|
||||
|
||||
# configure the debug scripts
|
||||
js.add_script("ext-base.js", rpath("js", "ext-base-debug.js"), "debug")
|
||||
js.add_script("ext-all.js", rpath("js", "ext-all-debug.js"), "debug")
|
||||
js.add_script("ext-extensions.js", rpath("js", "ext-extensions-debug.js"), "debug")
|
||||
js.add_script("deluge-all.js", rpath("js", "deluge-all-debug.js"), "debug")
|
||||
|
||||
# configure the normal scripts
|
||||
js.add_script("ext-base.js", rpath("js", "ext-base.js"), "debug")
|
||||
js.add_script("ext-all.js", rpath("js", "ext-all.js"), "debug")
|
||||
js.add_script("ext-extensions.js", rpath("js", "ext-extensions.js"), "debug")
|
||||
js.add_script("deluge-all.js", rpath("js", "deluge-all.js"), "debug")
|
||||
|
||||
self.putChild("js", js)
|
||||
|
||||
self.putChild("json", JSON())
|
||||
|
@ -457,11 +516,14 @@ class TopLevel(resource.Resource):
|
|||
dev = False
|
||||
|
||||
if dev:
|
||||
scripts = self.dev_scripts[:]
|
||||
mode = 'dev'
|
||||
elif debug:
|
||||
scripts = self.debug_scripts[:]
|
||||
mode = 'debug'
|
||||
else:
|
||||
scripts = self.scripts[:]
|
||||
mode = None
|
||||
|
||||
scripts = component.get("Scripts").get_scripts(mode)
|
||||
scripts.insert(0, "gettext.js")
|
||||
|
||||
template = Template(filename=rpath("index.html"))
|
||||
request.setHeader("content-type", "text/html; charset=utf-8")
|
||||
|
@ -484,12 +546,7 @@ class TopLevel(resource.Resource):
|
|||
web_config = component.get("Web").get_config()
|
||||
web_config["base"] = base
|
||||
config = dict([(key, web_config[key]) for key in UI_CONFIG_KEYS])
|
||||
js_config = """deluge = {
|
||||
author: 'Damien Churchill <damoxc@gmail.com>',
|
||||
version: '%s',
|
||||
config: %s
|
||||
}""" % (common.get_version(), common.json.dumps(config))
|
||||
|
||||
js_config = common.json.dumps(config)
|
||||
return template.render(scripts=scripts, stylesheets=self.stylesheets,
|
||||
debug=debug, base=base, js_config=js_config)
|
||||
|
||||
|
|
Loading…
Reference in New Issue