def get_display(my): web = WebContainer.get_web() widget = DivWdg() widget.add_class("spt_search_limit_top") #widget.add_style("border", "solid 1px blue") widget.add_color("background", "background") widget.add_color("color", "color") widget.add_style("padding: 5px") hidden = HiddenWdg("prefix", my.prefix) widget.add(hidden) if not my.search and not my.sobjects: widget.add("No search or sobjects found") return widget # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count(no_exception=True) # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if not limit: limit = 50 my.search_limit = limit if my.refresh: prev = SpanWdg( IconButtonWdg("Prev", IconWdg.LEFT, False ) ) prev.add_style("margin-left: 8px") prev.add_style("margin-right: 6px") prev.add_style("margin-top: -2px") next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) next.add_style("margin-left: 6px") prev.add_behavior( { 'type': 'click_up', 'cbjs_action': my.refresh_script } ) next.add_behavior( { 'type': 'click_up', 'cbjs_action': my.refresh_script } ) else: # the old code pre 2.5 prev = IconButtonWdg("Prev", IconWdg.LEFT, False ) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name,"") prev.add(hidden) prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name,"") next.add(hidden) next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \ %(hidden_name, my.refresh_script)) showing_wdg = DivWdg() widget.add(showing_wdg) showing_wdg.add_style("padding: 10px") showing_wdg.add_style("margin: 10px") showing_wdg.add_color("background", "background", -5) showing_wdg.add_border() label_span = SpanWdg("Showing: ") showing_wdg.add(label_span) showing_wdg.add( prev ) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset+1 if not limit: # prevent error in ItemsNavigatorWdg if a search encounters query error limit = 50 my.search_limit = limit right_bound = min(my.current_offset+limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: showing_wdg.add( current_value ) else: # add a range selector using ItemsNavigatorWdg from pyasm.widget import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit) selector.select.add_behavior( { 'type': 'change', 'cbjs_action': my.refresh_script } ) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) showing_wdg.add( selector) showing_wdg.add( next ) #showing_wdg.add( " x ") showing_wdg.add(my.text) my.text.add_style("margin-top: -3px") my.text.set_attr("size", "1") my.text.add_attr("title", "Set number of items per page") widget.add("<hr/>") # set the limit set_limit_wdg = my.get_set_limit_wdg() widget.add(set_limit_wdg) from tactic.ui.widget.button_new_wdg import ActionButtonWdg button = ActionButtonWdg(title='Search') widget.add(button) button.add_style("float: right") button.add_style("margin-top: 8px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var select = top.getElement(".spt_search_limit_select"); var value = select.value; if (value == 'Custom') { custom = top.getElement(".spt_search_limit_custom_text"); value = custom.value; } if (value == '') { value = 20; } var text = top.getElement(".spt_search_limit_text"); text.value = value; spt.dg_table.search_cbk({}, bvr) ''' } ) offset_wdg = HiddenWdg("%s_last_search_offset" %my.label) offset_wdg.set_value(my.current_offset) widget.add(offset_wdg) widget.add("<br clear='all'/>") return widget
def get_display(my): web = WebContainer.get_web() widget = DivWdg() widget.add_class("spt_search_limit_top") #widget.add_style("border", "solid 1px blue") widget.add_color("background", "background") widget.add_color("color", "color") widget.add_style("padding: 5px") hidden = HiddenWdg("prefix", my.prefix) widget.add(hidden) if not my.search and not my.sobjects: widget.add("No search or sobjects found") return widget # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count(no_exception=True) # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if not limit: limit = 50 my.search_limit = limit if my.refresh: prev = SpanWdg(IconButtonWdg("Prev", IconWdg.LEFT, False)) prev.add_style("margin-left: 8px") prev.add_style("margin-right: 6px") prev.add_style("margin-top: -2px") next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right") next.add_style("margin-left: 6px") prev.add_behavior({ 'type': 'click_up', 'cbjs_action': my.refresh_script }) next.add_behavior({ 'type': 'click_up', 'cbjs_action': my.refresh_script }) else: # the old code pre 2.5 prev = IconButtonWdg("Prev", IconWdg.LEFT, False) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name, "") prev.add(hidden) prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right") hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name, "") next.add(hidden) next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \ %(hidden_name, my.refresh_script)) showing_wdg = DivWdg() widget.add(showing_wdg) showing_wdg.add_style("padding: 10px") showing_wdg.add_style("margin: 10px") showing_wdg.add_color("background", "background", -5) showing_wdg.add_border() label_span = SpanWdg("Showing: ") showing_wdg.add(label_span) showing_wdg.add(prev) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset + 1 if not limit: # prevent error in ItemsNavigatorWdg if a search encounters query error limit = 50 my.search_limit = limit right_bound = min(my.current_offset + limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: showing_wdg.add(current_value) else: # add a range selector using ItemsNavigatorWdg from pyasm.widget import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit) selector.select.add_behavior({ 'type': 'change', 'cbjs_action': my.refresh_script }) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) showing_wdg.add(selector) showing_wdg.add(next) #showing_wdg.add( " x ") showing_wdg.add(my.text) my.text.add_style("margin-top: -3px") my.text.set_attr("size", "1") my.text.add_attr("title", "Set number of items per page") widget.add("<hr/>") # set the limit set_limit_wdg = my.get_set_limit_wdg() widget.add(set_limit_wdg) from tactic.ui.widget.button_new_wdg import ActionButtonWdg button = ActionButtonWdg(title='Search') widget.add(button) button.add_style("float: right") button.add_style("margin-top: 8px") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var select = top.getElement(".spt_search_limit_select"); var value = select.value; if (value == 'Custom') { custom = top.getElement(".spt_search_limit_custom_text"); value = custom.value; } if (value == '') { value = 20; } var text = top.getElement(".spt_search_limit_text"); text.value = value; spt.dg_table.search_cbk({}, bvr) ''' }) offset_wdg = HiddenWdg("%s_last_search_offset" % my.label) offset_wdg.set_value(my.current_offset) widget.add(offset_wdg) widget.add("<br clear='all'/>") return widget
def get_buttons_wdg(my): button_div = DivWdg() button = ActionButtonWdg(title='Run') button_div.add(button) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_script_editor_top"); var code = top.getElement(".spt_code").value; var folder = top.getElement(".spt_folder").value; var title = top.getElement(".spt_title").value; var language = top.getElement(".spt_language").value; spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var value = editor.getSession().toString(); try { if (language == 'javascript') { eval(value); } else if (language == 'expression') { var server = TacticServerStub.get(); var ret_val; ret_val = server.eval(value); if (ret_val && ret_val.length) { for (var i = 0; i < ret_val.length; i++) { log.critical(ret_val[i]); } } else { log.critical(ret_val); } } else if (language == 'python') { var path = folder + "/" + title; var server = TacticServerStub.get(); var info = server.execute_python_script(path); log.critical(info); } else { var ok = function() { eval(value);} spt.confirm("Please set the language of this script. It's assumed to be javascript if left blank. Continue to run?", ok, null); } } catch(e) { spt.error(spt.exception.handler(e)); } ''' }) button = ActionButtonWdg(title='Save') button_div.add(button) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'editor_id': my.unique_id, 'cbjs_action': ''' /* if (!has_changes(bvr)) { spt.alert("No changes have been made"); return; } */ var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.app_busy.show("Saving Script ..."); setTimeout(function() { spt.ace_editor.set_editor_top(top); spt.script_editor.save_script_cbk(evt, bvr); spt.app_busy.hide(); }, 10); ''' }) button = ActionButtonWdg(title='Clear') button_div.add(button) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() document.setValue(""); ''' }) button = ActionButtonWdg(title='Resize') #button_div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; $(editor_id).setStyle("width", "1000px"); $(editor_id).setStyle("height", "800px"); editor.resize(); ''' }) return button_div
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
def get_buttons_wdg(my): button_div = DivWdg() button = ActionButtonWdg(title='Run') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_script_editor_top"); var code = top.getElement(".spt_code").value; var folder = top.getElement(".spt_folder").value; var title = top.getElement(".spt_title").value; var language = top.getElement(".spt_language").value; spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var value = editor.getSession().toString(); try { if (language == 'javascript') { eval(value); } else if (language == 'expression') { var server = TacticServerStub.get(); var ret_val; ret_val = server.eval(value); if (ret_val && ret_val.length) { for (var i = 0; i < ret_val.length; i++) { log.critical(ret_val[i]); } } else { log.critical(ret_val); } } else if (language == 'python') { var path = folder + "/" + title; var server = TacticServerStub.get(); var info = server.execute_python_script(path); log.critical(info); } else { var ok = function() { eval(value);} spt.confirm("Please set the language of this script. It's assumed to be javascript if left blank. Continue to run?", ok, null); } } catch(e) { spt.error(spt.exception.handler(e)); } ''' } ) button = ActionButtonWdg(title='Save') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'editor_id': my.unique_id, 'cbjs_action': ''' /* if (!has_changes(bvr)) { spt.alert("No changes have been made"); return; } */ var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.app_busy.show("Saving Script ..."); setTimeout(function() { spt.ace_editor.set_editor_top(top); spt.script_editor.save_script_cbk(evt, bvr); spt.app_busy.hide(); }, 10); ''' } ) button = ActionButtonWdg(title='Clear') button_div.add(button) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() document.setValue(""); ''' } ) button = ActionButtonWdg(title='Resize') #button_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; $(editor_id).setStyle("width", "1000px"); $(editor_id).setStyle("height", "800px"); editor.resize(); ''' } ) return button_div