Ejemplo n.º 1
0
    def get_display(self):

        self.search_key = self.kwargs.get("search_key") 
        self.context = self.kwargs.get("context") 

        assert self.search_key
        assert self.context

        top = DivWdg()
        self.set_as_panel(top)
        top.add_class("spt_review_top")

        table = Table()
        top.add(table)
        table.add_row()
        left = table.add_cell()
        left.add_style("vertical-align: top")



        button = IconButtonWdg("Visual Notes", IconWdg.EDIT)
        button.add_behavior( {
        'type': 'click_up',
        'kwargs': {
            'search_key': self.search_key,
            'context': self.context,
        },
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_review_top");
        var content = top.getElement(".spt_review_content");
        spt.panel.load(content, "tactic.ui.widget.visual_notes_wdg.VisualNotesWdg", bvr.kwargs);
        '''
        } )
        left.add(button)


        # add a refresh button and a gear menu
        button = IconButtonWdg("Refresh", IconWdg.REFRESH)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var panel = bvr.src_el.getParent(".spt_review_top");
        spt.panel.refresh(panel);
        '''
        } )
        left.add(button)






        right = table.add_cell()
        right.add_style("vertical-align: top")
        right.add("Image Area")


        content_div = DivWdg()
        content_div.add_class("spt_review_content")
        content_div.add_style("padding: 5px")
        content_div.add_style("margin: 5px")
        content_div.add_style("border: solid 1px #999")
        content_div.add_style("min-width: 500px")
        content_div.add_style("min-height: 400px")
        content_div.add_style("height: 100%")

        right.add(content_div)



        sobject = Search.get_by_search_key(self.search_key)

        note_context = "%s|note" % self.context
        snapshots = Search.eval("@SOBJECT(sthpw/snapshot['context','=','%s'])" % note_context, [sobject])

        vnotes_div = DivWdg()
        vnotes_div.add_style("overflow: auto")
        vnotes_div.add_style("width: 200px")
        vnotes_div.add_style("min-height: 400px")
        vnotes_div.add_style("max-height: 600px")
        vnotes_div.add_style("border: solid 1px #999")
        vnotes_div.add_style("padding: 5px")
        vnotes_div.add_style("margin: 5px")

        left.add(vnotes_div)

        if not snapshots:
            vnotes_div.add("<b>No review notes available</b>")

            notes_wdg = VisualNotesWdg(search_key=self.search_key,context=self.context)
            content_div.add(notes_wdg)



        for snapshot in snapshots:
            vnote_div = DivWdg()
            vnotes_div.add(vnote_div)

            file_obj = snapshot.get_file_by_type('main')
            if not file_obj:
                vnote_div.add("None found")
                continue

            rel_path = file_obj.get_value("relative_dir")
            file_name = file_obj.get_value("file_name")
            image_url = "/assets/%s/%s" % (rel_path, file_name)


            login = snapshot.get_value("login")
            date = snapshot.get_value("timestamp")
            import dateutil
            date_str = dateutil.parser.parse(date).strftime("%b %m %Y - %H:%M")


            login_div = DivWdg()
            login_div.add_style("padding: 2px")
            login_div.add("User: "******"<b>%s</b><br/>" % login )
            login_div.add("Date: ")
            login_div.add( "<b>%s</b><br/>" % date_str )
            vnote_div.add(login_div)



            from pyasm.widget import ThumbWdg
            thumb_div = DivWdg()
            thumb_div.add_style("margin-left: 10px")
            thumb = ThumbWdg()
            thumb_div.add(thumb)
            thumb.set_has_img_link(False)
            thumb.set_option("detail", "false")
            thumb.set_option("icon_size", "80")
            thumb.set_sobject(snapshot)
            vnote_div.add(thumb_div)
            #file_obj = snapshot.get_file_by_type('icon')
            #rel_path = file_obj.get_value("relative_dir")
            #file_name = file_obj.get_value("file_name")
            #icon_url = "/assets/%s/%s" % (rel_path, file_name)
            #vnote_div.add("<img src='%s'/>" % icon_url )

            #vnote_div.add(snapshot.get_code() )
            vnote_div.add_attr("spt_image_url", image_url )
            vnote_div.add_class('hand')

            vnote_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var value = bvr.src_el.innerHTML;
            var image_url = bvr.src_el.getAttribute("spt_image_url");

            var top = bvr.src_el.getParent(".spt_review_top");
            var content = top.getElement(".spt_review_content");
            content.innerHTML = "<img src='"+image_url+"'/>";
            '''
            } )




            # get the related note to this vnote
            #notes = vnotes_div.get_related_notes()
            search = Search("sthpw/note")
            search.add_parent_filter(sobject)
            notes = search.get_sobjects()

            #for note in notes:
            #    vnote_div.add(note.get_value("note"))

            from pyasm.biz import SObjectConnection 
            connections, related_notes = SObjectConnection.get_connected_sobjects(snapshot, direction='src')
            for related_note in related_notes:
                vnote_div.add(related_note.get_value("note") )
                
            print "related_notes: ", related_notes


            vnote_div.add("<hr/>")




        return top
Ejemplo n.º 2
0
    def get_display(self):


        web = WebContainer.get_web()
        palette = web.get_palette()

        widget = DivWdg()
        widget.add_style("width: 100%")
        widget.add_style("text-align: center")

        from tactic.ui.app import PageHeaderWdg
        header = PageHeaderWdg(show_project=False)
        widget.add( header )

        security = Environment.get_security()


        search = Search("sthpw/project")
        search.add_where("\"code\" not in ('sthpw', 'admin', 'unittest')")
        search.add_where("\"type\" not in ('resource')")
        # hide template projects
        if security.check_access("builtin", "view_site_admin", "allow") or security.check_access("builtin", "view_template_projects", "allow"):
            pass
        else:
            search.add_op("begin")
            search.add_filter("is_template", True, op='!=')
            search.add_filter("is_template", 'NULL', quoted=False, op='is')
            search.add_op("or")

        search.add_order_by("category")

        projects = search.get_sobjects()
        
        num = len(projects)
        # sort by project
        if num < 5:
            columns = 1
            icon_size = 90
            width = 500
        elif num < 15:
            columns = 2
            icon_size = 60
            width = 700
        else:
            columns = 3
            icon_size = 45
            width = 800

        div = DivWdg()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        #div.add_style("width: 520px")
        div.center()
        widget.add(div)

        #logo = TacticLogoWdg()
        #div.add(logo)
        div.add("<br/>"*3)

        bg_color = palette.color("background")
        #div.add_color("color", "color")

        from tactic.ui.container import RoundedCornerDivWdg
        div = RoundedCornerDivWdg(hex_color_code=bg_color,corner_size="10")
        div.set_dimensions( width_str='%spx' % width, content_height_str='50px' )
        div.add_border()
        div.add_style("overflow: hidden")
        div.set_box_shadow()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        div.add_style("width: %spx" % width)
        table = Table()
        table.set_max_width()
        table.add_style("margin-left: auto")
        table.add_style("margin-right: auto")
        table.add_style("background-color: %s" % bg_color)
        table.add_color("color", "color")

        tr, td = table.add_row_cell()
        logo_div = DivWdg()
        logo_div.add_gradient("background", "background3", -5, -10)
        td.add(logo_div)
        logo = TacticLogoWdg()
        logo_div.add(logo)
        logo_div.add_style("margin: -6 -6 6 -6")


        app_name = WebContainer.get_web().get_app_name()
        security = Environment.get_security() 

        last_category = None
        has_category = False
        index = 0 

        # if TACTIC has not been set up, show the configuration page
        # FIXME: what is the requirement for is_installed?
        config_path = Config.get_config_path()
        if not os.path.exists(config_path):
            is_installed = False
        else:
            is_installed = True
        #is_installed = True



        # filter out projects due to security
        filtered = []
        for i, project in enumerate(projects):

            from pyasm.security import get_security_version
            security_version = get_security_version()
            if security_version >= 2:
                key = { "code": project.get_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.get_code(), "view", default="allow"):
                    continue

            filtered.append(project)

        projects = filtered





        if not is_installed:
            tr, td = table.add_row_cell()

            #from tactic.ui.startup import DbConfigWdg
            #td.add(DbConfigWdg())

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 5px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("Welcome to TACTIC ...<br/>")
            projects_div.add_style("font-size: 22px")


            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("Configure TACTIC to connect to an external database and set up asset folders.<br/><br/>")
            msg_div.add_style("text-align: center")


            action = ActionButtonWdg(title='Confgure', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = "/tactic/admin/#/link/configure";
            '''
            } )


            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("<br/><br/>Or start using TACTIC with default configuration with an internal database.<br/><br/>")

            msg_div.add_style("text-align: center")
            action = ActionButtonWdg(title='Start >>', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = "/tactic";
            '''
            } )


            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("<br/><br/><br/>")
            msg_div.add_style("text-align: center")



        elif projects:
            num_projets = 0
            for i, project in enumerate(projects):

                category = project.get_value("category")
                if category is not None and category != last_category:

                    table.add_row()
                    tr, td = table.add_row_cell()
                    category_div = DivWdg()
                    td.add(category_div)
                    if has_category and not category:
                        category_div.add("&nbsp;")
                    else:
                        category_div.add(category)
                    category_div.add_style("padding: 8px")
                    category_div.add_style("font-size: 16px")
                    category_div.add_style("font-weight: bold")
                    category_div.add_color("color", "color")
                    category_div.add_gradient("background", "background3",0, -10)
                    category_div.add_color("color", "color3")
                    #category_div.set_round_corners()
                    if last_category == None:
                        category_div.add_style("margin: -6 -6 6 -6")
                    else:
                        category_div.add_style("margin: 15 -6 0 -6")
                    table.add_row()
                    has_category = True
                    index = 0

                index += 1
                last_category = category


                thumb = ThumbWdg()
                thumb.set_name("snapshot")
                thumb.set_sobject(project)
                thumb.set_show_clipboard(False)
                thumb.set_has_img_link(False)
                thumb.set_icon_size(icon_size)
             
                code = project.get_code()
                title = project.get_value("title")
                # Restrict the length of project name
                if len(title) >= 36:
                    title = title[:36] + "..."
                if app_name != 'Browser':
                    href = HtmlElement.href(HtmlElement.h2(title), ref='/tactic/%s/%s'\
                        %(code, app_name))
                    img_href = HtmlElement.href(thumb, ref='/tactic/%s/%s'\
                        %(code, app_name))

                    link = '/tactic/%s/%s' % (code, app_name)
                else:
                    href = HtmlElement.href(HtmlElement.h2(title), ref="/tactic/%s/" % code)
                    img_href = DivWdg(thumb)
                    img_href.add_behavior( {
                        'type': 'click_up',
                        'code': code,
                        'cbjs_action': '''
                        document.location = '/tactic/'+bvr.code+'/';
                        '''
                    } )
                
                    link = '/tactic/%s/' % code

                href = href.get_buffer_display()
                if (index-1) % columns == 0:
                    table.add_row()
               
                td = table.add_cell()
                img_div = DivWdg()
                img_div.add(img_href)
                img_div.add_style("margin-right: 20px")
                img_div.add_style("float: left")
                img_div.add_border()
                #img_div.set_round_corners()
                img_div.set_box_shadow("0px 1px 5px")

                project_div = DivWdg()
                td.add(project_div)
                td.add_style("width: 230px")
                project_div.add_style("font-size: 16px")
                project_div.add_style("font-weight: bold")
                project_div.add_style("vertical-align: middle")
                project_div.add(img_div)
                #project_div.add(href)
                project_div.add(title)
                if project.get_value("is_template") == True:
                    project_div.add("<br/><i style='opacity: 0.5; font-size: 12px'>(template)</i>")
                project_div.add_style("height: %spx" % (icon_size-10))

                project_div.add_style("padding: 8px 10px 2px 20px")
                
                project_div.add_color("background", "background")
                project_div.add_behavior( {
                'type': 'hover',
                'add_color_modifier': -3,
                'cb_set_prefix': 'spt.mouse.table_layout_hover',
                } )
                project_div.set_round_corners()
                project_div.add_class("hand")

                project_div.add_behavior( {
                'type': 'click_up',
                'link': link,
                'title': title,
                'cbjs_action': '''
                document.location = bvr.link;
                '''
                } )

        elif not security.check_access("builtin", "view_site_admin", "allow", default="deny") and not security.check_access("builtin", "create_projects", "allow", default="deny"):
            tr, td = table.add_row_cell()

            msg_div = DivWdg()
            td.add(msg_div)
            from pyasm.widget import IconWdg
            icon = IconWdg("WARNING", IconWdg.WARNING)
            msg_div.add(icon)
            msg_div.add("You are not permitted to view any projects")
            msg_div.add_style("font-size: 16px")
            msg_div.add_style("text-align: center")
            msg_div.add_style("font-weight: bold")
            msg_div.add_style("margin: 50px")
            msg_div.add("<br/>"*2)
            msg_div.add("Please click to Sign Out:<br/>")
            action = ActionButtonWdg(title='Sign Out >>', size='m')
            msg_div.add(action)
            action.add_style('margin: 5px auto')
            action.add_style('text-align: center')
            web = WebContainer.get_web()
            action.add_behavior( {
                'type': 'click_up',
                'login': web.get_user_name(),
                'cbjs_action': '''
                var server = TacticServerStub.get();
                server.execute_cmd("SignOutCmd", {login: bvr.login} );
                window.location.href='/';
                '''
            } )

        else:
            tr, td = table.add_row_cell()

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 10px")
            title_div.add_style("margin: -8px -6px 20px -6px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("No Projects have been created ...<br/><br/>")
            projects_div.add_style("font-size: 22px")

            action = ActionButtonWdg(title='Create Project >>', size='large')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            projects_div.add(action)
            action.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = "/tactic/admin/link/create_project";
            '''
            } )


        if security.check_access("builtin", "view_site_admin", "allow"):
            admin_div = DivWdg()
            #href = HtmlElement.href(HtmlElement.h2('Admin Site'), ref='/tactic/admin/')
            #admin_div.add(href)
            #admin_div.add_border()
            admin_div.add_style("font-size: 16px")
            admin_div.add_style("font-weight: bold")
            admin_div.add_style("height: 30px")

            link_div = DivWdg()
            link_div.add_class("hand")
            admin_div.add(link_div)
            link_div.add("Go to Admin Site")
            link_div.add_style("text-align: center")
            link_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            document.location = '/tactic/admin/';
            '''
            } )
            tr, td = table.add_row_cell()
            td.add("<hr/><br/>")
            td.add(admin_div)


        div.add(table)
        widget.add(div)
        # Note sure what this is for
        #BaseAppServer.add_onload_script('spt.first_load=false')
        div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''spt.first_load=false'''
        } )
        return widget
