BUG: handler is string but not function
parent
ffc79d814c
commit
59adf589f5
|
@ -1,16 +1,15 @@
|
||||||
|
|
||||||
from orun.extjs import *
|
from orun.extjs import *
|
||||||
from orun.extjs import cp
|
from orun.extjs import cp
|
||||||
|
|
||||||
def ok_click(id, *args, **kwargs):
|
def ok_click(id_, *args, **kwargs):
|
||||||
cli << Ext.getCmp(id).setText('Clicked')
|
js.cli << Ext.getCmp(id_).setText('Clicked')
|
||||||
cli << js.client.alert('Server side message')
|
js.cli << js.client.alert('Server side message')
|
||||||
|
|
||||||
def button_click(id, *args, **kwargs):
|
def button_click(id_, *args, **kwargs):
|
||||||
js.write("""
|
js.write("""
|
||||||
Ext.getCmp("%s").setText('Clicked');
|
Ext.getCmp("%s").setText('Clicked');
|
||||||
alert('Server side callback message');
|
alert('Server side callback message');
|
||||||
""" % id)
|
""" % id_)
|
||||||
|
|
||||||
class MyApplication(cp.ExtApplication):
|
class MyApplication(cp.ExtApplication):
|
||||||
def main(self, *args, **kwargs):
|
def main(self, *args, **kwargs):
|
||||||
|
@ -18,7 +17,7 @@ class MyApplication(cp.ExtApplication):
|
||||||
'items': [{'xtype': 'button', 'text': 'Click Here', 'handler': button_click}],
|
'items': [{'xtype': 'button', 'text': 'Click Here', 'handler': button_click}],
|
||||||
'buttons': [
|
'buttons': [
|
||||||
{'text': 'OK', 'handler': ok_click},
|
{'text': 'OK', 'handler': ok_click},
|
||||||
{'text': 'Close', 'handler': js.function('this.up("window").close();')}]})
|
{'text': 'Close', 'handler': js.function('this.up(\'window\').close()')}]})
|
||||||
wnd.show()
|
wnd.show()
|
||||||
wnd.setHeight(200)
|
wnd.setHeight(200)
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from . import js
|
from . import js
|
||||||
|
import re
|
||||||
|
|
||||||
__all__ = ['create', 'createByAlias', 'Component']
|
__all__ = ['create', 'createByAlias', 'Component']
|
||||||
|
|
||||||
def js_ajax(fn):
|
def js_ajax(fn):
|
||||||
i = id(fn)
|
i = id(fn)
|
||||||
js.live_methods[i] = fn
|
js.live_methods[i] = fn
|
||||||
return js.client.Ext.Ajax.request({'url': js.AJAX_URL, 'method': 'GET', 'params': {'fn': i, 'id': js.client.this.id}, 'success': js.function('eval(arguments[0].responseText);')})
|
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);'))
|
||||||
|
|
||||||
js.js_ajax = js_ajax
|
js.js_ajax = js_ajax
|
||||||
|
|
||||||
def _create(meth, name, args):
|
def _create(meth, name, args):
|
||||||
#args['pyLive'] = True : TODO
|
#args['pyLive'] = True : TODO
|
||||||
obj = Component(**args)
|
obj = Component(**args)
|
||||||
js.write('var %s = Ext.create("%s", %s);' % (obj._id, name, str(obj)))
|
js.write('var %s = Ext.create(\'%s\', %s);' % (obj._id, name, str(obj)))
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def create(name, args={}):
|
def create(name, args={}):
|
||||||
|
@ -24,10 +26,10 @@ def createByAlias(alias, args={}):
|
||||||
return _create('createByAlias', alias, args)
|
return _create('createByAlias', alias, args)
|
||||||
|
|
||||||
def get(id):
|
def get(id):
|
||||||
return js.JsNode('Ext.get("%s")' % id)
|
return js.JsNode('Ext.get(\'%s\')' % id)
|
||||||
|
|
||||||
def getCmp(id):
|
def getCmp(id):
|
||||||
return js.JsNode('Ext.getCmp("%s")' % id)
|
return js.JsNode('Ext.getCmp(\'%s\')' % id)
|
||||||
|
|
||||||
class Component(js.JsObject):
|
class Component(js.JsObject):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -53,4 +55,6 @@ class Component(js.JsObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return json.dumps(self._js, default=js._encoder)
|
s = json.dumps(self._js, default=js._encoder)
|
||||||
|
|
||||||
|
return re.sub(r'("handler":\s+)("([^"]+)")', r'\1\3', s)
|
||||||
|
|
|
@ -25,9 +25,9 @@ def encode(o):
|
||||||
return json.dumps(o, default=_encoder)
|
return json.dumps(o, default=_encoder)
|
||||||
|
|
||||||
# trick json serialize javascript block
|
# trick json serialize javascript block
|
||||||
class JsBlock(int):
|
class JsBlock(str):
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
obj = super(JsBlock, cls).__new__(cls, 0)
|
obj = super(JsBlock, cls).__new__(cls, 'function () { %s }' % args[0])
|
||||||
obj.code = args[0]
|
obj.code = args[0]
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue