Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
    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
Esempio n. 6
0
    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
Esempio n. 7
0
    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
Esempio n. 9
0
    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
Esempio n. 10
0
    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
Esempio n. 11
0
    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
Esempio n. 12
0
    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
Esempio n. 13
0
    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
Esempio n. 14
0
    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
Esempio n. 15
0
    def get_display(my):

        my.search_key = my.kwargs.get("search_key")
        my.process = my.kwargs.get("process")
        my.sobject = Search.get_by_search_key(my.search_key)
        my.pipeline_code = my.kwargs.get("pipeline_code")

        top = DivWdg()
        top.add_class("spt_file_selector")
        top.add_style("position: relative")

        hidden = HiddenWdg("mode")
        #hidden = TextWdg("mode")
        hidden.add_class("spt_mode")
        top.add(hidden)

        top.add_style("padding: 5px")
        top.add_style("min-width: 500px")
        top.add_style("min-height: 400px")
        top.add_color("background", "background")
        top.add_color("color", "color")
        #top.add_border()

        logo_wdg = DivWdg()
        logo = HtmlElement.img(src="/context/icons/logo/perforce_logo.gif")
        logo_wdg.add(logo)
        top.add(logo_wdg)
        logo_wdg.add_style("opacity: 0.2")
        logo_wdg.add_style("position: absolute")
        logo_wdg.add_style("bottom: 0px")
        logo_wdg.add_style("right: 5px")

        # get some info from the config file
        """
        client_env_var = Config.get_value("perforce", "client_env_var")
        if not client_env_var:
            client_env_var = "P4Client"
        port_env_var = Config.get_value("perforce", "port_env_var")
        if not port_env_var:
            port_env_var = "P4Port"
        user_env_var = Config.get_value("perforce", "user_env_var")
        if not user_env_var:
            user_env_var = "P4User"
        password_env_var = Config.get_value("perforce", "password_env_var")
        if not password_env_var:
            password_env_var = "P4Passwd"
        """

        # {GET(sthpw/login)}_user
        host = ""
        client = ""
        user = ""
        password = ""
        port = ""

        project = my.sobject.get_project()
        depot = project.get_value("location", no_exception=True)
        if not depot:
            depot = ""

        top.add_behavior({
            'type': 'load',
            #'client_env_var': client_env_var,
            #'port_env_var': port_env_var,
            #'user_env_var': user_env_var,
            #'password_env_var': password_env_var,
            'client': client,
            'user': user,
            'password': password,
            'host': host,
            'port': port,
            'depot': depot,
            'cbjs_action': get_onload_js()
        })

        list_wdg = DivWdg()
        top.add(list_wdg)
        list_wdg.add_style("height: 32px")

        from tactic.ui.widget import SingleButtonWdg, ButtonNewWdg, ButtonRowWdg

        button_row = ButtonRowWdg()
        list_wdg.add(button_row)
        button_row.add_style("float: left")

        button = ButtonNewWdg(title="Refresh",
                              icon=IconWdg.REFRESH,
                              long=False)
        button_row.add(button)
        button.add_style("float: left")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.app_busy.show("Reading file system ...")
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.panel.refresh(top);
        spt.app_busy.hide();
        '''
        })

        button = ButtonNewWdg(title="Check-out",
                              icon=IconWdg.CHECK_OUT,
                              long=False)
        button_row.add(button)

        my.sandbox_dir = my.kwargs.get("sandbox_dir")

        # what are we trying to do here???
        #my.root_sandbox_dir = Environment.get_sandbox_dir()
        #project = my.sobject.get_project()
        #my.root_sandbox_dir = "%s/%s" % (my.root_sandbox_dir, project.get_code())
        #repo_dir = my.sandbox_dir.replace("%s/" % my.root_sandbox_dir, "")
        #repo_dir = "%s/%s" % (project.get_code(), repo_dir)

        # checkout command requires either starting with //<depot>/ or just
        # the relative path to the root.  The following removes
        # the root of the sandbox folder assuming that this is mapped
        # to the base of the depot
        my.root_sandbox_dir = Environment.get_sandbox_dir()
        repo_dir = my.sandbox_dir
        repo_dir = my.sandbox_dir.replace("%s/" % my.root_sandbox_dir, "")

        #button.add_style("padding-right: 14px")
        button.add_style("float: left")
        button.add_behavior({
            'type':
            'click_up',
            'repo_dir':
            repo_dir,
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.app_busy.show("Reading file system ...")

        var data = spt.scm.checkout(bvr.repo_dir)
        spt.panel.refresh(top);

        spt.app_busy.hide();
        '''
        })

        button = ButtonNewWdg(title="Perforce Actions",
                              icon=IconWdg.PERFORCE,
                              show_arrow=True)
        #button.set_show_arrow_menu(True)
        button_row.add(button)

        menu = Menu(width=220)
        menu_item = MenuItem(type='title', label='Perforce')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Show Workspaces')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = 'tactic.ui.checkin.WorkspaceWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");

            var el = top.getElement(".spt_mode");
            el.value = "workspace";

            var kwargs = {};
            spt.panel.load(content, class_name, kwargs);
            '''
        })

        menu_item = MenuItem(type='action', label='Show Changelists')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = 'tactic.ui.checkin.ChangelistWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");

            var el = top.getElement(".spt_mode");
            el.value = "changelist";

            var kwargs = {};
            spt.panel.load(content, class_name, kwargs);
            '''
        })

        menu_item = MenuItem(type='action', label='Show Branches')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = 'tactic.ui.checkin.branch_wdg.BranchWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");

            var el = top.getElement(".spt_mode");
            el.value = "branch";

            var kwargs = {};
            spt.panel.load(content, class_name, kwargs);
            '''
        })

        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Add New Changelist')
        menu.add(menu_item)

        menu_item.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);
            spt.scm.run("add_changelist", ["New Changelist"]);

            var class_name = 'tactic.ui.checkin.ChangelistWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");
            spt.panel.load(content, class_name);

            '''
        })

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Sign Out of Perforce')
        menu.add(menu_item)

        menu_item.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''

            if (!confirm("Are you sure you wish to sign out of Perforce?")) {
                return;
            }
            spt.scm.signout_user();

            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);


            '''
        })

        #SmartMenu.add_smart_menu_set( button.get_arrow_wdg(), { 'BUTTON_MENU': menu } )
        #SmartMenu.assign_as_local_activator( button.get_arrow_wdg(), "BUTTON_MENU", True )

        SmartMenu.add_smart_menu_set(button.get_button_wdg(),
                                     {'BUTTON_MENU': menu})
        SmartMenu.assign_as_local_activator(button.get_button_wdg(),
                                            "BUTTON_MENU", True)

        # Perforce script editor. (nice because it should run as the user
        # in the appopriate environment
        """
        button = ButtonNewWdg(title="P4 Script Editor", icon=IconWdg.CREATE, show_arrow=True)
        #button_row.add(button)
        button.add_style("padding-right: 14px")
        button.add_style("float: left")
        """

        button = ButtonNewWdg(title="Changelists Counter",
                              icon=IconWdg.CHECK_OUT_SM,
                              show_arrow=True)
        #button_row.add(button)
        #button.add_style("padding-right: 14px")
        button.add_style("float: left")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
                // find any changelists that were missed
                var changelists = spt.scm.run("get_changelists", []);
                for (var i = 0; i < changelists.length; i++) {
                    var changelist = changelists[i];
                    var info = spt.scm.run("get_changelist_info",[changelist.change]);
                    console.log(info);
                }
                '''
        })

        # Hiding this for now

        button = ButtonNewWdg(title="Create",
                              icon=IconWdg.NEW,
                              show_arrow=True)
        #button_row.add(button)
        button.add_style("padding-right: 14px")
        button.add_style("float: left")

        menu = Menu(width=220)
        menu_item = MenuItem(type='title', label='New ...')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Text File')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'sandbox_dir':
            my.sandbox_dir,
            'cbjs_action':
            '''
        var path = bvr.sandbox_dir + "/" + "new_text_file.txt";
        var env = spt.Environment.get();
        var url = env.get_server_url() + "/context/VERSION_API";
        var applet = spt.Applet.get();
        applet.download_file(url, path);

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);

        '''
        })

        #create_sobj = SObject.create("sthpw/virtual")
        #create_sobj.set_value("title", "Maya Project")
        #create_sobj.set_value("script_path", "create/maya_project")

        script_path = 'create/maya_project'
        menu_item = MenuItem(type='action', label='Maya Project')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'sandbox_dir':
            my.sandbox_dir,
            'process':
            my.process,
            'script_path':
            script_path,
            'cbjs_action':
            '''
        var script = spt.CustomProject.get_script_by_path(bvr.script_path);
        var options = {};
        options.script = script;

        // add some data to options
        options.sandbox_dir = bvr.sandbox_dir;
        options.process = bvr.process;
        spt.CustomProject.exec_custom_script({}, options);

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);
        '''
        })

        template_path = '/context/template/maya_project.zip'
        menu_item = MenuItem(type='action', label='Zipped Template')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'sandbox_dir':
            my.sandbox_dir,
            'template_path':
            template_path,
            'cbjs_action':
            '''
        var path = bvr.sandbox_dir + "/" + "_template.zip";
        var env = spt.Environment.get();
        var url = env.get_server_url() + bvr.template_path;
        var applet = spt.Applet.get();
        applet.download_file(url, path);
        applet.unzip_file(path, bvr.sandbox_dir);
        applet.rmtree(path);

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);

        '''
        })

        SmartMenu.add_smart_menu_set(button, {'BUTTON_MENU': menu})
        SmartMenu.assign_as_local_activator(button, "BUTTON_MENU", True)

        # Browse button for browsing files and dirs directly
        """
        browse_div = DivWdg()
        list_wdg.add(browse_div)
        browse_div.add_style("float: left")

        button = ActionButtonWdg(title="Browse", tip="Select Files or Folder to Check-In")
        browse_div.add(button)

        behavior = {
        'type': 'click_up',
        'base_dir': my.sandbox_dir,
        'cbjs_action': '''
            var current_dir = bvr.base_dir;
            var is_sandbox = false;
            spt.checkin.browse_folder(current_dir, is_sandbox);
        '''
        }
        button.add_behavior( behavior )
        """

        from tactic.ui.widget import SandboxButtonWdg, CheckoutButtonWdg, ExploreButtonWdg, GearMenuButtonWdg

        button_row = ButtonRowWdg()
        list_wdg.add(button_row)
        button_row.add_style("float: right")

        #button = SandboxButtonWdg(base_dir=my.sandbox_dir, process=my.process)
        #button_row.add(button)

        #button = CheckoutButtonWdg(base_dir=my.sandbox_dir, sobject=my.sobject, proces=my.process)
        #button_row.add(button)

        button = ExploreButtonWdg(base_dir=my.sandbox_dir)
        button_row.add(button)

        button = GearMenuButtonWdg(base_dir=my.sandbox_dir,
                                   process=my.process,
                                   pipeline_code=my.pipeline_code)
        button_row.add(button)

        list_wdg.add("<br clear='all'/>")

        top.add("<hr/>")

        content_div = DivWdg()
        top.add(content_div)
        content_div.add_class("spt_checkin_content")

        content = my.get_content_wdg()
        content_div.add(content)

        return top
