コード例 #1
0
    def get_display(my):

        widget = my.widget
        widget.set_box_shadow()

        widget.add_class("spt_dialog_top")
        widget.add_class("spt_popup")

        z_index = my.kwargs.get("z_index")
        if not z_index:
            z_index = "500"
        widget.add_style("z-index: %s" % z_index)

        web = WebContainer.get_web()

        widget.set_id(my.name)
        widget.add_attr("spt_dialog_id", my.name)
        if my.kwargs.get("display") not in [True, "true"]:
            widget.add_style("display: none")

        widget.add_style("position: absolute")

        widget.add_behavior({
            'type': 'listen',
            'event_name': '%s|dialog_close' % my.name,
            'cbjs_action': my.get_cancel_script()
        })

        offset = my.kwargs.get("offset")
        if not offset:
            offset = my.offset

        show_header = True
        show_resize = False

        drag_div = DivWdg()
        if show_header:
            widget.add(drag_div)

        show_pointer = my.kwargs.get("show_pointer")
        if show_pointer not in [False, 'false']:
            from tactic.ui.container import ArrowWdg
            offset_x = 15 - offset.get('x')
            offset_y = offset.get("y")
            arrow = ArrowWdg(offset_x=offset_x,
                             offset_y=offset_y,
                             color=widget.get_color("background", -10))
            arrow.add_class("spt_popup_pointer")
            arrow.add_style("z-index: 10")
            widget.add(arrow)

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

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

        drag_div.add(close_wdg)

        anchor_wdg = SpanWdg()
        drag_div.add(anchor_wdg)
        anchor_wdg.add_style("margin: 5px 5px 3px 1px")
        anchor_wdg.add(IconWdg("Anchor Dialog", "BS_PUSHPIN"))
        anchor_wdg.add_style("float: right")
        anchor_wdg.add_class("hand")

        anchor_wdg.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_dialog_top");
            var position = top.getStyle("position");
            if (position == 'fixed') {
                top.setStyle("position", "absolute");
                bvr.src_el.setStyle("opacity", "1.0");
            }
            else {
                top.setStyle("position", "fixed");
                bvr.src_el.setStyle("opacity", "0.5");
            }
            '''
        })

        width = my.kwargs.get("width")
        if not width:
            width = "100px"
        if width:
            drag_div.add_style("min-width: %s" % width)

        # style
        #drag_div.add_looks("popup")

        drag_div.add_style("text-align: left")
        drag_div.add_class("spt_popup_width")
        drag_div.add_style("border-style: solid")
        drag_div.add_color("border-color", "border")
        drag_div.add_style("border-size: 0 0 1 0")

        drag_handle_div = DivWdg(id='%s_title' % my.name)
        drag_div.add(drag_handle_div)
        drag_handle_div.add_style("padding: 3px;")
        #drag_handle_div.add_gradient("background", "background", +10)
        drag_handle_div.add_color("background", "background", -10)
        drag_handle_div.add_color("color", "color")
        drag_handle_div.add_style("padding: 8px 5px 8px 8px")

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

        # add the drag capability
        drag_handle_div.add_behavior({
            'type':
            'smart_drag',
            'drag_el':
            'spt.popup.get_popup(@);',
            'options': {
                'z_sort': 'bring_forward'
            },
            'ignore_default_motion':
            'false',
            'cbjs_setup':
            '''
            var pointer = bvr.drag_el.getElement(".spt_popup_pointer");
            if (pointer) {
                spt.hide(pointer);
            }
        '''
        })

        # add the content
        content_div = DivWdg()

        title_wdg = my.title_wdg
        if not title_wdg:
            title_wdg = "No Title"
            # if the title is empty, just don't show
        if my.kwargs.get("show_title") in [False, 'false']:
            drag_div.add_style("display: none")
        #else:
        #    content_div.add_style("margin-top: -1px")

        drag_handle_div.add(title_wdg)
        drag_handle_div.add_class("spt_popup_title")
        drag_handle_div.add_style("font-weight: bold")

        widget.add(content_div)
        content_div.add_color("color", "color2")
        content_div.add_gradient("background", "background2")

        content_div.set_id("%s_content" % my.name)
        content_div.add_class("spt_popup_content")
        content_div.add_class("spt_dialog_content")
        content_div.add_style("overflow: hidden")
        content_div.add_style("display: block")
        #content_div.add_style("padding: 5px")

        view = my.kwargs.get("view")
        if view:
            from tactic.ui.panel import CustomLayoutWdg
            my.add(CustomLayoutWdg(view=view))

        if not my.content_wdg:
            my.content_wdg = "No Content"

        content_div.add(my.content_wdg)

        # add the resize icon
        if show_resize:
            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: -25px")
            icon.add_style("margin-right: 5px")
            icon.add_behavior({
                'type': 'drag',
                "drag_el": '@',
                "cb_set_prefix": 'spt.popup.resize_drag'
            })
            widget.add(icon)

        return widget
コード例 #2
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
コード例 #3
0
    def get_display(my):

        widget = my.widget
        widget.set_box_shadow()

        widget.add_class("spt_dialog_top")
        widget.add_class("spt_popup")



        z_index = my.kwargs.get("z_index")
        if not z_index:
            z_index = "500"
        widget.add_style("z-index: %s" % z_index)


        web = WebContainer.get_web()

        widget.set_id(my.name)
        widget.add_attr("spt_dialog_id", my.name);
        if my.kwargs.get("display") not in [True, "true"]:
            widget.add_style("display: none")

        widget.add_style("position: absolute")

        widget.add_behavior( {
        'type': 'listen',
        'event_name': '%s|dialog_close' % my.name,
        'cbjs_action': my.get_cancel_script()
        } )


        offset = my.kwargs.get("offset")
        if not offset:
            offset = my.offset





        show_header = True
        show_resize = False


        drag_div = DivWdg()
        if show_header:
            widget.add(drag_div)



        show_pointer = my.kwargs.get("show_pointer")
        if show_pointer not in [False, 'false']:
            from tactic.ui.container import ArrowWdg
            offset_x = 15 - offset.get('x')
            offset_y = offset.get("y")
            arrow = ArrowWdg(
                    offset_x=offset_x,
                    offset_y=offset_y,
                    color=widget.get_color("background", -10)
            )
            arrow.add_class("spt_popup_pointer")
            arrow.add_style("z-index: 10")
            widget.add(arrow)


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

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

        drag_div.add(close_wdg)


        anchor_wdg = SpanWdg()
        drag_div.add(anchor_wdg)
        anchor_wdg.add_style("margin: 5px 5px 3px 1px")
        anchor_wdg.add( IconWdg("Anchor Dialog", "BS_PUSHPIN") )
        anchor_wdg.add_style("float: right")
        anchor_wdg.add_class("hand")

        anchor_wdg.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_dialog_top");
            var position = top.getStyle("position");
            if (position == 'fixed') {
                top.setStyle("position", "absolute");
                bvr.src_el.setStyle("opacity", "1.0");
            }
            else {
                top.setStyle("position", "fixed");
                bvr.src_el.setStyle("opacity", "0.5");
            }
            '''
        })







        width = my.kwargs.get("width")
        if not width:
            width = "100px"
        if width:
            drag_div.add_style("min-width: %s" % width)

        # style
        #drag_div.add_looks("popup")

        drag_div.add_style("text-align: left")
        drag_div.add_class("spt_popup_width")
        drag_div.add_style("border-style: solid")
        drag_div.add_color("border-color", "border")
        drag_div.add_style("border-size: 0 0 1 0")


        drag_handle_div = DivWdg(id='%s_title' %my.name)
        drag_div.add( drag_handle_div )
        drag_handle_div.add_style("padding: 3px;")
        #drag_handle_div.add_gradient("background", "background", +10)
        drag_handle_div.add_color("background", "background", -10)
        drag_handle_div.add_color("color", "color")
        drag_handle_div.add_style("padding: 8px 5px 8px 8px")

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


        # add the drag capability
        drag_handle_div.add_behavior( {
        'type':'smart_drag',
        'drag_el': 'spt.popup.get_popup(@);',
        'options': {'z_sort': 'bring_forward'},
        'ignore_default_motion': 'false',
        'cbjs_setup': '''
            var pointer = bvr.drag_el.getElement(".spt_popup_pointer");
            if (pointer) {
                spt.hide(pointer);
            }
        '''
        } )


        # add the content
        content_div = DivWdg()
        
        title_wdg = my.title_wdg
        if not title_wdg:
            title_wdg = "No Title"
            # if the title is empty, just don't show
        if my.kwargs.get("show_title") in [False, 'false']:
            drag_div.add_style("display: none")
        #else:
        #    content_div.add_style("margin-top: -1px")


        drag_handle_div.add(title_wdg)
        drag_handle_div.add_class("spt_popup_title")
        drag_handle_div.add_style("font-weight: bold")


        widget.add(content_div)
        content_div.add_color("color", "color2")
        content_div.add_gradient( "background", "background2" )

        content_div.set_id("%s_content" % my.name)
        content_div.add_class("spt_popup_content")
        content_div.add_class("spt_dialog_content")
        content_div.add_style("overflow: hidden")
        content_div.add_style("display: block")
        #content_div.add_style("padding: 5px")

        view = my.kwargs.get("view")
        if view:
            from tactic.ui.panel import CustomLayoutWdg
            my.add( CustomLayoutWdg(view=view) )

        if not my.content_wdg:
            my.content_wdg = "No Content"

        content_div.add(my.content_wdg)


        # add the resize icon
        if show_resize:
            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: -25px")
            icon.add_style("margin-right: 5px")
            icon.add_behavior( {
            'type': 'drag',
            "drag_el": '@',
            "cb_set_prefix": 'spt.popup.resize_drag'
            } )
            widget.add(icon)




        return widget
