cherryext/orun/extjs/base.py

66 lines
1.7 KiB
Python
Raw Permalink Normal View History

2013-04-30 09:49:34 +04:00
from . import js
2018-08-08 22:15:37 +03:00
2013-04-30 09:49:34 +04:00
__all__ = ['create', 'createByAlias', 'Component']
2018-08-16 19:31:35 +03:00
def js_ajax(fn, arg_dict = {}, f_type=js.js_procedure):
2013-04-30 09:49:34 +04:00
i = id(fn)
js.live_methods[i] = fn
2018-08-16 19:31:35 +03:00
func_args = ',\n'.join(['\'{k}\': {v}'.format( k = k,v = js.encode(v) ) for k,v in arg_dict.items()])
if func_args != '':
func_args = ',\n' + func_args
return f_type(i, ajax_args=func_args)
2013-04-30 09:49:34 +04:00
js.js_ajax = js_ajax
def _create(meth, name, args):
#args['pyLive'] = True : TODO
obj = Component(**args)
js.write('var %s = Ext.create(\'%s\', %s);' % (obj._id, name, str(obj)))
2013-04-30 09:49:34 +04:00
return obj
def create(name, args={}):
return _create('create', name, args)
2018-08-14 10:50:35 +03:00
def define(name, args={}):
js.write('Ext.define(\'%s\', %s);' % (name, js.encode(args)))
2013-04-30 09:49:34 +04:00
def createByAlias(alias, args={}):
return _create('createByAlias', alias, args)
def get(id):
return js.JsNode('Ext.get(\'%s\')' % id)
2013-04-30 09:49:34 +04:00
def getCmp(id):
return js.JsNode('Ext.getCmp(\'%s\')' % id)
2018-08-08 19:39:25 +03:00
def getBody():
return js.JsNode('Ext.getBody()')
2013-04-30 09:49:34 +04:00
2018-08-11 18:29:52 +03:00
tip = js.JsNode('Ext.tip')
2013-04-30 09:49:34 +04:00
class Component(js.JsObject):
def __init__(self, *args, **kwargs):
super(Component, self).__init__(*args, **kwargs)
def _update(self, config):
def get_obj(value):
if isinstance(value, dict):
return Component(**v)
elif isinstance(value, (list, tuple)):
return [get_obj(v) for v in value]
else:
return value
cfg = {}
for k, v in config.items():
cfg[k] = get_obj(v)
super(Component, self).update(cfg)
def down(self, item):
pass
def up(self, item):
pass
def __str__(self):
2018-08-08 22:15:37 +03:00
return js.dict2extjs(self._js)