renderTo
This commit is contained in:
		
							parent
							
								
									1caa69e2e4
								
							
						
					
					
						commit
						3286b15441
					
				@ -17,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': js.FuncWithParams(ok_click, {'arg1': 1, 'arg2': 'val2'})},
 | 
					                {'text': 'OK', 'handler': js.FuncWithParams(ok_click, {'arg1': 1, 'arg2': 'val2'})},
 | 
				
			||||||
                {'text': 'Close', 'handler': js.function('this.up(\'window\').close()')}]})
 | 
					                {'text': 'Close', 'handler': str(js.function('this.up(\'window\').close()'))}]})
 | 
				
			||||||
        wnd.show()
 | 
					        wnd.show()
 | 
				
			||||||
        wnd.setHeight(200)
 | 
					        wnd.setHeight(200)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -59,5 +59,5 @@ class Component(js.JsObject):
 | 
				
			|||||||
        pass
 | 
					        pass
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        s = json.dumps(self._js, default=js._encoder)
 | 
					        s = json.dumps(self._js, default=js._encoder, indent=4)
 | 
				
			||||||
        return re.sub(r'(":\s+)("(function[^"]+)")', r'\1\3', s)
 | 
					        return re.sub(r'("(handler|renderTo)":\s+)("([^"]+)")', r'\1\4', s)
 | 
				
			||||||
 | 
				
			|||||||
@ -19,9 +19,9 @@ def _encoder(o):
 | 
				
			|||||||
    elif isinstance(o, JsNode):
 | 
					    elif isinstance(o, JsNode):
 | 
				
			||||||
        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 str(function(js_ajax(o)))
 | 
				
			||||||
    elif isinstance(o, FuncWithParams):
 | 
					    elif isinstance(o, FuncWithParams):
 | 
				
			||||||
        return function(js_ajax(o.func, o.params))
 | 
					        return str(function(js_ajax(o.func, o.params)))
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
def encode(o):
 | 
					def encode(o):
 | 
				
			||||||
    if isinstance(o, JsNode):
 | 
					    if isinstance(o, JsNode):
 | 
				
			||||||
@ -34,7 +34,7 @@ def encode(o):
 | 
				
			|||||||
# trick json serialize javascript block
 | 
					# trick json serialize javascript block
 | 
				
			||||||
class JsBlock(str):
 | 
					class JsBlock(str):
 | 
				
			||||||
    def __new__(cls, *args, **kwargs):
 | 
					    def __new__(cls, *args, **kwargs):
 | 
				
			||||||
        obj = super(JsBlock, cls).__new__(cls, 'function () { %s }' % args[0])
 | 
					        obj = super(JsBlock, cls).__new__(cls, '%s' % args[0])
 | 
				
			||||||
        obj.code = args[0]
 | 
					        obj.code = args[0]
 | 
				
			||||||
        return obj
 | 
					        return obj
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user