Exemplo n.º 1
0
    def get_attrs_by_search_type(self, search_type):
        node = self.xml.get_node("schema/search_type[@name='%s']" % search_type)
        if node is not None:
            attrs = Xml.get_attributes(node)
        else:
            attrs = {}

        if not attrs and self.parent_schema:
            attrs = self.parent_schema.get_attrs_by_search_type(search_type)
        if not attrs and self.sthpw_schema:
            attrs = self.sthpw_schema.get_attrs_by_search_type(search_type)

        return attrs
Exemplo n.º 2
0
 def get_attr_by_search_type(self, search_type, attr):
     node = self.xml.get_node("schema/search_type[@name='%s']" % search_type)
     if node is None:
         return {}
     return Xml.get_attributes(node).get(attr)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def get_container(my, xml):
        # handle the container

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

        show_resize_scroll = attrs.get("show_resize_scroll")
        if not show_resize_scroll:
            show_resize_scroll = my.kwargs.get("show_resize_scroll")
        if not show_resize_scroll:
            show_resize_scroll = "false"


        # look for attributes in the element tag for specifying a title action button to plug
        # into the title bar of the custom section ...
        #
        title_action_icon = attrs.get("title_action_icon")
        title_action_script = attrs.get("title_action_script")
        title_action_label = attrs.get("title_action_label")
        if title_action_script and not title_action_label:
            title_action_label = '[action]'


        # get the width and height for the element content ...
        width = attrs.get("width")
        height = attrs.get("height")


        if width and height:
            container = ContainerWdg( inner_width=width, inner_height=height, show_resize_scroll=show_resize_scroll )
        else:
            container = ContainerWdg(show_resize_scroll=show_resize_scroll)

        # create the title
        title = attrs.get("title")
        if not title:
            title = Common.get_display_title(element_name)
        title_wdg = DivWdg()
        SmartMenu.assign_as_local_activator( title_wdg, 'HEADER_CTX' )
        title_wdg.add_style("margin: 0px 0px 5px 0px")
        title_wdg.add_gradient("background", "background", 0)
        title_wdg.add_color("color", "color")
        title_wdg.add_style("padding", "5px")


        if title_action_script:
            # add an action button if an action script code was found in the attributes of the element
            proj = Project.get_project_code()
            script_search = Search("config/custom_script")
            script_sobj = script_search.get_by_search_key( "config/custom_script?project=%s&code=%s" %
                                                           (proj, title_action_script) )
            script = script_sobj.get_value('script')
            icon_str = "HELP"
            if title_action_icon:
                icon_str = title_action_icon
            action_btn = HtmlElement.img( IconWdg.get_icon_path(icon_str) )
            action_btn.set_attr('title',title_action_label)
            # action_btn = IconWdg( title_action_label, icon=icon)
            action_btn.add_behavior( {'type': 'click_up', 'cbjs_action':  script } )
            action_btn.add_styles( "cursor: pointer; float: right;" )

            title_wdg.add( action_btn )


        title_wdg.add(title)
        container.add(title_wdg)

        return container
Exemplo n.º 5
0
 def get_attributes(my):
     return Xml.get_attributes(my.node)
Exemplo n.º 6
0
    def get_container(my, xml):
        # handle the container

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

        show_resize_scroll = attrs.get("show_resize_scroll")
        if not show_resize_scroll:
            show_resize_scroll = my.kwargs.get("show_resize_scroll")
        if not show_resize_scroll:
            show_resize_scroll = "false"


        # look for attributes in the element tag for specifying a title action button to plug
        # into the title bar of the custom section ...
        #
        title_action_icon = attrs.get("title_action_icon")
        title_action_script = attrs.get("title_action_script")
        title_action_label = attrs.get("title_action_label")
        if title_action_script and not title_action_label:
            title_action_label = '[action]'


        # get the width and height for the element content ...
        width = attrs.get("width")
        height = attrs.get("height")


        if width and height:
            container = ContainerWdg( inner_width=width, inner_height=height, show_resize_scroll=show_resize_scroll )
        else:
            container = ContainerWdg(show_resize_scroll=show_resize_scroll)

        # create the title
        title = attrs.get("title")
        if not title:
            title = Common.get_display_title(element_name)
        title_wdg = DivWdg()
        SmartMenu.assign_as_local_activator( title_wdg, 'HEADER_CTX' )
        title_wdg.add_style("margin: 0px 0px 5px 0px")
        title_wdg.add_gradient("background", "background", 0)
        title_wdg.add_color("color", "color")
        title_wdg.add_style("padding", "5px")


        if title_action_script:
            # add an action button if an action script code was found in the attributes of the element
            proj = Project.get_project_code()
            script_search = Search("config/custom_script")
            script_sobj = script_search.get_by_search_key( "config/custom_script?project=%s&code=%s" %
                                                           (proj, title_action_script) )
            script = script_sobj.get_value('script')
            icon_str = "HELP"
            if title_action_icon:
                icon_str = title_action_icon
            action_btn = HtmlElement.img( IconWdg.get_icon_path(icon_str) )
            action_btn.set_attr('title',title_action_label)
            # action_btn = IconWdg( title_action_label, icon=icon)
            action_btn.add_behavior( {'type': 'click_up', 'cbjs_action':  script } )
            action_btn.add_styles( "cursor: pointer; float: right;" )

            title_wdg.add( action_btn )


        title_wdg.add(title)
        container.add(title_wdg)

        return container
Exemplo n.º 7
0
    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

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



            # look at the attributes
            class_name = attrs.get("display_class")
            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 value.split(";"):
                        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
Exemplo n.º 8
0
    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")

        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")

            # look at the attributes
            class_name = attrs.get("display_class")
            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.
                # TODO: 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)



        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

            # TODO: 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 value.split(";"):
                        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)



            # DEPRECATED
            # All of these state mechanisms are deprecated and replaced with
            # the above explicit method for passing state

            # add in some extra options that can be used by the child.
            # parent_key and state are kept for backwards compatibility
            """
            extra = {
                'parent_key': my.search_key,
                'state': my.state,
                'parent_kwargs: ': my.kwargs # FIXME: not sure about this
            }
            element_wdg = config.get_display_widget(element_name, extra_options=extra)
            # FIXME: what is this for?
            # add external some parameters passed from the top widget
            element_wdg.kwargs['parent_key'] = my.search_key
            element_wdg.kwargs['state'] = my.state
            """



        except Exception, e:
            from pyasm.widget import ExceptionWdg
            log = ExceptionWdg(e)
            element_wdg = log
Exemplo n.º 9
0
 def get_attributes(my):
     return Xml.get_attributes(my.node)
Exemplo n.º 10
0
 def get_attributes(self):
     return Xml.get_attributes(self.node)