javascript auto-refresh

This commit is contained in:
Martijn Voncken 2008-11-05 21:16:15 +00:00
parent 21d707fa92
commit 09c5236a4b
10 changed files with 104 additions and 40 deletions

View File

@ -58,16 +58,6 @@ class WebCfgForm(forms.Form):
config.set(key, value)
config.save()
class CookieCfgForm(forms.Form):
"config base for webui"
def initial_data(self):
return dict(config)
def save(self, data):
config.update(data)
config.save_config()
class CfgForm(forms.Form):
"config base for deluge-cfg"
def initial_data(self):

View File

@ -54,6 +54,7 @@ class Template(config_forms.WebCfgForm):
template = forms.ChoiceField( label=_("Template"), choices = _templates)
button_style = forms.IntChoiceField(_("Button style"),_button_choices)
refresh_secs = forms.IntegerField(label= _("Auto refresh (seconds)"), min_value=2, max_value=60*60)
cache_templates = forms.CheckBox(_("Cache templates"))
def post_save(self):

View File

@ -20,10 +20,11 @@ def deluge_page_noauth(func):
add http headers;print result of func
"""
def deco(self, name = None):
web.header("Content-Type", "text/html; charset=utf-8")
web.header("Cache-Control", "no-cache, must-revalidate")
res = func(self, name) #deluge_page_noauth
print res
render.set_global("is_auto_refreshed", False);
web.header("Content-Type", "text/html; charset=utf-8")
web.header("Cache-Control", "no-cache, must-revalidate")
res = func(self, name) #deluge_page_noauth
print res
deco.__name__ = func.__name__
return deco
@ -112,11 +113,12 @@ def torrent(func):
return deco
def auto_refreshed(func):
"adds a refresh header"
""""
sets 'is_auto_refreshed' global for templates
note : decorate AFTER deluge_page_*
"""
def deco(self, name = None):
if getcookie('auto_refresh') == '1':
web.header("Refresh", "%i ; url=%s" %
(int(getcookie('auto_refresh_secs',10)),self_url()))
render.set_global("is_auto_refreshed", True);
return func(self, name) #auto_refreshed
deco.__name__ = func.__name__
return deco

View File

@ -217,7 +217,8 @@ template.Template.globals.update({
'base':'', #updated when running within apache.
'id_to_label':id_to_label,
'include_javascript':page_manager.include_javascript,
'ajax_javascript':page_manager.include_javascript
'ajax_javascript':page_manager.include_javascript,
'is_auto_refreshed':False
})
#/template-defs

View File

@ -0,0 +1,56 @@
/*
(c) Martijn Voncken mvoncken@gmail.com
License : GPLv3
quick and dirty auto-refresh timer.
Our users have waited too long for a new auto-refresh.
I need to get things done (even if it's ot pretty). ;with the least dependencies for a backport to 1.05
*/
var seconds=0;
var refresh_secs = 10;
var prc = 0;
var timer_active = 0;
function continue_timer(){
if (!timer_active) {
return;
}
seconds+=0.1;
if (seconds > refresh_secs){
timer_active = 0;
do_refresh();
}
prc = ((seconds / refresh_secs) * 100 );
el("timer_bar").style.width = prc + "%";
setTimeout("continue_timer()",100)
}
function do_refresh(){
location.reload(true);
}
function start_timer(){
timer_active = 1;
continue_timer();
el("timer_pause").style.display = "none";
el("timer_start").style.display = "inline";
el("timer_outer").title = "Auto refresh:Active; click here to pause";
setCookie('auto_refresh',"1");
}
function stop_timer(){
timer_active = 0;
el("timer_pause").style.display = "inline";
el("timer_start").style.display = "none";
el("timer_outer").title = "Auto refresh:Paused; click here to start";
setCookie('auto_refresh',"0");
}
function toggle_timer() {
if (timer_active) {
stop_timer();
}
else {
start_timer();
}
}

View File

@ -8,6 +8,7 @@ $def with (title, active_tab="NONE")
<!--javascript is only used for plugins in the classic-ui
classic ui should function without js.
-->
<script language="javascript" src="$base/static/deluge.js"></script>
<script language="javascript" src="$base/gettext.js"></script>
<script language="javascript" src="$base/static/mootools-1.2-core.js"></script>
<script language="javascript" src="$base/static/mootools-1.2-more.js"></script>
@ -46,9 +47,13 @@ $for id, title, url in admin_pages:
class="tab_button"
href='$base$url'>$title</a>
<a href="http://dev.deluge-torrent.org/wiki/Faq">Faq</a>
$if is_auto_refreshed:
<div style="position:absolute;right:20px;top:10px;width:120px;height:20px;overflow:hidden">
$:render.part_auto_refresh()
</div>
</div>
<div id="main_content">
<div id="main">
<center>

View File

@ -0,0 +1,24 @@
<script language="javascript" src="$base/static/refresh.js"></script>
<div class="progress_bar_outer"
id = "timer_outer"
style="width:100px;background-color:#EEE;margin-top:3px;"
title="$_('Auto Refresh')"
onclick="toggle_timer()"
>
<div id="timer_bar" class="progress_bar" style="width:0%" style="text-align:left">
<img src="$base/static/images/tango/pause.png" id="timer_pause" >
<img src="$base/static/images/tango/view-refresh.png" id="timer_start" style="display:none">
&nbsp;
</div>
</div>
<script language="javascript">
refresh_secs = $get_config("refresh_secs")
if (getCookie('auto_refresh') == "1") {
start_timer();
}
else {
stop_timer();
}
</script>

View File

@ -47,8 +47,8 @@ $for id, title, url in admin_pages:
</div>
</td><td align="left">
$:render.part_auto_refresh()
$if is_auto_refreshed:
$:render.part_auto_refresh()
</td><td>
</td><td align="right">

View File

@ -1,16 +0,0 @@
<div class="panel" id='refresh_panel'>
[
$_('Auto refresh:')
$if getcookie('auto_refresh') == '1':
($getcookie('auto_refresh_secs')) $_('seconds') &nbsp;
<a href="$base/refresh/set">$_('Set')</a>
<a href="$base/refresh/off">$_('Disable')</a><!--WRONG, setting things on a GET-->
$else:
$_('Off') &nbsp;
<a href="$base/refresh/on">$_('Enable')</a><!--WRONG, setting things on a GET-->
]
<a href="$base/config/">$_('Admin') </a>&nbsp;
</div>

View File

@ -66,5 +66,6 @@ CONFIG_DEFAULTS = {
"sidebar_show_trackers":False,
"show_keyword_search":False,
"show_sidebar":True,
"https":False
"https":False,
"refresh_secs":10
}