コード例 #4
0
ファイル: shelf_wdg.py プロジェクト: 2gDigitalPost/tactic_src
    def get_display(my):
        web = WebContainer.get_web()

        top = my.top
        top.add_class("spt_ace_editor_top")

        script = my.kwargs.get("custom_script")
        if script:
            language = script.get_value("language")
        else:
            language = my.kwargs.get("language")
            if not language:
                language = 'javascript'

        code = my.kwargs.get("code")
        if not code:
            code = ""


        show_options = my.kwargs.get("show_options")
        if show_options in ['false', False]:
            show_options = False
        else:
            show_options = True

        options_div = DivWdg()
        top.add(options_div)
        if not show_options:
            options_div.add_style("display: none")
        options_div.add_color("background", "background3")
        options_div.add_border()
        options_div.add_style("text-align: center")
        options_div.add_style("padding: 2px")



        select = SelectWdg("language")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.add_class("spt_language")
        select.set_option("values", "javascript|python|expression|xml")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var value = bvr.src_el.value;
            spt.ace_editor.set_language(value);

            //register_change(bvr);

            '''
        } )
 
        select = SelectWdg("font_size")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "8 pt|9 pt|10 pt|11 pt|12 pt|14 pt|16 pt")
        select.set_option("values", "8 pt|9pt|10pt|11pt|12pt|14pt|16pt")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'click_up',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var value = bvr.src_el.value;
            $(editor_id).setStyle("font-size", value)
            //editor.resize();
            '''
        } )



        select = SelectWdg("keybinding")
        select.add_style("width: 100px")
        #options_div.add(select)
        select.set_option("labels", "Ace|Vim|Emacs")
        select.set_option("values", "ace|vim|emacs")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var vim = require("ace/keyboard/keybinding/vim").Vim;
            editor.setKeyboardHandler(vim)
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)


        if code:
            load_div = DivWdg()
            top.add(load_div)
            readonly = my.kwargs.get("readonly")
            if readonly in ['true', True]:
                readonly = True
            else:
                readonly = False

            load_div.add_behavior( {
                'type': 'load',
                'code': code,
                'language': language,
                'editor_id': my.get_editor_id(),
                'readonly': readonly,
                'cbjs_action': '''
                spt.ace_editor.set_editor(bvr.editor_id);
                var func = function() {
                    var editor = spt.ace_editor.editor;
                    var document = editor.getSession().getDocument();
                    if (bvr.code) {
                        spt.ace_editor.set_value(bvr.code);
                    }
                    spt.ace_editor.set_language(bvr.language);
                    editor.setReadOnly(bvr.readonly);


                    var session = editor.getSession();
                    //session.setUseWrapMode(true);
                    //session.setWrapLimitRange(120, 120);
                };

                var editor = spt.ace_editor.editor;
                if (!editor) {
                    setTimeout( func, 1000);
                }
                else {
                    func();
                }

                '''
            } )




        # theme
        select = SelectWdg("theme")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "Eclipse|Twilight|TextMate|Vibrant Ink|Merbivore|Clouds")
        select.set_option("values", "eclipse|twilight|textmate|vibrant_ink|merbivore|clouds")
        select.set_value("twilight")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            value = bvr.src_el.value;

            editor.setTheme("ace/theme/" + value);
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)




        my.text_area.add_style("margin-top: -1px")
        my.text_area.add_style("margin-bottom: 0px")
        my.text_area.add_color("background", "background")
        my.text_area.add_style("font-family: courier new")
        my.text_area.add_border()
        editor_div.add(my.text_area)
        my.text_area.add_style("position: relative")
        #text_area.add_style("margin: 20px")


        size = web.get_form_value("size")
        if size:
            width, height = size.split(",")
        else:
            width = my.kwargs.get("width")
            if not width:
                width = "650px"
            height = my.kwargs.get("height")
            if not height:
                height = "450px"
        my.text_area.add_style("width: %s" % width)
        my.text_area.add_style("height: %s" % height)



        bottom_div = DivWdg()
        top.add(bottom_div)
        bottom_div.add_color("background", "background3")
        bottom_div.add_border()
        bottom_div.add_style("text-align: center")
        bottom_div.add_style("padding: 2px")
        bottom_div.add_style("height: 20px")

        bottom_title = "Script Editor"
        bottom_div.add(bottom_title)

        icon = IconWdg("Resize Editor", IconWdg.RESIZE_CORNER)
        bottom_div.add(icon)
        icon.add_style("float: right")
        icon.add_style("margin-right: -4px")
        icon.add_style("cursor: se-resize")
        icon.add_behavior( {
            'type': 'drag',
            "cb_set_prefix": 'spt.ace_editor.drag_resize',
        } )


        #hidden = HiddenWdg("size")
        hidden = TextWdg("size")
        bottom_div.add(hidden)
        hidden.add_style("width: 85px")
        hidden.add_style("text-align: center")
        hidden.add_style("float: right")
        hidden.add_class("spt_size")
        hidden.set_value("%s,%s" % (width, height))

        theme = top.get_theme()
        if theme == 'dark':
            theme = 'twilight'
        else:
            theme = 'eclipse'

        print "theme: ", theme

        top.add_behavior( {
            'type': 'load',
            'unique_id': my.unique_id,
            'theme': theme,
            'cbjs_action': '''

if (typeof(ace) == 'undefined') {

// fist time loading
spt.ace_editor = {}
spt.ace_editor.editor = null;
spt.ace_editor.editor_id = bvr.unique_id;
spt.ace_editor.theme = bvr.theme;


spt.ace_editor.set_editor = function(editor_id) {
    spt.ace_editor.editor_id = editor_id;
    spt.ace_editor.editor = $(editor_id).editor;
}

spt.ace_editor.set_editor_top = function(top_el) {
    if (!top_el.hasClass("spt_ace_editor")) {
        top_el = top_el.getElement(".spt_ace_editor");
    }

    var editor_id = top_el.getAttribute("id");
    spt.ace_editor.set_editor(editor_id);
}




spt.ace_editor.get_editor = function() {
    return spt.ace_editor.editor;

}



spt.ace_editor.clear_selection = function() {
    var editor = spt.ace_editor.editor;
    editor.clearSelection();

}



spt.ace_editor.get_selection = function() {
    var editor = spt.ace_editor.editor;
    //return editor.getSelection();
    return editor.getCopyText();
}





spt.ace_editor.get_value = function() {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    var value = document.getValue();
    return value;
}



spt.ace_editor.set_value = function(value) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    document.setValue(value);
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
}

spt.ace_editor.goto_line = function(number) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
 

}


spt.ace_editor.insert = function(value) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertInLine(position, value);
}

 
spt.ace_editor.insert_lines = function(values) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertLines(position.row, values);
}



spt.ace_editor.get_document = function() {
    var document = spt.ace_editor.editor.getSession().getDocument()
    return document;

}




spt.ace_editor.set_language = function(value) {
    if (!value) {
        value = 'javascript';
    }

    var editor = spt.ace_editor.editor;
    var top = $(spt.ace_editor.editor_id).getParent(".spt_ace_editor_top");
    var lang_el = top.getElement(".spt_language");

    for ( var i = 0; i < lang_el.options.length; i++ ) {
        if ( lang_el.options[i].value == value ) {
            lang_el.options[i].selected = true;
            break;
        }
    }



    var session = editor.getSession();
    var mode;
    if (value == 'python') {
        mode = require("ace/mode/python").Mode;
    }
    else if (value == 'xml') {
        mode = require("ace/mode/xml").Mode;
    }
    else if (value == 'expression') {
        mode = require("ace/mode/xml").Mode;
    }
    else {
        mode = require("ace/mode/javascript").Mode;
    }
    session.setMode( new mode() );
}

spt.ace_editor.drag_start_x;
spt.ace_editor.drag_start_y;
spt.ace_editor.drag_size;
spt.ace_editor.drag_editor_el;
spt.ace_editor.drag_size_el;
spt.ace_editor.drag_resize_setup = function(evt, bvr, mouse_411)
{
    var editor = spt.ace_editor.editor;
    var editor_id = spt.ace_editor.editor_id;

    spt.ace_editor.drag_start_x = mouse_411.curr_x;
    spt.ace_editor.drag_start_y = mouse_411.curr_y;

    var editor_el = $(editor_id);
    spt.ace_editor.drag_editor_el = editor_el;
    spt.ace_editor.drag_size = editor_el.getSize();

    var top = bvr.src_el.getParent(".spt_ace_editor_top");
    spt.ace_editor.drag_size_el = top.getElement(".spt_size");
}


spt.ace_editor.drag_resize_motion = function(evt, bvr, mouse_411)
{
    var diff_x = parseFloat(mouse_411.curr_x - spt.ace_editor.drag_start_x);
    var diff_y = parseFloat(mouse_411.curr_y - spt.ace_editor.drag_start_y);

    var size = spt.ace_editor.drag_size;


    var editor_el = spt.ace_editor.drag_editor_el;

    var width = size.x + diff_x
    if (width < 300) {
        width = 300;
    }
    var height = size.y + diff_y
    if (height < 200) {
        height = 200;
    }

    editor_el.setStyle("width", width);
    editor_el.setStyle("height", height);

    spt.ace_editor.drag_size_el.value = width + "," + height;

    var editor = spt.ace_editor.editor;
    editor.resize();

}
    var js_files = [
        "ace/ace-0.2.0/src/ace.js",
        //"ace/ace-0.2.0/src/ace-uncompressed.js",
    ];


   

    var ace_setup =  function() {
        var editor = ace.edit(bvr.unique_id);
        spt.ace_editor.editor = editor;

        // put the editor into the dom
        spt.ace_editor.editor_id = bvr.unique_id;
        $(bvr.unique_id).editor = editor;

        editor.setTheme("ace/theme/" + spt.ace_editor.theme);
        var JavaScriptMode = require("ace/mode/javascript").Mode;
        editor.getSession().setMode(new JavaScriptMode())
    }

    


    spt.dom.load_js(js_files, function() { 
    
        ace; require; define; 

        var core_js_files = [
        "ace/ace-0.2.0/src/mode-javascript.js",
         "ace/ace-0.2.0/src/mode-xml.js",
            "ace/ace-0.2.0/src/mode-python.js",
             "ace/ace-0.2.0/src/theme-twilight.js",
               
            "ace/ace-0.2.0/src/theme-textmate.js",
            "ace/ace-0.2.0/src/theme-vibrant_ink.js",
            "ace/ace-0.2.0/src/theme-merbivore.js",
            "ace/ace-0.2.0/src/theme-clouds.js",
            "ace/ace-0.2.0/src/theme-eclipse.js"
        ];
        //var supp_js_files = [];
           
         
        

        spt.dom.load_js(core_js_files, ace_setup);
        //spt.dom.load_js(supp_js_files);      
        });
   

    





}
else {
    var editor = ace.edit(bvr.unique_id);
    editor.setTheme("ace/theme/" +  bvr.theme);
    var JavaScriptMode = require("ace/mode/javascript").Mode;
   
    editor.getSession().setMode(new JavaScriptMode())

    spt.ace_editor.editor_id = bvr.unique_id;
    spt.ace_editor.editor = editor;
    $(bvr.unique_id).editor = editor;

}
            '''
        } )


        return top
