Example #1
0
    def get_display(my):

        div = DivWdg()

        if not Container.get_dict("JSLibraries", "spt_popup"):
            div.add_style("position: fixed")
            div.add_style("top: 0px")
            div.add_style("left: 0px")
            div.add_style("opacity: 0.4")
            div.add_style("background", "#000")
            div.add_style("padding: 100px")
            div.add_style("height: 100%")
            div.add_style("width: 100%")
            div.add_class("spt_popup_background")
            div.add_style("display: none")
            div.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.hide(bvr.src_el);
                '''
            })

        Container.put("PopupWdg:background", True)

        # This is the absolute outside of a popup, including the drop shadow
        widget = DivWdg()
        div.add(widget)
        widget.add_class("spt_popup")

        if not Container.get_dict("JSLibraries", "spt_popup"):
            widget.add_behavior({
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            })

        width = my.kwargs.get("width")
        if not width:
            width = 10

        #widget.add_behavior( {
        #    'type': 'load',
        #    'cbjs_action': 'bvr.src_el.makeResizable({handle:bvr.src_el.getElement(".spt_popup_resize")})'
        #} )

        web = WebContainer.get_web()

        widget.set_id(my.name)
        if my.kwargs.get("display") == "true":
            pass
        else:
            widget.add_style("display: none")

        widget.add_style("position: absolute")
        widget.add_style("left: 400px")
        widget.add_style("top: 100px")

        widget.add_border()
        widget.add_color("background", "background")

        #widget.set_box_shadow(color="#000")
        widget.set_box_shadow()

        table = Table()
        table.add_behavior({
            'type':
            'load',
            'width':
            width,
            'cbjs_action':
            '''
        bvr.src_el.setStyle("width", bvr.width)

        var popup = bvr.src_el.getParent(".spt_popup");
        var window_size = $(window).getSize();
        var size = bvr.src_el.getSize();
        var left = window_size.x/2 - size.x/2;
        var top = window_size.y/2 - size.y/2;
        popup.setStyle("left", left);
        //popup.setStyle("top", top);

        '''
        })

        table.add_row()
        """
        # Qt doesn't support shadows very well
        if web.get_browser() == 'Qtx':
            # dynamically add css files

            table.add_class("css_shadow_table")
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_right SPT_POPUP_SHADOW")


            # Middle (Content) Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_left SPT_POPUP_SHADOW")
        """

        content_td = table.add_cell()
        content_td.add_class("css_shadow_td")
        """
        if web.get_browser() == 'Qtx':
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_right SPT_POPUP_SHADOW")


            # Bottom Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_right SPT_POPUP_SHADOW")
        """

        drag_div = DivWdg()

        #from tactic.ui.container import ArrowWdg
        #arrow = ArrowWdg()
        #drag_div.add(arrow)

        # FIXME: for some reason, this causes popups to stop functioning after
        # close a couple of times
        my.add_header_context_menu(drag_div)

        # create the 'close' button ...
        if my.allow_close:
            close_wdg = SpanWdg()
            #close_wdg.add( IconWdg("Close", IconWdg.POPUP_WIN_CLOSE) )
            close_wdg.add(IconWdg("Close", "BS_REMOVE"))
            close_wdg.add_style("margin: 5px 1px 3px 1px")
            close_wdg.add_style("float: right")
            close_wdg.add_class("hand")

            close_wdg.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.get_cancel_script()
            })

            drag_div.add(close_wdg)

            # create the 'minimize' button ...
            minimize_wdg = SpanWdg()
            minimize_wdg.add_style("margin: 5px 1px 3px 1px")
            #minimize_wdg.add( IconWdg("Minimize", IconWdg.POPUP_WIN_MINIMIZE) )
            minimize_wdg.add(IconWdg("Minimize", "BS_MINUS"))
            minimize_wdg.add_style("float: right")
            minimize_wdg.add_class("hand")
            behavior = {
                'type': 'click_up',
                'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
            }
            minimize_wdg.add_behavior(behavior)
            drag_div.add(minimize_wdg)

        #-- TO ADD SOON -- create the 'refresh' button ...
        #   refresh_wdg = SpanWdg()
        #   refresh_wdg.add( IconWdg("Refresh Popup", IconWdg.POPUP_WIN_REFRESH) )
        #   refresh_wdg.add_style("float: right")
        #   refresh_wdg.add_class("hand")
        #   behavior = {
        #       'type': 'click_up',
        #       'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
        #   }
        #   refresh_wdg.add_behavior( behavior );
        #   drag_div.add(refresh_wdg)

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

        # style
        drag_div.add_style("font-size: 1.1em")

        drag_div.add_style("text-align: left")
        drag_div.add_class("spt_popup_width")

        drag_handle_div = DivWdg(id='%s_title' % my.name)
        drag_handle_div.add_style("padding: 12px;")
        #drag_handle_div.add_gradient("background", "background", +10)
        drag_handle_div.add_color("background", "background", -5)
        drag_handle_div.add_color("color", "color")
        drag_handle_div.add_style("font-weight", "bold")
        drag_handle_div.add_style("font-size", "12px")

        # add the drag capability.
        # NOTE: need to use getParent because spt.popup has not yet been
        # initialized when this is processed
        shadow_color = drag_div.get_color("shadow")
        drag_div.add_behavior({
            'type': 'smart_drag',
            'shadow_color': shadow_color,
            'drag_el': "@.getParent('.spt_popup')",
            'bvr_match_class': 'spt_popup_title',
            'options': {
                'z_sort': 'bring_forward'
            },
            'ignore_default_motion': 'true',
            "cbjs_setup": '''
              if (spt.popup.is_background_visible) {
                  spt.popup.offset_x = document.body.scrollLeft;
                  spt.popup.offset_y = document.body.scrollTop;
                  spt.popup.hide_background();
                  var parent = bvr.src_el.getParent(".spt_popup");
                  parent.setStyle("box-shadow","0px 0px 20px " + bvr.shadow_color);
              }
              else {
                  spt.popup.offset_x = 0;
                  spt.popup.offset_y = 0;
              }
            ''',
            "cbjs_motion": '''
              mouse_411.curr_x += spt.popup.offset_x;
              mouse_411.curr_y += spt.popup.offset_y;
              spt.mouse.default_drag_motion(evt, bvr, mouse_411);
            ''',
            "cbjs_action": ''
        })

        title_wdg = my.title_wdg
        if not title_wdg:
            title_wdg = "No Title"
        #else:
        #    title_wdg = title_wdg

        drag_handle_div.add_behavior({
            'type': 'double_click',
            'cbjs_action': my.get_cancel_script()
        })

        drag_handle_div.add(title_wdg)
        drag_handle_div.add_class("spt_popup_title")

        # add a context menu
        from tactic.ui.container.smart_menu_wdg import SmartMenu
        SmartMenu.assign_as_local_activator(drag_handle_div, 'HEADER_CTX')
        drag_handle_div.add_attr("spt_element_name", "Test Dock")

        # add the content
        content_div = DivWdg()
        content_div.add_color("color", "color2")
        #content_div.add_color("background", "background2")
        from pyasm.web.palette import Palette
        palette = Palette.get()
        content_div.add_color("color", "color2")
        content_div.add_color("background", "background2")

        content_div.add_style("margin", "0px, -1px -0px -1px")

        content_div.set_id("%s_content" % my.name)
        content_div.add_class("spt_popup_content")
        content_div.add_style("overflow: hidden")
        content_div.add_style("display: block")
        #content_div.add_style("padding: 10px")
        if not my.content_wdg:
            my.content_wdg = "No Content"

        content_div.add(my.content_wdg)

        drag_div.add(drag_handle_div)
        my.position_aux_div(drag_div, content_div)
        content_td.add(drag_div)
        widget.add(table)

        # ALWAYS make the Popup a Page Utility Widget (now processed client side)
        widget.add_class("SPT_PUW")

        if my.z_start:
            widget.set_z_start(my.z_start)
            widget.add_style("z-index: %s" % my.z_start)
        else:
            widget.add_style("z-index: 102")

        # add the resize icon
        icon = IconWdg("Resize", IconWdg.RESIZE_CORNER)
        icon.add_style("cursor: nw-resize")
        icon.add_style("z-index: 1000")
        icon.add_class("spt_popup_resize")
        icon.add_style("float: right")
        icon.add_style("margin-top: -15px")
        icon.add_behavior({
            'type': 'drag',
            "drag_el": '@',
            "cb_set_prefix": 'spt.popup.resize_drag'
        })
        content_td.add(icon)

        #return widget
        return div
Example #2
0
    def get_script_wdg(my):

        search = Search("config/custom_script")
        #search.add_user_filter()
        search.add_order_by("folder")
        search.add_order_by("title")
        scripts = search.get_sobjects()

        widget = DivWdg()
        widget.add_style("width: 100%")

        from pyasm.web.palette import Palette
        palette = Palette.get()
        bg_color = palette.color("background3")
        hover_color = palette.color("background3", 20)
        widget.add_color("background", bg_color)

        '''
        # Try the table layout widget
        from tactic.ui.panel import TableLayoutWdg
        table = TableLayoutWdg(id='js_edit_list',search_type="config/custom_script", view='simple')
        table.set_sobjects(scripts)
        widget.add(table)
        '''

        title = DivWdg()
        title.add("Saved Scripts")
        title.add_style("font-size: 14px")
        title.add_color("color", "color")
        title.add_style("padding: 8px 3px")
        title.add_style("margin: 0 0 0 -1")
        title.add_color("background", "background", -5)
        title.add_border()
        widget.add(title)


        script_div = DivWdg()
        script_div.add_border()
        script_div.add_color("background", "background3")
        script_div.add_color("color", "color3")
        script_div.add_style("padding: 8px")
        script_div.add_style("overflow-x: hidden")
        script_div.add_style("overflow-y: auto")
        script_div.add_style("height: 100%")
        script_div.add_style("min-width: 100px")
        script_div.add_style("width: 220px")
        script_div.add_style("margin: -1px 0px 0px -1px")
        script_div.add_class("spt_resizable")

        inner = DivWdg()
        script_div.add(inner)
        inner.add_style("height: 100%")
        inner.add_style("width: 800px")

        last_folder = ''
        for script in scripts:
            title = script.get_value("title")
            folder = script.get_value("folder")
            language = script.get_value("language", no_exception=True)
            if not language:
                language = 'javascript'

            if folder != last_folder:
                div = DivWdg()
                icon = IconWdg("Script", IconWdg.FOLDER)
                div.add(icon)
                div.add(" %s" % folder)
                inner.add(div)


            last_folder = folder

            div = DivWdg()
            inner.add(div)
            div.add_class('hand')
            icon = IconWdg("Script", IconWdg.TOGGLE_ON)
            icon.add_style("margin-left: 10px")
            div.add(icon)
            div.add("%s" %title)

            span = SpanWdg()
            span.add_style("font-size: 9px")
            span.add_style("opacity: 0.2")
            span.add(" <i>(%s)</i>" % language)
            div.add(span)

            div.add_event("onmou8eover", "this.style.background='%s'" % hover_color)
            div.add_event("onmouseout", "this.style.background='%s'" % bg_color)


            behavior = {
                'type': 'click_up',
                'editor_id': my.editor_id, 
                'cbjs_action': 'spt.script_editor.display_script_cbk(evt, bvr)',
                'code': script.get_code()
            }
            div.add_behavior(behavior)



        widget.add(script_div)

        return widget
Example #3
0
    def get_display(my):

        div = DivWdg()

        if not Container.get_dict("JSLibraries", "spt_popup"):
            div.add_style("position: fixed")
            div.add_style("top: 0px")
            div.add_style("left: 0px")
            div.add_style("opacity: 0.4")
            div.add_style("background", "#000")
            div.add_style("padding: 100px")
            div.add_style("height: 100%")
            div.add_style("width: 100%")
            div.add_class("spt_popup_background")
            div.add_style("display: none")
            div.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                spt.hide(bvr.src_el);
                '''
            } ) 

        Container.put("PopupWdg:background", True)



        # This is the absolute outside of a popup, including the drop shadow
        widget = DivWdg()
        div.add(widget)
        widget.add_class("spt_popup")



        if not Container.get_dict("JSLibraries", "spt_popup"):
            widget.add_behavior( {
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            } )


        width = my.kwargs.get("width")
        if not width:
            width = 10

        #widget.add_behavior( {
        #    'type': 'load',
        #    'cbjs_action': 'bvr.src_el.makeResizable({handle:bvr.src_el.getElement(".spt_popup_resize")})'
        #} )


        web = WebContainer.get_web()


        widget.set_id(my.name)
        if my.kwargs.get("display") == "true":
            pass
        else:
            widget.add_style("display: none")

        widget.add_style("position: absolute")
        widget.add_style("left: 400px")
        widget.add_style("top: 100px")

        widget.add_border()
        widget.add_color("background", "background")

        #widget.set_box_shadow(color="#000")
        widget.set_box_shadow()


        table = Table()
        table.add_behavior( {
        'type': 'load',
        'width': width,
        'cbjs_action': '''
        bvr.src_el.setStyle("width", bvr.width)

        var popup = bvr.src_el.getParent(".spt_popup");
        var window_size = $(window).getSize();
        var size = bvr.src_el.getSize();
        var left = window_size.x/2 - size.x/2;
        var top = window_size.y/2 - size.y/2;
        popup.setStyle("left", left);
        //popup.setStyle("top", top);

        '''
        } )



        table.add_row()

        """
        # Qt doesn't support shadows very well
        if web.get_browser() == 'Qtx':
            # dynamically add css files

            table.add_class("css_shadow_table")
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_top_right SPT_POPUP_SHADOW")


            # Middle (Content) Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_left SPT_POPUP_SHADOW")
        """

        content_td = table.add_cell()
        content_td.add_class("css_shadow_td")

        """
        if web.get_browser() == 'Qtx':
            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_right SPT_POPUP_SHADOW")


            # Bottom Row of Shadow table ...
            table.add_row()

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_left SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom SPT_POPUP_SHADOW")

            td = table.add_cell()
            td.add_class("css_shadow_td css_shadow_bottom_right SPT_POPUP_SHADOW")
        """


        drag_div = DivWdg()

        #from tactic.ui.container import ArrowWdg
        #arrow = ArrowWdg()
        #drag_div.add(arrow)


        # FIXME: for some reason, this causes popups to stop functioning after
        # close a couple of times
        my.add_header_context_menu(drag_div)


        # create the 'close' button ...
        if my.allow_close:
            close_wdg = SpanWdg(css='spt_popup_close')
            #close_wdg.add( IconWdg("Close", IconWdg.POPUP_WIN_CLOSE) )
            close_wdg.add( IconWdg("Close", "BS_REMOVE") )
            close_wdg.add_style("margin: 5px 1px 3px 1px")
            close_wdg.add_style("float: right")
            close_wdg.add_class("hand")

            close_wdg.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.get_cancel_script()
            })

            drag_div.add(close_wdg)


            # create the 'minimize' button ...
            minimize_wdg = SpanWdg(css='spt_popup_min')
            minimize_wdg.add_style("margin: 5px 1px 3px 1px")
            #minimize_wdg.add( IconWdg("Minimize", IconWdg.POPUP_WIN_MINIMIZE) )
            minimize_wdg.add( IconWdg("Minimize", "BS_MINUS") )
            minimize_wdg.add_style("float: right")
            minimize_wdg.add_class("hand")
            behavior = {
                'type': 'click_up',
                'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
            }
            minimize_wdg.add_behavior( behavior );
            drag_div.add(minimize_wdg)

        #-- TO ADD SOON -- create the 'refresh' button ...
        #   refresh_wdg = SpanWdg()
        #   refresh_wdg.add( IconWdg("Refresh Popup", IconWdg.POPUP_WIN_REFRESH) )
        #   refresh_wdg.add_style("float: right")
        #   refresh_wdg.add_class("hand")
        #   behavior = {
        #       'type': 'click_up',
        #       'cbjs_action': "spt.popup.toggle_minimize( bvr.src_el );"
        #   }
        #   refresh_wdg.add_behavior( behavior );
        #   drag_div.add(refresh_wdg)

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

        # style
        drag_div.add_style("font-size: 1.1em")

        drag_div.add_style("text-align: left")
        drag_div.add_class("spt_popup_width")

        drag_handle_div = DivWdg(id='%s_title' %my.name)
        drag_handle_div.add_style("padding: 12px;")
        #drag_handle_div.add_gradient("background", "background", +10)
        drag_handle_div.add_color("background", "background", -5)
        drag_handle_div.add_color("color", "color")
        drag_handle_div.add_style("font-weight", "bold")
        drag_handle_div.add_style("font-size", "12px")


        # add the drag capability.
        # NOTE: need to use getParent because spt.popup has not yet been
        # initialized when this is processed
        shadow_color = drag_div.get_color("shadow")
        drag_div.add_behavior( {
            'type':'smart_drag',
            'shadow_color': shadow_color,
            'drag_el': "@.getParent('.spt_popup')",
            'bvr_match_class': 'spt_popup_title',
            'options': {'z_sort': 'bring_forward'},
            'ignore_default_motion': 'true',
            "cbjs_setup": '''
              if (spt.popup.is_background_visible) {
                  spt.popup.offset_x = document.body.scrollLeft;
                  spt.popup.offset_y = document.body.scrollTop;
                  spt.popup.hide_background();
                  var parent = bvr.src_el.getParent(".spt_popup");
                  parent.setStyle("box-shadow","0px 0px 20px " + bvr.shadow_color);
              }
              else {
                  spt.popup.offset_x = 0;
                  spt.popup.offset_y = 0;
              }
            ''',
            "cbjs_motion": '''
              mouse_411.curr_x += spt.popup.offset_x;
              mouse_411.curr_y += spt.popup.offset_y;
              spt.mouse.default_drag_motion(evt, bvr, mouse_411);
            ''',
            "cbjs_action": ''
        } )


        
        title_wdg = my.title_wdg
        if not title_wdg:
            title_wdg = "No Title"
        #else:
        #    title_wdg = title_wdg

        drag_handle_div.add_behavior({
            'type': 'double_click',
            'cbjs_action': my.get_cancel_script()
        })


        drag_handle_div.add(title_wdg)
        drag_handle_div.add_class("spt_popup_title")


        # add a context menu
        from tactic.ui.container.smart_menu_wdg import SmartMenu
        SmartMenu.assign_as_local_activator( drag_handle_div, 'HEADER_CTX' )
        drag_handle_div.add_attr("spt_element_name", "Test Dock")



        # add the content
        content_div = DivWdg()
        content_div.add_color("color", "color2")
        #content_div.add_color("background", "background2")
        from pyasm.web.palette import Palette
        palette = Palette.get()
        content_div.add_color("color", "color2")
        content_div.add_color("background", "background2")

        content_div.add_style("margin", "0px, -1px -0px -1px")

        content_div.set_id("%s_content" % my.name)
        content_div.add_class("spt_popup_content")
        content_div.add_style("overflow: hidden")
        content_div.add_style("display: block")
        #content_div.add_style("padding: 10px")
        if not my.content_wdg:
            my.content_wdg = "No Content"

        content_div.add(my.content_wdg)

        drag_div.add( drag_handle_div )
        my.position_aux_div(drag_div, content_div)
        content_td.add(drag_div)
        widget.add(table)

        # ALWAYS make the Popup a Page Utility Widget (now processed client side)
        widget.add_class( "SPT_PUW" )

        if my.z_start:
            widget.set_z_start( my.z_start )
            widget.add_style("z-index: %s" % my.z_start)
        else:
            widget.add_style("z-index: 102")


        # add the resize icon
        icon = IconWdg( "Resize", IconWdg.RESIZE_CORNER )
        icon.add_style("cursor: nw-resize")
        icon.add_style("z-index: 1000")
        icon.add_class("spt_popup_resize")
        icon.add_style("float: right")
        icon.add_style("margin-top: -15px")
        icon.add_behavior( {
        'type': 'drag',
        "drag_el": '@',
        "cb_set_prefix": 'spt.popup.resize_drag'
        } )
        content_td.add(icon)

        #return widget
        return div
