diff --git a/orun/extjs/base.py b/orun/extjs/base.py index 94d3bd3..6b7a050 100644 --- a/orun/extjs/base.py +++ b/orun/extjs/base.py @@ -5,11 +5,13 @@ import re __all__ = ['create', 'createByAlias', 'Component'] -def js_ajax(fn): +def js_ajax(fn, arg_dict = {}): i = id(fn) js.live_methods[i] = fn - return "%s({'url': '%s', 'method': 'GET', 'params': {'fn': %d, 'id_': %s}, 'success': %s })"\ - % (js.client.Ext.Ajax.request, js.AJAX_URL, i, js.client.this.id, js.function('eval(arguments[0].responseText);')) + 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()]) + 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 diff --git a/orun/js.py b/orun/js.py index f85e7a9..2314bd4 100644 --- a/orun/js.py +++ b/orun/js.py @@ -8,6 +8,11 @@ js_ajax = None live_methods = {} +class FuncWithParams(object): + def __init__(self, func, params): + self.func = func + self.params = params + def _encoder(o): if isinstance(o, JsObject): return o._js @@ -15,6 +20,8 @@ def _encoder(o): return block(str(o)) elif isinstance(o, types.FunctionType) and js_ajax: return function(js_ajax(o)) + elif isinstance(o, FuncWithParams): + return function(js_ajax(o.func, o.params)) def encode(o): if isinstance(o, JsNode):