コード例 #5
0
    def get_display(my):
        web = WebContainer.get_web()

        top = my.top
        top.add_class("spt_ace_editor_top")

        script = my.kwargs.get("custom_script")
        if script:
            language = script.get_value("language")
        else:
            language = my.kwargs.get("language")
            if not language:
                language = 'javascript'

        code = my.kwargs.get("code")
        if not code:
            code = ""


        show_options = my.kwargs.get("show_options")
        if show_options in ['false', False]:
            show_options = False
        else:
            show_options = True

        options_div = DivWdg()
        top.add(options_div)
        if not show_options:
            options_div.add_style("display: none")
        options_div.add_color("background", "background3")
        options_div.add_border()
        options_div.add_style("text-align: center")
        options_div.add_style("padding: 2px")



        select = SelectWdg("language")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.add_class("spt_language")
        select.set_option("values", "javascript|server_js|python|expression|xml")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var value = bvr.src_el.value;
            spt.ace_editor.set_language(value);

            //register_change(bvr);

            '''
        } )
 
        select = SelectWdg("font_size")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "8 pt|9 pt|10 pt|11 pt|12 pt|14 pt|16 pt")
        select.set_option("values", "8 pt|9pt|10pt|11pt|12pt|14pt|16pt")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'click_up',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var value = bvr.src_el.value;
            $(editor_id).setStyle("font-size", value)
            //editor.resize();
            '''
        } )



        select = SelectWdg("keybinding")
        select.add_style("width: 100px")
        #options_div.add(select)
        select.set_option("labels", "Ace|Vim|Emacs")
        select.set_option("values", "ace|vim|emacs")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var vim = require("ace/keyboard/keybinding/vim").Vim;
            editor.setKeyboardHandler(vim)
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)


        if code:
            load_div = DivWdg()
            top.add(load_div)
            readonly = my.kwargs.get("readonly")
            if readonly in ['true', True]:
                readonly = True
            else:
                readonly = False

            load_div.add_behavior( {
                'type': 'load',
                'code': code,
                'language': language,
                'editor_id': my.get_editor_id(),
                'readonly': readonly,
                'cbjs_action': '''
                spt.ace_editor.set_editor(bvr.editor_id);
                var func = function() {
                    var editor = spt.ace_editor.editor;
                    var document = editor.getSession().getDocument();
                    if (bvr.code) {
                        spt.ace_editor.set_value(bvr.code);
                    }
                    spt.ace_editor.set_language(bvr.language);
                    editor.setReadOnly(bvr.readonly);


                    var session = editor.getSession();
                    //session.setUseWrapMode(true);
                    //session.setWrapLimitRange(120, 120);
                };

                var editor = spt.ace_editor.editor;
                if (!editor) {
                    setTimeout( func, 1000);
                }
                else {
                    func();
                }

                '''
            } )




        # theme
        select = SelectWdg("theme")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "Eclipse|Twilight|TextMate|Vibrant Ink|Merbivore|Clouds")
        select.set_option("values", "eclipse|twilight|textmate|vibrant_ink|merbivore|clouds")
        select.set_value("twilight")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            value = bvr.src_el.value;

            editor.setTheme("ace/theme/" + value);
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)




        my.text_area.add_style("margin-top: -1px")
        my.text_area.add_style("margin-bottom: 0px")
        my.text_area.add_color("background", "background")
        my.text_area.add_style("font-family: courier new")
        my.text_area.add_border()
        editor_div.add(my.text_area)
        my.text_area.add_style("position: relative")
        #text_area.add_style("margin: 20px")


        size = web.get_form_value("size")
        if size:
            width, height = size.split(",")
        else:
            width = my.kwargs.get("width")
            if not width:
                width = "650px"
            height = my.kwargs.get("height")
            if not height:
                height = "450px"
        my.text_area.add_style("width: %s" % width)
        my.text_area.add_style("height: %s" % height)



        bottom_div = DivWdg()
        top.add(bottom_div)
        bottom_div.add_color("background", "background3")
        bottom_div.add_border()
        bottom_div.add_style("text-align: center")
        bottom_div.add_style("padding: 2px")
        bottom_div.add_style("height: 20px")

        bottom_title = "Script Editor"
        bottom_div.add(bottom_title)

        icon = IconWdg("Resize Editor", IconWdg.RESIZE_CORNER)
        bottom_div.add(icon)
        icon.add_style("float: right")
        icon.add_style("margin-right: -4px")
        icon.add_style("cursor: se-resize")
        icon.add_behavior( {
            'type': 'drag',
            "cb_set_prefix": 'spt.ace_editor.drag_resize',
        } )


        #hidden = HiddenWdg("size")
        hidden = TextWdg("size")
        bottom_div.add(hidden)
        hidden.add_style("width: 85px")
        hidden.add_style("text-align: center")
        hidden.add_style("float: right")
        hidden.add_class("spt_size")
        hidden.set_value("%s,%s" % (width, height))

        theme = top.get_theme()
        if theme == 'dark':
            theme = 'twilight'
        else:
            theme = 'eclipse'

        print "theme: ", theme

        top.add_behavior( {
            'type': 'load',
            'unique_id': my.unique_id,
            'theme': theme,
            'cbjs_action': '''

if (typeof(ace) == 'undefined') {

// fist time loading
spt.ace_editor = {}
spt.ace_editor.editor = null;
spt.ace_editor.editor_id = bvr.unique_id;
spt.ace_editor.theme = bvr.theme;


spt.ace_editor.set_editor = function(editor_id) {
    spt.ace_editor.editor_id = editor_id;
    spt.ace_editor.editor = $(editor_id).editor;
}

spt.ace_editor.set_editor_top = function(top_el) {
    if (!top_el.hasClass("spt_ace_editor")) {
        top_el = top_el.getElement(".spt_ace_editor");
    }

    var editor_id = top_el.getAttribute("id");
    spt.ace_editor.set_editor(editor_id);
}




spt.ace_editor.get_editor = function() {
    return spt.ace_editor.editor;

}



spt.ace_editor.clear_selection = function() {
    var editor = spt.ace_editor.editor;
    editor.clearSelection();

}



spt.ace_editor.get_selection = function() {
    var editor = spt.ace_editor.editor;
    //return editor.getSelection();
    return editor.getCopyText();
}





spt.ace_editor.get_value = function() {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    var value = document.getValue();
    return value;
}



spt.ace_editor.set_value = function(value) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    document.setValue(value);
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
}

spt.ace_editor.goto_line = function(number) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
 

}


spt.ace_editor.insert = function(value) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertInLine(position, value);
}

 
spt.ace_editor.insert_lines = function(values) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertLines(position.row, values);
}



spt.ace_editor.get_document = function() {
    var document = spt.ace_editor.editor.getSession().getDocument()
    return document;

}




spt.ace_editor.set_language = function(value) {
    if (!value) {
        value = 'javascript';
    }

    var editor = spt.ace_editor.editor;
    var top = $(spt.ace_editor.editor_id).getParent(".spt_ace_editor_top");
    var lang_el = top.getElement(".spt_language");

    for ( var i = 0; i < lang_el.options.length; i++ ) {
        if ( lang_el.options[i].value == value ) {
            lang_el.options[i].selected = true;
            break;
        }
    }



    var session = editor.getSession();
    var mode;
    if (value == 'python') {
        mode = require("ace/mode/python").Mode;
    }
    else if (value == 'xml') {
        mode = require("ace/mode/xml").Mode;
    }
    else if (value == 'expression') {
        mode = require("ace/mode/xml").Mode;
    }
    else {
        mode = require("ace/mode/javascript").Mode;
    }
    session.setMode( new mode() );
}

spt.ace_editor.drag_start_x;
spt.ace_editor.drag_start_y;
spt.ace_editor.drag_size;
spt.ace_editor.drag_editor_el;
spt.ace_editor.drag_size_el;
spt.ace_editor.drag_resize_setup = function(evt, bvr, mouse_411)
{
    var editor = spt.ace_editor.editor;
    var editor_id = spt.ace_editor.editor_id;

    spt.ace_editor.drag_start_x = mouse_411.curr_x;
    spt.ace_editor.drag_start_y = mouse_411.curr_y;

    var editor_el = $(editor_id);
    spt.ace_editor.drag_editor_el = editor_el;
    spt.ace_editor.drag_size = editor_el.getSize();

    var top = bvr.src_el.getParent(".spt_ace_editor_top");
    spt.ace_editor.drag_size_el = top.getElement(".spt_size");
}


spt.ace_editor.drag_resize_motion = function(evt, bvr, mouse_411)
{
    var diff_x = parseFloat(mouse_411.curr_x - spt.ace_editor.drag_start_x);
    var diff_y = parseFloat(mouse_411.curr_y - spt.ace_editor.drag_start_y);

    var size = spt.ace_editor.drag_size;


    var editor_el = spt.ace_editor.drag_editor_el;

    var width = size.x + diff_x
    if (width < 300) {
        width = 300;
    }
    var height = size.y + diff_y
    if (height < 200) {
        height = 200;
    }

    editor_el.setStyle("width", width);
    editor_el.setStyle("height", height);

    spt.ace_editor.drag_size_el.value = width + "," + height;

    var editor = spt.ace_editor.editor;
    editor.resize();

}
    var js_files = [
        "ace/ace-0.2.0/src/ace.js",
        //"ace/ace-0.2.0/src/ace-uncompressed.js",
    ];


   

    var ace_setup =  function() {
        var editor = ace.edit(bvr.unique_id);
        spt.ace_editor.editor = editor;

        // put the editor into the dom
        spt.ace_editor.editor_id = bvr.unique_id;
        $(bvr.unique_id).editor = editor;

        editor.setTheme("ace/theme/" + spt.ace_editor.theme);
        var JavaScriptMode = require("ace/mode/javascript").Mode;
        editor.getSession().setMode(new JavaScriptMode())
    }

    


    spt.dom.load_js(js_files, function() { 
    
        ace; require; define; 

        var core_js_files = [
        "ace/ace-0.2.0/src/mode-javascript.js",
         "ace/ace-0.2.0/src/mode-xml.js",
            "ace/ace-0.2.0/src/mode-python.js",
             "ace/ace-0.2.0/src/theme-twilight.js",
               
            "ace/ace-0.2.0/src/theme-textmate.js",
            "ace/ace-0.2.0/src/theme-vibrant_ink.js",
            "ace/ace-0.2.0/src/theme-merbivore.js",
            "ace/ace-0.2.0/src/theme-clouds.js",
            "ace/ace-0.2.0/src/theme-eclipse.js"
        ];
        //var supp_js_files = [];
           
         
        

        spt.dom.load_js(core_js_files, ace_setup);
        //spt.dom.load_js(supp_js_files);      
        });
   

    





}
else {
    var editor = ace.edit(bvr.unique_id);
    editor.setTheme("ace/theme/" +  bvr.theme);
    var JavaScriptMode = require("ace/mode/javascript").Mode;
   
    editor.getSession().setMode(new JavaScriptMode())

    spt.ace_editor.editor_id = bvr.unique_id;
    spt.ace_editor.editor = editor;
    $(bvr.unique_id).editor = editor;

}
            '''
        } )


        return top
