<commit_before>###########################################################
#
# Copyright (c) 2009, Southpaw Technology
#                     All Rights Reserved
#
# PROPRIETARY INFORMATION.  This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ["ToolLayoutWdg","CustomLayoutWithSearchWdg", "CustomItemLayoutWithSearchWdg","RepoBrowserLayoutWdg","CardLayoutWdg"]

from pyasm.common import Common
from pyasm.search import Search, SearchKey
from pyasm.web import DivWdg, Table
from pyasm.widget import ThumbWdg, IconWdg
from tactic.ui.container import SmartMenu

from table_layout_wdg import FastTableLayoutWdg
from tactic.ui.widget import IconButtonWdg, SingleButtonWdg

class ToolLayoutWdg(FastTableLayoutWdg):

    ARGS_KEYS = {
        "search_type": {
            'description': "search type that this panels works with",
            'type': 'TextWdg',
            'order': 0,
            'category': 'Required'
        },
    } 


    def can_inline_insert(my):
        return False

    def can_save(my):
        return False

    def can_expand(my):
        return False

    def can_add_columns(my):
        return False

    def can_select(my):
        return False





    def get_display(my):

        my.view_editable = True

        if my.kwargs.get("do_search") != "false":
            my.handle_search()

        #my.kwargs['show_gear'] = 'false'


        # set the sobjects to all the widgets then preprocess
        for widget in my.widgets:
            widget.set_sobjects(my.sobjects)
            widget.set_parent_wdg(my)
            # preprocess the elements
            widget.preprocess()


        """
        # TEST code to return only the content
        temp = my.kwargs.get("temp")
        if temp:
            content = DivWdg()
            content.add( my.get_content_wdg() )
            return content
        """





        # extraneous variables inherited from TableLayoutWdg
        my.edit_permission = True

        top = DivWdg()
        my.set_as_panel(top)
        top.add_class("spt_sobject_top")

        inner = DivWdg()
        top.add(inner)
        inner.add_color("background", "background")
        inner.add_color("color", "color")
        inner.add_class("spt_table")
        inner.add_class("spt_layout")
        inner.add_attr("spt_version", "2")


        from tactic.ui.input import Html5UploadWdg
        upload_wdg = Html5UploadWdg()
        inner.add(upload_wdg)
        my.upload_id = upload_wdg.get_upload_id()

        # set up the context menus
        menus_in = {
            'DG_HEADER_CTX': [ my.get_smart_header_context_menu_data() ],
            'DG_DROW_SMENU_CTX': [ my.get_data_row_smart_context_menu_details() ]
        }
        SmartMenu.attach_smart_context_menu( inner, menus_in, False )


        thumb = ThumbWdg()
        thumb.handle_layout_behaviors(inner)

        is_refresh = my.kwargs.get("is_refresh")
        if my.kwargs.get("show_shelf") not in ['false', False]:
            action = my.get_action_wdg()
            inner.add(action)

        content = DivWdg()
        inner.add( content )
        content.add( my.get_content_wdg() )


        # NOTE: a lot of scaffolding to convince that search_cbk that this
        # is a proper layout
        top.add_class("spt_table_top");
        class_name = Common.get_full_class_name(my)
        top.add_attr("spt_class_name", class_name)


        # NOTE: adding a fake header to conform to a table layout.  Not
        # sure if this is the correct interface for this
        header_row_div = DivWdg()
        header_row_div.add_class("spt_table_header_row")
        content.add(header_row_div)
        content.add_class("spt_table_table")
        content.set_id(my.table_id)

        my.handle_load_behaviors(content)


        inner.add_class("spt_table_content");
        inner.add_attr("spt_search_type", my.kwargs.get('search_type'))
        inner.add_attr("spt_view", my.kwargs.get('view'))


        limit_span = DivWdg()
        inner.add(limit_span)
        limit_span.add_style("margin-top: 4px")
        limit_span.add_class("spt_table_search")
        limit_span.add_style("width: 250px")
        limit_span.add_style("margin: 5 auto")

        info = my.search_limit.get_info()
        if info.get("count") == None:
            info["count"] = len(my.sobjects)


        from tactic.ui.app import SearchLimitSimpleWdg
        limit_wdg = SearchLimitSimpleWdg(
            count=info.get("count"),
            search_limit=info.get("search_limit"),
            current_offset=info.get("current_offset"),
        )
        inner.add(limit_wdg)


        my.add_layout_behaviors(inner)

        if my.kwargs.get("is_refresh") == 'true':
            return inner
        else:
            return top


    def add_layout_behaviors(my, layout_wdg):

        layout_wdg.add_relay_behavior( {
            'type': 'click',
            'bvr_match_class': 'spt_item_content',
            'cbjs_action': '''
            spt.tab.set_main_body_tab();
            var top = bvr.src_el.getParent(".spt_item_top");
            var search_key = top.getAttribute("spt_search_key");
            var name = top.getAttribute("spt_name");
            var search_code = top.getAttribute("spt_search_code");
            var class_name = 'tactic.ui.tools.SObjectDetailWdg'
            var kwargs = {
                search_key: search_key
            }
            spt.tab.add_new(search_code, name, class_name, kwargs);
            '''
        } )

        main_bg1 = layout_wdg.get_color("background")
        main_bg2 = layout_wdg.get_color("background", 5)

        bg1 = layout_wdg.get_color("background3")
        bg2 = layout_wdg.get_color("background3", 5)
        layout_wdg.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_item_top',
            'cbjs_action': '''
            bvr.src_el.setStyle('background', '%s');
            var el = bvr.src_el.getElement(".spt_tile_title");
            if (el) {
                el.setStyle("background", "%s");
            }
            ''' % (main_bg2, bg2)
        } )

        layout_wdg.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_item_top',
            'cbjs_action': '''
            bvr.src_el.setStyle('background', '%s');
            var el = bvr.src_el.getElement(".spt_tile_title");
            if (el) {
                el.setStyle("background", "%s");
            }
            ''' %(main_bg1, bg1)
        } )





    def get_content_wdg(my):

        div = DivWdg()
        div.add_class("spt_tool_top")

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

        td = table.add_cell()
        from table_layout_wdg import FastTableLayoutWdg

        kwargs = my.kwargs.copy()


        td.add_style("width: 1%")
        td.add_style("vertical-align: top")
        layout_div = DivWdg()
        layout_div.add_style("min-height: 500px")
        td.add(layout_div)

        my.kwargs['element_names'] = ['name','description','detail', 'file_list','general_checkin']
        my.kwargs['show_shelf'] = False
        layout = FastTableLayoutWdg(**my.kwargs)
        layout_div.add(layout)


        td = table.add_cell()
        td.add_border()
        td.add_style("vertical-align: top")

        content = DivWdg()
        td.add(content)
        content.add_class("spt_tool_content")
        #content.add_style("margin: -1px")


        no_content_wdg = DivWdg()
        content.add(no_content_wdg)
        no_content_wdg.add("<br/>"*3)
        no_content_wdg.add("<i>-- No Content --</i>")
        #no_content_wdg.add_style("opacity: 0.5")
        no_content_wdg.add_style("margin: 30px auto")
        no_content_wdg.add_color("color", "color3")
        no_content_wdg.add_color("background", "background3")
        no_content_wdg.add_style("text-align", "center")
        no_content_wdg.add_style("padding-top: 20px")
        no_content_wdg.add_style("padding-bottom: 20px")
        no_content_wdg.add_style("width: 350px")
        no_content_wdg.add_style("height: 110px")
        no_content_wdg.add_border()


        return div