Ejemplo n.º 3
0
    def get_display(self):

        web = WebContainer.get_web()
        palette = web.get_palette()

        widget = DivWdg()
        widget.add_style("width: 100%")
        widget.add_style("text-align: center")

        from tactic.ui.app import PageHeaderWdg
        header = PageHeaderWdg(show_project=False)
        widget.add(header)

        security = Environment.get_security()

        search = Search("sthpw/project")
        search.add_where("\"code\" not in ('sthpw', 'admin', 'unittest')")
        search.add_where("\"type\" not in ('resource')")
        # hide template projects
        if security.check_access("builtin", "view_site_admin",
                                 "allow") or security.check_access(
                                     "builtin", "view_template_projects",
                                     "allow"):
            pass
        else:
            search.add_op("begin")
            search.add_filter("is_template", True, op='!=')
            search.add_filter("is_template", 'NULL', quoted=False, op='is')
            search.add_op("or")

        search.add_order_by("category")

        projects = search.get_sobjects()

        num = len(projects)
        # sort by project
        if num < 5:
            columns = 1
            icon_size = 90
            width = 500
        elif num < 15:
            columns = 2
            icon_size = 60
            width = 700
        else:
            columns = 3
            icon_size = 45
            width = 800

        div = DivWdg()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        #div.add_style("width: 520px")
        div.center()
        widget.add(div)

        #logo = TacticLogoWdg()
        #div.add(logo)
        div.add("<br/>" * 3)

        bg_color = palette.color("background")
        #div.add_color("color", "color")

        from tactic.ui.container import RoundedCornerDivWdg
        div = RoundedCornerDivWdg(hex_color_code=bg_color, corner_size="10")
        div.set_dimensions(width_str='%spx' % width, content_height_str='50px')
        div.add_border()
        div.add_style("overflow: hidden")
        div.set_box_shadow()

        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")
        div.add_style("width: %spx" % width)
        table = Table()
        table.set_max_width()
        table.add_style("margin-left: auto")
        table.add_style("margin-right: auto")
        table.add_style("background-color: %s" % bg_color)
        table.add_color("color", "color")

        tr, td = table.add_row_cell()
        logo_div = DivWdg()
        logo_div.add_gradient("background", "background3", -5, -10)
        td.add(logo_div)
        logo = TacticLogoWdg()
        logo_div.add(logo)
        logo_div.add_style("margin: -6 -6 6 -6")

        app_name = WebContainer.get_web().get_app_name()
        security = Environment.get_security()

        last_category = None
        has_category = False
        index = 0

        # if TACTIC has not been set up, show the configuration page
        # FIXME: what is the requirement for is_installed?
        config_path = Config.get_config_path()
        if not os.path.exists(config_path):
            is_installed = False
        else:
            is_installed = True
        #is_installed = True

        # filter out projects due to security
        filtered = []
        for i, project in enumerate(projects):

            from pyasm.security import get_security_version
            security_version = get_security_version()
            if security_version >= 2:
                key = {"code": project.get_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.get_code(), "view",
                        default="allow"):
                    continue

            filtered.append(project)

        projects = filtered

        if not is_installed:
            tr, td = table.add_row_cell()

            #from tactic.ui.startup import DbConfigWdg
            #td.add(DbConfigWdg())

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 5px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("Welcome to TACTIC ...<br/>")
            projects_div.add_style("font-size: 22px")

            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add(
                "Configure TACTIC to connect to an external database and set up asset folders.<br/><br/>"
            )
            msg_div.add_style("text-align: center")

            action = ActionButtonWdg(title='Confgure', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = "/tactic/admin/#/link/configure";
            '''
            })

            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add(
                "<br/><br/>Or start using TACTIC with default configuration with an internal database.<br/><br/>"
            )

            msg_div.add_style("text-align: center")
            action = ActionButtonWdg(title='Start >>', size='medium')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            td.add(action)
            action.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = "/tactic";
            '''
            })

            msg_div = DivWdg()
            td.add(msg_div)
            msg_div.add("<br/><br/><br/>")
            msg_div.add_style("text-align: center")

        elif projects:
            num_projets = 0
            for i, project in enumerate(projects):

                category = project.get_value("category")
                if category is not None and category != last_category:

                    table.add_row()
                    tr, td = table.add_row_cell()
                    category_div = DivWdg()
                    td.add(category_div)
                    if has_category and not category:
                        category_div.add("&nbsp;")
                    else:
                        category_div.add(category)
                    category_div.add_style("padding: 8px")
                    category_div.add_style("font-size: 16px")
                    category_div.add_style("font-weight: bold")
                    category_div.add_color("color", "color")
                    category_div.add_gradient("background", "background3", 0,
                                              -10)
                    category_div.add_color("color", "color3")
                    #category_div.set_round_corners()
                    if last_category == None:
                        category_div.add_style("margin: -6 -6 6 -6")
                    else:
                        category_div.add_style("margin: 15 -6 0 -6")
                    table.add_row()
                    has_category = True
                    index = 0

                index += 1
                last_category = category

                thumb = ThumbWdg()
                thumb.set_name("snapshot")
                thumb.set_sobject(project)
                thumb.set_show_clipboard(False)
                thumb.set_has_img_link(False)
                thumb.set_icon_size(icon_size)

                code = project.get_code()
                title = project.get_value("title")
                # Restrict the length of project name
                if len(title) >= 36:
                    title = title[:36] + "..."
                if app_name != 'Browser':
                    href = HtmlElement.href(HtmlElement.h2(title), ref='/tactic/%s/%s'\
                        %(code, app_name))
                    img_href = HtmlElement.href(thumb, ref='/tactic/%s/%s'\
                        %(code, app_name))

                    link = '/tactic/%s/%s' % (code, app_name)
                else:
                    href = HtmlElement.href(HtmlElement.h2(title),
                                            ref="/tactic/%s/" % code)
                    img_href = DivWdg(thumb)
                    img_href.add_behavior({
                        'type':
                        'click_up',
                        'code':
                        code,
                        'cbjs_action':
                        '''
                        document.location = '/tactic/'+bvr.code+'/';
                        '''
                    })

                    link = '/tactic/%s/' % code

                href = href.get_buffer_display()
                if (index - 1) % columns == 0:
                    table.add_row()

                td = table.add_cell()
                img_div = DivWdg()
                img_div.add(img_href)
                img_div.add_style("margin-right: 20px")
                img_div.add_style("float: left")
                img_div.add_border()
                #img_div.set_round_corners()
                img_div.set_box_shadow("0px 1px 5px")

                project_div = DivWdg()
                td.add(project_div)
                td.add_style("width: 230px")
                project_div.add_style("font-size: 16px")
                project_div.add_style("font-weight: bold")
                project_div.add_style("vertical-align: middle")
                project_div.add(img_div)
                #project_div.add(href)
                project_div.add(title)
                if project.get_value("is_template") == True:
                    project_div.add(
                        "<br/><i style='opacity: 0.5; font-size: 12px'>(template)</i>"
                    )
                project_div.add_style("height: %spx" % (icon_size - 10))

                project_div.add_style("padding: 8px 10px 2px 20px")

                project_div.add_color("background", "background")
                project_div.add_behavior({
                    'type':
                    'hover',
                    'add_color_modifier':
                    -3,
                    'cb_set_prefix':
                    'spt.mouse.table_layout_hover',
                })
                project_div.set_round_corners()
                project_div.add_class("hand")

                project_div.add_behavior({
                    'type':
                    'click_up',
                    'link':
                    link,
                    'title':
                    title,
                    'cbjs_action':
                    '''
                document.location = bvr.link;
                '''
                })

        elif not security.check_access(
                "builtin", "view_site_admin", "allow",
                default="deny") and not security.check_access(
                    "builtin", "create_projects", "allow", default="deny"):
            tr, td = table.add_row_cell()

            msg_div = DivWdg()
            td.add(msg_div)
            from pyasm.widget import IconWdg
            icon = IconWdg("WARNING", IconWdg.WARNING)
            msg_div.add(icon)
            msg_div.add("You are not permitted to view any projects")
            msg_div.add_style("font-size: 16px")
            msg_div.add_style("text-align: center")
            msg_div.add_style("font-weight: bold")
            msg_div.add_style("margin: 50px")
            msg_div.add("<br/>" * 2)
            msg_div.add("Please click to Sign Out:<br/>")
            action = ActionButtonWdg(title='Sign Out >>', size='m')
            msg_div.add(action)
            action.add_style('margin: 5px auto')
            action.add_style('text-align: center')
            web = WebContainer.get_web()
            action.add_behavior({
                'type':
                'click_up',
                'login':
                web.get_user_name(),
                'cbjs_action':
                '''
                var server = TacticServerStub.get();
                server.execute_cmd("SignOutCmd", {login: bvr.login} );
                window.location.href='/';
                '''
            })

        else:
            tr, td = table.add_row_cell()

            title_div = DivWdg()
            td.add(title_div)
            title_div.add_style("padding: 10px")
            title_div.add_style("margin: -8px -6px 20px -6px")
            title_div.add_style("font-weight: bold")
            title_div.add("Getting Started ...")
            title_div.add_gradient("background", "background", -10)

            projects_div = DivWdg()
            projects_div.add_style("padding: 20px")
            td.add(projects_div)
            projects_div.add_style("text-align: center")
            projects_div.add("No Projects have been created ...<br/><br/>")
            projects_div.add_style("font-size: 22px")

            action = ActionButtonWdg(title='Create Project >>', size='large')
            action.add_style("margin-left: auto")
            action.add_style("margin-right: auto")
            projects_div.add(action)
            action.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = "/tactic/admin/link/create_project";
            '''
            })

        if security.check_access("builtin", "view_site_admin", "allow"):
            admin_div = DivWdg()
            #href = HtmlElement.href(HtmlElement.h2('Admin Site'), ref='/tactic/admin/')
            #admin_div.add(href)
            #admin_div.add_border()
            admin_div.add_style("font-size: 16px")
            admin_div.add_style("font-weight: bold")
            admin_div.add_style("height: 30px")

            link_div = DivWdg()
            link_div.add_class("hand")
            admin_div.add(link_div)
            link_div.add("Go to Admin Site")
            link_div.add_style("text-align: center")
            link_div.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
            document.location = '/tactic/admin/';
            '''
            })
            tr, td = table.add_row_cell()
            td.add("<hr/><br/>")
            td.add(admin_div)

        div.add(table)
        widget.add(div)
        # Note sure what this is for
        #BaseAppServer.add_onload_script('spt.first_load=false')
        div.add_behavior({
            'type': 'load',
            'cbjs_action': '''spt.first_load=false'''
        })
        return widget