コード例 #6
0
ファイル: gallery_wdg.py プロジェクト: mwx1993/TACTIC
    def get_display(my):

        my.sobject_data = {}

        top = my.top
        top.add_style
        top.add_class("spt_gallery_top")

        inner = DivWdg()
        top.add(inner)
        inner.add_style("position: fixed")
        inner.add_style("top: 0")
        inner.add_style("left: 0")
        inner.add_style("width: 100%")
        #inner.add_style("height: 100%")
        inner.add_style("bottom: 0px")
        inner.add_style("padding-bottom: 40px")

        #inner.add_style("background: rgba(0,0,0,0.5)")
        inner.add_style("background: rgba(0,0,0,1)")
        inner.add_style("z-index: 1000")

        width = my.kwargs.get("width")
        height = my.kwargs.get("height")
        if not width:
            width = 1300
        else:
            width = int(width)

        paths = my.get_paths(file_type='main')
        # icon type may be too small
        thumb_paths = my.get_paths(file_type='web')

        descriptions = []
        for path in paths:
            sobject = my.sobject_data.get(path)
            if not sobject:
                descriptions.append("")
            else:
                description = sobject.get("description")
                if not description:
                    description = ""
                descriptions.append(description)

        total_width = width * len(paths)
        inner.add_behavior({
            'type':
            'load',
            'width':
            width,
            'total_width':
            total_width,
            'descriptions':
            descriptions,
            'cbjs_action':
            '''
        spt.gallery = {};
        // 1250 is defined also in the css styles
        spt.gallery.portrait = window.innerWidth < 1250;

       
        
        spt.gallery.top = bvr.src_el;
        spt.gallery.content = spt.gallery.top.getElement(".spt_gallery_content");
        spt.gallery.content.setStyle('opacity','0.1')
        spt.gallery.desc_el = spt.gallery.top.getElement(".spt_gallery_description");
        
        var height_factor = '100%'; 
        if (spt.gallery.portrait) {
            bvr.width = bvr.width * 0.8;
            var scroll = bvr.src_el.getElement('.spt_gallery_scroll');
            scroll.setStyle('width', bvr.width);
            scroll.setStyle('height', '80%');
            scroll.setStyle('position', 'relative');
            scroll.setStyle('top', '500px');
            
            var items = bvr.src_el.getElements('.spt_gallery_item');
            for (var k=0; k < items.length; k++) {
                items[k].setStyle('width', bvr.width);
                items[k].setStyle('height', '80%');
            }
            var left = bvr.src_el.getElement('.spt_left_arrow');
            var right = bvr.src_el.getElement('.spt_right_arrow');
            left.setStyle('top','88%')
            left.setStyle('left','35%')
            right.setStyle('top','88%')
            
            right.setStyle('right','35%')
            
            height_factor = '70%';
            
        }
        //window.addEvent('domready', function() {
        setTimeout(function() {
		// set the img h or w directly
		var items = bvr.src_el.getElements('.spt_gallery_item img');
		// fade in
        spt.gallery.content.set('tween', {duration: 250}).fade('in');

		for (var k=0; k < items.length; k++) {
		    var sizes = items[k].getSize();
		    var item_h = sizes.y;
		    var item_w = sizes.x;
		    if (item_h >= item_w){
			    items[k].setStyle('width', '');
			    items[k].setStyle('height', height_factor);
		    }
		    else {
			    items[k].setStyle('width','100%');
			    items[k].setStyle('height','');
		    }
		    
		}
        }, 50)
        spt.gallery.width = bvr.width;
        spt.gallery.descriptions = bvr.descriptions;
        spt.gallery.index = 0;
        spt.gallery.total = bvr.descriptions.length;
        spt.gallery.left_arrow = bvr.src_el.getElement('.spt_left_arrow');
        spt.gallery.right_arrow = bvr.src_el.getElement('.spt_right_arrow');
        spt.gallery.videos = {};
       

        spt.gallery.init = function() {
            
        }

        spt.gallery.stack = [];

        spt.gallery.push_stack = function(key) {
            spt.gallery.stack.push(key);
        }


        spt.gallery.show_next = function(src_el) {
            if (!src_el)
                src_el = spt.gallery.right_arrow;
           
            if (spt.gallery.index >= spt.gallery.total-2) {
                spt.hide(src_el);
            }
            if (spt.gallery.index == spt.gallery.total-1) {
                return;
            }
            spt.gallery.index += 1;
            spt.gallery.show_index(spt.gallery.index);
        }

        spt.gallery.show_prev = function(src_el) {
            if (!src_el)
                src_el = spt.gallery.left_arrow;
            if (spt.gallery.index <= 1) {
                spt.hide(src_el);
            
            }
            if (spt.gallery.index == 0) {
                return;
            }
            
            spt.gallery.index -= 1;
            spt.gallery.show_index(spt.gallery.index);
        }


        spt.gallery.show_index = function(index) {

          
            // stop all videos
            var videos = spt.gallery.top.getElements(".video-js");
            for (var i = 0; i < videos.length; i++) {
                try {
                    var video = videos[i];
                    var video_id = video.get("id");
                    var video_obj = videojs(video_id,  {"nativeControlsForTouch": false});
                    video_obj.pause();

                }
                catch(e) {
                }
            }
            var width = spt.gallery.width;
            var margin = - width * index;
            var content = spt.gallery.content;
            //content.setStyle("margin-left", margin + "px");
            new Fx.Tween(content,{duration: 250}).start("margin-left", margin);

            spt.gallery.index = index;
            var total = spt.gallery.total;
            
           
            if (index == 0) {
                spt.hide(spt.gallery.left_arrow);
                spt.show(spt.gallery.right_arrow);
            }
            else if (index == total - 1) {
                spt.show(spt.gallery.left_arrow);
                spt.hide(spt.gallery.right_arrow);
            }
            else {
                spt.show(spt.gallery.left_arrow);
                spt.show(spt.gallery.right_arrow);
            }
                

            
            var description = spt.gallery.descriptions[index];
            if (!description) {
                description = (index+1)+" of "+total;
            }
            else {
                description = (index+1)+" of "+total+" - " + description;
            }
            spt.gallery.set_description(description);
        }


        spt.gallery.close = function() {
            var content = spt.gallery.content;
            var top = content.getParent(".spt_gallery_top");
            spt.behavior.destroy_element(top);
        }


        spt.gallery.set_description = function(desc) {
            var desc_el = spt.gallery.desc_el;
            desc_el.innerHTML = desc;
        }

        '''
        })

        scroll = DivWdg(css='spt_gallery_scroll')
        inner.add(scroll)
        scroll.set_box_shadow()

        scroll.add_style("width: %s" % width)
        if height:
            scroll.add_style("height: %s" % height)
        scroll.add_style("overflow-x: hidden")
        scroll.add_style("overflow-y: hidden")
        scroll.add_style("background: #000")

        #scroll.add_style("position: absolute")
        scroll.add_style("margin-left: auto")
        scroll.add_style("margin-right: auto")

        content = DivWdg()
        top.add_attr('tabindex', '-1')

        scroll.add(content)
        content.add_class("spt_gallery_content")
        # make the itesm vertically align to bottom
        content.add_styles(
            "display: flex; flex-flow: row nowrap; align-items: flex-end;")
        content.add_style("width: %s" % total_width)

        top.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            bvr.src_el.focus();
            '''
        })

        top.add_behavior({
            'type':
            'mouseenter',
            'cbjs_action':
            '''
            bvr.src_el.focus();
            '''
        })
        top.add_behavior({
            'type':
            'mouseleave',
            'cbjs_action':
            '''
            bvr.src_el.blur();
            '''
        })
        """
        input = TextWdg("keydown")
        content.add(input)
        input.add_style("position: absolute")
        input.add_style("left: -5000px")
        """
        top.add_behavior({
            'type':
            'keydown',
            'cbjs_action':
            '''
            var key = evt.key;
            
            if (key == "left") {
                spt.gallery.push_stack(key);
                spt.gallery.show_prev();
            }
            else if (key == "right") {
                spt.gallery.push_stack(key);
                spt.gallery.show_next();
            }
            else if (key == "esc" || key == "enter") {
                
                var top = bvr.src_el
                spt.behavior.destroy_element(top);
            }



            '''
        })

        curr_index = 0
        for i, path in enumerate(paths):
            path_div = DivWdg(css='spt_gallery_item')
            content.add(path_div)
            path_div.add_style("float: left")

            if path == my.curr_path:
                curr_index = i

            try:
                thumb_path = thumb_paths[i]
            except IndexError:
                print "Cannot find the thumb_path [%s] " % i
                thumb_path = ''

            path_div.add_style("width: %s" % width)
            if height:
                path_div.add_style("height: %s" % height)

            from tactic.ui.widget import EmbedWdg
            embed = EmbedWdg(src=path,
                             click=False,
                             thumb_path=thumb_path,
                             index=i)
            path_div.add(embed)

            #img = HtmlElement.img(path)
            #path_div.add(img)
            #img.add_style("width: 100%")

        content.add_behavior({
            'type':
            'load',
            'index':
            curr_index,
            'cbjs_action':
            '''
            if (!bvr.index) bvr.index = 0;
            spt.gallery.show_index(bvr.index);
            '''
        })

        #icon = IconWdg(title="Close", icon="/plugins/remington/pos/icons/close.png")
        icon = IconWdg(title="Close",
                       icon="/context/icons/glyphs/close.png",
                       width="40px")
        inner.add(icon)
        #icon = DivWdg()
        #icon.add("X")
        #icon.add_style("font-size: 42px")
        #icon.add_style("color: #ddd")
        #icon.add_style("width: 48px")
        #icon.add_style("height: 48px")
        #icon.add_style("text-align: center")
        #icon.add_style("border-radius: 30px")
        #icon.add_style("border: solid 3px #ddd")
        icon.add_style("position: absolute")
        icon.add_style("cursor: pointer")
        icon.add_style("bottom: 80px")
        icon.add_style("left: 38px")
        icon.add_style("opacity: 0.5")
        icon.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_gallery_top");
            spt.behavior.destroy_element(top);
            '''
        })

        icon = IconWdg(title="Previous",
                       icon="/context/icons/glyphs/chevron_left.png")
        inner.add(icon)
        icon.add_class('spt_left_arrow')
        icon.add_style("cursor: pointer")
        icon.add_style("position: absolute")
        icon.add_style("top: 40%")
        icon.add_style("left: 0px")
        icon.add_style("opacity: 0.5")
        icon.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var arrow = bvr.src_el;
            spt.gallery.show_prev(arrow); 
            '''
        })

        icon = IconWdg(title="Next",
                       icon="/context/icons/glyphs/chevron_right.png")
        inner.add(icon)
        icon.add_class('spt_right_arrow')
        icon.add_style("position: absolute")
        icon.add_style("cursor: pointer")
        icon.add_style("top: 40%")
        icon.add_style("right: 0px")
        icon.add_style("opacity: 0.5")
        icon.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var arrow = bvr.src_el;
            spt.gallery.show_next(arrow); 
            '''
        })

        desc_div = DivWdg()
        desc_div.add_class("spt_gallery_description")
        desc_div.add_style("height: 30px")
        desc_div.add_style("width: %s" % width)
        desc_div.add_style("text-align: center")
        desc_div.add_style("background: rgba(0,0,0,1)")
        desc_div.add_style("color: #bbb")
        desc_div.add_style("font-weight: bold")
        desc_div.add_style("font-size: 16px")
        desc_div.add_style("padding-top: 10px")
        desc_div.add_style("margin-left: -%s" % (width / 2))
        desc_div.add_style("z-index: 1000")
        desc_div.add("")

        desc_outer_div = DivWdg()
        inner.add(desc_outer_div)
        desc_outer_div.add_style("position: fixed")
        desc_outer_div.add(desc_div)
        desc_outer_div.add_style("bottom: 0px")
        desc_outer_div.add_style("left: 50%")

        return top
コード例 #7
0
ファイル: popup_wdg.py プロジェクト: 2gDigitalPost/tactic_src
    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