Esempio n. 16
0
    def get_gear_menu(my):

        top = DivWdg()

        # FIXME: the gear menu widget should be here
        from tactic.ui.container import GearMenuWdg, Menu, MenuItem
        menu = Menu(width=180)

        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)


        # create a new element
        menu_item = MenuItem(type='action', label='New Element')
        behavior = {
        'options': {
          'is_insert': 'true',
          'search_type': my.search_type,
          'view':        my.view
        },
        'cbjs_action': '''

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_view_manager_top");
        var detail_panel = top.getElement(".spt_view_manager_detail");

        var class_name = 'tactic.ui.manager.ElementDefinitionWdg';
        var options = bvr.options
        var values = {};
        spt.panel.load(detail_panel, class_name, options, values, false);
        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)





        # Show preview of the view
        menu_item = MenuItem(type='action', label='Show Preview')
        behavior = {
        'search_type': my.search_type,
        'view':        my.view,
        'cbjs_action': '''
        var kwargs = {
          search_type: bvr.search_type,
          view: bvr.view
        };
        var title = "Search Type: [" + bvr.search_type + "], View [" + bvr.view + "]";
        spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs);
        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)



        # Show preview of the view
        menu_item = MenuItem(type='action', label='Show Full XML Config')
        behavior = {
        'search_type': my.search_type,
        'view':        my.view,
        'cbjs_action': '''
        var kwargs = {
          search_type: 'config/widget_config',
          view: 'table',
          expression: "@SOBJECT(config/widget_config['search_type','"+bvr.search_type+"']['view','"+bvr.view+"'])",
          filter: [{}]
        };
        var title = "Widget Config - ["+bvr.search_type+"] ["+bvr.view+"]";
        spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs);
        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)


        menu_item = MenuItem(type='separator')
        menu.add(menu_item)




        # New view popup
        new_view_wdg = DivWdg()
        new_view_wdg.add_class("spt_new_view")
        new_view_wdg.add_style("display: none")
        new_view_wdg.add_style("position: absolute")
        new_view_wdg.add_color("background", "background")
        new_view_wdg.add_style("z-index: 100")
        new_view_wdg.add_border()
        new_view_wdg.set_round_corners()
        new_view_wdg.set_box_shadow()
        new_view_wdg.add_style("padding: 30px")
        new_view_wdg.add("New View Name: ")
        new_view_text = TextWdg("new_view")
        new_view_text.add_class("spt_new_view_text")
        new_view_wdg.add(new_view_text)
        new_view_wdg.add(HtmlElement.br(2))

        #new_view_button = ProdIconButtonWdg('Save New View')
        new_view_button = ActionButtonWdg(title='Save', tip='Save New View')
        new_view_button.add_style("float: left")
        new_view_wdg.add(new_view_button)
        new_view_button.add_behavior( {
            'type': 'click_up',
            'search_type': my.search_type,
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_view_manager_top");
            var new_view_wdg = bvr.src_el.getParent(".spt_new_view");
            var new_view_text = new_view_wdg.getElement(".spt_new_view_text");
            var view = new_view_text.value;
            if (view != '') {
                var server = TacticServerStub.get()
                server.update_config(bvr.search_type, view, []);
                var values = {
                    search_type: bvr.search_type,
                    view: view
                };
                spt.panel.refresh(top, values);
                spt.hide(new_view_wdg);
            }
            else {
                alert("Must supply view name");
            }

            '''
        } )
        #new_view_cancel_button = ProdIconButtonWdg('Cancel')
        new_view_cancel_button = ActionButtonWdg(title='Cancel', tip='Cancel Save')
        new_view_cancel_button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var new_view_wdg = bvr.src_el.getParent(".spt_new_view");
            spt.hide(new_view_wdg);
            '''
        } )
        new_view_wdg.add(new_view_cancel_button)
        top.add(new_view_wdg)


        #TODO: to be implemented.. no more xx please!
        """
        # Save to Project View
        menu_item = MenuItem(type='action', label='xx Save to Project View')
        behavior = {
        'options': {
            'search_type': 'SideBarWdg',
            'view':        'project_view'
        },
        'cbjs_action': '''
        spt.panel.load_popup('SideBar Section', 'tactic.ui.manager.SideBarSectionWdg', bvr.options);
        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)
        """

        # Create a new view
        menu_item = MenuItem(type='action', label='Create New View')
        behavior = {
        'search_type': my.search_type,
        'view':       my.view,
        'cbjs_action': '''
        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_view_manager_top");
        var new_view_wdg = top.getElement(".spt_new_view");
        spt.show(new_view_wdg);

        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)


        # Clear the current view
        menu_item = MenuItem(type='action', label='Clear View')
        behavior = {
        'options': {
          'is_insert': 'true',
          'search_type': my.search_type,
          'view':       my.view
        },
        'cbjs_action': '''
        if (confirm("Are you sure you wih to clear this view?")) {
            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_view_manager_top");
            var list_top = top.getElement(".spt_menu_item_list");
            var elements = spt.side_bar.get_elements(bvr.view,list_top);
            for (var i=0; i<elements.length; i++) {
                var element = elements[i];
                if (element.hasClass("spt_side_bar_dummy")) {
                    continue;
                }
                element.destroy();

            }
        }
        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)



        gear_menu = GearMenuWdg()
        gear_menu.add(menu)

        top.add(gear_menu)
        return top
Esempio n. 17
0
    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
Esempio n. 18
0
    def get_display(my):

        my.search_key = my.kwargs.get("search_key")
        my.process = my.kwargs.get("process")
        my.sobject = Search.get_by_search_key(my.search_key)
        my.pipeline_code = my.kwargs.get("pipeline_code")

        top = DivWdg()
        top.add_class("spt_file_selector")
        top.add_style("position: relative")


        hidden = HiddenWdg("mode")
        #hidden = TextWdg("mode")
        hidden.add_class("spt_mode")
        top.add(hidden)



        top.add_style("padding: 5px")
        top.add_style("min-width: 500px")
        top.add_style("min-height: 400px")
        top.add_color("background", "background")
        top.add_color("color", "color")
        #top.add_border()


        logo_wdg = DivWdg()
        logo = HtmlElement.img(src="/context/icons/logo/perforce_logo.gif")
        logo_wdg.add(logo)
        top.add(logo_wdg)
        logo_wdg.add_style("opacity: 0.2")
        logo_wdg.add_style("position: absolute")
        logo_wdg.add_style("bottom: 0px")
        logo_wdg.add_style("right: 5px")



        # get some info from the config file
        """
        client_env_var = Config.get_value("perforce", "client_env_var")
        if not client_env_var:
            client_env_var = "P4Client"
        port_env_var = Config.get_value("perforce", "port_env_var")
        if not port_env_var:
            port_env_var = "P4Port"
        user_env_var = Config.get_value("perforce", "user_env_var")
        if not user_env_var:
            user_env_var = "P4User"
        password_env_var = Config.get_value("perforce", "password_env_var")
        if not password_env_var:
            password_env_var = "P4Passwd"
        """

        # {GET(sthpw/login)}_user
        host = ""
        client = ""
        user = ""
        password = ""
        port = ""

        project = my.sobject.get_project()
        depot = project.get_value("location", no_exception=True)
        if not depot:
            depot = ""


        top.add_behavior( {
            'type': 'load',
            #'client_env_var': client_env_var,
            #'port_env_var': port_env_var,
            #'user_env_var': user_env_var,
            #'password_env_var': password_env_var,
            'client': client,
            'user': user,
            'password': password,
            'host': host,
            'port': port,
            'depot': depot,
            'cbjs_action': get_onload_js()
        } )


        list_wdg = DivWdg()
        top.add(list_wdg)
        list_wdg.add_style("height: 32px")

        from tactic.ui.widget import SingleButtonWdg, ButtonNewWdg, ButtonRowWdg

        button_row = ButtonRowWdg()
        list_wdg.add(button_row)
        button_row.add_style("float: left")

        button = ButtonNewWdg(title="Refresh", icon=IconWdg.REFRESH, long=False)
        button_row.add(button)
        button.add_style("float: left")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.app_busy.show("Reading file system ...")
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.panel.refresh(top);
        spt.app_busy.hide();
        '''
        } )



        button = ButtonNewWdg(title="Check-out", icon=IconWdg.CHECK_OUT, long=False)
        button_row.add(button)

        my.sandbox_dir = my.kwargs.get("sandbox_dir")



        # what are we trying to do here???
        #my.root_sandbox_dir = Environment.get_sandbox_dir()
        #project = my.sobject.get_project()
        #my.root_sandbox_dir = "%s/%s" % (my.root_sandbox_dir, project.get_code())
        #repo_dir = my.sandbox_dir.replace("%s/" % my.root_sandbox_dir, "")
        #repo_dir = "%s/%s" % (project.get_code(), repo_dir)




        # checkout command requires either starting with //<depot>/ or just
        # the relative path to the root.  The following removes
        # the root of the sandbox folder assuming that this is mapped
        # to the base of the depot
        my.root_sandbox_dir = Environment.get_sandbox_dir()
        repo_dir = my.sandbox_dir
        repo_dir = my.sandbox_dir.replace("%s/" % my.root_sandbox_dir, "")



        #button.add_style("padding-right: 14px")
        button.add_style("float: left")
        button.add_behavior( {
        'type': 'click_up',
        'repo_dir': repo_dir,
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.app_busy.show("Reading file system ...")

        var data = spt.scm.checkout(bvr.repo_dir)
        spt.panel.refresh(top);

        spt.app_busy.hide();
        '''
        } )





        button = ButtonNewWdg(title="Perforce Actions", icon=IconWdg.PERFORCE, show_arrow=True)
        #button.set_show_arrow_menu(True)
        button_row.add(button)

        menu = Menu(width=220)
        menu_item = MenuItem(type='title', label='Perforce')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Show Workspaces')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = 'tactic.ui.checkin.WorkspaceWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");

            var el = top.getElement(".spt_mode");
            el.value = "workspace";

            var kwargs = {};
            spt.panel.load(content, class_name, kwargs);
            '''
        } )





        menu_item = MenuItem(type='action', label='Show Changelists')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = 'tactic.ui.checkin.ChangelistWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");

            var el = top.getElement(".spt_mode");
            el.value = "changelist";

            var kwargs = {};
            spt.panel.load(content, class_name, kwargs);
            '''
        } )



        menu_item = MenuItem(type='action', label='Show Branches')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = 'tactic.ui.checkin.branch_wdg.BranchWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");

            var el = top.getElement(".spt_mode");
            el.value = "branch";

            var kwargs = {};
            spt.panel.load(content, class_name, kwargs);
            '''
        } )


        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Add New Changelist')
        menu.add(menu_item)

        menu_item.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            spt.scm.run("add_changelist", ["New Changelist"]);

            var class_name = 'tactic.ui.checkin.ChangelistWdg';
            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");
            spt.panel.load(content, class_name);

            '''
        } )


        menu_item = MenuItem(type='separator')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Sign Out of Perforce')
        menu.add(menu_item)

        menu_item.add_behavior( {
            'type': 'load',
            'cbjs_action': '''

            if (!confirm("Are you sure you wish to sign out of Perforce?")) {
                return;
            }
            spt.scm.host = null;
            spt.scm.user = null;
            spt.scm.password = null;

            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);


            '''
        } )



 
        #SmartMenu.add_smart_menu_set( button.get_arrow_wdg(), { 'BUTTON_MENU': menu } )
        #SmartMenu.assign_as_local_activator( button.get_arrow_wdg(), "BUTTON_MENU", True )

        SmartMenu.add_smart_menu_set( button.get_button_wdg(), { 'BUTTON_MENU': menu } )
        SmartMenu.assign_as_local_activator( button.get_button_wdg(), "BUTTON_MENU", True )




        # Perforce script editor. (nice because it should run as the user
        # in the appopriate environment
        """
        button = ButtonNewWdg(title="P4 Script Editor", icon=IconWdg.CREATE, show_arrow=True)
        #button_row.add(button)
        button.add_style("padding-right: 14px")
        button.add_style("float: left")
        """



        button = ButtonNewWdg(title="Changelists Counter", icon=IconWdg.CHECK_OUT_SM, show_arrow=True)
        #button_row.add(button)
        #button.add_style("padding-right: 14px")
        button.add_style("float: left")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
                // find any changelists that were missed
                var changelists = spt.scm.run("get_changelists", []);
                for (var i = 0; i < changelists.length; i++) {
                    var changelist = changelists[i];
                    var info = spt.scm.run("get_changelist_info",[changelist.change]);
                    console.log(info);
                }
                '''
            } )



        # Hiding this for now

        button = ButtonNewWdg(title="Create", icon=IconWdg.NEW, show_arrow=True)
        #button_row.add(button)
        button.add_style("padding-right: 14px")
        button.add_style("float: left")

        menu = Menu(width=220)
        menu_item = MenuItem(type='title', label='New ...')
        menu.add(menu_item)


        menu_item = MenuItem(type='action', label='Text File')
        menu.add(menu_item)
        menu_item.add_behavior( {
        'type': 'click_up',
        'sandbox_dir': my.sandbox_dir,
        'cbjs_action': '''
        var path = bvr.sandbox_dir + "/" + "new_text_file.txt";
        var env = spt.Environment.get();
        var url = env.get_server_url() + "/context/VERSION_API";
        var applet = spt.Applet.get();
        applet.download_file(url, path);

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);

        '''
        } )


        #create_sobj = SObject.create("sthpw/virtual")
        #create_sobj.set_value("title", "Maya Project")
        #create_sobj.set_value("script_path", "create/maya_project")


        script_path = 'create/maya_project'
        menu_item = MenuItem(type='action', label='Maya Project')
        menu.add(menu_item)
        menu_item.add_behavior( {
        'type': 'click_up',
        'sandbox_dir': my.sandbox_dir,
        'process': my.process,
        'script_path': script_path,
        'cbjs_action': '''
        var script = spt.CustomProject.get_script_by_path(bvr.script_path);
        var options = {};
        options.script = script;

        // add some data to options
        options.sandbox_dir = bvr.sandbox_dir;
        options.process = bvr.process;
        spt.CustomProject.exec_custom_script({}, options);

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);
        '''
        } )


        template_path = '/context/template/maya_project.zip'
        menu_item = MenuItem(type='action', label='Zipped Template')
        menu.add(menu_item)
        menu_item.add_behavior( {
        'type': 'click_up',
        'sandbox_dir': my.sandbox_dir,
        'template_path': template_path,
        'cbjs_action': '''
        var path = bvr.sandbox_dir + "/" + "_template.zip";
        var env = spt.Environment.get();
        var url = env.get_server_url() + bvr.template_path;
        var applet = spt.Applet.get();
        applet.download_file(url, path);
        applet.unzip_file(path, bvr.sandbox_dir);
        applet.rmtree(path);

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);

        '''
        } )



        SmartMenu.add_smart_menu_set( button, { 'BUTTON_MENU': menu } )
        SmartMenu.assign_as_local_activator( button, "BUTTON_MENU", True )



        # Browse button for browsing files and dirs directly
        """
        browse_div = DivWdg()
        list_wdg.add(browse_div)
        browse_div.add_style("float: left")

        button = ActionButtonWdg(title="Browse", tip="Select Files or Folder to Check-In")
        browse_div.add(button)

        behavior = {
        'type': 'click_up',
        'base_dir': my.sandbox_dir,
        'cbjs_action': '''
            var current_dir = bvr.base_dir;
            var is_sandbox = false;
            spt.checkin.browse_folder(current_dir, is_sandbox);
        '''
        }
        button.add_behavior( behavior )
        """

        from tactic.ui.widget import SandboxButtonWdg, CheckoutButtonWdg, ExploreButtonWdg, GearMenuButtonWdg

        button_row = ButtonRowWdg()
        list_wdg.add(button_row)
        button_row.add_style("float: right")

        #button = SandboxButtonWdg(base_dir=my.sandbox_dir, process=my.process)
        #button_row.add(button)

        #button = CheckoutButtonWdg(base_dir=my.sandbox_dir, sobject=my.sobject, proces=my.process)
        #button_row.add(button)

        button = ExploreButtonWdg(base_dir=my.sandbox_dir)
        button_row.add(button)

        button = GearMenuButtonWdg(base_dir=my.sandbox_dir, process=my.process, pipeline_code=my.pipeline_code)
        button_row.add(button)



        list_wdg.add("<br clear='all'/>")

        top.add("<hr/>")

        content_div = DivWdg()
        top.add(content_div)
        content_div.add_class("spt_checkin_content")

        content = my.get_content_wdg()
        content_div.add(content)

        return top
Esempio n. 19
0
    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
Esempio n. 20
0
    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
Esempio n. 21
0
    def add_top_behaviors(self, top):

        # convert this to a repo directory
        asset_dir = Environment.get_asset_dir()
        web_dir = Environment.get_web_dir()

        web = WebContainer.get_web()
        browser = web.get_browser()
        use_applet = web.use_applet()

        if browser == 'Qt':
            top.add_relay_behavior({
                'type':
                'dblclick',
                'bvr_match_class':
                'spt_dir_list_item',
                'cbjs_action':
                '''
            var path = bvr.src_el.getAttribute("spt_path");
            var asset_dir = '%s';
            var web_dir = '%s';
            var relative_dir = path.replace(asset_dir, "");
            var url = web_dir + "/" + relative_dir;

            var url_parts = url.split("/");
            var file = url_parts.pop();
            file = encodeURIComponent(file);
            url_parts.push(file);
            url = url_parts.join("/");

            var class_name = 'tactic.ui.widget.EmbedWdg';
            var kwargs = {
                src: url
            }

            var parts = path.split("/");
            var filename = parts[parts.length-1];
            spt.tab.set_main_body_tab()
            spt.tab.add_new(filename, filename, class_name, kwargs);
            ''' % (asset_dir, web_dir)
            })
        else:
            top.add_relay_behavior({
                'type':
                'dblclick',
                'bvr_match_class':
                'spt_dir_list_item',
                'cbjs_action':
                '''
            var path = bvr.src_el.getAttribute("spt_path");
            if (path.indexOf('####') != -1) {
                spt.info('Cannot open the file sequence');
            } else {
                var asset_dir = '%s';
                var web_dir = '%s';
                var relative_dir = path.replace(asset_dir, "");
                var url = web_dir + "/" + relative_dir;

                // Encode the filename
                var url_parts = url.split("/");
                var filename = url_parts.pop();
                filename = encodeURIComponent(filename);
                url_parts.push(filename);
                url = url_parts.join("/");

                window.open(url);
            }
            ''' % (asset_dir, web_dir)
            })

        if use_applet:
            # add a top menu
            menu = Menu(width=180)
            menu_item = MenuItem(type='title', label='Actions')
            menu.add(menu_item)

            menu_item = MenuItem(type='action', label='Download to Folder')
            menu.add(menu_item)
            menu_item.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                var activator = spt.smenu.get_activator(bvr);
                var applet = spt.Applet.get();
                var select_dir = true;
                var dir = applet.open_file_browser('', select_dir);
                if (!dir) {
                    dir = applet.get_current_dir();
                }
                if (!dir) {
                    spt.alert("No folder selected to copy to");
                    return;
                }
                
                var path = activator.getAttribute("spt_path");

                var asset_dir = '%s';
                var env = spt.Environment.get();
                var server_url = env.get_server_url();
                var url = server_url + "/assets/" + path.replace(asset_dir, "");
                var parts = path.split("/");
                var filename = parts[parts.length-1];
                spt.app_busy.show("Downloading file", filename);
                applet.download_file(url, dir + "/" + filename);
                spt.app_busy.hide();
                if (dir)
                    spt.notify.show_message("Download to '" + dir + "' completed.")
                ''' % asset_dir
            })
            #menu_item = MenuItem(type='action', label='Check-out To Sandbox')
            #menu.add(menu_item)
            #menu_item.add_behavior( {
            #'type': 'click_up',
            #'cbjs_action': '''spt.alert('Not implemented yet.')'''
            #} )
            menu_item = MenuItem(type='action', label='Copy to Clipboard')
            menu.add(menu_item)
            menu_item.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var search_key = activator.getAttribute("spt_file_search_key");

            var server = TacticServerStub.get();
            var class_name = 'tactic.command.clipboard_cmd.ClipboardCopyCmd';
            var search_keys = [search_key];
            var kwargs = {
                search_keys: search_keys
            }
            try {
                spt.app_busy.show("Copy to Clipboard ...");
                server.execute_cmd(class_name, kwargs);
                spt.app_busy.hide();
                }
            catch(e) {
                spt.alert(spt.exception.handler(e));
            }
            '''
            })

            menu_item = MenuItem(type='action', label='View Metadata')
            menu.add(menu_item)
            menu_item.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var search_key = activator.getAttribute("spt_file_search_key");

            var server = TacticServerStub.get();
            var class_name = 'tactic.ui.checkin.SnapshotMetadataWdg';
            var kwargs = {
                search_key: search_key
            }
            spt.panel.load_popup("Metadata", class_name, kwargs);
            '''
            })

            menus_in = {
                'FILE_MENU_CTX': menu,
            }
            SmartMenu.attach_smart_context_menu(top, menus_in, False)

        self.add_selection(top)

        super(SnapshotDirListWdg, self).add_top_behaviors(top)
Esempio n. 22
0
    def add_base_dir_behaviors(self, div, base_dir):

        # add tooltip
        if self.use_applet:
            div.add_attr(
                'title',
                'This is the sandbox folder. Double-click to open and right-click for more options.'
            )
        # add a top menu
        menu = Menu(width=180)
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Explore sandbox folder')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'base_dir':
            base_dir,
            'cbjs_action':
            '''
            var applet = spt.Applet.get();
            var activator = spt.smenu.get_activator(bvr);
            var path = bvr.base_dir;
            if (applet)
                applet.open_file(path);
            '''
        })

        menu_item = MenuItem(type='action', label='Browse for sandbox folder')
        menu.add(menu_item)
        # FIXME: this code is identical to the one in checkin_wdg.py
        menu_item.add_behavior({
            'type':
            'click_up',
            'base_dir':
            base_dir,
            'cbjs_action':
            '''
            var current_dir = bvr.base_dir;
            var applet = spt.Applet.get();
            if (!applet) return;

            var file_paths = applet.open_file_browser(current_dir);

            // take the first one make sure it is a directory
            var dir = file_paths[0];
            if (!applet.is_dir(dir)) {
                spt.alert("Please Select a Folder");
                return;
            }
            dir = dir.replace(/\\\\/g, "/");

            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_checkin_top");
            top.setAttribute("spt_sandbox_dir", dir);
            spt.panel.refresh(top);

        '''
        })

        menu_item = MenuItem(type='action', label='Download from clipboard')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'base_dir':
            base_dir,
            'cbjs_action':
            '''
        var current_dir = bvr.base_dir;
        var server = TacticServerStub.get();
        var base = spt.Environment.get().get_server_url();
        var user = spt.Environment.get().get_user();

        var expr = "@SOBJECT(sthpw/clipboard['login','"+user+"'].sthpw/file)";
        var items = server.eval(expr);

        var applet = spt.Applet.get();
        if (!applet) return;

        var urls = [];
        for (var i = 0; i < items.length; i++) {
            var url = base + "/assets/" + items[i].relative_dir + "/" + items[i].file_name;
            var file_name = items[i].file_name;
            applet.download_file(url, current_dir + "/" + file_name);
        }

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);

        '''
        })

        menus_in = {
            'SANDBOX_MENU_CTX': menu,
        }
        SmartMenu.attach_smart_context_menu(div, menus_in, False)
        SmartMenu.assign_as_local_activator(div, 'SANDBOX_MENU_CTX')

        super(CheckinDirListWdg, self).add_base_dir_behaviors(div, base_dir)
Esempio n. 23
0
    def get_menu(my):
        menu = Menu(width=180)
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)


        menu_item = MenuItem(type='action', label='View')
        menu_item.add_behavior( {
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var kwargs = report_top.kwargs;
            var class_name = report_top.class_name;
            var element_name = report_top.element_name;

            spt.tab.set_main_body_tab();
            spt.tab.add_new(element_name, element_name, class_name, kwargs);
            '''
        } )
        menu.add(menu_item)



        menu_item = MenuItem(type='action', label='Show Definition')
        menu_item.add_behavior( {
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var xml = report_top.xml;
            console.log(xml);
            alert(xml);
            '''
        } )
        menu.add(menu_item)


        menu_item = MenuItem(type='separator')
        menu.add(menu_item)


        menu_item = MenuItem(type='action', label='Add to Side Bar')
        menu_item.add_behavior( {
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_tab_top");
            spt.tab.top = top;

            var header = activator;
            var title = header.getAttribute("spt_title");

            var report_top = activator.getParent(".spt_report_top");
            var kwargs = report_top.kwargs;
            var class_name = report_top.class_name;
            var element_name = report_top.element_name;

            var element_name = element_name.replace(/ /g, "_");
            element_name = element_name.replace(/\//g, "_");

            var kwargs = {
                class_name: 'LinkWdg',
                display_options: kwargs,
                element_attrs: {
                    title: title
                }
            }

            try {
                spt.app_busy.show("Adding Side Bar Link ["+element_name+"]");
                var server = TacticServerStub.get();
                server.start({description:"Added Side Bar Link ["+element_name+"]"});
                var info = server.add_config_element("SideBarWdg", "definition", element_name, kwargs);
                var info = server.add_config_element("SideBarWdg", "project_view", element_name, {});

                server.finish();
                spt.panel.refresh("side_bar");
                spt.app_busy.hide();
            }
            catch(e) {
                server.abort();
                alert(e);
                spt.app_busy.hide();
                throw(e);
            }

            '''
        } )
        menu.add(menu_item)

        return menu
Esempio n. 24
0
    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
Esempio n. 25
0
    def add_top_behaviors(my, top):
        if my.sobject:
            search_key = my.sobject.get_search_key()
        else:
            search_key = None

        bg_color = top.get_color("background")
        hilight_color = top.get_color("background", -20)

        top.add_behavior({
            'type': 'smart_click_up',
            'bvr_match_class': 'spt_dir_list_item',
            'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);

        var applet = spt.Applet.get();

        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        if (applet.is_dir(path)) {
            checkin_type.value = "dir_checkin";
        }
        else {
            checkin_type.value = "file_checkin";
        }

        ''' % {
                'bg_color': bg_color,
                'hilight_color': hilight_color
            }
        })

        top.add_behavior({
            'type': 'smart_click_up',
            'bvr_match_class': 'spt_dir_list_item',
            'modkeys': 'CTRL',
            'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        //spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);

        var applet = spt.Applet.get();

        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        if (applet.is_dir(path)) {
            checkin_type.value = "dir_checkin";
        }
        else {
            checkin_type.value = "file_checkin";
        }

        ''' % {
                'bg_color': bg_color,
                'hilight_color': hilight_color
            }
        })

        top.add_behavior({
            'type': 'load',
            'cbjs_action': '''

//for shift click feature
spt.checkin_list = {};
spt.checkin_list.top = null;
spt.checkin_list.last_selected = null;
spt.checkin_list.single_select = false;

spt.checkin_list.set_top = function(top) {
    spt.checkin_list.top = top;
}



spt.checkin_list.get_selected_paths = function() {
    // find the subcontext widget
    var rows = spt.checkin_list.get_all_rows();

    var paths = [];
    for (var i = 0; i < rows.length; i++) {
        var row = rows[i];
        if (row.is_selected == true) {
            var path = row.getAttribute("spt_path");
            paths.push(path);
        }
    }
    return paths;
} 


spt.checkin_list.get_all_rows = function() {
    var rows = spt.checkin_list.top.getElements(".spt_dir_list_item");
    return rows;
}

spt.checkin_list.unselect_all_rows = function() {

    var rows = spt.checkin_list.get_all_rows();
    for (var i = 0; i < rows.length; i++) {
        spt.checkin_list.unselect(rows[i]);
    }

}


spt.checkin_list.unselect = function(row) {
    var subcontext_el = row.getElement(".spt_subcontext");
    var context_el = row.getElement(".spt_context")
    row.is_selected = false;
    row.setStyle("background", '%(bg_color)s');
    row.setAttribute("spt_background", '%(bg_color)s');
    if (subcontext_el)
        subcontext_el.setStyle("display", "none");
    else if (context_el)
        context_el.setStyle("display", "none");

    spt.checkin_list.last_selected = null;

    spt.checkin_list.disable_checkin();
}



spt.checkin_list.select = function(row) {
    // find the subcontext widget
    var subcontext_el = row.getElement(".spt_subcontext")
    var context_el = row.getElement(".spt_context")

    if (row.is_selected == true) {
        row.is_selected = false;
        row.setStyle("background", '%(bg_color)s');
        row.setAttribute("spt_background", '%(bg_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "none");
        else if (context_el)
            context_el.setStyle("display", "none");

        spt.checkin_list.last_selected = null;

    }
    else {
        row.is_selected = true;
        row.setStyle("background", '%(hilight_color)s');
        row.setAttribute("spt_background", '%(hilight_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "");
		else if (context_el)
            context_el.setStyle("display", "");
        
        spt.checkin_list.last_selected = row;
    }
    var top = spt.checkin_list.top; 
    var paths = [];
    var els = top.getElements(".spt_dir_list_item");
    for (var i = 0; i < els.length; i++) {
        if (els[i].is_selected) {
            paths.push( els[i].getAttribute("spt_path") );
        }
    }

    var grey_el = top.getElement(".spt_publish_disable");
    if (paths.length == 0) {
        grey_el.setStyle("display", "");
        return;
    }

    grey_el.setStyle("display", "none");
}


spt.checkin_list.enable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "none");
} 


spt.checkin_list.disable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "");
} 





spt.checkin_list.select_preselected = function(){
    var top = spt.checkin_list.top; 
    var el = top.getElement(".spt_file_selector");
    if (el == null) {
        return;
    }

    var rows = spt.checkin_list.get_all_rows()
    //var cbs = top.getElements(".spt_dir_list_item");
    var paths = [];
    for (var k=0; k<rows.length; k++){
        var row = rows[k];
        if (spt.has_class(row, 'spt_preselected')) {
            var path = row.getAttribute("spt_path");
            paths.push(path); 
            spt.checkin_list.select(row);
        }
    }
    // reassign the new paths selection
    el.file_paths = paths;
}


var top = bvr.src_el.getParent(".spt_checkin_top");
spt.checkin_list.set_top(top);
spt.checkin_list.select_preselected();


        ''' % {
                'bg_color': bg_color,
                'hilight_color': hilight_color
            }
        })

        top.add_behavior({
            'type':
            'smart_click_up',
            'modkeys':
            'SHIFT',
            'bvr_match_class':
            'spt_dir_list_item',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_checkin_top");

        spt.checkin_list.set_top(top);

        var rows = spt.checkin_list.get_all_rows();

        var last_selected = spt.checkin_list.last_selected;
        var last_index;
        var cur_index;
        for (var i = 0; i < rows.length; i++) {
            if (rows[i] == last_selected) {
                last_index = i;
            }
            if (rows[i] == bvr.src_el) {
                cur_index = i;
            }
        }
        var start_index;
        var end_index;
        if (last_index < cur_index) {
            start_index = last_index + 1;
            end_index = cur_index ;
        }
        else {
            start_index = cur_index;
            end_index = last_index -1 ;
        }

        for (var i = start_index; i < end_index+1; i++) {
            spt.checkin_list.select(rows[i]);
        }

        spt.checkin_list.last_selected = bvr.src_el;
        '''
        })

        # add a top menu
        menu = Menu(width=180)
        my.menu = menu
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)

        #menu_item = MenuItem(type='action', label='Revert to Latest')
        #menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Open File')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            applet.open_file(path);
            '''
        })

        menu_item = MenuItem(type='action', label='Open Containing Folder')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            parts.pop()
            path = parts.join("/");
            applet.open_explorer(path);
            '''
        })

        menu_item = MenuItem(type='action', label='Copy File to Sandbox')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var selected_paths = spt.checkin_list.get_selected_paths();
            if (!selected_paths.length) {
                selected_paths = [path];
            }

            var top = activator.getParent(".spt_checkin_top");
            var default_sandbox_dir = top.getAttribute("spt_default_sandbox_dir");

            spt.app_busy.show("Copying files to Sandbox");
            for (var i = 0; i < selected_paths.length; i++) {
                var path = selected_paths[i];
                var parts = path.split("/");
                var filename = parts[parts.length-1];
                applet.copy_file(path, default_sandbox_dir + "/" + filename);
            }
            spt.app_busy.hide();

            spt.notify.show_message("Copied " + selected_paths.length + " files to sandbox");
            '''
        })

        #menu_item = MenuItem(type='action', label='Rename File')
        #menu.add(menu_item)

        # DISABLING until we actually have something that works better
        menu_item = MenuItem(type='action', label='Copy File')
        #menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var applet = spt.Applet.get();

            var parts = path.split("/");
            var basename = parts[parts.length-1];

            // FIXME: new to create new path
            var new_path = path + "_copy";
            var index = 1;
            while(1) {
                if (applet.exists(new_path)) {
                    new_path = path + "_copy" + index;
                    index += 1;
                }
                else {
                    break;
                }

                if (index > 100) {
                    spt.alert("More than 100 copies.  Exiting");
                    break;
                }
            }

            applet.copy_file(path, new_path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        })

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Delete File')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            var filename = parts[parts.length-1];

            var applet = spt.Applet.get();
            var label = applet.is_dir(path) ? 'directory': 'file';
            if (!confirm("Are you sure you wish to delete the local " + label + " ["+filename+"]?")) {
                return;
            }

            applet.rmtree(path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        })

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Properties')
        menu.add(menu_item)

        menu_item.add_behavior({
            'type':
            'click_up',
            'search_key':
            search_key,
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);

            var snapshot_code = activator.getAttribute("spt_snapshot_code");
            var path = activator.getAttribute("spt_path");
            var md5 = activator.getAttribute("spt_md5");

            var applet = spt.Applet.get();
            var cur_md5 = applet.get_md5(path);

            //if (md5 != cur_md5) {
            //    activator.setStyle("background", "#A77");
            //}


            var class_name = 'tactic.ui.checkin.FilePropertiesWdg';
            var kwargs = {
                path: path,
                md5: cur_md5,
                snapshot_code: snapshot_code,
                search_key: bvr.search_key
            };
            spt.panel.load_popup("File Properties", class_name, kwargs);
            '''
        })

        menu_item = MenuItem(type='action', label='Check in Preview Image')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'search_key':
            search_key,
            'cbjs_action':
            '''
            var server = TacticServerStub.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var context = "icon";
            server.simple_checkin( bvr.search_key, context, path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        })

        menus_in = {
            'FILE_MENU_CTX': menu,
        }
        SmartMenu.attach_smart_context_menu(top, menus_in, False)

        super(CheckinDirListWdg, my).add_top_behaviors(top)
Esempio n. 26
0
    def add_top_behaviors(self, top):
        if self.sobject:
            search_key = self.sobject.get_search_key()
        else:
            search_key = None

        bg_color = top.get_color("background")
        hilight_color = top.get_color("background", -20)

        top.add_behavior({
            'type': 'smart_click_up',
            'use_applet': self.use_applet,
            'bvr_match_class': 'spt_dir_list_item',
            'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);


        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        // try to disable applet

        if (bvr.use_applet) {
            var applet = spt.Applet.get();
            if (applet.is_dir(path)) {
                checkin_type.value = "dir_checkin";
            }
            else {
                checkin_type.value = "file_checkin";
            }
        }
        else
            checkin_type.value = "file_checkin";

        ''' % {
                'bg_color': bg_color,
                'hilight_color': hilight_color
            }
        })
        """
        top.add_behavior( {
        'type': 'smart_click_up',
        'bvr_match_class': 'spt_dir_list_item',
        'modkeys': 'CTRL',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        //spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);

        var applet = spt.Applet.get();

        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        if (applet.is_dir(path)) {
            checkin_type.value = "dir_checkin";
        }
        else {
            checkin_type.value = "file_checkin";
        }

        ''' %{'bg_color': bg_color, 'hilight_color': hilight_color}
        } )


        """
        top.add_behavior({
            'type': 'load',
            'cbjs_action': '''

//for shift click feature
spt.checkin_list = {};
spt.checkin_list.top = null;
spt.checkin_list.last_selected = null;
spt.checkin_list.single_select = false;

spt.checkin_list.set_top = function(top) {
    spt.checkin_list.top = top;
}



spt.checkin_list.get_selected_paths = function() {
    // find the subcontext widget
    var rows = spt.checkin_list.get_all_rows();

    var paths = [];
    for (var i = 0; i < rows.length; i++) {
        var row = rows[i];
        if (row.is_selected == true) {
            var path = row.getAttribute("spt_path");
            paths.push(path);
        }
    }
    return paths;
} 


spt.checkin_list.get_all_rows = function() {
    var rows = spt.checkin_list.top.getElements(".spt_dir_list_item");
    return rows;
}

spt.checkin_list.unselect_all_rows = function() {

    var rows = spt.checkin_list.get_all_rows();
    for (var i = 0; i < rows.length; i++) {
        spt.checkin_list.unselect(rows[i]);
    }

}


spt.checkin_list.unselect = function(row) {
    var subcontext_el = row.getElement(".spt_subcontext");
    var context_el = row.getElement(".spt_context")
    row.is_selected = false;
    row.setStyle("background", '%(bg_color)s');
    row.setAttribute("spt_background", '%(bg_color)s');
    if (subcontext_el)
        subcontext_el.setStyle("display", "none");
    else if (context_el)
        context_el.setStyle("display", "none");

    spt.checkin_list.last_selected = null;

    spt.checkin_list.disable_checkin();
}



spt.checkin_list.select = function(row) {
    // find the subcontext widget
    var subcontext_el = row.getElement(".spt_subcontext")
    var context_el = row.getElement(".spt_context")

    if (row.is_selected == true) {
        row.is_selected = false;
        row.setStyle("background", '%(bg_color)s');
        row.setAttribute("spt_background", '%(bg_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "none");
        else if (context_el)
            context_el.setStyle("display", "none");

        spt.checkin_list.last_selected = null;

    }
    else {
        row.is_selected = true;
        row.setStyle("background", '%(hilight_color)s');
        row.setAttribute("spt_background", '%(hilight_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "");
		else if (context_el)
            context_el.setStyle("display", "");
        
        spt.checkin_list.last_selected = row;
    }
    var top = spt.checkin_list.top; 
    var paths = [];
    var els = top.getElements(".spt_dir_list_item");
    for (var i = 0; i < els.length; i++) {
        if (els[i].is_selected) {
            paths.push( els[i].getAttribute("spt_path") );
        }
    }

    var grey_el = top.getElement(".spt_publish_disable");
    if (paths.length == 0) {
        grey_el.setStyle("display", "");
        return;
    }

    grey_el.setStyle("display", "none");
}


spt.checkin_list.enable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "none");
} 


spt.checkin_list.disable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "");
} 





