fixed the collapse function, refactored LOAD() to use new web2py.js

This commit is contained in:
niphlod
2013-06-27 22:31:11 +02:00
parent 81fa9b1984
commit 917d2087c5
4 changed files with 55 additions and 16 deletions
+15 -2
View File
@@ -20,7 +20,7 @@
if(window.focus) newwindow.focus(); if(window.focus) newwindow.focus();
return false; return false;
}, },
collapse: function () { collapse: function (id) {
$('#' + id).slideToggle(); $('#' + id).slideToggle();
}, },
fade: function (id, value) { fade: function (id, value) {
@@ -144,6 +144,7 @@
web2py.manage_errors(target); web2py.manage_errors(target);
web2py.ajax_fields(target); web2py.ajax_fields(target);
web2py.show_if_handler(target); web2py.show_if_handler(target);
web2py.component_handler(target);
}, },
//manage errors in forms //manage errors in forms
manage_errors: function(target) { manage_errors: function(target) {
@@ -275,7 +276,7 @@
var jelement = $("#" + target); var jelement = $("#" + target);
var element = jelement.get(0); var element = jelement.get(0);
var statement = "jQuery('#" + target + "').get(0).reload();"; var statement = "jQuery('#" + target + "').get(0).reload();";
jelement.reload = function () { element.reload = function () {
// Continue if times is Infinity or // Continue if times is Infinity or
// the times limit is not reached // the times limit is not reached
if(element.reload_check()) { if(element.reload_check()) {
@@ -484,6 +485,18 @@
show_if.call($('#' + name, target)); show_if.call($('#' + name, target));
}; };
}, },
component_handler : function (target) {
$('div[data-w2p_remote]', target).each(function () {
var remote, times, timeout, target;
var el = $(this);
remote = el.data('w2p_remote');
times = el.data('w2p_times');
timeout = el.data('w2p_timeout');
target = el.attr('id');
web2py.component(remote, target, timeout, times, $(this));
}
)
},
a_handler: function (el, e) { a_handler: function (el, e) {
e.preventDefault(); e.preventDefault();
var method = el.data('w2p_method'); var method = el.data('w2p_method');
+15 -2
View File
@@ -20,7 +20,7 @@
if(window.focus) newwindow.focus(); if(window.focus) newwindow.focus();
return false; return false;
}, },
collapse: function () { collapse: function (id) {
$('#' + id).slideToggle(); $('#' + id).slideToggle();
}, },
fade: function (id, value) { fade: function (id, value) {
@@ -144,6 +144,7 @@
web2py.manage_errors(target); web2py.manage_errors(target);
web2py.ajax_fields(target); web2py.ajax_fields(target);
web2py.show_if_handler(target); web2py.show_if_handler(target);
web2py.component_handler(target);
}, },
//manage errors in forms //manage errors in forms
manage_errors: function(target) { manage_errors: function(target) {
@@ -275,7 +276,7 @@
var jelement = $("#" + target); var jelement = $("#" + target);
var element = jelement.get(0); var element = jelement.get(0);
var statement = "jQuery('#" + target + "').get(0).reload();"; var statement = "jQuery('#" + target + "').get(0).reload();";
jelement.reload = function () { element.reload = function () {
// Continue if times is Infinity or // Continue if times is Infinity or
// the times limit is not reached // the times limit is not reached
if(element.reload_check()) { if(element.reload_check()) {
@@ -484,6 +485,18 @@
show_if.call($('#' + name, target)); show_if.call($('#' + name, target));
}; };
}, },
component_handler : function (target) {
$('div[data-w2p_remote]', target).each(function () {
var remote, times, timeout, target;
var el = $(this);
remote = el.data('w2p_remote');
times = el.data('w2p_times');
timeout = el.data('w2p_timeout');
target = el.attr('id');
web2py.component(remote, target, timeout, times, $(this));
}
)
},
a_handler: function (el, e) { a_handler: function (el, e) {
e.preventDefault(); e.preventDefault();
var method = el.data('w2p_method'); var method = el.data('w2p_method');
+15 -2
View File
@@ -20,7 +20,7 @@
if(window.focus) newwindow.focus(); if(window.focus) newwindow.focus();
return false; return false;
}, },
collapse: function () { collapse: function (id) {
$('#' + id).slideToggle(); $('#' + id).slideToggle();
}, },
fade: function (id, value) { fade: function (id, value) {
@@ -144,6 +144,7 @@
web2py.manage_errors(target); web2py.manage_errors(target);
web2py.ajax_fields(target); web2py.ajax_fields(target);
web2py.show_if_handler(target); web2py.show_if_handler(target);
web2py.component_handler(target);
}, },
//manage errors in forms //manage errors in forms
manage_errors: function(target) { manage_errors: function(target) {
@@ -275,7 +276,7 @@
var jelement = $("#" + target); var jelement = $("#" + target);
var element = jelement.get(0); var element = jelement.get(0);
var statement = "jQuery('#" + target + "').get(0).reload();"; var statement = "jQuery('#" + target + "').get(0).reload();";
jelement.reload = function () { element.reload = function () {
// Continue if times is Infinity or // Continue if times is Infinity or
// the times limit is not reached // the times limit is not reached
if(element.reload_check()) { if(element.reload_check()) {
@@ -484,6 +485,18 @@
show_if.call($('#' + name, target)); show_if.call($('#' + name, target));
}; };
}, },
component_handler : function (target) {
$('div[data-w2p_remote]', target).each(function () {
var remote, times, timeout, target;
var el = $(this);
remote = el.data('w2p_remote');
times = el.data('w2p_times');
timeout = el.data('w2p_timeout');
target = el.attr('id');
web2py.component(remote, target, timeout, times, $(this));
}
)
},
a_handler: function (el, e) { a_handler: function (el, e) {
e.preventDefault(); e.preventDefault();
var method = el.data('w2p_method'); var method = el.data('w2p_method');
+10 -10
View File
@@ -167,15 +167,15 @@ def LOAD(c=None, f='index', args=None, vars=None,
elif timeout <= 0: elif timeout <= 0:
raise ValueError( raise ValueError(
"Timeout argument must be greater than zero or None") "Timeout argument must be greater than zero or None")
statement = "web2py_component('%s','%s', %s, %s);" \ statement = "$.web2py.component('%s','%s', %s, %s);" \
% (url, target, timeout, times) % (url, target, timeout, times)
attr['_data-w2p_timeout'] = timeout
attr['_data-w2p_times'] = times
else: else:
statement = "web2py_component('%s','%s');" % (url, target) statement = "$.web2py.component('%s','%s');" % (url, target)
script = SCRIPT(statement, _type="text/javascript") attr['_data-w2p_remote'] = url
if not content is None: if not target is None:
return TAG[''](script, DIV(content, **attr)) return DIV(content, **attr)
else:
return TAG[''](script)
else: else:
if not isinstance(args, (list, tuple)): if not isinstance(args, (list, tuple)):
@@ -226,7 +226,7 @@ def LOAD(c=None, f='index', args=None, vars=None,
link = URL(request.application, c, f, r=request, link = URL(request.application, c, f, r=request,
args=args, vars=vars, extension=extension, args=args, vars=vars, extension=extension,
user_signature=user_signature) user_signature=user_signature)
js = "web2py_trap_form('%s','%s');" % (link, target) js = "$.web2py.trap_form('%s','%s');" % (link, target)
script = js and SCRIPT(js, _type="text/javascript") or '' script = js and SCRIPT(js, _type="text/javascript") or ''
return TAG[''](DIV(XML(page), **attr), script) return TAG[''](DIV(XML(page), **attr), script)
@@ -254,7 +254,7 @@ class LoadFactory(object):
url = url or html.URL(request.application, c, f, r=request, url = url or html.URL(request.application, c, f, r=request,
args=args, vars=vars, extension=extension, args=args, vars=vars, extension=extension,
user_signature=user_signature) user_signature=user_signature)
script = html.SCRIPT('web2py_component("%s","%s")' % (url, target), script = html.SCRIPT('$.web2py.component("%s","%s")' % (url, target),
_type="text/javascript") _type="text/javascript")
return html.TAG[''](script, html.DIV(content, **attr)) return html.TAG[''](script, html.DIV(content, **attr))
else: else:
@@ -305,7 +305,7 @@ class LoadFactory(object):
link = html.URL(request.application, c, f, r=request, link = html.URL(request.application, c, f, r=request,
args=args, vars=vars, extension=extension, args=args, vars=vars, extension=extension,
user_signature=user_signature) user_signature=user_signature)
js = "web2py_trap_form('%s','%s');" % (link, target) js = "$.web2py.trap_form('%s','%s');" % (link, target)
script = js and html.SCRIPT(js, _type="text/javascript") or '' script = js and html.SCRIPT(js, _type="text/javascript") or ''
return html.TAG[''](html.DIV(html.XML(page), **attr), script) return html.TAG[''](html.DIV(html.XML(page), **attr), script)