コード例 #8
0
ファイル: gallery_wdg.py プロジェクト: mincau/TACTIC
    def get_display(self):

        self.sobject_data = {}

        top = self.top
        top.add_style
        top.add_class("spt_gallery_top")

        inner = DivWdg()
        top.add(inner)

        # make the whole Gallery unselectable
        inner.add_class('unselectable')
        inner.add_style("position: fixed")
        inner.add_style("top: 0px")
        inner.add_style("left: 0px")
        inner.add_style("width: 100%")
        #inner.add_style("height: 100%")
        inner.add_style("bottom: 0px")
        inner.add_style("padding-bottom: 40px")

        #inner.add_style("background: rgba(0,0,0,0.5)")
        inner.add_style("background: rgba(0,0,0,1)")
        inner.add_style("z-index: 2000")


        width = self.kwargs.get("width")
        height = self.kwargs.get("height")
        
        # default to top.
        align = self.kwargs.get("align")
        if not align:
            align = "top"


        if not width:
            width = 1300
        else:
            width = int(width)


        paths = self.get_paths(file_type='main')
        # icon type may be too small
        thumb_paths = self.get_paths(file_type='web')
        
        descriptions = []
        for path in paths:
            sobject = self.sobject_data.get(path)
            if not sobject:
                descriptions.append("")
            else:
                description = sobject.get("description")
                if not description:
                    description = ""
                descriptions.append(description)

        total_width = width * len(paths)
        inner.add_behavior( {
        'type': 'load',
        'width': width,
        'total_width': total_width,
        'descriptions': descriptions,
        'cbjs_action': '''
        spt.gallery = {};
        // 1250 is defined also in the css styles
        spt.gallery.portrait = window.innerWidth < 1250;
        spt.gallery.portrait = false

        
        spt.gallery.top = bvr.src_el;
        spt.gallery.content = spt.gallery.top.getElement(".spt_gallery_content");
        spt.gallery.content.setStyle('opacity','0.1')
        spt.gallery.desc_el = spt.gallery.top.getElement(".spt_gallery_description");
        
        //window.addEvent('domready', function() {
        setTimeout(function() {
		// set the img h or w directly
		var items = bvr.src_el.getElements('.spt_gallery_item img');
		// fade in
        spt.gallery.content.set('tween', {duration: 250}).fade('in');

        /*
		for (var k=0; k < items.length; k++) {
		    var sizes = items[k].getSize();
		    var item_h = sizes.y;
		    var item_w = sizes.x;
		    if (item_h >= item_w){
			    //items[k].setStyle('width', 'auto');
			    //items[k].setStyle('height', '100%');
		    }
		    else {
			    //items[k].setStyle('width','auto');
			    //items[k].setStyle('height','100%');
		    }
		    
		}
        */


        }, 50)

        spt.gallery.width = bvr.width;
        spt.gallery.descriptions = bvr.descriptions;
        spt.gallery.index = 0;
        spt.gallery.total = bvr.descriptions.length;
        spt.gallery.left_arrow = bvr.src_el.getElement('.spt_left_arrow');
        spt.gallery.right_arrow = bvr.src_el.getElement('.spt_right_arrow');
        spt.gallery.videos = {};
       

        spt.gallery.init = function() {
            
        }

        spt.gallery.stack = [];

        spt.gallery.push_stack = function(key) {
            spt.gallery.stack.push(key);
        }


        spt.gallery.show_next = function(src_el) {
            if (!src_el)
                src_el = spt.gallery.right_arrow;
           
            if (spt.gallery.index >= spt.gallery.total-2) {
                spt.hide(src_el);
            }
            if (spt.gallery.index == spt.gallery.total-1) {
                return;
            }
            spt.gallery.index += 1;
            spt.gallery.show_index(spt.gallery.index);
        }

        spt.gallery.show_prev = function(src_el) {
            if (!src_el)
                src_el = spt.gallery.left_arrow;
            if (spt.gallery.index <= 1) {
                spt.hide(src_el);
            
            }
            if (spt.gallery.index == 0) {
                return;
            }
            
            spt.gallery.index -= 1;
            spt.gallery.show_index(spt.gallery.index);
        }


        spt.gallery.show_index = function(index) {

          
            // stop all videos
            var videos = spt.gallery.top.getElements(".video-js");
            for (var i = 0; i < videos.length; i++) {
                try {
                    var video = videos[i];
                    var video_id = video.get("id");
                    var video_obj = videojs(video_id,  {"nativeControlsForTouch": false});
                    video_obj.pause();

                }
                catch(e) {
                }
            }


            // can't tween percentage with this library???
            var width = spt.gallery.width;
            var margin = - width * index;
            var content = spt.gallery.content;
            //content.setStyle("margin-left", margin + "px");
            new Fx.Tween(content,{duration: 250}).start("margin-left", margin);
 


            spt.gallery.index = index;
            var total = spt.gallery.total;
            
           
            if (index == 0) {
                spt.hide(spt.gallery.left_arrow);
                spt.show(spt.gallery.right_arrow);
            }
            else if (index == total - 1) {
                spt.show(spt.gallery.left_arrow);
                spt.hide(spt.gallery.right_arrow);
            }
            else {
                spt.show(spt.gallery.left_arrow);
                spt.show(spt.gallery.right_arrow);
            }
                

            
            var description = spt.gallery.descriptions[index];
            if (!description) {
                description = (index+1)+" of "+total;
            }
            else {
                description = (index+1)+" of "+total+" - " + description;
            }
            spt.gallery.set_description(description);
        }


        spt.gallery.close = function() {
            var content = spt.gallery.content;
            var top = content.getParent(".spt_gallery_top");
            spt.behavior.destroy_element(top);
        }


        spt.gallery.set_description = function(desc) {
            var desc_el = spt.gallery.desc_el;
            desc_el.innerHTML = desc;
        }

        '''
        } )




        scroll = DivWdg(css='spt_gallery_scroll')
        inner.add(scroll)
        scroll.set_box_shadow()
        scroll.add_style("width: %s" % width)
        if height:
            scroll.add_style("height: %s" % height)
        scroll.add_style("overflow-x: hidden")
        scroll.add_style("overflow-y: hidden")
        scroll.add_style("background: #000")

        #scroll.add_style("position: absolute")
        scroll.add_style("margin-left: auto")
        scroll.add_style("margin-right: auto")



        

        content = DivWdg()
        top.add_attr('tabindex','-1')

        scroll.add(content)
        content.add_class("spt_gallery_content")

        # make the items vertically align to bottom (flex-emd)
        # on a regular monitor, align to top (flex-start) is better
        if align == 'bottom':
            align_items = 'flex-end'
        else:
            align_items = 'flex-start'
        content.add_styles("display: flex; flex-flow: row nowrap; align-items: %s; justify-content: center;"%align_items)

        content.add_style("width: %s" % total_width)

        top.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            bvr.src_el.focus();
            '''
        } )
 
        top.add_behavior( {
            'type': 'mouseenter',
            'cbjs_action': '''
            bvr.src_el.focus();
            '''
        } )
        top.add_behavior( {
            'type': 'mouseleave',
            'cbjs_action': '''
            bvr.src_el.blur();
            '''
        } )


        """
        input = TextWdg("keydown")
        content.add(input)
        input.add_style("position: absolute")
        input.add_style("left: -5000px")
        """
        top.add_behavior( {
            'type': 'keydown',
            'cbjs_action': '''
            var key = evt.key;
            
            if (key == "left") {
                spt.gallery.push_stack(key);
                spt.gallery.show_prev();
            }
            else if (key == "right") {
                spt.gallery.push_stack(key);
                spt.gallery.show_next();
            }
            else if (key == "esc" || key == "enter") {
                
                var top = bvr.src_el
                spt.behavior.destroy_element(top);
            }



            '''
        } )



        curr_index = 0
        for i, path in enumerate(paths):
            path_div = DivWdg(css='spt_gallery_item')
            content.add(path_div)
            #path_div.add_style("float: left")
            path_div.add_style("display: inline-block")
            path_div.add_style("vertical-align: middle")

            if path == self.curr_path:
                curr_index = i

            try:
                thumb_path = thumb_paths[i]
            except IndexError:
                print "Cannot find the thumb_path [%s] "%i 
                thumb_path = ''

            #path_div.add_style("width: %s" % width)
            #if height:
            #    path_div.add_style("height: %s" % height)
            path_div.add_style("width: 100%")
            path_div.add_style("height: 100%")
            path_div.add_style("overflow-x: hidden")
            path_div.add_style("overflow-y: hidden")

            from tactic.ui.widget import EmbedWdg
            embed = EmbedWdg(src=path, click=False, thumb_path=thumb_path, index=i, controls="true")
            path_div.add(embed)




        content.add_behavior({
            'type': 'load',
            'index': curr_index,
            'cbjs_action': '''
            if (!bvr.index) bvr.index = 0;
            spt.gallery.show_index(bvr.index);
            '''
        } )



        #icon = IconWdg(title="Close", icon="/plugins/remington/pos/icons/close.png")
        icon = IconWdg(title="Close", icon="/context/icons/glyphs/close.png", width="40px")
        inner.add(icon)
        icon.add_style("position: absolute")
        icon.add_style("cursor: pointer")
        icon.add_style("top: 30px")
        icon.add_style("right: 38px")
        icon.add_style("opacity: 0.5")
        icon.add_behavior( {
            'type': 'click_up' ,
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_gallery_top");
            spt.behavior.destroy_element(top);
            '''
        } )
        icon.add_style("background", "rgba(48,48,48,0.7)")
        icon.add_style("border-radius", "5px")


        icon = IconWdg(title="Previous", icon="/context/icons/glyphs/chevron_left.png")
        inner.add(icon)
        icon.add_class('spt_left_arrow')
        icon.add_style("cursor: pointer")
        icon.add_style("position: absolute")
        icon.add_style("top: 40%")
        icon.add_style("left: 0px")
        icon.add_style("opacity: 0.5")
        icon.add_behavior( {
            'type': 'click_up' ,
            'cbjs_action': '''
            var arrow = bvr.src_el;
            spt.gallery.show_prev(arrow); 
            '''
        } )
        icon.add_style("background", "rgba(48,48,48,0.7)")
        icon.add_style("border-radius", "5px")


        icon = IconWdg(title="Next", icon="/context/icons/glyphs/chevron_right.png")
        inner.add(icon)
        icon.add_class('spt_right_arrow')
        icon.add_style("position: absolute")
        icon.add_style("cursor: pointer")
        icon.add_style("top: 40%")
        icon.add_style("right: 0px")
        icon.add_style("opacity: 0.5")
        icon.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var arrow = bvr.src_el;
            spt.gallery.show_next(arrow); 
            '''
        } )
        icon.add_style("background", "rgba(48,48,48,0.7)")
        icon.add_style("border-radius", "5px")




        desc_div = DivWdg()
        desc_div.add_class("spt_gallery_description")
        desc_div.add_style("height: 30px")
        desc_div.add_style("width: %s" % width)
        desc_div.add_style("text-align: center")
        desc_div.add_style("background: rgba(0,0,0,1)")
        desc_div.add_style("color: #bbb")
        desc_div.add_style("font-weight: bold")
        desc_div.add_style("font-size: 16px")
        desc_div.add_style("padding-top: 10px")
        desc_div.add_style("margin-left: -%s" % (width/2))
        desc_div.add_style("z-index: 1000")
        desc_div.add("")

        desc_outer_div = DivWdg()
        inner.add(desc_outer_div)
        desc_outer_div.add_style("position: fixed")
        desc_outer_div.add(desc_div)
        desc_outer_div.add_style("bottom: 0px")
        desc_outer_div.add_style("left: 50%")



        return top
コード例 #9
0
ファイル: collection_wdg.py プロジェクト: asmboom/TACTIC
    def get_display(my):

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

        collection = Search.get_by_search_key(my.collection_key)

        top = my.top

        my.kwargs["scale"] = 75;
        my.kwargs["show_scale"] = False;
        my.kwargs["expand_mode"] = "plain"
        from tile_layout_wdg import TileLayoutWdg
        tile = TileLayoutWdg(
            **my.kwargs
        )
        parent_dict = my.kwargs.get("parent_dict")
        has_parent=False
        if parent_dict:
            has_parent = True

        path = my.kwargs.get("path")
        if collection and path:
            title_div = DivWdg()
            top.add(title_div)
            title_div.add_style("float: left")
            title_div.add_style("margin: 15px 0px 15px 30px")

            asset_lib_span_div = SpanWdg()
            title_div.add(asset_lib_span_div)

            icon = IconWdg(name="Asset Library", icon="BS_FOLDER_OPEN")
            
            asset_lib_span_div.add(icon)

            asset_lib_span_div.add(" <a><b>Asset Library</b></a> ")
            
            path = path.strip("/")
            parts = path.split("/")

            for idx, part in enumerate(parts):
                title_div.add(" / ")
                # the last spt_collection_link does not need a search_key
                if has_parent and (idx is not len(parts) - 1):
                    search_key = parent_dict.get(part)
                    title_div.add(" <a class='spt_collection_link' search_key=%s><b>%s</b></a> " % (search_key, part))
                else:
                    title_div.add(" <a class='spt_collection_link'><b>%s</b></a> " % part)
                title_div.add_style("margin-top: 10px")


            # Adding behavior to collections link

            parts = my.kwargs.get("search_type").split("/")
            collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])
            
            exists = SearchType.get(collection_type, no_exception=True)
            if not exists:
                title_div.add("SearchType %s is not registered." % collection_type)
                return top

            # These behaviors are only activated if the view is within collection layout,
            # "is_new_tab" is a kwargs set to true, if opening a new tab
            if not my.kwargs.get("is_new_tab"):
                icon.add_class("hand")
                icon.add_behavior( {
                    'type': 'mouseover',
                    'cbjs_action': '''
                    bvr.src_el.setStyle('opacity', 1.0);
                    '''
                } )
                icon.add_behavior( {
                    'type': 'mouseout',
                    'cbjs_action': '''
                    bvr.src_el.setStyle('opacity', 0.6);
                    '''
                } )
                # make icon and All Assets title clickable to return to view all assets
                asset_lib_span_div.add_class("hand")
                asset_lib_span_div.add_behavior( {
                    'type': 'click_up',
                    'cbjs_action': '''
                    var top = bvr.src_el.getParent(".spt_collection_top");
                    var content = top.getElements(".spt_collection_content");

                    spt.panel.refresh(top);
                    '''
                } )

                title_div.add_class("hand")
                title_div.add_relay_behavior( {
                    'type': 'mouseup',
                    'search_type': my.kwargs.get("search_type"),
                    'collection_type': collection_type,
                    'bvr_match_class': 'spt_collection_link',
                    'cbjs_action': '''

                    var top = bvr.src_el.getParent(".spt_collection_top");
                    var content = top.getElement(".spt_collection_content");

                    var collection_key = bvr.src_el.getAttribute("search_key");
                    if (!collection_key) {
                        spt.notify.show_message("Already in the Collection.");
                    } 
                    else {
                        var collection_code = collection_key.split("workflow/asset?project=workflow&code=")[1];
                        var collection_path = bvr.src_el.innerText;
                        var expr = "@SEARCH("+bvr.collection_type+"['parent_code','"+collection_code+"']."+bvr.search_type+")";

                        var cls = "tactic.ui.panel.CollectionContentWdg";
                        var kwargs = {
                            collection_key: collection_key,
                            path: collection_path,
                            search_type: bvr.search_type,
                            show_shelf: false,
                            show_search_limit: true,
                            expression: expr
                        }
                        spt.panel.load(content, cls, kwargs);

                        bvr.src_el.setStyle("box-shadow", "0px 0px 3px rgba(0,0,0,0.5)");
                    }

                    '''
                } )
                    
                #title_div.add("/ %s" % collection.get_value("name") )

        #scale_wdg = tile.get_scale_wdg()
        #top.add(scale_wdg)
        #scale_wdg.add_style("float: right")

        top.add(my.get_header_wdg())

        top.add(tile)

        return top
コード例 #10
0
ファイル: db_resource_wdg.py プロジェクト: zieglerm/TACTIC
    def get_tables_wdg(self):

        div = DivWdg()
        div.set_name("Tables")

        div.add(
            "In order to fully register a database, you must bind it to a TACTIC project"
        )
        div.add("<br/>")

        project_code = "mongodb"
        database = "test_database"

        db_resource = DbResource(server='localhost',
                                 vendor='MongoDb',
                                 database=database)

        try:
            connect = DbContainer.get(db_resource)
        except Exception as e:
            div.add("Could not connect")
            div.add_style("padding: 30px")
            div.add("<br/>" * 2)
            div.add(str(e))
            return div

        # Bind project to this resource
        database_text = TextWdg("database")
        div.add("Database: ")
        div.add(database_text)

        div.add("<br/>" * 2)

        project_text = TextWdg("project")
        div.add("Project Code: ")
        div.add(project_text)

        div.add("<br/>")
        div.add("<hr/>")

        # connect and introspect the tables in this database
        tables = connect.get_tables()

        table = Table()
        div.add(table)
        table.set_max_width()

        for table_name in tables:
            table.add_row()
            search_type = "table/%s?project=%s" % (table_name, project_code)

            td = table.add_cell()
            icon = IconWdg("View Table", IconWdg.FOLDER_GO)
            td.add(icon)
            icon.add_behavior({
                'type':
                'click_up',
                'search_type':
                search_type,
                'cbjs_action':
                '''
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type
                }
                spt.panel.load_popup("table", class_name, kwargs);
                '''
            })

            td = table.add_cell()
            td.add(table_name)

            td = table.add_cell()
            search = Search(search_type)
            count = search.get_count()
            td.add(" %s item/s" % count)

            columns = search.get_columns()
            td = table.add_cell()
            td.add(columns)

            # search_type
            td = table.add_cell()
            text = TextWdg("search_type")
            td.add(text)
            new_search_type = "%s/%s" % (project_code, table_name)
            text.set_value(new_search_type)

        register_div = DivWdg()
        div.add(register_div)
        register_div.add_style("padding: 20px")

        button = ActionButtonWdg(title="Register")
        register_div.add(button)

        return div
コード例 #11
0
    def get_display(my):

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

        collection = Search.get_by_search_key(my.collection_key)

        top = my.top
        top.add_style("min-height: 400px")

        my.kwargs["scale"] = 75
        my.kwargs["show_scale"] = False
        my.kwargs["expand_mode"] = "plain"
        my.kwargs["show_search_limit"] = False

        from tile_layout_wdg import TileLayoutWdg
        tile = TileLayoutWdg(**my.kwargs)
        parent_dict = my.kwargs.get("parent_dict")
        has_parent = False
        if parent_dict:
            has_parent = True

        path = my.kwargs.get("path")
        if collection and path:
            title_div = DivWdg()
            top.add(title_div)
            title_div.add_style("float: left")
            title_div.add_style("margin: 15px 0px 15px 30px")

            asset_lib_span_div = SpanWdg()
            title_div.add(asset_lib_span_div)

            icon = IconWdg(name="Asset Library", icon="BS_FOLDER_OPEN")

            asset_lib_span_div.add(icon)

            asset_lib_span_div.add(" <a><b>Asset Library</b></a> ")

            path = path.strip("/")
            parts = path.split("/")

            for idx, part in enumerate(parts):
                title_div.add(" / ")
                # the last spt_collection_link does not need a search_key
                if has_parent and (idx is not len(parts) - 1):
                    search_key = parent_dict.get(part)
                    title_div.add(
                        " <a class='spt_collection_link' search_key=%s><b>%s</b></a> "
                        % (search_key, part))
                else:
                    title_div.add(
                        " <a class='spt_collection_link'><b>%s</b></a> " %
                        part)
                title_div.add_style("margin-top: 10px")

            # Adding behavior to collections link

            parts = my.kwargs.get("search_type").split("/")
            collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])

            exists = SearchType.get(collection_type, no_exception=True)
            if not exists:
                title_div.add("SearchType %s is not registered." %
                              collection_type)
                return top

            # These behaviors are only activated if the view is within collection layout,
            # "is_new_tab" is a kwargs set to true, if opening a new tab
            if not my.kwargs.get("is_new_tab"):
                icon.add_class("hand")
                icon.add_behavior({
                    'type':
                    'mouseover',
                    'cbjs_action':
                    '''
                    bvr.src_el.setStyle('opacity', 1.0);
                    '''
                })
                icon.add_behavior({
                    'type':
                    'mouseout',
                    'cbjs_action':
                    '''
                    bvr.src_el.setStyle('opacity', 0.6);
                    '''
                })
                # make icon and All Assets title clickable to return to view all assets
                asset_lib_span_div.add_class("hand")
                asset_lib_span_div.add_behavior({
                    'type':
                    'click_up',
                    'cbjs_action':
                    '''
                    var top = bvr.src_el.getParent(".spt_collection_top");
                    var view_panel = top.getParent(".spt_view_panel");

                    spt.panel.refresh(view_panel);
                    '''
                })

                title_div.add_class("hand")
                title_div.add_relay_behavior({
                    'type':
                    'mouseup',
                    'search_type':
                    my.kwargs.get("search_type"),
                    'collection_type':
                    collection_type,
                    'bvr_match_class':
                    'spt_collection_link',
                    'cbjs_action':
                    '''

                    var top = bvr.src_el.getParent(".spt_collection_top");
                    var content = top.getElement(".spt_collection_content");

                    var collection_key = bvr.src_el.getAttribute("search_key");
                    if (!collection_key) {
                        spt.notify.show_message("Already in the Collection.");
                    } 
                    else {
                        var collection_code = collection_key.split("workflow/asset?project=workflow&code=")[1];
                        var collection_path = bvr.src_el.innerText;
                        var expr = "@SEARCH("+bvr.collection_type+"['parent_code','"+collection_code+"']."+bvr.search_type+")";

                        var cls = "tactic.ui.panel.CollectionContentWdg";
                        var kwargs = {
                            collection_key: collection_key,
                            path: collection_path,
                            search_type: bvr.search_type,
                            show_shelf: false,
                            show_search_limit: true,
                            expression: expr
                        }
                        spt.panel.load(content, cls, kwargs);

                        bvr.src_el.setStyle("box-shadow", "0px 0px 3px rgba(0,0,0,0.5)");
                    }

                    '''
                })

                #title_div.add("/ %s" % collection.get_value("name") )

        #scale_wdg = tile.get_scale_wdg()
        #top.add(scale_wdg)
        #scale_wdg.add_style("float: right")

        top.add(my.get_header_wdg())

        top.add(tile)

        return top
コード例 #12
0
ファイル: simple_search_wdg.py プロジェクト: zieglerm/TACTIC
    def get_display(self):

        element_data_dict = {}

        config = self.get_config()
        element_names = config.get_element_names()

        content_wdg = DivWdg()
        content_wdg.add_class("spt_simple_search_top")

        onload_js = DivWdg()
        content_wdg.add(onload_js)
        onload_js.add_behavior({
            'type': 'load',
            'cbjs_action': self.get_onload_js()
        })

        if not element_names:
            element_names = ['keywords']

        self.set_content(content_wdg)

        # this is somewhat duplicated logic from alter_search, but since this is called
        # in ViewPanelWdg, it's a diff instance and needs to retrieve again
        filter_data = FilterData.get()

        filter_view = self.kwargs.get("filter_view")
        if filter_view:
            search = Search("config/widget_config")
            search.add_filter("view", filter_view)
            search.add_filter("category", "search_filter")
            search.add_filter("search_type", self.search_type)
            filter_config = search.get_sobject()
            if filter_config:
                filter_xml = filter_config.get_xml_value("config")
                filter_value = filter_xml.get_value("config/filter/values")
                if filter_value:
                    data_list = jsonloads(filter_value)

        else:
            data_list = filter_data.get_values_by_prefix(self.prefix)

        for data in data_list:
            handler = data.get("handler")
            element_name = data.get("element_name")
            if not element_name:
                continue

            element_data_dict[element_name] = data

        elements_wdg = DivWdg()
        content_wdg.add(elements_wdg)
        elements_wdg.add_color("color", "color")
        elements_wdg.add_style("padding-top: 10px")
        elements_wdg.add_style("padding-bottom: 15px")

        #elements_wdg.add_color("background", "background3", 0)
        elements_wdg.add_color("background", "background", -3)
        elements_wdg.add_border()

        if len(element_names) == 1:
            elements_wdg.add_style("border-width: 0px 0px 0px 0px")
            elements_wdg.add_style("padding-right: 50px")
        else:
            elements_wdg.add_style("border-width: 0px 0px 0px 0px")

        table = Table()
        table.add_color("color", "color")
        elements_wdg.add(table)
        table.add_class("spt_simple_search_table")

        columns = self.kwargs.get("columns")
        if not columns:
            columns = 2
        else:
            columns = int(columns)

        num_rows = int(len(element_names) / columns) + 1
        tot_rows = int(len(element_names) / columns) + 1
        project_code = Project.get_project_code()
        # self.search_type could be the same as self.base_search_type
        full_search_type = SearchType.build_search_type(
            self.search_type, project_code)

        visible_rows = self.kwargs.get("visible_rows")
        if visible_rows:
            visible_rows = int(visible_rows)
            num_rows = visible_rows
        else:
            visible_rows = 0

        titles = config.get_element_titles()
        row_count = 0
        for i, element_name in enumerate(element_names):
            attrs = config.get_element_attributes(element_name)
            if i % columns == 0:

                if visible_rows and row_count == visible_rows:
                    tr, td = table.add_row_cell("+ more ...")
                    td.add_class("hand")
                    td.add_class("SPT_DTS")
                    td.add_class("spt_toggle")
                    td.add_style("padding-left: 10px")

                    td.add_behavior({
                        'type':
                        'click_up',
                        'visible_rows':
                        visible_rows,
                        'cbjs_action':
                        '''
                        var top = bvr.src_el.getParent(".spt_simple_search_table");
                        var expand = true;
                        var rows = top.getElements(".spt_simple_search_row");
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            if (row.getStyle("display") == "none") {
                                row.setStyle("display", "");
                            }
                            else {
                                row.setStyle("display", "none");
                                expand = false;
                            }
                        }
                        var spacer = top.getElements(".spt_spacer");
                        var cell = top.getElement(".spt_toggle");
                        if (expand) {
                            spacer.setStyle("height", (rows.length+bvr.visible_rows)*20);
                            cell.innerHTML = "- less ...";
                        }
                        else {
                            spacer.setStyle("height", bvr.visible_rows*20);
                            cell.innerHTML = "+ more ...";
                        }

                        '''
                    })

                tr = table.add_row()
                if visible_rows and row_count >= visible_rows:

                    tr.add_class("spt_simple_search_row")
                    tr.add_style("display: none")
                    tr.add_style("height: 0px")

                row_count += 1

            icon_td = table.add_cell()
            title_td = table.add_cell()
            element_td = table.add_cell()

            # need to add these to all the elements because it is all separated
            # by table tds
            icon_td.add_class("spt_element_item")
            icon_td.add_attr("spt_element_name", element_name)
            title_td.add_class("spt_element_item")
            title_td.add_attr("spt_element_name", element_name)
            element_td.add_class("spt_element_item")
            element_td.add_attr("spt_element_name", element_name)

            # show the title
            title_td.add_style("text-align: left")
            title_td.add_style("padding-right: 5px")
            title_td.add_style("min-width: 60px")

            element_wdg = DivWdg()
            if attrs.get('view') == 'false':
                element_wdg.add_style('display: none')
            element_td.add(element_wdg)

            if i >= 0 and i < columns - 1 and len(element_names) > 1:
                spacer = DivWdg()
                spacer.add_class("spt_spacer")
                spacer.add_style("border-style: solid")
                spacer.add_style("border-width: 0 0 0 0")
                #spacer.add_style("height: %spx" % (num_rows*20))
                spacer.add_style("height: %spx" % (num_rows * 10))
                spacer.add_style("width: 10px")
                spacer.add_style("border-color: %s" %
                                 spacer.get_color("border"))
                spacer.add("&nbsp;")
                td = table.add_cell(spacer)
                td.add_attr("rowspan", tot_rows)

            element_wdg.add_style("padding: 4px 10px 4px 5px")
            element_wdg.add_class("spt_table_search")
            element_wdg.add_style("margin: 1px")
            element_wdg.add_style("min-height: 20px")
            element_wdg.add_style("min-width: 250px")

            # this is done at get_top()
            #element_wdg.add_class("spt_search")
            element_wdg.add(HiddenWdg("prefix", self.prefix))

            display_handler = config.get_display_handler(element_name)
            element_wdg.add(HiddenWdg("handler", display_handler))

            element_wdg.add(HiddenWdg("element_name", element_name))

            from pyasm.widget import ExceptionWdg
            try:
                widget = config.get_display_widget(element_name)
                if widget:
                    widget.set_title(titles[i])

            except Exception as e:
                element_wdg.add(ExceptionWdg(e))
                continue

            if not widget:
                # the default for KeywordFilterElementWdg is mode=keyword
                if not self.column_choice:
                    self.column_choice = self.get_search_col(self.search_type)
                widget = KeywordFilterElementWdg(column=self.column_choice)
                widget.set_name(element_name)

            from pyasm.widget import IconWdg
            icon_div = DivWdg()
            icon_td.add(icon_div)
            icon_div.add_style("width: 20px")
            icon_div.add_style("margin-top: -2px")
            icon_div.add_style("padding-left: 6px")
            icon_div.add_class("spt_filter_top")

            widget.set_show_title(False)
            #element_wdg.add("%s: " % title)
            data = element_data_dict.get(element_name)

            view_panel_keywords = self.kwargs.get("keywords")
            #user data takes precedence over view_panel_keywords
            if isinstance(widget, KeywordFilterElementWdg):
                if view_panel_keywords:
                    widget.set_value("value", view_panel_keywords)
            if data:
                widget.set_values(data)

            if isinstance(
                    widget, KeywordFilterElementWdg
            ) and not full_search_type.startswith('sthpw/sobject_list'):
                widget.set_option('filter_search_type', full_search_type)
            try:
                if attrs.get('view') != 'false':
                    title_td.add(widget.get_title_wdg())

                element_wdg.add(widget.get_buffer_display())
            except Exception as e:
                element_wdg.add(ExceptionWdg(e))
                continue

            icon = IconWdg("Filter Set", "BS_ASTERISK")
            #icon.add_style("color", "#393")
            icon_div.add(icon)
            icon.add_class("spt_filter_set")
            icon.add_class("hand")
            icon.add_attr("spt_element_name", element_name)

            icon.add_behavior({
                'type':
                'click',
                'cbjs_action':
                '''
                var element_name = bvr.src_el.getAttribute("spt_element_name");
                spt.simple_search.clear_element(element_name);
                '''
            })

            if not widget.is_set():
                icon.add_style("display: none")

            else:
                color = icon_div.get_color("background", -10)
                icon_td.add_style("background-color", color)
                title_td.add_style("background-color", color)
                element_td.add_style("background-color", color)

        #elements_wdg.add("<br clear='all'/>")
        top = self.get_top()
        return top
コード例 #13
0
    def get_display(my):

        search_key = my.kwargs.get("search_key")
        msg = None
        base_search_type = SearchKey.extract_search_type(search_key)
        sobject = SearchKey.get_by_search_key(search_key)
        process_div = DivWdg()
        process_div.add_style('padding-top: 10px')

        if base_search_type  in ['sthpw/task', 'sthpw/note']:
            my.process = sobject.get_value('process')
            my.context = sobject.get_value('context')
            if not my.process:
                my.process = ''

            parent = sobject.get_parent()
            if parent:
                search_key = SearchKey.get_by_sobject(parent)
            else:
                msg = "Parent for [%s] not found"%search_key
            
        else:
            my.process = my.kwargs.get('process')

        
        top = my.top
        top.add_class('spt_simple_checkin')
        top.add_color("background", "background")
        top.add_styles("position: relative")

        content = DivWdg(msg)
        top.add(content)
        #content.add_border()
        #content.add_color("background", "background3")
        #content.add_color("color", "background3")
        content.add_style("width: 600px")
        content.add_styles("margin-left: auto; margin-right: auto;")
        content.add_style("height: 200px")

        from tactic.ui.widget import CheckinWdg
        content.add_behavior( {
            'type': 'load',
            'cbjs_action': CheckinWdg.get_onload_js()
        } )


        button_div = DivWdg()
        
        content.add(process_div)

        content.add(button_div)
        button = IconWdg(title="Check-In", icon=IconWdg.CHECK_IN_3D_LG)

        title = Common.get_display_title(my.checkin_action)
        button.add_attr('title', title)


        button_div.add(button)
        button_div.set_box_shadow("1px 1px 1px 1px")
        button_div.add_style("width: 60px")
        button_div.add_style("height: 60px")
        button_div.add_style("float: left")
        button_div.add_style("background: white")
        button_div.add_class("hand")

        button_div.add_style("padding: 2px 3px 0 0")
        button_div.add_style("margin: 20px 60px 20px 200px")
        button_div.add_style("text-align: center")

        button_div.add("Check-in")

        # to be consistent with Check-in New File
        if my.process:
            checkin_process = my.process
        else:
            # Dont' specify, the user can choose later in check-in widget
            checkin_process = ''
        button.add_behavior( {
            'type': 'click_up',
            'search_key': search_key,
            'process': checkin_process,
            'context': my.context,
            'cbjs_action': '''
            var class_name = 'tactic.ui.widget.CheckinWdg';
            var applet = spt.Applet.get();


            spt.app_busy.show("Choose file(s) to check in")


            var current_dir = null;
            var is_sandbox = false;
            var refresh = false
            var values = spt.checkin.browse_folder(current_dir, is_sandbox, refresh);
            if (!values) {
                spt.app_busy.hide();
                return;
            }

            var file_paths = values.file_paths;
            if (file_paths.length == 0) {
                spt.alert("You need to select files(s) to check in.");
                spt.app_busy.hide();
                return;
            }

            spt.app_busy.hide();

            var args = {
                'search_key': bvr.search_key,
                'show_links': false,
                'show_history': false,
                'close_on_publish': true
            }
            if (bvr.process) args.process = bvr.process;
            if (bvr.context) args.context = bvr.context;

            var kwargs = {};
            kwargs.values = values;
            spt.panel.load_popup("Check-in", class_name, args, kwargs);

            /*
            var options=  {
                title: "Check-in Widget",
                class_name: 'tactic.ui.widget.CheckinWdg',
                popup_id: 'checkin_widget'
            };
            var bvr2 = {};
            bvr2.options = options;
            bvr2.values = values;
            bvr2.args = args;
            spt.popup.get_widget({}, bvr2)

            */

            '''
        } )


        button_div = DivWdg()
        content.add(button_div)
        button = IconWdg(title="Check-Out", icon=IconWdg.CHECK_OUT_3D_LG)
        button_div.add(button)
        button_div.set_box_shadow("1px 1px 1px 1px")
        button_div.add_style("width: 60px")
        button_div.add_style("height: 60px")
        button_div.add_style("float: left")
        button_div.add_style("margin: 20px")
        button_div.add_style("padding: 2px 3px 0 0")
        button_div.add_style("background: white")
        button_div.add_class("hand")

        button_div.add_style("text-align: center")
        button_div.add("Check-out")

       
        sobject = SearchKey.get_by_search_key(search_key)

        # snapshot is retrieved for getting the process informatoin, they are not being used
        # for loading as real_time snapshot query option is used. 
        search = Search("sthpw/snapshot")
        search.add_sobject_filter(sobject)
        if my.process:
            search.add_filter("process", my.process)
        search.add_filter("is_latest", True)
        snapshot = search.get_sobject()

        if not my.process and snapshot:
            my.process = snapshot.get_value('process')
            # for old process-less snapshots
            if not my.process:
                my.process = snapshot.get_value('context')

        process_wdg = DivWdg(HtmlElement.b(checkin_process))
        if checkin_process:
            width = len(checkin_process)*10
        else:
            width = 10
        process_wdg.add_styles('margin-left: auto; margin-right: auto; text-align: center; width: %s'%width)
        process_div.add(process_wdg)
        # DO NOT pass in snapshot_code, get it in real time

        snapshot_codes = []
   
        show_status = True
        if my.checkout_action == 'latest':
            cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status)
            bvr = {'snapshot_codes': snapshot_codes,
                    'real_time': True,
                    'file_types': ['main'],
                    'filename_mode': 'repo',
                    'cbjs_action': cbjs_action}

        elif my.checkout_action == 'latest (version_omitted)':
            cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status)
            bvr = {'snapshot_codes':snapshot_codes,
                    'real_time': True,
                    'file_types': ['main'],
                    'filename_mode': 'versionless',
                    'cbjs_action': cbjs_action}

        elif my.checkout_action == 'latest versionless':
            cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status)
            bvr = {'snapshot_codes':snapshot_codes,
                    'real_time': True,
                    'versionless': True,
                    'file_types': ['main'],
                    'filename_mode': 'versionless',
                    'cbjs_action': cbjs_action}
       
        elif my.checkout_action == 'open file browser':
            bvr =  {
           
            'cbjs_action': '''
            var class_name = 'tactic.ui.checkin.SObjectDirListWdg';
            var kwargs = {
                search_keys: [bvr.search_key],
                process: '%s' 
            };
            spt.panel.load_popup("Check-out", class_name, kwargs);
            '''%my.process
            }
        bvr.update({ 'type': 'click_up', 'search_key': search_key})
        button.add_behavior(bvr)
        title = Common.get_display_title(my.checkout_action)
        button.add_attr('title', title)


        
        #TODO: remove these margin-top which is used to compensate all the ButtonNewWdg top extra white space
        
        content.add("<br clear='all'/>")
        status_div = DivWdg()
        status_div.add_style('margin: 20px 0 0 10px')
        status_div.add_style('width: 100%')
        text_info = FloatDivWdg()
        text_info.add_styles('padding: 4px; width: 500px')
        text_info.add_style('margin-top: 8px')
        text_info.add_attr('title','Displays the last checked out file path')

        text_info.add_border()
        text_info.set_round_corners()

        text_content = DivWdg()
        text_content.add('&nbsp;')
        text_content.add_class('spt_status_area')

        text_info.add(text_content)
        label = FloatDivWdg('path:')
        label.add_style('margin: 12px 6px 0 6px')

        # button
        button = ButtonNewWdg(title="Explore", icon=IconWdg.FOLDER_GO)
        button.add_style('padding-bottom: 15px')
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
            var applet = spt.Applet.get();
            var status_div = bvr.src_el.getParent('.spt_simple_checkin').getElement('.spt_status_area');
            var value = status_div.get('text');

            var dir_name = spt.path.get_dirname(value);
            if (dir_name)
                applet.open_explorer(dir_name);
        '''
        } )

        status_div.add(label)
        status_div.add(text_info)
        content.add(status_div)
        content.add(button)
    

        content.add_behavior({'type':'load',
            'cbjs_action': ''' 
            
            if (!spt.Applet.applet) {
                spt.api.app_busy_show('Initializing Java', 'Please wait...');
                var exec = function() {var applet = spt.Applet.get()};
                spt.api.app_busy_hide(exec);
            }'''})
        
        return top
