def use_applet(self): # determines whether the applet should be used for local file # operations use_applet = Config.get_value("checkin", "use_applet") if use_applet in ['false', False]: use_applet = False elif use_applet in ['true', True]: use_applet = True else: browser = self.get_browser() # TEAM can always use the applet if browser == "Qt": use_applet = True else: # Otherwise we need a way to detect the java applet reliably if Container.get_dict("JSLibraries", "spt_applet"): use_applet = True else: use_applet = False return use_applet
def get_display(self): self.view_editable = True #if self.kwargs.get("do_search") != "false": # self.handle_search() self._process_search_args() #self.kwargs['show_gear'] = 'false' from tile_layout_wdg import TileLayoutWdg self.tile_layout = TileLayoutWdg(search_type=self.search_type, expand_mode=self.expand_mode, process=self.process) # set the sobjects to all the widgets then preprocess for widget in self.widgets: widget.set_sobjects(self.sobjects) widget.set_parent_wdg(self) # preprocess the elements widget.preprocess() """ # TEST code to return only the content temp = self.kwargs.get("temp") if temp: content = DivWdg() content.add( self.get_content_wdg() ) return content """ # extraneous variables inherited from TableLayoutWdg self.edit_permission = True top = self.top self.set_as_panel(top) top.add_class("spt_sobject_top") top.add_class("spt_layout_top") inner = DivWdg() top.add(inner) # This is handled elsewhere #inner.add_color("background", "background") inner.add_color("color", "color") inner.add_attr("spt_version", "2") inner.add_class("spt_table") inner.add_class("spt_layout") self.layout_wdg = inner class_name = Common.get_full_class_name(self) inner.add_attr("spt_class_name", class_name) if not Container.get_dict("JSLibraries", "spt_html5upload"): from tactic.ui.input import Html5UploadWdg upload_wdg = Html5UploadWdg() inner.add(upload_wdg) self.upload_id = upload_wdg.get_upload_id() inner.add_attr('upload_id',self.upload_id) # this interferes with Html5Upload function on first load, commenting it out #thumb = ThumbWdg() #thumb.handle_layout_behaviors(inner) is_refresh = self.kwargs.get("is_refresh") if self.kwargs.get("show_shelf") not in ['false', False]: action = self.get_action_wdg() inner.add(action) info = self.search_limit.get_info() if info.get("count") == None: info["count"] = len(self.sobjects) show_search_limit = self.kwargs.get("show_search_limit") if show_search_limit in ['false', False]: search_limit_mode = None else: search_limit_mode = self.kwargs.get('search_limit_mode') if not search_limit_mode: search_limit_mode = 'bottom' if search_limit_mode in ['top','both']: from tactic.ui.app import SearchLimitSimpleWdg limit_wdg = SearchLimitSimpleWdg( count=info.get("count"), search_limit=info.get("search_limit"), current_offset=info.get("current_offset") ) inner.add(limit_wdg) content = DivWdg() inner.add( content ) content.add( self.get_content_wdg() ) # NOTE: a lot of scaffolding to convince that search_cbk that this # is a proper layout top.add_class("spt_table_top"); class_name = Common.get_full_class_name(self) top.add_attr("spt_class_name", class_name) # NOTE: adding a fake header to conform to a table layout. Not # sure if this is the correct interface for this header_row_div = DivWdg() header_row_div.add_class("spt_table_header_row") content.add(header_row_div) content.add_class("spt_table_table") content.set_id(self.table_id) self.handle_load_behaviors(content) inner.add_class("spt_table_content"); inner.add_attr("spt_search_type", self.kwargs.get('search_type')) inner.add_attr("spt_view", self.kwargs.get('view')) limit_span = DivWdg() inner.add(limit_span) limit_span.add_style("margin-top: 4px") limit_span.add_class("spt_table_search") limit_span.add_style("width: 250px") limit_span.add_style("margin: 5 auto") inner.add_attr("total_count", info.get("count")) if search_limit_mode in ['bottom','both']: from tactic.ui.app import SearchLimitSimpleWdg limit_wdg = SearchLimitSimpleWdg( count=info.get("count"), search_limit=info.get("search_limit"), current_offset=info.get("current_offset"), ) inner.add(limit_wdg) self.add_layout_behaviors(inner) if self.kwargs.get("is_refresh") == 'true': return inner else: return top
def get_display(my): my.view_editable = True if my.kwargs.get("do_search") != "false": my.handle_search() #my.kwargs['show_gear'] = 'false' # 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() """ # TEST code to return only the content temp = my.kwargs.get("temp") if temp: content = DivWdg() content.add( my.get_content_wdg() ) return content """ # extraneous variables inherited from TableLayoutWdg my.edit_permission = True top = DivWdg() my.set_as_panel(top) top.add_class("spt_sobject_top") inner = DivWdg() top.add(inner) # This is handled elsewhere #inner.add_color("background", "background") inner.add_color("color", "color") inner.add_attr("spt_version", "2") inner.add_class("spt_table") inner.add_class("spt_layout") if not Container.get_dict("JSLibraries", "spt_html5upload"): from tactic.ui.input import Html5UploadWdg upload_wdg = Html5UploadWdg() inner.add(upload_wdg) my.upload_id = upload_wdg.get_upload_id() inner.add_attr('upload_id',my.upload_id) # this interferes with Html5Upload function on first load, commenting it out #thumb = ThumbWdg() #thumb.handle_layout_behaviors(inner) is_refresh = my.kwargs.get("is_refresh") if my.kwargs.get("show_shelf") not in ['false', False]: action = my.get_action_wdg() inner.add(action) content = DivWdg() inner.add( content ) content.add( my.get_content_wdg() ) # NOTE: a lot of scaffolding to convince that search_cbk that this # is a proper layout top.add_class("spt_table_top"); class_name = Common.get_full_class_name(my) top.add_attr("spt_class_name", class_name) # NOTE: adding a fake header to conform to a table layout. Not # sure if this is the correct interface for this header_row_div = DivWdg() header_row_div.add_class("spt_table_header_row") content.add(header_row_div) content.add_class("spt_table_table") content.set_id(my.table_id) my.handle_load_behaviors(content) inner.add_class("spt_table_content"); inner.add_attr("spt_search_type", my.kwargs.get('search_type')) inner.add_attr("spt_view", my.kwargs.get('view')) limit_span = DivWdg() inner.add(limit_span) limit_span.add_style("margin-top: 4px") limit_span.add_class("spt_table_search") limit_span.add_style("width: 250px") limit_span.add_style("margin: 5 auto") info = my.search_limit.get_info() if info.get("count") == None: info["count"] = len(my.sobjects) from tactic.ui.app import SearchLimitSimpleWdg limit_wdg = SearchLimitSimpleWdg( count=info.get("count"), search_limit=info.get("search_limit"), current_offset=info.get("current_offset"), ) inner.add(limit_wdg) my.add_layout_behaviors(inner) if my.kwargs.get("is_refresh") == 'true': return inner else: return top
def get_display(my): div = DivWdg() if not Container.get_dict("JSLibraries", "spt_popup"): div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.4") div.add_style("background", "#000") div.add_style("padding: 100px") div.add_style("height: 100%") div.add_style("width: 100%") div.add_class("spt_popup_background") div.add_style("display: none") div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.hide(bvr.src_el); ''' }) Container.put("PopupWdg:background", True) # This is the absolute outside of a popup, including the drop shadow widget = DivWdg() div.add(widget) widget.add_class("spt_popup") if not Container.get_dict("JSLibraries", "spt_popup"): widget.add_behavior({ 'type': 'load', 'cbjs_action': my.get_onload_js() }) width = my.kwargs.get("width") if not width: width = 10 #widget.add_behavior( { # 'type': 'load', # 'cbjs_action': 'bvr.src_el.makeResizable({handle:bvr.src_el.getElement(".spt_popup_resize")})' #} ) web = WebContainer.get_web() widget.set_id(my.name) if my.kwargs.get("display") == "true": pass else: widget.add_style("display: none") widget.add_style("position: absolute") widget.add_style("left: 400px") widget.add_style("top: 100px") widget.add_border() widget.add_color("background", "background") #widget.set_box_shadow(color="#000") widget.set_box_shadow() table = Table() table.add_behavior({ 'type': 'load', 'width': width, 'cbjs_action': ''' bvr.src_el.setStyle("width", bvr.width) var popup = bvr.src_el.getParent(".spt_popup"); var window_size = $(window).getSize(); var size = bvr.src_el.getSize(); var left = window_size.x/2 - size.x/2; var top = window_size.y/2 - size.y/2; popup.setStyle("left", left); //popup.setStyle("top", top); ''' }) table.add_row() """ # Qt doesn't support shadows very well if web.get_browser() == 'Qtx': # dynamically add css files table.add_class("css_shadow_table") td = table.add_cell() td.add_class("css_shadow_td css_shadow_top_left SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_top SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_top_right SPT_POPUP_SHADOW") # Middle (Content) Row of Shadow table ... table.add_row() td = table.add_cell() td.add_class("css_shadow_td css_shadow_left SPT_POPUP_SHADOW") """ content_td = table.add_cell() content_td.add_class("css_shadow_td") """ if web.get_browser() == 'Qtx': td = table.add_cell() td.add_class("css_shadow_td css_shadow_right SPT_POPUP_SHADOW") # Bottom Row of Shadow table ... table.add_row() td = table.add_cell() td.add_class("css_shadow_td css_shadow_bottom_left SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_bottom SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_bottom_right SPT_POPUP_SHADOW") """ drag_div = DivWdg() #from tactic.ui.container import ArrowWdg #arrow = ArrowWdg() #drag_div.add(arrow) # FIXME: for some reason, this causes popups to stop functioning after # close a couple of times my.add_header_context_menu(drag_div) # create the 'close' button ... if my.allow_close: close_wdg = SpanWdg() #close_wdg.add( IconWdg("Close", IconWdg.POPUP_WIN_CLOSE) ) close_wdg.add(IconWdg("Close", "BS_REMOVE")) close_wdg.add_style("margin: 5px 1px 3px 1px") close_wdg.add_style("float: right") close_wdg.add_class("hand") close_wdg.add_behavior({ 'type': 'click_up', 'cbjs_action': my.get_cancel_script() }) drag_div.add(close_wdg) # create the 'minimize' button ... minimize_wdg = SpanWdg() minimize_wdg.add_style("margin: 5px 1px 3px 1px") #minimize_wdg.add( IconWdg("Minimize", IconWdg.POPUP_WIN_MINIMIZE) ) minimize_wdg.add(IconWdg("Minimize", "BS_MINUS")) minimize_wdg.add_style("float: right") minimize_wdg.add_class("hand") behavior = { 'type': 'click_up', 'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );" } minimize_wdg.add_behavior(behavior) drag_div.add(minimize_wdg) #-- TO ADD SOON -- create the 'refresh' button ... # refresh_wdg = SpanWdg() # refresh_wdg.add( IconWdg("Refresh Popup", IconWdg.POPUP_WIN_REFRESH) ) # refresh_wdg.add_style("float: right") # refresh_wdg.add_class("hand") # behavior = { # 'type': 'click_up', # 'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );" # } # refresh_wdg.add_behavior( behavior ); # drag_div.add(refresh_wdg) width = my.kwargs.get("width") # style drag_div.add_style("font-size: 1.1em") drag_div.add_style("text-align: left") drag_div.add_class("spt_popup_width") drag_handle_div = DivWdg(id='%s_title' % my.name) drag_handle_div.add_style("padding: 12px;") #drag_handle_div.add_gradient("background", "background", +10) drag_handle_div.add_color("background", "background", -5) drag_handle_div.add_color("color", "color") drag_handle_div.add_style("font-weight", "bold") drag_handle_div.add_style("font-size", "12px") # add the drag capability. # NOTE: need to use getParent because spt.popup has not yet been # initialized when this is processed shadow_color = drag_div.get_color("shadow") drag_div.add_behavior({ 'type': 'smart_drag', 'shadow_color': shadow_color, 'drag_el': "@.getParent('.spt_popup')", 'bvr_match_class': 'spt_popup_title', 'options': { 'z_sort': 'bring_forward' }, 'ignore_default_motion': 'true', "cbjs_setup": ''' if (spt.popup.is_background_visible) { spt.popup.offset_x = document.body.scrollLeft; spt.popup.offset_y = document.body.scrollTop; spt.popup.hide_background(); var parent = bvr.src_el.getParent(".spt_popup"); parent.setStyle("box-shadow","0px 0px 20px " + bvr.shadow_color); } else { spt.popup.offset_x = 0; spt.popup.offset_y = 0; } ''', "cbjs_motion": ''' mouse_411.curr_x += spt.popup.offset_x; mouse_411.curr_y += spt.popup.offset_y; spt.mouse.default_drag_motion(evt, bvr, mouse_411); ''', "cbjs_action": '' }) title_wdg = my.title_wdg if not title_wdg: title_wdg = "No Title" #else: # title_wdg = title_wdg drag_handle_div.add_behavior({ 'type': 'double_click', 'cbjs_action': my.get_cancel_script() }) drag_handle_div.add(title_wdg) drag_handle_div.add_class("spt_popup_title") # add a context menu from tactic.ui.container.smart_menu_wdg import SmartMenu SmartMenu.assign_as_local_activator(drag_handle_div, 'HEADER_CTX') drag_handle_div.add_attr("spt_element_name", "Test Dock") # add the content content_div = DivWdg() content_div.add_color("color", "color2") #content_div.add_color("background", "background2") from pyasm.web.palette import Palette palette = Palette.get() content_div.add_color("color", "color2") content_div.add_color("background", "background2") content_div.add_style("margin", "0px, -1px -0px -1px") content_div.set_id("%s_content" % my.name) content_div.add_class("spt_popup_content") content_div.add_style("overflow: hidden") content_div.add_style("display: block") #content_div.add_style("padding: 10px") if not my.content_wdg: my.content_wdg = "No Content" content_div.add(my.content_wdg) drag_div.add(drag_handle_div) my.position_aux_div(drag_div, content_div) content_td.add(drag_div) widget.add(table) # ALWAYS make the Popup a Page Utility Widget (now processed client side) widget.add_class("SPT_PUW") if my.z_start: widget.set_z_start(my.z_start) widget.add_style("z-index: %s" % my.z_start) else: widget.add_style("z-index: 102") # add the resize icon icon = IconWdg("Resize", IconWdg.RESIZE_CORNER) icon.add_style("cursor: nw-resize") icon.add_style("z-index: 1000") icon.add_class("spt_popup_resize") icon.add_style("float: right") icon.add_style("margin-top: -15px") icon.add_behavior({ 'type': 'drag', "drag_el": '@', "cb_set_prefix": 'spt.popup.resize_drag' }) content_td.add(icon) #return widget return div
def get_display(my): top = my.top form = my.form form.add_style("margin: 0px") form.add_style("padding: 0px") top.add(form) input = HtmlElement.input() form.add(input) input.set_attr("name", "file") input.add_class("spt_file") input.set_attr("type", "file") #input.add_style("display: none") #input.add_style("visibility: hidden") input.add_style("position: absolute") input.add_style("margin-left: -5000px") #input.add_style("margin-left: 500px") #input.add_style("margin-top: -50px") multiple = my.kwargs.get("multiple") if multiple in [True, 'true']: input.add_attr("multiple", "multiple") from pyasm.common import Container if not Container.get_dict("JSLibraries", "spt_html5upload"): form.add_behavior( { 'type': 'load', 'form_id': my.form_id, 'cbjs_action': ''' if (spt.html5upload) return; spt.Environment.get().add_library("spt_html5upload") spt.html5upload = {}; spt.html5upload.form = $(bvr.form_id); spt.html5upload.files = []; spt.html5upload.events = {}; spt.html5upload.set_form = function(form) { if (!form) { spt.alert('Cannot initialize the HTML upload. Invalid form detected.'); return; } spt.html5upload.form = form; } // get the last one in the list since this FileList is readonly and it is additive if multiple attr is on spt.html5upload.get_file = function() { var files = spt.html5upload.get_files(); if (files.length == 0) { return null; } return files[files.length-1]; } //FIXME: it doesn't need to be stored as files since it should be called // every time an upload occurs spt.html5upload.get_files = function() { var file_input = spt.html5upload.form.getElement('.spt_file'); spt.html5upload.files = file_input.files; return spt.html5upload.files; } spt.html5upload.select_file = function(onchange) { var files = spt.html5upload.select_files(onchange); if (!files) { spt.alert('You may need to refresh this page.'); return null; } if (files.length == 0) { return null; } return files[0]; } spt.html5upload.select_files = function(onchange) { var form = spt.html5upload.form; if (!form) { spt.alert('Cannot locate the upload form. Refresh this page/tab and try again'); return; } var el = form.getElement(".spt_file") ; /* if (replace) { spt.html5upload.events['select_file'] = null; el.removeEventListener("change", onchange); alert('remove') } */ var event_name = 'select_file'; // ensure this listener is only added once if (!spt.html5upload.events[event_name]){ el.addEventListener("change", onchange, true); } // This is necessary for Qt on a Mac?? if (spt.browser.is_Qt() || spt.browser.is_Safari()) { setTimeout( function() { el.click(); spt.html5upload.events[event_name] = onchange; }, 100 ); } else { el.click(); spt.html5upload.events[event_name] = onchange; } // FIXME: this is not very useful as the select file is async, but // is required for later code not to open a popup spt.html5upload.files = el.files; return spt.html5upload.files; } // clears the otherwise readonly filelist, disables the input spt.html5upload.clear = function() { var form = spt.html5upload.form; var el = form.getElement(".spt_file"); el.value = null; // cloning clears all the event listeners var new_element = el.cloneNode(true); el.parentNode.replaceChild(new_element, el); var event_name = 'select_file'; spt.html5upload.events[event_name] = null; } spt.html5upload.upload_failed = function(evt) { spt.app_busy.hide(); spt.alert("Upload failed"); } spt.html5upload.upload_file = function(kwargs) { if (!kwargs) { kwargs = {}; } var files = kwargs.files; if (typeof(files) == 'undefined') { // get the file from the form element var form = spt.html5upload.form; var el = form.getElement(".spt_file") ; files = el.files; } /* var file_name = el.value; if (file_name.test(/,/)) { spt.alert('Comma , is not allowed in file name.'); spt.html5upload.clear(); return; } */ var upload_start = kwargs.upload_start; var upload_complete = kwargs.upload_complete; var upload_progress = kwargs.upload_progress; var upload_failed = spt.html5upload.upload_failed; var transaction_ticket = kwargs.ticket; if (!transaction_ticket) { server = TacticServerStub.get(); transaction_ticket = server.get_transaction_ticket(); } var upload_dir = kwargs.upload_dir; if(!upload_dir){ upload_dir = ""; } // build the form data structure var fd = new FormData(); for (var i = 0; i < files.length; i++) { fd.append("file"+i, files[i]); files[i].name = JSON.stringify(files[i].name) fd.append("file_name"+i, files[i].name); } fd.append("num_files", files.length); fd.append('transaction_ticket', transaction_ticket); fd.append('upload_dir',upload_dir) /* event listeners */ var xhr = new XMLHttpRequest(); if (upload_start) { xhr.upload.addEventListener("loadstart", upload_start, false); } if (upload_progress) { xhr.upload.addEventListener("progress", upload_progress, false); } if (upload_complete) { xhr.addEventListener("load", upload_complete, false); } if (upload_failed) { xhr.addEventListener("error", upload_failed, false); } //xhr.addEventListener("abort", uploadCanceled, false); xhr.addEventListener("abort", function() {log.critical("abort")}, false); xhr.open("POST", "/tactic/default/UploadServer/", true); xhr.send(fd); } ''' } ) 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_display(self): top = self.top form = self.form form.add_style("margin: 0px") form.add_style("padding: 0px") top.add(form) input = HtmlElement.input() form.add(input) input.set_attr("name", "file") input.add_class("spt_file") input.set_attr("type", "file") input.add_style("position: absolute") input.add_style("margin-left: -5000px") multiple = self.kwargs.get("multiple") if multiple in [True, 'true']: input.add_attr("multiple", "multiple") from pyasm.common import Container if not Container.get_dict("JSLibraries", "spt_html5upload"): form.add_behavior({ 'type': 'load', 'form_id': self.form_id, 'cbjs_action': ''' if (spt.html5upload) return; spt.Environment.get().add_library("spt_html5upload") spt.html5upload = {}; spt.html5upload.form = $(bvr.form_id); spt.html5upload.files = []; spt.html5upload.events = {}; spt.html5upload.ticket; spt.html5upload.set_form = function(form) { if (!form) { spt.alert('Cannot initialize the HTML upload. Invalid form detected.'); return; } spt.html5upload.form = form; } // get the last one in the list since this FileList is readonly and it is additive if multiple attr is on spt.html5upload.get_file = function() { var files = spt.html5upload.get_files(); if (files.length == 0) { return null; } return files[files.length-1]; } //FIXME: it doesn't need to be stored as files since it should be called // every time an upload occurs spt.html5upload.get_files = function() { var file_input = spt.html5upload.form.getElement('.spt_file'); spt.html5upload.files = file_input.files; return spt.html5upload.files; } spt.html5upload.select_file = function(onchange) { var files = spt.html5upload.select_files(onchange); if (!files) { spt.alert('You may need to refresh this page.'); return null; } if (files.length == 0) { return null; } return files[0]; } spt.html5upload.select_files = function(onchange) { var form = spt.html5upload.form; if (!form) { spt.alert('Cannot locate the upload form. Refresh this page/tab and try again'); return; } var el = form.getElement(".spt_file") ; /* if (replace) { spt.html5upload.events['select_file'] = null; el.removeEventListener("change", onchange); alert('remove') } */ var event_name = 'select_file'; // ensure this listener is only added once if (!spt.html5upload.events[event_name]){ el.addEventListener("change", onchange, true); } spt.html5upload.events[event_name] = onchange; el.click(); // FIXME: this is not very useful as the select file is async, but // is required for later code not to open a popup spt.html5upload.files = el.files; return spt.html5upload.files; } // clears the otherwise readonly filelist, disables the input spt.html5upload.clear = function() { var form = spt.html5upload.form; var el = form.getElement(".spt_file"); el.value = null; // cloning clears all the event listeners var new_element = el.cloneNode(true); el.parentNode.replaceChild(new_element, el); var event_name = 'select_file'; spt.html5upload.events[event_name] = null; spt.html5upload.ticket = null; } spt.html5upload.upload_failed = function(evt) { spt.app_busy.hide(); spt.alert("Upload failed"); } spt.html5upload.upload_file = function(kwargs) { if (!kwargs) { kwargs = {}; } var files = kwargs.files; if (typeof(files) == 'undefined') { // get the file from the form element var form = spt.html5upload.form; var el = form.getElement(".spt_file") ; files = el.files; } /* var file_name = el.value; if (file_name.test(/,/)) { spt.alert('Comma , is not allowed in file name.'); spt.html5upload.clear(); return; } */ var upload_start = kwargs.upload_start; var upload_complete = kwargs.upload_complete; var upload_progress = kwargs.upload_progress; var upload_failed = spt.html5upload.upload_failed; var transaction_ticket = kwargs.ticket; if (!transaction_ticket) { server = TacticServerStub.get(); transaction_ticket = server.get_transaction_ticket(); } var upload_dir = kwargs.upload_dir; if(!upload_dir){ upload_dir = ""; } // build the form data structure var fd = new FormData(); for (var i = 0; i < files.length; i++) { fd.append("file"+i, files[i]); files[i].name = JSON.stringify(files[i].name) fd.append("file_name"+i, files[i].name); } fd.append("num_files", files.length); fd.append('transaction_ticket', transaction_ticket); fd.append('upload_dir',upload_dir) /* event listeners */ var xhr = new XMLHttpRequest(); if (upload_start) { xhr.upload.addEventListener("loadstart", upload_start, false); } if (upload_progress) { xhr.upload.addEventListener("progress", upload_progress, false); } if (upload_complete) { xhr.addEventListener("load", upload_complete, false); } if (upload_failed) { xhr.addEventListener("error", upload_failed, false); xhr.addEventListener("abort", upload_failed, false); } xhr.addEventListener('readystatechange', function(evt) { //console.log(evt); //console.log(this.readyState); //console.log(this.status); } ) var env = spt.Environment.get(); var site = env.get_site(); //xhr.addEventListener("abort", uploadCanceled, false); xhr.addEventListener("abort", function() {log.critical("abort")}, false); //alert("/tactic/"+site+"/default/UploadServer/"); if (site && site != "default") { xhr.open("POST", "/tactic/"+site+"/default/UploadServer/", true); } else { xhr.open("POST", "/tactic/default/UploadServer/", true); } xhr.send(fd); } ''' }) return top
def get_display(my): search_type_obj = SearchType.get(my.search_type) sobj_title = search_type_obj.get_title() my.color_mode = my.kwargs.get("color_mode") if not my.color_mode: my.color_mode = "default" top_div = my.top top_div.add_class("spt_edit_top") if not my.is_refresh: my.set_as_panel(top_div) content_div = DivWdg() content_div.add_class("spt_edit_top") content_div.add_class("spt_edit_form_top") content_div.set_attr("spt_search_key", my.search_key) if not Container.get_dict("JSLibraries", "spt_edit"): content_div.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() } ) layout_view = my.kwargs.get("layout_view") if layout_view: layout_wdg = my.get_custom_layout_wdg(layout_view) content_div.add(layout_wdg) return content_div # add close listener # NOTE: this is an absolute search, but is here for backwards # compatibility content_div.add_named_listener('close_EditWdg', ''' var popup = bvr.src_el.getParent( ".spt_popup" ); if (popup) spt.popup.close(popup); ''') attrs = my.config.get_view_attributes() default_access = attrs.get("access") if not default_access: default_access = "edit" project_code = Project.get_project_code() security = Environment.get_security() base_key = search_type_obj.get_base_key() key = { 'search_type': base_key, 'project': project_code } access = security.check_access("sobject", key, "edit", default=default_access) if not access: my.is_disabled = True else: my.is_disabled = False disable_wdg = None if my.is_disabled: # TODO: This overlay doesn't work in IE, size, position, # and transparency all fail. disable_wdg = DivWdg(id='edit_wdg') disable_wdg.add_style("position: absolute") disable_wdg.add_style("height: 90%") disable_wdg.add_style("width: 100%") disable_wdg.add_style("left: 0px") #disable_wdg.add_style("bottom: 0px") #disable_wdg.add_style("top: 0px") disable_wdg.add_style("opacity: 0.2") disable_wdg.add_style("background: #fff") #disable_wdg.add_style("-moz-opacity: 0.2") disable_wdg.add_style("filter: Alpha(opacity=20)") disable_wdg.add("<center>EDIT DISABLED</center>") content_div.add(disable_wdg) attrs = my.config.get_view_attributes() #inner doesn't get styled. inner = DivWdg() content_div.add(inner) menu = my.get_header_context_menu() menus = [menu.get_data()] menus_in = { 'HEADER_CTX': menus, } SmartMenu.attach_smart_context_menu( inner, menus_in, False ) #insert the header before body into inner show_header = my.kwargs.get("show_header") if show_header not in ['false', False]: my.add_header(inner, sobj_title) #insert table into a body container so styling gets applied table = Table() body_container = DivWdg() body_container.add_class("spt_popup_body") body_container.add(table) inner.add(body_container) if my.color_mode == "default": table.add_color("background", "background") elif my.color_mode == "transparent": table.add_style("background", "transparent") table.add_color("color", "color") width = attrs.get('width') if not width: width = my.kwargs.get("width") if not width: width = 600 height = attrs.get('height') if height: table.add_style("height: %s" % height) tr = table.add_row() stype_type = search_type_obj.get_value("type", no_exception=True) if my.mode != 'insert' and stype_type in ['media'] and my.sobjects: td = table.add_cell() width += 300 from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() thumb.set_sobject(my.sobjects[0]) td.add(thumb) thumb.add_style("margin: 0px 10px") path = thumb.get_lib_path() td.add_style("padding: 10px") td.add_attr("rowspan", len(my.widgets)+2) td.add_style("min-width: 250px") td.add_style("vertical-align: top") td.add_border(direction="right") if path: td.add("<h3>File Information</h3>") td.add("<br/>") from pyasm.checkin import BaseMetadataParser parser = BaseMetadataParser.get_parser_by_path(path) data = parser.get_tactic_metadata() data_table = Table() data_table.add_style("margin: 15px") td.add(data_table) for name, value in data.items(): data_table.add_row() display_name = Common.get_display_title(name) dtd = data_table.add_cell("%s: " % display_name) dtd.add_style("width: 150px") dtd.add_style("padding: 3px") dtd = data_table.add_cell(value) dtd.add_style("padding: 3px") else: td.add("<h3>No Image</h3>") td.add("<br/>") # set the width table.add_style("width: %s" % width) single = my.kwargs.get("single") if single in ['false', False] and my.mode == 'insert': multi_div = DivWdg() multi_div.add_style("text-align: left") multi_div.add_style("padding: 5px 10px") multi_div.add("<b>Specify number of new items to add: </b>") multi_div.add(" "*4) multi_text = TextWdg("multiplier") multi_text.add_class("form-control") multi_div.add(multi_text) multi_text.add_style("display: inline-block") multi_text.add_style("width: 60px") tr, td = table.add_row_cell( multi_div ) if my.color_mode == "defaultX": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1px") td.add_style("border-style: solid") td.add_style("padding: 8 3 8 3") td.add_color("background", "background3") td.add_color("color", "color3") security = Environment.get_security() # break the widgets up in columns num_columns = attrs.get('num_columns') if not num_columns: num_columns = my.kwargs.get('num_columns') if not num_columns: num_columns = 1 else: num_columns = int(num_columns) # go through each widget and draw it index = 0 for i, widget in enumerate(my.widgets): # since a widget name called code doesn't necessariy write to code column, it is commented out for now """ key = { 'search_type' : search_type_obj.get_base_key(), 'column' : widget.get_name(), 'project': project_code} # check security on widget if not security.check_access( "sobject_column",\ key, "edit"): my.skipped_element_names.append(widget.get_name()) continue """ if not hasattr(widget, 'set_input_prefix'): msg = DivWdg("Warning: The widget definition for [%s] uses [%s] and is not meant for use in Edit Layout. Please revise the edit_definition in widget config."% (widget.get_name(), widget.__class__.__name__ )) msg.add_style('color: orange') content_div.add(msg) content_div.add(HtmlElement.br()) continue if my.input_prefix: widget.set_input_prefix(my.input_prefix) # Bootstrap widget.add_class("form-control") if not isinstance(widget, CheckboxWdg): widget.add_style("width: 100%") if isinstance(widget, EditTitleWdg): tr, td = table.add_row_cell() tr.add_color("background", "background", -5) td.add_style("height", "30px") td.add_style("padding", "0px 10px") td.add(widget) index = 0 continue if isinstance(widget, HiddenWdg): content_div.add(widget) continue # Set up any validations configured on the widget ... from tactic.ui.app import ValidationUtil v_util = ValidationUtil( widget=widget ) v_bvr = v_util.get_validation_bvr() if v_bvr: if (isinstance(widget, CalendarInputWdg)): widget.set_validation( v_bvr.get('cbjs_validation'), v_bvr.get('validation_warning') ); else: widget.add_behavior( v_bvr ) widget.add_behavior( v_util.get_input_onchange_bvr() ) new_row = index % num_columns == 0 if new_row: tr = table.add_row() if my.color_mode == "default": if index % 2 == 0: tr.add_color("background", "background") else: tr.add_color("background", "background", -1 ) index += 1 show_title = widget.get_option("show_title") if not show_title: show_title = my.kwargs.get("show_title") if show_title in ['false', False]: show_title = False else: show_title = True if show_title: title = widget.get_title() td = table.add_cell(title) td.add_style("padding: 15px 15px 10px 5px") td.add_style("vertical-align: top") title_width = my.kwargs.get("title_width") if title_width: td.add_style("width: %s" % title_width) else: td.add_style("width: 150px") security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): SmartMenu.assign_as_local_activator( td, 'HEADER_CTX' ) if my.color_mode == "defaultX": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1" ) td.add_style("border-style: solid" ) td.add_style("text-align: right" ) hint = widget.get_option("hint") if hint: #hint_wdg = HintWdg(hint) #hint_wdg.add_style("float: right") #td.add( hint_wdg ) td.add_attr("title", hint) if not show_title: th, td = table.add_row_cell( widget ) continue else: td = table.add_cell( widget ) #td = table.add_cell( widget.get_value() ) td.add_style("min-width: 300px") td.add_style("padding: 10px 25px 10px 5px") td.add_style("vertical-align: top") if my.color_mode == "defaultX": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1" ) td.add_style("border-style: solid" ) if not my.is_disabled and not my.mode == 'view': inner.add( my.get_action_html() ) if my.input_prefix: prefix = HiddenWdg("input_prefix", my.input_prefix) tr, td = table.add_row_cell() td.add(prefix) top_div.add(content_div) return top_div
def get_display(my): div = DivWdg() if not Container.get_dict("JSLibraries", "spt_popup"): div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.4") div.add_style("background", "#000") div.add_style("padding: 100px") div.add_style("height: 100%") div.add_style("width: 100%") div.add_class("spt_popup_background") div.add_style("display: none") div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.hide(bvr.src_el); ''' } ) Container.put("PopupWdg:background", True) # This is the absolute outside of a popup, including the drop shadow widget = DivWdg() div.add(widget) widget.add_class("spt_popup") if not Container.get_dict("JSLibraries", "spt_popup"): widget.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() } ) width = my.kwargs.get("width") if not width: width = 10 #widget.add_behavior( { # 'type': 'load', # 'cbjs_action': 'bvr.src_el.makeResizable({handle:bvr.src_el.getElement(".spt_popup_resize")})' #} ) web = WebContainer.get_web() widget.set_id(my.name) if my.kwargs.get("display") == "true": pass else: widget.add_style("display: none") widget.add_style("position: absolute") widget.add_style("left: 400px") widget.add_style("top: 100px") widget.add_border() widget.add_color("background", "background") #widget.set_box_shadow(color="#000") widget.set_box_shadow() table = Table() table.add_behavior( { 'type': 'load', 'width': width, 'cbjs_action': ''' bvr.src_el.setStyle("width", bvr.width) var popup = bvr.src_el.getParent(".spt_popup"); var window_size = $(window).getSize(); var size = bvr.src_el.getSize(); var left = window_size.x/2 - size.x/2; var top = window_size.y/2 - size.y/2; popup.setStyle("left", left); //popup.setStyle("top", top); ''' } ) table.add_row() """ # Qt doesn't support shadows very well if web.get_browser() == 'Qtx': # dynamically add css files table.add_class("css_shadow_table") td = table.add_cell() td.add_class("css_shadow_td css_shadow_top_left SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_top SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_top_right SPT_POPUP_SHADOW") # Middle (Content) Row of Shadow table ... table.add_row() td = table.add_cell() td.add_class("css_shadow_td css_shadow_left SPT_POPUP_SHADOW") """ content_td = table.add_cell() content_td.add_class("css_shadow_td") """ if web.get_browser() == 'Qtx': td = table.add_cell() td.add_class("css_shadow_td css_shadow_right SPT_POPUP_SHADOW") # Bottom Row of Shadow table ... table.add_row() td = table.add_cell() td.add_class("css_shadow_td css_shadow_bottom_left SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_bottom SPT_POPUP_SHADOW") td = table.add_cell() td.add_class("css_shadow_td css_shadow_bottom_right SPT_POPUP_SHADOW") """ drag_div = DivWdg() #from tactic.ui.container import ArrowWdg #arrow = ArrowWdg() #drag_div.add(arrow) # FIXME: for some reason, this causes popups to stop functioning after # close a couple of times my.add_header_context_menu(drag_div) # create the 'close' button ... if my.allow_close: close_wdg = SpanWdg(css='spt_popup_close') #close_wdg.add( IconWdg("Close", IconWdg.POPUP_WIN_CLOSE) ) close_wdg.add( IconWdg("Close", "BS_REMOVE") ) close_wdg.add_style("margin: 5px 1px 3px 1px") close_wdg.add_style("float: right") close_wdg.add_class("hand") close_wdg.add_behavior({ 'type': 'click_up', 'cbjs_action': my.get_cancel_script() }) drag_div.add(close_wdg) # create the 'minimize' button ... minimize_wdg = SpanWdg(css='spt_popup_min') minimize_wdg.add_style("margin: 5px 1px 3px 1px") #minimize_wdg.add( IconWdg("Minimize", IconWdg.POPUP_WIN_MINIMIZE) ) minimize_wdg.add( IconWdg("Minimize", "BS_MINUS") ) minimize_wdg.add_style("float: right") minimize_wdg.add_class("hand") behavior = { 'type': 'click_up', 'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );" } minimize_wdg.add_behavior( behavior ); drag_div.add(minimize_wdg) #-- TO ADD SOON -- create the 'refresh' button ... # refresh_wdg = SpanWdg() # refresh_wdg.add( IconWdg("Refresh Popup", IconWdg.POPUP_WIN_REFRESH) ) # refresh_wdg.add_style("float: right") # refresh_wdg.add_class("hand") # behavior = { # 'type': 'click_up', # 'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );" # } # refresh_wdg.add_behavior( behavior ); # drag_div.add(refresh_wdg) width = my.kwargs.get("width") # style drag_div.add_style("font-size: 1.1em") drag_div.add_style("text-align: left") drag_div.add_class("spt_popup_width") drag_handle_div = DivWdg(id='%s_title' %my.name) drag_handle_div.add_style("padding: 12px;") #drag_handle_div.add_gradient("background", "background", +10) drag_handle_div.add_color("background", "background", -5) drag_handle_div.add_color("color", "color") drag_handle_div.add_style("font-weight", "bold") drag_handle_div.add_style("font-size", "12px") # add the drag capability. # NOTE: need to use getParent because spt.popup has not yet been # initialized when this is processed shadow_color = drag_div.get_color("shadow") drag_div.add_behavior( { 'type':'smart_drag', 'shadow_color': shadow_color, 'drag_el': "@.getParent('.spt_popup')", 'bvr_match_class': 'spt_popup_title', 'options': {'z_sort': 'bring_forward'}, 'ignore_default_motion': 'true', "cbjs_setup": ''' if (spt.popup.is_background_visible) { spt.popup.offset_x = document.body.scrollLeft; spt.popup.offset_y = document.body.scrollTop; spt.popup.hide_background(); var parent = bvr.src_el.getParent(".spt_popup"); parent.setStyle("box-shadow","0px 0px 20px " + bvr.shadow_color); } else { spt.popup.offset_x = 0; spt.popup.offset_y = 0; } ''', "cbjs_motion": ''' mouse_411.curr_x += spt.popup.offset_x; mouse_411.curr_y += spt.popup.offset_y; spt.mouse.default_drag_motion(evt, bvr, mouse_411); ''', "cbjs_action": '' } ) title_wdg = my.title_wdg if not title_wdg: title_wdg = "No Title" #else: # title_wdg = title_wdg drag_handle_div.add_behavior({ 'type': 'double_click', 'cbjs_action': my.get_cancel_script() }) drag_handle_div.add(title_wdg) drag_handle_div.add_class("spt_popup_title") # add a context menu from tactic.ui.container.smart_menu_wdg import SmartMenu SmartMenu.assign_as_local_activator( drag_handle_div, 'HEADER_CTX' ) drag_handle_div.add_attr("spt_element_name", "Test Dock") # add the content content_div = DivWdg() content_div.add_color("color", "color2") #content_div.add_color("background", "background2") from pyasm.web.palette import Palette palette = Palette.get() content_div.add_color("color", "color2") content_div.add_color("background", "background2") content_div.add_style("margin", "0px, -1px -0px -1px") content_div.set_id("%s_content" % my.name) content_div.add_class("spt_popup_content") content_div.add_style("overflow: hidden") content_div.add_style("display: block") #content_div.add_style("padding: 10px") if not my.content_wdg: my.content_wdg = "No Content" content_div.add(my.content_wdg) drag_div.add( drag_handle_div ) my.position_aux_div(drag_div, content_div) content_td.add(drag_div) widget.add(table) # ALWAYS make the Popup a Page Utility Widget (now processed client side) widget.add_class( "SPT_PUW" ) if my.z_start: widget.set_z_start( my.z_start ) widget.add_style("z-index: %s" % my.z_start) else: widget.add_style("z-index: 102") # add the resize icon icon = IconWdg( "Resize", IconWdg.RESIZE_CORNER ) icon.add_style("cursor: nw-resize") icon.add_style("z-index: 1000") icon.add_class("spt_popup_resize") icon.add_style("float: right") icon.add_style("margin-top: -15px") icon.add_behavior( { 'type': 'drag', "drag_el": '@', "cb_set_prefix": 'spt.popup.resize_drag' } ) content_td.add(icon) #return widget return 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("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_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 init(my): #my.inner = DivWdg() my.dialog = None my.button = DivWdg() my.hit_wdg = DivWdg() my.hit_wdg.add_class("spt_button_hit_wdg") my.arrow_div = DivWdg() my.arrow_menu = IconButtonWdg(title="More Options", icon=IconWdg.ARROWHEAD_DARK_DOWN) my.show_arrow_menu = False # for icon decoration my.icon_div = DivWdg() my.is_disabled = my.kwargs.get("is_disabled") in [True, "true"] if not Container.get_dict("JSLibraries", "spt_button"): doc_top = Container.get("TopWdg::top") if doc_top: doc_top.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.Environment.get().add_library("spt_button"); ''' }) bvr_wdg = doc_top else: bvr_wdg = my.top # change to a relay behavior bvr_wdg.add_relay_behavior({ 'type': 'mousedown', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", "none"); click.setStyle("display", ""); ''' }) bvr_wdg.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", ""); click.setStyle("display", "none"); ''' }) bvr_wdg.add_relay_behavior({ 'type': 'mouseenter', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", ""); click.setStyle("display", "none"); ''', }) bvr_wdg.add_relay_behavior({ 'type': 'mouseleave', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", "none"); click.setStyle("display", "none"); ''' })
def init(my): if not Container.get_dict("JSLibraries", "spt_icon_button"): doc_top = Container.get("TopWdg::top") if doc_top: doc_top.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.Environment.get().add_library("spt_icon_button"); ''' }) bvr_wdg = doc_top else: bvr_wdg = my bvr_wdg.add_relay_behavior({ 'type': 'mouseenter', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); out.setStyle("display", "none"); over.setStyle("display", ""); click.setStyle("display", "none"); ''' }) bvr_wdg.add_relay_behavior({ 'type': 'mouseleave', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); out.setStyle("display", ""); over.setStyle("display", "none"); click.setStyle("display", "none"); ''' }) bvr_wdg.add_relay_behavior({ 'type': 'mousedown', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); out.setStyle("display", "none"); over.setStyle("display", "none"); click.setStyle("display", ""); ''' }) bvr_wdg.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); over.setStyle("display", ""); over.setStyle("display", "none"); click.setStyle("display", "none"); ''' })
def init(my): if not Container.get_dict("JSLibraries", "spt_icon_button"): doc_top = Container.get("TopWdg::top") if doc_top: doc_top.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.Environment.get().add_library("spt_icon_button"); ''' } ) bvr_wdg = doc_top else: bvr_wdg = my bvr_wdg.add_relay_behavior( { 'type': 'mouseenter', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); out.setStyle("display", "none"); over.setStyle("display", ""); click.setStyle("display", "none"); ''' } ) bvr_wdg.add_relay_behavior( { 'type': 'mouseleave', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); out.setStyle("display", ""); over.setStyle("display", "none"); click.setStyle("display", "none"); ''' } ) bvr_wdg.add_relay_behavior( { 'type': 'mousedown', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); out.setStyle("display", "none"); over.setStyle("display", "none"); click.setStyle("display", ""); ''' } ) bvr_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_icon_button_top', 'cbjs_action': ''' var out = bvr.src_el.getElement(".spt_button_out"); var over = bvr.src_el.getElement(".spt_button_over"); var click = bvr.src_el.getElement(".spt_button_click"); over.setStyle("display", ""); over.setStyle("display", "none"); click.setStyle("display", "none"); ''' } )
def get_display(my): search_type_obj = SearchType.get(my.search_type) sobj_title = search_type_obj.get_title() my.color_mode = my.kwargs.get("color_mode") if not my.color_mode: my.color_mode = "default" top_div = my.top top_div.add_class("spt_edit_top") if not my.is_refresh: my.set_as_panel(top_div) content_div = DivWdg() content_div.add_class("spt_edit_top") content_div.add_class("spt_edit_form_top") content_div.set_attr("spt_search_key", my.search_key) if not Container.get_dict("JSLibraries", "spt_edit"): content_div.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() } ) layout_view = my.kwargs.get("layout_view") if layout_view: layout_wdg = my.get_custom_layout_wdg(layout_view) content_div.add(layout_wdg) return content_div # add close listener # NOTE: this is an absolute search, but is here for backwards # compatibility content_div.add_named_listener('close_EditWdg', ''' var popup = bvr.src_el.getParent( ".spt_popup" ); if (popup) spt.popup.close(popup); ''') attrs = my.config.get_view_attributes() default_access = attrs.get("access") if not default_access: default_access = "edit" project_code = Project.get_project_code() security = Environment.get_security() base_key = search_type_obj.get_base_key() key = { 'search_type': base_key, 'project': project_code } access = security.check_access("sobject", key, "edit", default=default_access) if not access: my.is_disabled = True else: my.is_disabled = False disable_wdg = None if my.is_disabled: # TODO: This overlay doesn't work in IE, size, position, # and transparency all fail. disable_wdg = DivWdg(id='edit_wdg') disable_wdg.add_style("position: absolute") disable_wdg.add_style("height: 90%") disable_wdg.add_style("width: 100%") disable_wdg.add_style("left: 0px") #disable_wdg.add_style("bottom: 0px") #disable_wdg.add_style("top: 0px") disable_wdg.add_style("opacity: 0.2") disable_wdg.add_style("background: #fff") #disable_wdg.add_style("-moz-opacity: 0.2") disable_wdg.add_style("filter: Alpha(opacity=20)") disable_wdg.add("<center>EDIT DISABLED</center>") content_div.add(disable_wdg) attrs = my.config.get_view_attributes() inner = DivWdg() content_div.add(inner) menu = my.get_header_context_menu() menus = [menu.get_data()] menus_in = { 'HEADER_CTX': menus, } SmartMenu.attach_smart_context_menu( inner, menus_in, False ) table = Table() inner.add(table) if my.color_mode == "default": table.add_color("background", "background") table.add_color("color", "color") width = attrs.get('width') if not width: width = my.kwargs.get("width") if not width: width = 500 table.add_style("width: %s" % width) height = attrs.get('height') if height: table.add_style("height: %s" % height) tr = table.add_row() show_header = my.kwargs.get("show_header") if show_header not in ['false', False]: my.add_header(table, sobj_title) single = my.kwargs.get("single") if single in ['false', False] and my.mode == 'insert': multi_div = DivWdg() multi_div.add_style("text-align: left") multi_div.add("Specify the number of items that will be added with this form:<br/><br/>") multi_div.add("<b># of new items to add: </b>") multi_div.add(" "*4) multi_text = TextWdg("multiplier") multi_text.add_style("width: 30px") multi_div.add(multi_text) tr, td = table.add_row_cell( multi_div ) if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1px") td.add_style("border-style: solid") td.add_style("padding: 8 3 8 3") td.add_color("background", "background3") td.add_color("color", "color3") security = Environment.get_security() # break the widgets up in columns num_columns = attrs.get('num_columns') if not num_columns: num_columns = my.kwargs.get('num_columns') if not num_columns: num_columns = 1 else: num_columns = int(num_columns) # go through each widget and draw it for i, widget in enumerate(my.widgets): # since a widget name called code doesn't necessariy write to code column, it is commented out for now """ key = { 'search_type' : search_type_obj.get_base_key(), 'column' : widget.get_name(), 'project': project_code} # check security on widget if not security.check_access( "sobject_column",\ key, "edit"): my.skipped_element_names.append(widget.get_name()) continue """ if not hasattr(widget, 'set_input_prefix'): msg = DivWdg("Warning: The widget definition for [%s] uses [%s] and is not meant for use in Edit Layout. Please revise the edit_definition in widget config."% (widget.get_name(), widget.__class__.__name__ )) msg.add_style('color: orange') content_div.add(msg) content_div.add(HtmlElement.br()) continue if my.input_prefix: widget.set_input_prefix(my.input_prefix) if isinstance(widget, HiddenWdg): content_div.add(widget) continue # Set up any validations configured on the widget ... from tactic.ui.app import ValidationUtil v_util = ValidationUtil( widget=widget ) v_bvr = v_util.get_validation_bvr() if v_bvr: if (isinstance(widget, CalendarInputWdg)): widget.set_validation( v_bvr.get('cbjs_validation'), v_bvr.get('validation_warning') ); else: widget.add_behavior( v_bvr ) widget.add_behavior( v_util.get_input_onchange_bvr() ) new_row = i % num_columns == 0 if new_row: tr = table.add_row() if my.color_mode == "default": if i % 2 == 0: tr.add_color("background", "background") else: tr.add_color("background", "background", -5) show_title = (widget.get_option("show_title") != "false") if show_title: title = widget.get_title() td = table.add_cell(title) td.add_style("padding: 10px 15px 10px 5px") td.add_style("vertical-align: top") title_width = my.kwargs.get("title_width") if title_width: td.add_style("width: %s" % title_width) else: td.add_style("width: 100px") security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): SmartMenu.assign_as_local_activator( td, 'HEADER_CTX' ) if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1" ) td.add_style("border-style: solid" ) td.add_style("text-align: right" ) if not show_title: th, td = table.add_row_cell( widget ) #td.add_border() continue else: td = table.add_cell( widget ) #td = table.add_cell( widget.get_value() ) td.add_style("min-width: 300px") td.add_style("padding: 10px 15px 10px 5px") td.add_style("vertical-align: top") if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1" ) td.add_style("border-style: solid" ) hint = widget.get_option("hint") if hint: table.add_data( HintWdg(hint) ) if not my.is_disabled and not my.mode == 'view': tr, td = table.add_row_cell( my.get_action_html() ) if my.input_prefix: prefix = HiddenWdg("input_prefix", my.input_prefix) tr, td = table.add_row_cell() td.add(prefix) top_div.add(content_div) return top_div
def init(my): #my.inner = DivWdg() my.dialog = None my.button = DivWdg() my.hit_wdg = DivWdg() my.hit_wdg.add_class("spt_button_hit_wdg") my.arrow_div = DivWdg() my.arrow_menu = IconButtonWdg(title="More Options", icon=IconWdg.ARROWHEAD_DARK_DOWN) my.show_arrow_menu = False # for icon decoration my.icon_div = DivWdg() my.is_disabled = my.kwargs.get("is_disabled") in [True,"true"] if not Container.get_dict("JSLibraries", "spt_button"): doc_top = Container.get("TopWdg::top") if doc_top: doc_top.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.Environment.get().add_library("spt_button"); ''' } ) bvr_wdg = doc_top else: bvr_wdg = my.top # change to a relay behavior bvr_wdg.add_relay_behavior( { 'type': 'mousedown', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", "none"); click.setStyle("display", ""); ''' } ) bvr_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", ""); click.setStyle("display", "none"); ''' } ) bvr_wdg.add_relay_behavior( { 'type': 'mouseenter', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", ""); click.setStyle("display", "none"); ''', } ) bvr_wdg.add_relay_behavior( { 'type': 'mouseleave', 'bvr_match_class': 'spt_button_hit_wdg', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_button_top") var over = top.getElement(".spt_button_over"); var click = top.getElement(".spt_button_click"); over.setStyle("display", "none"); click.setStyle("display", "none"); ''' } )
def get_display(my): search_type_obj = SearchType.get(my.search_type) sobj_title = search_type_obj.get_title() my.color_mode = my.kwargs.get("color_mode") if not my.color_mode: my.color_mode = "default" top_div = my.top top_div.add_class("spt_edit_top") if not my.is_refresh: my.set_as_panel(top_div) content_div = DivWdg() content_div.add_class("spt_edit_top") content_div.add_class("spt_edit_form_top") content_div.set_attr("spt_search_key", my.search_key) if not Container.get_dict("JSLibraries", "spt_edit"): content_div.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() } ) layout_view = my.kwargs.get("layout_view") if layout_view: layout_wdg = my.get_custom_layout_wdg(layout_view) content_div.add(layout_wdg) return content_div # add close listener # NOTE: this is an absolute search, but is here for backwards # compatibility content_div.add_named_listener('close_EditWdg', ''' var popup = bvr.src_el.getParent( ".spt_popup" ); if (popup) spt.popup.close(popup); ''') attrs = my.config.get_view_attributes() default_access = attrs.get("access") if not default_access: default_access = "edit" project_code = Project.get_project_code() security = Environment.get_security() base_key = search_type_obj.get_base_key() key = { 'search_type': base_key, 'project': project_code } access = security.check_access("sobject", key, "edit", default=default_access) if not access: my.is_disabled = True else: my.is_disabled = False disable_wdg = None if my.is_disabled: # TODO: This overlay doesn't work in IE, size, position, # and transparency all fail. disable_wdg = DivWdg(id='edit_wdg') disable_wdg.add_style("position: absolute") disable_wdg.add_style("height: 90%") disable_wdg.add_style("width: 100%") disable_wdg.add_style("left: 0px") #disable_wdg.add_style("bottom: 0px") #disable_wdg.add_style("top: 0px") disable_wdg.add_style("opacity: 0.2") disable_wdg.add_style("background: #fff") #disable_wdg.add_style("-moz-opacity: 0.2") disable_wdg.add_style("filter: Alpha(opacity=20)") disable_wdg.add("<center>EDIT DISABLED</center>") content_div.add(disable_wdg) attrs = my.config.get_view_attributes() inner = DivWdg() content_div.add(inner) menu = my.get_header_context_menu() menus = [menu.get_data()] menus_in = { 'HEADER_CTX': menus, } SmartMenu.attach_smart_context_menu( inner, menus_in, False ) table = Table() inner.add(table) if my.color_mode == "default": table.add_color("background", "background") elif my.color_mode == "transparent": table.add_style("background", "transparent") table.add_color("color", "color") width = attrs.get('width') if not width: width = my.kwargs.get("width") if not width: width = 600 table.add_style("width: %s" % width) height = attrs.get('height') if height: table.add_style("height: %s" % height) tr = table.add_row() show_header = my.kwargs.get("show_header") if show_header not in ['false', False]: my.add_header(table, sobj_title) single = my.kwargs.get("single") if single in ['false', False] and my.mode == 'insert': multi_div = DivWdg() multi_div.add_style("text-align: left") multi_div.add("Specify the number of items that will be added with this form:<br/><br/>") multi_div.add("<b># of new items to add: </b>") multi_div.add(" "*4) multi_text = TextWdg("multiplier") multi_text.add_style("width: 30px") multi_div.add(multi_text) tr, td = table.add_row_cell( multi_div ) if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1px") td.add_style("border-style: solid") td.add_style("padding: 8 3 8 3") td.add_color("background", "background3") td.add_color("color", "color3") security = Environment.get_security() # break the widgets up in columns num_columns = attrs.get('num_columns') if not num_columns: num_columns = my.kwargs.get('num_columns') if not num_columns: num_columns = 1 else: num_columns = int(num_columns) # go through each widget and draw it for i, widget in enumerate(my.widgets): # since a widget name called code doesn't necessariy write to code column, it is commented out for now """ key = { 'search_type' : search_type_obj.get_base_key(), 'column' : widget.get_name(), 'project': project_code} # check security on widget if not security.check_access( "sobject_column",\ key, "edit"): my.skipped_element_names.append(widget.get_name()) continue """ if not hasattr(widget, 'set_input_prefix'): msg = DivWdg("Warning: The widget definition for [%s] uses [%s] and is not meant for use in Edit Layout. Please revise the edit_definition in widget config."% (widget.get_name(), widget.__class__.__name__ )) msg.add_style('color: orange') content_div.add(msg) content_div.add(HtmlElement.br()) continue if my.input_prefix: widget.set_input_prefix(my.input_prefix) # Bootstrap widget.add_class("form-control") widget.add_style("width: 100%") class EditTitleWdg(BaseRefreshWdg): pass #if isinstance(widget, EditTitleWdg): """ has_title = True if has_title and i % 3 == 0: tr, td = table.add_row_cell() tr.add_color("background", "background", -5) td.add("TITLE") td.add_style("height", "30px") td.add_style("padding", "0px 10px") """ if isinstance(widget, HiddenWdg): content_div.add(widget) continue # Set up any validations configured on the widget ... from tactic.ui.app import ValidationUtil v_util = ValidationUtil( widget=widget ) v_bvr = v_util.get_validation_bvr() if v_bvr: if (isinstance(widget, CalendarInputWdg)): widget.set_validation( v_bvr.get('cbjs_validation'), v_bvr.get('validation_warning') ); else: widget.add_behavior( v_bvr ) widget.add_behavior( v_util.get_input_onchange_bvr() ) new_row = i % num_columns == 0 if new_row: tr = table.add_row() if my.color_mode == "default": if i % 2 == 0: tr.add_color("background", "background") else: tr.add_color("background", "background", -2 ) show_title = widget.get_option("show_title") if not show_title: show_title = my.kwargs.get("show_title") if show_title in ['false', False]: show_title = False else: show_title = True if show_title: title = widget.get_title() td = table.add_cell(title) td.add_style("padding: 10px 15px 10px 5px") td.add_style("vertical-align: top") title_width = my.kwargs.get("title_width") if title_width: td.add_style("width: %s" % title_width) else: td.add_style("width: 150px") security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): SmartMenu.assign_as_local_activator( td, 'HEADER_CTX' ) if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1" ) td.add_style("border-style: solid" ) td.add_style("text-align: right" ) hint = widget.get_option("hint") if hint: #hint_wdg = HintWdg(hint) #hint_wdg.add_style("float: right") #td.add( hint_wdg ) td.add_attr("title", hint) if not show_title: th, td = table.add_row_cell( widget ) continue else: td = table.add_cell( widget ) #td = table.add_cell( widget.get_value() ) td.add_style("min-width: 300px") td.add_style("padding: 10px 15px 10px 5px") td.add_style("vertical-align: top") if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1" ) td.add_style("border-style: solid" ) if not my.is_disabled and not my.mode == 'view': tr, td = table.add_row_cell( my.get_action_html() ) if my.input_prefix: prefix = HiddenWdg("input_prefix", my.input_prefix) tr, td = table.add_row_cell() td.add(prefix) top_div.add(content_div) return top_div