spt.checkin_list.select_preselected = function(){
    var top = spt.checkin_list.top; 
    var el = top.getElement(".spt_file_selector");
    if (el == null) {
        return;
    }

    var rows = spt.checkin_list.get_all_rows()
    //var cbs = top.getElements(".spt_dir_list_item");
    var paths = [];
    for (var k=0; k<rows.length; k++){
        var row = rows[k];
        if (spt.has_class(row, 'spt_preselected')) {
            var path = row.getAttribute("spt_path");
            paths.push(path); 
            spt.checkin_list.select(row);
        }
    }
    // reassign the new paths selection
    el.file_paths = paths;
}

// can explicitly specify a context, description
// this is similar to spt.checkin.html5_checkin()
spt.checkin.html5_strict_checkin = function(files, context, description) {
    var server = TacticServerStub.get();

    var options = spt.checkin.get_checkin_data();
    var search_key = options.search_key;
    var process = options.process;
    if (!description)
    	description = options.description;

    var is_current = true;
    var checkin_type = 'file';
    var mode = 'uploaded';
    
    var top = spt.checkin_list.top;
    var progress = top.getElement(".spt_checkin_progress");
    progress.setStyle("display", "");

    var upload_complete = function() {

        try {
            if (bvr.validate_script_path){
                var script = spt.CustomProject.get_script_by_path(bvr.validate_script_path);
                bvr['script'] = script;
                spt.app_busy.show("Running Validation", bvr.validate_script_path);
                spt.CustomProject.exec_custom_script(evt, bvr);
            } 
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                var file_path = file.name;
                if (!context)
                    context = process + '/' + file.name;
                snapshot = server.simple_checkin(search_key, context, file_path, {description: description, mode: mode, is_current: is_current, checkin_type: checkin_type});
                spt.notify.show_message("Check-in of ["+ file.name +"] successful", 4000);
            }
            progress.setStyle("display", "");

        }
        catch(e) {
            progress.setStyle("background", "#F00");
            progress.setStyle("display", "none");
            alert(e);
            throw(e);
            
        }

    }

    var upload_progress = function(evt) {

        var percent = Math.round(evt.loaded * 100 / evt.total);
        //spt.app_busy.show("Uploading ["+percent+"%% complete]");
        progress.setStyle("width", percent + "%%");
    }

    var upload_kwargs = {
        upload_complete: upload_complete,
        upload_progress: upload_progress,
        files: files
    }
    spt.html5upload.upload_file(upload_kwargs);

}