from custom_layout_wdg import CustomLayoutWdg
class CustomLayoutWithSearchWdg(ToolLayoutWdg):

    ARGS_KEYS = CustomLayoutWdg.ARGS_KEYS.copy()
    ARGS_KEYS['search_type'] = 'search type of the sobject to be displayed'

    def get_content_wdg(my):
        kwargs = my.kwargs.copy()
        layout = CustomLayoutWdg(**kwargs)
        layout.set_sobjects(my.sobjects)
        return layout





class CustomItemLayoutWithSearchWdg(ToolLayoutWdg):

    ARGS_KEYS = CustomLayoutWdg.ARGS_KEYS.copy()
    ARGS_KEYS['search_type'] = 'search type of the sobject to be displayed'

    def get_content_wdg(my):
        div = DivWdg()
        for sobject in my.sobjects:
            kwargs = my.kwargs.copy()
            layout = CustomLayoutWdg(**kwargs)
            layout.set_sobjects(my.sobjects)
            layout.set_sobject(sobject)
            div.add(layout)
        return div





class RepoBrowserLayoutWdg(ToolLayoutWdg):

    ARGS_KEYS = CustomLayoutWdg.ARGS_KEYS.copy()
    ARGS_KEYS['search_type'] = 'search type of the sobject to be displayed'

    def get_content_wdg(my):
        from tactic.ui.tools import RepoBrowserWdg
        kwargs = my.kwargs.copy()
        kwargs['open_depth'] = 1
        layout = RepoBrowserWdg(**kwargs)
        layout.set_sobjects(my.sobjects)
        return layout