Example #4
0
    def get_script_wdg(my):

        search = Search("config/custom_script")
        #search.add_user_filter()
        search.add_order_by("folder")
        search.add_order_by("title")
        scripts = search.get_sobjects()

        widget = DivWdg()
        widget.add_style("width: 100%")

        from pyasm.web.palette import Palette
        palette = Palette.get()
        bg_color = palette.color("background3")
        hover_color = palette.color("background3", 20)
        widget.add_color("background", bg_color)


        title = DivWdg()
        title.add("Saved Scripts")
        title.add_style("font-size: 14px")
        title.add_color("color", "color")
        title.add_style("padding: 8px 3px")
        title.add_style("margin: 0 0 0 -1")
        title.add_color("background", "background", -5)
        title.add_border()
        widget.add(title)


        script_div = DivWdg()
        script_div.add_border()
        script_div.add_color("background", "background3")
        script_div.add_color("color", "color3")
        script_div.add_style("padding: 8px")
        script_div.add_style("overflow-x: hidden")
        script_div.add_style("overflow-y: auto")
        script_div.add_style("height: 100%")
        script_div.add_style("min-width: 100px")
        script_div.add_style("width: 220px")
        script_div.add_style("margin: -1px 0px 0px -1px")
        script_div.add_class("spt_resizable")

        inner = DivWdg()
        script_div.add(inner)
        inner.add_style("height: 100%")
        inner.add_style("width: 800px")


        paths = []
        scripts_dict = {}
        for script in scripts:
            path = "///%s/%s" % (script.get_value("folder"), script.get_value("title"))
            paths.append(path)
            scripts_dict[path] = script
        dir_list_wdg = ScriptDirListWdg(paths=paths, base_dir="/", editor_id=my.editor_id, scripts=scripts_dict)
        inner.add(dir_list_wdg)


        """
        last_folder = ''
        for script in scripts:
            title = script.get_value("title")
            folder = script.get_value("folder")
            language = script.get_value("language", no_exception=True)
            if not language:
                language = 'javascript'

            if folder != last_folder:
                div = DivWdg()
                icon = IconWdg("Script", IconWdg.FOLDER)
                div.add(icon)
                div.add(" %s" % folder)
                inner.add(div)


            last_folder = folder

            div = DivWdg()
            inner.add(div)
            div.add_class('hand')
            icon = IconWdg("Script", IconWdg.TOGGLE_ON)
            icon.add_style("margin-left: 10px")
            div.add(icon)
            div.add("%s" %title)

            span = SpanWdg()
            span.add_style("font-size: 9px")
            span.add_style("opacity: 0.2")
            span.add(" <i>(%s)</i>" % language)
            div.add(span)

            div.add_event("onmouseover", "this.style.background='%s'" % hover_color)
            div.add_event("onmouseout", "this.style.background='%s'" % bg_color)


            behavior = {
                'type': 'click_up',
                'editor_id': my.editor_id, 
                'cbjs_action': 'spt.script_editor.display_script_cbk(evt, bvr)',
                'code': script.get_code()
            }
            div.add_behavior(behavior)
        """


        widget.add(script_div)

        return widget
