def get_display(my): div = DivWdg() sobject = my.get_current_sobject() search_key = SearchKey.get_by_sobject(sobject) if sobject.is_admin(): return "ADMIN" icon = IconButtonWdg("Global Permissions", IconWdg.EDIT) icon.add_behavior( { "type": "click_up", "cbjs_action": "spt.popup.get_widget(evt, bvr)", "options": { "class_name": "tactic.ui.panel.SecurityManagerWdg", "title": "Permisssion Manager", "popup_id": "Permission Manager" }, "args": { "search_key": search_key } } ) div.add(icon) return div
def get_display(my): widget = Widget() thumb = super(ThumbPublishWdg, my).get_display() widget.add(thumb) sobject = my.get_current_sobject() search_type = sobject.get_search_type() search_id = sobject.get_id() publish_link = PublishLinkWdg(search_type,search_id) div = DivWdg(publish_link) div.set_style('clear: left; padding-top: 6px') widget.add(div) # build an iframe to show publish browsing browse_link = IconButtonWdg("Publish Browser", IconWdg.CONTENTS) iframe = WebContainer.get_iframe() iframe.set_width(100) url = WebContainer.get_web().get_widget_url() url.set_option("widget", "pyasm.prod.web.PublishBrowserWdg") url.set_option("search_type", search_type) url.set_option("search_id", search_id) script = iframe.get_on_script(url.to_string()) browse_link.add_event("onclick", script) div.add(browse_link) div.set_style('padding-top: 6px') return widget
def get_display(my): widget = Widget() thumb = super(ThumbPublishWdg, my).get_display() widget.add(thumb) sobject = my.get_current_sobject() search_type = sobject.get_search_type() search_id = sobject.get_id() publish_link = PublishLinkWdg(search_type, search_id) div = DivWdg(publish_link) div.set_style('clear: left; padding-top: 6px') widget.add(div) # build an iframe to show publish browsing browse_link = IconButtonWdg("Publish Browser", IconWdg.CONTENTS) iframe = WebContainer.get_iframe() iframe.set_width(100) url = WebContainer.get_web().get_widget_url() url.set_option("widget", "pyasm.prod.web.PublishBrowserWdg") url.set_option("search_type", search_type) url.set_option("search_id", search_id) script = iframe.get_on_script(url.to_string()) browse_link.add_event("onclick", script) div.add(browse_link) div.set_style('padding-top: 6px') return widget
def get_display(my): my.view = my.kwargs.get('view') if not my.view: my.view = 'publish' widget = Widget() sobject = my.get_current_sobject() search_type = sobject.get_search_type() search_id = sobject.get_id() if my.get_option('preview') != 'false': my.thumb.set_current_index(my.get_current_index()) widget.add(my.thumb) publish_link = PublishLinkWdg(search_type,search_id, config_base=my.view) div = DivWdg(publish_link) div.set_style('clear: left; padding-top: 6px') widget.add(div) # build a popup link to show publish browsing browse_link = IconButtonWdg("Publish Browser", IconWdg.CONTENTS) browse_link.add_behavior({'type': 'click_up', 'cbjs_action': 'spt.popup.get_widget(evt, bvr)', 'options': {'popup_id' : 'publish_browser', 'class_name' : 'pyasm.prod.web.PublishBrowserWdg' , 'title': 'Publish Browser'}, 'args' : { 'search_type': search_type, 'search_id' : search_id } }) div.add(browse_link) div.set_style('padding-top: 6px') return widget
def get_display(my): sobject = my.get_current_sobject() widget_class = my.get_option("class") if widget_class == '': raise WidgetException("No widget class defined") url = WebContainer.get_web().get_widget_url() url.set_option("widget", widget_class) url.set_option("search_key", sobject.get_search_key()) ref = url.get_url() iframe = Container.get("iframe") iframe.set_width(90) action = iframe.get_on_script(ref) info_type = my.get_option("info_type") button = IconButtonWdg("%s info" % info_type, IconWdg.INFO) button.add_event("onclick", "%s" % (action) ) button.add_style("margin: 3px 5px") return button
def get_display(self): top = DivWdg() self.set_as_panel(top) title_div = DivWdg() title_div.add_class("maq_search_bar") title_div.add("Diagnostics") top.add(title_div) tool_div = DivWdg() top.add(tool_div) refresh = IconButtonWdg("Refresh", IconWdg.REFRESH) refresh.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' }) tool_div.add(refresh) content = RoundedCornerDivWdg(hex_color_code="2F2F2F", corner_size="10") content.set_dimensions(width_str='300px', content_height_str=None) top.add(content) server_title_div = DivWdg() server_title_div.add_class("maq_search_bar") content.add(server_title_div) server_title_div.add("Server") server_content_div = DivWdg() server_content_div.add_style("padding: 10px") server_content_div.add(self.get_ping_wdg()) server_content_div.add(self.get_load_balance_wdg()) content.add(server_content_div) database_title_div = DivWdg() database_title_div.add_class("maq_search_bar") content.add(database_title_div) database_title_div.add("Database") database_content_div = DivWdg() database_content_div.add_style("padding: 10px") database_content_div.add(self.get_database_wdg()) content.add(database_content_div) checkin_title_div = DivWdg() checkin_title_div.add_class("maq_search_bar") content.add(checkin_title_div) checkin_title_div.add("Database") checkin_content_div = DivWdg() checkin_content_div.add_style("padding: 10px") checkin_content_div.add(self.get_asset_dir_wdg()) checkin_content_div.add(self.get_asset_management_wdg()) content.add(checkin_content_div) return top
def get_display(my): web = WebContainer.get_web() if not my.view: view = web.get_form_value("filter|view") # create popup create_popup = PopupWdg("create_action") create_popup.set_auto_hide(False) create_popup.add("Enter name of view: ") create_popup.add(TextWdg("create_view_name")) # create_popup.add( HtmlElement.br(2) ) # create_popup.add( "Copy from template: " ) # template_select = SelectWdg("copy_from_template") # template_select.add_empty_option("-- None --") # template_select.set_option("values", "list|summary|task") # create_popup.add( template_select ) create_popup.add(HtmlElement.br(2, clear="all")) from pyasm.prod.web import ProdIconButtonWdg, ProdIconSubmitWdg create_icon = ProdIconButtonWdg("Create") ajax = AjaxCmd() ajax.register_cmd("pyasm.widget.CustomCreateViewCbk") ajax.add_element_name("create_view_name") ajax.add_element_name("auto_create_edit") ajax.set_option("search_type", my.search_type) ajax.set_option("project", Project.get_project_code()) if my.view: ajax.set_option("template_view", my.view) create_icon.add_event( "onclick", "%s;%s" % (ajax.get_on_script(), "toggle_display('create_action');setTimeout('document.form.submit()',1000)"), ) cancel_icon = ProdIconButtonWdg("Cancel") cancel_icon.add_event("onclick", "toggle_display('create_action')") span = SpanWdg() span.add(create_icon) span.add(cancel_icon) create_popup.add(span) create_popup.add(HtmlElement.br()) # add the create button create = IconButtonWdg("Create View", IconWdg.SAVE, True) create.add_event("onclick", "%s" % create_popup.get_on_script()) # lay it all out widget = Widget() widget.add(create_popup) # Browser does not have create # widget.add(create) return widget
def get_display(my): web = WebContainer.get_web() if not my.view: view = web.get_form_value("filter|view") # create popup create_popup = PopupWdg("create_action") create_popup.set_auto_hide(False) create_popup.add("Enter name of view: ") create_popup.add(TextWdg("create_view_name")) #create_popup.add( HtmlElement.br(2) ) #create_popup.add( "Copy from template: " ) #template_select = SelectWdg("copy_from_template") #template_select.add_empty_option("-- None --") #template_select.set_option("values", "list|summary|task") #create_popup.add( template_select ) create_popup.add(HtmlElement.br(2, clear="all")) from pyasm.prod.web import ProdIconButtonWdg, ProdIconSubmitWdg create_icon = ProdIconButtonWdg('Create') ajax = AjaxCmd() ajax.register_cmd("pyasm.widget.CustomCreateViewCbk") ajax.add_element_name("create_view_name") ajax.add_element_name("auto_create_edit") ajax.set_option("search_type", my.search_type) ajax.set_option("project", Project.get_project_code()) if my.view: ajax.set_option("template_view", my.view) create_icon.add_event( "onclick", "%s;%s" % (ajax.get_on_script(), "toggle_display('create_action');setTimeout('document.form.submit()',1000)" )) cancel_icon = ProdIconButtonWdg('Cancel') cancel_icon.add_event("onclick", "toggle_display('create_action')") span = SpanWdg() span.add(create_icon) span.add(cancel_icon) create_popup.add(span) create_popup.add(HtmlElement.br()) # add the create button create = IconButtonWdg("Create View", IconWdg.SAVE, True) create.add_event("onclick", "%s" % create_popup.get_on_script()) # lay it all out widget = Widget() widget.add(create_popup) # Browser does not have create #widget.add(create) return widget
def init(my): my.layer = LayerWdg(my.xpos, my.ypos, my.display) if not my.width: my.shadowbox = ShadowBoxWdg(my.shad_name) else: my.shadowbox = ShadowBoxWdg(my.shad_name, my.width) # do not enable it for the Login page web = WebContainer.get_web() if my.shad_name and not web.is_IE(): BaseAppServer.add_onload_script("Move.drag('%s','%s')" \ %(my.shadowbox.get_name(), my.iframe_name)) div = DivWdg() from pyasm.widget import IconButtonWdg move_button = IconWdg(name='move me', icon=IconWdg.NAV) move_button.set_id("%s_handle" % (my.shad_name)) move_button.add_class('move') move_button.add_style('float: left') move_button.add_style('padding: 2px 0 0 6px') if not web.is_IE(): div.add(move_button) mbutton = IconButtonWdg(name='close window', icon=IconWdg.KILL) mbutton.set_class("moduleKillBtn") mbutton.add_event("onclick", my.layer.get_off_script() ) div.add(mbutton) if my.nav_links: back_link = HtmlElement.href("<<", "javascript:history.back()") back_link.add_style("font-size", "1.4em") for_link = HtmlElement.href(">>", "javascript:history.forward()") for_link.add_style("font-size", "1.4em") div.add(SpanWdg(back_link, css='med')) div.add(SpanWdg(for_link, css='med')) my.shadowbox.set_header(div) # add button and title_wdg to shadow box if my.title_wdg: title_wdg = DivWdg() title_wdg.set_class("moduleTitle") title_wdg.add(my.title_wdg) my.shadowbox.set_title_wdg(title_wdg) my.layer.add(my.shadowbox) my._add_widget(my.layer)
def get_item_wdg(self, item, is_template=False): item_div = DivWdg() item_div.add_style("margin-top: 3px") if is_template == True: item_div.add_style("display: none") #item_div.add_style("border: solid 1px blue") item_div.add_class("spt_list_template_item") else: item_div.add_class("spt_list_item") outer = DivWdg() outer.add_style("float: left") outer.add_style("text-align: left") outer.add(item) if self.show_enabled: checkbox = CheckboxWdg("enabled") checkbox.add_style("float: left") checkbox.set_checked() else: checkbox = HiddenWdg("enabled") item_div.add(checkbox) #item_div.add(item) item_div.add(outer) from tactic.ui.widget import IconButtonWdg add_wdg = DivWdg() add_wdg.add_class("hand") add_wdg.add_class("SPT_DTS") #add_wdg.add("(+)") add_wdg.add_class("spt_add") button = IconButtonWdg(title="Add Entry", icon="BS_PLUS") add_wdg.add(button) add_wdg.add_style("float: left") add_wdg.add_style("opacity: 0.5") #add_wdg.add_style("margin: 3px") item_div.add(add_wdg) remove_wdg = DivWdg() remove_wdg.add_class("hand") remove_wdg.add_class("SPT_DTS") #remove_wdg.add("(-)") remove_wdg.add_class("spt_remove") button = IconButtonWdg(title="Remove Entry", icon="BS_REMOVE") remove_wdg.add(button) remove_wdg.add_style("float: left") remove_wdg.add_style("opacity: 0.5") #remove_wdg.add_style("margin: 3px") item_div.add(remove_wdg) item_div.add("<br clear='all'/>") return item_div
def get_create_view_wdg(my, search_type): # create popup create_popup = PopupWdg("create_action") create_popup.set_auto_hide(False) create_popup.add("Enter name of view: ") create_popup.add(TextWdg("create_view_name")) #create_popup.add( HtmlElement.br(2) ) #create_popup.add( "Copy from template: " ) #template_select = SelectWdg("copy_from_template") #template_select.add_empty_option("-- None --") #template_select.set_option("values", "list|summary|task") #create_popup.add( template_select ) create_popup.add(HtmlElement.br(2)) create_popup.add( CheckboxWdg('auto_create_edit', label='Auto Create Edit View')) create_popup.add(HtmlElement.br(2, clear="all")) from pyasm.prod.web import ProdIconButtonWdg, ProdIconSubmitWdg create_icon = ProdIconButtonWdg('Create') ajax = AjaxCmd() ajax.register_cmd("pyasm.widget.CustomCreateViewCbk") ajax.add_element_name("create_view_name") ajax.add_element_name("auto_create_edit") ajax.set_option("search_type", search_type) ajax.set_option("project", Project.get_project_code()) div = ajax.generate_div() div.set_post_ajax_script('document.form.submit()') create_icon.add_event( "onclick", "%s;%s" % (ajax.get_on_script(), "toggle_display('create_action')")) cancel_icon = ProdIconButtonWdg('Cancel') cancel_icon.add_event("onclick", "toggle_display('create_action')") span = SpanWdg() span.add(create_icon) span.add(cancel_icon) create_popup.add(span) create_popup.add(HtmlElement.br()) # add the create button create = IconButtonWdg("Create View", IconWdg.SAVE, True) create.add_event("onclick", "%s" % create_popup.get_on_script()) # lay it all out widget = Widget() widget.add(create_popup) widget.add(create) widget.add(div) return widget
def get_create_view_wdg(my, search_type): # create popup create_popup = PopupWdg("create_action") create_popup.set_auto_hide(False) create_popup.add("Enter name of view: ") create_popup.add(TextWdg("create_view_name")) # create_popup.add( HtmlElement.br(2) ) # create_popup.add( "Copy from template: " ) # template_select = SelectWdg("copy_from_template") # template_select.add_empty_option("-- None --") # template_select.set_option("values", "list|summary|task") # create_popup.add( template_select ) create_popup.add(HtmlElement.br(2)) create_popup.add(CheckboxWdg("auto_create_edit", label="Auto Create Edit View")) create_popup.add(HtmlElement.br(2, clear="all")) from pyasm.prod.web import ProdIconButtonWdg, ProdIconSubmitWdg create_icon = ProdIconButtonWdg("Create") ajax = AjaxCmd() ajax.register_cmd("pyasm.widget.CustomCreateViewCbk") ajax.add_element_name("create_view_name") ajax.add_element_name("auto_create_edit") ajax.set_option("search_type", search_type) ajax.set_option("project", Project.get_project_code()) div = ajax.generate_div() div.set_post_ajax_script("document.form.submit()") create_icon.add_event("onclick", "%s;%s" % (ajax.get_on_script(), "toggle_display('create_action')")) cancel_icon = ProdIconButtonWdg("Cancel") cancel_icon.add_event("onclick", "toggle_display('create_action')") span = SpanWdg() span.add(create_icon) span.add(cancel_icon) create_popup.add(span) create_popup.add(HtmlElement.br()) # add the create button create = IconButtonWdg("Create View", IconWdg.SAVE, True) create.add_event("onclick", "%s" % create_popup.get_on_script()) # lay it all out widget = Widget() widget.add(create_popup) widget.add(create) widget.add(div) return widget
def get_display(self): sobject = self.get_current_sobject() url = WebContainer.get_web().get_widget_url() url.set_option("widget", self.get_annotate_wdg_class()) url.set_option("search_type", sobject.get_search_type()) url.set_option("search_id", sobject.get_id()) button = IconButtonWdg("Annotate", IconWdg.DETAILS, False) button.add_event("onclick", \ "document.location='%s'" % url.to_string() ) widget = Widget() widget.add(button) return widget
def get_display(my): # add the add property button iframe = WebContainer.get_iframe() url = WebContainer.get_web().get_widget_url() url.set_option("widget", "pyasm.widget.CustomAddPropertyWdg") url.set_option("search_type", my.search_type) url.set_option("view", my.view) action = iframe.get_on_script(url.to_string() ) add = IconButtonWdg("Add Property", IconWdg.INSERT, True) add.add_event("oncontextmenu", "%s;return false" % action ) add.add_event("onclick", "%s" % action ) widget = Widget() widget.add(add) return widget
def get_display(my): sobject = my.get_current_sobject() url = WebContainer.get_web().get_widget_url() url.set_option("widget", my.get_annotate_wdg_class() ) url.set_option("search_type", sobject.get_search_type() ) url.set_option("search_id", sobject.get_id() ) button = IconButtonWdg("Annotate", IconWdg.DETAILS, False) button.add_event("onclick", \ "document.location='%s'" % url.to_string() ) widget = Widget() widget.add(button) return widget
def get_open_wdg( sobject, file_type=None): ''' given a snapshot. open the sandbox in explorer ''' span = SpanWdg() # explore button dir = sobject.get_client_lib_dir(file_type=file_type) open_button = IconButtonWdg( "Explore: %s" % dir, IconWdg.LOAD, False) open_button.add_event("onclick", "Applet.open_explorer('%s')" % dir) open_button.add_class('small') span.add(open_button) #dir = sobject.get_sandbox_dir() #copy_button = IconButtonWdg( "Copy to sandbox: %s" % dir, IconWdg.DOWNLOAD, False) #span.add(copy_button) return span
def get_values_script(self): save_button = IconButtonWdg("Save Settings", IconWdg.SAVE) save_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' get_values = function() { var top = bvr.src_el.getParent(".spt_list_top"); var elements = bvr.src_el.getElements(".spt_list_items"); var data = []; for (var i=0; i<elements.length; i++) { var values = spt.api.get_input_values(elements[i]); data.push(values) } return data; } ''' } ) content_div.add(save_button)
def get_values_script(my): save_button = IconButtonWdg("Save Settings", IconWdg.SAVE) save_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' get_values = function() { var top = bvr.src_el.getParent(".spt_list_top"); var elements = bvr.src_el.getElements(".spt_list_items"); var data = []; for (var i=0; i<elements.length; i++) { var values = spt.api.get_input_values(elements[i]); data.push(values) } return data; } ''' }) content_div.add(save_button)
def get_display(my): sobject = my.get_current_sobject() widget_class = my.get_option("class") if widget_class == '': raise WidgetException("No widget class defined") url = WebContainer.get_web().get_widget_url() url.set_option("widget", widget_class) url.set_option("search_key", sobject.get_search_key()) ref = url.get_url() iframe = Container.get("iframe") iframe.set_width(90) action = iframe.get_on_script(ref) info_type = my.get_option("info_type") button = IconButtonWdg("%s info" % info_type, IconWdg.INFO) button.add_event("onclick", "%s" % (action)) button.add_style("margin: 3px 5px") return button
def init(self): self.layer = LayerWdg(self.xpos, self.ypos, self.display) if not self.width: self.shadowbox = ShadowBoxWdg(self.shad_name) else: self.shadowbox = ShadowBoxWdg(self.shad_name, self.width) # do not enable it for the Login page web = WebContainer.get_web() if self.shad_name and not web.is_IE(): BaseAppServer.add_onload_script("Move.drag('%s','%s')" \ %(self.shadowbox.get_name(), self.iframe_name)) div = DivWdg() from pyasm.widget import IconButtonWdg move_button = IconWdg(name='move me', icon=IconWdg.NAV) move_button.set_id("%s_handle" % (self.shad_name)) move_button.add_class('move') move_button.add_style('float: left') move_button.add_style('padding: 2px 0 0 6px') if not web.is_IE(): div.add(move_button) mbutton = IconButtonWdg(name='close window', icon=IconWdg.KILL) mbutton.set_class("moduleKillBtn") mbutton.add_event("onclick", self.layer.get_off_script()) div.add(mbutton) if self.nav_links: back_link = HtmlElement.href("<<", "javascript:history.back()") back_link.add_style("font-size", "1.4em") for_link = HtmlElement.href(">>", "javascript:history.forward()") for_link.add_style("font-size", "1.4em") div.add(SpanWdg(back_link, css='med')) div.add(SpanWdg(for_link, css='med')) self.shadowbox.set_header(div) # add button and title_wdg to shadow box if self.title_wdg: title_wdg = DivWdg() title_wdg.set_class("moduleTitle") title_wdg.add(self.title_wdg) self.shadowbox.set_title_wdg(title_wdg) self.layer.add(self.shadowbox) self._add_widget(self.layer)
def _add_publish_link(self, main_div): publish_link = PublishLinkWdg(self.sobject.get_search_type(), self.sobject.get_id()) div = DivWdg(publish_link) div.add_style('padding-top','5px') main_div.add(div) # build an iframe to show publish browsing search_type = self.sobject.get_search_type() search_id = self.sobject.get_id() from pyasm.widget import IconButtonWdg, IconWdg browse_link = IconButtonWdg("Publish Browser", IconWdg.CONTENTS) iframe = WebContainer.get_iframe() iframe.set_width(100) url = WebContainer.get_web().get_widget_url() url.set_option("widget", "pyasm.prod.web.PublishBrowserWdg") url.set_option("search_type", search_type) url.set_option("search_id", search_id) script = iframe.get_on_script(url.to_string()) browse_link.add_event("onclick", script) div.add(browse_link) div.set_style('padding-top: 6px')
def _add_publish_link(self, main_div): publish_link = PublishLinkWdg(self.sobject.get_search_type(), self.sobject.get_id()) div = DivWdg(publish_link) div.add_style('padding-top', '5px') main_div.add(div) # build an iframe to show publish browsing search_type = self.sobject.get_search_type() search_id = self.sobject.get_id() from pyasm.widget import IconButtonWdg, IconWdg browse_link = IconButtonWdg("Publish Browser", IconWdg.CONTENTS) iframe = WebContainer.get_iframe() iframe.set_width(100) url = WebContainer.get_web().get_widget_url() url.set_option("widget", "pyasm.prod.web.PublishBrowserWdg") url.set_option("search_type", search_type) url.set_option("search_id", search_id) script = iframe.get_on_script(url.to_string()) browse_link.add_event("onclick", script) div.add(browse_link) div.set_style('padding-top: 6px')
def get_display(self): parent = self.get_current_sobject() parent_key = SearchKey.get_by_sobject(parent) div = DivWdg() from pyasm.widget import IconButtonWdg, IconWdg icon = IconButtonWdg("Add Task", IconWdg.ADD) div.add(icon) #div.add("Add Tasks") div.add_class("hand") div.add_behavior({ "type": "click_up", "parent_type": parent.get_base_search_type(), "cbfn_action": "spt.dg_table.add_tasks_cbk", }) content = DivWdg() content.add_class("content") div.add(content) return div
def get_open_wdg(sobject, file_type=None): ''' given a snapshot. open the sandbox in explorer ''' span = SpanWdg() # explore button dir = sobject.get_client_lib_dir(file_type=file_type) open_button = IconButtonWdg("Explore: %s" % dir, IconWdg.LOAD, False) open_button.add_event("onclick", "Applet.open_explorer('%s')" % dir) open_button.add_class('small') span.add(open_button) #dir = sobject.get_sandbox_dir() #copy_button = IconButtonWdg( "Copy to sandbox: %s" % dir, IconWdg.DOWNLOAD, False) #span.add(copy_button) return span
def get_display(my): my.set_option('icon', "CONTENTS") sobject = my.get_current_sobject() search_type = sobject.get_search_type() context = my.get_option("context") if not context: context = "publish" process = my.get_option("process") if not process: process = "publish" if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject sobject = snapshot.get_parent() if sobject: search_type = sobject.get_search_type() else: top = DivWdg() return top else: if process: snapshot = Snapshot.get_latest_by_sobject(sobject, process=process) else: snapshot = Snapshot.get_latest_by_sobject(sobject, context=context) if not snapshot: top = DivWdg() return top top = DivWdg() icon = IconButtonWdg( "Show Metadata", eval( "IconWdg.%s" % my.get_option('icon') ) ) top.add(icon) top.add_style("text-align: center") lib_path = snapshot.get_lib_path_by_type("main") basename = os.path.basename(lib_path) dirname = os.path.dirname(lib_path) my.behavior['basename'] = basename my.behavior['dirname'] = dirname my.behavior['search_type'] = search_type cbjs_action = ''' var class_name = 'tactic.ui.tools.repo_browser_wdg.RepoBrowserContentWdg'; var kwargs = { basename: '%(basename)s', dirname: '%(dirname)s', search_type: '%(search_type)s' }; //spt.tab.set_main_body_tab(); //spt.tab.add_new("Detail", "Detail", class_name, kwargs); spt.panel.load_popup("Detail", class_name, kwargs); ''' % (my.behavior) my.behavior['type'] = 'click_up' my.behavior['cbjs_action'] = cbjs_action icon.add_behavior(my.behavior) return top
def get_display(self): top = DivWdg() top.add_class("ad_input_top") name = self.get_name() text = TextWdg(self.get_input_name()) # get the login sobject = self.get_current_sobject() client = sobject.get_value("contact_name") print "client: ", client if client: login_sobj = Login.get_by_code(client) else: login_sobj = Environment.get_login() # build the display_name login = login_sobj.get_value("login") display_name = login_sobj.get_value("display_name") if not display_name: display_name = "%s %s" % (user.get('first_name'), user.get('last_name')) display_name = display_name.replace('"', "'") print "login: "******"spt_ad_input") if login: hidden.set_value(login) top.add(hidden) # copy over some options #text.set_options( self.options.copy() ) if login: text.set_value(display_name) text.set_option("read_only", "true") text.add_class("spt_ad_display") top.add(text) top.add(" ") groups_str = self.get_option("groups_allowed_to_search") if groups_str: stmt = 'groups_list = %s' % groups_str exec stmt else: groups_list = None allow_search = True if groups_list: allow_search = False login_in_group_list = Search.eval( "@SOBJECT(sthpw/login_in_group['login','=','%s'])" % login) for login_in_group in login_in_group_list: group = login_in_group.get_value("login_group") if group in groups_list: allow_search = True break if login == 'admin': allow_search = True if allow_search: button = IconButtonWdg('Search for User', IconWdg.USER) #button = ButtonWdg() button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); spt.toggle_show_hide(content); ''' }) top.add(button) ad_top = DivWdg() ad_top.add_class("ad_input_content") ad_top.add_style("display: none") ad_top.add_style("position: absolute") ad_top.add_style("background: #222") ad_top.add_style("min-width: 300px") ad_top.add_style("border: solid 1px #000") ad_top.add_style("padding: 20px") cbjs_action = ''' var value = bvr.src_el.getAttribute('spt_input_value'); var display_value = bvr.src_el.getAttribute('spt_display_value'); var phone_number = bvr.src_el.getAttribute('spt_phone_number'); var email = bvr.src_el.getAttribute('spt_mail'); var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); var input = top.getElement('.spt_ad_input'); var display = top.getElement('.spt_ad_display'); input.value = value; display.value = display_value; server = TacticServerStub.get() server.execute_cmd("tactic.active_directory.ADCacheUserCbk", {login: value}) spt.toggle_show_hide(content); ''' ad_search_wdg = ADSearchWdg(cbjs_action=cbjs_action) ad_top.add(ad_search_wdg) top.add(ad_top) return top
def get_buttons_wdg(my): buttons_div = DivWdg() buttons_div.add_style("margin-left: 20px") buttons_div.add_style("margin-right: 20px") # add brush size text_note_wdg = DivWdg() text_note_wdg.add("<b>Text Note</b>") buttons_div.add(text_note_wdg) text_note = TextAreaWdg("spt_text_note") text_note.add_style("width: 400px") text_note.add_class("spt_text_note") buttons_div.add(text_note) from pyasm.widget import IconButtonWdg, IconWdg save_button = IconButtonWdg("Export", IconWdg.SAVE) save_button.add_style("float: right") buttons_div.add(save_button) script = ''' try { function getFlashMovie(movieName) { var isIE = navigator.appName.indexOf("Microsoft") != -1; return (isIE) ? window[movieName] : document[movieName]; } spt.app_busy.show("Exporting Visual Note", " ") var data = getFlashMovie("visual_notes_wdg").visual_notes_export(); var applet = spt.Applet.get(); var server = TacticServerStub.get(); //server.start(); var search_key = bvr.kwargs.search_key; var txt_path = "c:/sthpw/sandbox/temp/visual_notes/visual_notes_temp.txt" var jpg_path = "c:/sthpw/sandbox/temp/visual_notes/visual_notes_temp.jpg" applet.create_file(txt_path, data); applet.decodeFileToFile(txt_path, jpg_path); var top_el = bvr.src_el.getParent(".spt_visual_notes_top"); var context = bvr.kwargs.context; var snapshot = server.simple_checkin(search_key, context, jpg_path); //var note_context = context + "|note"; var note_context = context; var note = top_el.getElement(".spt_text_note").value; var note_sobj = server.insert("sthpw/note", { note: note, context: note_context}, {parent_key: search_key} ); server.connect_sobjects( snapshot, note_sobj); //server.finish("Visual Notes"); spt.app_busy.hide(); alert("Visual note added for [" + context + "]"); } catch(err) { spt.app_busy.hide(); alert(err); } ''' save_button.add_behavior( { 'type': 'click_up', 'cbjs_action': script, 'kwargs': { 'search_key': my.search_key, 'context': my.note_context } }) return buttons_div
def get_action_wdg(self): main_div = DivWdg(css="filter_box center_content") div = DivWdg() main_div.add(self.get_view_select()) main_div.add(div) div.add_style('height', '16px') div.add_style('margin', '3px 0 3px 0') search_type = self.get_search_type() div.add(HtmlElement.b("Action: ")) add_button = IconButtonWdg(self.ADD_BUTTON, IconWdg.ADD, long=True) behavior = { 'type': 'click_up', 'mouse_btn': 'LMB', 'cbfn_action': 'spt.sobject_planner.action', 'action': 'add', 'search_type': search_type } add_button.add_behavior(behavior) retire_button = IconButtonWdg("Retire Instance",\ IconWdg.RETIRE, long=True) behavior = { 'type': 'click_up', 'mouse_btn': 'LMB', 'cbfn_action': 'spt.sobject_planner.action', 'action': 'retire', 'search_type': search_type } retire_button.add_behavior(behavior) delete_button = IconButtonWdg("Delete Instance",\ IconWdg.DELETE, long=True) behavior = { 'type': 'click_up', 'mouse_btn': 'LMB', 'cbfn_action': 'spt.sobject_planner.action', 'action': 'delete', 'search_type': search_type } delete_button.add_behavior(behavior) div.add(add_button) div.add(retire_button) div.add(delete_button) ''' # add test popup from tactic.ui.container import PopupWdg from tactic.ui.panel import TableLayoutWdg popup = PopupWdg(id="planner", allow_page_activity=True) content = DivWdg() #content.add_style("height: 500px") #content.add_style("overflow: scroll") search_type = self.get_search_type() layout = TableLayoutWdg(search_type=search_type, view="planner_left") search = Search(search_type) layout.set_sobjects( search.get_sobjects() ) content.add(layout) popup.add("Assets", "title") popup.add(content, "content") popup_button = IconButtonWdg("Popup",\ IconWdg.DELETE, long=True) popup_button.add_event("onclick", "$('planner').setStyle('display','')") main_div.add(popup) main_div.add(popup_button) ''' return main_div
def get_display(self): self.search_key = self.kwargs.get("search_key") self.context = self.kwargs.get("context") assert self.search_key assert self.context top = DivWdg() self.set_as_panel(top) top.add_class("spt_review_top") table = Table() top.add(table) table.add_row() left = table.add_cell() left.add_style("vertical-align: top") button = IconButtonWdg("Visual Notes", IconWdg.EDIT) button.add_behavior( { 'type': 'click_up', 'kwargs': { 'search_key': self.search_key, 'context': self.context, }, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_review_top"); var content = top.getElement(".spt_review_content"); spt.panel.load(content, "tactic.ui.widget.visual_notes_wdg.VisualNotesWdg", bvr.kwargs); ''' } ) left.add(button) # add a refresh button and a gear menu button = IconButtonWdg("Refresh", IconWdg.REFRESH) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var panel = bvr.src_el.getParent(".spt_review_top"); spt.panel.refresh(panel); ''' } ) left.add(button) right = table.add_cell() right.add_style("vertical-align: top") right.add("Image Area") content_div = DivWdg() content_div.add_class("spt_review_content") content_div.add_style("padding: 5px") content_div.add_style("margin: 5px") content_div.add_style("border: solid 1px #999") content_div.add_style("min-width: 500px") content_div.add_style("min-height: 400px") content_div.add_style("height: 100%") right.add(content_div) sobject = Search.get_by_search_key(self.search_key) note_context = "%s|note" % self.context snapshots = Search.eval("@SOBJECT(sthpw/snapshot['context','=','%s'])" % note_context, [sobject]) vnotes_div = DivWdg() vnotes_div.add_style("overflow: auto") vnotes_div.add_style("width: 200px") vnotes_div.add_style("min-height: 400px") vnotes_div.add_style("max-height: 600px") vnotes_div.add_style("border: solid 1px #999") vnotes_div.add_style("padding: 5px") vnotes_div.add_style("margin: 5px") left.add(vnotes_div) if not snapshots: vnotes_div.add("<b>No review notes available</b>") notes_wdg = VisualNotesWdg(search_key=self.search_key,context=self.context) content_div.add(notes_wdg) for snapshot in snapshots: vnote_div = DivWdg() vnotes_div.add(vnote_div) file_obj = snapshot.get_file_by_type('main') if not file_obj: vnote_div.add("None found") continue rel_path = file_obj.get_value("relative_dir") file_name = file_obj.get_value("file_name") image_url = "/assets/%s/%s" % (rel_path, file_name) login = snapshot.get_value("login") date = snapshot.get_value("timestamp") import dateutil date_str = dateutil.parser.parse(date).strftime("%b %m %Y - %H:%M") login_div = DivWdg() login_div.add_style("padding: 2px") login_div.add("User: "******"<b>%s</b><br/>" % login ) login_div.add("Date: ") login_div.add( "<b>%s</b><br/>" % date_str ) vnote_div.add(login_div) from pyasm.widget import ThumbWdg thumb_div = DivWdg() thumb_div.add_style("margin-left: 10px") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_has_img_link(False) thumb.set_option("detail", "false") thumb.set_option("icon_size", "80") thumb.set_sobject(snapshot) vnote_div.add(thumb_div) #file_obj = snapshot.get_file_by_type('icon') #rel_path = file_obj.get_value("relative_dir") #file_name = file_obj.get_value("file_name") #icon_url = "/assets/%s/%s" % (rel_path, file_name) #vnote_div.add("<img src='%s'/>" % icon_url ) #vnote_div.add(snapshot.get_code() ) vnote_div.add_attr("spt_image_url", image_url ) vnote_div.add_class('hand') vnote_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var value = bvr.src_el.innerHTML; var image_url = bvr.src_el.getAttribute("spt_image_url"); var top = bvr.src_el.getParent(".spt_review_top"); var content = top.getElement(".spt_review_content"); content.innerHTML = "<img src='"+image_url+"'/>"; ''' } ) # get the related note to this vnote #notes = vnotes_div.get_related_notes() search = Search("sthpw/note") search.add_parent_filter(sobject) notes = search.get_sobjects() #for note in notes: # vnote_div.add(note.get_value("note")) from pyasm.biz import SObjectConnection connections, related_notes = SObjectConnection.get_connected_sobjects(snapshot, direction='src') for related_note in related_notes: vnote_div.add(related_note.get_value("note") ) print "related_notes: ", related_notes vnote_div.add("<hr/>") return top
def get_display(my): my.search_type = my.kwargs.get('search_type') my.element_name = my.kwargs.get('element_name') assert my.search_type assert my.element_name class_name = 'tactic.ui.app.aggregate_wdg.AggregateCmd' interval = 120 priority = None if my.kwargs.get('is_refresh'): user = Environment.get_user_name() # these interval jobs need to have a specific code code = "aggregate|%s|%s" % (my.search_type, my.element_name) # check to see if the job exists #job = Search.get_by_code("sthpw/queue", code) job = None if not job: job = SearchType.create("sthpw/queue") #job.set_value("code", code) job.set_value("project_code", Project.get_project_code() ) job.set_value("class_name", class_name) job.set_value("command", class_name) job.set_value("serialized", str(my.kwargs) ) job.set_value("interval", 120) job.set_value("state", 'pending') job.set_value("queue", 'interval') job.set_value("priority", 9999) job.set_value("login", user) job.commit() my.view = my.kwargs.get('view') if not my.view: my.view = 'definition' top = DivWdg() my.set_as_panel(top) action_div = DivWdg() top.add(action_div) refresh = IconButtonWdg("Refresh", IconWdg.REFRESH) refresh.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' } ) action_div.add(refresh) register_div = DivWdg() register_div.add_class("spt_queue_register") top.add(register_div) register_div.add_style("border: solid 1px black") register_div.add_style("padding: 20px") register_div.add("Register new interval aggregate") table = Table() table.add_style("margin: 15px") register_div.add(table) table.add_row() table.add_cell("command: ") table.add_cell(class_name) #table.add_row() #table.add_cell("priority: ") #table.add_cell(priority) table.add_row() table.add_cell("interval: ") td = table.add_cell("every ") td.set_attr("title", "Recalculation interval") text = TextWdg("interval") text.add_style("width: 30px") text.set_value(interval) td.add(text) unit_select = SelectWdg("unit") unit_select.set_value(interval) unit_select.set_option("values", "seconds|minutes|hours|days") td.add(" ") td.add(unit_select) table.add_row() table.add_cell("queue: ") table.add_cell("interval") from pyasm.widget import ProdIconButtonWdg button = ProdIconButtonWdg("Register") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_queue_register") var values = spt.api.get_input_values(top); var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' } ) register_div.add(button) from pyasm.widget import ProdIconButtonWdg button = ProdIconButtonWdg("Cancel") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' alert('cancel'); ''' } ) register_div.add(button) ''' cmd = AggregateCmd(**my.kwargs) print "registering scheduled task" scheduler = Scheduler.get() scheduler.start_thread() task = AggregateRefreshTask(name="cow", command=cmd) scheduler.add_interval_task(task, 10, mode='forked') scheduler.cancel_task("cow", delay=35) ''' top.add("<br/>") top.add("<b>Current Job Queue</b>") top.add("<br/><br/>") from tactic.ui.panel import TableLayoutWdg table = TableLayoutWdg(search_type='sthpw/queue',view='test') top.add(table) return top
def get_display(my): sobject = my.get_current_sobject() search_key = SearchKey.build_by_sobject(sobject) display = DivWdg() display.add_style("position: relative") display.add_class("spt_button_top") BASE = '/context/themes2/default/' over_div = DivWdg() display.add(over_div) over_div.add_class("spt_button_over") over_img = "<img src='%s/MainButton_over.png'/>" % BASE over_div.add(over_img) over_div.add_style("position: absolute") over_div.add_style("top: -9px") over_div.add_style("left: 0px") over_div.add_style("display: none") click_div = DivWdg() display.add(click_div) click_div.add_class("spt_button_click") click_img = "<img src='%s/MainButton_click.png'/>" % BASE click_div.add(click_img) click_div.add_style("position: absolute") click_div.add_style("top: -9px") click_div.add_style("left: 0px") click_div.add_style("display: none") if my.get_option('align') == 'left': display.add_style("text-align: left") else: display.add_style("text-align: center") icon = my.get_option("icon") if not icon: icon = "create" icon_tip = my.get_option("icon_tip") if not icon_tip: icon_tip = my.get_option("hint") if not icon_tip: icon_tip = "" enable = my.get_option("enable") if enable: result = ExpressionParser().eval(enable, sobject) if not result: return " " if not my.script_obj and not my.script: icon_wdg = IconButtonWdg("No Script Found", IconWdg.ERROR) else: try: icon_link = eval("IconWdg.%s" % icon.upper()) except Exception, e: print "WARNING: ", str(e) icon_link = IconWdg.ERROR icon_wdg = IconButtonWdg(icon_tip, icon_link) if not sobject.is_insert(): icon_wdg.add_class("hand") #icon_wdg.add_behavior(my.behavior) icon_wdg.add_class("spt_button_%s" % my.name)
def get_display(self): top = DivWdg() top.add_class("ad_input_top") name = self.get_name() text = TextWdg(self.get_input_name()) # get the login sobject = self.get_current_sobject() client = sobject.get_value("contact_name") print "client: ", client if client: login_sobj = Login.get_by_code(client) else: login_sobj = Environment.get_login() # build the display_name login = login_sobj.get_value("login") display_name = login_sobj.get_value("display_name") if not display_name: display_name = "%s %s" % (user.get('first_name'), user.get('last_name')) display_name = display_name.replace('"', "'") print "login: "******"spt_ad_input") if login: hidden.set_value(login) top.add(hidden) # copy over some options #text.set_options( self.options.copy() ) if login: text.set_value(display_name) text.set_option("read_only", "true") text.add_class("spt_ad_display") top.add(text) top.add(" ") groups_str = self.get_option("groups_allowed_to_search") if groups_str: stmt = 'groups_list = %s' % groups_str exec stmt else: groups_list = None allow_search = True if groups_list: allow_search = False login_in_group_list = Search.eval("@SOBJECT(sthpw/login_in_group['login','=','%s'])" % login) for login_in_group in login_in_group_list: group = login_in_group.get_value("login_group") if group in groups_list: allow_search = True break if login == 'admin': allow_search = True if allow_search: button = IconButtonWdg('Search for User', IconWdg.USER) #button = ButtonWdg() button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); spt.toggle_show_hide(content); ''' } ) top.add(button) ad_top = DivWdg() ad_top.add_class("ad_input_content") ad_top.add_style("display: none") ad_top.add_style("position: absolute") ad_top.add_style("background: #222") ad_top.add_style("min-width: 300px") ad_top.add_style("border: solid 1px #000") ad_top.add_style("padding: 20px") cbjs_action = ''' var value = bvr.src_el.getAttribute('spt_input_value'); var display_value = bvr.src_el.getAttribute('spt_display_value'); var phone_number = bvr.src_el.getAttribute('spt_phone_number'); var email = bvr.src_el.getAttribute('spt_mail'); var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); var input = top.getElement('.spt_ad_input'); var display = top.getElement('.spt_ad_display'); input.value = value; display.value = display_value; server = TacticServerStub.get() server.execute_cmd("tactic.active_directory.ADCacheUserCbk", {login: value}) spt.toggle_show_hide(content); ''' ad_search_wdg = ADSearchWdg(cbjs_action=cbjs_action) ad_top.add(ad_search_wdg) top.add(ad_top) return top
def get_display(my): my.set_option('icon', "CONTENTS") sobject = my.get_current_sobject() search_type = sobject.get_search_type() context = my.get_option("context") if not context: context = "publish" process = my.get_option("process") if not process: process = "publish" if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject sobject = snapshot.get_parent() search_type = sobject.get_search_type() else: if process: snapshot = Snapshot.get_latest_by_sobject(sobject, process=process) else: snapshot = Snapshot.get_latest_by_sobject(sobject, context=context) if not snapshot: top = DivWdg() return top top = DivWdg() icon = IconButtonWdg("Show Metadata", eval("IconWdg.%s" % my.get_option('icon'))) top.add(icon) lib_path = snapshot.get_lib_path_by_type("main") basename = os.path.basename(lib_path) dirname = os.path.dirname(lib_path) my.behavior['basename'] = basename my.behavior['dirname'] = dirname my.behavior['search_type'] = search_type cbjs_action = ''' var class_name = 'tactic.ui.tools.repo_browser_wdg.RepoBrowserContentWdg'; var kwargs = { basename: '%(basename)s', dirname: '%(dirname)s', search_type: '%(search_type)s' }; //spt.tab.set_main_body_tab(); //spt.tab.add_new("Detail", "Detail", class_name, kwargs); spt.panel.load_popup("Detail", class_name, kwargs); ''' % (my.behavior) my.behavior['type'] = 'click_up' my.behavior['cbjs_action'] = cbjs_action icon.add_behavior(my.behavior) return top
def init(self): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = self.get_current_sobject() if not sobject: if not self.__dict__.has_key("search_type"): web = WebContainer.get_web() self.search_type = web.get_form_value("search_type") self.search_id = web.get_form_value("search_id") if not self.search_type: self.add("No search type") return search = Search(self.search_type) search.add_id_filter(self.search_id) sobject = search.get_sobject() snapshot = Snapshot.get_latest_by_sobject(sobject) # TODO: # this is a bit klunky snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value( "snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name()) # add the annotate js object script = HtmlElement.script("annotate = new Annotate()") self.add(script) # add the image self.add("<h3>Image Annotations</h3>") width = 600 img = HtmlElement.img(path) img.add_style("position: absolute") img.set_id("annotate_image") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 1") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") self.add(img) # test version = snapshot.get_value("version") if version != 1: last_version = version - 1 snapshot = Snapshot.get_by_version( \ self.search_type, self.search_id, version=last_version ) snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value( "snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name()) img = HtmlElement.img(path) img.set_id("annotate_image_alt") img.add_style("position: absolute") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 0") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") self.add(img) #script = HtmlElement.script("align_element('%s','%s')" % \ # ("annotate_image", "annotate_image_alt") ) #self.add(script) div = DivWdg() div.add_style("position: absolute") div.add_style("left: 620") div.add_style("top: 300") self.add(div) button = IconButtonWdg("Switch", IconWdg.REFRESH, True) button.add_event("onclick", "annotate.switch_alt()") div.add(button) button = IconButtonWdg("Opacity", IconWdg.LOAD, True) button.add_event("onclick", "annotate.set_opacity()") div.add(button) # add the new annotation div new_annotation_div = DivWdg() new_annotation_div.set_id("annotate_msg") new_annotation_div.set_class("annotate_new") new_annotation_div.add_style("top: 0") new_annotation_div.add_style("left: 0") title = DivWdg("Enter Annotation:") title.add_style("background-color: #000000") title.add_style("color: #ffffff") new_annotation_div.add(title) text = TextAreaWdg("annotate_msg") text.set_attr("cols", "30") text.set_attr("rows", "3") new_annotation_div.add(text) new_annotation_div.add("<br/>") cancel = ButtonWdg("Cancel") cancel.add_style("float: right") cancel.add_event("onclick", "toggle_display('annotate_msg')") new_annotation_div.add(cancel) submit = SubmitWdg("Add Annotation") submit.add_style("float: right") new_annotation_div.add(submit) new_annotation_div.add_style("display: none") new_annotation_div.add_style("position: absolute") self.add(new_annotation_div) # get all of the stored annotations for this image search = Search("sthpw/annotation") search.add_order_by("login") search.add_filter("file_code", file_code) annotations = search.get_sobjects() # sort by user sorted_annotations = {} for annotation in annotations: user = annotation.get_value("login") if not sorted_annotations.has_key(user): sorted_annotations[user] = [] sorted_annotations[user].append(annotation) buttons = [] for user, annotations in sorted_annotations.items(): button = IconButtonWdg(user, IconWdg.INSERT, True) button.add_event( "onclick", "annotate.show_marks('%s','%s')" % (user, len(annotations) - 1)) buttons.append(button) count = 0 for annotation in annotations: self.add(self.get_annotate_wdg(annotation, count)) count += 1 # add the user buttons table = Table() table.set_class("table") table.add_style("width: 0px") table.add_style("position: absolute") table.add_style("left: 620") table.add_style("top: 0") table.add_row() table.add_header("Annotations") for button in buttons: table.add_row() legend_wdg = DivWdg() legend_wdg.set_class("annotate_mark") legend_wdg.add_style("position: relative") legend_wdg.add(" ") table.add_cell(legend_wdg) table.add_cell(button) self.add(table) # add form elements hidden = HiddenWdg("mouse_xpos") self.add(hidden) hidden = HiddenWdg("mouse_ypos") self.add(hidden) hidden = HiddenWdg("file_code", file_code) self.add(hidden) # move the rest below self.add("<div style='height:300'> </div>")
def get_display(self): current = self.get_current_sobject() if current.is_insert(): widget = Widget() parent_key = self.get_option('parent_key') if parent_key: parent = SearchKey.get_by_search_key(parent_key) if parent: widget.add(SpanWdg(parent.get_code())) else: # use the project as the parent parent = Project.get() widget.add(SpanWdg("Project: %s" % parent.get_code())) #raise TacticException('Task creation aborted since parent is undetermined. Please check the configuration that generates this table.') text = HiddenWdg(self.get_input_name()) text.set_option('size','40') text.set_value(parent_key) widget.add(text) return widget else: search_type = current.get_value('search_type') if not search_type: return "No parent type" widget = Widget() parent = current.get_parent() if parent: widget.add(parent.get_code()) return widget # What is this look up code for? text = TextWdg(self.get_input_name()) behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } text.add_behavior(behavior) widget.add(text) icon = IconButtonWdg("Look up", IconWdg.ZOOM) icon.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var options = { title: '%s', class_name: 'tactic.ui.panel.ViewPanelWdg' }; var args = { search_type: '%s', view: 'list' }; spt.popup.get_widget( {}, {options: options, args: args} ); ''' % (search_type, search_type) } ) widget.add(icon) return widget
def get_display(my): if not my.search_type: return "No search type found" web = WebContainer.get_web() my.view = web.get_form_value("view") if not my.view: my.view = web.get_form_value("filter|view") if not my.view: my.view = get_template_view() widget = Widget() widget.add( HiddenWdg("search_type", my.search_type) ) element_names = [] # see if there is an override search_type_obj = SearchType.get(my.search_type) config = WidgetConfigView.get_by_search_type(my.search_type,"browser_list") if config: element_names = config.get_element_names() search = Search("sthpw/widget_config") search.add_filter("search_type", my.search_type) search.add_filter("view", my.view) widget_config = search.get_sobject() if widget_config: edit_link_wdg = EditLinkWdg("sthpw/widget_config", widget_config.get_id(), text="Edit XML", long=True) edit_link_wdg.set_iframe_width(95) widget.add(edit_link_wdg) custom_config = WidgetConfigView.get_by_search_type(my.search_type,my.view) custom_element_names = custom_config.get_element_names() # get the custom properties search = Search("prod/custom_property") search.add_filter("search_type", my.search_type) custom_properties = search.get_sobjects() # action popup action_popup = PopupMenuWdg("table_action", multi=True, width='12em') action_popup.set_auto_hide(False) action_popup.set_submit(False) action_popup.add( HtmlElement.href("Add ...", "javascript:document.form.submit()") ) for custom_property in custom_properties: element_name = custom_property.get_name() if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) # if there is an override if element_names: for element_name in element_names: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) # get all of the columns else: search_type_obj = SearchType.get(my.search_type) element_names = search_type_obj.get_columns() for element_name in element_names: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) # add some standard properties if my.view in ["edit", "insert"]: for element_name in PREDEFINED_EDIT_ELEMENTS: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) else: for element_name in PREDEFINED_ELEMENTS: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) action_popup.add_separator() action_popup.add( HtmlElement.href("Remove ...", "javascript:document.form.submit()") ) for element_name in custom_element_names: action_popup.add( " %s" % element_name, "remove|%s" % element_name ) action_popup.add_separator() span = SpanWdg("New Custom ...", css="hand") iframe = WebContainer.get_iframe() url = WebContainer.get_web().get_widget_url() url.set_option("widget", "pyasm.widget.CustomAddPropertyWdg") url.set_option("search_type", my.search_type) url.set_option("view", my.view) action = iframe.get_on_script(url.to_string() ) span.add_event("onclick", action) action_popup.add( span ) # add the edit button edit = IconButtonWdg("Edit View", IconWdg.EDIT, True) edit.add_event("oncontextmenu", "%s;return false" % action_popup.get_on_script() ) edit.add_event("onclick", "%s" % action_popup.get_on_script() ) # lay it all out widget.add(SpanWdg(action_popup)) widget.add(edit) # add the edit button #save = IconButtonWdg("Save", IconWdg.SAVE, True) #widget.add(save) # add the add property button if my.mode == "admin": add = CustomAddPropertyLinkWdg(my.search_type, my.view) widget.add(add) #add_element = CustomAddElementLinkWdg(my.search_type, my.view) #widget.add(add_element) # add the clear button if my.mode == "admin" or my.view.startswith("custom_"): clear = IconSubmitWdg("Clear", IconWdg.DELETE, True) widget.add(clear) widget.add(SpanWdg(css="small")) WebContainer.register_cmd("pyasm.widget.CustomViewAction") return widget
def init(self): self.name = "iframe%s" % (self.generate_unique_id()) self.img_span_name = '%s_loading' % self.name self.iframe = HtmlElement.iframe() self.iframe.set_id(self.name) self.iframe.set_attr('name', self.name) # To adjust the real-time size of the overlay box, do it in get_on_script self.overlay = OverlayWdg(name='%s_shadowbox'%self.name, \ width=self.width * 1.0, display=False, iframe_name=self.name ) self.overlay.add(self.iframe) self.shadowbox = self.overlay.get_shadow_box() tall_control = IconButtonWdg( name='taller', icon='/context/icons/common/dn_button.png') tall_control.add_style("float: right") tall_control.add_event( "onclick", self.get_taller_script(self.name, self.shadowbox.name)) short_control = IconButtonWdg( name='shorter', icon='/context/icons/common/up_button.png') short_control.add_style("float: right") short_control.add_style("padding-bottom: 4px") short_control.add_event( "onclick", self.get_shorter_script(self.name, self.shadowbox.name)) control = DivWdg() control.add_style('margin-top: -30px') control.add(short_control) control.add(tall_control) if not WebContainer.get_web().is_IE(): self.shadowbox.set_control(control) self.overlay.add(self._get_loading_span()) self.add(self.overlay)
def get_display(my): web = WebContainer.get_web() widget = DivWdg() widget.add_class("spt_search_limit_top") #widget.add_style("border", "solid 1px blue") widget.add_color("background", "background") widget.add_color("color", "color") widget.add_style("padding: 5px") hidden = HiddenWdg("prefix", my.prefix) widget.add(hidden) if not my.search and not my.sobjects: widget.add("No search or sobjects found") return widget # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count(no_exception=True) # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if not limit: limit = 50 my.search_limit = limit if my.refresh: prev = SpanWdg( IconButtonWdg("Prev", IconWdg.LEFT, False ) ) prev.add_style("margin-left: 8px") prev.add_style("margin-right: 6px") prev.add_style("margin-top: -2px") next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) next.add_style("margin-left: 6px") prev.add_behavior( { 'type': 'click_up', 'cbjs_action': my.refresh_script } ) next.add_behavior( { 'type': 'click_up', 'cbjs_action': my.refresh_script } ) else: # the old code pre 2.5 prev = IconButtonWdg("Prev", IconWdg.LEFT, False ) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name,"") prev.add(hidden) prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name,"") next.add(hidden) next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \ %(hidden_name, my.refresh_script)) showing_wdg = DivWdg() widget.add(showing_wdg) showing_wdg.add_style("padding: 10px") showing_wdg.add_style("margin: 10px") showing_wdg.add_color("background", "background", -5) showing_wdg.add_border() label_span = SpanWdg("Showing: ") showing_wdg.add(label_span) showing_wdg.add( prev ) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset+1 if not limit: # prevent error in ItemsNavigatorWdg if a search encounters query error limit = 50 my.search_limit = limit right_bound = min(my.current_offset+limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: showing_wdg.add( current_value ) else: # add a range selector using ItemsNavigatorWdg from pyasm.widget import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit) selector.select.add_behavior( { 'type': 'change', 'cbjs_action': my.refresh_script } ) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) showing_wdg.add( selector) showing_wdg.add( next ) #showing_wdg.add( " x ") showing_wdg.add(my.text) my.text.add_style("margin-top: -3px") my.text.set_attr("size", "1") my.text.add_attr("title", "Set number of items per page") widget.add("<hr/>") # set the limit set_limit_wdg = my.get_set_limit_wdg() widget.add(set_limit_wdg) from tactic.ui.widget.button_new_wdg import ActionButtonWdg button = ActionButtonWdg(title='Search') widget.add(button) button.add_style("float: right") button.add_style("margin-top: 8px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var select = top.getElement(".spt_search_limit_select"); var value = select.value; if (value == 'Custom') { custom = top.getElement(".spt_search_limit_custom_text"); value = custom.value; } if (value == '') { value = 20; } var text = top.getElement(".spt_search_limit_text"); text.value = value; spt.dg_table.search_cbk({}, bvr) ''' } ) offset_wdg = HiddenWdg("%s_last_search_offset" %my.label) offset_wdg.set_value(my.current_offset) widget.add(offset_wdg) widget.add("<br clear='all'/>") return widget
def get_display(my): sobject = my.get_current_sobject() search_key = SearchKey.build_by_sobject(sobject) display = DivWdg() display.add_style("position: relative") display.add_class("spt_button_top") BASE = "/context/themes2/default/" over_div = DivWdg() display.add(over_div) over_div.add_class("spt_button_over") over_img = "<img src='%s/MainButton_over.png'/>" % BASE over_div.add(over_img) over_div.add_style("position: absolute") over_div.add_style("top: -9px") over_div.add_style("left: 0px") over_div.add_style("display: none") click_div = DivWdg() display.add(click_div) click_div.add_class("spt_button_click") click_img = "<img src='%s/MainButton_click.png'/>" % BASE click_div.add(click_img) click_div.add_style("position: absolute") click_div.add_style("top: -9px") click_div.add_style("left: 0px") click_div.add_style("display: none") if my.get_option("align") == "left": display.add_style("text-align: left") else: display.add_style("text-align: center") icon = my.get_option("icon") if not icon: icon = "create" icon_tip = my.get_option("icon_tip") if not icon_tip: icon_tip = my.get_option("hint") if not icon_tip: icon_tip = "" enable = my.get_option("enable") if enable: result = ExpressionParser().eval(enable, sobject) if not result: return " " if not my.script_obj and not my.script: icon_wdg = IconButtonWdg("No Script Found", IconWdg.ERROR) else: try: icon_link = eval("IconWdg.%s" % icon.upper()) except Exception, e: print "WARNING: ", str(e) icon_link = IconWdg.ERROR icon_wdg = IconButtonWdg(icon_tip, icon_link) if not sobject.is_insert(): icon_wdg.add_class("hand") # icon_wdg.add_behavior(my.behavior) icon_wdg.add_class("spt_button_%s" % my.name)
def get_display(my): mode = my.get_option('mode') size = my.get_option('icon_size') if mode == 'add': my.set_option('icon', "CHECK_OUT") else: if size == 'large': my.set_option('icon', "CHECK_OUT_LG") else: my.set_option('icon', "CHECK_OUT_SM") top = DivWdg() icon = IconButtonWdg( "Checkout", eval( "IconWdg.%s" % my.get_option('icon') ) ) top.add(icon) my.process = my.get_option('process') my.context = '' transfer_mode = my.get_option('transfer_mode') sobject = my.get_current_sobject() if sobject.get_id() == -1: sobject = None snapshot_code = my.get_option("snapshot_code") sandbox_dir = my.get_option("sandbox_dir") if not sandbox_dir and sobject and isinstance(sobject, Snapshot): sandbox_dir = sobject.get_sandbox_dir(file_type='main') snapshot_code = sobject.get_code() lock_process = my.get_option("lock_process") sobject = my.get_current_sobject() search_key = SearchKey.get_by_sobject(sobject) if sobject.get_base_search_type() in ['sthpw/task', 'sthpw/note']: my.process = sobject.get_value('process') my.context = sobject.get_value('context') if not my.process: my.process = '' parent = sobject.get_parent() if not parent: return DivWdg() search_key = SearchKey.get_by_sobject(parent) else: my.process = my.get_option('process') search_key = SearchKey.get_by_sobject(sobject) checkout_script_path = my.get_option("checkout_script_path") checkout_panel_script_path = my.get_option("checkout_panel_script_path") lock_process = my.get_option("lock_process") if not checkout_script_path: checkout_script_path = '' if not checkout_panel_script_path: checkout_panel_script_path = '' # FIXME: this does not get passed through 'cuz get_display is overridden here # so passed in directly in the script below my.behavior['checkout_panel_script_path'] = checkout_panel_script_path my.behavior['checkout_script_path'] = checkout_script_path my.behavior['process'] = my.process my.behavior['context'] = my.context my.behavior['lock_process'] = lock_process my.behavior['search_key'] = search_key my.behavior['snapshot_code'] = snapshot_code my.behavior['sandbox_dir'] = sandbox_dir my.behavior['transfer_mode'] = transfer_mode #layout_wdg = my.get_layout_wdg() #state = layout_wdg.get_state() cbjs_action = ''' var kwargs = { search_key: '%(search_key)s', sandbox_dir: '%(sandbox_dir)s', process: '%(process)s', context: '%(context)s', lock_process: '%(lock_process)s', checkout_script_path: '%(checkout_script_path)s' }; var transfer_mode = bvr.transfer_mode; if (!transfer_mode) { transfer_mode = spt.Environment.get().get_transfer_mode(); } if (transfer_mode == null) { transfer_mode = 'web'; } // NOTE: reusing checkin transfer mode if (transfer_mode == 'copy') { transfer_mode = 'client_repo'; } var values = {}; var top = bvr.src_el.getParent(".spt_checkin_top"); script = spt.CustomProject.get_script_by_path(bvr.checkout_panel_script_path); if (script) { bvr['script'] = script; bvr.values = kwargs; spt.app_busy.show("Running Checkout Panel Script", kwargs.checkout_panel_script_path); setTimeout( function() { try { spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { throw(e); spt.alert('No script found. <checkout_panel_script_path> display option should refer to a valid script path.'); } spt.app_busy.hide(); }, 50); } else { if (bvr.snapshot_code) { if (!bvr.checkout_script_path){ spt.app_busy.show("Checking out files", 'To: '+ bvr.sandbox_dir); setTimeout( function() { try { var server = TacticServerStub.get(); file_types = ['main']; filename_mode = 'source'; // we want this undefined so the checkout // snapshot can deal with it correctly. Explicitly // putting in a dir will force it to go there, // regardless of naming conventions sandbox_dir = null; server.checkout_snapshot(bvr.snapshot_code, sandbox_dir, {mode: transfer_mode, filename_mode: filename_mode, file_types: file_types} ); var checkin_top = bvr.src_el.getParent(".spt_checkin_top"); if (checkin_top) { spt.app_busy.show("Reading file system ...") spt.panel.refresh(checkin_top); spt.app_busy.hide(); } } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } else { setTimeout( function() { try { bvr['script'] = bvr.checkout_script_path; bvr.values = kwargs; spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } } else { var class_name = 'tactic.ui.widget.CheckoutWdg'; var values = kwargs; bvr.values = values; var search_key = values.search_key; var sandbox_dir = values.sandbox_dir; var process = values.process; var context = values.context; var options = { 'show_publish': 'false', 'process': process, 'context': context, 'search_key': search_key, 'checkout_script_path': bvr.checkout_script_path, 'sandbox_dir': sandbox_dir }; var popup_id ='Check-out Widget'; spt.panel.load_popup(popup_id, class_name, options); } } ''' % (my.behavior) my.behavior['type'] = 'click_up' my.behavior['cbjs_action'] = cbjs_action icon.add_behavior(my.behavior) return top
def get_display(self): top = DivWdg() self.set_as_panel(top) title_div = DivWdg() title_div.add_class("maq_search_bar") title_div.add("Diagnostics") top.add(title_div) tool_div = DivWdg() top.add(tool_div) refresh = IconButtonWdg("Refresh", IconWdg.REFRESH) refresh.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' } ) tool_div.add(refresh) content = RoundedCornerDivWdg(hex_color_code="2F2F2F",corner_size="10") content.set_dimensions( width_str='300px', content_height_str=None ) top.add(content) server_title_div = DivWdg() server_title_div.add_class("maq_search_bar") content.add(server_title_div) server_title_div.add("Server") server_content_div = DivWdg() server_content_div.add_style("padding: 10px") server_content_div.add(self.get_ping_wdg()) server_content_div.add(self.get_load_balance_wdg()) content.add(server_content_div) database_title_div = DivWdg() database_title_div.add_class("maq_search_bar") content.add(database_title_div) database_title_div.add("Database") database_content_div = DivWdg() database_content_div.add_style("padding: 10px") database_content_div.add(self.get_database_wdg()) content.add(database_content_div) checkin_title_div = DivWdg() checkin_title_div.add_class("maq_search_bar") content.add(checkin_title_div) checkin_title_div.add("Database") checkin_content_div = DivWdg() checkin_content_div.add_style("padding: 10px") checkin_content_div.add(self.get_asset_dir_wdg() ) checkin_content_div.add(self.get_asset_management_wdg()) content.add(checkin_content_div) return top
def get_display(my): web = WebContainer.get_web() naming_util = NamingUtil() if not my.widget_name: my.widget_name = my.get_name() # get the sobject required by this input sobject = my.get_current_sobject() if not sobject: sobject = Search.get_by_id(my.search_type, my.search_id) if my.new_sample_name: my.new_sample_name.replace("//", "/") else: my.new_sample_name = sobject.get_value(my.widget_name) widget = DivWdg() widget.set_id("naming") widget.add_style("display: block") # set the sample text div = DivWdg() div.add("Sample name: <i>%s</i>" % my.new_sample_name) div.add(HtmlElement.br(2)) new_sample_wdg = ProdIconButtonWdg("Set New Sample") new_sample_wdg.add_event("onclick", "toggle_display('generate')") div.add(new_sample_wdg) generate = DivWdg() generate.add(HtmlElement.br()) generate.set_id("generate") generate.add_style("display: none") sample_text = TextWdg("new_sample_name") sample_text.set_option("size", "30") # sample_text.set_persist_on_submit() # if my.new_sample_name: # sample_text.set_value(my.new_sample_name) generate.add(sample_text) button = IconButtonWdg("Generate", IconWdg.REFRESH, long=True) on_script = my.setup_ajax("naming") button.add_event("onclick", on_script) generate.add(button) generate.add(HtmlElement.br(2)) div.add(generate) widget.add(div) hidden = TextWdg(my.widget_name) value = my.naming hidden.set_value(my.new_sample_name) widget.add(my.widget_name) widget.add(hidden) # get all of the parts # TODO: not sure if this should be dictated by the sample name # break up the name into parts import re if my.new_sample_name: tmp = my.new_sample_name.strip("/") parts = re.split("[\\/._]", tmp) print "parts: ", parts else: return widget # if there is a naming, then populate that if my.edit_search_type: options = naming_util.get_options(my.edit_search_type) else: options = naming_util.get_options(sobject.get_value("search_type")) table = Table() type_values = [] padding_values = [] for idx, part in enumerate(parts): table.add_row() table.add_cell(part) type_select = SelectWdg("type_%s" % idx) type_select.add_empty_option("-- Explicit --") type_select.set_persist_on_submit() type_select.set_option("values", "|".join(options)) type_values.append(type_select.get_value()) td = table.add_cell(type_select) widget.add(table) return widget
def get_preview_wdg(self): widget = Widget() web = WebContainer.get_web() csv_parser = CsvParser(self.file_path) csv_parser.parse() csv_titles = csv_parser.get_titles() csv_data = csv_parser.get_data() ajax = AjaxCmd() ajax.set_option("search_type", self.search_type) ajax.set_option("file_path", self.file_path) ajax.add_element_name("has_title") event = WebContainer.get_event_container() caller = event.get_event_caller(SiteMenuWdg.EVENT_ID) div = ajax.generate_div() div.set_post_ajax_script(caller) widget.add(div) columns = [] num_columns = len(csv_titles) ajax.set_option("num_columns", num_columns) for i in range(0, num_columns): column = web.get_form_value("column_%s" % i) if column: column = csv_titles[i] else: column = web.get_form_value("column_new_%s" % i) columns.append(column) ajax.add_element_name("column_%s" % i) ajax.add_element_name("new_column_%s" % i) ajax.register_cmd("pyasm.command.csv_import_cmd.CsvImportCmd") import_button = IconButtonWdg("Import", IconWdg.REFRESH, True) import_button.add_event("onclick", ajax.get_on_script(show_progress=False)) import_button.add_style("float: right") widget.add(import_button) preview_submit = IconSubmitWdg("Preview", IconWdg.REFRESH, True) preview_submit.add_style("float: right") widget.add(preview_submit) sobject_title = self.search_type_obj.get_title() widget.add("<p>4. Import</p>") widget.add(HtmlElement.br()) widget.add( "<p>The following table will be imported into %s (Showing Max: 100)</p>" % sobject_title) table = Table(css="table") table.add_style("width: 100%") table.add_row() for i, title in enumerate(columns): if not title: title = "<b style='color:red'>*</b>" table.add_header(title) for i, row in enumerate(csv_data): if i > 100: break table.add_row() for j, cell in enumerate(row): table.add_cell(cell) widget.add(table) return widget
def init(my): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = my.get_current_sobject() if not sobject: if not my.__dict__.has_key("search_type"): web = WebContainer.get_web() my.search_type = web.get_form_value("search_type") my.search_id = web.get_form_value("search_id") if not my.search_type: my.add("No search type") return search = Search(my.search_type) search.add_id_filter(my.search_id) sobject = search.get_sobject() snapshot = Snapshot.get_latest_by_sobject(sobject) # TODO: # this is a bit klunky snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value("snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name() ) # add the annotate js object script = HtmlElement.script("annotate = new Annotate()") my.add(script) # add the image my.add("<h3>Image Annotations</h3>") width = 600 img = HtmlElement.img(path) img.add_style("position: absolute") img.set_id("annotate_image") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 1") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") my.add(img) # test version = snapshot.get_value("version") if version != 1: last_version = version - 1 snapshot = Snapshot.get_by_version( \ my.search_type, my.search_id, version=last_version ) snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value("snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name() ) img = HtmlElement.img(path) img.set_id("annotate_image_alt") img.add_style("position: absolute") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 0") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") my.add(img) #script = HtmlElement.script("align_element('%s','%s')" % \ # ("annotate_image", "annotate_image_alt") ) #my.add(script) div = DivWdg() div.add_style("position: absolute") div.add_style("left: 620") div.add_style("top: 300") my.add(div) button = IconButtonWdg("Switch", IconWdg.REFRESH, True) button.add_event("onclick", "annotate.switch_alt()") div.add(button) button = IconButtonWdg("Opacity", IconWdg.LOAD, True) button.add_event("onclick", "annotate.set_opacity()") div.add(button) # add the new annotation div new_annotation_div = DivWdg() new_annotation_div.set_id("annotate_msg") new_annotation_div.set_class("annotate_new") new_annotation_div.add_style("top: 0") new_annotation_div.add_style("left: 0") title = DivWdg("Enter Annotation:") title.add_style("background-color: #000000") title.add_style("color: #ffffff") new_annotation_div.add(title) text = TextAreaWdg("annotate_msg") text.set_attr("cols", "30") text.set_attr("rows", "3") new_annotation_div.add(text) new_annotation_div.add("<br/>") cancel = ButtonWdg("Cancel") cancel.add_style("float: right") cancel.add_event("onclick", "toggle_display('annotate_msg')") new_annotation_div.add( cancel ) submit = SubmitWdg("Add Annotation") submit.add_style("float: right") new_annotation_div.add( submit ) new_annotation_div.add_style("display: none") new_annotation_div.add_style("position: absolute") my.add(new_annotation_div) # get all of the stored annotations for this image search = Search("sthpw/annotation") search.add_order_by("login") search.add_filter("file_code", file_code) annotations = search.get_sobjects() # sort by user sorted_annotations = {} for annotation in annotations: user = annotation.get_value("login") if not sorted_annotations.has_key(user): sorted_annotations[user] = [] sorted_annotations[user].append(annotation) buttons = [] for user, annotations in sorted_annotations.items(): button = IconButtonWdg(user, IconWdg.INSERT, True) button.add_event("onclick", "annotate.show_marks('%s','%s')" % (user, len(annotations)-1) ) buttons.append(button) count = 0 for annotation in annotations: my.add( my.get_annotate_wdg(annotation,count) ) count += 1 # add the user buttons table = Table() table.set_class("table") table.add_style("width: 0px") table.add_style("position: absolute") table.add_style("left: 620") table.add_style("top: 0") table.add_row() table.add_header("Annotations") for button in buttons: table.add_row() legend_wdg = DivWdg() legend_wdg.set_class("annotate_mark") legend_wdg.add_style("position: relative") legend_wdg.add(" ") table.add_cell(legend_wdg) table.add_cell(button) my.add(table) # add form elements hidden = HiddenWdg("mouse_xpos") my.add(hidden) hidden = HiddenWdg("mouse_ypos") my.add(hidden) hidden = HiddenWdg("file_code", file_code) my.add(hidden) # move the rest below my.add("<div style='height:300'> </div>")
def init(my): my.name = "iframe%s" % (my.generate_unique_id()) my.img_span_name = '%s_loading' %my.name my.iframe = HtmlElement.iframe() my.iframe.set_id(my.name) my.iframe.set_attr('name',my.name) # To adjust the real-time size of the overlay box, do it in get_on_script my.overlay = OverlayWdg(name='%s_shadowbox'%my.name, \ width=my.width * 1.0, display=False, iframe_name=my.name ) my.overlay.add(my.iframe) my.shadowbox = my.overlay.get_shadow_box() tall_control = IconButtonWdg(name='taller', icon='/context/icons/common/dn_button.png') tall_control.add_style("float: right") tall_control.add_event("onclick", my.get_taller_script(my.name, my.shadowbox.name) ) short_control = IconButtonWdg(name='shorter', icon='/context/icons/common/up_button.png') short_control.add_style("float: right") short_control.add_style("padding-bottom: 4px") short_control.add_event("onclick", my.get_shorter_script(my.name, my.shadowbox.name) ) control = DivWdg() control.add_style('margin-top: -30px') control.add(short_control) control.add(tall_control) if not WebContainer.get_web().is_IE(): my.shadowbox.set_control(control) my.overlay.add(my._get_loading_span()) my.add(my.overlay)
def get_preview_wdg(my): widget = Widget() web = WebContainer.get_web() csv_parser = CsvParser(my.file_path) csv_parser.parse() csv_titles = csv_parser.get_titles() csv_data = csv_parser.get_data() ajax = AjaxCmd() ajax.set_option("search_type", my.search_type) ajax.set_option("file_path", my.file_path) ajax.add_element_name("has_title") event = WebContainer.get_event_container() caller = event.get_event_caller(SiteMenuWdg.EVENT_ID) div = ajax.generate_div() div.set_post_ajax_script(caller) widget.add(div) columns = [] num_columns = len(csv_titles) ajax.set_option("num_columns", num_columns) for i in range(0, num_columns): column = web.get_form_value("column_%s" % i) if column: column = csv_titles[i] else: column = web.get_form_value("column_new_%s" % i) columns.append(column) ajax.add_element_name("column_%s" % i) ajax.add_element_name("new_column_%s" % i) ajax.register_cmd("pyasm.command.csv_import_cmd.CsvImportCmd") import_button = IconButtonWdg("Import", IconWdg.REFRESH, True) import_button.add_event("onclick", ajax.get_on_script(show_progress=False)) import_button.add_style("float: right") widget.add( import_button ) preview_submit = IconSubmitWdg("Preview", IconWdg.REFRESH, True) preview_submit.add_style("float: right") widget.add(preview_submit) sobject_title = my.search_type_obj.get_title() widget.add("<p>4. Import</p>") widget.add(HtmlElement.br()) widget.add("<p>The following table will be imported into %s (Showing Max: 100)</p>" % sobject_title) table = Table(css="table") table.add_style("width: 100%") table.add_row() for i, title in enumerate(columns): if not title: title = "<b style='color:red'>*</b>" table.add_header(title) for i, row in enumerate(csv_data): if i > 100: break table.add_row() for j, cell in enumerate(row): table.add_cell(cell) widget.add(table) return widget
def get_display(my): web = WebContainer.get_web() widget = DivWdg() widget.add_class("spt_search_limit_top") #widget.add_style("border", "solid 1px blue") widget.add_color("background", "background") widget.add_color("color", "color") widget.add_style("padding: 5px") hidden = HiddenWdg("prefix", my.prefix) widget.add(hidden) if not my.search and not my.sobjects: widget.add("No search or sobjects found") return widget # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count(no_exception=True) # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if not limit: limit = 50 my.search_limit = limit if my.refresh: prev = SpanWdg(IconButtonWdg("Prev", IconWdg.LEFT, False)) prev.add_style("margin-left: 8px") prev.add_style("margin-right: 6px") prev.add_style("margin-top: -2px") next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right") next.add_style("margin-left: 6px") prev.add_behavior({ 'type': 'click_up', 'cbjs_action': my.refresh_script }) next.add_behavior({ 'type': 'click_up', 'cbjs_action': my.refresh_script }) else: # the old code pre 2.5 prev = IconButtonWdg("Prev", IconWdg.LEFT, False) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name, "") prev.add(hidden) prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right") hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name, "") next.add(hidden) next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \ %(hidden_name, my.refresh_script)) showing_wdg = DivWdg() widget.add(showing_wdg) showing_wdg.add_style("padding: 10px") showing_wdg.add_style("margin: 10px") showing_wdg.add_color("background", "background", -5) showing_wdg.add_border() label_span = SpanWdg("Showing: ") showing_wdg.add(label_span) showing_wdg.add(prev) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset + 1 if not limit: # prevent error in ItemsNavigatorWdg if a search encounters query error limit = 50 my.search_limit = limit right_bound = min(my.current_offset + limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: showing_wdg.add(current_value) else: # add a range selector using ItemsNavigatorWdg from pyasm.widget import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit) selector.select.add_behavior({ 'type': 'change', 'cbjs_action': my.refresh_script }) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) showing_wdg.add(selector) showing_wdg.add(next) #showing_wdg.add( " x ") showing_wdg.add(my.text) my.text.add_style("margin-top: -3px") my.text.set_attr("size", "1") my.text.add_attr("title", "Set number of items per page") widget.add("<hr/>") # set the limit set_limit_wdg = my.get_set_limit_wdg() widget.add(set_limit_wdg) from tactic.ui.widget.button_new_wdg import ActionButtonWdg button = ActionButtonWdg(title='Search') widget.add(button) button.add_style("float: right") button.add_style("margin-top: 8px") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var select = top.getElement(".spt_search_limit_select"); var value = select.value; if (value == 'Custom') { custom = top.getElement(".spt_search_limit_custom_text"); value = custom.value; } if (value == '') { value = 20; } var text = top.getElement(".spt_search_limit_text"); text.value = value; spt.dg_table.search_cbk({}, bvr) ''' }) offset_wdg = HiddenWdg("%s_last_search_offset" % my.label) offset_wdg.set_value(my.current_offset) widget.add(offset_wdg) widget.add("<br clear='all'/>") return widget
def get_display(my): my.search_key = my.kwargs.get("search_key") my.context = my.kwargs.get("context") assert my.search_key assert my.context top = DivWdg() my.set_as_panel(top) top.add_class("spt_review_top") table = Table() top.add(table) table.add_row() left = table.add_cell() left.add_style("vertical-align: top") button = IconButtonWdg("Visual Notes", IconWdg.EDIT) button.add_behavior( { "type": "click_up", "kwargs": {"search_key": my.search_key, "context": my.context}, "cbjs_action": """ var top = bvr.src_el.getParent(".spt_review_top"); var content = top.getElement(".spt_review_content"); spt.panel.load(content, "tactic.ui.widget.visual_notes_wdg.VisualNotesWdg", bvr.kwargs); """, } ) left.add(button) # add a refresh button and a gear menu button = IconButtonWdg("Refresh", IconWdg.REFRESH) button.add_behavior( { "type": "click_up", "cbjs_action": """ var panel = bvr.src_el.getParent(".spt_review_top"); spt.panel.refresh(panel); """, } ) left.add(button) right = table.add_cell() right.add_style("vertical-align: top") right.add("Image Area") content_div = DivWdg() content_div.add_class("spt_review_content") content_div.add_style("padding: 5px") content_div.add_style("margin: 5px") content_div.add_style("border: solid 1px #999") content_div.add_style("min-width: 500px") content_div.add_style("min-height: 400px") content_div.add_style("height: 100%") right.add(content_div) sobject = Search.get_by_search_key(my.search_key) note_context = "%s|note" % my.context snapshots = Search.eval("@SOBJECT(sthpw/snapshot['context','=','%s'])" % note_context, [sobject]) vnotes_div = DivWdg() vnotes_div.add_style("overflow: auto") vnotes_div.add_style("width: 200px") vnotes_div.add_style("min-height: 400px") vnotes_div.add_style("max-height: 600px") vnotes_div.add_style("border: solid 1px #999") vnotes_div.add_style("padding: 5px") vnotes_div.add_style("margin: 5px") left.add(vnotes_div) if not snapshots: vnotes_div.add("<b>No review notes available</b>") notes_wdg = VisualNotesWdg(search_key=my.search_key, context=my.context) content_div.add(notes_wdg) for snapshot in snapshots: vnote_div = DivWdg() vnotes_div.add(vnote_div) file_obj = snapshot.get_file_by_type("main") if not file_obj: vnote_div.add("None found") continue rel_path = file_obj.get_value("relative_dir") file_name = file_obj.get_value("file_name") image_url = "/assets/%s/%s" % (rel_path, file_name) login = snapshot.get_value("login") date = snapshot.get_value("timestamp") import dateutil date_str = dateutil.parser.parse(date).strftime("%b %m %Y - %H:%M") login_div = DivWdg() login_div.add_style("padding: 2px") login_div.add("User: "******"<b>%s</b><br/>" % login) login_div.add("Date: ") login_div.add("<b>%s</b><br/>" % date_str) vnote_div.add(login_div) from pyasm.widget import ThumbWdg thumb_div = DivWdg() thumb_div.add_style("margin-left: 10px") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_has_img_link(False) thumb.set_option("detail", "false") thumb.set_option("icon_size", "80") thumb.set_sobject(snapshot) vnote_div.add(thumb_div) # file_obj = snapshot.get_file_by_type('icon') # rel_path = file_obj.get_value("relative_dir") # file_name = file_obj.get_value("file_name") # icon_url = "/assets/%s/%s" % (rel_path, file_name) # vnote_div.add("<img src='%s'/>" % icon_url ) # vnote_div.add(snapshot.get_code() ) vnote_div.add_attr("spt_image_url", image_url) vnote_div.add_class("hand") vnote_div.add_behavior( { "type": "click_up", "cbjs_action": """ var value = bvr.src_el.innerHTML; var image_url = bvr.src_el.getAttribute("spt_image_url"); var top = bvr.src_el.getParent(".spt_review_top"); var content = top.getElement(".spt_review_content"); content.innerHTML = "<img src='"+image_url+"'/>"; """, } ) # get the related note to this vnote # notes = vnotes_div.get_related_notes() search = Search("sthpw/note") search.add_parent_filter(sobject) notes = search.get_sobjects() # for note in notes: # vnote_div.add(note.get_value("note")) from pyasm.biz import SObjectConnection connections, related_notes = SObjectConnection.get_connected_sobjects(snapshot, direction="src") for related_note in related_notes: vnote_div.add(related_note.get_value("note")) print "related_notes: ", related_notes vnote_div.add("<hr/>") return top
def get_display(self): sobject = self.get_current_sobject() search_key = SearchKey.build_by_sobject(sobject) display = DivWdg() display.add_style("position: relative") display.add_class("spt_button_top") display.add_style("width: 26px") display.add_style("margin-left: auto") display.add_style("margin-right: auto") BASE = '/context/themes2/default/' over_div = DivWdg() display.add(over_div) over_div.add_class("spt_button_over") over_img = "<img src='%s/MainButton_over.png'/>" % BASE over_div.add(over_img) over_div.add_style("position: absolute") over_div.add_style("top: -9px") over_div.add_style("left: 0px") over_div.add_style("display: none") click_div = DivWdg() display.add(click_div) click_div.add_class("spt_button_click") click_img = "<img src='%s/MainButton_click.png'/>" % BASE click_div.add(click_img) click_div.add_style("position: absolute") click_div.add_style("top: -9px") click_div.add_style("left: 0px") click_div.add_style("display: none") if self.get_option('align') =='left': display.add_style("text-align: left") else: display.add_style("text-align: center") icon = self.get_option("icon") if not icon: icon = "create" icon_tip = self.get_option("icon_tip") if not icon_tip: icon_tip = self.get_option("hint") if not icon_tip: icon_tip = "" enable = self.get_option("enable") if enable: result = ExpressionParser().eval(enable, sobject) if not result: return " " if not self.script_obj and not self.script: icon_wdg = IconButtonWdg("No Script Found", IconWdg.ERROR) else: icon_link = icon.upper() icon_wdg = IconButtonWdg(icon_tip, icon=icon_link) if not sobject.is_insert(): icon_wdg.add_class("hand") #icon_wdg.add_behavior(self.behavior) icon_wdg.add_class("spt_button_%s" % self.name) icon_div = DivWdg() icon_div.add(icon_wdg) icon_div.add_style("position: absolute") icon_div.add_style("top: 2px") icon_div.add_style("left: 5px") display.add(icon_div) hit_wdg = icon_div hit_wdg.add_class("spt_button_hit") if sobject.is_insert(): hit_wdg.add_style("opacity: 0.4") else: hit_wdg.add_class("spt_button_hit_wdg") display.add_style("height: 18px") display.add_style("min-width: 21px") #display.add_style("overflow: hidden") display.add_style("margin-top: 0px") expression = self.kwargs.get('expression') if expression: value = Search.eval(expression, sobject, single=True) if value: badge = DivWdg() badge.add_style("position: absolute") badge.add_style("right: -30px") badge.add_style("top: -2px") badge.add_style("margin: 4px 3px 3px 6px") badge.add_style("opacity: 0.5") badge.add_style("font-size: 0.7em") badge.add_class("badge") badge.add(value) display.add(badge) display.add_style("position: relative") #return top return display
def get_display(self): self.search_type = self.kwargs.get('search_type') self.element_name = self.kwargs.get('element_name') assert self.search_type assert self.element_name class_name = 'tactic.ui.app.aggregate_wdg.AggregateCmd' interval = 120 priority = None if self.kwargs.get('is_refresh'): user = Environment.get_user_name() # these interval jobs need to have a specific code code = "aggregate|%s|%s" % (self.search_type, self.element_name) # check to see if the job exists #job = Search.get_by_code("sthpw/queue", code) job = None if not job: job = SearchType.create("sthpw/queue") #job.set_value("code", code) job.set_value("project_code", Project.get_project_code()) job.set_value("class_name", class_name) job.set_value("command", class_name) job.set_value("serialized", str(self.kwargs)) job.set_value("interval", 120) job.set_value("state", 'pending') job.set_value("queue", 'interval') job.set_value("priority", 9999) job.set_value("login", user) job.commit() self.view = self.kwargs.get('view') if not self.view: self.view = 'definition' top = DivWdg() self.set_as_panel(top) action_div = DivWdg() top.add(action_div) refresh = IconButtonWdg("Refresh", IconWdg.REFRESH) refresh.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' }) action_div.add(refresh) register_div = DivWdg() register_div.add_class("spt_queue_register") top.add(register_div) register_div.add_style("border: solid 1px black") register_div.add_style("padding: 20px") register_div.add("Register new interval aggregate") table = Table() table.add_style("margin: 15px") register_div.add(table) table.add_row() table.add_cell("command: ") table.add_cell(class_name) #table.add_row() #table.add_cell("priority: ") #table.add_cell(priority) table.add_row() table.add_cell("interval: ") td = table.add_cell("every ") td.set_attr("title", "Recalculation interval") text = TextWdg("interval") text.add_style("width: 30px") text.set_value(interval) td.add(text) unit_select = SelectWdg("unit") unit_select.set_value(interval) unit_select.set_option("values", "seconds|minutes|hours|days") td.add(" ") td.add(unit_select) table.add_row() table.add_cell("queue: ") table.add_cell("interval") from pyasm.widget import ProdIconButtonWdg button = ProdIconButtonWdg("Register") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_queue_register") var values = spt.api.get_input_values(top); var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' }) register_div.add(button) from pyasm.widget import ProdIconButtonWdg button = ProdIconButtonWdg("Cancel") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' alert('cancel'); ''' }) register_div.add(button) ''' cmd = AggregateCmd(**self.kwargs) print "registering scheduled task" scheduler = Scheduler.get() scheduler.start_thread() task = AggregateRefreshTask(name="cow", command=cmd) scheduler.add_interval_task(task, 10, mode='forked') scheduler.cancel_task("cow", delay=35) ''' top.add("<br/>") top.add("<b>Current Job Queue</b>") top.add("<br/><br/>") from tactic.ui.panel import TableLayoutWdg table = TableLayoutWdg(search_type='sthpw/queue', view='test') top.add(table) return top
def get_tool_bar(my): widget = DivWdg() widget.add_style("width: 250px") refresh = IconButtonWdg("Refresh", IconWdg.REFRESH) refresh.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' } ) widget.add( refresh ) widget.add(" ") trash_div = SpanWdg() # reset some global variables on load trash_div.add_behavior({'type':'load', 'cbjs_action':'spt.side_bar.trashed_items=[]; spt.side_bar.changed_views={}'}) trash_div.set_id('trash_me') trash_div.add(IconWdg('Trash', IconWdg.TRASH)) trash_div.add_class("hand") trash_div.add_class("spt_side_bar_trash") trash_div.set_attr("SPT_ACCEPT_DROP", "manageSideBar") bvr = { "type": "click_up",\ 'cbjs_action': "alert('Drag and drop link or folder here to remove it.')"} trash_div.add_behavior(bvr) widget.add(trash_div) save_div = SpanWdg(css='med hand spt_side_bar_trash') save_div.add(IconWdg('Save Ordering', IconWdg.SAVE)) bvr = { "type": "click_up", "search_type": my.search_type, "view": my.view, 'cbjs_action': ''' if (confirm("Save ordering of this view [" + bvr.view + "] ?") ) { var top = bvr.src_el.getParent(".spt_view_manager_top"); var list_top = top.getElement(".spt_menu_item_list"); var server = TacticServerStub.get(); server.start({"title": "Updating views"}); var is_personal = false; spt.app_busy.show("Saving", "Saving view ["+bvr.view+"]"); spt.side_bar.save_view(bvr.search_type, bvr.view, is_personal, list_top); server.finish(); spt.app_busy.hide(); } ''' } save_div.add_behavior(bvr) widget.add(save_div) gear = my.get_gear_menu() gear.add_style("float: right") widget.add( gear ) return widget
def get_tool_bar(my): widget = DivWdg() widget.add_style("width: 250px") refresh = IconButtonWdg("Refresh", IconWdg.REFRESH) refresh.add_behavior( { "type": "click_up", "cbjs_action": """ var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); """, } ) widget.add(refresh) widget.add(" ") trash_div = SpanWdg() # reset some global variables on load trash_div.add_behavior( {"type": "load", "cbjs_action": "spt.side_bar.trashed_items=[]; spt.side_bar.changed_views={}"} ) trash_div.set_id("trash_me") trash_div.add(IconWdg("Trash", IconWdg.TRASH)) trash_div.add_class("hand") trash_div.add_class("spt_side_bar_trash") trash_div.set_attr("SPT_ACCEPT_DROP", "manageSideBar") bvr = {"type": "click_up", "cbjs_action": "alert('Drag and drop link or folder here to remove it.')"} trash_div.add_behavior(bvr) widget.add(trash_div) save_div = SpanWdg(css="med hand spt_side_bar_trash") save_div.add(IconWdg("Save Ordering", IconWdg.SAVE)) bvr = { "type": "click_up", "search_type": my.search_type, "view": my.view, "cbjs_action": """ if (confirm("Save ordering of this view [" + bvr.view + "] ?") ) { var top = bvr.src_el.getParent(".spt_view_manager_top"); var list_top = top.getElement(".spt_menu_item_list"); var server = TacticServerStub.get(); server.start({"title": "Updating views"}); var is_personal = false; spt.app_busy.show("Saving", "Saving view ["+bvr.view+"]"); spt.side_bar.save_view(bvr.search_type, bvr.view, is_personal, list_top); server.finish(); spt.app_busy.hide(); } """, } save_div.add_behavior(bvr) widget.add(save_div) gear = my.get_gear_menu() gear.add_style("float: right") widget.add(gear) return widget
def get_display(self): web = WebContainer.get_web() naming_util = NamingUtil() if not self.widget_name: self.widget_name = self.get_name() # get the sobject required by this input sobject = self.get_current_sobject() if not sobject: sobject = Search.get_by_id(self.search_type, self.search_id) if self.new_sample_name: self.new_sample_name.replace("//", "/") else: self.new_sample_name = sobject.get_value(self.widget_name) widget = DivWdg() widget.set_id("naming") widget.add_style("display: block") # set the sample text div = DivWdg() div.add("Sample name: <i>%s</i>" % self.new_sample_name) div.add(HtmlElement.br(2)) new_sample_wdg = ProdIconButtonWdg("Set New Sample") new_sample_wdg.add_event("onclick", "toggle_display('generate')") div.add(new_sample_wdg) generate = DivWdg() generate.add(HtmlElement.br()) generate.set_id("generate") generate.add_style("display: none") sample_text = TextWdg("new_sample_name") sample_text.set_option("size", "30") #sample_text.set_persist_on_submit() #if self.new_sample_name: # sample_text.set_value(self.new_sample_name) generate.add(sample_text) button = IconButtonWdg("Generate", IconWdg.REFRESH, long=True) on_script = self.setup_ajax("naming") button.add_event("onclick", on_script) generate.add(button) generate.add(HtmlElement.br(2)) div.add(generate) widget.add(div) hidden = TextWdg(self.widget_name) value = self.naming hidden.set_value(self.new_sample_name) widget.add(self.widget_name) widget.add(hidden) # get all of the parts # TODO: not sure if this should be dictated by the sample name # break up the name into parts import re if self.new_sample_name: tmp = self.new_sample_name.strip("/") parts = re.split('[\\/._]', tmp) print "parts: ", parts else: return widget # if there is a naming, then populate that if self.edit_search_type: options = naming_util.get_options(self.edit_search_type) else: options = naming_util.get_options(sobject.get_value("search_type")) table = Table() type_values = [] padding_values = [] for idx, part in enumerate(parts): table.add_row() table.add_cell(part) type_select = SelectWdg("type_%s" % idx) type_select.add_empty_option("-- Explicit --") type_select.set_persist_on_submit() type_select.set_option("values", "|".join(options)) type_values.append(type_select.get_value()) td = table.add_cell(type_select) widget.add(table) return widget
def get_display(my): mode = my.get_option('mode') size = my.get_option('icon_size') if mode == 'add': my.set_option('icon', "CHECK_OUT") else: if size == 'large': my.set_option('icon', "CHECK_OUT_LG") else: my.set_option('icon', "CHECK_OUT_SM") top = DivWdg() icon = IconButtonWdg("Checkout", eval("IconWdg.%s" % my.get_option('icon'))) top.add(icon) my.process = my.get_option('process') my.context = '' transfer_mode = my.get_option('transfer_mode') sobject = my.get_current_sobject() if sobject.get_id() == -1: sobject = None snapshot_code = my.get_option("snapshot_code") sandbox_dir = my.get_option("sandbox_dir") if not sandbox_dir and sobject and isinstance(sobject, Snapshot): sandbox_dir = sobject.get_sandbox_dir(file_type='main') snapshot_code = sobject.get_code() lock_process = my.get_option("lock_process") sobject = my.get_current_sobject() search_key = SearchKey.get_by_sobject(sobject) if sobject.get_base_search_type() in ['sthpw/task', 'sthpw/note']: my.process = sobject.get_value('process') my.context = sobject.get_value('context') if not my.process: my.process = '' parent = sobject.get_parent() if not parent: return DivWdg() search_key = SearchKey.get_by_sobject(parent) else: my.process = my.get_option('process') search_key = SearchKey.get_by_sobject(sobject) checkout_script_path = my.get_option("checkout_script_path") checkout_panel_script_path = my.get_option( "checkout_panel_script_path") lock_process = my.get_option("lock_process") if not checkout_script_path: checkout_script_path = '' if not checkout_panel_script_path: checkout_panel_script_path = '' # FIXME: this does not get passed through 'cuz get_display is overridden here # so passed in directly in the script below my.behavior['checkout_panel_script_path'] = checkout_panel_script_path my.behavior['checkout_script_path'] = checkout_script_path my.behavior['process'] = my.process my.behavior['context'] = my.context my.behavior['lock_process'] = lock_process my.behavior['search_key'] = search_key my.behavior['snapshot_code'] = snapshot_code my.behavior['sandbox_dir'] = sandbox_dir my.behavior['transfer_mode'] = transfer_mode #layout_wdg = my.get_layout_wdg() #state = layout_wdg.get_state() cbjs_action = ''' var kwargs = { search_key: '%(search_key)s', sandbox_dir: '%(sandbox_dir)s', process: '%(process)s', context: '%(context)s', lock_process: '%(lock_process)s', checkout_script_path: '%(checkout_script_path)s' }; var transfer_mode = bvr.transfer_mode; if (!transfer_mode) { transfer_mode = spt.Environment.get().get_transfer_mode(); } if (transfer_mode == null) { transfer_mode = 'web'; } // NOTE: reusing checkin transfer mode if (transfer_mode == 'copy') { transfer_mode = 'client_repo'; } var values = {}; var top = bvr.src_el.getParent(".spt_checkin_top"); script = spt.CustomProject.get_script_by_path(bvr.checkout_panel_script_path); if (script) { bvr['script'] = script; bvr.values = kwargs; setTimeout( function() { try { spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { throw(e); spt.alert('No script found. <checkout_panel_script_path> display option should refer to a valid script path.'); } spt.app_busy.hide(); }, 50); } else { if (bvr.snapshot_code) { if (!bvr.checkout_script_path){ spt.app_busy.show("Checking out files", 'To: '+ bvr.sandbox_dir); setTimeout( function() { try { var server = TacticServerStub.get(); file_types = ['main']; filename_mode = 'source'; // we want this undefined so the checkout // snapshot can deal with it correctly. Explicitly // putting in a dir will force it to go there, // regardless of naming conventions sandbox_dir = null; server.checkout_snapshot(bvr.snapshot_code, sandbox_dir, {mode: transfer_mode, filename_mode: filename_mode, file_types: file_types} ); var checkin_top = bvr.src_el.getParent(".spt_checkin_top"); if (checkin_top) { spt.app_busy.show("Reading file system ...") spt.panel.refresh(checkin_top); spt.app_busy.hide(); } } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } else { setTimeout( function() { try { bvr['script'] = bvr.checkout_script_path; bvr.values = kwargs; spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } } else { var class_name = 'tactic.ui.widget.CheckoutWdg'; var values = kwargs; bvr.values = values; var search_key = values.search_key; var sandbox_dir = values.sandbox_dir; var process = values.process; var context = values.context; var options = { 'show_publish': 'false', 'process': process, 'context': context, 'search_key': search_key, 'checkout_script_path': bvr.checkout_script_path, 'sandbox_dir': sandbox_dir }; var popup_id ='Check-out Widget'; spt.panel.load_popup(popup_id, class_name, options); } } ''' % (my.behavior) my.behavior['type'] = 'click_up' my.behavior['cbjs_action'] = cbjs_action icon.add_behavior(my.behavior) return top
def get_display(my): current = my.get_current_sobject() if current.is_insert(): widget = Widget() parent_key = my.get_option('parent_key') if parent_key: parent = SearchKey.get_by_search_key(parent_key) if parent: widget.add(SpanWdg(parent.get_code())) else: # use the project as the parent parent = Project.get() widget.add(SpanWdg("Project: %s" % parent.get_code())) #raise TacticException('Task creation aborted since parent is undetermined. Please check the configuration that generates this table.') text = HiddenWdg(my.get_input_name()) text.set_option('size', '40') text.set_value(parent_key) widget.add(text) return widget else: search_type = current.get_value('search_type') if not search_type: return "No parent type" widget = Widget() parent = current.get_parent() if parent: widget.add(parent.get_code()) return widget # What is this look up code for? text = TextWdg(my.get_input_name()) behavior = { 'type': 'keyboard', 'kbd_handler_name': 'DgTableMultiLineTextEdit' } text.add_behavior(behavior) widget.add(text) icon = IconButtonWdg("Look up", IconWdg.ZOOM) icon.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var options = { title: '%s', class_name: 'tactic.ui.panel.ViewPanelWdg' }; var args = { search_type: '%s', view: 'list' }; spt.popup.get_widget( {}, {options: options, args: args} ); ''' % (search_type, search_type) }) widget.add(icon) return widget