<commit_msg>BRANCH 4.1: added a break clear=all for CustomItemLayouts to allow for <div> that are float left<commit_after>###########################################################
#
# Copyright (c) 2009, Southpaw Technology
#                     All Rights Reserved
#
# PROPRIETARY INFORMATION.  This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ["ToolLayoutWdg","CustomLayoutWithSearchWdg", "CustomItemLayoutWithSearchWdg","RepoBrowserLayoutWdg","CardLayoutWdg"]

from pyasm.common import Common
from pyasm.search import Search, SearchKey
from pyasm.web import DivWdg, Table
from pyasm.widget import ThumbWdg, IconWdg
from tactic.ui.container import SmartMenu

from table_layout_wdg import FastTableLayoutWdg
from tactic.ui.widget import IconButtonWdg, SingleButtonWdg

class ToolLayoutWdg(FastTableLayoutWdg):

    ARGS_KEYS = {
        "search_type": {
            'description': "search type that this panels works with",
            'type': 'TextWdg',
            'order': 0,
            'category': 'Required'
        },
    } 


    def can_inline_insert(my):
        return False

    def can_save(my):
        return False

    def can_expand(my):
        return False

    def can_add_columns(my):
        return False

    def can_select(my):
        return False





    def get_display(my):

        my.view_editable = True

        if my.kwargs.get("do_search") != "false":
            my.handle_search()

        #my.kwargs['show_gear'] = 'false'


        # set the sobjects to all the widgets then preprocess
        for widget in my.widgets:
            widget.set_sobjects(my.sobjects)
            widget.set_parent_wdg(my)
            # preprocess the elements
            widget.preprocess()


        """
        # TEST code to return only the content
        temp = my.kwargs.get("temp")
        if temp:
            content = DivWdg()
            content.add( my.get_content_wdg() )
            return content
        """





        # extraneous variables inherited from TableLayoutWdg
        my.edit_permission = True

        top = DivWdg()
        my.set_as_panel(top)
        top.add_class("spt_sobject_top")

        inner = DivWdg()
        top.add(inner)
        inner.add_color("background", "background")
        inner.add_color("color", "color")
        inner.add_class("spt_table")
        inner.add_class("spt_layout")
        inner.add_attr("spt_version", "2")


        from tactic.ui.input import Html5UploadWdg
        upload_wdg = Html5UploadWdg()
        inner.add(upload_wdg)
        my.upload_id = upload_wdg.get_upload_id()

        # set up the context menus
        menus_in = {
            'DG_HEADER_CTX': [ my.get_smart_header_context_menu_data() ],
            'DG_DROW_SMENU_CTX': [ my.get_data_row_smart_context_menu_details() ]
        }
        SmartMenu.attach_smart_context_menu( inner, menus_in, False )


        thumb = ThumbWdg()
        thumb.handle_layout_behaviors(inner)

        is_refresh = my.kwargs.get("is_refresh")
        if my.kwargs.get("show_shelf") not in ['false', False]:
            action = my.get_action_wdg()
            inner.add(action)

        content = DivWdg()
        inner.add( content )
        content.add( my.get_content_wdg() )


        # NOTE: a lot of scaffolding to convince that search_cbk that this
        # is a proper layout
        top.add_class("spt_table_top");
        class_name = Common.get_full_class_name(my)
        top.add_attr("spt_class_name", class_name)


        # NOTE: adding a fake header to conform to a table layout.  Not
        # sure if this is the correct interface for this
        header_row_div = DivWdg()
        header_row_div.add_class("spt_table_header_row")
        content.add(header_row_div)
        content.add_class("spt_table_table")
        content.set_id(my.table_id)

        my.handle_load_behaviors(content)


        inner.add_class("spt_table_content");
        inner.add_attr("spt_search_type", my.kwargs.get('search_type'))
        inner.add_attr("spt_view", my.kwargs.get('view'))


        limit_span = DivWdg()
        inner.add(limit_span)
        limit_span.add_style("margin-top: 4px")
        limit_span.add_class("spt_table_search")
        limit_span.add_style("width: 250px")
        limit_span.add_style("margin: 5 auto")

        info = my.search_limit.get_info()
        if info.get("count") == None:
            info["count"] = len(my.sobjects)


        from tactic.ui.app import SearchLimitSimpleWdg
        limit_wdg = SearchLimitSimpleWdg(
            count=info.get("count"),
            search_limit=info.get("search_limit"),
            current_offset=info.get("current_offset"),
        )
        inner.add(limit_wdg)


        my.add_layout_behaviors(inner)

        if my.kwargs.get("is_refresh") == 'true':
            return inner
        else:
            return top


    def add_layout_behaviors(my, layout_wdg):

        layout_wdg.add_relay_behavior( {
            'type': 'click',
            'bvr_match_class': 'spt_item_content',
            'cbjs_action': '''
            spt.tab.set_main_body_tab();
            var top = bvr.src_el.getParent(".spt_item_top");
            var search_key = top.getAttribute("spt_search_key");
            var name = top.getAttribute("spt_name");
            var search_code = top.getAttribute("spt_search_code");
            var class_name = 'tactic.ui.tools.SObjectDetailWdg'
            var kwargs = {
                search_key: search_key
            }
            spt.tab.add_new(search_code, name, class_name, kwargs);
            '''
        } )

        main_bg1 = layout_wdg.get_color("background")
        main_bg2 = layout_wdg.get_color("background", 5)

        bg1 = layout_wdg.get_color("background3")
        bg2 = layout_wdg.get_color("background3", 5)
        layout_wdg.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_item_top',
            'cbjs_action': '''
            bvr.src_el.setStyle('background', '%s');
            var el = bvr.src_el.getElement(".spt_tile_title");
            if (el) {
                el.setStyle("background", "%s");
            }
            ''' % (main_bg2, bg2)
        } )

        layout_wdg.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_item_top',
            'cbjs_action': '''
            bvr.src_el.setStyle('background', '%s');
            var el = bvr.src_el.getElement(".spt_tile_title");
            if (el) {
                el.setStyle("background", "%s");
            }
            ''' %(main_bg1, bg1)
        } )





    def get_content_wdg(my):

        div = DivWdg()
        div.add_class("spt_tool_top")

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

        td = table.add_cell()
        from table_layout_wdg import FastTableLayoutWdg

        kwargs = my.kwargs.copy()


        td.add_style("width: 1%")
        td.add_style("vertical-align: top")
        layout_div = DivWdg()
        layout_div.add_style("min-height: 500px")
        td.add(layout_div)

        my.kwargs['element_names'] = ['name','description','detail', 'file_list','general_checkin']
        my.kwargs['show_shelf'] = False
        layout = FastTableLayoutWdg(**my.kwargs)
        layout_div.add(layout)


        td = table.add_cell()
        td.add_border()
        td.add_style("vertical-align: top")

        content = DivWdg()
        td.add(content)
        content.add_class("spt_tool_content")
        #content.add_style("margin: -1px")


        no_content_wdg = DivWdg()
        content.add(no_content_wdg)
        no_content_wdg.add("<br/>"*3)
        no_content_wdg.add("<i>-- No Content --</i>")
        #no_content_wdg.add_style("opacity: 0.5")
        no_content_wdg.add_style("margin: 30px auto")
        no_content_wdg.add_color("color", "color3")
        no_content_wdg.add_color("background", "background3")
        no_content_wdg.add_style("text-align", "center")
        no_content_wdg.add_style("padding-top: 20px")
        no_content_wdg.add_style("padding-bottom: 20px")
        no_content_wdg.add_style("width: 350px")
        no_content_wdg.add_style("height: 110px")
        no_content_wdg.add_border()


        return div







