mirror of
https://git.deluge-torrent.org/deluge
synced 2025-09-18 15:51:57 +00:00
plugin-javascript
This commit is contained in:
parent
1945674c0a
commit
d4dec67fc4
10 changed files with 78 additions and 29 deletions
|
@ -39,6 +39,11 @@ class PluginBase:
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
try:
|
try:
|
||||||
|
log.debug(0)
|
||||||
|
if hasattr(self.plugin, "base_enable"):
|
||||||
|
log.debug(1)
|
||||||
|
self.plugin.base_enable()
|
||||||
|
log.debug(2)
|
||||||
self.plugin.enable()
|
self.plugin.enable()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to enable plugin: %s", e)
|
log.warning("Unable to enable plugin: %s", e)
|
||||||
|
@ -48,6 +53,8 @@ class PluginBase:
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
try:
|
try:
|
||||||
|
if hasattr(self.plugin, "base_disable"):
|
||||||
|
self.plugin.base_disable()
|
||||||
self.plugin.disable()
|
self.plugin.disable()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.warning("Unable to disable plugin: %s", e)
|
log.warning("Unable to disable plugin: %s", e)
|
||||||
|
|
2
deluge/plugins/label/label/data/test1.js
Normal file
2
deluge/plugins/label/label/data/test1.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*testing include_javascript*/
|
||||||
|
window.alert("test-plugin-javascript");
|
|
@ -40,19 +40,20 @@ import ui
|
||||||
|
|
||||||
import config
|
import config
|
||||||
import pages
|
import pages
|
||||||
|
from deluge.plugins.webuipluginbase import WebUIPluginBase
|
||||||
|
|
||||||
class WebUI(ui.UI):
|
|
||||||
def __init__(self, plugin_api, plugin_name):
|
#TODO: use more additions to WebUIPluginBase, thish whould be and example -lougin.
|
||||||
log.debug("Calling UI init")
|
class WebUI(WebUIPluginBase):
|
||||||
# Call UI constructor
|
include_javascript = ["/label/data/test1.js"]
|
||||||
ui.UI.__init__(self, plugin_api, plugin_name)
|
|
||||||
log.debug("Label WebUI plugin initalized..")
|
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
|
log.debug("**HERE**")
|
||||||
pages.register()
|
pages.register()
|
||||||
config.register()
|
config.register()
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
|
log.debug("**HERE**")
|
||||||
pages.deregister()
|
pages.deregister()
|
||||||
config.deregister()
|
config.deregister()
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ setup(
|
||||||
license=__license__,
|
license=__license__,
|
||||||
long_description=__long_description__,
|
long_description=__long_description__,
|
||||||
|
|
||||||
packages=[__plugin_name__.lower()],
|
packages=[__plugin_name__.lower(), "label.gtkui", "label.webui"],
|
||||||
package_data = __pkg_data__,
|
package_data = __pkg_data__,
|
||||||
|
|
||||||
entry_points="""
|
entry_points="""
|
||||||
|
|
|
@ -45,23 +45,50 @@ class WebUIPluginBase:
|
||||||
* templates: /template are added to api.render.plugin-name.
|
* templates: /template are added to api.render.plugin-name.
|
||||||
* pages: urls attribute registers pages : urls = [(url, class), ..]
|
* pages: urls attribute registers pages : urls = [(url, class), ..]
|
||||||
"""
|
"""
|
||||||
urls= []
|
include_javascript = []
|
||||||
|
ajax_javascript = []
|
||||||
|
urls = []
|
||||||
|
|
||||||
def __init__(self, plugin_api, plugin_name):
|
def __init__(self, plugin_api, plugin_name):
|
||||||
log.debug("%s plugin : start initalize.." % plugin_name)
|
log.debug("%s plugin : start initalize.." % plugin_name)
|
||||||
|
|
||||||
self.plugin = plugin_api
|
self.plugin = plugin_api
|
||||||
self.plugin_name = plugin_name
|
self.plugin_name = plugin_name
|
||||||
clean_plugin_name = plugin_name.lower().replace(" ","_")
|
self.clean_plugin_name = plugin_name.lower().replace(" ","_")
|
||||||
|
|
||||||
|
|
||||||
|
def base_enable(self):
|
||||||
|
"""
|
||||||
|
enable plugin.
|
||||||
|
"""
|
||||||
for url , klass in self.urls:
|
for url , klass in self.urls:
|
||||||
api.page_manager.register_page(url, klass)
|
api.page_manager.register_page(url, klass)
|
||||||
|
|
||||||
|
for js in self.include_javascript:
|
||||||
|
api.page_manager.include_javascript.append(js)
|
||||||
|
|
||||||
class egg_data_static(api.egg_handler): #serves files in /data from egg
|
class egg_data_static(api.egg_handler): #serves files in /data from egg
|
||||||
resource = clean_plugin_name
|
resource = self.clean_plugin_name
|
||||||
base_path = "data"
|
base_path = "data"
|
||||||
|
|
||||||
#use as : api.render.plugin-name.template-name[excluding.html](parameters)
|
#use as : api.render.plugin-name.template-name[excluding.html](parameters)
|
||||||
setattr(api.render, clean_plugin_name, api.egg_render(clean_plugin_name, "template"))
|
setattr(api.render, self.clean_plugin_name, api.egg_render(self.clean_plugin_name, "template"))
|
||||||
|
|
||||||
|
api.page_manager.register_page("/%s/data/(.*)" % self.clean_plugin_name , egg_data_static)
|
||||||
|
|
||||||
|
log.debug("%s plugin : end base_enable().." % self.plugin_name)
|
||||||
|
|
||||||
|
def base_disable(self):
|
||||||
|
"""
|
||||||
|
disable plugin.
|
||||||
|
"""
|
||||||
|
for url , klass in self.urls:
|
||||||
|
api.page_manager.deregister_page(url, klass)
|
||||||
|
|
||||||
|
for js in self.include_javascript:
|
||||||
|
api.page_manager.include_javascript.remove(js)
|
||||||
|
|
||||||
|
log.debug("%s plugin : end base_disable().." % self.plugin_name)
|
||||||
|
|
||||||
|
|
||||||
api.page_manager.register_page("/%s/data/(.*)" % clean_plugin_name , egg_data_static)
|
|
||||||
|
|
||||||
log.debug("%s plugin : end initalize.." % plugin_name)
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import time
|
||||||
import gobject
|
import gobject
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from deluge.tracker_icons import TrackerIcons
|
from deluge.ui.tracker_icons import TrackerIcons
|
||||||
from deluge.common import get_default_config_dir
|
from deluge.common import get_default_config_dir
|
||||||
|
|
||||||
def del_old():
|
def del_old():
|
||||||
|
|
|
@ -112,6 +112,8 @@ class PageManager(component.Component):
|
||||||
component.Component.__init__(self, "PageManager")
|
component.Component.__init__(self, "PageManager")
|
||||||
self.page_classes = {}
|
self.page_classes = {}
|
||||||
self.urls = []
|
self.urls = []
|
||||||
|
self.include_javascript = []
|
||||||
|
self.ajax_javascript = []
|
||||||
|
|
||||||
def register_pages(self, url_list, class_list):
|
def register_pages(self, url_list, class_list):
|
||||||
self.urls += url_list
|
self.urls += url_list
|
||||||
|
@ -200,14 +202,15 @@ class PluginApi(component.Component):
|
||||||
self.utils = utils
|
self.utils = utils
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
|
__page_manager = PageManager()
|
||||||
__plugin_manager = PluginManager()
|
__plugin_manager = PluginManager()
|
||||||
__menu_manager = MenuManager()
|
__menu_manager = MenuManager()
|
||||||
__page_manager = PageManager()
|
|
||||||
__config_page_manager = ConfigPageManager()
|
__config_page_manager = ConfigPageManager()
|
||||||
__plugin_api = PluginApi()
|
__plugin_api = PluginApi()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
register()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,14 @@ from utils import *
|
||||||
import utils
|
import utils
|
||||||
#/relative
|
#/relative
|
||||||
from deluge import common
|
from deluge import common
|
||||||
|
from deluge import component
|
||||||
from web import template, Storage
|
from web import template, Storage
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
config = ConfigManager("webui06.conf")
|
config = ConfigManager("webui06.conf")
|
||||||
|
page_manager = component.get("PageManager")
|
||||||
|
|
||||||
|
|
||||||
class subclassed_render(object):
|
class subclassed_render(object):
|
||||||
"""
|
"""
|
||||||
|
@ -212,7 +215,9 @@ template.Template.globals.update({
|
||||||
'forms':web.Storage(),
|
'forms':web.Storage(),
|
||||||
'enumerate':enumerate,
|
'enumerate':enumerate,
|
||||||
'base':'', #updated when running within apache.
|
'base':'', #updated when running within apache.
|
||||||
'id_to_label':id_to_label
|
'id_to_label':id_to_label,
|
||||||
|
'include_javascript':page_manager.include_javascript,
|
||||||
|
'ajax_javascript':page_manager.include_javascript
|
||||||
})
|
})
|
||||||
#/template-defs
|
#/template-defs
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ $def with (title, active_tab="NONE")
|
||||||
<link rel="shortcut icon" href="$base/static/images/deluge-icon.png" type="image/png" />
|
<link rel="shortcut icon" href="$base/static/images/deluge-icon.png" type="image/png" />
|
||||||
<link rel="stylesheet" type="text/css" href="$base/template_style.css" />
|
<link rel="stylesheet" type="text/css" href="$base/template_style.css" />
|
||||||
<script language="javascript" src="$base/static/deluge.js"></script>
|
<script language="javascript" src="$base/static/deluge.js"></script>
|
||||||
|
$for js in include_javascript:
|
||||||
|
<script language="javascript" src="$base$js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
|
@ -26,13 +26,15 @@ $if get_config("show_keyword_search"):
|
||||||
$filter_items
|
$filter_items
|
||||||
-->
|
-->
|
||||||
$for cat in filter_items.keys():
|
$for cat in filter_items.keys():
|
||||||
<div class="title">$id_to_label(cat)</div>
|
<div class="title" id="label_cat_$cat">$id_to_label(cat)</div>
|
||||||
<ul>
|
<ul>
|
||||||
$for value, count in filter_items[cat]:
|
$for value, count in filter_items[cat]:
|
||||||
<li
|
<li id="label_$(cat)_$(value)"
|
||||||
$if cat == get('filter_cat'):
|
$if cat == get('filter_cat'):
|
||||||
$if value == get('filter_value'):
|
$if value == get('filter_value'):
|
||||||
class="selected"
|
class="selected label_$cat"
|
||||||
|
$else:
|
||||||
|
class="label_$cat"
|
||||||
$# I hate this, special case for All
|
$# I hate this, special case for All
|
||||||
$# templetor sucks with multiple conditions in 1 if-statement, i need to find a better way,
|
$# templetor sucks with multiple conditions in 1 if-statement, i need to find a better way,
|
||||||
$if cat == "state":
|
$if cat == "state":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue