def get_def_config(my, def_xml=None):
        def_confg = None

        my.def_view = my.kwargs.get('definition')
        if my.def_view:
            #raise TacticException("No definition view defined in custom layout with view [%s]" % my.view)

            my.search_type = "CustomLayoutWdg"
            search = Search("config/widget_config")
            search.add_filter("search_type", my.search_type)
            search.add_filter("view", my.def_view)
            def_db_config = search.get_sobject()
            if not def_db_config:
                raise TacticException("Definition config [%s] not defined" % my.def_view)
            def_xml = def_db_config.get_xml()
            def_config = WidgetConfig.get("definition", xml=def_xml)


        # also look inline to see if there are any definitions        
        if def_xml:
            # just use the passed in xml for a definition
            def_config = WidgetConfig.get(my.view, xml=def_xml)


        return def_config
示例#2
0
    def get_def_config(my, def_xml=None):
        def_confg = None

        my.def_view = my.kwargs.get('definition')
        if my.def_view:
            #raise TacticException("No definition view defined in custom layout with view [%s]" % my.view)

            my.search_type = "CustomLayoutWdg"
            search = Search("config/widget_config")
            search.add_filter("search_type", my.search_type)
            search.add_filter("view", my.def_view)
            def_db_config = search.get_sobject()
            if not def_db_config:
                raise TacticException("Definition config [%s] not defined" % my.def_view)
            def_xml = def_db_config.get_xml()
            def_config = WidgetConfig.get("definition", xml=def_xml)


        # also look inline to see if there are any definitions        
        if def_xml:
            # just use the passed in xml for a definition
            def_config = WidgetConfig.get(my.view, xml=def_xml)


        return def_config
示例#3
0
    def get_config(my):
        config = None
        config_xml = my.kwargs.get("config_xml")
        if config_xml:
            config = WidgetConfig.get(xml=config_xml, view=my.view)
            return config

        # this is the new preferred way of defining CustomLayoutWdg
        search = Search("config/widget_config")
        if my.category:
            search.add_filter("category", my.category)
        else:
            search.add_filter("category", "CustomLayoutWdg")
        if my.search_type:
            search.add_filter("search_type", my.search_type)

        search.add_filter("view", my.view)

        config = search.get_sobject()
        if config:
            return config
        # if it is not defined in the database, look at a config file

        includes = my.kwargs.get("include")
        if includes:
            includes = includes.split("|")

            for include in includes:
                tmp_path = __file__
                dir_name = os.path.dirname(tmp_path)
                file_path = "%s/../config/%s" % (dir_name, include)
                config = WidgetConfig.get(file_path=file_path, view=my.view)
                if config and config.has_view(my.view):
                    return config

        # deprecated approach, assuming a "CustomLayoutWdg" as search_type,
        # is deprecated
        if not config:
            search = Search("config/widget_config")
            if my.category:
                search.add_filter("category", my.category)
            if my.search_type:
                search.add_filter("search_type", "CustomLayoutWdg")

            search.add_filter("view", my.view)

            config = search.get_sobject()

        # if not config and my.search_type and my.view:
        #    config = WidgetConfigView.get_by_search_type(my.search_type, my.view)
        # this is the new preferred way of defining CustomLayoutWdg
        # NOTE: this finds a definition where search type is not explicitly
        # given>
        if not config:
            search = Search("config/widget_config")
            search.add_filter("view", my.view)
            search.add_filter("search_type", None)
            config = search.get_sobject()

        return config
示例#4
0
    def add_internal_config(cls, configs, views):
        '''add an internal config based on project base type'''
        project = Project.get()
        project_type = project.get_base_type()
        # catch potential invalid xpath error
        try:
            if project_type:
                tmp_path = __file__
                dir_name = os.path.dirname(tmp_path)
                file_path = "%s/../config/%s-conf.xml" % (dir_name,
                                                          project_type)
                if os.path.exists(file_path):
                    for view in views:
                        config = WidgetConfig.get(file_path=file_path,
                                                  view=view)
                        if config.get_view_node():
                            configs.append(config)

            # finally, just look at the DEFAULT config
            tmp_path = __file__
            dir_name = os.path.dirname(tmp_path)
            file_path = "%s/../config/%s-conf.xml" % (dir_name, "DEFAULT")

            if os.path.exists(file_path):
                for view in views:
                    config = WidgetConfig.get(file_path=file_path, view=view)
                    if config.get_view_node():
                        configs.append(config)

        except XmlException as e:
            msg = "Error with view [%s]" % ' '.join(views)
            error_list = Container.get_seq(cls.ERR_MSG)
            if msg not in error_list:
                Container.append_seq(cls.ERR_MSG, msg)
                print(e.__str__())
示例#5
0
    def add_internal_config(cls, configs, views):
        '''add an internal config based on project base type'''
        project = Project.get()
        project_type = project.get_base_type()
        # catch potential invalid xpath error
        try:
            if project_type:
                tmp_path = __file__
                dir_name = os.path.dirname(tmp_path)
                file_path="%s/../config/%s-conf.xml" % (dir_name, project_type)
                if os.path.exists(file_path):
                    for view in views:
                        config = WidgetConfig.get(file_path=file_path, view=view)
                        if config.get_view_node():
                            configs.append(config)

            # finally, just look at the DEFAULT config
            tmp_path = __file__
            dir_name = os.path.dirname(tmp_path)
            file_path="%s/../config/%s-conf.xml" % (dir_name, "DEFAULT")
                
            if os.path.exists(file_path):
                for view in views:
                    config = WidgetConfig.get(file_path=file_path, view=view)
                    if config.get_view_node():
                        configs.append(config)

        except XmlException, e:
            msg = "Error with view [%s]"% ' '.join(views)
            error_list = Container.get_seq(cls.ERR_MSG)
            if msg not in error_list:
                Container.append_seq(cls.ERR_MSG, msg)
                print e.__str__()
    def get_async_element_wdg(my, xml, element_name, load):

        tmp_config = WidgetConfig.get('tmp', xml=xml)
        display_handler = tmp_config.get_display_handler(element_name)
        display_options = tmp_config.get_display_options(element_name)

        div = DivWdg()
        unique_id = div.set_unique_id()

        if load == "sequence":
            my.sequence_data.append( {
                'class_name': display_handler,
                'kwargs': display_options,
                'unique_id': unique_id
            } )
        else:
            div.add_behavior( {
                'type': 'load',
                'class_name': display_handler,
                'kwargs': display_options,
                'cbjs_action': '''
                spt.panel.async_load(bvr.src_el, bvr.class_name, bvr.kwargs);
                '''
            } )

        loading_div = DivWdg()
        loading_div.add_style("margin: auto auto")
        loading_div.add_style("width: 150px")
        loading_div.add_style("text-align: center")
        loading_div.add_style("padding: 20px")
        div.add(loading_div)
        loading_div.add('''<img src="/context/icons/common/indicator_snake.gif" border="0"/> <b>Loading ...</b>''')

        return div
示例#7
0
文件: note_wdg.py 项目: mincau/TACTIC
    def _get_main_config(self, view, process_names):
        '''get the main config for this table layout'''
        xml = Xml()
        xml.create_doc("config")
        root = xml.get_root_node()
        view_node = xml.create_element(view)
        #root.appendChild(view_node)
        xml.append_child(root, view_node)
        
        for idx, process_name in enumerate(process_names):
            element  = xml.create_element('element')
            Xml.set_attribute(element, 'name', process_name)
            #view_node.appendChild(element)
            xml.append_child(view_node, element)
            display =   xml.create_element('display')
            if self.element_class:
                Xml.set_attribute(display, 'class',self.element_class)
            else:
                Xml.set_attribute(display, 'class', "tactic.ui.app.NoteTableElementWdg")
            #element.appendChild(display)
            xml.append_child(element, display)

            op_element = xml.create_data_element('parent_key', self.search_key)
            xml.append_child(display, op_element)
            

        config_xml = xml.to_string()
        widget_config = WidgetConfig.get(view=view, xml = config_xml)
        widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config])

        return widget_config_view
    def get_folder_wdg(my, element_name, config, options, base_path, current_path, info, personal, use_same_config):
        li = HtmlElement.li()
        li.add_class("spt_side_bar_link")
        li.add_class("main_li")


        title = my._get_title(config, element_name)
        title_wdg = DivWdg()
        title_wdg.add_class("menu_header")
        li.add(title_wdg)
        title_wdg.add(title)


        ul = HtmlElement.ul()
        li.add(ul)
        ul.add_class("spt_side_bar_section")
        ul.add_class("sub_ul")

        # then get view name from options in order to read a new
        # config and recurse ...
        options_view_name = options.get('view')
        if options_view_name:
            if use_same_config:
                xml = config.get_xml()
                sub_config = WidgetConfig.get(xml=xml)
                sub_config.set_view(options_view_name)
            else:
                sub_config = my.get_config( my.config_search_type, options_view_name, default=my.default, personal=personal)

            info['level'] += 1
            my.generate_section( sub_config, ul, info, base_path=current_path, personal=personal, use_same_config=use_same_config )
            info['level'] -= 1

        return li
    def init(my):
        """initialize the widget_config, and from there retrieve the schema_config"""
        web = WebContainer.get_web()
        my.search_type = my.kwargs.get("search_type")

        element_name = my.kwargs.get("element_name")
        my.view = my.kwargs.get("view")

        # FIXME: comment out the assert for now to avoid error screen
        if not my.view:
            my.view = "table"
        # assert my.view

        my.config_xml = my.kwargs.get("config_xml")
        if not my.config_xml:
            my.config_xml = web.get_form_value("config_xml")

        my.default = my.kwargs.get("default") == "True"

        cbk = ManageSearchTypeDetailCbk(search_type=my.search_type, view=my.view, element_name=element_name)
        Command.execute_cmd(cbk)

        my.config_string = ""
        my.data_type_string = ""
        my.name_string = ""
        my.title_string = ""
        my.nullable_string = ""
        my.has_column = True

        if element_name:
            if my.config_xml:
                my.config_string = my.config_xml
                whole_config_string = "<config><%s>%s</%s></config>" % (my.view, my.config_xml, my.view)
                config = WidgetConfig.get(xml=whole_config_string, view=my.view)
                my.config = WidgetConfigView(my.search_type, my.view, [config])
            else:
                # don't pass in default here
                my.config = my.get_config(my.search_type, my.view)
                node = my.config.get_element_node(element_name)
                if node is not None:
                    config_xml = my.config.get_xml()

                    my.config_string = config_xml.to_string(node)
                    my.title_string = config_xml.get_attribute(node, "title")
            schema_config = SearchType.get_schema_config(my.search_type)

            attributes = schema_config.get_element_attributes(element_name)
            my.data_type_string = attributes.get("data_type")

            # double_precision is float
            if my.data_type_string == "double precision":
                my.data_type_string = "float"

            my.name_string = attributes.get("name")
            my.nullable_string = attributes.get("nullable")
            my.is_new_column = attributes.get("new") == "True"

            # a database columnless widget
            if not my.name_string:
                my.has_column = False
示例#10
0
    def get_async_element_wdg(my, xml, element_name, load):

        tmp_config = WidgetConfig.get("tmp", xml=xml)
        display_handler = tmp_config.get_display_handler(element_name)
        display_options = tmp_config.get_display_options(element_name)

        div = DivWdg()
        unique_id = div.set_unique_id()

        if load == "sequence":
            my.sequence_data.append({"class_name": display_handler, "kwargs": display_options, "unique_id": unique_id})
        else:
            div.add_behavior(
                {
                    "type": "load",
                    "class_name": display_handler,
                    "kwargs": display_options,
                    "cbjs_action": """
                spt.panel.async_load(bvr.src_el, bvr.class_name, bvr.kwargs);
                """,
                }
            )

        loading_div = DivWdg()
        loading_div.add_style("margin: auto auto")
        loading_div.add_style("width: 150px")
        loading_div.add_style("text-align: center")
        loading_div.add_style("padding: 20px")
        div.add(loading_div)
        loading_div.add("""<img src="/context/icons/common/indicator_snake.gif" border="0"/> <b>Loading ...</b>""")

        return div
示例#11
0
    def _get_main_config(my, view, process_names):
        '''get the main config for this table layout'''
        xml = Xml()
        xml.create_doc("config")
        root = xml.get_root_node()
        view_node = xml.create_element(view)
        #root.appendChild(view_node)
        xml.append_child(root, view_node)

        for idx, process_name in enumerate(process_names):
            element = xml.create_element('element')
            Xml.set_attribute(element, 'name', process_name)
            #view_node.appendChild(element)
            xml.append_child(view_node, element)
            display = xml.create_element('display')
            if my.element_class:
                Xml.set_attribute(display, 'class', my.element_class)
            else:
                Xml.set_attribute(display, 'class',
                                  "tactic.ui.app.NoteTableElementWdg")
            #element.appendChild(display)
            xml.append_child(element, display)

            op_element = xml.create_data_element('parent_key', my.search_key)
            xml.append_child(display, op_element)

        config_xml = xml.to_string()
        widget_config = WidgetConfig.get(view=view, xml=config_xml)
        widget_config_view = WidgetConfigView('sthpw/note', view,
                                              [widget_config])

        return widget_config_view
示例#12
0
    def _get_template_config(self):

        base_dir = Environment.get_install_dir()
        file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir
        if os.path.exists(file_path):
            widget_config = WidgetConfig.get(file_path=file_path, view='template')
        return widget_config
示例#13
0
    def get_async_element_wdg(my, xml, element_name, load):

        tmp_config = WidgetConfig.get('tmp', xml=xml)
        display_handler = tmp_config.get_display_handler(element_name)
        display_options = tmp_config.get_display_options(element_name)

        div = DivWdg()
        unique_id = div.set_unique_id()

        if load == "sequence":
            my.sequence_data.append( {
                'class_name': display_handler,
                'kwargs': display_options,
                'unique_id': unique_id
            } )
        else:
            div.add_behavior( {
                'type': 'load',
                'class_name': display_handler,
                'kwargs': display_options,
                'cbjs_action': '''
                spt.panel.async_load(bvr.src_el, bvr.class_name, bvr.kwargs);
                '''
            } )

        loading_div = DivWdg()
        loading_div.add_style("margin: auto auto")
        loading_div.add_style("width: 150px")
        loading_div.add_style("text-align: center")
        loading_div.add_style("padding: 20px")
        div.add(loading_div)
        loading_div.add('''<img src="/context/icons/common/indicator_snake.gif" border="0"/> <b>Loading ...</b>''')

        return div
    def _get_template_config(my):

        base_dir = Environment.get_install_dir()
        file_path = "%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir
        if os.path.exists(file_path):
            widget_config = WidgetConfig.get(file_path=file_path,
                                             view='template')
        return widget_config
示例#15
0
    def get_config(my):
        # TEST
        config_xml = '''
        <config>
        <custom_filter>
          <element name='asset_library'>
            <display class='SelectWdg'>
                <query>prod/asset_library|code|code</query>
                <empty>true</empty>
            </display>
          </element>
          <element name='pipeline_code'>
            <display class='SelectWdg'>
                <query>sthpw/pipeline|code|code</query>
                <empty>true</empty>
            </display>
          </element>
        </custom_filter>
        </config>
        '''

        my.view = my.kwargs.get("search_view")
        if not my.view:
            my.view = 'custom_filter'
        #view = "custom_filter"
        project_code = Project.extract_project_code(my.search_type)
        search = Search("config/widget_config", project_code=project_code )
        search.add_filter("view", my.view)
        
       
        search.add_filter("search_type", my.base_search_type)
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("config")
        
        else:
            config_xml = '''
            <config>
            <custom_filter>
            </custom_filter>
            </config>
            '''
            # use the one defined in the default config file
            file_configs = WidgetConfigView.get_configs_from_file(my.base_search_type, my.view)
            if file_configs:
                config = file_configs[0]
                xml_node = config.get_view_node()
                if xml_node is not None:
                    xml = Xml(config.get_xml().to_string())
                    config_xml = '<config>%s</config>' %xml.to_string(node=xml_node)

            


        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view=my.view, xml=config_xml)

        return config
示例#16
0
    def get_config(my):
        # TEST
        config_xml = '''
        <config>
        <custom_filter>
          <element name='asset_library'>
            <display class='SelectWdg'>
                <query>prod/asset_library|code|code</query>
                <empty>true</empty>
            </display>
          </element>
          <element name='pipeline_code'>
            <display class='SelectWdg'>
                <query>sthpw/pipeline|code|code</query>
                <empty>true</empty>
            </display>
          </element>
        </custom_filter>
        </config>
        '''

        my.view = my.kwargs.get("search_view")
        if not my.view:
            my.view = 'custom_filter'
        #view = "custom_filter"
        project_code = Project.extract_project_code(my.search_type)
        search = Search("config/widget_config", project_code=project_code )
        search.add_filter("view", my.view)
        
       
        search.add_filter("search_type", my.base_search_type)
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("config")
        
        else:
            config_xml = '''
            <config>
            <custom_filter>
            </custom_filter>
            </config>
            '''
            # use the one defined in the default config file
            file_configs = WidgetConfigView.get_configs_from_file(my.base_search_type, my.view)
            if file_configs:
                config = file_configs[0]
                xml_node = config.get_view_node()
                if xml_node is not None:
                    xml = Xml(config.get_xml().to_string())
                    config_xml = '<config>%s</config>' %xml.to_string(node=xml_node)

            


        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view=my.view, xml=config_xml)

        return config