var top = bvr.src_el.getParent(".spt_checkin_top");
spt.checkin_list.set_top(top);
spt.checkin_list.select_preselected();


        ''' % {
                'bg_color': bg_color,
                'hilight_color': hilight_color
            }
        })

        top.add_behavior({
            'type':
            'smart_click_up',
            'modkeys':
            'SHIFT',
            'bvr_match_class':
            'spt_dir_list_item',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_checkin_top");

        spt.checkin_list.set_top(top);

        var rows = spt.checkin_list.get_all_rows();

        var last_selected = spt.checkin_list.last_selected;
        var last_index;
        var cur_index;
        for (var i = 0; i < rows.length; i++) {
            if (rows[i] == last_selected) {
                last_index = i;
            }
            if (rows[i] == bvr.src_el) {
                cur_index = i;
            }
        }
        var start_index;
        var end_index;
        if (last_index < cur_index) {
            start_index = last_index + 1;
            end_index = cur_index ;
        }
        else {
            start_index = cur_index;
            end_index = last_index -1 ;
        }

        for (var i = start_index; i < end_index+1; i++) {
            spt.checkin_list.select(rows[i]);
        }

        spt.checkin_list.last_selected = bvr.src_el;
        '''
        })

        # add a top menu
        menu = Menu(width=180)
        self.menu = menu
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)

        #menu_item = MenuItem(type='action', label='Revert to Latest')
        #menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Open File')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            applet.open_file(path);
            '''
        })

        menu_item = MenuItem(type='action', label='Open Containing Folder')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            parts.pop()
            path = parts.join("/");
            applet.open_explorer(path);
            '''
        })

        menu_item = MenuItem(type='action', label='Copy File to Sandbox')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var selected_paths = spt.checkin_list.get_selected_paths();
            if (!selected_paths.length) {
                selected_paths = [path];
            }

            var top = activator.getParent(".spt_checkin_top");
            var default_sandbox_dir = top.getAttribute("spt_default_sandbox_dir");

            spt.app_busy.show("Copying files to Sandbox");
            for (var i = 0; i < selected_paths.length; i++) {
                var path = selected_paths[i];
                var parts = path.split("/");
                var filename = parts[parts.length-1];
                applet.copy_file(path, default_sandbox_dir + "/" + filename);
            }
            spt.app_busy.hide();

            spt.notify.show_message("Copied " + selected_paths.length + " files to sandbox");
            '''
        })

        #menu_item = MenuItem(type='action', label='Rename File')
        #menu.add(menu_item)

        # DISABLING until we actually have something that works better
        menu_item = MenuItem(type='action', label='Copy File')
        #menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var applet = spt.Applet.get();

            var parts = path.split("/");
            var basename = parts[parts.length-1];

            // FIXME: new to create new path
            var new_path = path + "_copy";
            var index = 1;
            while(1) {
                if (applet.exists(new_path)) {
                    new_path = path + "_copy" + index;
                    index += 1;
                }
                else {
                    break;
                }

                if (index > 100) {
                    spt.alert("More than 100 copies.  Exiting");
                    break;
                }
            }

            applet.copy_file(path, new_path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        })

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Delete File')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            var filename = parts[parts.length-1];

            var applet = spt.Applet.get();
            var label = applet.is_dir(path) ? 'directory': 'file';
            if (!confirm("Are you sure you wish to delete the local " + label + " ["+filename+"]?")) {
                return;
            }

            applet.rmtree(path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        })

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Properties')
        menu.add(menu_item)

        menu_item.add_behavior({
            'type':
            'click_up',
            'search_key':
            search_key,
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);

            var snapshot_code = activator.getAttribute("spt_snapshot_code");
            var path = activator.getAttribute("spt_path");
            var md5 = activator.getAttribute("spt_md5");

            var applet = spt.Applet.get();
            var cur_md5 = applet.get_md5(path);

            //if (md5 != cur_md5) {
            //    activator.setStyle("background", "#A77");
            //}


            var class_name = 'tactic.ui.checkin.FilePropertiesWdg';
            var kwargs = {
                path: path,
                md5: cur_md5,
                snapshot_code: snapshot_code,
                search_key: bvr.search_key
            };
            spt.panel.load_popup("File Properties", class_name, kwargs);
            '''
        })

        menu_item = MenuItem(type='action', label='Check in Preview Image')
        menu.add(menu_item)
        menu_item.add_behavior({
            'type':
            'click_up',
            'search_key':
            search_key,
            'cbjs_action':
            '''
            var server = TacticServerStub.get();

            var activator = spt.smenu.get_activator(bvr);

            var path = activator.getAttribute("spt_path");
            var tmps = path.split('/');
            var base_name = tmps[1];
            
            //server.simple_checkin( bvr.search_key, context, path);

            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");
            var files = content.files;
            var selected_file;

            //find selected file
            for (var k =0; k < files.length; k++){
                if (files[k].name == base_name) {
                    selected_file = files[k];
                    break;
                }
            }
            
            if (selected_file) {
                var context = "icon";
                spt.checkin.html5_strict_checkin(files, context, "Icon Check-in") 
                spt.panel.refresh(top);
                
            }
            else {
                spt.alert("Cannot determine chosen file. Please drag and drop to try again.");
            }
            '''
        })

        menus_in = {
            'FILE_MENU_CTX': menu,
        }
        SmartMenu.attach_smart_context_menu(top, menus_in, False)

        super(CheckinDirListWdg, self).add_top_behaviors(top)