コード例 #14
0
ファイル: db_resource_wdg.py プロジェクト: mincau/TACTIC
    def get_tables_wdg(self):
        
        div = DivWdg()
        div.set_name("Tables")

        div.add("In order to fully register a database, you must bind it to a TACTIC project")
        div.add("<br/>")



        project_code = "mongodb"
        database = "test_database"

        db_resource = DbResource(
                server='localhost',
                vendor='MongoDb',
                database=database
        )


        try:
            connect = DbContainer.get(db_resource)
        except Exception as e:
            div.add("Could not connect")
            div.add_style("padding: 30px")
            div.add("<br/>"*2)
            div.add(str(e))
            return div



        # Bind project to this resource
        database_text = TextWdg("database")
        div.add("Database: ")
        div.add(database_text)

        div.add("<br/>"*2)

        project_text = TextWdg("project")
        div.add("Project Code: ")
        div.add(project_text)

        div.add("<br/>")
        div.add("<hr/>")



        # connect and introspect the tables in this database
        tables = connect.get_tables()


        table = Table()
        div.add(table)
        table.set_max_width()

        for table_name in tables:
            table.add_row()
            search_type = "table/%s?project=%s" % (table_name, project_code)

            td = table.add_cell()
            icon = IconWdg("View Table", IconWdg.FOLDER_GO)
            td.add(icon)
            icon.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'cbjs_action': '''
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type
                }
                spt.panel.load_popup("table", class_name, kwargs);
                '''
            } )


            td = table.add_cell()
            td.add(table_name)

            td = table.add_cell()
            search = Search(search_type)
            count = search.get_count()
            td.add(" %s item/s" % count)

            columns = search.get_columns()
            td = table.add_cell()
            td.add(columns)

            # search_type
            td = table.add_cell()
            text = TextWdg("search_type")
            td.add(text)
            new_search_type = "%s/%s" % (project_code, table_name)
            text.set_value(new_search_type)



        register_div = DivWdg()
        div.add(register_div)
        register_div.add_style("padding: 20px")

        button = ActionButtonWdg(title="Register")
        register_div.add(button)


        return div