示例#17
0
    def get_config(self):


        self.view = self.kwargs.get("search_view")
        config = self.kwargs.get("search_config")

        if not self.view:
            self.view = 'custom_filter'
        #view = "custom_filter"

        project_code = Project.extract_project_code(self.search_type)

        search = Search("config/widget_config", project_code=project_code )
        search.add_filter("view", self.view)
        search.add_filter("search_type", self.base_search_type)
        config_sobjs = search.get_sobjects()

        from pyasm.search import WidgetDbConfig
        config_sobj = WidgetDbConfig.merge_configs(config_sobjs)

        if config_sobj:
            #config_xml = config_sobj.get("config")
            config_xml = config_sobj.get_xml().to_string()
            config_xml = config_xml.replace("&lt;", "<")
            config_xml = config_xml.replace("&gt;", ">")
            config_xml = Common.run_mako(config_xml)

        elif config:
            config_xml = '''
            <config>
            <custom_filter>%s
            </custom_filter>
            </config>
            ''' % config
        else:
            config_xml = '''
            <config>
            <custom_filter>
            </custom_filter>
            </config>
            '''
            # use the one defined in the default config file
            file_configs = WidgetConfigView.get_configs_from_file(self.base_search_type, self.view)
            if file_configs:
                config = file_configs[0]
                xml_node = config.get_view_node()
                if xml_node is not None:
                    xml = Xml(config.get_xml().to_string())
                    config_xml = '<config>%s</config>' %xml.to_string(node=xml_node)

            
        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view=self.view, xml=config_xml)

        return config
示例#18
0
    def get_config(self):

        self.view = self.kwargs.get("search_view")
        config = self.kwargs.get("search_config")

        if not self.view:
            self.view = 'custom_filter'
        #view = "custom_filter"

        project_code = Project.extract_project_code(self.search_type)

        search = Search("config/widget_config", project_code=project_code)
        search.add_filter("view", self.view)
        search.add_filter("search_type", self.base_search_type)
        config_sobjs = search.get_sobjects()

        from pyasm.search import WidgetDbConfig
        config_sobj = WidgetDbConfig.merge_configs(config_sobjs)

        if config_sobj:
            #config_xml = config_sobj.get("config")
            config_xml = config_sobj.get_xml().to_string()
            config_xml = config_xml.replace("&lt;", "<")
            config_xml = config_xml.replace("&gt;", ">")
            config_xml = Common.run_mako(config_xml)

        elif config:
            config_xml = '''
            <config>
            <custom_filter>%s
            </custom_filter>
            </config>
            ''' % config
        else:
            config_xml = '''
            <config>
            <custom_filter>
            </custom_filter>
            </config>
            '''
            # use the one defined in the default config file
            file_configs = WidgetConfigView.get_configs_from_file(
                self.base_search_type, self.view)
            if file_configs:
                config = file_configs[0]
                xml_node = config.get_view_node()
                if xml_node is not None:
                    xml = Xml(config.get_xml().to_string())
                    config_xml = '<config>%s</config>' % xml.to_string(
                        node=xml_node)

        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view=self.view, xml=config_xml)

        return config
示例#19
0
    def get_config(self):

        self.view = self.kwargs.get("view")

        search = Search("config/widget_config")
        search.add_filter("category", "TabWdg")
        config_sobj = search.get_sobject()
        config_xml = config_sobj.get_value("config")
        config = WidgetConfig.get(view=self.view, xml=config_xml)

        return config
示例#20
0
    def get_config(my):

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

        search = Search("config/widget_config")
        search.add_filter("category", "TabWdg")
        config_sobj = search.get_sobject()
        config_xml = config_sobj.get_value("config")
        config = WidgetConfig.get(view=my.view, xml=config_xml)

        return config
示例#21
0
    def get_last_filter_config(search_type):

        # get the last search
        view = "saved_search:%s" % search_type

        search = Search('config/widget_config')
        search.add_filter("view", view)
        search.add_filter("search_type", search_type)
        search.add_user_filter()
        config_sobj = search.get_sobject()
        config = None
        if config_sobj:
            config_xml = config_sobj.get_xml_value("config")
            config = WidgetConfig.get(xml=config_xml, view='filter')
        return config
示例#22
0
    def get_last_filter_config(search_type):

        # get the last search
        view = "saved_search:%s" % search_type

        search = Search('config/widget_config')
        search.add_filter("view", view)
        search.add_filter("search_type", search_type)
        search.add_user_filter()
        config_sobj = search.get_sobject()
        config = None
        if config_sobj:
            config_xml = config_sobj.get_xml_value("config")
            config = WidgetConfig.get(xml=config_xml, view='filter')
        return config
示例#23
0
    def get_folder_wdg(self, element_name, config, options, base_path,
                       current_path, info, personal, use_same_config):

        attributes = config.get_element_attributes(element_name)
        if attributes.get("is_visible") == "false":
            return

        li = HtmlElement.li()
        li.add_class("spt_side_bar_link")
        li.add_class("main_li unselectable")

        title = self._get_title(config, element_name)
        title_wdg = DivWdg()
        title_wdg.add_class("menu_header")
        li.add(title_wdg)
        title_wdg.add(title)

        ul = HtmlElement.ul()
        li.add(ul)
        ul.add_class("spt_side_bar_section")
        ul.add_class("sub_ul unselectable")
        ul.add_style('cursor', 'pointer')

        # then get view name from options in order to read a new
        # config and recurse ...
        options_view_name = options.get('view')
        if options_view_name:
            if use_same_config:
                xml = config.get_xml()
                sub_config = WidgetConfig.get(xml=xml)
                sub_config.set_view(options_view_name)
            else:
                sub_config = self.get_config(self.config_search_type,
                                             options_view_name,
                                             default=self.default,
                                             personal=personal)

            info['level'] += 1
            self.generate_section(sub_config,
                                  ul,
                                  info,
                                  base_path=current_path,
                                  personal=personal,
                                  use_same_config=use_same_config)
            info['level'] -= 1

        return li
示例#24
0
    def get_config(my):

        my.view = my.kwargs.get("view")
        my.view = 'tab_config_whatever'

        search = Search("config/widget_config")
        search.add_filter("category", "TabWdg")
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("config")
        else:
            config_xml = '''
            <config>
              <tab>
              </tab>
            </config>'''
        config = WidgetConfig.get(view=my.view, xml=config_xml)

        return config
示例#25
0
    def get_config(self):

        self.view = self.kwargs.get("view")
        self.view = 'tab_config_whatever'

        search = Search("config/widget_config")
        search.add_filter("category", "TabWdg")
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("config")
        else:
            config_xml = '''
            <config>
              <tab>
              </tab>
            </config>'''
        config = WidgetConfig.get(view=self.view, xml=config_xml)

        return config
示例#26
0
 def get_default_filter_config(my):
     custom_filter_view = my.kwargs.get('custom_filter_view')
     config = '''
     <config>
     <filter>
       <element name='Filter'>
         <display class='tactic.ui.filter.GeneralFilterWdg'>
           <prefix>%(prefix_namespace)s_main_body</prefix>
           <search_type>%(search_type)s</search_type>
           <mode>sobject</mode>
         </display>
       </element>
     </filter>
     </config>
     ''' % {'search_type': my.searchable_search_type, 'prefix_namespace': my.prefix_namespace  }
     config_xml = Xml()
     config_xml.read_string(config)
     config = WidgetConfig.get(xml=config_xml, view='filter')
     return config
示例#27
0
 def get_default_filter_config(self):
     custom_filter_view = self.kwargs.get('custom_filter_view')
     config = '''
     <config>
     <filter>
       <element name='Filter'>
         <display class='tactic.ui.filter.GeneralFilterWdg'>
           <prefix>%(prefix_namespace)s_main_body</prefix>
           <search_type>%(search_type)s</search_type>
           <mode>sobject</mode>
         </display>
       </element>
     </filter>
     </config>
     ''' % {'search_type': self.searchable_search_type, 'prefix_namespace': self.prefix_namespace  }
     config_xml = Xml()
     config_xml.read_string(config)
     config = WidgetConfig.get(xml=config_xml, view='filter')
     return config
示例#28
0
    def get_folder_wdg(self, element_name, config, options, base_path, current_path, info, personal, use_same_config):

        attributes = config.get_element_attributes(element_name)
        if attributes.get("is_visible") == "false":
            return


        li = HtmlElement.li()
        li.add_class("spt_side_bar_link")
        li.add_class("main_li unselectable")


        title = self._get_title(config, element_name)
        title_wdg = DivWdg()
        title_wdg.add_class("menu_header")
        li.add(title_wdg)
        title_wdg.add(title)


        ul = HtmlElement.ul()
        li.add(ul)
        ul.add_class("spt_side_bar_section")
        ul.add_class("sub_ul unselectable")
        ul.add_style('cursor','pointer')

        # then get view name from options in order to read a new
        # config and recurse ...
        options_view_name = options.get('view')
        if options_view_name:
            if use_same_config:
                xml = config.get_xml()
                sub_config = WidgetConfig.get(xml=xml)
                sub_config.set_view(options_view_name)
            else:
                sub_config = self.get_config( self.config_search_type, options_view_name, default=self.default, personal=personal)

            info['level'] += 1
            self.generate_section( sub_config, ul, info, base_path=current_path, personal=personal, use_same_config=use_same_config )
            info['level'] -= 1

        return li
示例#29
0
文件: note_wdg.py 项目: mincau/TACTIC
 def _get_edit_config(self, view, process_names):
     xml = Xml()
     xml.create_doc("config")
     root = xml.get_root_node()
     view_node = xml.create_element(view)
     #root.appendChild(view_node)
     xml.append_child(root, view_node)
     for idx, process_name in enumerate(process_names):
         element  = xml.create_element('element')
         Xml.set_attribute(element, 'name', process_name)
         #view_node.appendChild(element)
         xml.append_child(view_node, element)
         display =   xml.create_element('display')
         Xml.set_attribute(display, 'class', "pyasm.widget.TextAreaWdg")
         #element.appendChild(display)
         xml.append_child(element, display)
     
     config_xml = xml.to_string()
     widget_config = WidgetConfig.get(view=view, xml = config_xml)
     widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config])
     return widget_config_view
示例#30
0
    def get_display(my):

        my.search_type = None

        my.view = 'tab'
        config_xml = my.get_config_xml()
        config = WidgetConfig.get(view=my.view, xml=config_xml)

        top = DivWdg()
        #tab = TabWdg(width=1000, save_state="admin_tab_state")
        tab = TabWdg(config=config, view=my.view, width=1000)
        top.add(tab)
        for widget in my.widgets:
            tab.add(widget)


        # set the current one active
        div = DivWdg()
        div.add_style("display: hidden")
        div.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        spt.tab.set_main_body_top();
        var headers = spt.tab.get_headers();
        // if there are no headers, then there was an error
        if (headers.length == 0) {
            return;
        }

        var name = headers[headers.length-1].getAttribute("spt_element_name");
        spt.tab.select(name);
        '''
        } )

        top.add(div)



        return top
示例#31
0
    def _get_edit_config(my, view, process_names):
        xml = Xml()
        xml.create_doc("config")
        root = xml.get_root_node()
        view_node = xml.create_element(view)
        #root.appendChild(view_node)
        xml.append_child(root, view_node)
        for idx, process_name in enumerate(process_names):
            element = xml.create_element('element')
            Xml.set_attribute(element, 'name', process_name)
            #view_node.appendChild(element)
            xml.append_child(view_node, element)
            display = xml.create_element('display')
            Xml.set_attribute(display, 'class', "pyasm.widget.TextAreaWdg")
            #element.appendChild(display)
            xml.append_child(element, display)

        config_xml = xml.to_string()
        widget_config = WidgetConfig.get(view=view, xml=config_xml)
        widget_config_view = WidgetConfigView('sthpw/note', view,
                                              [widget_config])
        return widget_config_view
示例#32
0
    def get_display(self):

        self.search_type = None

        self.view = 'tab'
        config_xml = self.get_config_xml()
        config = WidgetConfig.get(view=self.view, xml=config_xml)

        top = DivWdg()
        #tab = TabWdg(width=1000, save_state="admin_tab_state")
        tab = TabWdg(config=config, view=self.view, width=1000)
        top.add(tab)
        for widget in self.widgets:
            tab.add(widget)

        # set the current one active
        div = DivWdg()
        div.add_style("display: hidden")
        div.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
        spt.tab.set_main_body_top();
        var headers = spt.tab.get_headers();
        // if there are no headers, then there was an error
        if (headers.length == 0) {
            return;
        }

        var name = headers[headers.length-1].getAttribute("spt_element_name");
        spt.tab.select(name);
        '''
        })

        top.add(div)

        return top
示例#33
0
    def get_display(self):

        category = 'SerializeWdg'
        view = '123COW'

        sobjects = Search.eval("@SOBJECT(prod/asset)")
        element_names = ['preview', 'code', 'task_status']

        serializer = SObjectSerializer()
        serialized = serializer.create_config_xml("prod/asset", sobjects, element_names)



        search = Search("config/widget_config")
        search.add_filter("category", category)
        search.add_filter("view", view)
        config_sobj = search.get_sobject()

        serialized = config_sobj.get_xml_value("config")

        sobject_str = serialized.get_value("config/custom/element/display/sobjects")
        
        sobjects = serializer.loads("prod/asset", sobject_str)
        print sobjects

        top = DivWdg()
        self.set_as_panel(top)
        print top.attrs

        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view='custom', xml=serialized)
        widget = config.get_display_widget("custom")
        widget.set_sobjects(sobjects[1:3])

        top.add(widget)
        return top
示例#34
0
    def get_display(my):

        category = 'SerializeWdg'
        view = '123COW'

        sobjects = Search.eval("@SOBJECT(prod/asset)")
        element_names = ['preview', 'code', 'task_status']

        serializer = SObjectSerializer()
        serialized = serializer.create_config_xml("prod/asset", sobjects, element_names)



        search = Search("config/widget_config")
        search.add_filter("category", category)
        search.add_filter("view", view)
        config_sobj = search.get_sobject()

        serialized = config_sobj.get_xml_value("config")

        sobject_str = serialized.get_value("config/custom/element/display/sobjects")
        
        sobjects = serializer.loads("prod/asset", sobject_str)
        print sobjects

        top = DivWdg()
        my.set_as_panel(top)
        print top.attrs

        from pyasm.widget import WidgetConfig
        config = WidgetConfig.get(view='custom', xml=serialized)
        widget = config.get_display_widget("custom")
        widget.set_sobjects(sobjects[1:3])

        top.add(widget)
        return top
    def get_element_wdg(my, xml, def_config):

        element_node = xml.get_node("config/tmp/element")
        attrs = Xml.get_attributes(element_node)
        element_name = attrs.get("name")

        widget = my.get_widget(element_name)
        if widget:
            return widget


        if not element_name:
            import random
            num = random.randint(0, 100000)
            element_name = "element%s" % num
            xml.set_attribute(element_node, "name", element_name)


        # enable an ability to have a widget only loaded once in a request
        if attrs.get('load_once') in ['true', True]:
            widgets = Container.get("CustomLayoutWdg:widgets")
            if widgets == None:
                widgets = {}
                Container.put("CustomLayoutWdg:widgets", widgets)
            else:
                if widgets[element_name] == True:
                    return None

                widgets[element_name] = True


        # provide the ability to have shorthand format 
        # ie: <element display_class="tactic.ui..." />
        display_node = xml.get_node("config/tmp/element/display")
        if display_node is None:
            view = attrs.get("view")
            type = attrs.get("type")

            if type == "reference":
                search_type = attrs.get("search_type")
                my.config = WidgetConfigView.get_by_search_type(search_type, view)
                # check if definition has no name.  Don't use element_name
                if not attrs.get("name"):
                    return

                element_wdg = my.config.get_display_widget(element_name, extra_options=attrs)
                container = DivWdg()
                container.add(element_wdg)
                return container


            class_name = attrs.get("display_class")

            # if no class name is defined and not view is defined look
            # at predefined elements
            if not view and not class_name:
                element_wdg = my.config.get_display_widget(element_name, extra_options=attrs)
                container = DivWdg()
                container.add(element_wdg)
                return container


            # look at the attributes
            if not class_name:
                class_name = "tactic.ui.panel.CustomLayoutWdg"
            display_node = xml.create_element("display")
            xml.set_attribute(display_node, "class", class_name)
            xml.append_child(element_node, display_node)

            for name, value in attrs.items():
                # replace the spt_ in the name.
                # NOTE: should this be restricted to only spt_ attributes?
                name = name.replace("spt_", "")
                attr_node = xml.create_element(name)
                xml.set_node_value(attr_node, value)
                xml.append_child(display_node, attr_node)


        load = attrs.get("load")
        if load in ["async", "sequence"]:
            return my.get_async_element_wdg(xml, element_name, load)




        use_container = attrs.get('use_container') == 'true'
        if use_container:
            # DEPRECATED
            container = my.get_container(xml)
        else:
            container = DivWdg()

        # add in attribute from the element definition
        # DEPRECATED: does this make any sense to have this here?
        for name, value in attrs.items():
            if name == 'name':
                continue
            container.add_style(name, value)






        # add the content
        try:
            view_node = xml.get_node("config/tmp/element/display/view")
            if view_node is not None:
                view = xml.get_node_value(view_node)
                if view.startswith("."):
                    if my.view_folder:
                        xml.set_node_value(view_node, "%s%s" %(my.view_folder,view))
            tmp_config = WidgetConfig.get('tmp', xml=xml)
            configs = []
            configs.append(tmp_config)

            # add the def_config if it exists
            if def_config:
                configs.append(def_config)

            config = WidgetConfigView('CustomLayoutWdg', 'tmp', configs, state=my.state)

            # NOTE: this doesn't work too well when we go to an abasolute
            # view.
            parent_view = my.kwargs.get("parent_view")
            if parent_view:
                parent_view = parent_view.replace(".", "/")
                parent_view = "%s/%s" % (parent_view, my.view)
            else:
                parent_view = my.view

            # NOTE: need some protection code for infinite loops


            includes = my.kwargs.get("include")
            element_wdg = config.get_display_widget(element_name, extra_options={"include":includes, "parent_view":parent_view})

            element_top = element_wdg.get_top()
            for name, value in attrs.items():
                if name == 'class':
                    for item in value.split(" "):
                        element_top.add_class(item)

                elif name == 'style':
                    for item in re.split(";\ ?", value):
                        element_top.add_style(item)

                else:
                    element_top.set_attr(name, value)




            # make a provision if this custom widget is in a table
            if my.layout:
                sobject = my.get_current_sobject()
                element_wdg.set_sobject(sobject)



        except Exception, e:
            from pyasm.widget import ExceptionWdg
            log = ExceptionWdg(e)
            element_wdg = log
