plugin-javascript

This commit is contained in:
Martijn Voncken 2008-10-28 22:20:38 +00:00
parent 1945674c0a
commit d4dec67fc4
10 changed files with 78 additions and 29 deletions

View File

@ -39,6 +39,11 @@ class PluginBase:
def enable(self):
try:
log.debug(0)
if hasattr(self.plugin, "base_enable"):
log.debug(1)
self.plugin.base_enable()
log.debug(2)
self.plugin.enable()
except Exception, e:
log.warning("Unable to enable plugin: %s", e)
@ -48,6 +53,8 @@ class PluginBase:
def disable(self):
try:
if hasattr(self.plugin, "base_disable"):
self.plugin.base_disable()
self.plugin.disable()
except Exception, e:
log.warning("Unable to disable plugin: %s", e)

View File

@ -0,0 +1,2 @@
/*testing include_javascript*/
window.alert("test-plugin-javascript");

View File

@ -40,19 +40,20 @@ import ui
import config
import pages
from deluge.plugins.webuipluginbase import WebUIPluginBase
class WebUI(ui.UI):
def __init__(self, plugin_api, plugin_name):
log.debug("Calling UI init")
# Call UI constructor
ui.UI.__init__(self, plugin_api, plugin_name)
log.debug("Label WebUI plugin initalized..")
#TODO: use more additions to WebUIPluginBase, thish whould be and example -lougin.
class WebUI(WebUIPluginBase):
include_javascript = ["/label/data/test1.js"]
def enable(self):
log.debug("**HERE**")
pages.register()
config.register()
def disable(self):
log.debug("**HERE**")
pages.deregister()
config.deregister()

View File

@ -58,7 +58,7 @@ setup(
license=__license__,
long_description=__long_description__,
packages=[__plugin_name__.lower()],
packages=[__plugin_name__.lower(), "label.gtkui", "label.webui"],
package_data = __pkg_data__,
entry_points="""

View File

@ -45,23 +45,50 @@ class WebUIPluginBase:
* templates: /template are added to api.render.plugin-name.
* pages: urls attribute registers pages : urls = [(url, class), ..]
"""
urls= []
include_javascript = []
ajax_javascript = []
urls = []
def __init__(self, plugin_api, plugin_name):
log.debug("%s plugin : start initalize.." % plugin_name)
self.plugin = plugin_api
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:
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
resource = clean_plugin_name
resource = self.clean_plugin_name
base_path = "data"
#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)

View File

@ -2,7 +2,7 @@ import time
import gobject
import os
from deluge.tracker_icons import TrackerIcons
from deluge.ui.tracker_icons import TrackerIcons
from deluge.common import get_default_config_dir
def del_old():

View File

@ -112,6 +112,8 @@ class PageManager(component.Component):
component.Component.__init__(self, "PageManager")
self.page_classes = {}
self.urls = []
self.include_javascript = []
self.ajax_javascript = []
def register_pages(self, url_list, class_list):
self.urls += url_list
@ -200,14 +202,15 @@ class PluginApi(component.Component):
self.utils = utils
def register():
__page_manager = PageManager()
__plugin_manager = PluginManager()
__menu_manager = MenuManager()
__page_manager = PageManager()
__config_page_manager = ConfigPageManager()
__plugin_api = PluginApi()
if __name__ == "__main__":
register()

View File

@ -35,11 +35,14 @@ from utils import *
import utils
#/relative
from deluge import common
from deluge import component
from web import template, Storage
import os
from deluge.configmanager import ConfigManager
config = ConfigManager("webui06.conf")
page_manager = component.get("PageManager")
class subclassed_render(object):
"""
@ -212,7 +215,9 @@ template.Template.globals.update({
'forms':web.Storage(),
'enumerate':enumerate,
'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

View File

@ -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="stylesheet" type="text/css" href="$base/template_style.css" />
<script language="javascript" src="$base/static/deluge.js"></script>
$for js in include_javascript:
<script language="javascript" src="$base$js"></script>
</head>
<body>

View File

@ -26,13 +26,15 @@ $if get_config("show_keyword_search"):
$filter_items
-->
$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>
$for value, count in filter_items[cat]:
<li
<li id="label_$(cat)_$(value)"
$if cat == get('filter_cat'):
$if value == get('filter_value'):
class="selected"
class="selected label_$cat"
$else:
class="label_$cat"
$# I hate this, special case for All
$# templetor sucks with multiple conditions in 1 if-statement, i need to find a better way,
$if cat == "state":