Ejemplo n.º 1
0
    def get_display(my):
        # if no filters are defined, then display nothing
        if not my.filters:
            return Widget()

        #filter_top = DivWdg(css="maq_search_bar")
        filter_top = DivWdg()
        filter_top.add_color("color", "color")
        filter_top.add_color("background", "background", -5)
        filter_top.add_style("padding: 5px")
        filter_top.add_style("min-width: 700px")
        filter_top.add_border()
        my.set_as_panel(filter_top)


        # TEST link to help for search widget
        help_button = ActionButtonWdg(title="?", tip="Search Documentation", size='small')
        filter_top.add(help_button)
        help_button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.help.set_top();
            spt.help.load_alias("search-quickstart|what-is-searching|search-interface|search-compound|search-expressions");
            '''
        } )
        help_button.add_style("float: right")


        # this id should be removed
        filter_top.set_id("%s_search" % my.prefix)
        filter_top.add_class("spt_search")


        for name, value in my.kwargs.items():
            filter_top.set_attr("spt_%s" % name, value)

        #filter_top.add(my.statement)
        popup = my.get_retrieve_wdg()
        filter_top.add(popup)
        popup = my.get_save_wdg()
        filter_top.add(popup)

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

        # Add a number of filters indicator
        div = DivWdg()
        div.add_class("spt_search_num_filters")
        div.add_style("float: right")
        div.add_style("font-size: 0.9em")
        div.add_style("margin: 0 10 0 10")
        #search_summary.add(div)
        filter_top.add(div)

        if my.num_filters_enabled:
            msg = "[%s] filter/s" % my.num_filters_enabled
            icon = IconWdg(msg, IconWdg.DOT_GREEN)
            div.add(icon)
            div.add("%s" % msg)


        filter_div = DivWdg()
        filter_div.set_id("search_filters")
        filter_div.add_class("spt_search_filters")


        # TODO: disabling for now
        # add the action buttons
        #action_wdg =  my.get_action_wdg()
        #action_wdg.add_style("text-align: right")
        #filter_div.add( action_wdg )
        # add the top
        display_str = 'block'
        if not display:
            display_str = 'none'
        filter_div.add_style("display: %s" % display_str)

        search_wdg = my.get_search_wdg()

        prefix = "filter_mode"
        if my.prefix_namespace:
            prefix = '%s_%s' %(my.prefix_namespace, prefix)
        hidden = HiddenWdg("prefix", prefix)

        match_div = DivWdg()
        match_div.add(hidden)
        match_div.add_class('spt_search_filter') 

        palette =  match_div.get_palette()
        bg_color = palette.color('background')
        light_bg_color =  palette.color('background', modifier=+10)
        

        select = SelectWdg("filter_mode")
        select.add_class("spt_search_filter_mode")
        select.set_persist_on_submit(prefix)
        select.remove_empty_option() 
        # for Local search, leave out compound search for now
        if my.kwargs.get('prefix_namespace'):
            select.set_option("labels", "Match all|Match any")
            select.set_option("values", "and|or")
        else:
            select.set_option("labels", "Match all|Match any|Compound search")
            select.set_option("values", "and|or|custom")
        #select.set_option("labels", "all|any")
        #select.set_option("values", "and|or")

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var display = bvr.src_el.value == 'custom';;

        var top = bvr.src_el.getParent(".spt_search");
        var ops = top.getElements(".spt_op");
        for (var i = 0; i < ops.length; i++) {
            var op = ops[i];
            var element = op.getElement(".spt_op_display");
            var value = op.getAttribute("spt_op");
            if (display) {
                element.innerHTML = value;
                var level = op.getAttribute("spt_level");
                if (level == 1) {
                    element.setStyle("background", "%s")
                    element.setStyle("padding", "4px")
                }
            } else {
                element.innerHTML = '&nbsp;';
                element.setStyle("background", "%s")
                element.setStyle("padding", "1px")
            }
        }
        ''' %(light_bg_color, bg_color)
        } )

        match_div.add(select)
        match_div.add_color("color", "color2")
        match_div.add(" on the following")
        hint = HintWdg( "An 'AND' operation is always applied to each category below. " \
                        "This controls only the filters within each category." )
        match_div.add(hint)
        match_div.add('<br/>')

        match_div.add_style("padding-top: 5px")

        filter_div.add( search_wdg)
        search_wdg.add_style("float: left")
        filter_div.add( match_div)


        filter_div.add(HtmlElement.br())

        filters_div = DivWdg()
        filters_div.add_style("margin: 0 -6 0 -6")

        security = Environment.get_security()

        # add all the filters
        for filter in my.filters:
            element_name = filter.get_name()

            if not security.check_access("search", element_name, "view"):
                continue

            # no need to create it again    
            #filter = my.config.get_display_widget(element_name)
            div = DivWdg()
            filters_div.add(div)

            div.add_class("hand")
            class_suffix = element_name.replace(' ', '_')
            cbjs_action = 'var el=spt.get_cousin(bvr.src_el,".spt_search",".spt_filter_%s");spt.simple_display_toggle(el);' % class_suffix
            div.add_behavior( {
                'type': 'click_up',
                'cbjs_action': cbjs_action
            } )
            div.add_color("color", "color", +5)
            div.add_gradient("background", "background", -5, -5)
            div.add_style("margin-top: -1px")

            div.add_border()
            div.add_style("padding: 3px")
            div.add_style("whitespace: nowrap")

            
            if element_name in ["Parent", 'Children']:
                swap = SwapDisplayWdg.get_triangle_wdg()
            else:
                swap = SwapDisplayWdg.get_triangle_wdg()
                swap.set_off()
            swap.add_action_script(cbjs_action)


            div.add_event("onclick", swap.get_swap_script() )
            div.add(swap)
            div.add_class("SPT_DTS")
            div.add(element_name)

            div = DivWdg()
            div.add_class("spt_filter_%s" % class_suffix)

            if element_name in ["Parent", 'Children']:
                div.add_style("display: none")
            else:
                div.add_style("display: block")

            #div.add_style("background-color: #333")
            div.add_color("background", "background")
            div.add_border()
            div.add_style("padding: 5px 3px 5px 3px")
            div.add_style("margin-top: -1px")
            #div.add_style("margin-left: 20px")
            #div.add_style("width: 660")
            div.add(filter)
            filters_div.add(div)

        filter_div.add(filters_div)

        buttons_div = DivWdg()
        buttons_div.add_style("margin-top: 7px")
        buttons_div.add_style("margin-bottom: 7px")
        buttons_div.add(my.get_search_wdg() )
        filter_div.add(buttons_div)


        filter_top.add(filter_div)

        return filter_top
