function with arguments
parent
e13109f5aa
commit
2d545c0ccc
|
@ -5,11 +5,13 @@ import re
|
||||||
|
|
||||||
__all__ = ['create', 'createByAlias', 'Component']
|
__all__ = ['create', 'createByAlias', 'Component']
|
||||||
|
|
||||||
def js_ajax(fn):
|
def js_ajax(fn, arg_dict = {}):
|
||||||
i = id(fn)
|
i = id(fn)
|
||||||
js.live_methods[i] = fn
|
js.live_methods[i] = fn
|
||||||
return "%s({'url': '%s', 'method': 'GET', 'params': {'fn': %d, 'id_': %s}, 'success': %s })"\
|
func_args = ', '.join(['\'{k}\': {v}'.format( k = k,v = '\'%s\'' % v if type(v) is str else v ) for k,v in arg_dict.items()])
|
||||||
% (js.client.Ext.Ajax.request, js.AJAX_URL, i, js.client.this.id, js.function('eval(arguments[0].responseText);'))
|
if func_args != '': func_args = ', ' + func_args
|
||||||
|
return "%s({'url': '%s', 'method': 'GET', 'params': { 'fn': %d, 'id_': %s %s}, 'success': %s })"\
|
||||||
|
% (js.client.Ext.Ajax.request, js.AJAX_URL, i, js.client.this.id, func_args, js.function('eval(arguments[0].responseText);'))
|
||||||
|
|
||||||
js.js_ajax = js_ajax
|
js.js_ajax = js_ajax
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,11 @@ js_ajax = None
|
||||||
|
|
||||||
live_methods = {}
|
live_methods = {}
|
||||||
|
|
||||||
|
class FuncWithParams(object):
|
||||||
|
def __init__(self, func, params):
|
||||||
|
self.func = func
|
||||||
|
self.params = params
|
||||||
|
|
||||||
def _encoder(o):
|
def _encoder(o):
|
||||||
if isinstance(o, JsObject):
|
if isinstance(o, JsObject):
|
||||||
return o._js
|
return o._js
|
||||||
|
@ -15,6 +20,8 @@ def _encoder(o):
|
||||||
return block(str(o))
|
return block(str(o))
|
||||||
elif isinstance(o, types.FunctionType) and js_ajax:
|
elif isinstance(o, types.FunctionType) and js_ajax:
|
||||||
return function(js_ajax(o))
|
return function(js_ajax(o))
|
||||||
|
elif isinstance(o, FuncWithParams):
|
||||||
|
return function(js_ajax(o.func, o.params))
|
||||||
|
|
||||||
def encode(o):
|
def encode(o):
|
||||||
if isinstance(o, JsNode):
|
if isinstance(o, JsNode):
|
||||||
|
|
Loading…
Reference in New Issue