def get_header_context_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu.set_setup_cbfn('spt.dg_table.smenu_ctx.setup_cbk') menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Edit Column Definition') menu_item.add_behavior({ 'args': { 'search_type': my.search_type, 'options': { 'class_name': 'tactic.ui.manager.ElementDefinitionWdg', 'popup_id': 'edit_column_defn_wdg', 'title': 'Edit Column Definition' } }, 'cbjs_action': ''' spt.alert("Not yet implemented"); return var activator = spt.smenu.get_activator(bvr); bvr.args.element_name = activator.getProperty("spt_element_name"); bvr.args.view = activator.getAttribute('spt_view'); var popup = spt.popup.get_widget(evt,bvr); popup.activator = activator; ''' }) menu.add(menu_item) return menu
def get_add_menu(self): from tactic.ui.container import Menu, MenuItem menu = Menu(width=180) menu.set_allow_icons(False) #menu.set_setup_cbfn( 'spt.smenu_ctx.setup_cbk' ) menu_item = MenuItem(type='title', label='Add Item') menu.add(menu_item) menu_item = MenuItem(type='action', label='Label') menu_item.add_behavior({ 'element_name': 'label', 'cbjs_action': self.get_add_bvr_action() }) menu.add(menu_item) menu_item = MenuItem(type='action', label='Text') menu_item.add_behavior({ 'element_name': 'text', 'cbjs_action': self.get_add_bvr_action() }) menu.add(menu_item) menu_item = MenuItem(type='action', label='TextArea') menu_item.add_behavior({ 'element_name': 'textarea', 'cbjs_action': self.get_add_bvr_action() }) menu.add(menu_item) return menu
def get_extra_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Edit Tab Config') menu_item.add_behavior({ 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); spt.tab.top = activator.getParent(".spt_tab_top"); var element_name = 'edit_tab_config'; var title = 'Edit Tab Config'; var class_name = 'tactic.ui.manager.ViewManagerWdg'; var kwargs = { search_type: 'prod/asset', view: 'tab_config_model' } spt.tab.add_new(element_name, title, class_name, kwargs); ''' }) menu.add(menu_item) return menu
def get_extra_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Edit Tab Config') menu_item.add_behavior( { 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); spt.tab.top = activator.getParent(".spt_tab_top"); var element_name = 'edit_tab_config'; var title = 'Edit Tab Config'; var class_name = 'tactic.ui.manager.ViewManagerWdg'; var kwargs = { search_type: 'prod/asset', view: 'tab_config_model' } spt.tab.add_new(element_name, title, class_name, kwargs); ''' } ) menu.add(menu_item) return menu
def get_context_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Remove Share') menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' if (!confirm("Delete share?") ) { return; } var activator = spt.smenu.get_activator(bvr); var code = activator.getAttribute("spt_share_code"); var class_name = 'tactic.ui.startup.ShareItemCbk'; var kwargs = { 'action': 'delete', 'code': code }; var server = TacticServerStub.get(); server.execute_cmd(class_name, kwargs); var top = activator.getParent(".spt_share_top"); spt.panel.refresh(top); ''' }) return menu
def get_context_menu(self): menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Remove Share') menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' if (!confirm("Delete share?") ) { return; } var activator = spt.smenu.get_activator(bvr); var code = activator.getAttribute("spt_share_code"); var class_name = 'tactic.ui.startup.ShareItemCbk'; var kwargs = { 'action': 'delete', 'code': code }; var server = TacticServerStub.get(); server.execute_cmd(class_name, kwargs); var top = activator.getParent(".spt_share_top"); spt.panel.refresh(top); ''' }) return menu
def get_add_menu(self): from tactic.ui.container import Menu, MenuItem menu = Menu(width=180) menu.set_allow_icons(False) #menu.set_setup_cbfn( 'spt.smenu_ctx.setup_cbk' ) menu_item = MenuItem(type='title', label='Add Item') menu.add(menu_item) menu_item = MenuItem(type='action', label='Label') menu_item.add_behavior( { 'element_name': 'label', 'cbjs_action': self.get_add_bvr_action() } ) menu.add(menu_item) menu_item = MenuItem(type='action', label='Text') menu_item.add_behavior( { 'element_name': 'text', 'cbjs_action': self.get_add_bvr_action() } ) menu.add(menu_item) menu_item = MenuItem(type='action', label='TextArea') menu_item.add_behavior( { 'element_name': 'textarea', 'cbjs_action': self.get_add_bvr_action() } ) menu.add(menu_item) return menu
def get_test_context_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type="title", label="Actions") menu.add(menu_item) menu_item = MenuItem(type="action", label="Refresh") menu.add(menu_item) menu_item.add_behavior( { "type": "click_up", "view": my.view, "cbjs_action": """ var activator = spt.smenu.get_activator(bvr); var top = activator.getParent(".spt_custom_top"); top.setAttribute("spt_is_test", "true"); var size = top.getSize(); top.innerHTML = "<div style='width: "+size.x+";height: "+size.y+";padding: 10px; font-weight: bold'>Loading ...</div>"; spt.panel.refresh(top); """, } ) menu_item = MenuItem(type="action", label="Edit") menu.add(menu_item) menu_item.add_behavior( { "type": "click_up", "view": my.view, "cbjs_action": """ var activator = spt.smenu.get_activator(bvr); var popup_top = activator.getParent(".spt_popup"); var top = popup_top.top; if (top) { top.setAttribute("spt_view", bvr.view); spt.app_busy.show("Loading view: " + bvr.view); spt.panel.refresh(top); spt.app_busy.hide(); } """, } ) return menu
def get_test_context_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Refresh') menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'view': my.view, 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var top = activator.getParent(".spt_custom_top"); top.setAttribute("spt_is_test", "true"); var size = top.getSize(); top.innerHTML = "<div style='width: "+size.x+";height: "+size.y+";padding: 10px; font-weight: bold'>Loading ...</div>"; spt.panel.refresh(top); ''' } ) menu_item = MenuItem(type='action', label='Edit') menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'view': my.view, 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var popup_top = activator.getParent(".spt_popup"); var top = popup_top.top; if (top) { top.setAttribute("spt_view", bvr.view); spt.app_busy.show("Loading view: " + bvr.view); spt.panel.refresh(top); spt.app_busy.hide(); } ''' } ) return menu
def get_node_context_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu.set_setup_cbfn( 'spt.dg_table.smenu_ctx.setup_cbk' ) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Load Detail Report') menu_item.add_behavior( { 'cbjs_action': ''' var node = spt.smenu.get_activator(bvr); var name = node.getAttribute("spt_element_name"); var top = node.getParent(".spt_detail_top"); spt.tab.top = top.getElement(".spt_tab_top"); var search_key = top.getAttribute("spt_parent_key"); if (!search_key) { search_key = top.getAttribute("spt_search_key"); } var class_name = 'tactic.ui.tools.sobject_wdg.SObjectSingleProcessDetailWdg'; var kwargs = { search_key: search_key, process: name } var title = "Detail ["+name+"]"; var element_name = "detail_"+name; spt.tab.add_new(element_name, title, class_name, kwargs); ''' } ) menu.add(menu_item) return menu
def get_text_new_context_menu(my): search_type_obj = SearchType.get(my.search_type) title = search_type_obj.get_title() menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label="Update line") menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var line_el = activator.getParent(".spt_new_line"); var prev_line_el = line_el.getPrevious(".spt_line"); prev_line_el.setStyle("border", "solid 1px red"); var content = prev_line_el.getElement(".spt_line_content"); alert(content.innerHTML); var prev_line_el = prev_line_el.getPrevious(".spt_line"); prev_line_el.setStyle("border", "solid 1px red"); var next_line_el = line_el.getNext(".spt_line"); next_line_el.setStyle("border", "solid 1px red"); var next_line_el = next_line_el.getNext(".spt_line"); next_line_el.setStyle("border", "solid 1px red"); ''' }) return menu
def get_text_new_context_menu(self): search_type_obj = SearchType.get(self.search_type) title = search_type_obj.get_title() menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label="Update line") menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var activator = spt.smenu.get_activator(bvr); var line_el = activator.getParent(".spt_new_line"); var prev_line_el = line_el.getPrevious(".spt_line"); prev_line_el.setStyle("border", "solid 1px red"); var content = prev_line_el.getElement(".spt_line_content"); alert(content.innerHTML); var prev_line_el = prev_line_el.getPrevious(".spt_line"); prev_line_el.setStyle("border", "solid 1px red"); var next_line_el = line_el.getNext(".spt_line"); next_line_el.setStyle("border", "solid 1px red"); var next_line_el = next_line_el.getNext(".spt_line"); next_line_el.setStyle("border", "solid 1px red"); ''' } ) return menu
def get_node_context_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu.set_setup_cbfn('spt.dg_table.smenu_ctx.setup_cbk') menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Load Detail Report') menu_item.add_behavior({ 'cbjs_action': ''' var node = spt.smenu.get_activator(bvr); var name = node.getAttribute("spt_element_name"); var top = node.getParent(".spt_detail_top"); spt.tab.top = top.getElement(".spt_tab_top"); var search_key = top.getAttribute("spt_parent_key"); if (!search_key) { search_key = top.getAttribute("spt_search_key"); } var class_name = 'tactic.ui.tools.sobject_wdg.SObjectSingleProcessDetailWdg'; var kwargs = { search_key: search_key, process: name } var title = "Detail ["+name+"]"; var element_name = "detail_"+name; spt.tab.add_new(element_name, title, class_name, kwargs); ''' }) menu.add(menu_item) return menu
def get_add_menu(my): from tactic.ui.container import Menu, MenuItem menu = Menu(width=180) menu.set_allow_icons(False) # menu.set_setup_cbfn( 'spt.dg_table.smenu_ctx.setup_cbk' ) menu_item = MenuItem(type="title", label="Add Item") menu.add(menu_item) menu_item = MenuItem(type="action", label="Label") menu_item.add_behavior({"element_name": "label", "cbjs_action": my.get_add_bvr_action()}) menu.add(menu_item) menu_item = MenuItem(type="action", label="Text") menu_item.add_behavior({"element_name": "text", "cbjs_action": my.get_add_bvr_action()}) menu.add(menu_item) menu_item = MenuItem(type="action", label="TextArea") menu_item.add_behavior({"element_name": "textarea", "cbjs_action": my.get_add_bvr_action()}) menu.add(menu_item) return menu
def get_header_context_menu(my): menu = Menu(width=180) menu.set_allow_icons(False) menu.set_setup_cbfn( 'spt.dg_table.smenu_ctx.setup_cbk' ) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) menu_item = MenuItem(type='action', label='Edit Column Definition') menu_item.add_behavior( { 'args' : { 'search_type': my.search_type, 'options': { 'class_name': 'tactic.ui.manager.ElementDefinitionWdg', 'popup_id': 'edit_column_defn_wdg', 'title': 'Edit Column Definition' } }, 'cbjs_action': ''' spt.alert("Not yet implemented"); return var activator = spt.smenu.get_activator(bvr); bvr.args.element_name = activator.getProperty("spt_element_name"); bvr.args.view = activator.getAttribute('spt_view'); var popup = spt.popup.get_widget(evt,bvr); popup.activator = activator; ''' } ) menu.add(menu_item) return menu
def get_text_context_menu(self): search_type_obj = SearchType.get(self.search_type) title = search_type_obj.get_title() menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) label = 'Create New "%s"' % title menu_item = MenuItem(type='action', label=label) menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'search_type': self.search_type, 'column': self.column, 'cbjs_action': r''' var activator = spt.smenu.get_activator(bvr); var selection = spt.document.selected_text; if (!selection) { alert("Nothing selected"); return; } spt.app_busy.show("Adding " + bvr.search_type); var data = {} data[bvr.column] = selection; var server = TacticServerStub.get(); server.insert(bvr.search_type, data); spt.app_busy.hide(); ''' } ) label = '%s (Detail)' % label menu_item = MenuItem(type='action', label=label) menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'search_type': self.search_type, 'cbjs_action': r''' var activator = spt.smenu.get_activator(bvr); var selection = spt.document.selected_text; if (!selection) { alert("Nothing selected"); return; } var class_name = 'tactic.ui.panel.EditWdg'; var kwargs = { search_type: bvr.search_type, default: { description: selection } } spt.panel.load_popup("Add", class_name, kwargs); ''' } ) menu_item = MenuItem(type='separator') menu.add(menu_item) menu_item = MenuItem(type='action', label='Search') menu.add(menu_item) menu_item.add_behavior( { 'type': 'click_up', 'search_type': self.search_type, 'cbjs_action': r''' var activator = spt.smenu.get_activator(bvr); var selection = spt.document.selected_text; if (!selection) { alert("Nothing selected"); return; } var top = activator.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); spt.app_busy.show("Searching " + selection); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'keywords': selection, 'simple_search_view': 'simple_filter', } spt.panel.load(data_el, class_name, kwargs); spt.app_busy.hide(); ''' } ) return menu
def get_display(my): menus = [] widget = DivWdg(id='ProjectSelectWdg', css='spt_panel') widget.set_attr('spt_class_name', 'tactic.ui.app.ProjectSelectWdg') if not WebContainer.get_web().is_IE(): widget.add_style("float: right") from tactic.ui.widget import SingleButtonWdg button = SingleButtonWdg(title='Open Project', icon=IconWdg.PROJECT, show_arrow=True) widget.add(button) #from tactic.ui.activator import ButtonForDropdownMenuWdg #menu_data = [] #menu_id = "project_select_menu" allowed = Project.get_user_projects() allowed_codes = [x.get_code() for x in allowed] search = Search("sthpw/project") search.add_filters("code", allowed_codes) # ignore some builtin projects search.add_where("\"code\" not in ('admin','sthpw','unittest')") search.add_op("begin") #search.add_filter("is_template", 'true', quoted=False, op='!=') search.add_filter("is_template", True, op='!=') search.add_filter("is_template", 'NULL', quoted=False, op='is') search.add_op("or") projects = search.get_sobjects() from tactic.ui.container import Menu, MenuItem menu = Menu(width=240) menus.append(menu) menu.set_allow_icons(False) security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow", default="deny") or security.check_access("builtin", "create_projects", "allow", default="deny"): menu_item = MenuItem(type='title', label='Project Action') menu.add(menu_item) menu_item = MenuItem(type='action', label='Create New Project') menu.add(menu_item) menu_item.add_behavior( { 'cbjs_action': ''' //spt.popup.open('create_project_wizard'); //Effects.fade_in($('create_project_wizard'), 200); var env = spt.Environment.get(); var project = env.get_project(); if (project == 'admin') { spt.tab.set_main_body_top(); var class_name = 'tactic.ui.app.ProjectCreateWdg'; spt.tab.add_new("create_project", "Create Project", class_name); } else { document.location = "/tactic/admin/link/create_project"; } ''' } ) search = Search("config/url") search.add_filter("url", "/index") url = search.get_sobject() if url: menu_item = MenuItem(type='action', label='Open Index') menu.add(menu_item) menu_item.add_behavior( { 'cbjs_action': ''' var env = spt.Environment.get(); var project = env.get_project(); //document.location = "/tactic/" + project + "/"; window.open('/tactic/'+project+'/'); ''' } ) menu_item = MenuItem(type='title', label='Open Project') menu.add(menu_item) def add_project_menu(menu, project): project_code = project.get_code() menu_item = MenuItem(type='action', label=project.get_value("title")) web = WebContainer.get_web() browser = web.get_browser() if browser != 'Qt': menu_item.add_behavior( { 'type': 'click_up', 'project_code': project_code, 'cbjs_action': ''' window.open('/tactic/%s/'); ''' % project_code } ) else: menu_item.add_behavior( { 'project_code': project_code, 'cbjs_action': ''' spt.app_busy.show("Jumping to Project ["+bvr.project_code+"]", ""); document.location = '/tactic/%s/'; ''' % project_code } ) menu.add(menu_item) search = Search("sthpw/project") search.add_column("category", distinct=True) categories = [x.get_value("category") for x in search.get_sobjects() ] for category in categories: if category == '': continue # FIXME: a little inefficient, but should be ok for now category_projects = [] for project in projects: if project.get_value("category") != category: continue project_code = project.get_code() if not security.check_access("project", project_code, "view"): continue category_projects.append(project) if category_projects: suffix = Common.get_filesystem_name(category) label = "%s (%s)" % (category, len(category_projects)) menu_item = MenuItem(type='submenu', label=label) menu_item.set_submenu_tag_suffix(suffix) menu.add(menu_item) submenu = Menu(width=200, menu_tag_suffix=suffix) menus.append(submenu) for project in category_projects: add_project_menu(submenu, project) from pyasm.security import get_security_version security_version = get_security_version() for project in projects: if project.get_value("category") != "": continue project_code = project.get_code() if security_version >= 2: key = { "code": project_code } key2 = { "code": "*" } keys = [key, key2] default = "deny" if not security.check_access("project", keys, "allow", default=default): continue else: if not security.check_access("project", project_code, "view", default="allow"): continue add_project_menu(menu, project) if not projects: menu_item = MenuItem(type='action', label="- No Projects Created -") menu_item.add_behavior( { 'cbjs_action': ''' ''' } ) menu.add(menu_item) if security.check_access("builtin", "view_site_admin", "allow") or security.check_access("builtin", "view_template_projects", "allow"): search = Search("sthpw/project") #search.add_filter("is_template", 'true', quoted=False) search.add_filter("is_template", True) projects = search.get_sobjects() if projects: menu_item = MenuItem(type='title', label="Template Projects") menu.add(menu_item) for project in projects: project_code = project.get_code() if security_version >= 2: key = { "code": project_code } key2 = { "code": "*" } keys = [key, key2] default = "deny" if not security.check_access("project", keys, "allow", default=default): continue else: if not security.check_access("project", project_code, "view", default="allow"): continue menu_item = MenuItem(type='action', label=project.get_value("title")) menu_item.add_behavior( { 'project_code': project_code, 'cbjs_action': ''' spt.app_busy.show("Jumping to Project ["+bvr.project_code+"]", ""); document.location = '/projects/%s/' ''' % project_code } ) menu.add(menu_item) if security.check_access("builtin", "view_site_admin", "allow", default="deny") or security.check_access("builtin", "create_projects", "allow", default="deny"): menu_item = MenuItem(type='title', label="Admin") menu.add(menu_item) project = Project.get_by_code("admin") add_project_menu(menu, project) from tactic.ui.container import SmartMenu smenu_set = SmartMenu.add_smart_menu_set( button, { 'BUTTON_MENU': menus } ) SmartMenu.assign_as_local_activator( button, "BUTTON_MENU", True ) return widget
def get_text_context_menu(my): search_type_obj = SearchType.get(my.search_type) title = search_type_obj.get_title() menu = Menu(width=180) menu.set_allow_icons(False) menu_item = MenuItem(type='title', label='Actions') menu.add(menu_item) label = 'Create New "%s"' % title menu_item = MenuItem(type='action', label=label) menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'search_type': my.search_type, 'column': my.column, 'cbjs_action': r''' var activator = spt.smenu.get_activator(bvr); var selection = spt.document.selected_text; if (!selection) { alert("Nothing selected"); return; } spt.app_busy.show("Adding " + bvr.search_type); var data = {} data[bvr.column] = selection; var server = TacticServerStub.get(); server.insert(bvr.search_type, data); spt.app_busy.hide(); ''' }) label = '%s (Detail)' % label menu_item = MenuItem(type='action', label=label) menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'search_type': my.search_type, 'cbjs_action': r''' var activator = spt.smenu.get_activator(bvr); var selection = spt.document.selected_text; if (!selection) { alert("Nothing selected"); return; } var class_name = 'tactic.ui.panel.EditWdg'; var kwargs = { search_type: bvr.search_type, default: { description: selection } } spt.panel.load_popup("Add", class_name, kwargs); ''' }) menu_item = MenuItem(type='separator') menu.add(menu_item) menu_item = MenuItem(type='action', label='Search') menu.add(menu_item) menu_item.add_behavior({ 'type': 'click_up', 'search_type': my.search_type, 'cbjs_action': r''' var activator = spt.smenu.get_activator(bvr); var selection = spt.document.selected_text; if (!selection) { alert("Nothing selected"); return; } var top = activator.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); spt.app_busy.show("Searching " + selection); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'keywords': selection, 'simple_search_view': 'simple_filter', } spt.panel.load(data_el, class_name, kwargs); spt.app_busy.hide(); ''' }) return menu