示例#36
0
    def __init__(my):

        key = "WidgetClassHandler:config"
        my.config = Container.get(key)
        if my.config != None:
            return

        base_config = """
        <config>
        <widget_definition>
        <element name='simple'>
            <display class='tactic.ui.common.SimpleTableElementWdg'/>
        </element>

        <element name='default'>
            <display class='tactic.ui.common.SimpleTableElementWdg'/>
        </element>



        <element name='raw_data' help='main'>
            <display class='tactic.ui.common.RawTableElementWdg'/>
        </element>


        <element name='format' help='format-element-wdg'>
            <display class='tactic.ui.table.FormatElementWdg'/>
        </element>


        <element name='expression' help='search'>
            <display class='tactic.ui.table.ExpressionElementWdg'/>
        </element>

        <element name='expression_value' help='expression-value-element-wdg'>
            <display class='tactic.ui.table.ExpressionValueElementWdg'/>
        </element>
        <element name='link' help='link-element-wdg'>
            <display class='tactic.ui.table.LinkElementWdg'/>
        </element>



        <element name='completion' help='task-completion-wdg'>
            <display class='tactic.ui.table.TaskCompletionWdg'/>
        </element>

        <element name='gantt' help='gantt-wdg'>
            <display class='tactic.ui.table.GanttElementWdg'/>
        </element>
        <element name='button'>
            <display class='tactic.ui.table.ButtonElementWdg'/>
        </element>


        <element name='custom_layout' help='custom-layout-wdg'>
        <!--
            <display class='tactic.ui.panel.CustomLayoutWdg'/>
        -->
            <display class='tactic.ui.table.CustomLayoutElementWdg'/>
        </element>

        <element name='freeform_layout'>
            <display class='tactic.ui.table.FreeFormLayoutElementWdg'/>
        </element>

        <element name='delete'>
            <display class='tactic.ui.table.DeleteElementWdg'/>
        </element>

        <element name='edit_layout'>
            <display class='tactic.ui.panel.EditWdg'/>
        </element>

        <element name='table_layout'>
            <display class='tactic.ui.panel.TableLayoutWdg'/>
        </element>
        <element name='fast_table_layout'>
            <display class='tactic.ui.panel.FastTableLayoutWdg'/>
        </element>
        <element name='tile_layout'>
            <display class='tactic.ui.panel.TileLayoutWdg'/>
        </element>
        <element name='fast_layout'>
            <display class='tactic.ui.panel.table_layout_wdg.FastTableLayoutWdg'/>
        </element>
        <element name='view_panel'>
            <display class='tactic.ui.panel.ViewPanelWdg'/>
        </element>

        <element name='freeform_layout'>
            <display class='tactic.ui.tools.freeform_layout_wdg.FreeFormLayoutWdg'/>
        </element>



        <element name='explorer'>
            <display class='tactic.ui.table.ExploreElementWdg'/>
        </element>

        <element name='hidden_row'>
            <!--
            <display class='pyasm.widget.HiddenRowToggleWdg'/>
            -->
            <display class='tactic.ui.table.HiddenRowElementWdg'/>
        </element>

        <element name='text'>
        <!--
            <display class='tactic.ui.input.TextInputWdg'/>
        -->
            <display class='pyasm.widget.TextWdg'/>
        </element>
        <element name='select'>
            <display class='pyasm.widget.SelectWdg'/>
        </element>
        <element name='calendar'>
            <display class='tactic.ui.widget.CalendarInputWdg'/>
        </element>
        <element name='calendar_time'>
            <display class='tactic.ui.widget.CalendarInputWdg'>
              <show_time>true</show_time>
            </display>
        </element>
        <element name='time'>
            <display class='tactic.ui.widget.TimeInputWdg'/>
        </element>

        <element name='color'>
            <display class='tactic.ui.input.ColorInputWdg'/>
        </element>

        <element name='drop_item' help='drop-element-wdg'>
            <display class='tactic.ui.table.DropElementWdg'/>
        </element>

        <element name='file_list'>
            <display class="tactic.ui.table.SObjectFilesElementWdg"/>
        </element>

        <element name='metadata'>
            <display class="tactic.ui.table.MetadataElementWdg"/>
        </element>

        <element name='python'>
            <display class="tactic.ui.table.PythonElementWdg"/>
        </element>


        </widget_definition>
        </config>
        """
        from pyasm.widget import WidgetConfig

        my.config = WidgetConfig.get(view="widget_definition", xml=base_config)

        # customize config to register widgets
        # path = "xxx.conf"

        Container.put(key, my.config)
    def get_display(my):
        is_admin_project = Project.get().is_admin()
        security = Environment.get_security() 
        if is_admin_project and not security.check_access("builtin", "view_site_admin", "allow"):
            return Error403Wdg()
                
        # create the elements
        config = WidgetConfig.get(xml=my.config_xml, view="application")

        left_nav_handler = config.get_display_handler("left_nav")
        left_nav_options = config.get_display_options("left_nav")

        view_side_bar = None
        if left_nav_handler:
            left_nav_wdg = Common.create_from_class_path(left_nav_handler, [], left_nav_options)

            # caching
            side_bar_cache = my.get_side_bar_cache(left_nav_wdg)
        else:
            view_side_bar = False

        # create the main table
        core_table = Table()
        core_table.add_tbody()
        core_table.set_style("border: 0px; border-collapse: collapse; width: 100%;")


        # add a spacer row
        #spacer_tr = core_table.add_row()
        #spacer_tr.add_style("width: 100%")
        #td = core_table.add_cell()
        #td.set_style("min-height: 1px; height: 1px;")
        #core_table.add_cell()
        #core_table.add_cell()

        # determine if the side bar is visible
        if view_side_bar == None:
            view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow')


        # add the main cells
        tr, td = core_table.add_row_cell()
        td.add_style("padding: 0px")
        td.add_style("margin: 0px")

        # add the main resizable table
        from tactic.ui.container import ResizableTableWdg
        main_table = ResizableTableWdg()
        main_table.set_keep_table_size()

        main_table.add_style("width: 100%")

        td.add(main_table)

        left_nav_td = main_table.add_cell()
        if view_side_bar:
            left_nav_td.add_class("spt_panel")
            left_nav_td.add_style("padding: 0px")

        main_body_td = main_table.add_cell(resize=False)
        main_body_td.add_style("padding: 10px")
        main_body_td.set_style( "width: 100%; vertical-align: top; text-align: center; padding-top: 3px" )

        if view_side_bar:
            left_nav_td.set_style( "vertical-align: top" )

            # create the left navigation panel
            left_nav_div = DivWdg()
            left_nav_td.add(left_nav_div)

            left_nav_div.set_id("side_bar" )
            # add the detail to the panel
            left_nav_div.add_attr("spt_class_name", left_nav_handler)
            for name, value in left_nav_options.items():
                left_nav_div.add_attr("spt_%s" % name, value)


            left_nav_div.add_style("max_width: 185px")
            left_nav_div.add_style("width: 185px")
            left_nav_div.add_style("text-align: right")
            left_nav_div.add_style("vertical-align: top")
            left_nav_div.add_style("overflow: hidden")

            left_nav_div.add_class("spt_resizable")
            side_bar_inner = DivWdg()
            left_nav_div.add(side_bar_inner)

            #side_bar_inner.add_style("padding-left: 1px")
            side_bar_inner.add_style("width: 100%")

            # add side bar to nav
            side_bar_inner.add(side_bar_cache)

            left_nav_div.add_style("border-style: solid")
            left_nav_div.add_style("border-width: 0px 1px 0px 0px")
            #left_nav_div.add_color("border-color", "border")
            left_nav_div.add_color("border-color", "border", -10)

            web = WebContainer.get_web()
            browser = web.get_browser()
            if browser in ['Qt','Webkit']:
                min_width = "1px"
            else:
                min_width = "0px"

            left_nav_div.add_behavior( {
                'type': 'listen',
                'event_name': 'side_bar|hide_now',
                'min_width': min_width,
                'cbjs_action': '''
                var size = bvr.src_el.getSize();
                bvr.src_el.setAttribute("spt_size", size.x);
                bvr.src_el.setStyle("width", bvr.min_width);

                '''
            } )


            left_nav_div.add_behavior( {
                'type': 'listen',
                'event_name': 'side_bar|hide',
                'min_width': min_width,
                'cbjs_action': '''
                var size = bvr.src_el.getSize();
                bvr.src_el.setAttribute("spt_size", size.x);
                new Fx.Tween(bvr.src_el, {duration:'short'}).start('width', bvr.min_width);

                '''
            } )


            left_nav_div.add_behavior( {
                'type': 'listen',
                'event_name': 'side_bar|show',
                'min_width': min_width,
                'cbjs_action': '''
                var width = bvr.src_el.getAttribute("spt_size");
                if (!width) {
                   width = 185;
                }
                if (parseInt(width) < 5) {
                    width = 185;
                }
                //bvr.src_el.setStyle("width", width + "px");
                new Fx.Tween(bvr.src_el, {duration:'short'}).start('width', bvr.min_width, width+"px");
                '''
            } )


            left_nav_div.add_behavior( {
                'type': 'listen',
                'event_name': 'side_bar|toggle',
                'cbjs_action': '''
                var size = bvr.src_el.getSize();
                if (size.x < 5) {
                    spt.named_events.fire_event("side_bar|show", {} );
                }
                else {
                    spt.named_events.fire_event("side_bar|hide", {} );
                }
                '''
            } )




        # create the main body panel

        palette = WebContainer.get_palette()
        color = palette.color("background2")
        main_body_rounded = DivWdg()
        main_body_inner = main_body_rounded

        main_body_inner.add_style("min-height: 500px")


        # DEBREACATED
        """
        # add a breadcrumb
        breadcrumb_wdg = DivWdg()
        # hide the breadcrumb
        breadcrumb_wdg.add_style("display", "none")
        Container.put("breadcrumb", breadcrumb_wdg)
        breadcrumb_wdg.set_id("breadcrumb")
        breadcrumb_wdg.add_style("text-align: left")
        breadcrumb_wdg.add_looks( "fnt_title_3" )
        main_body_inner.add(breadcrumb_wdg)
        """

        main_body_panel = DivWdg()
        main_body_panel.set_id("main_body")
        main_body_panel.add_class("spt_main_panel")
        main_body_inner.add(main_body_panel)


        tab = MainBodyTabWdg()
        main_body_panel.add(tab)

        # TEST: NEW LAYOUT
        if Config.get_value("install", "layout") == "fixed":
            main_body_panel.add_style("margin-top: 31px")
            main_body_rounded.add_color("background", "background")
            main_body_rounded.add_style("padding: 3px 0px 0px 0px")



        # add the content to the main body panel
        try:
            if my.widget:
                tab.add(my.widget)
                element_name = my.widget.get_name()

            else:
                main_body_handler = config.get_display_handler("main_body")
                main_body_options = config.get_display_options("main_body")
                element_name = main_body_options.get("element_name")
                title = main_body_options.get("title")

                main_body_content = Common.create_from_class_path(main_body_handler, [], main_body_options)
                # get the web values from top_layout
                main_body_values = config.get_web_options("main_body")
                web = WebContainer.get_web()
                if isinstance(main_body_values, dict):
                    for name, value in main_body_values.items():
                        web.set_form_value(name, value)

                main_body_content.set_name(element_name)
                tab.add(main_body_content, element_name, title)

                my.set_as_panel(main_body_panel, class_name=main_body_handler, kwargs=main_body_options)

            main_body_panel.add_behavior( {
                'type': 'load',
                'element_name': element_name,
                'cbjs_action': '''
                if (spt.help)
                    spt.help.set_view(bvr.element_name);
                '''
            } )


           
        except Exception, e:
            # handle an error in the drawing
            buffer = my.get_buffer_on_exception()
            error_wdg = my.handle_exception(e)
            main_body_content = DivWdg()
            main_body_content.add(error_wdg)
            main_body_content = main_body_content.get_buffer_display()
            tab.add(main_body_content, element_name, title)
