From 917d2087c52ab835e123c69a3d9edc9f2ac4ffc4 Mon Sep 17 00:00:00 2001 From: niphlod Date: Thu, 27 Jun 2013 22:31:11 +0200 Subject: [PATCH] fixed the collapse function, refactored LOAD() to use new web2py.js --- applications/admin/static/js/web2py.js | 17 +++++++++++++++-- applications/examples/static/js/web2py.js | 17 +++++++++++++++-- applications/welcome/static/js/web2py.js | 17 +++++++++++++++-- gluon/compileapp.py | 20 ++++++++++---------- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index 7cbb2d19..c7570263 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -20,7 +20,7 @@ if(window.focus) newwindow.focus(); return false; }, - collapse: function () { + collapse: function (id) { $('#' + id).slideToggle(); }, fade: function (id, value) { @@ -144,6 +144,7 @@ web2py.manage_errors(target); web2py.ajax_fields(target); web2py.show_if_handler(target); + web2py.component_handler(target); }, //manage errors in forms manage_errors: function(target) { @@ -275,7 +276,7 @@ var jelement = $("#" + target); var element = jelement.get(0); var statement = "jQuery('#" + target + "').get(0).reload();"; - jelement.reload = function () { + element.reload = function () { // Continue if times is Infinity or // the times limit is not reached if(element.reload_check()) { @@ -484,6 +485,18 @@ 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) { e.preventDefault(); var method = el.data('w2p_method'); diff --git a/applications/examples/static/js/web2py.js b/applications/examples/static/js/web2py.js index 7cbb2d19..c7570263 100644 --- a/applications/examples/static/js/web2py.js +++ b/applications/examples/static/js/web2py.js @@ -20,7 +20,7 @@ if(window.focus) newwindow.focus(); return false; }, - collapse: function () { + collapse: function (id) { $('#' + id).slideToggle(); }, fade: function (id, value) { @@ -144,6 +144,7 @@ web2py.manage_errors(target); web2py.ajax_fields(target); web2py.show_if_handler(target); + web2py.component_handler(target); }, //manage errors in forms manage_errors: function(target) { @@ -275,7 +276,7 @@ var jelement = $("#" + target); var element = jelement.get(0); var statement = "jQuery('#" + target + "').get(0).reload();"; - jelement.reload = function () { + element.reload = function () { // Continue if times is Infinity or // the times limit is not reached if(element.reload_check()) { @@ -484,6 +485,18 @@ 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) { e.preventDefault(); var method = el.data('w2p_method'); diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index 7cbb2d19..c7570263 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -20,7 +20,7 @@ if(window.focus) newwindow.focus(); return false; }, - collapse: function () { + collapse: function (id) { $('#' + id).slideToggle(); }, fade: function (id, value) { @@ -144,6 +144,7 @@ web2py.manage_errors(target); web2py.ajax_fields(target); web2py.show_if_handler(target); + web2py.component_handler(target); }, //manage errors in forms manage_errors: function(target) { @@ -275,7 +276,7 @@ var jelement = $("#" + target); var element = jelement.get(0); var statement = "jQuery('#" + target + "').get(0).reload();"; - jelement.reload = function () { + element.reload = function () { // Continue if times is Infinity or // the times limit is not reached if(element.reload_check()) { @@ -484,6 +485,18 @@ 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) { e.preventDefault(); var method = el.data('w2p_method'); diff --git a/gluon/compileapp.py b/gluon/compileapp.py index 875f732b..fd197044 100644 --- a/gluon/compileapp.py +++ b/gluon/compileapp.py @@ -167,15 +167,15 @@ def LOAD(c=None, f='index', args=None, vars=None, elif timeout <= 0: raise ValueError( "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) + attr['_data-w2p_timeout'] = timeout + attr['_data-w2p_times'] = times else: - statement = "web2py_component('%s','%s');" % (url, target) - script = SCRIPT(statement, _type="text/javascript") - if not content is None: - return TAG[''](script, DIV(content, **attr)) - else: - return TAG[''](script) + statement = "$.web2py.component('%s','%s');" % (url, target) + attr['_data-w2p_remote'] = url + if not target is None: + return DIV(content, **attr) else: 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, args=args, vars=vars, extension=extension, 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 '' 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, args=args, vars=vars, extension=extension, 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") return html.TAG[''](script, html.DIV(content, **attr)) else: @@ -305,7 +305,7 @@ class LoadFactory(object): link = html.URL(request.application, c, f, r=request, args=args, vars=vars, extension=extension, 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 '' return html.TAG[''](html.DIV(html.XML(page), **attr), script)