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

        web = WebContainer.get_web()

        widget = DivWdg()
        widget.add_class("spt_search_limit_top")
        #widget.add_style("border", "solid 1px blue")
        widget.add_color("background", "background")
        widget.add_color("color", "color")
        widget.add_style("padding: 5px")

        hidden = HiddenWdg("prefix", my.prefix)
        widget.add(hidden)

   
        if not my.search and not my.sobjects:
            widget.add("No search or sobjects found")
            return widget

        # my.count should have been set in alter_search()
        # which can be called explicitly thru this instance, my.
        if not my.count:
            my.count = my.search.get_count(no_exception=True)
        
        # if my.sobjects exist thru inheriting from parent widgets
        # or explicitly set, (this is not mandatory though)
        if my.sobjects and len(my.sobjects) < my.search_limit:
            limit = len(my.sobjects)
        elif my.search and my.count < my.search_limit:
            # this is only true if the total result of the search is 
            # less than the limit and so this wdg will not display
            limit = my.count
        else:
            limit = my.search_limit

        if not limit:
            limit = 50
            my.search_limit = limit

    
        if my.refresh: 
            prev = SpanWdg( IconButtonWdg("Prev", IconWdg.LEFT, False ) )
            prev.add_style("margin-left: 8px")
            prev.add_style("margin-right: 6px")
            prev.add_style("margin-top: -2px")
            next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" )
            next.add_style("margin-left: 6px")

            prev.add_behavior( {
                'type': 'click_up',
                'cbjs_action': my.refresh_script
            } )
            next.add_behavior( {
                'type': 'click_up',
                'cbjs_action': my.refresh_script
            } )
        else: # the old code pre 2.5
            prev = IconButtonWdg("Prev", IconWdg.LEFT, False )
            hidden_name = my.prev_hidden_name
            hidden = HiddenWdg(hidden_name,"")
            prev.add(hidden)
            prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\
                    %(hidden_name, my.refresh_script))
            next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" )
            hidden_name = my.next_hidden_name
            hidden = HiddenWdg(hidden_name,"")
            next.add(hidden)
            next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \
                    %(hidden_name, my.refresh_script))


        showing_wdg = DivWdg()
        widget.add(showing_wdg)
        showing_wdg.add_style("padding: 10px")
        showing_wdg.add_style("margin: 10px")
        showing_wdg.add_color("background", "background", -5)
        showing_wdg.add_border()

        label_span = SpanWdg("Showing: ")
        showing_wdg.add(label_span)
        showing_wdg.add( prev )
       

        # this min calculation is used so that if my.sobjects is not set
        # above for the calculation of the limit, which will make the last 
        # set of range numbers too big
        
        left_bound = my.current_offset+1
        if not limit:
            # prevent error in ItemsNavigatorWdg if a search encounters query error
            limit = 50
            my.search_limit = limit

        right_bound = min(my.current_offset+limit, my.count)
        if left_bound > right_bound:
            left_bound = 1
        current_value = "%d - %d" % (left_bound, right_bound)

        if my.style == my.SIMPLE:
            showing_wdg.add( current_value )
        else:
            # add a range selector using ItemsNavigatorWdg
            from pyasm.widget import ItemsNavigatorWdg
            selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit)
            selector.select.add_behavior( {
                'type': 'change',
                'cbjs_action': my.refresh_script
            } )

            selector.set_style(my.style)

            selector.set_value(current_value)
            selector.set_display_label(False)

            showing_wdg.add( selector) 

        showing_wdg.add( next )

        #showing_wdg.add( " x ")
        showing_wdg.add(my.text)
        my.text.add_style("margin-top: -3px")
        my.text.set_attr("size", "1")
        my.text.add_attr("title", "Set number of items per page")

        widget.add("<hr/>")


        # set the limit
        set_limit_wdg = my.get_set_limit_wdg()
        widget.add(set_limit_wdg)


        from tactic.ui.widget.button_new_wdg import ActionButtonWdg
        button = ActionButtonWdg(title='Search')
        widget.add(button)
        button.add_style("float: right")
        button.add_style("margin-top: 8px")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_search_limit_top");
            var select = top.getElement(".spt_search_limit_select");
            var value = select.value;
            if (value == 'Custom') {
                custom = top.getElement(".spt_search_limit_custom_text");
                value = custom.value;
            }
            if (value == '') {
                value = 20;
            }
            var text = top.getElement(".spt_search_limit_text");
            text.value = value;

            spt.dg_table.search_cbk({}, bvr) 
            '''
        } )


        offset_wdg = HiddenWdg("%s_last_search_offset" %my.label)
        offset_wdg.set_value(my.current_offset)
        widget.add(offset_wdg)

        widget.add("<br clear='all'/>")
 
        return widget
Ejemplo n.º 2
0
    def get_buttons_wdg(my):

        button_div = DivWdg()

        button = ActionButtonWdg(title='Run')
        button_div.add(button)
        button.add_style("float: left")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_script_editor_top");
            var code = top.getElement(".spt_code").value;
            var folder = top.getElement(".spt_folder").value;
            var title = top.getElement(".spt_title").value;
            var language = top.getElement(".spt_language").value;

            spt.ace_editor.set_editor_top(top);
            var editor = spt.ace_editor.editor;
            var value = editor.getSession().toString();

            try {
                if (language == 'javascript') {
                    eval(value);
                } 
                else if (language == 'expression') {
                    var server = TacticServerStub.get();
                    var ret_val;
                   
                        ret_val = server.eval(value);

                    if (ret_val && ret_val.length) {
                        for (var i = 0; i < ret_val.length; i++) {
                            log.critical(ret_val[i]);
                        }
                    }
                    else {
                        log.critical(ret_val);
                    }
                } 
                else if (language == 'python') {
                    var path = folder + "/" + title;
                    var server = TacticServerStub.get();
                    var info = server.execute_python_script(path);
                    log.critical(info);
                }
                else {
                    var ok = function() { eval(value);}
                    spt.confirm("Please set the language of this script. It's assumed to be javascript if left blank. Continue to run?", ok, null);
                   
                } 
            } catch(e) {
                spt.error(spt.exception.handler(e));
            }

            '''
        })

        button = ActionButtonWdg(title='Save')
        button_div.add(button)
        button.add_style("float: left")
        button.add_behavior({
            'type':
            'click_up',
            'editor_id':
            my.unique_id,
            'cbjs_action':
            '''
            /*
            if (!has_changes(bvr)) {
                spt.alert("No changes have been made");
                return;
            }
            */

            var top = bvr.src_el.getParent(".spt_script_editor_top");

            spt.app_busy.show("Saving Script ...");
            setTimeout(function() {
                spt.ace_editor.set_editor_top(top);
                spt.script_editor.save_script_cbk(evt, bvr);
                spt.app_busy.hide();
            }, 10);

            '''
        })

        button = ActionButtonWdg(title='Clear')
        button_div.add(button)
        button.add_style("float: left")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') );

            var top = bvr.src_el.getParent(".spt_script_editor_top");
            spt.ace_editor.set_editor_top(top);
            var editor = spt.ace_editor.editor;
            var document = editor.getSession().getDocument()
            document.setValue("");
            '''
        })

        button = ActionButtonWdg(title='Resize')
        #button_div.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            $(editor_id).setStyle("width", "1000px");
            $(editor_id).setStyle("height", "800px");
            editor.resize();

            '''
        })

        return button_div