示例#38
0
    def get_display(my):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_gradient("background", "background", 0, -5)
        #top.add_style("height: 550px")

        top.add_class("spt_reports_top")
        my.set_as_panel(top)

        inner = DivWdg()
        top.add(inner)


        title = DivWdg()
        title.add("Reports")
        title.add_style("font-size: 18px")
        title.add_style("font-weight: bold")
        title.add_style("text-align: center")
        title.add_style("padding: 10px")
        title.add_style("margin: -10px -10px 0px -10px")

        inner.add(title)
        title.add_gradient("background", "background3", 5, -10)


        from tactic.ui.widget import TitleWdg
        subtitle = TitleWdg(name_of_title='List of Built in Reports',help_alias='main')
        inner.add(subtitle)
        inner.add("<br/>")

        button_div = DivWdg()
        inner.add(button_div)
        button_div.add_class("spt_buttons_top")
        button_div.add_style("margin-top: -5px")
        button_div.add_style("margin-bottom: 30px")
        button_div.add_border()

        button_div.add_style("margin-top: -15px")
        button_div.add_style("margin-bottom: 0px")
        button_div.add_style("width: 100%")
        button_div.add_style("height: 33px")
        button_div.add_color("background", "background2")
        button_div.add_style("margin-left: auto")
        button_div.add_style("margin-right: auto")


        button = SingleButtonWdg(title="Collapse", icon=IconWdg.HOME)
        button_div.add(button)
        button.add_style("float: left")
        button.add_style("left: 5px")
        button.add_style("top: 5px")


        # FIXME: get home for the user
        #home = 'tactic.ui.startup.ContentCreatorWdg'
        home = 'tactic.ui.startup.MainWdg'


        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tab.set_main_body_tab();
            var class_name = 'tactic.ui.startup.MainWdg';
            var kwargs = {
                help_alias: 'main'
                };
            spt.tab.add_new("_startup", "Startup", class_name, kwargs);

            '''
        } )



        """
        button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP)
        button_div.add(button)
        button.add_class("spt_collapse")
        inner.add(button_div)
        button.add_style("float: left")
        button.add_style("left: 5px")
        button.add_style("top: 5px")

        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_reports_top");
            var element = top.getElement(".spt_reports_list");

            var buttons = bvr.src_el.getParent(".spt_buttons_top");
            expand = buttons.getElement(".spt_expand");
            new Fx.Tween(element).start('margin-top', "-400px");
            expand.setStyle("display", "");
            bvr.src_el.setStyle("display", "none");
            '''
        } )

        button = SingleButtonWdg(title="Expand", icon=IconWdg.ARROW_DOWN)
        button.add_style("display: none")
        button.add_class("spt_expand")
        button_div.add(button)
        button.add_style("left: 5px")
        button.add_style("top: 5px")
        inner.add(button_div)
        button.add_style("float: left")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_reports_top");
            var element = top.getElement(".spt_reports_list");

            var buttons = bvr.src_el.getParent(".spt_buttons_top");
            collapse = buttons.getElement(".spt_collapse");
            new Fx.Tween(element).start('margin-top', "0px");
            collapse.setStyle("display", "");
            bvr.src_el.setStyle("display", "none");
            '''
        } )
        """



        reports = []

        # read the config file
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path="%s/../config/reports-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")

        category = my.kwargs.get('category')

        # get all of the configs from the database
        if not category or category in ["custom_reports", "custom_charts"]:
            search = Search("config/widget_config")
            search.add_op("begin")
            if category == "custom_reports":
                search.add_filter("widget_type", "report")
            elif category == "custom_charts":
                search.add_filter("widget_type", "chart")
            elif not category:
                search.add_filters("widget_type", ["chart","report"])

            search.add_op("or")
            db_configs = search.get_sobjects()
        else:
            db_configs = []


        element_names = my.kwargs.get("element_names")
        if element_names is None:
            element_names = config.get_element_names()



        project = Project.get()

        for element_name in element_names:
            key = {'project': project.get_code(), 'element': element_name}
            key2 = {'project': project.get_code(), 'element': '*'}
            key3 = {'element': element_name}
            key4 = {'element': '*'}
            keys = [key, key2, key3, key4]
            if not top.check_access("link", keys, "view", default="deny"):
                continue

            attrs = config.get_element_attributes(element_name)
            report_data = {}
            kwargs = config.get_display_options(element_name)
            class_name = kwargs.get('class_name')

            # the straight xml definition contains the sidebar class_name
            # with LinkWdg ... we shouldn't use this, so build the
            # element from scratch
            #xml = config.get_element_xml(element_name)
            from pyasm.search import WidgetDbConfig
            xml = WidgetDbConfig.build_xml_definition(class_name, kwargs)

            report_data['class_name'] = class_name
            report_data['kwargs'] = kwargs
            report_data['title'] = attrs.get("title")
            report_data['description'] = attrs.get("description")
            report_data['image'] = attrs.get("image")
            report_data['xml'] = xml

            reports.append(report_data)



        for db_config in db_configs:
            element_name = db_config.get_value("view")
            key = {'project': project.get_code(), 'element': element_name}
            key2 = {'project': project.get_code(), 'element': '*'}
            key3 = {'element': element_name}
            key4 = {'element': '*'}
            keys = [key, key2, key3, key4]
            if not top.check_access("link", keys, "view", default="deny"):
                continue

            report_data = {}
            view = db_config.get_value("view")
            kwargs = {
                'view': view
            }
            parts = view.split(".")
            title = Common.get_display_title(parts[-1])

            xml = db_config.get_value("config")

            report_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg"
            report_data['kwargs'] = kwargs
            report_data['title'] = title
            report_data['description'] = title
            report_data['image'] = None
            report_data['xml'] = xml
            report_data['widget_type'] = db_config.get_value("widget_type")
            if report_data['widget_type'] == 'report':
                report_data['category'] = "custom_reports"
            elif report_data['widget_type'] == 'chart':
                report_data['category'] = "custom_charts"


            reports.append(report_data)





        """
        report_data = {
            'title': 'Tasks Completed This Week',
            'class_name': 'tactic.ui.panel.ViewPanelWdg',
            'kwargs': {
                    'search_type': 'sthpw/task',
                    'view': 'table'
                },
        }
        reports.append(report_data)
        """
        if category == 'list_item_reports' or not category:
            search_types = Project.get().get_search_types()
            for search_type in search_types:
                base_key = search_type.get_base_key()

                key = {'project': project.get_code(), 'code': base_key}
                key2 = {'project': project.get_code(), 'code': '*'}
                key3 = {'code': base_key}
                key4 = {'code': '*'}
                keys = [key, key2, key3, key4]
                if not top.check_access("search_type", keys, "view", default="deny"):
                    continue


                if not SearchType.column_exists(base_key, "pipeline_code"):
                    continue

                thumb_div = DivWdg()
                image = thumb_div
                thumb_div.add_border()
                thumb_div.set_box_shadow("1px 1px 1px 1px")
                thumb_div.add_style("width: 60px")

                thumb = ThumbWdg()
                thumb_div.add(thumb)
                thumb.set_sobject(search_type)
                thumb.set_icon_size(60)

                report_data = {
                    'title': '%s Workflow Status' % search_type.get_title(),
                    'description': 'Number of items in each process',
                    'class_name': 'tactic.ui.report.stype_report_wdg.STypeReportWdg',
                    'kwargs': {
                        'search_type': base_key
                    },
                    'image': thumb_div
                }
                reports.append(report_data)

 
                report_data = {
                    'title': '%s Labor Cost Report' % search_type.get_title(),
                    'description': 'Labor Cost Breakdown for each Item',
                    'class_name': 'tactic.ui.panel.ViewPanelWdg',
                    'kwargs': {
                        'search_type': search_type.get_code(),
                        'view': "table",
                        'show_header': False,
                        'mode': 'simple',
                        'element_names': "preview,code,title,cost_breakdown,bid_hours,bid_cost,actual_hours,actual_cost,overbudget,variance"
                    },
                    'image': IconWdg("", IconWdg.REPORT_03)
                }
                reports.append(report_data)



        table2 = Table()
        inner.add(table2)
        table2.add_style("width: 100%")


        categories_div = DivWdg()
        td = table2.add_cell(categories_div)
        td.add_style("vertical-align: top")
        td.add_style("width: 200px")
        td.add_color("background", "background3")
        td.add_border()

        #categories_div.add_style("margin: -1px 0px 0px -1px")
        categories_div.add_style("padding-top: 10px")
        #categories_div.add_style("float: left")
        categories_div.add_color("color", "color3")


        categories = config.get_all_views()
        categories.insert(-1, "list_item_reports")
        categories.insert(-1, "custom_charts")
        categories.insert(-1, "custom_reports")

        table_div = DivWdg()
        td = table2.add_cell(table_div)
        td.add_style("vertical-align: top")
        table_div.add_class("spt_reports_list")
        table_div.add_border()
        table_div.add_color("background", "background", -5)

        table_div.add_style("min-height: 500px")



        for i, category in enumerate(categories):

            if i == len(categories) - 1:
                categories_div.add("<hr/>")


            config.set_view(category)
            element_names = config.get_element_names()

            if category == "definition":
                title = "All Reports"
            else:
                title = Common.get_display_title(category)


            category_div = DivWdg()
            categories_div.add(category_div)
            category_div.add(title)
            category_div.add_style("padding: 5px")
            category_div.add_class("hand")

            category_div.add_behavior( {
            'type': 'click_up',
            'category': category,
            'element_names': element_names,
            'class_name': Common.get_full_class_name(my),
            'cbjs_action': '''
            var kwargs = {
                is_refresh: true,
                category: bvr.category,
                element_names: bvr.element_names
            }

            //spt.panel.refresh(top, kwargs);
            var top = bvr.src_el.getParent(".spt_reports_top");
            spt.panel.load(top, bvr.class_name, kwargs);
            '''
            } )

            bgcolor = category_div.get_color("background3", -10)
            category_div.add_behavior( {
            'type': 'mouseover',
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.bgcolor);
            '''
            } )
            category_div.add_behavior( {
            'type': 'mouseout',
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "");
            '''
            } )








        # create a bunch of panels
        table = Table()
        table_div.add(table)
        table.add_color("color", "color")
        table.add_style("margin-top: 20px")
        table.center()
        table_div.add_style("margin: -3px -3px -1px -2px")


        if not reports:
            tr = table.add_row()
            td = table.add_cell()
            td.add("There are no reports defined.")
            td.add_style("padding: 50px")

            if my.kwargs.get("is_refresh") in ['true', True]:
                return inner
            else:
                return top



        for i, report in enumerate(reports):

            #if i == 0 or i%4 == 0:
            if i%3 == 0:
                tr = table.add_row()

            td = table.add_cell()
            td.add_style("vertical-align: top")
            td.add_style("padding: 3px")
            title = report
            #description = '''The schema is used to layout the basic components of your project.  Each component represents a list of items that you use in your business everyday.'''

            description = report.get("title")

            # Each node will contain a list of "items" and will be stored as a table in the database.'''

            class_name = report.get("class_name")
            kwargs = report.get("kwargs")
            title = report.get("title")
            description = report.get("description")
            widget_type = report.get("widget_type")

            image = report.get("image")
            icon = report.get("icon")
            xml = report.get("xml")

            if image:
                div = DivWdg()
                if isinstance(image, basestring):
                    image = image.upper()
                    image = eval("IconWdg('', IconWdg.%s)" % image)
                    div.add_style("margin-left: 15px")
                    div.add_style("margin-top: 5px")
                else:
                    image = image
                div.add(image)
                image = div

            elif icon:
                icon = icon.upper()
                image = eval("IconWdg('', IconWdg.%s)" % icon)

            else:
                div = DivWdg()
                """
                import random
                num = random.randint(0,3)
                if num == 1:
                    image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_01)
                elif num == 2:
                    image = IconWdg("Bar Chart", IconWdg.GRAPH_LINE_01)
                else:
                    image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_02)
                """

                if widget_type == "chart":
                    image = IconWdg("Chart", IconWdg.GRAPH_BAR_02)
                else:
                    image = IconWdg("No Image", IconWdg.WARNING)
                div.add_style("margin-left: 15px")
                div.add_style("margin-top: 5px")
                div.add(image)
                image = div


            behavior = {
            'type': 'click_up',
            'title': title,
            'class_name': class_name,
            'kwargs': kwargs,
            'cbjs_action': '''

            spt.tab.set_main_body_tab();
            //var top = bvr.src_el.getParent(".spt_reports_top");
            //spt.tab.set_tab_top(top);
            spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs);
            '''
            }
            schema_wdg = my.get_section_wdg(title, description, image, behavior)

            schema_wdg.add_behavior( {
            'type': 'load',
            'title': title,
            'class_name': class_name,
            'xml': xml,
            'kwargs': kwargs,
            'cbjs_action': '''
                var report_top = bvr.src_el;
                report_top.kwargs = bvr.kwargs;
                report_top.class_name = bvr.class_name;
                report_top.element_name = bvr.title;
                report_top.xml = bvr.xml;
            '''
            } )

            td.add(schema_wdg)


        inner.add("<br/>")



        #from tactic.ui.container import TabWdg
        #tab = TabWdg(show_add=False)
        #inner.add(tab)

        if my.kwargs.get("is_refresh") in ['true', True]:
            return inner
        else:
            return top
示例#39
0
    def get_config(cls, config_search_type, view, default=False):

        config = None
        configs = []
        login = None
        defined_view = view

        # this is really for the predefined view that shouldn't go to the db
        # otherwise, it is a never ending cycle.
        if default:
            views = [defined_view, 'definition']
            cls.add_internal_config(configs, views)

        # special condition for children
        elif view in ['children']:
            tmp_path = __file__
            dir_name = os.path.dirname(tmp_path)
            file_path = "%s/../config/children-conf.xml" % (dir_name)
            config = WidgetConfig.get(file_path=file_path, view=defined_view)
            configs.append(config)

        elif view == "definition":
            # look for a definition in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", config_search_type)
            search.add_filter("view", "definition")
            # lower the chance of getting some other definition files
            search.add_filter("login", None)
            config = search.get_sobject()
            if config:
                configs.append(config)
            # We should not allow redefinition of a predefined item
            # so it is fine to add internal config for definition
            # then look for a definition in the definition file
            cls.add_internal_config(configs, ['definition'])

        else:
            # first look in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", config_search_type)
            search.add_filter("view", view)
            #search.add_filter("login", login)

            config = search.get_sobject()
            if config:
                configs.append(config)
            # then look for a file
            cls.add_internal_config(configs, [defined_view])

            # look for a definition in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", config_search_type)
            search.add_filter("view", "definition")
            # lower the chance of getting some other definition files
            search.add_filter("login", None)
            config = search.get_sobject()
            if config:
                configs.append(config)

            # then look for a definition in the definition file
            cls.add_internal_config(configs, ['definition'])

        widget_config_view = WidgetConfigView(config_search_type, view,
                                              configs)
        return widget_config_view
示例#40
0
    def get_display(self):

        top = self.top
        top.add_class("spt_switcher_top")
        
        '''
        This supports supports two menu definitions:
        menu - specifies a view for SideBarWdg which will be ingected as menu 
        config_xml - specifies menu entries. For example:

        <display class="tactic.ui.widget.LayoutSwitcherWdg">
          <!-- config_xml -->
          <config>
            <!-- Menu item 1 -->
            <element name="self_tasks_default" title="My Tasks" target=spt_my_tasks_table_top">
              <display class="tactic.ui.panel.ViewPanelWdg">
                <search_type>sthpw/task</search_type>
                <show_shelf>false</show_shelf>
                <view>my_tasks_default</view>
              </display>
            </element>
            <!-- Menu item 2 -->
            <element ... >
              <display ... >
              </display>
            </element>
          </config>
        </display>

        target - specifies target div to load views when using "menu" kwarg
        use_href - updates address bar hash (this is TODO)
        '''
        
        menu = self.kwargs.get("menu")
        config_xml = self.kwargs.get("config_xml")
        target = self.kwargs.get("target")

        #default
        default_layout = self.kwargs.get("default_layout")

        # find the save state value, if state is to be saved
        save_state = self.kwargs.get("save_state")

        if save_state in [False, 'false']:
            save_state = None
            show_first = False
        else:
            show_first = True

        state_value = None
        if save_state:
            state_value = WidgetSettings.get_value_by_key(save_state)
        elif default_layout:
            state_value = default_layout

        title = self.kwargs.get("title")
        if not title and state_value:
            title = state_value
        if not title:
            title = "Switch Layout"

        mode = self.kwargs.get("mode")
        if mode == "button":
            color = self.kwargs.get("color") or "default"
            activator = DivWdg("<button class='btn btn-%s dropdown-toggle' style='width: 160px'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (color, title))
        elif mode == "div":
            color = self.kwargs.get("color") or ""
            background = self.kwargs.get("background") or "transparent"
            activator = DivWdg("<button class='btn dropdown-toggle' style='width: 160px; background: %s; color: %s; font-weight: bold'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (background, color, title))

        else:
            activator = IconButtonWdg( name="Layout Switcher", icon="BS_TH_LIST")


        top.add(activator)
        activator.add_class("spt_switcher_activator")
        activator.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = bvr.src_el;
            var top = activator.getParent(".spt_switcher_top");
            var menu = top.getElement(".spt_switcher_menu");
            
            if (top.hasClass("spt_selected")) {
                top.removeClass("spt_selected");
                menu.setStyle("display", "none");    
            } else {
                top.addClass("spt_selected");
                menu.setStyle("display", "");
                var pos = activator.getPosition();
                var button_size = activator.getSize();
                var menu_size = menu.getSize();
                var offset = {
                    x: button_size.x - menu_size.x,
                    y: button_size.y
                }
                menu.position({position: 'upperleft', relativeTo: activator, offset: offset});

                spt.body.add_focus_element(menu);

                var pointer = menu.getElement(".spt_switcher_popup_pointer");
                pointer.setStyle("margin-left", menu_size.x - button_size.x);

            } 
            '''
        } )


        outer_wdg = DivWdg()
        top.add(outer_wdg)
            
        # menu_wdg 


        menu_wdg = DivWdg()
        outer_wdg.add(menu_wdg)
        menu_wdg.add_color("color", "color")
        menu_wdg.add_color("background", "background")
        menu_wdg.add_border()
        menu_wdg.add_class("spt_switcher_menu")
        menu_wdg.add_style("display: none")
        menu_wdg.add_style("margin-top", "20px")
        menu_wdg.add_style("position", "absolute")
        menu_wdg.add_style("z-index", "101")
        menu_wdg.add_behavior( {
            'type': 'mouseleave',
            'cbjs_action': '''
            var menu = bvr.src_el;
            var top = menu.getParent(".spt_switcher_top");
            top.removeClass("spt_selected");
            menu.setStyle("display", "none")
            '''
        } )

        border_color = menu_wdg.get_color("border")
        
        # Pointer under activator
        pointer_wdg = DivWdg()
        menu_wdg.add(pointer_wdg)
        pointer_wdg.add('''
            <div class="spt_switcher_first_arrow_div"> </div>
            <div class="spt_switcher_second_arrow_div"> </div>
        ''')
        pointer_wdg.add_class("spt_switcher_popup_pointer")

        style = HtmlElement.style('''
            .spt_switcher_menu .spt_switcher_popup_pointer {
                z-index: 10;
                position: absolute;
                top: -15px;
                right: 15px;
            }

            .spt_switcher_menu .spt_switcher_first_arrow_div {
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) %s;
                top: -15px;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                left: 15px;
            }

            .spt_switcher_menu .spt_switcher_second_arrow_div{
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                margin-top: -14px;
                position: absolute;
                left: 0px;
                top: 15px;
            }
        ''' % border_color)
        pointer_wdg.add(style)
 
        if menu:
            from tactic.ui.panel import SimpleSideBarWdg
            simple_sidebar = SimpleSideBarWdg(view=menu, search_type="SidebarWdg", target=target) 
            menu_wdg.add(simple_sidebar)
        else:
            style = self.get_style()
            top.add(style)
            
            self.view = 'tab'
            config = WidgetConfig.get(view=self.view, xml=config_xml)
            element_names = config.get_element_names()

            if not element_names:
                outer_wdg.add_style("display: none")

            if not state_value:
                if not element_names:
                    state_value = ""
                else:
                    state_value = element_names[0]


            for element_name in element_names:

                item_div = DivWdg()
                menu_wdg.add(item_div)
                item_div.add_class("spt_switcher_item")
                item_div.add_class("tactic_hover")

                item_div.add_style("width: 100%")

                attrs = config.get_element_attributes(element_name)
                title = attrs.get("title")
                if not title:
                    title = Common.get_display_title(element_name)


                for name, value in attrs.items():
                    if name in ['title', 'class']:
                        continue
                    item_div.add_attr(name, value)



                css_class = attrs.get("class")
                if css_class:
                    item_div.add_class(css_class)

                item_div.add(title)
                item_div.add_attr("spt_title", title)

                target = attrs.get("target")
                if not target:
                    target = "spt_content"

                display_class = config.get_display_handler(element_name)
                display_options = config.get_display_options(element_name)

                if show_first != False:
                    if element_name == state_value:
                        item_div.add_behavior( {
                            'type': 'load',
                            'cbjs_action': '''
                            bvr.src_el.click();
                            '''
                        } )

                if display_class:
                    item_div.add_behavior( {
                        'type': 'click_up',
                        'display_class': display_class,
                        'display_options': display_options,
                        'element_name': element_name,
                        'target': target,
                        'save_state': save_state,
                        'cbjs_action': '''
                        var menu_item = bvr.src_el;
                        var top = menu_item.getParent(".spt_switcher_top");
                        var menu = menu_item.getParent(".spt_switcher_menu");
                        
                        // Get target class
                        var target_class = bvr.target;
                        if (target_class.indexOf(".") != -1) {
                            var parts = target_class.split(".");
                            target_class = parts[1]; 
                            target_top_class = parts[0];
                        }
                        else {
                            target_top_class = null;
                        }
                    
                        if (target_top_class) {
                            var target_top = bvr.src_el.getParent("."+target_top_class);
                        }
                        else {
                            var target_top = $(document.body);
                        }
                        var target = target_top.getElement("."+target_class);
                        if (target) {
                            spt.panel.load(target, bvr.display_class, bvr.display_options);
                        }

                        menu.setStyle("display", "none");
                        top.removeClass("spt_selected");

                        var title = bvr.src_el.getAttribute("spt_title");

                        var title_el = top.getElement(".spt_title");
                        if (title_el)
                            title_el.innerHTML = title

                        if (bvr.save_state) {
                            var server = TacticServerStub.get()
                            server.set_widget_setting(bvr.save_state, bvr.element_name);
                        }

                        '''
                    } )
            
        return top
示例#41
0
    def _get_predefined_url(cls, key, hash):

        # only allow people with site admin
        security = Environment.get_security()
        is_admin = security.is_admin()
        if not is_admin and key == "admin":
            return None
 
 
        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")
            
            if not link:
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:

                # put in a check to ensure this is a user
                parts = link.split(".")

                user = Environment.get_user_name()
                
                def is_personal(user, parts):
                    '''See if parts contains period
                       seperated form of username.'''
                    acc = ""
                    for part in parts:
                        if acc == "":
                            acc = part
                        else:
                            acc = "%s.%s" % (acc, part)
                        if user == acc:
                            return True
                    return False

                personal = is_personal(user, parts) 
                
            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not personal and not security.check_access("link", keys, "allow", default="deny"):
                print "Not allowed"
                return None


            # This is used to find a sub menu (?)
            #view = link
            view = "definition"
            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", view, personal=personal)

            view = config.get_element_attribute(link, 'view')
            if view:
                options['widget_key'] = 'custom_layout'
                options['view'] = view
                class_name = None
            else:
                options = config.get_display_options(link)
                class_name = config.get_display_handler(link)


            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None


            if not class_name or class_name == "LinkWdg":
                class_name = options.get("class_name")

            widget_key = options.get("widget_key")


            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject


        elif key == "rest":

            xml = '''<element widget='true'>
  <display class='tactic.protocol.APIRestHandler'>
  </display>
</element>'''

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/rest")
            sobject.set_value("widget", xml )

            return sobject


        else:
            return None
示例#42
0
    def get_display(my):

        top = my.top
        top.add_class("spt_switcher_top")
        '''
        This supports supports two menu definitions:
        menu - specifies a view for SideBarWdg which will be ingected as menu 
        config_xml - specifies menu entries. For example:

        <display class="tactic.ui.widget.LayoutSwitcherWdg">
          <!-- config_xml -->
          <config>
            <!-- Menu item 1 -->
            <element name="my_tasks_default" title="My Tasks">
              <display class="tactic.ui.panel.ViewPanelWdg">
                <search_type>sthpw/task</search_type>
                <show_shelf>false</show_shelf>
                <view>my_tasks_default</view>
                <target>spt_my_tasks_table_top</target>
              </display>
            </element>
            <!-- Menu item 2 -->
            <element ... >
              <display ... >
                <target ... />
              </display>
            </element>
          </config>
        </display>

        target - specifies target div to load views when using "menu" kwarg
        use_href - updates address bar hash (this is TODO)
        '''

        menu = my.kwargs.get("menu")
        config_xml = my.kwargs.get("config_xml")
        target = my.kwargs.get("target")
        # TODO: use_href to go to specific layout switcher view
        # use_href = my.kwrags.get("use_href")

        # Layout switcher button displays menu and assumes right hand position of screen
        activator = IconButtonWdg(name="Layout Switcher", icon="BS_TH_LIST")
        top.add(activator)
        activator.add_class("spt_switcher_activator")
        activator.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = bvr.src_el;
            var top = activator.getParent(".spt_switcher_top");
            var menu = top.getElement(".spt_switcher_menu");
            
            if (top.hasClass("spt_selected")) {
                top.removeClass("spt_selected");
                menu.setStyle("display", "none");    
            } else {
                top.addClass("spt_selected");
                menu.setStyle("display", "");
                var pos = activator.getPosition();
                var button_size = activator.getSize();
                var menu_size = menu.getSize();
                var offset = {
                    x: button_size.x - menu_size.x,
                    y: button_size.y
                }
                menu.position({position: 'upperleft', relativeTo: activator, offset: offset});

                var pointer = menu.getElement(".spt_popup_pointer");
                pointer.setStyle("margin-left", menu_size.x - button_size.x);
            } 
            '''
        })

        # menu_wdg
        menu_wdg = DivWdg()
        top.add(menu_wdg)
        menu_wdg.add_class("spt_switcher_menu")
        menu_wdg.add_style("display: none")
        menu_wdg.add_style("margin-top", "15px")
        menu_wdg.add_style("position", "absolute")
        menu_wdg.add_style("z-index", "10")
        menu_wdg.add_behavior({
            'type':
            'mouseleave',
            'cbjs_action':
            '''
            var menu = bvr.src_el;
            var top = menu.getParent(".spt_switcher_top");
            top.removeClass("spt_selected");
            menu.setStyle("display", "none")
            '''
        })

        # Pointer under activator
        pointer_wdg = DivWdg()
        menu_wdg.add(pointer_wdg)
        pointer_wdg.add('''
            <div class="spt_first_arrow_div"> </div>
            <div class="spt_second_arrow_div"> </div>
        ''')
        pointer_wdg.add_class("spt_popup_pointer")

        style = HtmlElement.style('''
            .spt_switcher_menu .spt_popup_pointer {
                z-index: 10;
                margin-top: -15px;
                margin-left: 100px;
            }

            .spt_switcher_menu .spt_first_arrow_div {
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #ccc;
                top: -15px;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                left: 15px;
            }

            .spt_switcher_menu .spt_second_arrow_div{
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                margin-top: -14px;
                position: absolute;
            }
        ''')
        pointer_wdg.add(style)

        if menu:
            from tactic.ui.panel import SimpleSideBarWdg
            simple_sidebar = SimpleSideBarWdg(view=menu,
                                              search_type="SidebarWdg",
                                              target=target)
            menu_wdg.add(simple_sidebar)
        else:
            style = my.get_style()
            top.add(style)

            my.view = 'tab'
            config = WidgetConfig.get(view=my.view, xml=config_xml)
            element_names = config.get_element_names()

            for element_name in element_names:

                item_div = DivWdg()
                menu_wdg.add(item_div)
                item_div.add_class("spt_switcher_item")
                item_div.add_class("tactic_hover")

                attrs = config.get_element_attributes(element_name)
                title = attrs.get("title")
                if not title:
                    title = Common.get_display_title(element_name)

                item_div.add(title)

                target = attrs.get("target")
                if not target:
                    target = "spt_content"

                display_class = config.get_display_handler(element_name)
                display_options = config.get_display_options(element_name)

                item_div.add_behavior({
                    'type':
                    'click_up',
                    'display_class':
                    display_class,
                    'display_options':
                    display_options,
                    'target':
                    target,
                    'cbjs_action':
                    '''
                    var menu_item = bvr.src_el;
                    var top = menu_item.getParent(".spt_switcher_top");
                    var menu = menu_item.getParent(".spt_switcher_menu");
                    
                    // Get target class
                    var target_class = bvr.target;
                    if (target_class.indexOf(".") != "-1") {
                        var parts = target_class.split(".");
                        target_class = parts[1]; 
                    }
                    
                    var target = $(document.body).getElement("."+target_class);
                    if (target) {
                        spt.panel.load(target, bvr.display_class, bvr.display_options);
                    }

                    menu.setStyle("display", "none");
                    top.removeClass("spt_selected");
                    '''
                })

        return top