コード例 #15
0
ファイル: simple_search_wdg.py プロジェクト: mincau/TACTIC
    def get_display(self):

        element_data_dict = {}

        config = self.get_config()
        element_names = config.get_element_names()

        content_wdg = DivWdg()
        content_wdg.add_class("spt_simple_search_top")

        onload_js = DivWdg()
        content_wdg.add(onload_js)
        onload_js.add_behavior( {
            'type': 'load',
            'cbjs_action': self.get_onload_js()
        } )




        if not element_names:
            element_names = ['keywords']

        self.set_content(content_wdg)

        
        # this is somewhat duplicated logic from alter_search, but since this is called 
        # in ViewPanelWdg, it's a diff instance and needs to retrieve again
        filter_data = FilterData.get()

        filter_view = self.kwargs.get("filter_view")
        if filter_view:
            search = Search("config/widget_config")
            search.add_filter("view", filter_view)
            search.add_filter("category", "search_filter")
            search.add_filter("search_type", self.search_type)
            filter_config = search.get_sobject()
            if filter_config:
                filter_xml = filter_config.get_xml_value("config")
                filter_value = filter_xml.get_value("config/filter/values")
                if filter_value:
                    data_list = jsonloads(filter_value)

        else:
            data_list = filter_data.get_values_by_prefix(self.prefix)



        for data in data_list:
            handler = data.get("handler")
            element_name = data.get("element_name")
            if not element_name:
                continue

            element_data_dict[element_name] = data

        elements_wdg = DivWdg()
        content_wdg.add(elements_wdg)
        elements_wdg.add_color("color", "color")
        elements_wdg.add_style("padding-top: 10px")
        elements_wdg.add_style("padding-bottom: 15px")

        #elements_wdg.add_color("background", "background3", 0)
        elements_wdg.add_color("background", "background", -3)
        elements_wdg.add_border()



        if len(element_names) == 1:
            elements_wdg.add_style("border-width: 0px 0px 0px 0px" )
            elements_wdg.add_style("padding-right: 50px" )
        else:
            elements_wdg.add_style("border-width: 0px 0px 0px 0px" )

        table = Table()
        table.add_color("color", "color")
        elements_wdg.add(table)
        table.add_class("spt_simple_search_table")
        
        columns = self.kwargs.get("columns")
        if not columns:
            columns = 2
        else:
            columns = int(columns) 
       
        num_rows = int(len(element_names)/columns)+1
        tot_rows = int(len(element_names)/columns)+1
        project_code = Project.get_project_code()
        # self.search_type could be the same as self.base_search_type
        full_search_type = SearchType.build_search_type(self.search_type, project_code)


        visible_rows = self.kwargs.get("visible_rows")
        if visible_rows:
            visible_rows = int(visible_rows)
            num_rows = visible_rows
        else:
            visible_rows = 0

        titles = config.get_element_titles() 
        row_count = 0
        for i, element_name in enumerate(element_names):
            attrs = config.get_element_attributes(element_name)
            if i % columns == 0:

                if visible_rows and row_count == visible_rows:
                    tr, td = table.add_row_cell("+ more ...")
                    td.add_class("hand")
                    td.add_class("SPT_DTS")
                    td.add_class("spt_toggle")
                    td.add_style("padding-left: 10px")

                    td.add_behavior( {
                        'type': 'click_up',
                        'visible_rows': visible_rows,
                        'cbjs_action': '''
                        var top = bvr.src_el.getParent(".spt_simple_search_table");
                        var expand = true;
                        var rows = top.getElements(".spt_simple_search_row");
                        for (var i = 0; i < rows.length; i++) {
                            var row = rows[i];
                            if (row.getStyle("display") == "none") {
                                row.setStyle("display", "");
                            }
                            else {
                                row.setStyle("display", "none");
                                expand = false;
                            }
                        }
                        var spacer = top.getElements(".spt_spacer");
                        var cell = top.getElement(".spt_toggle");
                        if (expand) {
                            spacer.setStyle("height", (rows.length+bvr.visible_rows)*20);
                            cell.innerHTML = "- less ...";
                        }
                        else {
                            spacer.setStyle("height", bvr.visible_rows*20);
                            cell.innerHTML = "+ more ...";
                        }

                        '''
                    } )


                tr = table.add_row()
                if visible_rows and row_count >= visible_rows:

                    tr.add_class("spt_simple_search_row")
                    tr.add_style("display: none")
                    tr.add_style("height: 0px")

                row_count += 1

            icon_td = table.add_cell()
            title_td = table.add_cell()
            element_td = table.add_cell()

            # need to add these to all the elements because it is all separated
            # by table tds
            icon_td.add_class("spt_element_item")
            icon_td.add_attr("spt_element_name", element_name)
            title_td.add_class("spt_element_item")
            title_td.add_attr("spt_element_name", element_name)
            element_td.add_class("spt_element_item")
            element_td.add_attr("spt_element_name", element_name)

            # show the title
            title_td.add_style("text-align: left")
            title_td.add_style("padding-right: 5px")
            title_td.add_style("min-width: 60px")



            element_wdg = DivWdg()
            if attrs.get('view') == 'false':
                element_wdg.add_style('display: none')
            element_td.add(element_wdg)



            if i >= 0  and i < columns -1 and len(element_names) > 1:
                spacer = DivWdg()
                spacer.add_class("spt_spacer")
                spacer.add_style("border-style: solid")
                spacer.add_style("border-width: 0 0 0 0")
                #spacer.add_style("height: %spx" % (num_rows*20))
                spacer.add_style("height: %spx" % (num_rows*10))
                spacer.add_style("width: 10px")
                spacer.add_style("border-color: %s" % spacer.get_color("border") )
                spacer.add("&nbsp;")
                td = table.add_cell(spacer)
                td.add_attr("rowspan", tot_rows)

            element_wdg.add_style("padding: 4px 10px 4px 5px")
            element_wdg.add_class("spt_table_search")
            element_wdg.add_style("margin: 1px")
            element_wdg.add_style("min-height: 20px")
            element_wdg.add_style("min-width: 250px")

            # this is done at get_top()
            #element_wdg.add_class("spt_search")
            element_wdg.add( HiddenWdg("prefix", self.prefix))

            display_handler = config.get_display_handler(element_name)
            element_wdg.add( HiddenWdg("handler", display_handler))


            element_wdg.add( HiddenWdg("element_name", element_name))
        

            from pyasm.widget import ExceptionWdg
            try:
                widget = config.get_display_widget(element_name)
                if widget:
                    widget.set_title(titles[i])

            except Exception as e:
                element_wdg.add(ExceptionWdg(e))
                continue


            if not widget:
                # the default for KeywordFilterElementWdg is mode=keyword
                if not self.column_choice:
                    self.column_choice = self.get_search_col(self.search_type)
                widget = KeywordFilterElementWdg(column=self.column_choice)
                widget.set_name(element_name)
                


            from pyasm.widget import IconWdg
            icon_div = DivWdg()
            icon_td.add(icon_div)
            icon_div.add_style("width: 20px")
            icon_div.add_style("margin-top: -2px")
            icon_div.add_style("padding-left: 6px")
            icon_div.add_class("spt_filter_top")


            widget.set_show_title(False)
            #element_wdg.add("%s: " % title)
            data = element_data_dict.get(element_name)

			
            view_panel_keywords = self.kwargs.get("keywords")
            #user data takes precedence over view_panel_keywords
            if isinstance(widget, KeywordFilterElementWdg):
                if view_panel_keywords:
                    widget.set_value("value", view_panel_keywords)
            if data:
                widget.set_values(data)

                
           
			    
                    

            if isinstance(widget, KeywordFilterElementWdg) and not full_search_type.startswith('sthpw/sobject_list'):
                widget.set_option('filter_search_type', full_search_type)
            try:
                if attrs.get('view') != 'false':
                    title_td.add(widget.get_title_wdg())

                element_wdg.add(widget.get_buffer_display())
            except Exception as e:
                element_wdg.add(ExceptionWdg(e))
                continue
                


            icon = IconWdg("Filter Set", "BS_ASTERISK")
            #icon.add_style("color", "#393")
            icon_div.add(icon)
            icon.add_class("spt_filter_set")
            icon.add_class("hand")
            icon.add_attr("spt_element_name", element_name)

            icon.add_behavior( {
                'type': 'click',
                'cbjs_action': '''
                var element_name = bvr.src_el.getAttribute("spt_element_name");
                spt.simple_search.clear_element(element_name);
                '''

            } )

            if not widget.is_set():
                icon.add_style("display: none")

            else:
                color = icon_div.get_color("background", -10)
                icon_td.add_style("background-color", color)
                title_td.add_style("background-color", color)
                element_td.add_style("background-color", color)



        #elements_wdg.add("<br clear='all'/>")
        top = self.get_top()
        return top