Esempio n. 27
0
    def get_gear_menu(my):

        top = DivWdg()

        # FIXME: the gear menu widget should be here
        from tactic.ui.container import GearMenuWdg, Menu, MenuItem

        menu = Menu(width=180)

        menu_item = MenuItem(type="title", label="Actions")
        menu.add(menu_item)

        # create a new element
        menu_item = MenuItem(type="action", label="New Element")
        behavior = {
            "options": {"is_insert": "true", "search_type": my.search_type, "view": my.view},
            "cbjs_action": """

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_view_manager_top");
        var detail_panel = top.getElement(".spt_view_manager_detail");

        var class_name = 'tactic.ui.manager.ElementDefinitionWdg';
        var options = bvr.options
        var values = {};
        spt.panel.load(detail_panel, class_name, options, values, false);
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        menu_item = MenuItem(type="separator")
        menu.add(menu_item)

        # Show preview of the view
        menu_item = MenuItem(type="action", label="Show Preview")
        behavior = {
            "search_type": my.search_type,
            "view": my.view,
            "cbjs_action": """
        var kwargs = {
          search_type: bvr.search_type,
          view: bvr.view
        };
        var title = "Search Type: [" + bvr.search_type + "], View [" + bvr.view + "]";
        spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs);
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        # Show preview of the view
        menu_item = MenuItem(type="action", label="Show Full XML Config")
        behavior = {
            "search_type": my.search_type,
            "view": my.view,
            "cbjs_action": """
        var kwargs = {
          search_type: 'config/widget_config',
          view: 'table',
          expression: "@SOBJECT(config/widget_config['search_type','"+bvr.search_type+"']['view','"+bvr.view+"'])",
          filter: [{}]
        };
        var title = "Widget Config - ["+bvr.search_type+"] ["+bvr.view+"]";
        spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs);
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        menu_item = MenuItem(type="separator")
        menu.add(menu_item)

        # New view popup
        new_view_wdg = DivWdg()
        new_view_wdg.add_class("spt_new_view")
        new_view_wdg.add_style("display: none")
        new_view_wdg.add_style("position: absolute")
        new_view_wdg.add_color("background", "background")
        new_view_wdg.add_style("z-index: 100")
        new_view_wdg.add_border()
        new_view_wdg.set_round_corners()
        new_view_wdg.set_box_shadow()
        new_view_wdg.add_style("padding: 30px")
        new_view_wdg.add("New View Name: ")
        new_view_text = TextWdg("new_view")
        new_view_text.add_class("spt_new_view_text")
        new_view_wdg.add(new_view_text)
        new_view_wdg.add(HtmlElement.br(2))

        # new_view_button = ProdIconButtonWdg('Save New View')
        new_view_button = ActionButtonWdg(title="Save", tip="Save New View")
        new_view_button.add_style("float: left")
        new_view_wdg.add(new_view_button)
        new_view_button.add_behavior(
            {
                "type": "click_up",
                "search_type": my.search_type,
                "cbjs_action": """
            var top = bvr.src_el.getParent(".spt_view_manager_top");
            var new_view_wdg = bvr.src_el.getParent(".spt_new_view");
            var new_view_text = new_view_wdg.getElement(".spt_new_view_text");
            var view = new_view_text.value;
            if (view != '') {
                var server = TacticServerStub.get()
                server.update_config(bvr.search_type, view, []);
                var values = {
                    search_type: bvr.search_type,
                    view: view
                };
                spt.panel.refresh(top, values);
                spt.hide(new_view_wdg);
            }
            else {
                alert("Must supply view name");
            }

            """,
            }
        )
        # new_view_cancel_button = ProdIconButtonWdg('Cancel')
        new_view_cancel_button = ActionButtonWdg(title="Cancel", tip="Cancel Save")
        new_view_cancel_button.add_behavior(
            {
                "type": "click_up",
                "cbjs_action": """
            var new_view_wdg = bvr.src_el.getParent(".spt_new_view");
            spt.hide(new_view_wdg);
            """,
            }
        )
        new_view_wdg.add(new_view_cancel_button)
        top.add(new_view_wdg)

        # TODO: to be implemented.. no more xx please!
        """
        # Save to Project View
        menu_item = MenuItem(type='action', label='xx Save to Project View')
        behavior = {
        'options': {
            'search_type': 'SideBarWdg',
            'view':        'project_view'
        },
        'cbjs_action': '''
        spt.panel.load_popup('SideBar Section', 'tactic.ui.manager.SideBarSectionWdg', bvr.options);
        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)
        """

        # Create a new view
        menu_item = MenuItem(type="action", label="Create New View")
        behavior = {
            "search_type": my.search_type,
            "view": my.view,
            "cbjs_action": """
        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_view_manager_top");
        var new_view_wdg = top.getElement(".spt_new_view");
        spt.show(new_view_wdg);

        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        # Clear the current view
        menu_item = MenuItem(type="action", label="Clear View")
        behavior = {
            "options": {"is_insert": "true", "search_type": my.search_type, "view": my.view},
            "cbjs_action": """
        if (confirm("Are you sure you wih to clear this view?")) {
            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_view_manager_top");
            var list_top = top.getElement(".spt_menu_item_list");
            var elements = spt.side_bar.get_elements(bvr.view,list_top);
            for (var i=0; i<elements.length; i++) {
                var element = elements[i];
                if (element.hasClass("spt_side_bar_dummy")) {
                    continue;
                }
                element.destroy();

            }
        }
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        gear_menu = GearMenuWdg()
        gear_menu.add(menu)

        top.add(gear_menu)
        return top
Esempio n. 28
0
    def get_menu(self):
        menu = Menu(width=180)
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='View')
        menu_item.add_behavior({
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var kwargs = report_top.kwargs;
            var class_name = report_top.class_name;
            var element_name = report_top.element_name;

            spt.tab.set_main_body_tab();
            spt.tab.add_new(element_name, element_name, class_name, kwargs);
            '''
        })
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Show Definition')
        menu_item.add_behavior({
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var xml = report_top.xml;
            alert(xml);
            '''
        })
        menu.add(menu_item)

        menu_item = MenuItem(type='separator')
        menu.add(menu_item)

        widget_def = '''
<element name='index' palette="BLACK">
  <display class='tactic.ui.panel.CustomLayoutWdg'>
    <view>VIEW</view>
  </display>
</element>
        '''

        menu_item = MenuItem(type='action', label='Set as Project Theme')
        menu_item.add_behavior({
            'type':
            'click_up',
            'widget_def':
            widget_def,
            'cbjs_action':
            '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var kwargs = report_top.kwargs;
            var class_name = report_top.class_name;
            var element_name = report_top.element_name;
            var view = report_top.view;

            if (!confirm("Change theme to ["+view+"]?")) {
                return;
            }

            var widget_def = bvr.widget_def;
            widget_def = widget_def.replace(/VIEW/, view);

            var data = {
                url: '/index',
                description: 'Index Page',
                widget: widget_def
            }

            var server = TacticServerStub.get();
            var url = server.eval("@SOBJECT(config/url['url','/index'])", {single:true});
            if (url) {
                server.update(url, data);
            }
            else {
                server.insert('config/url', data);
            }

            '''
        })
        menu.add(menu_item)

        return menu