示例#43
0
    def _get_predefined_url(cls, key, hash):

        # make some predefined fake urls
        if key in ["link", "tab", "admin"]:
            # this is called by PageNav
            if key == "admin":
                expression = "/admin/link/{link}"
            else:
                expression = "/%s/{link}" % key
            options = Common.extract_dict(hash, expression)
            link = options.get("link")

            if not link:
                return None


            # test link security
            project_code = Project.get_project_code()
            security = Environment.get_security()
            keys = [
                    { "element": link },
                    { "element": "*" },
                    { "element": link, "project": project_code },
                    { "element": "*", "project": project_code }
            ]
            if not security.check_access("link", keys, "allow", default="deny"):
                return None


            from tactic.ui.panel import SideBarBookmarkMenuWdg
            personal = False
            if '.' in link:
                personal = True



            config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal)
            options = config.get_display_options(link)
            if not options:

                from pyasm.biz import Schema
                config_xml = []
                config_xml.append( '''
                <config>
                ''')
         
                config_schema = Schema.get_predefined_schema('config')
                SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml)
                schema = Schema.get_admin_schema()
                SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml)

                config_xml.append( '''
                </config>
                ''')

                xml = "".join(config_xml)

                from pyasm.widget import WidgetConfig
                schema_config = WidgetConfig.get(view="_admin_schema", xml=xml)
                options = schema_config.get_display_options(link)
                if not options:
                    schema_config.set_view("_config_schema")
                    options = schema_config.get_display_options(link)

                if not options:
                    return None




            class_name = options.get("class_name")
            widget_key = options.get("widget_key")
            if widget_key:
                class_name = WidgetClassHandler().get_display_handler(widget_key)
            elif not class_name:
                class_name = 'tactic.ui.panel.ViewPanelWdg'


            if key in ["admin", "tab"]:
                use_index = "false"
            else:
                use_index = "true"

            if key in ['admin']:
                use_admin = "true"
            else:
                use_admin = "false"


            xml = []
            xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index))
            xml.append('''  <display class="%s">''' % class_name)
            for name, value in options.items():
                xml.append("<%s>%s</%s>" % (name, value, name) )
            xml.append('''  </display>''')
            xml.append('''</element>''')

            xml = "\n".join(xml)

            sobject = SearchType.create("config/url")
            sobject.set_value("url", "/%s/{value}" % key)
            sobject.set_value("widget", xml )

            return sobject
 
        else:
            return None
示例#44
0
    def get_display(self):

        top_wdg = DivWdg()
        top_wdg.add_style("color: black")
        top_wdg.add_style("width: 350px")
        top_wdg.add_style("margin-top: 10px")
        top_wdg.add_style("padding: 10px")
        top_wdg.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add_style("margin-top: -22px")

        top_wdg.add(title)
        #if not self.name_string:
        #    title.add('No database column')
        #    return top_wdg
        
        title.add("Widget Definition")

        widget_types = {
            'foreign_key': 'tactic.ui.table.ForeignKeyElementWdg',
            'button': 'tactic.ui.table.ButtonElementWdg',
            'expression': 'tactic.ui.table.ExpressionElementWdg'
        }


        web = WebContainer.get_web()
        config_string = web.get_form_value("config_xml")
        if not config_string:
            config_string = '<config/>'
        xml = Xml()
        xml.read_string(config_string)

        #print "config_string: ", config_string

        # get values from the config file
        element_name = xml.get_value('element/@name')

        config = WidgetConfig.get(view='element',xml='<config><element>%s</element></config>' % config_string)
        display_options = config.get_display_options(element_name)


        title = xml.get_value('element/@title')
        display_handler = xml.get_value('element/display/@class')
        if not display_handler:
            display_handler = 'tactic.ui.panel.TypeTableElementWdg'

        widget_name = xml.get_value('element/display/@widget')
        if not widget_name:
            widget_name = 'custom'

 
        custom_table = Table()
        custom_table.add_style("color: black")
        top_wdg.add(custom_table)

        name_text = DivWdg()
        name_text.add_style("color: black")
        name_text.add(element_name)
        custom_table.add_row()
        custom_table.add_cell("Name: ")
        custom_table.add_cell(name_text)



        # add title
        custom_table.add_row()
        title_wdg = TextWdg("custom_title")
        title_wdg.set_value(title)
        title_wdg.add_attr("size", "50")
        custom_table.add_cell( "Title: " )
        custom_table.add_cell( title_wdg )

        # add description
        #custom_table.add_row()
        #description_wdg = TextAreaWdg("custom_description")
        #td = custom_table.add_cell( "Description: " )
        #td.add_style("vertical-align: top")
        #custom_table.add_cell( description_wdg )


        type_select = SelectWdg("custom_type")
        #type_select.add_empty_option("-- Select --")

        type_select.set_option("values", "string|integer|float|boolean|currency|date|foreign_key|link|list|button|custom")
        type_select.set_option("labels", "String(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key|Link|List|Button|Custom")
        type_select.set_value(widget_name)

        #type_select.set_option("values", "string|integer|float|boolean|currency|date|link|list|foreign_key|button|empty")
        #type_select.set_option("labels", "String|Integer|Float|Boolean|Currency|Date|Link|List|Foreign Key|Button|Empty")
        custom_table.add_row()
        td = custom_table.add_cell("Widget Type: ")
        td.add_style("vertical-align: top")
        td = custom_table.add_cell(type_select)
        type_select.add_event("onchange", "spt.CustomProject.property_type_select_cbk(this)")


        td.add(HtmlElement.br())
        display_handler_text = TextWdg("display_handler")
        display_handler_text.add_attr("size", "50")
        display_handler_text.set_value(display_handler)
        td.add(display_handler_text)



        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())



        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Relate to: ")
        search_type_select = SearchTypeSelectWdg("foreign_key_search_select", mode=SearchTypeSelectWdg.CURRENT_PROJECT)
        div.add(search_type_select)
        td.add(div)



        # extra info for list
        custom_table.add_row()
        div = DivWdg()
        div.add_class("list_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Values: ")
        search_type_text = TextWdg("list_values")
        div.add(search_type_text)
        td.add(div)




        # extra info for button
        custom_table.add_row()
        div = DivWdg()
        div.add_style("color: black")
        div.add_class("button_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")

        #class_path = "tactic.ui.table.ButtonElementWdg"
        class_path = display_handler
        button = Common.create_from_class_path(class_path)
        args_keys = button.get_args_keys()


        div.add("Options")
        div.add(HtmlElement.br())

        for key in args_keys.keys():
            option_name_text = HiddenWdg("option_name")
            option_name_text.set_value(key)
            div.add(option_name_text)

            div.add("%s: " % key)
            div.add(" &nbsp; &nbsp;")

            input = button.get_input_by_arg_key(key)

            value = display_options.get(key)
            if value:
                input.set_value(value)

            div.add(input)
            div.add(HtmlElement.br())
        td.add(div)






        # is searchable checkbox
        #custom_table.add_row()
        #current_searchable_wdg = CheckboxWdg("is_searchable")
        #current_view_wdg.set_checked()
        #custom_table.add_cell("Searchable? ")
        #td = custom_table.add_cell(current_searchable_wdg)

        custom_table.close_tbody()


        return top_wdg
