def init(my): my.widget_class = my.xml.get_value("widget/display/@class") my.draw = my.xml.get_value("widget/display/@draw") my.title = my.xml.get_value("widget/@name") my.name = my.title # convert the widget data options = {} nodes = my.xml.get_nodes("widget/display/*") for node in nodes: name = node.nodeName value = Xml.get_node_value(node) if options.has_key(name): # turn this into an array array = [] array.append(options.get(name)) array.append(value) options[name] = array else: options[name] = value my.options = options my.widget = Common.create_from_class_path(my.widget_class, [my.title])
def init(self): self.widget_class = self.xml.get_value("widget/display/@class") self.draw = self.xml.get_value("widget/display/@draw") self.title = self.xml.get_value("widget/@name") self.name = self.title # convert the widget data options = {} nodes = self.xml.get_nodes("widget/display/*") for node in nodes: name = node.nodeName value = Xml.get_node_value(node) if options.has_key(name): # turn this into an array array = [] array.append(options.get(name)) array.append(value) options[name] = array else: options[name] = value self.options = options self.widget = Common.create_from_class_path(self.widget_class, [self.title])
def get_action_options(my, event_name, scope="dependent"): options = {} action_node = my.get_action_node(event_name, scope=scope) if action_node is None: return options nodes = Xml.get_children(action_node) for node in nodes: name = Xml.get_node_name(node) if name == "#text": continue value = Xml.get_node_value(node) options[name] = value return options
def add_behaviors(my, widget, xml): behavior_nodes = xml.get_nodes("config/%s/behavior" % my.view) if behavior_nodes: hidden_div = DivWdg() hidden_div.add_styles("display: none"); hidden_div.add_class("spt_customlayoutwdg_handoffs") widget.add( hidden_div ) widget.add_behavior({ 'type': 'load', 'cbjs_action': ''' // handle embedded load behaviors! var el_load_list = bvr.src_el.getElements(".SPT_BVR_LOAD_PENDING"); spt.behavior.process_load_behaviors( el_load_list ); ''' }) for behavior_node in behavior_nodes: bvr_div = DivWdg() hidden_div.add( bvr_div ) css_class = Xml.get_attribute(behavior_node, 'class') behavior_str = Xml.get_node_value(behavior_node) behavior_str = behavior_str.strip() # if the event is specified in the xml, then use that event = Xml.get_attribute(behavior_node, 'event') modkeys = Xml.get_attribute(behavior_node, 'modkeys') relay_class = Xml.get_attribute(behavior_node, 'relay_class') if not behavior_str: continue try: try: bvr = eval(behavior_str) except: # try it as a string bvr_str = eval("'''\n%s\n'''" % behavior_str) if bvr_str: bvr = {} bvr['cbjs_action'] = bvr_str if event: bvr['type'] = event if modkeys: bvr['modkeys'] = modkeys # add the kwargs to this so behaviors have access bvr['kwargs'] = my.kwargs bvr['class_name'] = Common.get_full_class_name(my) if relay_class: bvr['bvr_match_class'] = relay_class if not bvr.get("type"): bvr['type'] = 'mouseup' my.content.add_relay_behavior( bvr ) elif bvr.get("type") == "smart_drag": bvr['bvr_match_class'] = css_class my.content.add_behavior(bvr) else: bvr['_handoff_'] = '@.getParent(".spt_custom_content").getElements(".%s")' % css_class if not bvr.get("type"): bvr['type'] = 'click_up' bvr_div.add_behavior( bvr ) except Exception, e: print "Error: ", e raise TacticException("Error parsing behavior [%s]" % behavior_str)
def get_display(my): my.kwargs['search_key'] = 'prod/asset?project=sample3d&code=chr001' custom = """<?xml version='1.0' encoding='UTF-8'?> <custom> <html> <div> This is html <textarea class='spt_test spt_input' name='description'> </textarea> <input class='spt_input' type='text' name='title'/> <br/> <input class='spt_button1' type='button' value='Press Me'/> <input class='spt_button2' type='button' value='Press Me2'/> <input class='spt_button3' type='button' value='Calendar'/> <input class='spt_refresh' type='button' value='Refresh'/> <element> <display class='tactic.ui.widget.CalendarWdg'/> </element> Much simpler!!! <elemeent class='CalendarWdg' blah='adasf'/> </div> </html> <behavior class='spt_button1'>{ "type": "click_up", "cbjs_action": ''' app.mel('sphere'); //var top = bvr.src_el.getParent(".spt_panel"); //var values = spt.api.Utility.get_input_values(top); //console.log(values); ''' }</behavior> <behavior class='spt_button2'>{ "type": "click_up", "cbjs_action": "alert(bvr.kwargs.search_key);" }</behavior> <behavior class='spt_button3'>{ "type": "click_up", "cbjs_action": ''' spt.panel.load('main_body', bvr.class_name, bvr.kwargs); //spt.panel.load('main_body', 'tactic.ui.widget.CalendarWdg', bvr.kwargs); ''' }</behavior> <behavior class='spt_refresh'>{ "type": "click_up", "cbjs_action": ''' var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' }</behavior> </custom> """ xml = Xml() xml.read_string(custom) top = DivWdg() my.set_as_panel(top) top.add_class("spt_panel") inner = DivWdg() top.add(inner) html_node = xml.get_node("custom/html") html = xml.to_string(html_node) inner.add(html) behaviors = xml.get_nodes("custom/behavior") for behavior in behaviors: css_class = Xml.get_attribute(behavior, 'class') value = Xml.get_node_value(behavior) value = eval(value) # add the kwargs to this so behaviors have access value['kwargs'] = my.kwargs value['class_name'] = Common.get_full_class_name(my) inner.add_behavior({ 'type': 'load', 'value': value, 'css_class': css_class, 'cbjs_action': ''' var el = bvr.src_el.getElement("."+bvr.css_class); if (!el) { alert("WARNING: element ["+bvr.css_clsss+"] does not exist"); } spt.behavior.add( el, bvr.value); ''' }) if my.kwargs.get("is_refresh"): return inner else: return top