def get_default_display_wdg(cls, element_name, display_options, element_type, kbd_handler=False): from pyasm.widget import TextAreaWdg, CheckboxWdg, SelectWdg, TextWdg if element_type in ["integer", "smallint", "bigint", "int"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableIntegerTextEdit' } input = TextWdg("main") input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type in ["float"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableFloatTextEdit' } input = TextAreaWdg("main") input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type in ["string", "link", "varchar", "character", "timecode"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } input = TextWdg('main') input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type in ["text"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } input = TextAreaWdg('main') input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type == "boolean": input = CheckboxWdg('main') input.set_options(display_options) input.add_behavior( {"type" : "click_up", 'propagate_evt': True}) elif element_type in ["timestamp", "date", "time", "datetime2"]: from tactic.ui.widget import CalendarInputWdg, CalendarWdg, TimeInputWdg # FIXME: take wild guess for the time if element_name.endswith("_time"): #input = TimeInputWdg() behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } input = TextWdg('main') input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) else: #input = CalendarWdg() input = CalendarInputWdg() input.set_option('show_activator', False) #input.set_options(display_options) elif element_type == 'datetime': from tactic.ui.widget import CalendarInputWdg input = CalendarInputWdg() input.set_option('show_time', 'true') elif element_type == "color": from tactic.ui.widget import ColorInputWdg input = ColorInputWdg() input.set_options(display_options) elif element_type =="sqlserver_timestamp": # better then set it to None input = TextWdg() input.add_attr('disabled','disabled') else: # else try to instantiate it as a class print "WARNING: EditWdg handles type [%s] as default TextWdg" %element_type input = TextWdg() input.add("No input defined") return input
def get_set_limit_wdg(my): limit_content = DivWdg() limit_content.add_style("font-size: 10px") #limit_content.add_style("padding", "5px") #limit_content.add_border() limit_content.add("Show ") limit_select = SelectWdg("limit_select") limit_select.add_class("spt_search_limit_select") limit_select.set_option("values", "10|20|50|100|200|Custom") limit_select.add_style("font-size: 10px") limit_content.add(limit_select) limit_content.add(" items per page<br/>") if my.search_limit in [10, 20, 50, 100, 200]: limit_select.set_value(my.search_limit) is_custom = False else: limit_select.set_value("Custom") is_custom = True limit_select.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var value = bvr.src_el.value; var custom = top.getElement(".spt_search_limit_custom"); if (value == 'Custom') { custom.setStyle("display", ""); } else { custom.setStyle("display", "none"); } ''' }) custom_limit = DivWdg() limit_content.add(custom_limit) custom_limit.add_class("spt_search_limit_custom") custom_limit.add("<br/>Custom: ") text = TextWdg("custom_limit") text.add_class("spt_search_limit_custom_text") text.add_style("width: 50px") if not is_custom: custom_limit.add_style("display: none") else: text.set_value(my.search_limit) custom_limit.add(text) text.add(" items") behavior = { 'type': 'keydown', 'cbjs_action': ''' if (evt.key=='enter') { // register this as changed item var value = bvr.src_el.value; if (isNaN(value) || value.test(/[\.-]/)) { spt.error('You have to use an integer.'); } } ''' } text.add_behavior(behavior) return limit_content
def get_set_limit_wdg(my): limit_content = DivWdg() limit_content.add_style("font-size: 10px") #limit_content.add_style("padding", "5px") #limit_content.add_border() limit_content.add("Show ") limit_select = SelectWdg("limit_select") limit_select.add_class("spt_search_limit_select") limit_select.set_option("values", "10|20|50|100|200|Custom") limit_select.add_style("font-size: 10px") limit_content.add(limit_select) limit_content.add(" items per page<br/>") if my.search_limit in [10,20,50,100,200]: limit_select.set_value(my.search_limit) is_custom = False else: limit_select.set_value("Custom") is_custom = True limit_select.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var value = bvr.src_el.value; var custom = top.getElement(".spt_search_limit_custom"); if (value == 'Custom') { custom.setStyle("display", ""); } else { custom.setStyle("display", "none"); } ''' } ) custom_limit = DivWdg() limit_content.add(custom_limit) custom_limit.add_class("spt_search_limit_custom") custom_limit.add("<br/>Custom: ") text = TextWdg("custom_limit") text.add_class("spt_search_limit_custom_text") text.add_style("width: 50px") if not is_custom: custom_limit.add_style("display: none") else: text.set_value(my.search_limit) custom_limit.add(text) text.add(" items") behavior = { 'type': 'keydown', 'cbjs_action': ''' if (evt.key=='enter') { // register this as changed item var value = bvr.src_el.value; if (isNaN(value) || value.test(/[\.-]/)) { spt.error('You have to use an integer.'); } } '''} text.add_behavior(behavior) return limit_content
def get_default_display_wdg(cls, element_name, display_options, element_type, kbd_handler=False): from pyasm.widget import TextAreaWdg, CheckboxWdg, SelectWdg, TextWdg if element_type in ["integer", "smallint", "bigint", "int"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableIntegerTextEdit' } input = TextWdg("main") input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type in ["float"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableFloatTextEdit' } input = TextAreaWdg("main") input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type in ["string", "link", "varchar", "character", "timecode"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } input = TextWdg('main') input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type in ["text"]: behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } input = TextAreaWdg('main') input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) elif element_type == "boolean": input = CheckboxWdg('main') input.set_options(display_options) input.add_behavior( {"type" : "click_up", 'propagate_evt': True}) elif element_type in ["timestamp", "date", "time", "datetime2"]: from tactic.ui.widget import CalendarInputWdg, CalendarWdg, TimeInputWdg # FIXME: take wild guess for the time if element_name.endswith("_time"): #input = TimeInputWdg() behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } input = TextWdg('main') input.set_options(display_options) if kbd_handler: input.add_behavior(behavior) else: #input = CalendarWdg() input = CalendarInputWdg() input.set_option('show_activator', False) #input.set_options(display_options) elif element_type == 'datetime': from tactic.ui.widget import CalendarInputWdg input = CalendarInputWdg() input.set_option('show_time', 'true') elif element_type == "color": from tactic.ui.widget import ColorInputWdg input = ColorInputWdg() input.set_options(display_options) elif element_type =="sqlserver_timestamp": # NoneType Exception is prevented in WidgetConfig already input = None else: # else try to instantiate it as a class print "WARNING: EditWdg handles type [%s] as default TextWdg" %element_type input = TextWdg() input.add("No input defined") return input