Example #5
0
    def get_script_wdg(my):

        search = Search("config/custom_script")
        #search.add_user_filter()
        search.add_order_by("folder")
        search.add_order_by("title")
        scripts = search.get_sobjects()

        widget = DivWdg()
        widget.add_style("width: 100%")

        from pyasm.web.palette import Palette
        palette = Palette.get()
        bg_color = palette.color("background3")
        hover_color = palette.color("background3", 20)
        widget.add_color("background", bg_color)
        '''
        # Try the table layout widget
        from tactic.ui.panel import TableLayoutWdg
        table = TableLayoutWdg(id='js_edit_list',search_type="config/custom_script", view='simple')
        table.set_sobjects(scripts)
        widget.add(table)
        '''

        title = DivWdg()
        title.add("Saved Scripts")
        title.add_style("font-size: 14px")
        title.add_color("color", "color")
        title.add_style("padding: 3px")
        title.add_style("margin: 0 0 0 -1")
        title.add_gradient("background", "background")
        title.add_border()
        widget.add(title)

        script_div = DivWdg()
        script_div.add_border()
        script_div.add_color("background", "background3")
        script_div.add_color("color", "color3")
        script_div.add_style("padding: 8px")
        script_div.add_style("overflow-x: hidden")
        script_div.add_style("overflow-y: auto")
        script_div.add_style("height: 100%")
        script_div.add_style("min-width: 100px")
        script_div.add_style("width: 220px")
        script_div.add_style("margin: -1px 0px 0px -1px")
        script_div.add_class("spt_resizable")

        inner = DivWdg()
        script_div.add(inner)
        inner.add_style("height: 100%")
        inner.add_style("width: 800px")

        last_folder = ''
        for script in scripts:
            title = script.get_value("title")
            folder = script.get_value("folder")
            language = script.get_value("language", no_exception=True)
            if not language:
                language = 'javascript'

            if folder != last_folder:
                div = DivWdg()
                icon = IconWdg("Script", IconWdg.FOLDER)
                div.add(icon)
                div.add(" %s" % folder)
                inner.add(div)

            last_folder = folder

            div = DivWdg()
            inner.add(div)
            div.add_class('hand')
            icon = IconWdg("Script", IconWdg.TOGGLE_ON)
            icon.add_style("margin-left: 10px")
            div.add(icon)
            div.add("%s" % title)

            span = SpanWdg()
            span.add_style("font-size: 9px")
            span.add_style("opacity: 0.2")
            span.add(" <i>(%s)</i>" % language)
            div.add(span)

            div.add_event("onmouseover",
                          "this.style.background='%s'" % hover_color)
            div.add_event("onmouseout",
                          "this.style.background='%s'" % bg_color)

            behavior = {
                'type': 'click_up',
                'editor_id': my.editor_id,
                'cbjs_action':
                'spt.script_editor.display_script_cbk(evt, bvr)',
                'code': script.get_code()
            }
            div.add_behavior(behavior)

        widget.add(script_div)

        return widget