Ejemplo n.º 4
0
    def get_display(my):

        my.search_key = my.kwargs.get("search_key")
        my.context = my.kwargs.get("context")

        assert my.search_key
        assert my.context

        top = DivWdg()
        my.set_as_panel(top)
        top.add_class("spt_review_top")

        table = Table()
        top.add(table)
        table.add_row()
        left = table.add_cell()
        left.add_style("vertical-align: top")

        button = IconButtonWdg("Visual Notes", IconWdg.EDIT)
        button.add_behavior(
            {
                "type": "click_up",
                "kwargs": {"search_key": my.search_key, "context": my.context},
                "cbjs_action": """
        var top = bvr.src_el.getParent(".spt_review_top");
        var content = top.getElement(".spt_review_content");
        spt.panel.load(content, "tactic.ui.widget.visual_notes_wdg.VisualNotesWdg", bvr.kwargs);
        """,
            }
        )
        left.add(button)

        # add a refresh button and a gear menu
        button = IconButtonWdg("Refresh", IconWdg.REFRESH)
        button.add_behavior(
            {
                "type": "click_up",
                "cbjs_action": """
        var panel = bvr.src_el.getParent(".spt_review_top");
        spt.panel.refresh(panel);
        """,
            }
        )
        left.add(button)

        right = table.add_cell()
        right.add_style("vertical-align: top")
        right.add("Image Area")

        content_div = DivWdg()
        content_div.add_class("spt_review_content")
        content_div.add_style("padding: 5px")
        content_div.add_style("margin: 5px")
        content_div.add_style("border: solid 1px #999")
        content_div.add_style("min-width: 500px")
        content_div.add_style("min-height: 400px")
        content_div.add_style("height: 100%")

        right.add(content_div)

        sobject = Search.get_by_search_key(my.search_key)

        note_context = "%s|note" % my.context
        snapshots = Search.eval("@SOBJECT(sthpw/snapshot['context','=','%s'])" % note_context, [sobject])

        vnotes_div = DivWdg()
        vnotes_div.add_style("overflow: auto")
        vnotes_div.add_style("width: 200px")
        vnotes_div.add_style("min-height: 400px")
        vnotes_div.add_style("max-height: 600px")
        vnotes_div.add_style("border: solid 1px #999")
        vnotes_div.add_style("padding: 5px")
        vnotes_div.add_style("margin: 5px")

        left.add(vnotes_div)

        if not snapshots:
            vnotes_div.add("<b>No review notes available</b>")

            notes_wdg = VisualNotesWdg(search_key=my.search_key, context=my.context)
            content_div.add(notes_wdg)

        for snapshot in snapshots:
            vnote_div = DivWdg()
            vnotes_div.add(vnote_div)

            file_obj = snapshot.get_file_by_type("main")
            if not file_obj:
                vnote_div.add("None found")
                continue

            rel_path = file_obj.get_value("relative_dir")
            file_name = file_obj.get_value("file_name")
            image_url = "/assets/%s/%s" % (rel_path, file_name)

            login = snapshot.get_value("login")
            date = snapshot.get_value("timestamp")
            import dateutil

            date_str = dateutil.parser.parse(date).strftime("%b %m %Y - %H:%M")

            login_div = DivWdg()
            login_div.add_style("padding: 2px")
            login_div.add("User: "******"<b>%s</b><br/>" % login)
            login_div.add("Date: ")
            login_div.add("<b>%s</b><br/>" % date_str)
            vnote_div.add(login_div)

            from pyasm.widget import ThumbWdg

            thumb_div = DivWdg()
            thumb_div.add_style("margin-left: 10px")
            thumb = ThumbWdg()
            thumb_div.add(thumb)
            thumb.set_has_img_link(False)
            thumb.set_option("detail", "false")
            thumb.set_option("icon_size", "80")
            thumb.set_sobject(snapshot)
            vnote_div.add(thumb_div)
            # file_obj = snapshot.get_file_by_type('icon')
            # rel_path = file_obj.get_value("relative_dir")
            # file_name = file_obj.get_value("file_name")
            # icon_url = "/assets/%s/%s" % (rel_path, file_name)
            # vnote_div.add("<img src='%s'/>" % icon_url )

            # vnote_div.add(snapshot.get_code() )
            vnote_div.add_attr("spt_image_url", image_url)
            vnote_div.add_class("hand")

            vnote_div.add_behavior(
                {
                    "type": "click_up",
                    "cbjs_action": """
            var value = bvr.src_el.innerHTML;
            var image_url = bvr.src_el.getAttribute("spt_image_url");

            var top = bvr.src_el.getParent(".spt_review_top");
            var content = top.getElement(".spt_review_content");
            content.innerHTML = "<img src='"+image_url+"'/>";
            """,
                }
            )

            # get the related note to this vnote
            # notes = vnotes_div.get_related_notes()
            search = Search("sthpw/note")
            search.add_parent_filter(sobject)
            notes = search.get_sobjects()

            # for note in notes:
            #    vnote_div.add(note.get_value("note"))

            from pyasm.biz import SObjectConnection

            connections, related_notes = SObjectConnection.get_connected_sobjects(snapshot, direction="src")
            for related_note in related_notes:
                vnote_div.add(related_note.get_value("note"))

            print "related_notes: ", related_notes

            vnote_div.add("<hr/>")

        return top