示例#45
0
    def get_display(my):

        my.sobject = my.get_sobject()

        top = DivWdg()
        top.add_class("spt_detail_top")
        top.add_color("background", "background")
        top.add_color("color", "color")

        if not my.sobject:
            top.add("No SObject defined for this widget")
            return top

        if my.parent:
            my.search_type = my.parent.get_base_search_type()
            my.search_key = SearchKey.get_by_sobject(my.parent)
            top.add_attr("spt_parent_key", my.search_key) 
            my.pipeline_code = my.parent.get_value("pipeline_code", no_exception=True)
            my.full_search_type = my.parent.get_search_type()
        else:
            my.pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True)
            my.search_type = my.sobject.get_base_search_type()
            my.search_key = SearchKey.get_by_sobject(my.sobject)
            my.full_search_type = my.sobject.get_search_type()

        if not my.pipeline_code:
            my.pipeline_code = 'default'


        top.add_style("text-align: left")
        my.set_as_panel(top)

        table = Table()
        #from tactic.ui.container import ResizableTableWdg
        #table = ResizableTableWdg()
        table.add_color("background", "background")
        table.add_color("color", "color")
        top.add(table)
        table.set_max_width()

        table.add_row()

        # left
        #td = table.add_cell(resize=False)
        td = table.add_cell()
        #td.add_style("padding: 10px")
        td.add_style("width: 200px")
        td.add_style("min-width: 200px")
        td.add_style("vertical-align: top")
        #td.add_border()
        #td.add_style("border-style: solid")
        #td.add_style("border-width: 1px 0 1px 1px")
        #td.add_color("border-color", "border")
        #td.add_color("background", "background", -10)


        if my.parent:
            code = my.parent.get_code()
        else:
            code = my.sobject.get_code()

        # add the tile
        title = DivWdg()
        td.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add_style("font-size: 1.4em")
        title.add("%s" % code)
        title.add_border()


        div = DivWdg()
        td.add(div)
        div.add_class("spt_sobject_detail_top")

        thumb_table = Table()
        div.add(thumb_table)
        thumb_table.add_row()

        thumb = ThumbWdg()

        # use a larger version for clearer display
        thumb.set_icon_type('web')
        # prefer to see the original image, then web
        thumb.set_option('image_link_order', 'main|web|.swf')
        thumb.set_option("detail", "false")
        thumb.set_option("icon_size", "100%")

        td = thumb_table.add_cell(thumb)
        td.add_style("vertical-align: top")
        td.add_style("width: 200px")
        td.add_style("padding: 20px")

        if my.parent:
            thumb.set_sobject(my.parent)
        else:
            thumb.set_sobject(my.sobject)

        sobject_info_wdg = my.get_sobject_info_wdg()
        sobject_info_wdg.add_style("width: 200px")


        td.add(sobject_info_wdg)

        if my.search_type == 'sthpw/task' and not my.parent:
            pass
        else:
            sobject_info_wdg = my.get_sobject_detail_wdg()
            td = table.add_cell()
            td.add(sobject_info_wdg)
            td.add_style("vertical-align: top")
            #td.add_color("background", "background", -10)
            td.add_style("overflow: hidden")
            #td.add_style("border-style: solid")
            #td.add_style("border-width: 1px 1px 1px 0px")
            #td.add_color("border-color", "border")


        # right
        td = table.add_cell()
        td.add_style("text-align: left")
        td.add_style("vertical-align: top")
        #td.add_color("background", "background", -10)
        td.add_class("spt_notes_wrapper")
        #td.add_border()

        # add the title
        title = DivWdg()
        td.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add("Notes")
        title.add_border()

        notes_div = DivWdg()
        td.add(notes_div)
        from tactic.ui.widget.discussion_wdg import DiscussionWdg
        discussion_wdg = DiscussionWdg(search_key=my.search_key, context_hidden=False, show_note_expand=False)
        notes_div.add(discussion_wdg)
        notes_div.add_style("min-width: 300px")
        notes_div.add_style("height: 200")
        notes_div.add_style("overflow-y: auto")
        notes_div.add_class("spt_resizable")



        # get the process
        if my.parent:
            process = my.sobject.get_value("process")
        else:
            process = ''



        # content
        tr = table.add_row()
        td = table.add_cell()
        td.add_attr("colspan", "5")
        #td.add_attr("colspan", "3")

        # create a state for tab.  The tab only passes a search key
        # parent key
        search_key = SearchKey.get_by_sobject(my.sobject)
        parent = my.sobject.get_parent()
        if parent:
            parent_key = parent.get_search_key()
        else:
            parent_key = ""

        state = {
            'search_key': search_key,
            'parent_key': parent_key,
            'process': process,
        }
        WebState.get().push(state)


        config_xml = my.get_config_xml()
        config = WidgetConfig.get(view="tab", xml=config_xml)


        if process:
            custom_view = "tab_config_%s" % process
        else:
            custom_view = "tab_config"
        search = Search("config/widget_config")
        search.add_filter("category", "TabWdg")
        search.add_filter("search_type", my.search_type)
        search.add_filter("view", custom_view)
        custom_config_sobj = search.get_sobject()
        if custom_config_sobj:
            custom_config_xml = custom_config_sobj.get_value("config")
            custom_config = WidgetConfig.get(view=custom_view, xml=custom_config_xml)
            config = WidgetConfigView(search_type='TabWdg', view=custom_view, configs=[custom_config, config])

        #menu = my.get_extra_menu()
        #tab = TabWdg(config=config, state=state, extra_menu=menu)
        tab = TabWdg(config=config, state=state, show_add=False, show_remove=False, tab_offset=5 )
        tab.add_style("margin: 0px -2px -2px -2px")
        td.add(tab)
        td.add_style("padding-top: 10px")

        return top
    def execute(my):
        web = WebContainer.get_web()
        alter_mode = my.kwargs.get("alter_mode")
        title = my.kwargs.get("title")
        config_mode = web.get_form_value("config_mode")
        view = web.get_form_value('view')
        constraint = web.get_form_value("config_constraint")
        data_type = ''

        if config_mode == "advanced":
            config_string = web.get_form_value("config_xml")
            if config_string:
                xml = Xml()
                xml.read_string(config_string)
                node = xml.get_root_node()
                data_type = xml.get_attribute(node, "data_type")
                nullable = xml.get_attribute(node,
                                             "nullable") in ['true', 'True']

        else:
            data_type = web.get_form_value("config_data_type")
            if data_type == 'Other...':
                data_type = web.get_form_value("config_data_type_custom")
            cb = CheckboxWdg("config_nullable")
            nullable = cb.is_checked()

        # if advanced is selected in the Widget Column view, data_type is ''
        # read from UI
        if not data_type and view == 'definition':
            data_type = web.get_form_value("config_data_type")
            if data_type == 'Other...':
                data_type = web.get_form_value("config_data_type_custom")
            cb = CheckboxWdg("config_nullable")
            nullable = cb.is_checked()

        column_name = web.get_form_value("column_name")
        search_type = web.get_form_value("target_search_type")
        if alter_mode == ManageSearchTypeDetailWdg.REMOVE_COLUMN:
            cmd = ColumnDropCmd(search_type, column_name)
            Command.execute_cmd(cmd)
            # delete widget config from definition view
            widget_config = WidgetDbConfig.get_by_search_type(
                search_type, 'definition')
            if widget_config:
                config = WidgetConfig.get(
                    'definition', xml=widget_config.get_xml_value('config'))
                config.remove_xml_element(column_name)
                new_xml = config.get_xml().to_string()
                widget_config.set_value("config", new_xml)
                widget_config.commit()
                # set cache to {}
                from pyasm.common import Container

                Container.put("WidgetConfigView:config_cache", {})
                #Container.put("WidgetConfig:config_cache", {})
        elif alter_mode == ManageSearchTypeDetailWdg.MODIFY_COLUMN:
            cmd = ColumnAlterCmd(search_type, column_name, data_type, nullable)
            Command.execute_cmd(cmd)
            element_options = {}
            element_options['type'] = data_type
            if title:
                element_options['title'] = title

            # handle the "default" view
            # update the widget config data type in the xml
            view = my.DEFAULT_VIEW
            config = WidgetDbConfig.get_by_search_type(search_type, view)
            if config:
                config.append_display_element(column_name, options={}, \
                    element_attrs=element_options)
                config.commit_config()

        elif alter_mode == ManageSearchTypeDetailWdg.ADD_COLUMN:
            cmd = ColumnAddCmd(search_type, column_name, data_type, nullable)
            Command.execute_cmd(cmd)

        if constraint:
            # add constraint
            from pyasm.command import ColumnAddIndexWdg
            cmd = ColumnAddIndexWdg()
            cmd.execute()
        else:
            # remove constraint
            pass
                if default_config:
                    default_config.get_xml().clear_xpath_cache()
                    widget_config_list = [default_config]

            else:
                config_view = WidgetConfigView.get_by_search_type(
                    search_type, view, use_cache=True)

        elif view == "database_definition":
            schema_config = SearchType.get_schema_config(search_type)
            widget_config_list = [schema_config]
        elif view == 'template':
            base_dir = Environment.get_install_dir()
            file_path = "%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir
            if os.path.exists(file_path):
                widget_config = WidgetConfig.get(file_path=file_path,
                                                 view=view)
                widget_config_list = [widget_config]
            '''
            elif default == True :
                base_dir = Environment.get_install_dir()
                file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir
                if os.path.exists(file_path):
                    widget_config = WidgetConfig.get(file_path=file_path, view="default_definition")
                    widget_config_list = [widget_config]
            '''
        elif view == "custom_definition":
            # look for a definition in the database
            search = Search("config/widget_config")
            search.add_filter("search_type", 'SearchTypeSchema')
            search.add_filter("view", view)
            config = search.get_sobject()
示例#48
0
文件: edit_wdg.py 项目: funic/TACTIC
    def init(my):
        my.is_refresh = my.kwargs.get("refresh")
        my.search_key = my.kwargs.get("search_key")
        my.ticket_key = my.kwargs.get("ticket")
        my.parent_key = my.kwargs.get("parent_key")
        my.expression = my.kwargs.get("expression")

        # This assumed parent can cause errors as it tries to find a
        # relationship between to stypes that don't exist ... or worse,
        # try to bind them when one stype does not have the sufficent columns
        # ie: pipeline_code
        #if not my.parent_key:
        #    project = Project.get()
        #    my.parent_key = project.get_search_key()


        my.code = my.kwargs.get("code")
        sobject = None
        if my.search_key:
            sobject = Search.get_by_search_key(my.search_key)
            my.search_id = sobject.get_id()
            my.search_type = sobject.get_base_search_type()
            if sobject.is_insert():
                my.mode = 'insert'
            else:
                my.mode = 'edit'

        elif my.expression:
            sobject = Search.eval(my.expression, single=True)
            my.search_id = sobject.get_id()
            my.search_type = sobject.get_base_search_type()
            my.mode = 'edit'


        elif my.ticket_key:
            from pyasm.security import Ticket, Login
            ticket = Ticket.get_by_valid_key(my.ticket_key)
            if not ticket:
                raise TacticException("No valid ticket")
            login_code = ticket.get_value("login")
            login = Login.get_by_code(login_code)
            my.search_type = "sthpw/login"
            my.search_id = login.get_id()
            my.mode = 'edit'

        elif my.code:
            my.search_type = my.kwargs.get("search_type")
            search = Search(my.search_type)
            search.add_filter("code", my.code)
            sobject = search.get_sobject()
            
            my.search_id = sobject.get_id()
            my.search_type = sobject.get_base_search_type()
            my.mode = 'edit'


        else:
            my.search_type = my.kwargs.get("search_type")
            my.search_id = my.kwargs.get("search_id")
            if not my.search_id:
                my.search_id = -1
            my.search_id = int(my.search_id)
            if my.search_id != -1:
                my.mode = "edit"
            else:
                my.mode = "insert"
                

        # explicit override
        if my.kwargs.get("mode"):
            my.mode = my.kwargs.get("mode")


        my.view = my.kwargs.get("view")
        if not my.view:
            my.view = my.kwargs.get("config_base")
        if not my.view:
            my.view = "edit"


        default_data = my.kwargs.get('default')
        
        if not default_data:
            default_data = {}
        elif isinstance(default_data, basestring):
            try:
                default_data = jsonloads(default_data)
            except:
                #may be it's regular dictionary
                try:
                    default_data = eval(default_data)
                except:
                    print "Warning: Cannot evaluate [%s]" %default_data
                    default_data = {}

        if sobject:
            my.set_sobjects([sobject], None)
        else:
            my.do_search()

        # TODO: get_config() is going the right direction (less features) but the more complicated method is biased 
        # towards edit and insert view.. and so it needs improvement as well

        if my.view not in ["insert", "edit"]:
            # try a new smaller way to get config only when an explicit view
            # is set
            my.config = my.get_config()
        else:
            my.config = WidgetConfigView.get_by_search_type(my.search_type, my.view, use_cache=False)

        # for inline config definitions
        config_xml = my.kwargs.get("config_xml")
        if config_xml:
            #from pyasm.common import Xml
            #xml = Xml()
            #xml.read_string(config_xml)
            #node = xml.get_node("config/%s" % my.view)
            #xml.set_attribute(node, "class", "tactic.ui.panel.EditWdg")
            #config = WidgetConfig.get(view=my.view, xml=xml)
            config_xml = config_xml.replace("&", "&amp;")

            config = WidgetConfig.get(view="tab", xml=config_xml)
            my.config.insert_config(0, config)

        
        my.skipped_element_names = []

        # if there is a layout view, then find the element names using that
        layout_view = my.kwargs.get("layout_view")
        if layout_view:
            layout_view = layout_view.replace("/", ".")
            search = Search("config/widget_config")
            search.add_filter("view", layout_view)
            layout_config = search.get_sobject()
             
            xml = layout_config.get_xml_value("config")
            my.element_names = xml.get_values("config//html//element/@name")
        else:
            my.element_names = my.config.get_element_names()

        ignore = my.kwargs.get("ignore")
        if isinstance(ignore, basestring):
            ignore = ignore.split("|")
        if not ignore:
            ignore = []

        my.element_titles = []
        my.element_descriptions = []
        for element_name in my.element_names:
            my.element_titles.append( my.config.get_element_title(element_name) )
            my.element_descriptions.append( my.config.get_element_description(element_name) )

        #my.element_titles = my.config.get_element_titles()  
        #my.element_descriptions = my.config.get_element_descriptions()  


        # MongoDb
        # Default columns
        if not my.element_names:
            impl = SearchType.get_database_impl_by_search_type(my.search_type)
            if impl.get_database_type() == "MongoDb":
                my.element_names = impl.get_default_columns()
                my.element_titles = ['Code', 'Name', 'Description']
                my.element_descriptions = ['Code', 'Name', 'Description']




        my.input_prefix = my.kwargs.get('input_prefix')
        if not my.input_prefix:
            my.input_prefix = 'edit'
        
        security = Environment.get_security()
        default_access = "edit"
        project_code = Project.get_project_code()


        for i, element_name in enumerate(my.element_names):

            if element_name in ignore:
                my.skipped_element_names.append(element_name)
                continue


            # check security access
            access_key2 = {
                'search_type': my.search_type,
                'project': project_code
            }
            access_key1 = {
                'search_type': my.search_type,
                'key': element_name, 
                'project': project_code

            }
            access_keys = [access_key1, access_key2]
            is_editable = security.check_access('element', access_keys, "edit", default=default_access)

            
            if not is_editable:
                my.skipped_element_names.append(element_name)
                continue
            widget = my.config.get_display_widget(element_name, kbd_handler=False)
            # some element could be disabled due to its data_type e.g. sql_timestamp
            if not widget:
                my.skipped_element_names.append(element_name)
                continue


            widget.set_sobject(my.sobjects[0])

            default_value = default_data.get(element_name)
            if default_value:
                widget.set_value(default_value)
           
            attrs = my.config.get_element_attributes(element_name)
            editable = widget.is_editable()
            if editable:
                editable = attrs.get("edit")
                editable = editable != "false"
            
            if not editable:
                my.skipped_element_names.append(element_name)
                continue

            # set parent
            widget.set_parent_wdg(my)
            
            # set parent_key in insert mode for now
            if my.mode =='insert' and my.parent_key:
                widget.set_option('parent_key', my.parent_key)
            
            
            title = my.element_titles[i]
            if title:
                widget.set_title(title)

            my.widgets.append(widget)

            description = my.element_descriptions[i]
            widget.add_attr("title", description)
示例#49
0
    def get_display(my):

        category = "FreeformWdg"
        view = my.get_input_value("view")

        sobject = my.get_input_value("sobject")
        if not sobject and my.sobjects:
            sobject = my.sobjects[0]
        if not view:
            view = 'freeform'

        if sobject:
            search_key = sobject.get_search_key()
            search_type = sobject.get_base_search_type()

        else:
            search_key = my.get_input_value("search_key")
            search_type = my.get_input_value("search_type")

        if sobject:
            pass
        elif search_key:
            sobject = Search.get_by_search_key(search_key)
        elif search_type:
            search = Search(search_type)
            search.add_limit(1)
            sobject = search.get_sobject()
        else:
            sobject = None

        top = DivWdg()
        top.add_class("spt_freeform_top")

        search = Search("config/widget_config")
        search.add_filter("search_type", search_type)
        search.add_filter("view", view)
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("config")
        else:
            config_xml = ""

        if not config_xml:
            top.add("No definition found")
            return top

        config = WidgetConfig.get(view=view, xml=config_xml)
        view_attrs = config.get_view_attributes()

        bgcolor = view_attrs.get("bgcolor")
        if not bgcolor:
            bgcolor = my.get_default_background()

        if bgcolor:
            top.add_style("background", bgcolor)

        # draw the layout
        freeform_layout = my.get_canvas_display(search_type, view, config,
                                                sobject)
        top.add(freeform_layout)

        return top
