def get_save_wdg(my): # add the popup popup = PopupWdg(id="save_search_wdg") popup.add("Save Search", "title") div = DivWdg() div.add("Save current search as: ") text = TextWdg("save_search_text") text.set_id("save_search_text") div.add(text) save_button = ButtonWdg("Save Search") behavior = {"type": "click", "mouse_btn": "LMB", "cbjs_action": "spt.dg_table.save_search_cbk(evt, bvr);"} save_button.add_behavior(behavior) cancel_button = ButtonWdg("Cancel") cancel_button.add_event("onclick", "$('save_search_wdg').style.display = 'none'") div.add(HtmlElement.hr()) button_div = DivWdg() button_div.add_style("text-align: center") button_div.add(save_button) button_div.add(" ") button_div.add(cancel_button) div.add(button_div) popup.add(div, "content") return popup
def get_save_wdg(self): div = DivWdg() div.add("Save current search as: ") text = TextWdg("save_search_text") text.set_id("save_search_text") div.add(text) save_button = ButtonWdg("Save Search") behavior = { 'cbjs_action': 'spt.table.save_search();' } save_button.add_behavior( behavior ) cancel_button = ButtonWdg("Cancel") cancel_button.add_event("onclick", "$('save_search_wdg').style.display = 'none'") div.add(HtmlElement.hr()) button_div = DivWdg() button_div.add_style("text-align: center") button_div.add(save_button) button_div.add(" ") button_div.add(cancel_button) div.add(button_div) return div
def get_display(my): raise Exception("tactic.widget.ColorInputWdg is deprecated") color_div = DivWdg() color_div.add_style("z-index: 1000") # color_div.add_style("float: left") import random number = random.randint(1, 1000) rainbow_id = "rainbow_%s" % number color_div.add( """ <img id="%s" src="/context/spt_js/mooRainbow/rainbow.png" alt="[r]" width="16" height="16" /> """ % rainbow_id ) # <input id="myInput" name="myInput" type="text" size="13" /> text = TextWdg(my.get_name()) text.set_id("myInput") behavior = {"type": "keyboard", "kbd_handler_name": "DgTableMultiLineTextEdit"} text.add_behavior(behavior) color_div.add(text) color_div.add_behavior( { "type": "load", "cbjs_action": """ var r = new MooRainbow('%s', { startColor: [58, 142, 246], imgPath: '/context/spt_js/mooRainbow/images/', onComplete: function(color) { $(myInput).value=color.hex; } }); """ % rainbow_id, } ) return color_div
def get_display(self): raise Exception("tactic.widget.ColorInputWdg is deprecated") color_div = DivWdg() color_div.add_style("z-index: 1000") #color_div.add_style("float: left") import random number = random.randint(1, 1000) rainbow_id = "rainbow_%s" % number color_div.add(''' <img id="%s" src="/context/spt_js/mooRainbow/rainbow.png" alt="[r]" width="16" height="16" /> ''' % rainbow_id) #<input id="selfInput" name="selfInput" type="text" size="13" /> text = TextWdg(self.get_name()) text.set_id("selfInput") behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } text.add_behavior(behavior) color_div.add(text) color_div.add_behavior( { "type": "load", "cbjs_action": ''' var r = new MooRainbow('%s', { startColor: [58, 142, 246], imgPath: '/context/spt_js/mooRainbow/images/', onComplete: function(color) { $(myInput).value=color.hex; } }); ''' % rainbow_id } ) return color_div
def get_display(my): assert my.load_script widget = DivWdg() widget.add_style('float', 'right') load_button = TextOptionBtnWdg(label=' Load ', size='medium') load_button.get_top_el().add_style('float', 'left') load_button.get_top_el().set_id(my.LOAD_BUTTON_ID) load_button.add_behavior( {'type': "click_up", "cbjs_action": "setTimeout(function() {%s}, 200) "% my.load_script }) widget.add(load_button) arrow_button = load_button.get_option_widget() #widget.add(arrow_button) suffix = "ASSET_LOADER_FUNCTIONS" menus_in = [ my.smart_menu_data ] SmartMenu.add_smart_menu_set( arrow_button, menus_in) SmartMenu.assign_as_local_activator(arrow_button, None, True) #SmartMenu.attach_smart_context_menu( load_button, menus_in, False ) x_div = FloatDivWdg("x") x_div.add_color('color','color') x_div.add_style('margin-right: 6px') widget.add(x_div) multiplier = TextWdg() multiplier.set_id("load_multiplier") multiplier.set_option("size", "1.5") multiplier.add_style("font-size: 0.8em") multiplier.add_style("float: left") multiplier.add_class("load_multiplier") widget.add( multiplier ) return widget
def get_save_wdg(my): # add the popup popup = PopupWdg(id='save_search_wdg') popup.add("Save Search", "title") div = DivWdg() div.add("Save current search as: ") text = TextWdg("save_search_text") text.set_id("save_search_text") div.add(text) save_button = ButtonWdg("Save Search") behavior = { 'type': 'click', 'mouse_btn': 'LMB', 'cbjs_action': 'spt.dg_table.save_search_cbk(evt, bvr);' } save_button.add_behavior(behavior) cancel_button = ButtonWdg("Cancel") cancel_button.add_event("onclick", "$('save_search_wdg').style.display = 'none'") div.add(HtmlElement.hr()) button_div = DivWdg() button_div.add_style("text-align: center") button_div.add(save_button) button_div.add(" ") button_div.add(cancel_button) div.add(button_div) popup.add(div, "content") return popup
def get_display(my): top = my.top top.add_class("spt_script_editor_top") """ top.add_class("SPT_CHANGE") top.add_behavior( { 'type': 'load', 'cbjs_action': ''' register_change = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); change_top.addClass("SPT_HAS_CHANGES"); change_top.update_change(change_top, bvr); } has_changes = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); return change_top.hasClass("SPT_HAS_CHANGES"); } bvr.src_el.update_change = function(top, bvr) { change_el = top.getElement(".spt_change_element"); change_el.setStyle("display", ""); } ''' } ) """ change_div = DivWdg() top.add(change_div) #change_div.add("CHANGES!!!") change_div.add_style("display: none") change_div.add_class("spt_change_element") top.add_class("spt_panel") top.add_class("spt_js_editor") top.add_attr("spt_class_name", Common.get_full_class_name(my)) top.add_color("background", "background") top.add_style("padding", "10px") div = DivWdg() top.add(div) # if script_path script_path = my.kwargs.get("script_path") search_key = my.kwargs.get("search_key") if script_path: search = Search("config/custom_script") dirname = os.path.dirname(script_path) basename = os.path.basename(script_path) search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() elif search_key: script_sobj = Search.get_by_search_key(search_key) else: script_sobj = None if script_sobj: script_code = script_sobj.get_value("code") script_folder = script_sobj.get_value("folder") script_name = script_sobj.get_value("title") script_value = script_sobj.get_value("script") script_language = script_sobj.get_value("langauge") else: script_code = '' script_folder = '' script_name = '' script_value = '' editor = AceEditorWdg(custom_script=script_sobj) my.editor_id = editor.get_editor_id() if not Container.get_dict("JSLibraries", "spt_script_editor"): div.add_behavior({ 'type': 'load', 'cbjs_action': my.get_onload_js() }) # create the insert button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Script Editor Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior({ 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("tactic-script-editor")''' }) # create the insert button add_button_wdg = DivWdg() add_button_wdg.add_style("float: right") add_button = ActionButtonWdg(title="Manage") add_button.add_behavior({ 'type': 'click_up', 'cbfn_action': 'spt.popup.get_widget', 'options': { 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'title': 'Manage: [%s]' % my.search_type }, 'args': { 'search_type': my.search_type, 'view': 'table' }, }) add_button_wdg.add(add_button) div.add(add_button_wdg) button_div = editor.get_buttons_wdg() div.add(button_div) """ button_div = DivWdg() #div.add(button_div) button_div.add_style("text-align: left") button = ActionButtonWdg(title="Run") button.add_style("float: left") button.add_style("margin: 0 10 3") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' //var editor = $('shelf_script'); var value = editAreaLoader.getValue('shelf_script') eval( value ) ''' } ) button_div.add(button) button = ActionButtonWdg(title="Save") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Save") #button.add_style("margin: 5 10") behavior = { 'type': 'click_up', 'cbfn_action': 'spt.script_editor.save_script_cbk' } button.add_behavior(behavior) button_div.add(button) button = ActionButtonWdg(title="Clear") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Clear") #button.add_style("margin: 5 10") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); editAreaLoader.setValue('shelf_script', ''); ''' } ) button_div.add(button) """ div.add(HtmlElement.br(clear='all')) div.add(HtmlElement.hr()) save_wdg = DivWdg() save_wdg.add_style("padding: 2px 5px 6px 5px") save_wdg.add_color("background", "background", -5) # script code save_span = SpanWdg() save_span.add("<b>Code: </b>") save_wdg.add(save_span) save_text = TextWdg("shelf_code") save_text.set_value(script_code) save_text.add_attr("readonly", "true") save_text.set_id("shelf_code") save_text.add_class("spt_code") save_wdg.add(save_text) save_wdg.add(" ") # script name (path??) save_span = SpanWdg() save_span.add("<b>Script Path: </b>") save_wdg.add(save_span) save_text = TextWdg("shelf_folder") save_text.add_attr("size", "40") save_text.set_id("shelf_folder") save_text.add_class("spt_folder") save_text.set_value(script_folder) save_wdg.add(save_text) save_wdg.add(" / ") save_text = TextWdg("shelf_title") save_text.add_attr("size", "40") save_text.set_id("shelf_title") save_text.add_class("spt_title") save_text.set_value(script_name) save_wdg.add(save_text) div.add(save_wdg) from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() table.add_row() td = table.add_cell(resize=False) td.add_style("vertical-align: top") td.add(editor) text = TextAreaWdg("shelf_script") #text.add_behavior( { # 'type': 'double_click', # 'cbjs_action': ''' # var text = $('shelf_script'); # editor(text) # ''' # } ) """ text.set_id("shelf_script") text.add_style("width: 550px") text.add_style("height: 300px") text.add_class("codepress") text.add_class("html") text.add_behavior( { 'type': 'load', 'cbjs_action': ''' editAreaLoader.init({ id: "shelf_script", // id of the textarea to transform start_highlight: true, // if start with highlight allow_resize: "both", allow_toggle: true, word_wrap: true, language: "en", syntax: "js", // need to make this setable replace_tab_by_spaces: "4", font_size: "8", toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, highlight", syntax_selection_allow: "js,python" }); ''' } ) text.add_style("margin-top: 5px") text.add_style("font-family: courier new") text.add_style("font-size: 11px") text.set_id("shelf_script") #text.add_attr("cols", "80") #text.add_attr("rows", "20") text.add_style("min-height", "400px") text.add_style("height", "400px") text.add_style("width", "600px") text.set_value(script_value) td.add(text) """ td = table.add_cell() td.add_style('vertical-align: top') td.add(my.get_script_wdg()) table.add_row(resize=False) div.add(table) if my.kwargs.get("is_refresh"): return div else: return top
def get_display(my): top = my.top top.add_class("spt_script_editor_top") """ top.add_class("SPT_CHANGE") top.add_behavior( { 'type': 'load', 'cbjs_action': ''' register_change = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); change_top.addClass("SPT_HAS_CHANGES"); change_top.update_change(change_top, bvr); } has_changes = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); return change_top.hasClass("SPT_HAS_CHANGES"); } bvr.src_el.update_change = function(top, bvr) { change_el = top.getElement(".spt_change_element"); change_el.setStyle("display", ""); } ''' } ) """ change_div = DivWdg() top.add(change_div) #change_div.add("CHANGES!!!") change_div.add_style("display: none") change_div.add_class("spt_change_element"); top.add_class("spt_panel") top.add_class("spt_js_editor") top.add_attr("spt_class_name", Common.get_full_class_name(my) ) top.add_color("background", "background") top.add_style("padding", "10px") div = DivWdg() top.add(div) # if script_path script_path = my.kwargs.get("script_path") search_key = my.kwargs.get("search_key") if script_path: search = Search("config/custom_script") dirname = os.path.dirname(script_path) basename = os.path.basename(script_path) search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() elif search_key: script_sobj = Search.get_by_search_key(search_key) else: script_sobj = None if script_sobj: script_code = script_sobj.get_value("code") script_folder = script_sobj.get_value("folder") script_name = script_sobj.get_value("title") script_value = script_sobj.get_value("script") script_language = script_sobj.get_value("langauge") else: script_code = '' script_folder = '' script_name = '' script_value = '' editor = AceEditorWdg(custom_script=script_sobj) my.editor_id = editor.get_editor_id() if not Container.get_dict("JSLibraries", "spt_script_editor"): div.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() } ) # create the insert button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Script Editor Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior( { 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("tactic-script-editor")''' } ) # create the insert button add_button_wdg = DivWdg() add_button_wdg.add_style("float: right") add_button = ActionButtonWdg(title="Manage") add_button.add_behavior( { 'type': 'click_up', 'cbfn_action': 'spt.popup.get_widget', 'options': { 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'title': 'Manage: [%s]' % my.search_type }, 'args': { 'search_type': my.search_type, 'view': 'table' }, } ) add_button_wdg.add(add_button) div.add(add_button_wdg) button_div = editor.get_buttons_wdg() div.add(button_div) """ button_div = DivWdg() #div.add(button_div) button_div.add_style("text-align: left") button = ActionButtonWdg(title="Run") button.add_style("float: left") button.add_style("margin: 0 10 3") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' //var editor = $('shelf_script'); var value = editAreaLoader.getValue('shelf_script') eval( value ) ''' } ) button_div.add(button) button = ActionButtonWdg(title="Save") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Save") #button.add_style("margin: 5 10") behavior = { 'type': 'click_up', 'cbfn_action': 'spt.script_editor.save_script_cbk' } button.add_behavior(behavior) button_div.add(button) button = ActionButtonWdg(title="Clear") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Clear") #button.add_style("margin: 5 10") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); editAreaLoader.setValue('shelf_script', ''); ''' } ) button_div.add(button) """ div.add( HtmlElement.br(clear='all') ) div.add( HtmlElement.hr() ) save_wdg = DivWdg() save_wdg.add_style("padding: 2px 5px 6px 5px") save_wdg.add_color("background", "background", -5) # script code save_span = SpanWdg() save_span.add("<b>Code: </b>") save_wdg.add(save_span) save_text = TextWdg("shelf_code") save_text.set_value(script_code) save_text.add_attr("readonly", "true") save_text.set_id("shelf_code") save_text.add_class("spt_code") save_wdg.add(save_text) save_wdg.add(" ") # script name (path??) save_span = SpanWdg() save_span.add("<b>Script Path: </b>") save_wdg.add(save_span) save_text = TextWdg("shelf_folder") save_text.add_attr("size", "40") save_text.set_id("shelf_folder") save_text.add_class("spt_folder") save_text.set_value(script_folder) save_wdg.add(save_text) save_wdg.add(" / ") save_text = TextWdg("shelf_title") save_text.add_attr("size", "40") save_text.set_id("shelf_title") save_text.add_class("spt_title") save_text.set_value(script_name) save_wdg.add(save_text) div.add(save_wdg) from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() table.add_row() td = table.add_cell(resize=False) td.add_style("vertical-align: top") td.add(editor) text = TextAreaWdg("shelf_script") #text.add_behavior( { # 'type': 'double_click', # 'cbjs_action': ''' # var text = $('shelf_script'); # editor(text) # ''' # } ) """ text.set_id("shelf_script") text.add_style("width: 550px") text.add_style("height: 300px") text.add_class("codepress") text.add_class("html") text.add_behavior( { 'type': 'load', 'cbjs_action': ''' editAreaLoader.init({ id: "shelf_script", // id of the textarea to transform start_highlight: true, // if start with highlight allow_resize: "both", allow_toggle: true, word_wrap: true, language: "en", syntax: "js", // need to make this setable replace_tab_by_spaces: "4", font_size: "8", toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, highlight", syntax_selection_allow: "js,python" }); ''' } ) text.add_style("margin-top: 5px") text.add_style("font-family: courier new") text.add_style("font-size: 11px") text.set_id("shelf_script") #text.add_attr("cols", "80") #text.add_attr("rows", "20") text.add_style("min-height", "400px") text.add_style("height", "400px") text.add_style("width", "600px") text.set_value(script_value) td.add(text) """ td = table.add_cell() td.add_style('vertical-align: top') td.add(my.get_script_wdg()) table.add_row(resize=False) div.add(table) if my.kwargs.get("is_refresh"): return div else: return top