Ejemplo n.º 2
0
    def get_display(my):
        # if no filters are defined, then display nothing
        if not my.filters:
            return Widget()

        #filter_top = DivWdg(css="maq_search_bar")
        filter_top = DivWdg()
        filter_top.add_color("color", "color")
        filter_top.add_color("background", "background", -5)
        filter_top.add_style("padding: 5px")
        filter_top.add_style("min-width: 800px")
        filter_top.add_border()
        my.set_as_panel(filter_top)

        # TEST link to help for search widget
        help_button = ActionButtonWdg(title="?",
                                      tip="Search Documentation",
                                      size='small')
        filter_top.add(help_button)
        help_button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.help.set_top();
            spt.help.load_alias("search-quickstart|what-is-searching|search-interface|search-compound|search-expressions");
            '''
        })
        help_button.add_style("float: right")

        # this id should be removed
        filter_top.set_id("%s_search" % my.prefix)
        filter_top.add_class("spt_search")

        for name, value in my.kwargs.items():
            filter_top.set_attr("spt_%s" % name, value)

        #filter_top.add(my.statement)
        popup = my.get_retrieve_wdg()
        filter_top.add(popup)
        popup = my.get_save_wdg()
        filter_top.add(popup)

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

        # Add a number of filters indicator
        div = DivWdg()
        div.add_class("spt_search_num_filters")
        div.add_style("float: right")
        div.add_style("font-size: 0.9em")
        div.add_style("margin: 0 10 0 10")
        #search_summary.add(div)
        filter_top.add(div)

        if my.num_filters_enabled:
            msg = "[%s] filter/s" % my.num_filters_enabled
            icon = IconWdg(msg, IconWdg.DOT_GREEN)
            div.add(icon)
            div.add("%s" % msg)

        filter_div = DivWdg()
        filter_div.set_id("search_filters")
        filter_div.add_class("spt_search_filters")

        # TODO: disabling for now
        # add the action buttons
        #action_wdg =  my.get_action_wdg()
        #action_wdg.add_style("text-align: right")
        #filter_div.add( action_wdg )
        # add the top
        display_str = 'block'
        if not display:
            display_str = 'none'
        filter_div.add_style("display: %s" % display_str)

        search_wdg = my.get_search_wdg()

        prefix = "filter_mode"
        if my.prefix_namespace:
            prefix = '%s_%s' % (my.prefix_namespace, prefix)
        hidden = HiddenWdg("prefix", prefix)

        match_div = DivWdg()
        match_div.add(hidden)
        match_div.add_class('spt_search_filter')

        palette = match_div.get_palette()
        bg_color = palette.color('background')
        light_bg_color = palette.color('background', modifier=+10)

        select = SelectWdg("filter_mode")
        select.add_style("width: 110px")

        select.add_class("spt_search_filter_mode")
        select.set_persist_on_submit(prefix)
        select.remove_empty_option()
        # for Local search, leave out compound search for now
        if my.kwargs.get('prefix_namespace'):
            select.set_option("labels", "Match all|Match any")
            select.set_option("values", "and|or")
        else:
            select.set_option("labels", "Match all|Match any|Compound")
            select.set_option("values", "and|or|custom")
        #select.set_option("labels", "all|any")
        #select.set_option("values", "and|or")

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var display = bvr.src_el.value == 'custom';;

        var top = bvr.src_el.getParent(".spt_search");
        var ops = top.getElements(".spt_op");
        for (var i = 0; i < ops.length; i++) {
            var op = ops[i];
            var element = op.getElement(".spt_op_display");
            var value = op.getAttribute("spt_op");
            if (display) {
                element.innerHTML = value;
                var level = op.getAttribute("spt_level");
                if (level == 1) {
                    element.setStyle("background", "%s")
                    element.setStyle("padding", "4px")
                }
            } else {
                element.innerHTML = '&nbsp;';
                element.setStyle("background", "%s")
                element.setStyle("padding", "1px")
            }
        }
        ''' % (light_bg_color, bg_color)
        })

        match_div.add(select)
        match_div.add_color("color", "color2")
        #match_div.add(" on the following")
        #hint = HintWdg( "An 'AND' operation is always applied to each category below. " \
        #                "This controls only the filters within each category." )
        #match_div.add(hint)
        #match_div.add('<br/>')
        #match_div.add_style("padding-top: 5px")

        filter_div.add(search_wdg)
        search_wdg.add_style("float: left")
        filter_div.add(match_div)

        filter_div.add(HtmlElement.br())

        filters_div = DivWdg()
        filters_div.add_style("margin: 0 -6 0 -6")

        security = Environment.get_security()

        # add all the filters
        for filter in my.filters:
            element_name = filter.get_name()

            if not security.check_access("search", element_name, "view"):
                continue

            # no need to create it again
            #filter = my.config.get_display_widget(element_name)
            div = DivWdg()
            filters_div.add(div)

            div.add_class("hand")
            class_suffix = element_name.replace(' ', '_')
            cbjs_action = 'var el=spt.get_cousin(bvr.src_el,".spt_search",".spt_filter_%s");spt.simple_display_toggle(el);' % class_suffix
            div.add_behavior({'type': 'click_up', 'cbjs_action': cbjs_action})
            div.add_color("color", "color", +5)
            #div.add_gradient("background", "background", -5, -5)
            div.add_style("margin-top: -1px")
            div.add_style("height: 18px")

            div.add_border()
            div.add_style("padding: 8px 5px")
            div.add_style("whitespace: nowrap")

            if element_name in ["Parent", 'Children']:
                swap = SwapDisplayWdg.get_triangle_wdg()
            else:
                swap = SwapDisplayWdg.get_triangle_wdg()
                swap.set_off()
            swap.add_action_script(cbjs_action)

            div.add_event("onclick", swap.get_swap_script())
            div.add(swap)
            div.add_class("SPT_DTS")
            div.add(element_name)

            div = DivWdg()
            div.add_class("spt_filter_%s" % class_suffix)

            if element_name in ["Parent", 'Children']:
                div.add_style("display: none")
            else:
                div.add_style("display: block")

            #div.add_style("background-color: #333")
            div.add_color("background", "background")
            div.add_border()
            div.add_style("padding: 10px 8px")
            div.add_style("margin-top: -1px")
            #div.add_style("margin-left: 20px")
            #div.add_style("width: 660")
            div.add(filter)
            filters_div.add(div)

        filter_div.add(filters_div)

        buttons_div = DivWdg()
        buttons_div.add_style("margin-top: 7px")
        buttons_div.add_style("margin-bottom: 7px")
        search_wdg = my.get_search_wdg()
        search_wdg.add_style("margin: 15px auto")
        buttons_div.add(search_wdg)
        filter_div.add(buttons_div)

        filter_top.add(filter_div)

        return filter_top