Esempio n. 29
0
    def get_menu(self):
        menu = Menu(width=180)
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)

        
        menu_item = MenuItem(type='action', label='View')
        menu_item.add_behavior( {
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var kwargs = report_top.kwargs;
            var class_name = report_top.class_name;
            var element_name = report_top.element_name;

            spt.tab.set_main_body_tab();
            spt.tab.add_new(element_name, element_name, class_name, kwargs);
            '''
        } )
        menu.add(menu_item)



        menu_item = MenuItem(type='action', label='Show Definition')
        menu_item.add_behavior( {
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var xml = report_top.xml;
            alert(xml);
            '''
        } )
        menu.add(menu_item)


        menu_item = MenuItem(type='separator')
        menu.add(menu_item)



        widget_def = '''
<element name='index' palette="BLACK">
  <display class='tactic.ui.panel.CustomLayoutWdg'>
    <view>VIEW</view>
  </display>
</element>
        '''


        menu_item = MenuItem(type='action', label='Set as Project Theme')
        menu_item.add_behavior( {
            'type': 'click_up',
            'widget_def': widget_def,
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var report_top = activator.getParent(".spt_report_top");
            var kwargs = report_top.kwargs;
            var class_name = report_top.class_name;
            var element_name = report_top.element_name;
            var view = report_top.view;

            if (!confirm("Change theme to ["+view+"]?")) {
                return;
            }

            var widget_def = bvr.widget_def;
            widget_def = widget_def.replace(/VIEW/, view);

            var data = {
                url: '/index',
                description: 'Index Page',
                widget: widget_def
            }

            var server = TacticServerStub.get();
            var url = server.eval("@SOBJECT(config/url['url','/index'])", {single:true});
            if (url) {
                server.update(url, data);
            }
            else {
                server.insert('config/url', data);
            }

            '''
        } )
        menu.add(menu_item)

        return menu
Esempio n. 30
0
    def add_top_behaviors(self, top):
        if self.sobject:
            search_key = self.sobject.get_search_key()
        else:
            search_key = None

        bg_color = top.get_color("background")
        hilight_color =  top.get_color("background", -20)

        top.add_behavior( {
        'type': 'smart_click_up',
        'use_applet': self.use_applet,
        'bvr_match_class': 'spt_dir_list_item',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);


        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        // try to disable applet

        if (bvr.use_applet) {
            var applet = spt.Applet.get();
            if (applet.is_dir(path)) {
                checkin_type.value = "dir_checkin";
            }
            else {
                checkin_type.value = "file_checkin";
            }
        }
        else
            checkin_type.value = "file_checkin";

        ''' %{'bg_color': bg_color, 'hilight_color': hilight_color}
        } )

        """
        top.add_behavior( {
        'type': 'smart_click_up',
        'bvr_match_class': 'spt_dir_list_item',
        'modkeys': 'CTRL',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        //spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);

        var applet = spt.Applet.get();

        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        if (applet.is_dir(path)) {
            checkin_type.value = "dir_checkin";
        }
        else {
            checkin_type.value = "file_checkin";
        }

        ''' %{'bg_color': bg_color, 'hilight_color': hilight_color}
        } )


        """
        top.add_behavior( {
        'type': 'load',
        'cbjs_action': '''

//for shift click feature
spt.checkin_list = {};
spt.checkin_list.top = null;
spt.checkin_list.last_selected = null;
spt.checkin_list.single_select = false;

spt.checkin_list.set_top = function(top) {
    spt.checkin_list.top = top;
}



spt.checkin_list.get_selected_paths = function() {
    // find the subcontext widget
    var rows = spt.checkin_list.get_all_rows();

    var paths = [];
    for (var i = 0; i < rows.length; i++) {
        var row = rows[i];
        if (row.is_selected == true) {
            var path = row.getAttribute("spt_path");
            paths.push(path);
        }
    }
    return paths;
} 


spt.checkin_list.get_all_rows = function() {
    var rows = spt.checkin_list.top.getElements(".spt_dir_list_item");
    return rows;
}

spt.checkin_list.unselect_all_rows = function() {

    var rows = spt.checkin_list.get_all_rows();
    for (var i = 0; i < rows.length; i++) {
        spt.checkin_list.unselect(rows[i]);
    }

}


spt.checkin_list.unselect = function(row) {
    var subcontext_el = row.getElement(".spt_subcontext");
    var context_el = row.getElement(".spt_context")
    row.is_selected = false;
    row.setStyle("background", '%(bg_color)s');
    row.setAttribute("spt_background", '%(bg_color)s');
    if (subcontext_el)
        subcontext_el.setStyle("display", "none");
    else if (context_el)
        context_el.setStyle("display", "none");

    spt.checkin_list.last_selected = null;

    spt.checkin_list.disable_checkin();
}



spt.checkin_list.select = function(row) {
    // find the subcontext widget
    var subcontext_el = row.getElement(".spt_subcontext")
    var context_el = row.getElement(".spt_context")

    if (row.is_selected == true) {
        row.is_selected = false;
        row.setStyle("background", '%(bg_color)s');
        row.setAttribute("spt_background", '%(bg_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "none");
        else if (context_el)
            context_el.setStyle("display", "none");

        spt.checkin_list.last_selected = null;

    }
    else {
        row.is_selected = true;
        row.setStyle("background", '%(hilight_color)s');
        row.setAttribute("spt_background", '%(hilight_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "");
		else if (context_el)
            context_el.setStyle("display", "");
        
        spt.checkin_list.last_selected = row;
    }
    var top = spt.checkin_list.top; 
    var paths = [];
    var els = top.getElements(".spt_dir_list_item");
    for (var i = 0; i < els.length; i++) {
        if (els[i].is_selected) {
            paths.push( els[i].getAttribute("spt_path") );
        }
    }

    var grey_el = top.getElement(".spt_publish_disable");
    if (paths.length == 0) {
        grey_el.setStyle("display", "");
        return;
    }

    grey_el.setStyle("display", "none");
}


spt.checkin_list.enable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "none");
} 


spt.checkin_list.disable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "");
} 





spt.checkin_list.select_preselected = function(){
    var top = spt.checkin_list.top; 
    var el = top.getElement(".spt_file_selector");
    if (el == null) {
        return;
    }

    var rows = spt.checkin_list.get_all_rows()
    //var cbs = top.getElements(".spt_dir_list_item");
    var paths = [];
    for (var k=0; k<rows.length; k++){
        var row = rows[k];
        if (spt.has_class(row, 'spt_preselected')) {
            var path = row.getAttribute("spt_path");
            paths.push(path); 
            spt.checkin_list.select(row);
        }
    }
    // reassign the new paths selection
    el.file_paths = paths;
}

// can explicitly specify a context, description
// this is similar to spt.checkin.html5_checkin()
spt.checkin.html5_strict_checkin = function(files, context, description) {
    var server = TacticServerStub.get();

    var options = spt.checkin.get_checkin_data();
    var search_key = options.search_key;
    var process = options.process;
    if (!description)
    	description = options.description;

    var is_current = true;
    var checkin_type = 'file';
    var mode = 'uploaded';
    
    var top = spt.checkin_list.top;
    var progress = top.getElement(".spt_checkin_progress");
    progress.setStyle("display", "");

    var upload_complete = function() {

        try {
            if (bvr.validate_script_path){
                var script = spt.CustomProject.get_script_by_path(bvr.validate_script_path);
                bvr['script'] = script;
                spt.app_busy.show("Running Validation", bvr.validate_script_path);
                spt.CustomProject.exec_custom_script(evt, bvr);
            } 
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                var file_path = file.name;
                if (!context)
                    context = process + '/' + file.name;
                snapshot = server.simple_checkin(search_key, context, file_path, {description: description, mode: mode, is_current: is_current, checkin_type: checkin_type});
                spt.notify.show_message("Check-in of ["+ file.name +"] successful", 4000);
            }
            progress.setStyle("display", "");

        }
        catch(e) {
            progress.setStyle("background", "#F00");
            progress.setStyle("display", "none");
            alert(e);
            throw(e);
            
        }

    }

    var upload_progress = function(evt) {

        var percent = Math.round(evt.loaded * 100 / evt.total);
        //spt.app_busy.show("Uploading ["+percent+"%% complete]");
        progress.setStyle("width", percent + "%%");
    }

    var upload_kwargs = {
        upload_complete: upload_complete,
        upload_progress: upload_progress,
        files: files
    }
    spt.html5upload.upload_file(upload_kwargs);

}

var top = bvr.src_el.getParent(".spt_checkin_top");
spt.checkin_list.set_top(top);
spt.checkin_list.select_preselected();


        ''' %{'bg_color': bg_color, 'hilight_color': hilight_color}
        } )
 

        top.add_behavior( {
        'type': 'smart_click_up',
        'modkeys': 'SHIFT',
        'bvr_match_class': 'spt_dir_list_item',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");

        spt.checkin_list.set_top(top);

        var rows = spt.checkin_list.get_all_rows();

        var last_selected = spt.checkin_list.last_selected;
        var last_index;
        var cur_index;
        for (var i = 0; i < rows.length; i++) {
            if (rows[i] == last_selected) {
                last_index = i;
            }
            if (rows[i] == bvr.src_el) {
                cur_index = i;
            }
        }
        var start_index;
        var end_index;
        if (last_index < cur_index) {
            start_index = last_index + 1;
            end_index = cur_index ;
        }
        else {
            start_index = cur_index;
            end_index = last_index -1 ;
        }

        for (var i = start_index; i < end_index+1; i++) {
            spt.checkin_list.select(rows[i]);
        }

        spt.checkin_list.last_selected = bvr.src_el;
        '''
        } )




        # add a top menu
        menu = Menu(width=180)
        self.menu = menu
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)


        #menu_item = MenuItem(type='action', label='Revert to Latest')
        #menu.add(menu_item)




        menu_item = MenuItem(type='action', label='Open File')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            applet.open_file(path);
            '''
        } )



        menu_item = MenuItem(type='action', label='Open Containing Folder')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            parts.pop()
            path = parts.join("/");
            applet.open_explorer(path);
            '''
        } )



        menu_item = MenuItem(type='action', label='Copy File to Sandbox')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var selected_paths = spt.checkin_list.get_selected_paths();
            if (!selected_paths.length) {
                selected_paths = [path];
            }

            var top = activator.getParent(".spt_checkin_top");
            var default_sandbox_dir = top.getAttribute("spt_default_sandbox_dir");

            spt.app_busy.show("Copying files to Sandbox");
            for (var i = 0; i < selected_paths.length; i++) {
                var path = selected_paths[i];
                var parts = path.split("/");
                var filename = parts[parts.length-1];
                applet.copy_file(path, default_sandbox_dir + "/" + filename);
            }
            spt.app_busy.hide();

            spt.notify.show_message("Copied " + selected_paths.length + " files to sandbox");
            '''
        } )


 


        #menu_item = MenuItem(type='action', label='Rename File')
        #menu.add(menu_item)

        # DISABLING until we actually have something that works better
        menu_item = MenuItem(type='action', label='Copy File')
        #menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var applet = spt.Applet.get();

            var parts = path.split("/");
            var basename = parts[parts.length-1];

            // FIXME: new to create new path
            var new_path = path + "_copy";
            var index = 1;
            while(1) {
                if (applet.exists(new_path)) {
                    new_path = path + "_copy" + index;
                    index += 1;
                }
                else {
                    break;
                }

                if (index > 100) {
                    spt.alert("More than 100 copies.  Exiting");
                    break;
                }
            }

            applet.copy_file(path, new_path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        } )



        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Delete File')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            var filename = parts[parts.length-1];

            var applet = spt.Applet.get();
            var label = applet.is_dir(path) ? 'directory': 'file';
            if (!confirm("Are you sure you wish to delete the local " + label + " ["+filename+"]?")) {
                return;
            }

            applet.rmtree(path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        } )


        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Properties')
        menu.add(menu_item)

        menu_item.add_behavior( {
            'type': 'click_up',
            'search_key': search_key,
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);

            var snapshot_code = activator.getAttribute("spt_snapshot_code");
            var path = activator.getAttribute("spt_path");
            var md5 = activator.getAttribute("spt_md5");

            var applet = spt.Applet.get();
            var cur_md5 = applet.get_md5(path);

            //if (md5 != cur_md5) {
            //    activator.setStyle("background", "#A77");
            //}


            var class_name = 'tactic.ui.checkin.FilePropertiesWdg';
            var kwargs = {
                path: path,
                md5: cur_md5,
                snapshot_code: snapshot_code,
                search_key: bvr.search_key
            };
            spt.panel.load_popup("File Properties", class_name, kwargs);
            '''
        } )


        menu_item = MenuItem(type='action', label='Check in Preview Image')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'search_key': search_key,
            'cbjs_action': '''
            var server = TacticServerStub.get();

            var activator = spt.smenu.get_activator(bvr);

            var path = activator.getAttribute("spt_path");
            var tmps = path.split('/');
            var base_name = tmps[1];
            
            //server.simple_checkin( bvr.search_key, context, path);

            var top = activator.getParent(".spt_checkin_top");
            var content = top.getElement(".spt_checkin_content");
            var files = content.files;
            var selected_file;

            //find selected file
            for (var k =0; k < files.length; k++){
                if (files[k].name == base_name) {
                    selected_file = files[k];
                    break;
                }
            }
            
            if (selected_file) {
                var context = "icon";
                spt.checkin.html5_strict_checkin(files, context, "Icon Check-in") 
                spt.panel.refresh(top);
                
            }
            else {
                spt.alert("Cannot determine chosen file. Please drag and drop to try again.");
            }
            '''
        } )

        menus_in = {
            'FILE_MENU_CTX': menu,
        }
        SmartMenu.attach_smart_context_menu( top, menus_in, False )
 
        super(CheckinDirListWdg, self).add_top_behaviors(top)
Esempio n. 31
0
    def add_base_dir_behaviors(my, div, base_dir):

        # add tooltip
        div.add_attr('title','This is the sandbox folder. Double-click to open and right-click for more options.')
        # add a top menu
        menu = Menu(width=180)
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Explore sandbox folder')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'base_dir': base_dir,
            'cbjs_action': '''
            var applet = spt.Applet.get();
            var activator = spt.smenu.get_activator(bvr);
            var path = bvr.base_dir;
            applet.open_file(path);
            '''
        } )


        menu_item = MenuItem(type='action', label='Browse for sandbox folder')
        menu.add(menu_item)
        # FIXME: this code is identical to the one in checkin_wdg.py
        menu_item.add_behavior( {
        'type': 'click_up',
        'base_dir': base_dir,
        'cbjs_action': '''
            var current_dir = bvr.base_dir;
            var applet = spt.Applet.get();
            var file_paths = applet.open_file_browser(current_dir);

            // take the first one make sure it is a directory
            var dir = file_paths[0];
            if (!applet.is_dir(dir)) {
                spt.alert("Please Select a Folder");
                return;
            }
            dir = dir.replace(/\\\\/g, "/");

            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_checkin_top");
            top.setAttribute("spt_sandbox_dir", dir);
            spt.panel.refresh(top);

        '''
        } )


        menu_item = MenuItem(type='action', label='Download from clipboard')
        menu.add(menu_item)
        menu_item.add_behavior( {
        'type': 'click_up',
        'base_dir': base_dir,
        'cbjs_action': '''
        var current_dir = bvr.base_dir;
        var server = TacticServerStub.get();
        var base = spt.Environment.get().get_server_url();
        var user = spt.Environment.get().get_user();

        var expr = "@SOBJECT(sthpw/clipboard['login','"+user+"'].sthpw/file)";
        var items = server.eval(expr);

        var applet = spt.Applet.get();

        var urls = [];
        for (var i = 0; i < items.length; i++) {
            var url = base + "/assets/" + items[i].relative_dir + "/" + items[i].file_name;
            var file_name = items[i].file_name;
            applet.download_file(url, current_dir + "/" + file_name);
        }

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_checkin_top");
        spt.panel.refresh(top);

        '''
        } )

        menus_in = {
            'SANDBOX_MENU_CTX': menu,
        }
        SmartMenu.attach_smart_context_menu( div, menus_in, False )
        SmartMenu.assign_as_local_activator( div, 'SANDBOX_MENU_CTX' )


        super(CheckinDirListWdg, my).add_base_dir_behaviors(div,base_dir)
Esempio n. 32
0
    def add_top_behaviors(my, top):
        if my.sobject:
            search_key = my.sobject.get_search_key()
        else:
            search_key = None

        bg_color = top.get_color("background")
        hilight_color =  top.get_color("background", -20)

        top.add_behavior( {
        'type': 'smart_click_up',
        'bvr_match_class': 'spt_dir_list_item',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);

        var applet = spt.Applet.get();

        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        if (applet.is_dir(path)) {
            checkin_type.value = "dir_checkin";
        }
        else {
            checkin_type.value = "file_checkin";
        }

        ''' %{'bg_color': bg_color, 'hilight_color': hilight_color}
        } )


        top.add_behavior( {
        'type': 'smart_click_up',
        'bvr_match_class': 'spt_dir_list_item',
        'modkeys': 'CTRL',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");
        spt.checkin_list.set_top(top);

        //spt.checkin_list.unselect_all_rows();
        spt.checkin_list.select(bvr.src_el);

        var applet = spt.Applet.get();

        var path = bvr.src_el.getAttribute("spt_path");
        var checkin_type = top.getElement(".spt_checkin_type");
        if (applet.is_dir(path)) {
            checkin_type.value = "dir_checkin";
        }
        else {
            checkin_type.value = "file_checkin";
        }

        ''' %{'bg_color': bg_color, 'hilight_color': hilight_color}
        } )



        top.add_behavior( {
        'type': 'load',
        'cbjs_action': '''

//for shift click feature
spt.checkin_list = {};
spt.checkin_list.top = null;
spt.checkin_list.last_selected = null;
spt.checkin_list.single_select = false;

spt.checkin_list.set_top = function(top) {
    spt.checkin_list.top = top;
}



spt.checkin_list.get_selected_paths = function() {
    // find the subcontext widget
    var rows = spt.checkin_list.get_all_rows();

    var paths = [];
    for (var i = 0; i < rows.length; i++) {
        var row = rows[i];
        if (row.is_selected == true) {
            var path = row.getAttribute("spt_path");
            paths.push(path);
        }
    }
    return paths;
} 


spt.checkin_list.get_all_rows = function() {
    var rows = spt.checkin_list.top.getElements(".spt_dir_list_item");
    return rows;
}

spt.checkin_list.unselect_all_rows = function() {

    var rows = spt.checkin_list.get_all_rows();
    for (var i = 0; i < rows.length; i++) {
        spt.checkin_list.unselect(rows[i]);
    }

}


spt.checkin_list.unselect = function(row) {
    var subcontext_el = row.getElement(".spt_subcontext");
    var context_el = row.getElement(".spt_context")
    row.is_selected = false;
    row.setStyle("background", '%(bg_color)s');
    row.setAttribute("spt_background", '%(bg_color)s');
    if (subcontext_el)
        subcontext_el.setStyle("display", "none");
    else if (context_el)
        context_el.setStyle("display", "none");

    spt.checkin_list.last_selected = null;

    spt.checkin_list.disable_checkin();
}



spt.checkin_list.select = function(row) {
    // find the subcontext widget
    var subcontext_el = row.getElement(".spt_subcontext")
    var context_el = row.getElement(".spt_context")

    if (row.is_selected == true) {
        row.is_selected = false;
        row.setStyle("background", '%(bg_color)s');
        row.setAttribute("spt_background", '%(bg_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "none");
        else if (context_el)
            context_el.setStyle("display", "none");

        spt.checkin_list.last_selected = null;

    }
    else {
        row.is_selected = true;
        row.setStyle("background", '%(hilight_color)s');
        row.setAttribute("spt_background", '%(hilight_color)s');
        if (subcontext_el)
            subcontext_el.setStyle("display", "");
		else if (context_el)
            context_el.setStyle("display", "");
        
        spt.checkin_list.last_selected = row;
    }
    var top = spt.checkin_list.top; 
    var paths = [];
    var els = top.getElements(".spt_dir_list_item");
    for (var i = 0; i < els.length; i++) {
        if (els[i].is_selected) {
            paths.push( els[i].getAttribute("spt_path") );
        }
    }

    var grey_el = top.getElement(".spt_publish_disable");
    if (paths.length == 0) {
        grey_el.setStyle("display", "");
        return;
    }

    grey_el.setStyle("display", "none");
}


spt.checkin_list.enable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "none");
} 


spt.checkin_list.disable_checkin = function() {
    var top = spt.checkin_list.top; 
    var grey_el = top.getElement(".spt_publish_disable");
    grey_el.setStyle("display", "");
} 





spt.checkin_list.select_preselected = function(){
    var top = spt.checkin_list.top; 
    var el = top.getElement(".spt_file_selector");
    if (el == null) {
        return;
    }

    var rows = spt.checkin_list.get_all_rows()
    //var cbs = top.getElements(".spt_dir_list_item");
    var paths = [];
    for (var k=0; k<rows.length; k++){
        var row = rows[k];
        if (spt.has_class(row, 'spt_preselected')) {
            var path = row.getAttribute("spt_path");
            paths.push(path); 
            spt.checkin_list.select(row);
        }
    }
    // reassign the new paths selection
    el.file_paths = paths;
}


var top = bvr.src_el.getParent(".spt_checkin_top");
spt.checkin_list.set_top(top);
spt.checkin_list.select_preselected();


        ''' %{'bg_color': bg_color, 'hilight_color': hilight_color}
        } )
 

        top.add_behavior( {
        'type': 'smart_click_up',
        'modkeys': 'SHIFT',
        'bvr_match_class': 'spt_dir_list_item',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_checkin_top");

        spt.checkin_list.set_top(top);

        var rows = spt.checkin_list.get_all_rows();

        var last_selected = spt.checkin_list.last_selected;
        var last_index;
        var cur_index;
        for (var i = 0; i < rows.length; i++) {
            if (rows[i] == last_selected) {
                last_index = i;
            }
            if (rows[i] == bvr.src_el) {
                cur_index = i;
            }
        }
        var start_index;
        var end_index;
        if (last_index < cur_index) {
            start_index = last_index + 1;
            end_index = cur_index ;
        }
        else {
            start_index = cur_index;
            end_index = last_index -1 ;
        }

        for (var i = start_index; i < end_index+1; i++) {
            spt.checkin_list.select(rows[i]);
        }

        spt.checkin_list.last_selected = bvr.src_el;
        '''
        } )




        # add a top menu
        menu = Menu(width=180)
        my.menu = menu
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)


        #menu_item = MenuItem(type='action', label='Revert to Latest')
        #menu.add(menu_item)




        menu_item = MenuItem(type='action', label='Open File')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            applet.open_file(path);
            '''
        } )



        menu_item = MenuItem(type='action', label='Open Containing Folder')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            parts.pop()
            path = parts.join("/");
            applet.open_explorer(path);
            '''
        } )



        menu_item = MenuItem(type='action', label='Copy File to Sandbox')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var applet = spt.Applet.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var selected_paths = spt.checkin_list.get_selected_paths();
            if (!selected_paths.length) {
                selected_paths = [path];
            }

            var top = activator.getParent(".spt_checkin_top");
            var default_sandbox_dir = top.getAttribute("spt_default_sandbox_dir");

            spt.app_busy.show("Copying files to Sandbox");
            for (var i = 0; i < selected_paths.length; i++) {
                var path = selected_paths[i];
                var parts = path.split("/");
                var filename = parts[parts.length-1];
                applet.copy_file(path, default_sandbox_dir + "/" + filename);
            }
            spt.app_busy.hide();

            spt.notify.show_message("Copied " + selected_paths.length + " files to sandbox");
            '''
        } )


 


        #menu_item = MenuItem(type='action', label='Rename File')
        #menu.add(menu_item)

        # DISABLING until we actually have something that works better
        menu_item = MenuItem(type='action', label='Copy File')
        #menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var applet = spt.Applet.get();

            var parts = path.split("/");
            var basename = parts[parts.length-1];

            // FIXME: new to create new path
            var new_path = path + "_copy";
            var index = 1;
            while(1) {
                if (applet.exists(new_path)) {
                    new_path = path + "_copy" + index;
                    index += 1;
                }
                else {
                    break;
                }

                if (index > 100) {
                    spt.alert("More than 100 copies.  Exiting");
                    break;
                }
            }

            applet.copy_file(path, new_path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        } )



        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Delete File')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");
            var parts = path.split("/");
            var filename = parts[parts.length-1];

            var applet = spt.Applet.get();
            var label = applet.is_dir(path) ? 'directory': 'file';
            if (!confirm("Are you sure you wish to delete the local " + label + " ["+filename+"]?")) {
                return;
            }

            applet.rmtree(path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        } )


        menu_item = MenuItem(type='separator')
        menu.add(menu_item)
        menu_item = MenuItem(type='action', label='Properties')
        menu.add(menu_item)

        menu_item.add_behavior( {
            'type': 'click_up',
            'search_key': search_key,
            'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);

            var snapshot_code = activator.getAttribute("spt_snapshot_code");
            var path = activator.getAttribute("spt_path");
            var md5 = activator.getAttribute("spt_md5");

            var applet = spt.Applet.get();
            var cur_md5 = applet.get_md5(path);

            //if (md5 != cur_md5) {
            //    activator.setStyle("background", "#A77");
            //}


            var class_name = 'tactic.ui.checkin.FilePropertiesWdg';
            var kwargs = {
                path: path,
                md5: cur_md5,
                snapshot_code: snapshot_code,
                search_key: bvr.search_key
            };
            spt.panel.load_popup("File Properties", class_name, kwargs);
            '''
        } )


        menu_item = MenuItem(type='action', label='Use as Preview Image')
        menu.add(menu_item)
        menu_item.add_behavior( {
            'type': 'click_up',
            'search_key': search_key,
            'cbjs_action': '''
            var server = TacticServerStub.get();

            var activator = spt.smenu.get_activator(bvr);
            var path = activator.getAttribute("spt_path");

            var context = "icon";
            server.simple_checkin( bvr.search_key, context, path);

            var top = activator.getParent(".spt_checkin_top");
            spt.panel.refresh(top);
            '''
        } )

        menus_in = {
            'FILE_MENU_CTX': menu,
        }
        SmartMenu.attach_smart_context_menu( top, menus_in, False )
 
        super(CheckinDirListWdg, my).add_top_behaviors(top)