示例#50
0
    def get_display(my):

        my.sobject = my.get_sobject()

        top = DivWdg()
        top.add_class("spt_detail_top")
        top.add_color("background", "background")
        top.add_color("color", "color")

        if not my.sobject:
            top.add("No SObject defined for this widget")
            return top

        if my.parent:
            my.search_type = my.parent.get_base_search_type()
            my.search_key = SearchKey.get_by_sobject(my.parent)
            top.add_attr("spt_parent_key", my.search_key)
            my.pipeline_code = my.parent.get_value("pipeline_code",
                                                   no_exception=True)
            my.full_search_type = my.parent.get_search_type()
        else:
            my.pipeline_code = my.sobject.get_value("pipeline_code",
                                                    no_exception=True)
            my.search_type = my.sobject.get_base_search_type()
            my.search_key = SearchKey.get_by_sobject(my.sobject)
            my.full_search_type = my.sobject.get_search_type()

        if not my.pipeline_code:
            my.pipeline_code = 'default'

        top.add_style("text-align: left")
        my.set_as_panel(top)

        table = Table()
        #from tactic.ui.container import ResizableTableWdg
        #table = ResizableTableWdg()
        table.add_color("background", "background")
        table.add_color("color", "color")
        top.add(table)
        table.set_max_width()

        table.add_row()

        # left
        #td = table.add_cell(resize=False)
        td = table.add_cell()
        #td.add_style("padding: 10px")
        td.add_style("width: 200px")
        td.add_style("min-width: 200px")
        td.add_style("vertical-align: top")
        #td.add_border()
        #td.add_style("border-style: solid")
        #td.add_style("border-width: 1px 0 1px 1px")
        #td.add_color("border-color", "border")
        #td.add_color("background", "background", -10)

        if my.parent:
            code = my.parent.get_code()
        else:
            code = my.sobject.get_code()

        # add the tile
        title = DivWdg()
        td.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add_style("font-size: 1.4em")
        title.add("%s" % code)
        title.add_border()

        div = DivWdg()
        td.add(div)
        div.add_class("spt_sobject_detail_top")

        thumb_table = Table()
        div.add(thumb_table)
        thumb_table.add_row()

        thumb = ThumbWdg()
        # use a larger version for clearer display
        thumb.set_icon_type('web')

        # prefer to see the original image, then web
        thumb.set_option('image_link_order', 'main|web|icon')
        thumb.set_option("detail", "false")
        thumb.set_option("icon_size", "100%")

        td = thumb_table.add_cell(thumb)
        td.add_style("vertical-align: top")
        td.add_style("width: 240px")
        td.add_style("padding: 15px")

        if my.parent:
            thumb.set_sobject(my.parent)
        else:
            thumb.set_sobject(my.sobject)

        sobject_info_wdg = my.get_sobject_info_wdg()
        sobject_info_wdg.add_style("width: 200px")

        td.add(sobject_info_wdg)

        if my.search_type == 'sthpw/task' and not my.parent:
            pass
        else:
            sobject_info_wdg = my.get_sobject_detail_wdg()
            td = table.add_cell()
            td.add(sobject_info_wdg)
            td.add_style("vertical-align: top")
            td.add_style("overflow: hidden")

        # right
        td = table.add_cell()
        td.add_style("text-align: left")
        td.add_style("vertical-align: top")
        #td.add_color("background", "background", -10)
        td.add_class("spt_notes_wrapper")
        #td.add_border()

        # add the title
        title = DivWdg()
        td.add(title)
        title.add_gradient("background", "background3", 0, -10)
        title.add_style("height: 20px")
        title.add_style("padding: 4px")
        title.add_style("font-weight: bold")
        title.add("Notes")
        title.add_border()

        notes_div = DivWdg()
        td.add(notes_div)
        from tactic.ui.widget.discussion_wdg import DiscussionWdg
        discussion_wdg = DiscussionWdg(search_key=my.search_key,
                                       context_hidden=False,
                                       show_note_expand=False)
        notes_div.add(discussion_wdg)
        notes_div.add_style("min-width: 300px")
        notes_div.add_style("height: 200")
        notes_div.add_style("overflow-y: auto")
        notes_div.add_class("spt_resizable")

        # get the process
        if my.parent:
            process = my.sobject.get_value("process")
        else:
            process = ''

        # content
        tr = table.add_row()
        td = table.add_cell()
        td.add_attr("colspan", "5")
        #td.add_attr("colspan", "3")

        # create a state for tab.  The tab only passes a search key
        # parent key
        search_key = SearchKey.get_by_sobject(my.sobject)
        parent = my.sobject.get_parent()
        if parent:
            parent_key = parent.get_search_key()
        else:
            parent_key = ""

        state = {
            'search_key': search_key,
            'parent_key': parent_key,
            'process': process,
        }
        WebState.get().push(state)

        config_xml = my.get_config_xml()
        config = WidgetConfig.get(view="tab", xml=config_xml)

        if process:
            custom_view = "tab_config_%s" % process
        else:
            custom_view = "tab_config"
        search = Search("config/widget_config")
        search.add_filter("category", "TabWdg")
        search.add_filter("search_type", my.search_type)
        search.add_filter("view", custom_view)
        custom_config_sobj = search.get_sobject()
        if custom_config_sobj:
            custom_config_xml = custom_config_sobj.get_value("config")
            custom_config = WidgetConfig.get(view=custom_view,
                                             xml=custom_config_xml)
            config = WidgetConfigView(search_type='TabWdg',
                                      view=custom_view,
                                      configs=[custom_config, config])

        #menu = my.get_extra_menu()
        #tab = TabWdg(config=config, state=state, extra_menu=menu)
        tab = TabWdg(config=config,
                     state=state,
                     show_add=False,
                     show_remove=False,
                     tab_offset=5)
        tab.add_style("margin: 0px -2px -2px -2px")
        td.add(tab)
        td.add_style("padding-top: 10px")

        return top
    def init(my):
        '''initialize the widget_config, and from there retrieve the schema_config'''
        web = WebContainer.get_web()
        my.search_type = my.kwargs.get('search_type')

        element_name = my.kwargs.get('element_name')
        my.view = my.kwargs.get('view')

        # FIXME: comment out the assert for now to avoid error screen
        if not my.view:
            my.view = 'table'
        #assert my.view

        my.config_xml = my.kwargs.get('config_xml')
        if not my.config_xml:
            my.config_xml = web.get_form_value('config_xml')

        my.default = my.kwargs.get('default') == 'True'

        cbk = ManageSearchTypeDetailCbk(search_type=my.search_type, view=my.view, \
                element_name=element_name)
        Command.execute_cmd(cbk)

        my.config_string = ""
        my.data_type_string = ""
        my.name_string = ""
        my.title_string = ""
        my.nullable_string = ""
        my.has_column = True

        if element_name:
            if my.config_xml:
                my.config_string = my.config_xml
                whole_config_string = "<config><%s>%s</%s></config>" % (
                    my.view, my.config_xml, my.view)
                config = WidgetConfig.get(xml=whole_config_string,
                                          view=my.view)
                my.config = WidgetConfigView(my.search_type, my.view, [config])
            else:
                # don't pass in default here
                my.config = my.get_config(my.search_type, my.view)
                node = my.config.get_element_node(element_name)
                if node is not None:
                    config_xml = my.config.get_xml()

                    my.config_string = config_xml.to_string(node)
                    my.title_string = config_xml.get_attribute(node, 'title')
            schema_config = SearchType.get_schema_config(my.search_type)

            attributes = schema_config.get_element_attributes(element_name)
            my.data_type_string = attributes.get("data_type")

            # double_precision is float
            if my.data_type_string == 'double precision':
                my.data_type_string = 'float'

            my.name_string = attributes.get("name")
            my.nullable_string = attributes.get("nullable")
            my.is_new_column = attributes.get("new") == 'True'

            # a database columnless widget
            if not my.name_string:
                my.has_column = False
示例#52
0
    def get_display(my):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_gradient("background", "background", 0, -5)
        #top.add_style("height: 550px")

        top.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            spt.named_events.fire_event("side_bar|hide", {} );
            '''
        })

        project = Project.get()

        title = TitleWdg(title='Client Home')
        top.add(title)

        shelf = DivWdg()
        top.add(shelf)
        shelf.add_style("margin-left: -8px")
        shelf.add_style("width: 130px")

        security = Environment.get_security()
        view_side_bar = security.check_access("builtin",
                                              "view_side_bar",
                                              "allow",
                                              default='allow')
        if view_side_bar:
            button_div = DivWdg()
            shelf.add(button_div)
            button_div.add_style("float: left")
            button_div.add_style("margin-top: -3px")

            button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT)
            button_div.add(button)
            shelf.add("Toggle Side Bar")
            button.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            })

            shelf.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            })
            shelf.add_class("hand")
        else:
            shelf.add("&nbsp;")

        search_wdg = DivWdg()
        search_wdg.add_class("spt_main_top")
        top.add(search_wdg)
        search_wdg.add_style("padding: 10px")
        search_wdg.add_style("margin: 10px auto")
        search_wdg.add_style("width: 430px")
        search_wdg.add("Search: ")
        search_wdg.add("&nbsp;" * 3)

        custom_cbk = {}
        custom_cbk['enter'] = '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords != '') {
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    'search_type': 'sthpw/sobject_list',
                    'view': 'table',
                    'keywords': keywords,
                    'simple_search_view': 'simple_search',
                    //'show_shelf': false,
                }
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            }
        '''

        from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg
        #text = TextInputWdg(name="search")
        text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk)
        #text = TextWdg("search")
        text.add_class("spt_main_search")
        text.add_style("width: 290px")
        search_wdg.add(text)
        search_wdg.add_style("font-weight: bold")
        search_wdg.add_style("font-size: 16px")

        button = ActionButtonWdg(title="Search")
        #search_wdg.add(button)
        button.add_style("float: right")
        #button.add_style("margin-top: -28px")

        icon_div = DivWdg()
        search_wdg.add(icon_div)
        icon_div.add_style("width: 38px")
        icon_div.add_style("height: 27px")
        icon_div.add_style("padding-top: 3px")
        icon_div.add_style("padding-left: 4px")
        icon_div.add_style("text-align: center")
        #icon_div.add_gradient("background", "background3", 15, -10)
        icon_div.add_color("background", "background3", 10)
        over_color = icon_div.get_color("background3", 0)
        out_color = icon_div.get_color("background3", 10)
        icon_div.set_round_corners(5)
        icon_div.set_box_shadow("1px 1px 1px 1px")
        icon = IconWdg("Search", IconWdg.SEARCH_32, width=24)
        icon_div.add(icon)
        icon_div.add_style("float: right")
        icon_div.add_style("margin-top: -5px")
        button = icon_div
        icon_div.add_class("hand")
        icon_div.add_behavior({
            'type':
            'mouseover',
            'color':
            over_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        })
        icon_div.add_behavior({
            'type':
            'mouseout',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", bvr.color);
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        })
        icon_div.add_behavior({
            'type':
            'click',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("box-shadow", "0px 0px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-3");
            bvr.src_el.setStyle("margin-right", "-2");
            '''
        })
        icon_div.add_behavior({
            'type':
            'click_up',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        })

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords == '') {
                return;
            }

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': 'sthpw/sobject_list',
                'view': 'table',
                'keywords': keywords,
                'simple_search_view': 'simple_search',
                //'show_shelf': false,
            }
            spt.tab.set_main_body_tab();
            spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            '''
        })

        #desc = DivWdg()
        #top.add(desc)
        #desc.add("Dashboard")
        #desc.add_style("width: 600px")

        # create a bunch of panels
        table = Table()
        table.add_color("color", "color")
        table.add_style("margin-bottom: 20px")
        table.center()
        top.add(table)
        table.add_row()

        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "My Approvals"
        description = '''View all pending items for approval<br/><br/>
        '''
        #image = "<img src='/context/images/getting_started_pipeline.png'/>"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.panel.ViewPanelWdg';
        var kwargs = {
            search_type: 'sthpw/sobject_list',
            view: 'client_approval',
            show_shelf: false,
            show_select: false,
            element_names: ['preview', 'name', 'description', 'task_pipeline_vertical','notes'],
            is_editable: false,
            //expression: "@SOBJECT(sthpw/task['project_code','fickle3'].fickle3/cars.sthpw/sobject_list)"
        };
        spt.tab.add_new("approvals", "Approvals", class_name, kwargs);
        '''
        }
        config_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(config_wdg)

        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "My Dashboard"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''Dashboards display key project data in single views. Drill down further to work on tasks, make status changes or add notes.'''

        # read the config file
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path = "%s/../config/dashboard-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")

        #element_name = "my_dashboard"
        element_name = "my_dashboard"
        attrs = config.get_element_attributes(element_name)
        dashboard_data = {}
        kwargs = config.get_display_options(element_name)
        class_name = kwargs.get('class_name')

        dashboard_data['class_name'] = class_name
        dashboard_data['kwargs'] = kwargs
        dashboard_data['title'] = attrs.get("title")
        dashboard_data['description'] = attrs.get("description")
        dashboard_data['image'] = attrs.get("image")

        behavior = {
            'type':
            'click_up',
            'dashboard':
            dashboard_data,
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.startup.dashboards_wdg.DashboardsWdg';
        var kwargs = {};
        spt.tab.set_main_body_tab();
        spt.tab.add_new("my_dashboard", "My Dashboard", bvr.dashboard.class_name, bvr.dashboard.kwargs);
        '''
        }
        pipeline_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(pipeline_wdg)

        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "My Reports"
        image = "<img src='/context/icons/64x64/report_64.png'/>"
        description = '''TACTIC provides a number of predefined reports that project managers can access instantly to get real-time analytics.'''

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg';
        var kwargs = {};
        spt.tab.set_main_body_tab();
        spt.tab.add_new("reports", "Reports", class_name, kwargs);
        //spt.panel.load_popup("Reports", class_name, kwargs);
        '''
        }

        side_bar_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(side_bar_wdg)
        """
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
	title = "Documentation"

        description = '''TACTIC Documentation.
        <br/><br/>
        * Project Setup Documentation<br/>
        <br/>
        * End User Documentation<br/>
        <br/>
        * Developer Documentation<br/>
        <br/>
        * System Administrator Documentation<br/>
        <br/>
        '''
        image = "<img src='/context/images/getting_started_pipeline.png'/>"
        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.load_alias("main")
        '''
        }
        doc_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(doc_wdg)
        """

        tr, td = table.add_row_cell()
        td.add_style("font-size: 14px")
        td.add("<br/>" * 2)

        quick_links_wdg = QuickLinksWdg()
        td.add(quick_links_wdg)

        return top
示例#53
0
    def __init__(self):

        key = "WidgetClassHandler:config"
        self.config = Container.get(key)
        if self.config != None:
            return

        base_config = '''
        <config>
        <widget_definition>
        <element name='simple'>
            <display class='tactic.ui.common.SimpleTableElementWdg'/>
        </element>

        <element name='default'>
            <display class='tactic.ui.common.SimpleTableElementWdg'/>
        </element>



        <element name='raw_data' help='main'>
            <display class='tactic.ui.common.RawTableElementWdg'/>
        </element>


        <element name='format' help='format-element-wdg'>
            <display class='tactic.ui.table.FormatElementWdg'/>
        </element>


        <element name='expression' help='search'>
            <display class='tactic.ui.table.ExpressionElementWdg'/>
        </element>

        <element name='expression_value' help='expression-value-element-wdg'>
            <display class='tactic.ui.table.ExpressionValueElementWdg'/>
        </element>
        <element name='link' help='link-element-wdg'>
            <display class='tactic.ui.table.LinkElementWdg'/>
        </element>



        <element name='completion' help='task-completion-wdg'>
            <display class='tactic.ui.table.TaskCompletionWdg'/>
        </element>

        <element name='gantt' help='gantt-wdg'>
            <display class='tactic.ui.table.GanttElementWdg'/>
        </element>
        <element name='button'>
            <display class='tactic.ui.table.ButtonElementWdg'/>
        </element>


        <element name='custom_layout' help='custom-layout-wdg'>
        <!--
            <display class='tactic.ui.panel.CustomLayoutWdg'/>
        -->
            <display class='tactic.ui.table.CustomLayoutElementWdg'/>
        </element>

        <element name='freeform_layout'>
            <display class='tactic.ui.table.FreeFormLayoutElementWdg'/>
        </element>

        <element name='delete'>
            <display class='tactic.ui.table.DeleteElementWdg'/>
        </element>

        <element name='edit_layout'>
            <display class='tactic.ui.panel.EditWdg'/>
        </element>

        <element name='table_layout'>
            <display class='tactic.ui.panel.TableLayoutWdg'/>
        </element>
        <element name='fast_table_layout'>
            <display class='tactic.ui.panel.FastTableLayoutWdg'/>
        </element>
        <element name='tile_layout'>
            <display class='tactic.ui.panel.TileLayoutWdg'/>
        </element>
        <element name='fast_layout'>
            <display class='tactic.ui.panel.table_layout_wdg.FastTableLayoutWdg'/>
        </element>
        <element name='view_panel'>
            <display class='tactic.ui.panel.ViewPanelWdg'/>
        </element>

        <element name='freeform_layout'>
            <display class='tactic.ui.tools.freeform_layout_wdg.FreeFormLayoutWdg'/>
        </element>



        <element name='explorer'>
            <display class='tactic.ui.table.ExploreElementWdg'/>
        </element>

        <element name='hidden_row'>
            <display class='tactic.ui.table.HiddenRowElementWdg'/>
        </element>






        <element name='title'>
            <display class='tactic.ui.panel.EditTitleWdg'/>
        </element>

        <element name='text'>
            <display class='tactic.ui.input.TextInputWdg'/>
        </element>


        <element name='select'>
            <display class='pyasm.widget.SelectWdg'/>
        </element>
        <element name='calendar'>
            <display class='tactic.ui.widget.CalendarInputWdg'/>
        </element>
        <element name='calendar_time'>
            <display class='tactic.ui.widget.CalendarInputWdg'>
              <show_time>true</show_time>
            </display>
        </element>
        <element name='time'>
            <display class='tactic.ui.widget.TimeInputWdg'/>
        </element>

        <element name='color'>
            <display class='tactic.ui.input.ColorInputWdg'/>
        </element>

        <element name='drop_item' help='drop-element-wdg'>
            <display class='tactic.ui.table.DropElementWdg'/>
        </element>

        <element name='file_list'>
            <display class="tactic.ui.table.SObjectFilesElementWdg"/>
        </element>

        <element name='metadata'>
            <display class="tactic.ui.table.MetadataElementWdg"/>
        </element>

        <element name='python'>
            <display class="tactic.ui.table.PythonElementWdg"/>
        </element>


        </widget_definition>
        </config>
        '''
        from pyasm.widget import WidgetConfig
        self.config = WidgetConfig.get(view='widget_definition',
                                       xml=base_config)

        # customize config to register widgets
        #path = "xxx.conf"

        Container.put(key, self.config)
    def get_display(my):

        top_wdg = DivWdg()
        top_wdg.add_style("color: black")
        top_wdg.add_style("width: 350px")
        top_wdg.add_style("margin-top: 10px")
        top_wdg.add_style("padding: 10px")
        top_wdg.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add_style("margin-top: -22px")

        top_wdg.add(title)
        #if not my.name_string:
        #    title.add('No database column')
        #    return top_wdg

        title.add("Widget Definition")

        widget_types = {
            'foreign_key': 'tactic.ui.table.ForeignKeyElementWdg',
            'button': 'tactic.ui.table.ButtonElementWdg',
            'expression': 'tactic.ui.table.ExpressionElementWdg'
        }

        web = WebContainer.get_web()
        config_string = web.get_form_value("config_xml")
        if not config_string:
            config_string = '<config/>'
        xml = Xml()
        xml.read_string(config_string)

        #print "config_string: ", config_string

        # get values from the config file
        element_name = xml.get_value('element/@name')

        config = WidgetConfig.get(
            view='element',
            xml='<config><element>%s</element></config>' % config_string)
        display_options = config.get_display_options(element_name)

        title = xml.get_value('element/@title')
        display_handler = xml.get_value('element/display/@class')
        if not display_handler:
            display_handler = 'tactic.ui.panel.TypeTableElementWdg'

        widget_name = xml.get_value('element/display/@widget')
        if not widget_name:
            widget_name = 'custom'

        custom_table = Table()
        custom_table.add_style("color: black")
        top_wdg.add(custom_table)

        name_text = DivWdg()
        name_text.add_style("color: black")
        name_text.add(element_name)
        custom_table.add_row()
        custom_table.add_cell("Name: ")
        custom_table.add_cell(name_text)

        # add title
        custom_table.add_row()
        title_wdg = TextWdg("custom_title")
        title_wdg.set_value(title)
        title_wdg.add_attr("size", "50")
        custom_table.add_cell("Title: ")
        custom_table.add_cell(title_wdg)

        # add description
        #custom_table.add_row()
        #description_wdg = TextAreaWdg("custom_description")
        #td = custom_table.add_cell( "Description: " )
        #td.add_style("vertical-align: top")
        #custom_table.add_cell( description_wdg )

        type_select = SelectWdg("custom_type")
        #type_select.add_empty_option("-- Select --")

        type_select.set_option(
            "values",
            "string|integer|float|boolean|currency|date|foreign_key|link|list|button|custom"
        )
        type_select.set_option(
            "labels",
            "String(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key|Link|List|Button|Custom"
        )
        type_select.set_value(widget_name)

        #type_select.set_option("values", "string|integer|float|boolean|currency|date|link|list|foreign_key|button|empty")
        #type_select.set_option("labels", "String|Integer|Float|Boolean|Currency|Date|Link|List|Foreign Key|Button|Empty")
        custom_table.add_row()
        td = custom_table.add_cell("Widget Type: ")
        td.add_style("vertical-align: top")
        td = custom_table.add_cell(type_select)
        type_select.add_event(
            "onchange", "spt.CustomProject.property_type_select_cbk(this)")

        td.add(HtmlElement.br())
        display_handler_text = TextWdg("display_handler")
        display_handler_text.add_attr("size", "50")
        display_handler_text.set_value(display_handler)
        td.add(display_handler_text)

        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())

        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Relate to: ")
        search_type_select = SearchTypeSelectWdg(
            "foreign_key_search_select",
            mode=SearchTypeSelectWdg.CURRENT_PROJECT)
        div.add(search_type_select)
        td.add(div)

        # extra info for list
        custom_table.add_row()
        div = DivWdg()
        div.add_class("list_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Values: ")
        search_type_text = TextWdg("list_values")
        div.add(search_type_text)
        td.add(div)

        # extra info for button
        custom_table.add_row()
        div = DivWdg()
        div.add_style("color: black")
        div.add_class("button_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")

        #class_path = "tactic.ui.table.ButtonElementWdg"
        class_path = display_handler
        button = Common.create_from_class_path(class_path)
        args_keys = button.get_args_keys()

        div.add("Options")
        div.add(HtmlElement.br())

        for key in args_keys.keys():
            option_name_text = HiddenWdg("option_name")
            option_name_text.set_value(key)
            div.add(option_name_text)

            div.add("%s: " % key)
            div.add(" &nbsp; &nbsp;")

            input = button.get_input_by_arg_key(key)

            value = display_options.get(key)
            if value:
                input.set_value(value)

            div.add(input)
            div.add(HtmlElement.br())
        td.add(div)

        # is searchable checkbox
        #custom_table.add_row()
        #current_searchable_wdg = CheckboxWdg("is_searchable")
        #current_view_wdg.set_checked()
        #custom_table.add_cell("Searchable? ")
        #td = custom_table.add_cell(current_searchable_wdg)

        custom_table.close_tbody()

        return top_wdg
