Beispiel #1
0
    def check(my):
        my.web = WebContainer.get_web()
        search_type = my.sobject.get_search_type_obj()
        
        config = WidgetConfig.get_by_search_type(search_type, "insert", local_search=True)
        columns = config.get_element_names()

        if len(columns) != 3:
            raise TacticException('The command is expecting 3 fields only.')
      
        my.date = my.web.get_form_value('edit|%s' % columns[0])
        my.desc =  my.web.get_form_value('edit|%s'% columns[1])
        date = Date(db_date=my.date)
        my.year = date.get_year()
        my.week = date.get_week()
        my.project_code =  my.web.get_form_value('edit|%s'% columns[2])
         
        if not my.desc or not my.date or not my.project_code:
            raise UserException('One or more fields are empty.')
        Project.set_project(my.project_code)
        return True
Beispiel #2
0
    def get_display(my):
        if not my.search_type:
            return "No search type found"

        web = WebContainer.get_web()
        my.view = web.get_form_value("view")
        if not my.view:
            my.view = web.get_form_value("filter|view")
        if not my.view:
            my.view = get_template_view()

        widget = Widget()

        widget.add( HiddenWdg("search_type", my.search_type) )

        element_names = []

        # see if there is an override
        search_type_obj = SearchType.get(my.search_type)  
        config = WidgetConfig.get_by_search_type(my.search_type,"browser_list")
        if config:
            element_names = config.get_element_names()


        search = Search("sthpw/widget_config")
        search.add_filter("search_type", my.search_type)
        search.add_filter("view", my.view)
        widget_config = search.get_sobject()
        if widget_config:
            edit_link_wdg = EditLinkWdg("sthpw/widget_config", widget_config.get_id(), text="Edit XML", long=True)
            edit_link_wdg.set_iframe_width(95)
            widget.add(edit_link_wdg)


        custom_config = WidgetConfigView.get_by_search_type(my.search_type,my.view)
        custom_element_names = custom_config.get_element_names()


        # get the custom properties
        search = Search("prod/custom_property")
        search.add_filter("search_type", my.search_type)
        custom_properties = search.get_sobjects()


        # action popup
        action_popup = PopupMenuWdg("table_action", multi=True, width='12em')
        action_popup.set_auto_hide(False)
        action_popup.set_submit(False)

        
        action_popup.add( HtmlElement.href("Add ...", "javascript:document.form.submit()") )


        for custom_property in custom_properties:
            element_name = custom_property.get_name()
            if element_name not in custom_element_names:
                action_popup.add( " %s" % element_name, "add|%s" % element_name )

        # if there is an override
        if element_names:
            for element_name in element_names:
                if element_name not in custom_element_names:
                    action_popup.add( " %s" % element_name, "add|%s" % element_name )


        # get all of the columns
        else:
            search_type_obj = SearchType.get(my.search_type)
            element_names = search_type_obj.get_columns()

            for element_name in element_names:
                if element_name not in custom_element_names:
                    action_popup.add( " %s" % element_name, "add|%s" % element_name )

            # add some standard properties
            if my.view in ["edit", "insert"]:
                for element_name in PREDEFINED_EDIT_ELEMENTS:
                    if element_name not in custom_element_names:
                        action_popup.add( " %s" % element_name, "add|%s" % element_name )
            else:
                for element_name in PREDEFINED_ELEMENTS:
                    if element_name not in custom_element_names:
                        action_popup.add( " %s" % element_name, "add|%s" % element_name )

        action_popup.add_separator()
        action_popup.add( HtmlElement.href("Remove ...", "javascript:document.form.submit()") )
        for element_name in custom_element_names:
            action_popup.add( " %s" % element_name, "remove|%s" % element_name )
        action_popup.add_separator()

        span = SpanWdg("New Custom ...", css="hand")
        iframe = WebContainer.get_iframe()
        url = WebContainer.get_web().get_widget_url()
        url.set_option("widget", "pyasm.widget.CustomAddPropertyWdg")
        url.set_option("search_type", my.search_type)
        url.set_option("view", my.view)
        action = iframe.get_on_script(url.to_string() )
        span.add_event("onclick", action)
        action_popup.add( span )


        # add the edit button
        edit = IconButtonWdg("Edit View", IconWdg.EDIT, True)

        edit.add_event("oncontextmenu", "%s;return false" % action_popup.get_on_script() )
        edit.add_event("onclick", "%s" % action_popup.get_on_script() )



        # lay it all out
        widget.add(SpanWdg(action_popup))
        widget.add(edit)

        # add the edit button
        #save = IconButtonWdg("Save", IconWdg.SAVE, True)
        #widget.add(save)

        # add the add property button
        if my.mode == "admin":
            add = CustomAddPropertyLinkWdg(my.search_type, my.view)
            widget.add(add)
            #add_element = CustomAddElementLinkWdg(my.search_type, my.view)
            #widget.add(add_element)


        # add the clear button
        if my.mode == "admin" or my.view.startswith("custom_"):
            clear = IconSubmitWdg("Clear", IconWdg.DELETE, True)
            widget.add(clear)

        
        widget.add(SpanWdg(css="small"))


        WebContainer.register_cmd("pyasm.widget.CustomViewAction")

        return widget