from custom_layout_wdg import CustomLayoutWdg
class CustomLayoutWithSearchWdg(ToolLayoutWdg):

    ARGS_KEYS = CustomLayoutWdg.ARGS_KEYS.copy()
    ARGS_KEYS['search_type'] = 'search type of the sobject to be displayed'

    def get_content_wdg(my):
        kwargs = my.kwargs.copy()
        layout = CustomLayoutWdg(**kwargs)
        layout.set_sobjects(my.sobjects)
        return layout





class CustomItemLayoutWithSearchWdg(ToolLayoutWdg):

    ARGS_KEYS = CustomLayoutWdg.ARGS_KEYS.copy()
    ARGS_KEYS['search_type'] = 'search type of the sobject to be displayed'

    def get_content_wdg(my):
        div = DivWdg()
        for sobject in my.sobjects:
            kwargs = my.kwargs.copy()
            layout = CustomLayoutWdg(**kwargs)
            layout.set_sobjects(my.sobjects)
            layout.set_sobject(sobject)
            div.add(layout)
        div.add("<br clear='all'/>")
        return div





class RepoBrowserLayoutWdg(ToolLayoutWdg):

    ARGS_KEYS = CustomLayoutWdg.ARGS_KEYS.copy()
    ARGS_KEYS['search_type'] = 'search type of the sobject to be displayed'

    def get_content_wdg(my):
        from tactic.ui.tools import RepoBrowserWdg
        kwargs = my.kwargs.copy()
        kwargs['open_depth'] = 1
        layout = RepoBrowserWdg(**kwargs)
        layout.set_sobjects(my.sobjects)
        return layout




{'fraction_non_alphanumeric': 0.1155403301152289, 'fraction_numerical': 0.005086681200041524, 'mean_word_length': 2.34090514999133, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2542535', 'n_tokens_mistral': 6390, 'n_tokens_neox': 6009, 'n_words': 1103}