Ejemplo n.º 3
0
    def get_display(my):

        web = WebContainer.get_web()

        widget = DivWdg()
        widget.add_class("spt_search_limit_top")
        #widget.add_style("border", "solid 1px blue")
        widget.add_color("background", "background")
        widget.add_color("color", "color")
        widget.add_style("padding: 5px")

        hidden = HiddenWdg("prefix", my.prefix)
        widget.add(hidden)

        if not my.search and not my.sobjects:
            widget.add("No search or sobjects found")
            return widget

        # my.count should have been set in alter_search()
        # which can be called explicitly thru this instance, my.
        if not my.count:
            my.count = my.search.get_count(no_exception=True)

        # if my.sobjects exist thru inheriting from parent widgets
        # or explicitly set, (this is not mandatory though)
        if my.sobjects and len(my.sobjects) < my.search_limit:
            limit = len(my.sobjects)
        elif my.search and my.count < my.search_limit:
            # this is only true if the total result of the search is
            # less than the limit and so this wdg will not display
            limit = my.count
        else:
            limit = my.search_limit

        if not limit:
            limit = 50
            my.search_limit = limit

        if my.refresh:
            prev = SpanWdg(IconButtonWdg("Prev", IconWdg.LEFT, False))
            prev.add_style("margin-left: 8px")
            prev.add_style("margin-right: 6px")
            prev.add_style("margin-top: -2px")
            next = IconButtonWdg("Next",
                                 IconWdg.RIGHT,
                                 False,
                                 icon_pos="right")
            next.add_style("margin-left: 6px")

            prev.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.refresh_script
            })
            next.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.refresh_script
            })
        else:  # the old code pre 2.5
            prev = IconButtonWdg("Prev", IconWdg.LEFT, False)
            hidden_name = my.prev_hidden_name
            hidden = HiddenWdg(hidden_name, "")
            prev.add(hidden)
            prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\
                    %(hidden_name, my.refresh_script))
            next = IconButtonWdg("Next",
                                 IconWdg.RIGHT,
                                 False,
                                 icon_pos="right")
            hidden_name = my.next_hidden_name
            hidden = HiddenWdg(hidden_name, "")
            next.add(hidden)
            next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \
                    %(hidden_name, my.refresh_script))

        showing_wdg = DivWdg()
        widget.add(showing_wdg)
        showing_wdg.add_style("padding: 10px")
        showing_wdg.add_style("margin: 10px")
        showing_wdg.add_color("background", "background", -5)
        showing_wdg.add_border()

        label_span = SpanWdg("Showing: ")
        showing_wdg.add(label_span)
        showing_wdg.add(prev)

        # this min calculation is used so that if my.sobjects is not set
        # above for the calculation of the limit, which will make the last
        # set of range numbers too big

        left_bound = my.current_offset + 1
        if not limit:
            # prevent error in ItemsNavigatorWdg if a search encounters query error
            limit = 50
            my.search_limit = limit

        right_bound = min(my.current_offset + limit, my.count)
        if left_bound > right_bound:
            left_bound = 1
        current_value = "%d - %d" % (left_bound, right_bound)

        if my.style == my.SIMPLE:
            showing_wdg.add(current_value)
        else:
            # add a range selector using ItemsNavigatorWdg
            from pyasm.widget import ItemsNavigatorWdg
            selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit)
            selector.select.add_behavior({
                'type': 'change',
                'cbjs_action': my.refresh_script
            })

            selector.set_style(my.style)

            selector.set_value(current_value)
            selector.set_display_label(False)

            showing_wdg.add(selector)

        showing_wdg.add(next)

        #showing_wdg.add( " x ")
        showing_wdg.add(my.text)
        my.text.add_style("margin-top: -3px")
        my.text.set_attr("size", "1")
        my.text.add_attr("title", "Set number of items per page")

        widget.add("<hr/>")

        # set the limit
        set_limit_wdg = my.get_set_limit_wdg()
        widget.add(set_limit_wdg)

        from tactic.ui.widget.button_new_wdg import ActionButtonWdg
        button = ActionButtonWdg(title='Search')
        widget.add(button)
        button.add_style("float: right")
        button.add_style("margin-top: 8px")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_search_limit_top");
            var select = top.getElement(".spt_search_limit_select");
            var value = select.value;
            if (value == 'Custom') {
                custom = top.getElement(".spt_search_limit_custom_text");
                value = custom.value;
            }
            if (value == '') {
                value = 20;
            }
            var text = top.getElement(".spt_search_limit_text");
            text.value = value;

            spt.dg_table.search_cbk({}, bvr) 
            '''
        })

        offset_wdg = HiddenWdg("%s_last_search_offset" % my.label)
        offset_wdg.set_value(my.current_offset)
        widget.add(offset_wdg)

        widget.add("<br clear='all'/>")

        return widget
Ejemplo n.º 4
0
    def get_buttons_wdg(my):

        button_div = DivWdg()

        button = ActionButtonWdg(title='Run')
        button_div.add(button)
        button.add_style("float: left")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_script_editor_top");
            var code = top.getElement(".spt_code").value;
            var folder = top.getElement(".spt_folder").value;
            var title = top.getElement(".spt_title").value;
            var language = top.getElement(".spt_language").value;

            spt.ace_editor.set_editor_top(top);
            var editor = spt.ace_editor.editor;
            var value = editor.getSession().toString();

            try {
                if (language == 'javascript') {
                    eval(value);
                } 
                else if (language == 'expression') {
                    var server = TacticServerStub.get();
                    var ret_val;
                   
                        ret_val = server.eval(value);

                    if (ret_val && ret_val.length) {
                        for (var i = 0; i < ret_val.length; i++) {
                            log.critical(ret_val[i]);
                        }
                    }
                    else {
                        log.critical(ret_val);
                    }
                } 
                else if (language == 'python') {
                    var path = folder + "/" + title;
                    var server = TacticServerStub.get();
                    var info = server.execute_python_script(path);
                    log.critical(info);
                }
                else {
                    var ok = function() { eval(value);}
                    spt.confirm("Please set the language of this script. It's assumed to be javascript if left blank. Continue to run?", ok, null);
                   
                } 
            } catch(e) {
                spt.error(spt.exception.handler(e));
            }

            '''
        } )

        button = ActionButtonWdg(title='Save')
        button_div.add(button)
        button.add_style("float: left")
        button.add_behavior( {
            'type': 'click_up',
            'editor_id': my.unique_id,
            'cbjs_action': '''
            /*
            if (!has_changes(bvr)) {
                spt.alert("No changes have been made");
                return;
            }
            */

            var top = bvr.src_el.getParent(".spt_script_editor_top");

            spt.app_busy.show("Saving Script ...");
            setTimeout(function() {
                spt.ace_editor.set_editor_top(top);
                spt.script_editor.save_script_cbk(evt, bvr);
                spt.app_busy.hide();
            }, 10);

            '''
        } )
       
 
        button = ActionButtonWdg(title='Clear')
        button_div.add(button)
        button.add_style("float: left")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') );

            var top = bvr.src_el.getParent(".spt_script_editor_top");
            spt.ace_editor.set_editor_top(top);
            var editor = spt.ace_editor.editor;
            var document = editor.getSession().getDocument()
            document.setValue("");
            '''
        } )
       

        button = ActionButtonWdg(title='Resize')
        #button_div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            $(editor_id).setStyle("width", "1000px");
            $(editor_id).setStyle("height", "800px");
            editor.resize();

            '''
        } )
       
        return button_div