def get_display(my): div = DivWdg() div.add_class("spt_project_template_top") my.set_as_panel(div) div.add_color("background", "background") upload_div = DivWdg() upload_div.add_style("padding: 10px") upload_div.add_style("width: 600px") # add the main layout table = ResizableTableWdg() table.add_color("color", "color") div.add(table) table.add_row() left = table.add_cell() left.add_border() left.add_style("min-width: 250px") left.add_style("height: 400px") left.add(my.get_templates_wdg() ) right = table.add_cell() right.add_border() right.add_style("width: 400px") right.add_style("height: 400px") right.add_style("padding: 5px") right.add_class("spt_project_template_content") template = my.kwargs.get("template") if template: template_dir = Environment.get_template_dir() template_dir = "%s/%s" % (template_dir, template) class_name = 'tactic.ui.app.ProjectTemplateEditWdg'; content_div = ProjectTemplateEditWdg(template_dir=template_dir) else: content_div = DivWdg() content_div.add_style("margin: 40px") content_div.add_style("width: 300px") content_div.add_style("height: 150px") content_div.add_style("opacity: 0.7") content_div.add_border() content_div.add_color("background", "background3") content_div.add("<br/>"*4) content_div.add("No templates selected") content_div.add_style("text-align: center") right.add(content_div) return div
def get_display(self): div = DivWdg() div.add_class("spt_project_template_top") self.set_as_panel(div) div.add_color("background", "background") upload_div = DivWdg() upload_div.add_style("padding: 10px") upload_div.add_style("width: 600px") # add the main layout table = ResizableTableWdg() table.add_color("color", "color") div.add(table) table.add_row() left = table.add_cell() left.add_border() left.add_style("min-width: 250px") left.add_style("height: 400px") left.add(self.get_templates_wdg() ) right = table.add_cell() right.add_border() right.add_style("width: 400px") right.add_style("height: 400px") right.add_style("padding: 5px") right.add_class("spt_project_template_content") template = self.kwargs.get("template") if template: template_dir = Environment.get_template_dir() template_dir = "%s/%s" % (template_dir, template) class_name = 'tactic.ui.app.ProjectTemplateEditWdg'; content_div = ProjectTemplateEditWdg(template_dir=template_dir) else: content_div = DivWdg() content_div.add_style("margin: 40px") content_div.add_style("width: 300px") content_div.add_style("height: 150px") content_div.add_style("opacity: 0.7") content_div.add_border() content_div.add_color("background", "background3") content_div.add("<br/>"*4) content_div.add("No templates selected") content_div.add_style("text-align: center") right.add(content_div) return div
def get_display(my): # set the sobjects to all the widgets then preprocess for widget in my.widgets: widget.set_sobjects(my.sobjects) widget.set_parent_wdg(my) # preprocess the elements widget.preprocess() top = my.top my.set_as_panel(top) inner = DivWdg() top.add(inner) inner.add_color("background", "background") inner.add_color("color", "color") inner.add_class("spt_dashboard_top") title = DivWdg() inner.add(title) title.add(my.get_title()) title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") #title.add_style("margin: -10px -10px 10px -10px") #temp solution. Disable the frame title showing, so have more space for the view table title.add_style("display: none") title.add_color("background", "background3") #table = Table() from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() inner.add(table) table.set_max_width() panels = my.get_panels() for panel in panels: title = panel.get('title') #if title in ['Data', None]: # tr, td = table.add_row_cell() #else: # td = table.add_cell() tr = table.add_row() td = table.add_cell(resize=False) td.add_style("min-height: 100px") td.add_style("vertical-align: top") panel = my.get_panel_wdg(td, panel) td.add(panel) return top
def get_display(my): top = my.top my.set_as_panel(top) top.add_color("background", "background") top.add_border() top.add_class("spt_tab_edit_top") my.config = my.get_config() table = ResizableTableWdg() top.add(table) table.add_color("color", "color") table.add_row() left = table.add_cell() left.add(my.get_elements_wdg() ) left.add_style("width: 200px") left.add_border() left.add_color("background", "background3") left.add_color("color", "color3") right = table.add_cell() right.add_border() title_wdg = DivWdg() right.add(title_wdg) title_wdg.add("Definition") title_wdg.add_style("padding: 5px") title_wdg.add_gradient("background", "background", -10) right_div = DivWdg() right.add(right_div) right_div.add_style("width: 500px") right_div.add_class("spt_tab_edit_content") return top
def get_display(self): top = self.top self.set_as_panel(top) top.add_color("background", "background") top.add_border() top.add_class("spt_tab_edit_top") self.config = self.get_config() table = ResizableTableWdg() top.add(table) table.add_color("color", "color") table.add_row() left = table.add_cell() left.add(self.get_elements_wdg()) left.add_style("width: 200px") left.add_border() left.add_color("background", "background3") left.add_color("color", "color3") right = table.add_cell() right.add_border() title_wdg = DivWdg() right.add(title_wdg) title_wdg.add("Definition") title_wdg.add_style("padding: 5px") title_wdg.add_gradient("background", "background", -10) right_div = DivWdg() right.add(right_div) right_div.add_style("width: 500px") right_div.add_class("spt_tab_edit_content") return top
def get_display(my): my.doc_mode = my.kwargs.get("doc_mode") path = my.kwargs.get("path") my.search_type = my.kwargs.get("search_type") my.last_path = None doc_key = my.kwargs.get("doc_key") if doc_key: my.doc = Search.get_by_search_key(doc_key) snapshot = Snapshot.get_latest_by_sobject(my.doc) if snapshot: my.last_path = snapshot.get_lib_path_by_type('main') path = my.doc.get_value("link") # TEST TEST TEST if not path: #path = "/home/apache/pdf/mongodb.txt" #path = "/home/apache/assets/google_docs.html" #path = "/home/apache/pdf/star_wars.txt" path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true" path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub" #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html" path = "/home/apache/tactic/doc/alias.json" if not my.search_type: my.search_type = "test3/shot" my.column = "description" top = my.top top.add_class("spt_document_top") my.set_as_panel(top) #table = Table() table = ResizableTableWdg() top.add(table) table.add_row() table.set_max_width() left_td = table.add_cell() left_td.add_style("vertical-align: top") title = DivWdg() left_td.add(title) title.add_style("padding: 10px") title.add_color("background", "background3") button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH) title.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) button.add_style("float: left") button = IconButtonWdg(title="Save", icon=IconWdg.SAVE) title.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' ''' }) button.add_style("float: left") if not my.doc_mode: my.doc_mode = "text" select = SelectWdg("doc_mode") select.set_option("values", "text|formatted") title.add(select) select.set_value(my.doc_mode) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); var value = bvr.src_el.value; top.setAttribute("spt_doc_mode", value); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) title.add("<br clear='all'/>") #title.add(path) text_wdg = DivWdg() text_wdg.add_class("spt_document_content") left_td.add(text_wdg) #if path.startswith("https://docs.google.com/spreadsheet"): # #path = "http://www.southpawtech.com.com" # text_wdg.add(''' # <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe> # ''' % path) # text_wdg.add_style("overflow-x: hidden") if True: if not my.last_path and my.doc: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') text = my.get_text(path, highlight=False) f.write(text) f.close() cmd = FileCheckin(my.doc, tmp_path) Command.execute_cmd(cmd) else: save = False if save: # open up the last path f = open(my.last_path, 'r') last_text = f.read() text = my.get_text(path, None, highlight=False) if last_text != text: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') f.write(text) f.write(text) f.close() cmd = FileCheckin(my.doc, tmp_path) Command.execute_cmd(cmd) text = my.get_text(path, my.last_path) lines = text.split("\n") if my.doc_mode == "text": num_lines = len(lines) """ line_div = HtmlElement.pre() text_wdg.add(line_div) line_div.add_style("width: 20px") line_div.add_style("float: left") line_div.add_style("text-align: right") line_div.add_style("opacity: 0.3") line_div.add_style("padding-right: 10px") for i in range(0, num_lines*2): line_div.add(i+1) line_div.add("<br/>") """ if my.doc_mode == "text": pre = HtmlElement.pre() pre.add_style("white-space: pre-wrap") else: pre = DivWdg() pre = DivWdg() text_wdg.add(pre) text_wdg.add_style("padding: 10px 5px") text_wdg.add_style("max-height: 600px") text_wdg.add_style("overflow-y: auto") text_wdg.add_style("width: 600px") text_wdg.add_class("spt_resizable") pre.add_style("font-family: courier") if my.doc_mode == "formatted": pre.add(text) else: line_table = Table() pre.add(line_table) line_table.add_style("width: 100%") count = 1 for line in lines: #line = line.replace(" ", " ") tr = line_table.add_row() if count % 2 == 0: tr.add_color("background", "background", -2) td = line_table.add_cell() # FIXME: hacky if line.startswith('''<span style='background: #CFC'>'''): is_new = True else: td.add_style("vertical-align: top") text = TextWdg() text.add_style("border", "none") text.add_style("text-align", "right") text.add_style("width", "25px") text.add_style("margin", "0 10 0 0") text.add_style("opacity", "0.5") text.set_value(count) td.add(text) count += 1 is_new = False td = line_table.add_cell() if not is_new: SmartMenu.assign_as_local_activator(td, 'TEXT_CTX') tr.add_class("spt_line") else: SmartMenu.assign_as_local_activator(td, 'TEXT_NEW_CTX') tr.add_class("spt_new_line") td.add_class("spt_line_content") td.add(line) #from tactic.ui.app import AceEditorWdg #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px") #text_wdg.add(editor) # add a click on spt_item text_wdg.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); var search_key = bvr.src_el.getAttribute("spt_search_key"); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'search_key': search_key, } spt.panel.load(data_el, class_name, kwargs); ''' }) # add a double click on spt_item bgcolor = text_wdg.get_color("background", -10) text_wdg.add_relay_behavior({ 'type': 'mouseover', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "normal"); bvr.src_el.setStyle("background", bvr.bgcolor); ''' }) # add a double click on spt_item text_wdg.add_relay_behavior({ 'type': 'mouseout', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "bold"); bvr.src_el.setStyle("background", ""); ''' }) # add a context menu ctx_menu = my.get_text_context_menu() ctx_new_menu = my.get_text_new_context_menu() menus_in = { 'TEXT_CTX': ctx_menu, 'TEXT_NEW_CTX': ctx_new_menu, } SmartMenu.attach_smart_context_menu(text_wdg, menus_in, False) panel = ViewPanelWdg(search_type=my.search_type, layout="blah") right_td = table.add_cell() right_td.add_style("vertical-align: top") panel_div = DivWdg() panel_div.add_class("spt_document_data") right_td.add(panel_div) panel_div.add(panel) text_wdg.add_behavior({ 'type': 'load', 'cbjs_action': r''' spt.document = {}; spt.document.selected_text = null; spt.document.get_selected_text = function(frame) { var t = ''; if (frame) { var rng = frame.contentWindow.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (window.getSelection) // FF4 with one tab open? { var rng = window.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.getSelection) // FF4 with multiple tabs open? { var rng = document.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.selection) // IE8 { var rng = document.selection.createRange(); // expand range to enclose any word partially enclosed in it rng.expand("word"); t = rng.text; } // convert newline chars to spaces, collapse whitespace, and trim non-word chars return t.replace(/^\W+|\W+$/g, ''); //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, ''); } // expand FF range to enclose any word partially enclosed in it spt.document.expandtoword = function(range) { if (range.collapsed) { return; } while (range.startOffset > 0 && range.toString()[0].match(/\w/)) { range.setStart(range.startContainer, range.startOffset - 1); } while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/)) { range.setEnd(range.endContainer, range.endOffset + 1); } } ''' }) top.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_document_content', 'cbjs_action': r''' //spt.ace_editor.set_editor_top(bvr.src_el); //var text = spt.ace_editor.get_selection(); var text = spt.document.get_selected_text(); text = text.replace(/\n\n/mg, "\n"); text = text.replace(/\n\n/mg, "\n"); spt.document.selected_text = text + ""; ''' }) 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("language") 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', 'show_shelf': False, 'element_names': ['folder', 'title', 'description', 'language'], }, } ) 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( "<br clear='all'/><br/>") save_wdg = DivWdg() div.add(save_wdg) save_wdg.add_style("padding: 2px 5px 6px 5px") #save_wdg.add_color("background", "background", -5) # script code save_span = Table() save_wdg.add(save_span) save_span.add_row() code_span = SpanWdg() code_span.add("<b>Code: </b>") td = save_span.add_cell(code_span) td.add_style("display: none") code_text = TextInputWdg(name="shelf_code") code_text.add_style("display: inline") code_text.add_style("width: 100px") code_text.set_value(script_code) code_text.add_attr("readonly", "true") code_text.set_id("shelf_code") code_text.add_class("spt_code") td = save_span.add_cell(code_text) td.add_style("padding-top: 10px") td.add_style("display: none") save_span.add_cell(" ") # script name (path??) td = save_span.add_cell("<b>Script Path: </b>") td.add_style("padding-top: 10px") save_text = TextInputWdg(name="shelf_folder") save_text.add_style("width: 250px") save_text.set_id("shelf_folder") save_text.add_class("spt_folder") save_text.set_value(script_folder) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") td = save_span.add_cell(" / ") td.add_style("padding-top: 10px") td.add_style("font-size: 1.5em") save_text = TextInputWdg(name="shelf_title") save_text.add_style("width: 350px") save_text.add_attr("size", "40") save_text.set_id("shelf_title") save_text.add_class("spt_title") save_text.set_value(script_name) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") 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") 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_content_wdg(my): div = DivWdg() div.add_class("spt_tool_top") #table = Table() from tactic.ui.container import ResizableTableWdg from table_layout_wdg import FastTableLayoutWdg table = ResizableTableWdg() table.add_style("table-layout", "fixed") table.add_style("width: 100%") div.add(table) table.add_row() td = table.add_cell() kwargs = my.kwargs.copy() td.add_style("vertical-align: top") layout_div = DivWdg() layout_div.add_style("min-height: 500px") layout_div.add_style("height: auto") td.add(layout_div) td.add_style("overflow: hidden") kwargs['show_shelf'] = False kwargs['show_search_limit'] = False kwargs['expand_on_load'] = False layout = FastTableLayoutWdg(**kwargs) layout_div.add(layout) layout.set_sobjects(my.sobjects) #from tactic.ui.panel import TileLayoutWdg #layout = TileLayoutWdg(**my.kwargs) #layout_div.add(layout) td = table.add_cell() td.add_border(color="#EEE") td.add_style("vertical-align: top") content = DivWdg() td.add(content) content.add_class("spt_tool_content") content.add_border(color="#EEE") content.add_style("margin: -1px") content.add_style("height: 100%") #content.add_style("padding: 0px 20px") no_content_wdg = DivWdg() content.add(no_content_wdg) no_content_wdg.add("<br/>"*3) ''' The no content message displays tool icons and a message in format: <tools> <msg> ''' tool_icons = my.kwargs.get('tool_icon') if isinstance(tool_icons, basestring): tool_icon_lst = tool_icons.split("|") else: tool_icon_lst = None if tool_icon_lst: for icon in tool_icon_lst: icon = IconWdg(icon=icon) icon.add_style("padding", "5px") no_content_wdg.add(icon) no_content_wdg.add("</br></br>") tool_msg = my.kwargs.get('tool_msg') if tool_msg: no_content_wdg.add("<p>%s<p>" % tool_msg) else: no_content_wdg.add("Click the tool(s) to modify settings.") #no_content_wdg.add_style("opacity: 0.5") no_content_wdg.add_style("margin: 30px auto") no_content_wdg.add_color("color", "color3") no_content_wdg.add_color("background", "background3") no_content_wdg.add_style("text-align", "center") no_content_wdg.add_style("padding-top: 20px") no_content_wdg.add_style("padding-bottom: 20px") no_content_wdg.add_style("width: 350px") no_content_wdg.add_style("height: 110px") no_content_wdg.add_style("margin: 30px auto") no_content_wdg.add_border() return div
def get_display(my): my.search_key = my.kwargs.get("search_key") sobject = Search.get_by_search_key(my.search_key) if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject elif sobject.get_base_search_type() == "sthpw/file": # if it is a file object snapshot = sobject.get_parent() else: snapshots = Snapshot.get_by_sobject(sobject) snapshot = snapshots[0] #parent = snapshot.get_parent() top = my.top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) table.add_row() table.add_style("width: 100%") from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color( "background", "background", ) td.add_style("vertical-align: middle") td.add_style("height: 200px") td.add_style("overflow-x: auto") file_type = "icon" thumb_path = snapshot.get_web_path_by_type(file_type) file_type = "main" src = snapshot.get_web_path_by_type(file_type) parts = os.path.splitext(src) ext = parts[1] ext = ext.lower() if ext in ['.doc', '.xls']: from pyasm.widget import ThumbWdg link = ThumbWdg.find_icon_link(src) img = HtmlElement.img(src=link) href = DivWdg() href.add_style("text-align: center") href.add(img) td.add(href) href.add_behavior({ 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' }) href.add_class("hand") else: embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_style("width: 100%") embed_wdg.add_style("height: 240px") embed_wdg.add_behavior({ 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' }) embed_wdg.add_behavior({ 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' }) table.add_row() td = table.add_cell() from tactic.ui.checkin import PathMetadataWdg from tactic.ui.checkin import SnapshotMetadataWdg metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") parser = my.kwargs.get("parser") use_tactic_tags = my.kwargs.get("use_tactic_tags") file_type = "main" server_src = snapshot.get_lib_path_by_type(file_type) # get it dynamically by path metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags) metadata_div.add(metadata_wdg) #else: # metadata_wdg = SnapshotMetadataWdg(snapshot=snapshot) # metadata_div.add(metadata_wdg) top.add("<br/>") return top
def get_display(my): top = my.top top.add_class("spt_help_edit_top") top.add_color("background", "background") view = my.kwargs.get("view") from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) table.add_color("color", "color") table.add_style("width: 100%") table.add_style("height: 500px") table.add_row() left = table.add_cell() left.add_color("background", "background3") title_wdg = Table() title_wdg.add_row() left.add(title_wdg) title_wdg.add_gradient("background", "background", 0, -10) title_wdg.add_style("padding: 5px") title_wdg.add_style("margin-bottom: 5px") title_wdg.add_style("width: 100%") title_div = DivWdg("<b>Help Pages</b>") title_cell = title_wdg.add_cell(title_div) title_cell.add_style("width: 100%") from tactic.ui.widget import ActionButtonWdg insert_button = ActionButtonWdg(title="+", size="small") insert_button.add_style("margin-top: -3px") insert_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var class_name = "tactic.ui.panel.EditWdg" var view = "edit" var title = "Add new help doc" var cbjs_insert = "spt.tab.reload_selected();" var kwargs = { 'view': view, 'search_type': 'config/widget_config', 'default': '{"category":"HelpWdg"}', 'ignore': 'search_type|login|config', 'mode': 'insert', //'cbjs_insert': cbjs_insert } spt.panel.load_popup(title, class_name, kwargs); ''' }) title_wdg.add_cell(insert_button) docs_wdg = my.get_doc_wdg() left.add(docs_wdg) left.add_style("width: 150px") left.add_style("min-width: 150px") left.add_style("min-height: 500px") left.add_style("vertical-align: top") left.add_border() right = table.add_cell() right.add_style("vertical-align: top") right.add_border() content = HelpEditContentWdg(view=view) right.add(content) return top
def get_display(self): self.doc_mode = self.kwargs.get("doc_mode") path = self.kwargs.get("path") self.search_type = self.kwargs.get("search_type") self.last_path = None doc_key = self.kwargs.get("doc_key") if doc_key: self.doc = Search.get_by_search_key(doc_key) snapshot = Snapshot.get_latest_by_sobject(self.doc) if snapshot: self.last_path = snapshot.get_lib_path_by_type('main') path = self.doc.get_value("link") # TEST TEST TEST if not path: #path = "/home/apache/pdf/mongodb.txt" #path = "/home/apache/assets/google_docs.html" #path = "/home/apache/pdf/star_wars.txt" path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true" path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub" #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html" path = "/home/apache/tactic/doc/alias.json" if not self.search_type: self.search_type = "test3/shot" self.column = "description" top = self.top top.add_class("spt_document_top") self.set_as_panel(top) #table = Table() table = ResizableTableWdg() top.add(table) table.add_row() table.set_max_width() left_td = table.add_cell() left_td.add_style("vertical-align: top") title = DivWdg() left_td.add(title) title.add_style("padding: 10px") title.add_color("background", "background3") button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH) title.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) button.add_style("float: left") button = IconButtonWdg(title="Save", icon=IconWdg.SAVE) title.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' ''' } ) button.add_style("float: left") if not self.doc_mode: self.doc_mode = "text" select = SelectWdg("doc_mode") select.set_option("values", "text|formatted") title.add(select) select.set_value(self.doc_mode) select.add_behavior( { 'type': 'change', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); var value = bvr.src_el.value; top.setAttribute("spt_doc_mode", value); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) title.add("<br clear='all'/>") #title.add(path) text_wdg = DivWdg() text_wdg.add_class("spt_document_content") left_td.add(text_wdg) #if path.startswith("https://docs.google.com/spreadsheet"): # #path = "http://www.southpawtech.com.com" # text_wdg.add(''' # <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe> # ''' % path) # text_wdg.add_style("overflow-x: hidden") if True: if not self.last_path and self.doc: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') text = self.get_text(path, highlight=False) f.write(text) f.close() cmd = FileCheckin(self.doc, tmp_path) Command.execute_cmd(cmd) else: save = False if save: # open up the last path f = open(self.last_path, 'r') last_text = f.read() text = self.get_text(path, None, highlight=False) if last_text != text: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') f.write(text) f.write(text) f.close() cmd = FileCheckin(self.doc, tmp_path) Command.execute_cmd(cmd) text = self.get_text(path, self.last_path) lines = text.split("\n") if self.doc_mode == "text": num_lines = len(lines) """ line_div = HtmlElement.pre() text_wdg.add(line_div) line_div.add_style("width: 20px") line_div.add_style("float: left") line_div.add_style("text-align: right") line_div.add_style("opacity: 0.3") line_div.add_style("padding-right: 10px") for i in range(0, num_lines*2): line_div.add(i+1) line_div.add("<br/>") """ if self.doc_mode == "text": pre = HtmlElement.pre() pre.add_style("white-space: pre-wrap") else: pre = DivWdg() pre = DivWdg() text_wdg.add(pre) text_wdg.add_style("padding: 10px 5px") text_wdg.add_style("max-height: 600px") text_wdg.add_style("overflow-y: auto") text_wdg.add_style("width: 600px") text_wdg.add_class("spt_resizable") pre.add_style("font-family: courier") if self.doc_mode == "formatted": pre.add(text) else: line_table = Table() pre.add(line_table) line_table.add_style("width: 100%") count = 1 for line in lines: #line = line.replace(" ", " ") tr = line_table.add_row() if count % 2 == 0: tr.add_color("background", "background", -2) td = line_table.add_cell() # FIXME: hacky if line.startswith('''<span style='background: #CFC'>'''): is_new = True else: td.add_style("vertical-align: top") text = TextWdg() text.add_style("border", "none") text.add_style("text-align", "right") text.add_style("width", "25px") text.add_style("margin", "0 10 0 0") text.add_style("opacity", "0.5") text.set_value(count) td.add(text) count += 1 is_new = False td = line_table.add_cell() if not is_new: SmartMenu.assign_as_local_activator( td,'TEXT_CTX' ) tr.add_class("spt_line"); else: SmartMenu.assign_as_local_activator( td,'TEXT_NEW_CTX' ) tr.add_class("spt_new_line"); td.add_class("spt_line_content"); td.add(line) #from tactic.ui.app import AceEditorWdg #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px") #text_wdg.add(editor) # add a click on spt_item text_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); var search_key = bvr.src_el.getAttribute("spt_search_key"); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'search_key': search_key, } spt.panel.load(data_el, class_name, kwargs); ''' } ) # add a double click on spt_item bgcolor = text_wdg.get_color("background", -10) text_wdg.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "normal"); bvr.src_el.setStyle("background", bvr.bgcolor); ''' } ) # add a double click on spt_item text_wdg.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "bold"); bvr.src_el.setStyle("background", ""); ''' } ) # add a context menu ctx_menu = self.get_text_context_menu() ctx_new_menu = self.get_text_new_context_menu() menus_in = { 'TEXT_CTX': ctx_menu, 'TEXT_NEW_CTX': ctx_new_menu, } SmartMenu.attach_smart_context_menu( text_wdg, menus_in, False ) panel = ViewPanelWdg( search_type=self.search_type, layout="blah" ) right_td = table.add_cell() right_td.add_style("vertical-align: top") panel_div = DivWdg() panel_div.add_class("spt_document_data") right_td.add(panel_div) panel_div.add(panel) text_wdg.add_behavior( { 'type': 'load', 'cbjs_action': r''' spt.document = {}; spt.document.selected_text = null; spt.document.get_selected_text = function(frame) { var t = ''; if (frame) { var rng = frame.contentWindow.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (window.getSelection) // FF4 with one tab open? { var rng = window.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.getSelection) // FF4 with multiple tabs open? { var rng = document.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.selection) // IE8 { var rng = document.selection.createRange(); // expand range to enclose any word partially enclosed in it rng.expand("word"); t = rng.text; } // convert newline chars to spaces, collapse whitespace, and trim non-word chars return t.replace(/^\W+|\W+$/g, ''); //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, ''); } // expand FF range to enclose any word partially enclosed in it spt.document.expandtoword = function(range) { if (range.collapsed) { return; } while (range.startOffset > 0 && range.toString()[0].match(/\w/)) { range.setStart(range.startContainer, range.startOffset - 1); } while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/)) { range.setEnd(range.endContainer, range.endOffset + 1); } } ''' } ) top.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_document_content', 'cbjs_action': r''' //spt.ace_editor.set_editor_top(bvr.src_el); //var text = spt.ace_editor.get_selection(); var text = spt.document.get_selected_text(); text = text.replace(/\n\n/mg, "\n"); text = text.replace(/\n\n/mg, "\n"); spt.document.selected_text = text + ""; ''' } ) return top
def get_display(self): category = "FreeformWdg" search_type = self.get_value("search_type") if not search_type: search_type = "sthpw/login" view = self.get_value("view") if not view: view = 'freeform' search = Search("config/widget_config") search.add_filter("search_type", search_type) search.add_filter("view", view) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = "<config/>" top = self.top self.set_as_panel(top) top.add_class("spt_freeform_top") inner = DivWdg() top.add(inner) table = ResizableTableWdg() table.add_color("background", "background") inner.add(table) table.add_row() table.set_max_width() td = table.add_cell() td.add_attr("colspan", "5") td.add_color("background", "background3") td.add_color("color", "color") td.add_style("padding", "10px") td.add("Search Type: ") select = SelectWdg("search_type") project = Project.get() search_types = project.get_search_types() values = [x.get_base_key() for x in search_types] labels = [ "%s (%s)" % (x.get_title(), x.get_base_key()) for x in search_types ] select.set_option("values", values) select.set_option("labels", labels) if search_type: select.set_value(search_type) td.add(select) td.add(" " * 10) td.add("View: ") text = TextWdg("view") td.add(text) if view: text.set_value(view) button = ActionButtonWdg(title="Load") button.add_style("float: left") td.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Loading View"); var top = bvr.src_el.getParent(".spt_freeform_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) table.add_row() left = table.add_cell() left.add_style("vertical-align: top") left.add_border() left.add_color("color", "color") left.add_color("background", "background") left.add_style("min-width: 150px") left_div = DivWdg() left.add(left_div) left_div.add_style("min-height: 300px") left_div.add_style("min-width: 150px") left_div.add_style("width: 150px") title = DivWdg() left_div.add(title) title.add_style("font-weight: bold") title.add_style("font-size: 14px") title.add_style("width: 100%") title.add("Elements") title.add_gradient("background", "background", -5) title.add_style("padding: 10px 5px 5px 5px") title.add_style("height: 25px") title.add_style("margin-bottom: 10px") left.add_behavior({ 'type': 'smart_click_up', 'bvr_match_class': 'SPT_ELEMENT_CLICK', 'cbjs_action': r''' var top = bvr.src_el.getParent(".spt_freeform_top"); var template_top = top.getElement(".spt_freeform_template_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); var element_name = bvr.src_el.getAttribute("spt_element_name"); var template_els = template_top.getElements(".spt_element"); var els = canvas.getElements(".spt_element"); // get the highest number var number = 0; for ( var i = 0; i < els.length; i++) { var el = els[i]; var name = el.getAttribute("spt_element_name"); var num = name.match(/(\d+)/); if (!num) continue; num = parseInt(num); if (num > number) { number = num; } } number = number + 1; for ( var i = 0; i < template_els.length; i++) { var el = template_els[i]; if (el.getAttribute("spt_element_name") == element_name) { var clone = spt.behavior.clone(el); canvas.appendChild(clone); clone.setStyle("top", "30px"); clone.setStyle("left", "30px"); clone.setStyle("position", "absolute"); var new_name = element_name + number; clone.setAttribute("spt_element_name", new_name) clone.attrs = {}; var number = Math.floor(Math.random()*10001) clone.setAttribute("spt_element_id", "element"+number); spt.freeform.select(clone); break; } } ''' }) values = [ 'Label', 'Box', 'Text', 'TextArea', 'Button', 'Preview', 'Image', 'HTML', 'Table', 'Border', 'Custom Layout' ] names = [ 'label', 'box', 'text', 'textarea', 'button', 'preview', 'image', 'html', 'table', 'border', 'custom' ] icons = [IconWdg.VIEW] for name, value in zip(names, values): element_div = DivWdg() left_div.add(element_div) element_div.add_style("padding: 3px") element_div.add_class("SPT_DTS") element_div.add_class("hand") icon = IconWdg(name, IconWdg.VIEW) element_div.add(icon) element_div.add(value) element_div.add_class("SPT_ELEMENT_CLICK") element_div.add_attr("spt_element_name", name) element_div.add_style("padding-left: 10px") hover = element_div.get_color("background", -10) element_div.add_behavior({ 'type': 'hover', 'hover': hover, 'cbjs_action_over': '''bvr.src_el.setStyle("background", bvr.hover)''', 'cbjs_action_out': '''bvr.src_el.setStyle("background", "")''' }) element_div.add_class("hand") element_div.add_behavior({ 'type': 'drag', "drag_el": '@', "cb_set_prefix": 'spt.freeform.create_element_drag' }) """ button = ActionButtonWdg(title="Save") left_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_freeform_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); spt.freeform.init(canvas); var xml = spt.freeform.export(); var search_type = canvas.getAttribute("spt_search_type"); var view = canvas.getAttribute("spt_view"); if (!search_type || !view) { alert("Cannot find search type or view"); return; } var server = TacticServerStub.get(); var sobject = server.get_unique_sobject("config/widget_config", {search_type: search_type, view: view} ); server.update(sobject, {config: xml} ); ''' } ) """ from tactic.ui.container import DialogWdg dialog = DialogWdg(display=False, show_pointer=False) dialog.add_title("Properties") self.dialog_id = dialog.get_id() left.add(dialog) attr_div = self.get_attr_wdg() dialog.add(attr_div) template_div = DivWdg() left.add(template_div) template_div.add_class("spt_freeform_template_top") template_div.add_style("display: none") template_config_xml = self.get_template_config_xml() freeform_layout = FreeFormCanvasWdg(search_type=search_type, view="freeform", config_xml=template_config_xml, dialog_id=self.dialog_id) template_div.add(freeform_layout) # handle the canvas canvas = table.add_cell(resize=False) canvas.add(self.get_action_wdg()) canvas.add_style("overflow: hidden") canvas.add_style("vertical-align: top") canvas.add_color("background", "background") canvas.add_color("color", "color") canvas_div = DivWdg() canvas_div.add_style("margin: 20px") canvas_div.add_style("width: 90%") canvas_div.add_style("min-width: 300px") canvas_div.add_style("padding: 10px") canvas_div.add_style("height: 100%") canvas_div.add_class("spt_freeform_canvas_top") canvas.add(canvas_div) freeform_layout = FreeFormCanvasWdg(search_type=search_type, view=view, config_xml=config_xml, dialog_id=self.dialog_id) canvas_div.add(freeform_layout) table.add_resize_row() if self.kwargs.get("is_refresh") in [True, "true"]: return inner else: return top
def get_display(self): parser = self.kwargs.get("parser") self.search_key = self.kwargs.get("search_key") sobject = Search.get_by_search_key(self.search_key) if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject elif sobject.get_base_search_type() == "sthpw/file": # if it is a file object snapshot = sobject.get_parent() else: snapshots = Snapshot.get_by_sobject(sobject, is_latest=True) snapshot = snapshots[0] # Extension determine UI class for preview thumb_path = snapshot.get_web_path_by_type("icon") web_src = snapshot.get_web_path_by_type("web") from pyasm.biz import File file_type = "main" lib_path = snapshot.get_lib_path_by_type(file_type) src = snapshot.get_web_path_by_type(file_type) if not web_src: web_src = src parts = os.path.splitext(src) ext = parts[1] ext = ext.lstrip(".") ext = ext.lower() #parent = snapshot.get_parent() top = self.top self.set_as_panel(top) if ext == "pdf": iframe = HtmlElement.iframe() iframe.set_attr('src', src) iframe.add_style("width: 100%") iframe.add_style("height: 800px") top.add(iframe) return top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) tr = table.add_row() # These bvrs allow for smooth switching if switching between files # like in the RepoBrowserWdg tr.add_style("height: 200px") load_height_bvr = { 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' } tr.add_behavior(load_height_bvr) unload_height_bvr = { 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' } tr.add_behavior(unload_height_bvr) table.add_style("width: 100%") table.add_style("text-align", "center") from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color("background", "background",) td.add_style("vertical-align: middle") td.add_style("height: inherit") td.add_style("overflow-x: auto") if ext in ['txt','html', 'ini']: content_div = DivWdg() f = open(lib_path, 'r') content = f.read(10000) f.close() if not content: text = "No Content" else: size = os.path.getsize(lib_path) from pyasm.common import FormatValue value = FormatValue().get_format_value(size, "KB") content_div.add("Showing first 10K of %s<hr/>" % value) text = TextAreaWdg() text.add(content) text.add_style("width: 100%") text.add_style("height: 100%") text.add_style("padding: 10px") text.add_style("border: none") text.add_attr("readonly", "true") content_div.add(text) td.add(content_div) content_div.add_style("color", "#000") content_div.add_style("width", "auto") content_div.add_style("margin", "20px") content_div.add_style("height", "100%") elif ext in File.IMAGE_EXT or ext == "gif": if lib_path.find("#") != -1: img = DivWdg() file_range = snapshot.get_file_range() file_range_div = DivWdg() file_range_div.add("File Range: %s" % file_range.get_display()) img.add(file_range_div) file_range_div.add_style("font-size: 1.4em") file_range_div.add_style("margin: 15px 0px") """ left_chevron = IconWdg("Previous", "BS_CHEVRON_LEFT") file_range_div.add(left_chevron) right_chevron = IconWdg("Next", "BS_CHEVRON_RIGHT") file_range_div.add(right_chevron) """ expanded_paths = snapshot.get_expanded_web_paths() lib_paths = snapshot.get_expanded_lib_paths() lib_path = lib_paths[0] items_div = DivWdg() img.add(items_div) items_div.add_style("width: auto") for path in expanded_paths: item = HtmlElement.img(src=path) items_div.add(item) item.add_style("max-height: 300px") item.add_style("height: auto") item.add_style("width: 32%") item.add_style("margin: 2px") item.add_style("display: inline-block") #item.add_class("spt_resizable") img.add_style("margin: 20px") img.add_style("max-height: 400px") img.add_style("overflow-y: auto") img.add_style("overflow-hidden: auto") img.add_style("text-align: left") else: if ext == "gif": img = HtmlElement.img(src=src) else: img = HtmlElement.img(src=web_src) img.add_style("height: inherit") img.add_style("width: auto") td.add(img) elif ext in File.VIDEO_EXT: embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path, preload="auto", controls=True) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_behavior(load_height_bvr) embed_wdg.add_behavior(unload_height_bvr) else: thumb_table = DivWdg() td.add(thumb_table) thumb_table.add_behavior( { 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' } ) thumb_table.add_class("hand") thumb_table.add_style("width: 200px") thumb_table.add_style("height: 125px") thumb_table.add_style("padding: 5px") thumb_table.add_style("margin-left: 20px") thumb_table.add_style("display: inline-block") thumb_table.add_style("vertical-align: top") thumb_table.add_style("overflow-y: hidden") from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() thumb_table.add(thumb) thumb.set_sobject(snapshot) table.add_row() td = table.add_cell() from tactic.ui.checkin import PathMetadataWdg from tactic.ui.checkin import SnapshotMetadataWdg from pyasm.widget import SelectWdg select = SelectWdg(name="parser") select.add_style("width: 125px") select.add_style("margin-top: 0px") select.add_style("margin-right: 10px") select.add_empty_option("-- Metadata --") td.add(select) select.add_style("float: right") select.set_option("values", ["IPTC","EXIF","XMP","ImageMagick","PIL"]) select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var parser = bvr.src_el.value; spt.panel.refresh_element(bvr.src_el, {parser: parser}) ''' } ) if parser: select.set_value(parser) title_div = DivWdg() td.add(title_div) title_div.add("<div style='font-size: 16px'>File Metadata</div>") title_div.add("<div>Metadata extracted directly from the file</div>") title_div.add("<hr/>") title_div.add_style("text-align: left") title_div.add_style("margin: 0px 10px") metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") metadata_div.add_style("margin: 20px 0px 20px 10px") metadata_div.add_style("text-align: left") use_tactic_tags = self.kwargs.get("use_tactic_tags") server_src = lib_path # get it dynamically by path metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags, search_key=self.search_key) metadata_div.add(metadata_wdg) top.add("<br/>") return top
def get_display(my): category = "FreeformWdg" search_type = my.get_value("search_type") if not search_type: search_type = "sthpw/login" view = my.get_value("view") if not view: view = "freeform" search = Search("config/widget_config") search.add_filter("search_type", search_type) search.add_filter("view", view) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = "<config/>" top = my.top my.set_as_panel(top) top.add_class("spt_freeform_top") inner = DivWdg() top.add(inner) table = ResizableTableWdg() table.add_color("background", "background") inner.add(table) table.add_row() table.set_max_width() td = table.add_cell() td.add_attr("colspan", "5") td.add_color("background", "background3") td.add_color("color", "color") td.add_style("padding", "10px") td.add("Search Type: ") select = SelectWdg("search_type") project = Project.get() search_types = project.get_search_types() values = [x.get_base_key() for x in search_types] labels = ["%s (%s)" % (x.get_title(), x.get_base_key()) for x in search_types] select.set_option("values", values) select.set_option("labels", labels) if search_type: select.set_value(search_type) td.add(select) td.add(" " * 10) td.add("View: ") text = TextWdg("view") td.add(text) if view: text.set_value(view) button = ActionButtonWdg(title="Load") button.add_style("float: left") td.add(button) button.add_behavior( { "type": "click_up", "cbjs_action": """ spt.app_busy.show("Loading View"); var top = bvr.src_el.getParent(".spt_freeform_top"); spt.panel.refresh(top); spt.app_busy.hide(); """, } ) table.add_row() left = table.add_cell() left.add_style("vertical-align: top") left.add_border() left.add_color("color", "color") left.add_color("background", "background") left.add_style("min-width: 150px") left_div = DivWdg() left.add(left_div) left_div.add_style("min-height: 300px") left_div.add_style("min-width: 150px") left_div.add_style("width: 150px") title = DivWdg() left_div.add(title) title.add_style("font-weight: bold") title.add_style("font-size: 14px") title.add_style("width: 100%") title.add("Elements") title.add_gradient("background", "background", -5) title.add_style("padding: 10px 5px 5px 5px") title.add_style("height: 25px") title.add_style("margin-bottom: 10px") left.add_behavior( { "type": "smart_click_up", "bvr_match_class": "SPT_ELEMENT_CLICK", "cbjs_action": r""" var top = bvr.src_el.getParent(".spt_freeform_top"); var template_top = top.getElement(".spt_freeform_template_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); var element_name = bvr.src_el.getAttribute("spt_element_name"); var template_els = template_top.getElements(".spt_element"); var els = canvas.getElements(".spt_element"); // get the highest number var number = 0; for ( var i = 0; i < els.length; i++) { var el = els[i]; var name = el.getAttribute("spt_element_name"); var num = name.match(/(\d+)/); if (!num) continue; num = parseInt(num); if (num > number) { number = num; } } number = number + 1; for ( var i = 0; i < template_els.length; i++) { var el = template_els[i]; if (el.getAttribute("spt_element_name") == element_name) { var clone = spt.behavior.clone(el); canvas.appendChild(clone); clone.setStyle("top", "30px"); clone.setStyle("left", "30px"); clone.setStyle("position", "absolute"); var new_name = element_name + number; clone.setAttribute("spt_element_name", new_name) clone.attrs = {}; var number = Math.floor(Math.random()*10001) clone.setAttribute("spt_element_id", "element"+number); spt.freeform.select(clone); break; } } """, } ) values = [ "Label", "Box", "Text", "TextArea", "Button", "Preview", "Image", "HTML", "Table", "Border", "Custom Layout", ] names = ["label", "box", "text", "textarea", "button", "preview", "image", "html", "table", "border", "custom"] icons = [IconWdg.VIEW] for name, value in zip(names, values): element_div = DivWdg() left_div.add(element_div) element_div.add_style("padding: 3px") element_div.add_class("SPT_DTS") element_div.add_class("hand") icon = IconWdg(name, IconWdg.VIEW) element_div.add(icon) element_div.add(value) element_div.add_class("SPT_ELEMENT_CLICK") element_div.add_attr("spt_element_name", name) element_div.add_style("padding-left: 10px") hover = element_div.get_color("background", -10) element_div.add_behavior( { "type": "hover", "hover": hover, "cbjs_action_over": """bvr.src_el.setStyle("background", bvr.hover)""", "cbjs_action_out": """bvr.src_el.setStyle("background", "")""", } ) element_div.add_class("hand") element_div.add_behavior( {"type": "drag", "drag_el": "@", "cb_set_prefix": "spt.freeform.create_element_drag"} ) """ button = ActionButtonWdg(title="Save") left_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_freeform_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); spt.freeform.init(canvas); var xml = spt.freeform.export(); var search_type = canvas.getAttribute("spt_search_type"); var view = canvas.getAttribute("spt_view"); if (!search_type || !view) { alert("Cannot find search type or view"); return; } var server = TacticServerStub.get(); var sobject = server.get_unique_sobject("config/widget_config", {search_type: search_type, view: view} ); server.update(sobject, {config: xml} ); ''' } ) """ from tactic.ui.container import DialogWdg dialog = DialogWdg(display=False, show_pointer=False) dialog.add_title("Properties") my.dialog_id = dialog.get_id() left.add(dialog) attr_div = my.get_attr_wdg() dialog.add(attr_div) template_div = DivWdg() left.add(template_div) template_div.add_class("spt_freeform_template_top") template_div.add_style("display: none") template_config_xml = my.get_template_config_xml() freeform_layout = FreeFormCanvasWdg( search_type=search_type, view="freeform", config_xml=template_config_xml, dialog_id=my.dialog_id ) template_div.add(freeform_layout) # handle the canvas canvas = table.add_cell(resize=False) canvas.add(my.get_action_wdg()) canvas.add_style("overflow: hidden") canvas.add_style("vertical-align: top") canvas.add_color("background", "background") canvas.add_color("color", "color") canvas_div = DivWdg() canvas_div.add_style("margin: 20px") canvas_div.add_style("width: 90%") canvas_div.add_style("min-width: 300px") canvas_div.add_style("padding: 10px") canvas_div.add_style("height: 100%") canvas_div.add_class("spt_freeform_canvas_top") canvas.add(canvas_div) freeform_layout = FreeFormCanvasWdg( search_type=search_type, view=view, config_xml=config_xml, dialog_id=my.dialog_id ) canvas_div.add(freeform_layout) table.add_resize_row() if my.kwargs.get("is_refresh") in [True, "true"]: return inner else: return top
def get_display(self): top = self.top table = ResizableTableWdg() table.add_color("color", "color") top.add(table) table.add_row() left_element_names = ['preview','login','name'] left_search_type = 'sthpw/login' left_view = 'planner_left' right_element_names = ['preview','login_group','drop'] right_search_type = 'sthpw/login_group' right_view = 'planner_right' left = table.add_cell() left.add_border() title_div = DivWdg() left.add(title_div) title_div.add_style("height: 20px") title_div.add_style("font-size: 14px") title_div.add_style("font-weight: bold") title_div.add_style("padding: 8px") title_div.add_color("background", "background", -10) title_div.add(left_search_type) left_div = DivWdg() left_div.add_style("width: 500px") left_div.add_class("spt_resizable") left_div.add_style("overflow-x: auto") left_div.add_style("height: 100%") left_div.add_style("min-height: 600px") left.add(left_div) left_layout = ViewPanelWdg(search_type=left_search_type, view=left_view, element_names=left_element_names, show_search_limit="false") left_div.add(left_layout) middle = table.add_cell(resize=False) middle.add( self.get_middle_wdg() ) right = table.add_cell() right.add_border() title_div = DivWdg() right.add(title_div) title_div.add_style("height: 20px") title_div.add_style("font-size: 14px") title_div.add_style("font-weight: bold") title_div.add_style("padding: 8px") title_div.add_color("background", "background", -10) title_div.add(right_search_type) right_div = DivWdg() right_div.add_style("width: 500px") right_div.add_class("spt_resizable") right_div.add_style("overflow-x: auto") right.add_style("height: 100%") right.add_style("min-height: 600px") right.add(right_div) right_layout = ViewPanelWdg(search_type=right_search_type, view=right_view, element_names=right_element_names, show_search_limit="false") right_div.add(right_layout) return top
def get_display(self): top = self.top table = ResizableTableWdg() table.add_color("color", "color") top.add(table) table.add_row() left_element_names = ['preview', 'login', 'name'] left_search_type = 'sthpw/login' left_view = 'planner_left' right_element_names = ['preview', 'login_group', 'drop'] right_search_type = 'sthpw/login_group' right_view = 'planner_right' left = table.add_cell() left.add_border() title_div = DivWdg() left.add(title_div) title_div.add_style("height: 20px") title_div.add_style("font-size: 14px") title_div.add_style("font-weight: bold") title_div.add_style("padding: 8px") title_div.add_color("background", "background", -10) title_div.add(left_search_type) left_div = DivWdg() left_div.add_style("width: 500px") left_div.add_class("spt_resizable") left_div.add_style("overflow-x: auto") left_div.add_style("height: 100%") left_div.add_style("min-height: 600px") left.add(left_div) left_layout = ViewPanelWdg(search_type=left_search_type, view=left_view, element_names=left_element_names, show_search_limit="false") left_div.add(left_layout) middle = table.add_cell(resize=False) middle.add(self.get_middle_wdg()) right = table.add_cell() right.add_border() title_div = DivWdg() right.add(title_div) title_div.add_style("height: 20px") title_div.add_style("font-size: 14px") title_div.add_style("font-weight: bold") title_div.add_style("padding: 8px") title_div.add_color("background", "background", -10) title_div.add(right_search_type) right_div = DivWdg() right_div.add_style("width: 500px") right_div.add_class("spt_resizable") right_div.add_style("overflow-x: auto") right.add_style("height: 100%") right.add_style("min-height: 600px") right.add(right_div) right_layout = ViewPanelWdg(search_type=right_search_type, view=right_view, element_names=right_element_names, show_search_limit="false") right_div.add(right_layout) 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( "<br clear='all'/><br/>") save_wdg = DivWdg() div.add(save_wdg) save_wdg.add_style("padding: 2px 5px 6px 5px") #save_wdg.add_color("background", "background", -5) # script code save_span = Table() save_wdg.add(save_span) save_span.add_row() code_span = SpanWdg() code_span.add("<b>Code: </b>") save_span.add_cell(code_span) code_text = TextInputWdg(name="shelf_code") code_text.add_style("display: inline") code_text.add_style("width: 100px") code_text.set_value(script_code) code_text.add_attr("readonly", "true") code_text.set_id("shelf_code") code_text.add_class("spt_code") td = save_span.add_cell(code_text) td.add_style("padding-top: 10px") save_span.add_cell(" ") # script name (path??) save_span.add_cell("<b>Script Path: </b>") save_text = TextInputWdg(name="shelf_folder") save_text.add_style("width: 120px") save_text.add_attr("size", "40") save_text.set_id("shelf_folder") save_text.add_class("spt_folder") save_text.set_value(script_folder) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") save_span.add_cell(" / ") save_text = TextInputWdg(name="shelf_title") save_text.add_style("width: 350px") save_text.add_attr("size", "40") save_text.set_id("shelf_title") save_text.add_class("spt_title") save_text.set_value(script_name) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") 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_content_wdg(my): div = DivWdg() div.add_class("spt_tool_top") #table = Table() from tactic.ui.container import ResizableTableWdg from table_layout_wdg import FastTableLayoutWdg table = ResizableTableWdg() table.add_style("table-layout", "fixed") table.add_style("width: 100%") div.add(table) table.add_row() td = table.add_cell() kwargs = my.kwargs.copy() td.add_style("vertical-align: top") layout_div = DivWdg() layout_div.add_style("min-height: 500px") layout_div.add_style("height: auto") td.add(layout_div) td.add_style("overflow: hidden") kwargs['show_shelf'] = False kwargs['show_search_limit'] = False kwargs['expand_on_load'] = False layout = FastTableLayoutWdg(**kwargs) layout_div.add(layout) layout.set_sobjects(my.sobjects) #from tactic.ui.panel import TileLayoutWdg #layout = TileLayoutWdg(**my.kwargs) #layout_div.add(layout) td = table.add_cell() td.add_border(color="#EEE") td.add_style("vertical-align: top") content = DivWdg() td.add(content) content.add_class("spt_tool_content") content.add_border(color="#EEE") content.add_style("margin: -1px") content.add_style("height: 100%") #content.add_style("padding: 0px 20px") no_content_wdg = DivWdg() content.add(no_content_wdg) no_content_wdg.add("<br/>"*3) no_content_wdg.add("<i>-- No Content --</i>") #no_content_wdg.add_style("opacity: 0.5") no_content_wdg.add_style("margin: 30px auto") no_content_wdg.add_color("color", "color3") no_content_wdg.add_color("background", "background3") no_content_wdg.add_style("text-align", "center") no_content_wdg.add_style("padding-top: 20px") no_content_wdg.add_style("padding-bottom: 20px") no_content_wdg.add_style("width: 350px") no_content_wdg.add_style("height: 110px") no_content_wdg.add_style("margin: 30px auto") no_content_wdg.add_border() return div
def get_display(my): top = my.top top.add_class("spt_help_edit_top") top.add_color("background", "background") view = my.kwargs.get("view") from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) table.add_color("color", "color") table.add_style("width: 100%") table.add_style("height: 500px") table.add_row() left = table.add_cell() left.add_color("background", "background3") title_wdg = Table() title_wdg.add_row() left.add(title_wdg) title_wdg.add_gradient("background", "background", 0, -10) title_wdg.add_style("padding: 5px") title_wdg.add_style("margin-bottom: 5px") title_wdg.add_style("width: 100%") title_div = DivWdg("<b>Help Pages</b>") title_cell = title_wdg.add_cell(title_div) title_cell.add_style("width: 100%") from tactic.ui.widget import ActionButtonWdg insert_button = ActionButtonWdg(title="+", size="small") insert_button.add_style("margin-top: -3px") insert_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = "tactic.ui.panel.EditWdg" var view = "edit" var title = "Add new help doc" var cbjs_insert = "spt.tab.reload_selected();" var kwargs = { 'view': view, 'search_type': 'config/widget_config', 'default': '{"category":"HelpWdg"}', 'ignore': 'search_type|login|config', 'mode': 'insert', //'cbjs_insert': cbjs_insert } spt.panel.load_popup(title, class_name, kwargs); ''' }) title_wdg.add_cell(insert_button) docs_wdg = my.get_doc_wdg() left.add(docs_wdg) left.add_style("width: 150px") left.add_style("min-width: 150px") left.add_style("min-height: 500px") left.add_style("vertical-align: top") left.add_border() right = table.add_cell() right.add_style("vertical-align: top") right.add_border() content = HelpEditContentWdg(view=view) right.add(content) return top
def get_display(my): my.search_key = my.kwargs.get("search_key") my.sobject = Search.get_by_search_key(my.search_key) snapshot = my.sobject.get_parent() parent = snapshot.get_parent() top = my.top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) table.add_row() table.add_style("width: 100%") #td = table.add_cell() #thumb_div = DivWdg() #td.add(thumb_div) #thumb = ThumbWdg() #thumb_div.add(thumb) #thumb_div.add_class("spt_resizable") #thumb.set_sobject(parent) #thumb.set_icon_size(120) from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color("background", "background",) td.add_style("vertical-align: middle") td.add_style("height: 200px") td.add_style("overflow-x: auto") src = my.sobject.get_web_path() parts = os.path.splitext(src) ext = parts[1] ext = ext.lower() if ext in ['.doc','.xls']: from pyasm.widget import ThumbWdg link = ThumbWdg.find_icon_link(src) img = HtmlElement.img(src=link) href = DivWdg() href.add_style("text-align: center") href.add(img) td.add(href) href.add_behavior( { 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' } ) href.add_class("hand") else: embed_wdg = EmbedWdg(src=src) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_style("width: 100%") embed_wdg.add_style("height: 240px") embed_wdg.add_behavior( { 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' } ) embed_wdg.add_behavior( { 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' } ) table.add_row() from tactic.ui.checkin import SnapshotMetadataWdg metadata_wdg = SnapshotMetadataWdg(snapshot=snapshot) td = table.add_cell() metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") metadata_div.add(metadata_wdg) top.add("<br/>") return top
def get_display(my): my.search_key = my.kwargs.get("search_key") sobject = Search.get_by_search_key(my.search_key) if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject elif sobject.get_base_search_type() == "sthpw/file": # if it is a file object snapshot = sobject.get_parent() else: snapshots = Snapshot.get_by_sobject(sobject) snapshot = snapshots[0] #parent = snapshot.get_parent() top = my.top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) table.add_row() table.add_style("width: 100%") from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color("background", "background",) td.add_style("vertical-align: middle") td.add_style("height: 200px") td.add_style("overflow-x: auto") file_type = "icon" thumb_path = snapshot.get_web_path_by_type(file_type) file_type = "main" src = snapshot.get_web_path_by_type(file_type) parts = os.path.splitext(src) ext = parts[1] ext = ext.lower() if ext in ['.doc','.xls']: from pyasm.widget import ThumbWdg link = ThumbWdg.find_icon_link(src) img = HtmlElement.img(src=link) href = DivWdg() href.add_style("text-align: center") href.add(img) td.add(href) href.add_behavior( { 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' } ) href.add_class("hand") else: embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_style("width: 100%") embed_wdg.add_style("height: 240px") embed_wdg.add_behavior( { 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' } ) embed_wdg.add_behavior( { 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' } ) table.add_row() td = table.add_cell() from tactic.ui.checkin import PathMetadataWdg from tactic.ui.checkin import SnapshotMetadataWdg metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") parser = my.kwargs.get("parser") use_tactic_tags = my.kwargs.get("use_tactic_tags") file_type = "main" server_src = snapshot.get_lib_path_by_type(file_type) # get it dynamically by path metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags) metadata_div.add(metadata_wdg) #else: # metadata_wdg = SnapshotMetadataWdg(snapshot=snapshot) # metadata_div.add(metadata_wdg) top.add("<br/>") 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_display(self): parser = self.kwargs.get("parser") self.search_key = self.kwargs.get("search_key") sobject = Search.get_by_search_key(self.search_key) if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject elif sobject.get_base_search_type() == "sthpw/file": # if it is a file object snapshot = sobject.get_parent() else: snapshots = Snapshot.get_by_sobject(sobject, is_latest=True) snapshot = snapshots[0] # Extension determine UI class for preview thumb_path = snapshot.get_web_path_by_type("icon") web_src = snapshot.get_web_path_by_type("web") from pyasm.biz import File file_type = "main" lib_path = snapshot.get_lib_path_by_type(file_type) src = snapshot.get_web_path_by_type(file_type) if not web_src: web_src = src parts = os.path.splitext(src) ext = parts[1] ext = ext.lstrip(".") ext = ext.lower() #parent = snapshot.get_parent() top = self.top self.set_as_panel(top) if ext == "pdf": iframe = HtmlElement.iframe() iframe.set_attr('src', src) iframe.add_style("width: 100%") iframe.add_style("height: 800px") top.add(iframe) return top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) tr = table.add_row() # These bvrs allow for smooth switching if switching between files # like in the RepoBrowserWdg tr.add_style("height: 200px") load_height_bvr = { 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' } tr.add_behavior(load_height_bvr) unload_height_bvr = { 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' } tr.add_behavior(unload_height_bvr) table.add_style("width: 100%") table.add_style("text-align", "center") from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color( "background", "background", ) td.add_style("vertical-align: middle") td.add_style("height: inherit") td.add_style("overflow-x: auto") if ext in ['txt', 'html', 'ini']: content_div = DivWdg() f = open(lib_path, 'r') content = f.read(10000) f.close() if not content: text = "No Content" else: size = os.path.getsize(lib_path) from pyasm.common import FormatValue value = FormatValue().get_format_value(size, "KB") content_div.add("Showing first 10K of %s<hr/>" % value) text = TextAreaWdg() text.add(content) text.add_style("width: 100%") text.add_style("height: 100%") text.add_style("padding: 10px") text.add_style("border: none") text.add_attr("readonly", "true") content_div.add(text) td.add(content_div) content_div.add_style("color", "#000") content_div.add_style("width", "auto") content_div.add_style("margin", "20px") content_div.add_style("height", "100%") elif ext in File.IMAGE_EXT or ext == "gif": if lib_path.find("#") != -1: img = DivWdg() file_range = snapshot.get_file_range() file_range_div = DivWdg() file_range_div.add("File Range: %s" % file_range.get_display()) img.add(file_range_div) file_range_div.add_style("font-size: 1.4em") file_range_div.add_style("margin: 15px 0px") """ left_chevron = IconWdg("Previous", "BS_CHEVRON_LEFT") file_range_div.add(left_chevron) right_chevron = IconWdg("Next", "BS_CHEVRON_RIGHT") file_range_div.add(right_chevron) """ expanded_paths = snapshot.get_expanded_web_paths() lib_paths = snapshot.get_expanded_lib_paths() lib_path = lib_paths[0] items_div = DivWdg() img.add(items_div) items_div.add_style("width: auto") for path in expanded_paths: item = HtmlElement.img(src=path) items_div.add(item) item.add_style("max-height: 300px") item.add_style("height: auto") item.add_style("width: 32%") item.add_style("margin: 2px") item.add_style("display: inline-block") #item.add_class("spt_resizable") img.add_style("margin: 20px") img.add_style("max-height: 400px") img.add_style("overflow-y: auto") img.add_style("overflow-hidden: auto") img.add_style("text-align: left") else: if ext == "gif": img = HtmlElement.img(src=src) else: img = HtmlElement.img(src=web_src) img.add_style("height: inherit") img.add_style("width: auto") td.add(img) elif ext in File.VIDEO_EXT: embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path, preload="auto", controls=True) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_behavior(load_height_bvr) embed_wdg.add_behavior(unload_height_bvr) else: thumb_table = DivWdg() td.add(thumb_table) thumb_table.add_behavior({ 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' }) thumb_table.add_class("hand") thumb_table.add_style("width: 200px") thumb_table.add_style("height: 125px") thumb_table.add_style("padding: 5px") thumb_table.add_style("margin-left: 20px") thumb_table.add_style("display: inline-block") thumb_table.add_style("vertical-align: top") thumb_table.add_style("overflow-y: hidden") from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() thumb_table.add(thumb) thumb.set_sobject(snapshot) table.add_row() td = table.add_cell() from tactic.ui.checkin import PathMetadataWdg from tactic.ui.checkin import SnapshotMetadataWdg from pyasm.widget import SelectWdg select = SelectWdg(name="parser") select.add_style("width: 125px") select.add_style("margin-top: 0px") select.add_style("margin-right: 10px") select.add_empty_option("-- Metadata --") td.add(select) select.add_style("float: right") select.set_option("values", ["IPTC", "EXIF", "XMP", "ImageMagick", "PIL"]) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var parser = bvr.src_el.value; spt.panel.refresh_element(bvr.src_el, {parser: parser}) ''' }) if parser: select.set_value(parser) title_div = DivWdg() td.add(title_div) title_div.add("<div style='font-size: 16px'>File Metadata</div>") title_div.add("<div>Metadata extracted directly from the file</div>") title_div.add("<hr/>") title_div.add_style("text-align: left") title_div.add_style("margin: 0px 10px") metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") metadata_div.add_style("margin: 20px 0px 20px 10px") metadata_div.add_style("text-align: left") use_tactic_tags = self.kwargs.get("use_tactic_tags") server_src = lib_path # get it dynamically by path metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags, search_key=self.search_key) metadata_div.add(metadata_wdg) top.add("<br/>") return top
def get_display(my): my.search_key = my.kwargs.get("search_key") sobject = Search.get_by_search_key(my.search_key) if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject elif sobject.get_base_search_type() == "sthpw/file": # if it is a file object snapshot = sobject.get_parent() else: snapshots = Snapshot.get_by_sobject(sobject) snapshot = snapshots[0] #parent = snapshot.get_parent() top = my.top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) table.add_row() table.add_style("width: 100%") from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color("background", "background",) td.add_style("vertical-align: middle") td.add_style("height: 200px") td.add_style("overflow-x: auto") file_type = "icon" thumb_path = snapshot.get_web_path_by_type(file_type) file_type = "main" src = snapshot.get_web_path_by_type(file_type) lib_path = snapshot.get_lib_path_by_type(file_type) parts = os.path.splitext(src) ext = parts[1] ext = ext.lower() content_div = DivWdg() if ext in ['.doc','.xls']: from pyasm.widget import ThumbWdg link = ThumbWdg.find_icon_link(src) img = HtmlElement.img(src=link) href = DivWdg() href.add_style("text-align: center") href.add(img) td.add(href) href.add_behavior( { 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' } ) href.add_class("hand") elif ext in ['.txt','.html', '.ini']: f = open(lib_path, 'r') content = f.read(10000) f.close() if not content: text = "No Content" else: size = os.path.getsize(lib_path) from pyasm.common import FormatValue value = FormatValue().get_format_value(size, "KB") content_div.add("Showing first 10K of %s<hr/>" % value) text = TextAreaWdg() text.add(content) text.add_style("width: 100%") text.add_style("height: 300px") text.add_style("padding: 10px") text.add_style("border: none") text.add_attr("readonly", "true") content_div.add(text) td.add(content_div) content_div.add_style("color", "#000") content_div.add_style("width", "auto") content_div.add_style("margin", "20px") elif thumb_path == "__DYNAMIC__": td.add("No Preview") else: embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_style("width: 100%") embed_wdg.add_style("height: 240px") embed_wdg.add_behavior( { 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' } ) embed_wdg.add_behavior( { 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' } ) table.add_row() td = table.add_cell() from tactic.ui.checkin import PathMetadataWdg from tactic.ui.checkin import SnapshotMetadataWdg metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") parser = my.kwargs.get("parser") use_tactic_tags = my.kwargs.get("use_tactic_tags") file_type = "main" server_src = snapshot.get_lib_path_by_type(file_type) # get it dynamically by path metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags) metadata_div.add(metadata_wdg) #else: # metadata_wdg = SnapshotMetadataWdg(snapshot=snapshot) # metadata_div.add(metadata_wdg) top.add("<br/>") return top