Esempio n. 33
0
    def add_top_behaviors(my, top):

        # convert this to a repo directory
        asset_dir = Environment.get_asset_dir()

        # FIXME: not sure how general this
        #webdirname = "/assets/%s" % dirname.replace(asset_dir, "")

        web = WebContainer.get_web()
        browser = web.get_browser()


        if browser == 'Qt':
            top.add_relay_behavior( {
            'type': 'dblclick',
            'bvr_match_class': 'spt_dir_list_item',
            'cbjs_action': '''
            var path = bvr.src_el.getAttribute("spt_path");
            var asset_dir = '%s';
            var url = "/assets/" + path.replace(asset_dir, "");
            //window.open(url);

            var url_parts = url.split("/");
            var file = url_parts.pop();
            file = encodeURIComponent(file);
            url_parts.push(file);
            url = url_parts.join("/");

            var class_name = 'tactic.ui.widget.EmbedWdg';
            var kwargs = {
                src: url
            }

            var parts = path.split("/");
            var filename = parts[parts.length-1];
            spt.tab.set_main_body_tab()
            spt.tab.add_new(filename, filename, class_name, kwargs);
            ''' % asset_dir
            } )
        else:
            top.add_relay_behavior( {
            'type': 'dblclick',
            'bvr_match_class': 'spt_dir_list_item',
            'cbjs_action': '''
            var path = bvr.src_el.getAttribute("spt_path");
            
            if (path.indexOf('####') != -1) {
                spt.info('Cannot open the file sequence');
            } 
            else {
            var asset_dir = '%s';
            var url = "/assets/" + path.replace(asset_dir, "");

            var url_parts = url.split("/");
            var filename = url_parts.pop();
            filename = encodeURIComponent(filename);
            url_parts.push(filename);
            url = url_parts.join("/");

            window.open(url);
            }
            ''' % asset_dir
            } )

        # add a top menu
        menu = Menu(width=180)
        menu_item = MenuItem(type='title', label='Actions')
        menu.add(menu_item)

        menu_item = MenuItem(type='action', label='Download to Folder')
        menu.add(menu_item)
        menu_item.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
            var activator = spt.smenu.get_activator(bvr);
            var applet = spt.Applet.get();
            var select_dir = true;
            var dir = applet.open_file_browser('', select_dir);
            if (!dir) {
                dir = applet.get_current_dir();
            }
            if (!dir) {
                spt.alert("No folder selected to copy to");
                return;
            }
            
            var path = activator.getAttribute("spt_path");

            var asset_dir = '%s';
            var env = spt.Environment.get();
            var server_url = env.get_server_url();
            var url = server_url + "/assets/" + path.replace(asset_dir, "");
            var parts = path.split("/");
            var filename = parts[parts.length-1];
            spt.app_busy.show("Downloading file", filename);
            applet.download_file(url, dir + "/" + filename);
            spt.app_busy.hide();
            if (dir)
                spt.notify.show_message("Download to '" + dir + "' completed.")
            ''' % asset_dir
        } )
        #menu_item = MenuItem(type='action', label='Check-out To Sandbox')
        #menu.add(menu_item)
        #menu_item.add_behavior( {
        #'type': 'click_up',
        #'cbjs_action': '''spt.alert('Not implemented yet.')'''
        #} )
        menu_item = MenuItem(type='action', label='Copy to Clipboard')
        menu.add(menu_item)
        menu_item.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var activator = spt.smenu.get_activator(bvr);
        var path = activator.getAttribute("spt_path");

        var search_key = activator.getAttribute("spt_file_search_key");

        var server = TacticServerStub.get();
        var class_name = 'tactic.command.clipboard_cmd.ClipboardCopyCmd';
        var search_keys = [search_key];
        var kwargs = {
            search_keys: search_keys
        }
        try {
            spt.app_busy.show("Copy to Clipboard ...");
            server.execute_cmd(class_name, kwargs);
            spt.app_busy.hide();
            }
        catch(e) {
            spt.alert(spt.exception.handler(e));
        }
        '''
        } )


        menu_item = MenuItem(type='action', label='View Metadata')
        menu.add(menu_item)
        menu_item.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var activator = spt.smenu.get_activator(bvr);
        var path = activator.getAttribute("spt_path");

        var search_key = activator.getAttribute("spt_file_search_key");

        var server = TacticServerStub.get();
        var class_name = 'tactic.ui.checkin.SnapshotMetadataWdg';
        var kwargs = {
            search_key: search_key
        }
        spt.panel.load_popup("Metadata", class_name, kwargs);
        '''
        } )



        menus_in = {
            'FILE_MENU_CTX': menu,
        }
        SmartMenu.attach_smart_context_menu( top, menus_in, False )


        my.add_selection(top)
 
        super(SnapshotDirListWdg, my).add_top_behaviors(top)
Esempio n. 34
0
    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