示例#55
0
    def get_display(self):


        from tactic.ui.panel import CustomLayoutWdg

        top = self.top
        top.add_class("spt_content_box")
        top.add_class("spt_content_box_inline")
        top.add_style("min-width: 200px")

        #top.add_style("opacity: 0.1")

        """
        top.add_behavior( {
            'type': 'loadX',
            'cbjs_action': '''
            new Fx.Tween(bvr.src_el, {duration: 500}).start("opacity", 1.0);
            '''
        } )
        """

        colors = {
            #"color3": top.get_color("color3"),
            #"background3": top.get_color("background3"),
            #"background3": "rgba(18, 50, 91, 1.0)",
            "background3": "#323232",
            "color3": "#FFF",
            "border": top.get_color("border", -10),
        }

        style = HtmlElement.style()
        top.add(style)
        style.add('''
        .spt_content_box_inline {
            margin: 15px;
        }

        .spt_content_box_max {
            margin: 0px;
            width: 100%%;
            height: 100%%;
            background: rgba(0,0,0,0.0);
            z-index: 1000;
            position: fixed;
            top: 0px;
            left: 0px;
        }

        .spt_content_box_max .spt_content_box_content {
            //height: 100%% !important;
        }


        .spt_content_box .spt_content_box_title {
            width: auto;
            border: none;
            background: %(background3)s;
            color: %(color3)s;
            height: 18px;
            padding: 6px 8px;
            font-weight: bold;
            font-size: 1.2em;
            border: solid 1px %(border)s;
        }

        .spt_content_box .spt_content_box_shelf {
            margin-top: 0px;
            border: solid 1px #AAA;
            padding: 8px 15px;
            height: 23px;
            background: #F8F8F8;
        }

        .spt_content_box .spt_content_box_content {
            width: auto;
            margin-top: -1px;
            margin-bottom: 5px;
            border: solid 1px #AAA;
            padding: 15px 0px 0px 0px;
            background: #FFF;
            overflow-x: auto;

        }

        .spt_content_box .spt_content_box_footer {
            margin-top: -1px;
            border: solid 1px #AAA;
            padding: 8px 15px;
            height: 23px;
            background: #F8F8F8;
        }
        ''' % colors)


        top.add(self.get_title_wdg())

        inner = DivWdg()
        top.add(inner)
        inner.add_class("spt_content_box_inner")
        inner.add_style("overflow: hidden")
        inner.add_style("margin-top: 0px")


        # handle the shelf
        shelf_view = self.kwargs.get("shelf_view")
        if shelf_view:
            shelf_div = DivWdg()
            inner.add(shelf_div)
            shelf_div.add_class("spt_content_box_shelf")

            if shelf_view == "true":
                pass
            else:
                layout = CustomLayoutWdg(view=shelf_view)
                shelf_div.add(layout)



        content_div = DivWdg()
        content_div.add_class("spt_content_box_content")
        inner.add(content_div)
        content_div.add_style("width: auto")

        content_height = self.kwargs.get("content_height")
        if content_height:
            content_div.add_style("height: %s" % content_height)
        content_div.add_style("overflow-x: auto")

        content_view = self.kwargs.get("content_view")
        #content_div.add(content_view)
        if content_view:
            layout = CustomLayoutWdg(view=content_view)
            content_div.add(layout)

            content_margin = self.kwargs.get("content_margin")
            if content_margin:
                layout.add_style("margin", content_margin)

        config_xml = self.kwargs.get("config_xml")
        if config_xml:
            config = WidgetConfig.get(view="tab", xml=config_xml)
            layout = config.get_display_widget("content")
            content_div.add(layout)


        content_wdg = self.get_widget("content")
        if not content_wdg and self.widgets:
            content_wdg = self.widgets[0]
        if content_wdg:
            content_div.add(content_wdg)


        # handle the footer
        footer_view = self.kwargs.get("footer_view")
        if footer_view:
            footer_div = DivWdg()
            inner.add(footer_div)
            footer_div.add_class("spt_content_box_footer")

            layout = CustomLayoutWdg(view=footer_view)
            shelf_div.add(layout)


        return top
示例#56
0
    def get_config(my):
        config = None
        config_xml = my.kwargs.get('config_xml')
        if config_xml:
            config = WidgetConfig.get(xml=config_xml, view=my.view)
            return config


        # this is the new preferred way of defining CustomLayoutWdg
        search = Search("config/widget_config")
        if my.category:
            search.add_filter("category", my.category)
        else:
            search.add_filter("category", 'CustomLayoutWdg')
        if my.search_type:
            search.add_filter("search_type", my.search_type)

        search.add_filter("view", my.view)

        config = search.get_sobject()
        if config:
            return config
        # if it is not defined in the database, look at a config file
        
        includes = my.kwargs.get("include")
        if includes:
            includes = includes.split("|")

            for include in includes:
                tmp_path = __file__
                dir_name = os.path.dirname(tmp_path)
                file_path="%s/../config/%s" % (dir_name, include)
                config = WidgetConfig.get(file_path=file_path, view=my.view)
                if config and config.has_view(my.view):
                    return config

        # deprecated approach, assuming a "CustomLayoutWdg" as search_type,
        # is deprecated
        if not config:
            search = Search("config/widget_config")
            if my.category:
                search.add_filter("category", my.category)
            if my.search_type:
                search.add_filter("search_type", "CustomLayoutWdg")

            search.add_filter("view", my.view)

            config = search.get_sobject()
        
        #if not config and my.search_type and my.view:
        #    config = WidgetConfigView.get_by_search_type(my.search_type, my.view)
        # this is the new preferred way of defining CustomLayoutWdg
        # NOTE: this finds a definition where search type is not explicitly
        # given>
        if not config:
            search = Search("config/widget_config")
            search.add_filter("view", my.view)
            search.add_filter("search_type", None)
            config = search.get_sobject()


        return config
示例#57
0
    def get_display(my):

        from tactic.ui.panel import CustomLayoutWdg

        top = my.top
        top.add_class("spt_content_box")
        top.add_class("spt_content_box_inline")
        top.add_style("min-width: 200px")

        #top.add_style("opacity: 0.1")
        """
        top.add_behavior( {
            'type': 'loadX',
            'cbjs_action': '''
            new Fx.Tween(bvr.src_el, {duration: 500}).start("opacity", 1.0);
            '''
        } )
        """

        colors = {
            #"color3": top.get_color("color3"),
            #"background3": top.get_color("background3"),
            #"background3": "rgba(18, 50, 91, 1.0)",
            "background3": "#323232",
            "color3": "#FFF",
            "border": top.get_color("border", -10),
        }

        style = HtmlElement.style()
        top.add(style)
        style.add('''
        .spt_content_box_inline {
            margin: 15px;
        }

        .spt_content_box_max {
            margin: 0px;
            width: 100%%;
            height: 100%%;
            background: rgba(0,0,0,0.0);
            z-index: 1000;
            position: fixed;
            top: 0px;
            left: 0px;
        }

        .spt_content_box_max .spt_content_box_content {
            //height: 100%% !important;
        }


        .spt_content_box .spt_content_box_title {
            width: auto;
            border: none;
            background: %(background3)s;
            color: %(color3)s;
            height: 18px;
            padding: 6px 8px;
            font-weight: bold;
            font-size: 1.2em;
            border: solid 1px %(border)s;
        }

        .spt_content_box .spt_content_box_shelf {
            margin-top: 0px;
            border: solid 1px #AAA;
            padding: 8px 15px;
            height: 23px;
            background: #F8F8F8;
        }

        .spt_content_box .spt_content_box_content {
            width: auto;
            margin-top: -1px;
            margin-bottom: 5px;
            border: solid 1px #AAA;
            padding: 15px 0px 0px 0px;
            background: #FFF;
            overflow-x: auto;

        }

        .spt_content_box .spt_content_box_footer {
            margin-top: -1px;
            border: solid 1px #AAA;
            padding: 8px 15px;
            height: 23px;
            background: #F8F8F8;
        }
        ''' % colors)

        top.add(my.get_title_wdg())

        inner = DivWdg()
        top.add(inner)
        inner.add_class("spt_content_box_inner")
        inner.add_style("overflow: hidden")
        inner.add_style("margin-top: 0px")

        # handle the shelf
        shelf_view = my.kwargs.get("shelf_view")
        if shelf_view:
            shelf_div = DivWdg()
            inner.add(shelf_div)
            shelf_div.add_class("spt_content_box_shelf")

            if shelf_view == "true":
                pass
            else:
                layout = CustomLayoutWdg(view=shelf_view)
                shelf_div.add(layout)

        content_div = DivWdg()
        content_div.add_class("spt_content_box_content")
        inner.add(content_div)
        content_div.add_style("width: auto")

        content_height = my.kwargs.get("content_height")
        if content_height:
            content_div.add_style("height: %s" % content_height)
        content_div.add_style("overflow-x: auto")

        content_view = my.kwargs.get("content_view")
        #content_div.add(content_view)
        if content_view:
            layout = CustomLayoutWdg(view=content_view)
            content_div.add(layout)

            content_margin = my.kwargs.get("content_margin")
            if content_margin:
                layout.add_style("margin", content_margin)

        config_xml = my.kwargs.get("config_xml")
        if config_xml:
            config = WidgetConfig.get(view="tab", xml=config_xml)
            layout = config.get_display_widget("content")
            content_div.add(layout)

        content_wdg = my.get_widget("content")
        if not content_wdg and my.widgets:
            content_wdg = my.widgets[0]
        if content_wdg:
            content_div.add(content_wdg)

        # handle the footer
        footer_view = my.kwargs.get("footer_view")
        if footer_view:
            footer_div = DivWdg()
            inner.add(footer_div)
            footer_div.add_class("spt_content_box_footer")

            layout = CustomLayoutWdg(view=footer_view)
            shelf_div.add(layout)

        return top
示例#58
0
    def get_display(my):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_color("background", "background")

        top.add_class("spt_reports_top")

        title = DivWdg()
        title.add("Dashboards")
        title.add_style("font-size: 18px")
        title.add_style("font-weight: bold")
        title.add_style("text-align: center")
        title.add_style("padding: 10px")
        title.add_style("margin: -10px -10px 10px -10px")
        title.add_gradient("background", "background3", 5, -10)
        top.add(title)

        from tactic.ui.widget import TitleWdg
        subtitle = TitleWdg(name_of_title='List of Dashboards',
                            help_alias='project-startup-dashboards')
        top.add(subtitle)

        top.add("<br/>")

        dashboards = []

        # read the config file
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path = "%s/../config/dashboard-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")
        element_names = config.get_element_names()

        for element_name in element_names:
            attrs = config.get_element_attributes(element_name)
            dashboard_data = {}
            kwargs = config.get_display_options(element_name)
            class_name = kwargs.get('class_name')

            dashboard_data['class_name'] = class_name
            dashboard_data['kwargs'] = kwargs
            dashboard_data['title'] = attrs.get("title")
            dashboard_data['description'] = attrs.get("description")
            dashboard_data['image'] = attrs.get("image")
            dashboard_data['image'] = attrs.get("image")

            dashboards.append(dashboard_data)

        # get all of the configs from the database
        search = Search("config/widget_config")
        search.add_filter("widget_type", "dashboard")
        db_configs = search.get_sobjects()

        for db_config in db_configs:
            dashboard_data = {}
            view = db_config.get_value("view")
            kwargs = {'view': view}
            parts = view.split(".")
            title = Common.get_display_title(parts[-1])

            xml = db_config.get_value("config")

            dashboard_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg"
            dashboard_data['kwargs'] = kwargs
            dashboard_data['title'] = title
            dashboard_data['description'] = title
            dashboard_data['image'] = None
            dashboard_data['xml'] = xml
            dashboard_data['widget_type'] = db_config.get_value("widget_type")

            dashboards.append(dashboard_data)

        # create a bunch of panels
        table = Table()
        top.add(table)
        table.add_color("color", "color")
        table.add_style("margin-bottom: 20px")
        table.center()

        for i, dashboard in enumerate(dashboards):

            if i == 0 or i % 4 == 0:
                tr = table.add_row()

            td = table.add_cell()
            td.add_style("vertical-align: top")
            td.add_style("padding: 3px")
            title = dashboard

            description = dashboard.get("title")

            # Each node will contain a list of "items" and will be stored as a table in the database.'''

            class_name = dashboard.get("class_name")
            kwargs = dashboard.get("kwargs")
            title = dashboard.get("title")
            description = dashboard.get("description")
            xml = dashboard.get("xml") or ""

            image = dashboard.get("image")
            icon = dashboard.get("icon")

            if image:
                div = DivWdg()
                if isinstance(image, basestring):
                    image = image.upper()
                    image = eval("IconWdg('', IconWdg.%s)" % image)
                    div.add_style("margin-left: 15px")
                    div.add_style("margin-top: 5px")
                else:
                    image = image
                div.add(image)
                image = div

            elif icon:
                icon = icon.upper()
                image = eval("IconWdg('', IconWdg.%s)" % icon)

            else:
                div = DivWdg()
                #image = IconWdg("Bar Chart", IconWdg.WARNING)
                image = IconWdg("Bar Chart", IconWdg.DASHBOARD_02)
                div.add_style("margin-left: 15px")
                div.add_style("margin-top: 5px")
                div.add(image)
                image = div

            behavior = {
                'type':
                'click_up',
                'title':
                title,
                'class_name':
                class_name,
                'kwargs':
                kwargs,
                'cbjs_action':
                '''

            var top = bvr.src_el.getParent(".spt_reports_top");
            spt.tab.set_main_body_tab();
            //spt.tab.set_tab_top(top);
            var kwargs = {};
            spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs);
            '''
            }
            schema_wdg = my.get_section_wdg(title, description, image,
                                            behavior)

            schema_wdg.add_behavior({
                'type':
                'load',
                'title':
                title,
                'class_name':
                class_name,
                'xml':
                xml,
                'kwargs':
                kwargs,
                'cbjs_action':
                '''
                var report_top = bvr.src_el;
                report_top.kwargs = bvr.kwargs;
                report_top.class_name = bvr.class_name;
                report_top.element_name = bvr.title;
                report_top.xml = bvr.xml;
            '''
            })

            td.add(schema_wdg)

        #from tactic.ui.container import TabWdg
        #tab = TabWdg(show_add=False)
        #top.add(tab)

        return top