Пример #1
0
    def alter_search(self, search=None):

        if not search:
            search = self.search
            if self.limit:
                try:
                    limit = int(self.limit)
                except ValueError:
                    limit = 50
            else:
                limit = 50
            if limit > 0:
                search.set_limit(limit)
       

        # if a parent key was added
        parent_key = self.kwargs.get('parent_key')
        if parent_key:
            parent = Search.get_by_search_key(parent_key)
            search.add_parent_filter(parent)

        self.state = self.kwargs.get('state')
        self.state = BaseRefreshWdg.process_state(self.state)
        
        if self.state:
            parent_type = self.state.get('parent_type')
            if parent_type:
                search.add_filter("search_type", parent_type)


            

        filter_data = FilterData.get()
        data = filter_data.get_data()
        filter_mode = None
        prefix = "filter_mode"
        if self.prefix_namespace:
            prefix = '%s_%s' %(self.prefix_namespace, prefix)
        values = FilterData.get().get_values_by_index(prefix, 0)
        
        if values:
            filter_mode = values.get('filter_mode')
        if not filter_mode:
            filter_mode = 'and'

        # handle the showing of retired
        show_retired = False
        search.set_show_retired(show_retired)

        # add all the filters
        for filter in self.filters:
            filter.set_filter_mode(filter_mode)
            filter.set_state(self.state)
            filter.alter_search(search)

            self.num_filters_enabled += filter.get_num_filters_enabled()
Пример #2
0
    def alter_search(my, search=None):

        if not search:
            search = my.search
            if my.limit:
                try:
                    limit = int(my.limit)
                except ValueError:
                    limit = 50
            else:
                limit = 50
            if limit > 0:
                search.set_limit(limit)
       

        # if a parent key was added
        parent_key = my.kwargs.get('parent_key')
        if parent_key:
            parent = Search.get_by_search_key(parent_key)
            search.add_parent_filter(parent)

        my.state = my.kwargs.get('state')
        my.state = BaseRefreshWdg.process_state(my.state)
        
        if my.state:
            parent_type = my.state.get('parent_type')
            if parent_type:
                search.add_filter("search_type", parent_type)


            

        filter_data = FilterData.get()
        data = filter_data.get_data()
        filter_mode = None
        prefix = "filter_mode"
        if my.prefix_namespace:
            prefix = '%s_%s' %(my.prefix_namespace, prefix)
        values = FilterData.get().get_values_by_index(prefix, 0)
        
        if values:
            filter_mode = values.get('filter_mode')
        if not filter_mode:
            filter_mode = 'and'

        # handle the showing of retired
        show_retired = False
        search.set_show_retired(show_retired)

        # add all the filters
        for filter in my.filters:
            filter.set_filter_mode(filter_mode)
            filter.set_state(my.state)
            filter.alter_search(search)

            my.num_filters_enabled += filter.get_num_filters_enabled()
Пример #3
0
    def get_process(my):
        '''Get from the ProcessFilterWdg in SObjectLoadWdg,
            otherwise get from FilterData'''

        process = ''

        # Ususally there is no pipeline defined for prod/shot_instance
        # so get from prod/shot
        search_type = my.search_type
        if search_type =='prod/shot_instance':
            search_type = 'prod/shot'

        state = Container.get("global_state")
        if state:
            process = state.get('process')
        else:
            
            # get it from FilterData
            data = FilterData.get()
            values = data.get_values_by_prefix('view_action_option')
            if values:
                process = values[0].get('load_%s_process' %search_type)

        if not process:
            from pyasm.prod.web import ProcessFilterWdg
            process_filter = ProcessFilterWdg(None, search_type)
            process = process_filter.get_value()
        return process
Пример #4
0
    def execute(my):
        my.init()

        # create the filters
        my.filters = []
        """
        for element_name in my.config.get_element_names():
            
            filter = my.config.get_display_widget(element_name)
            my.filters.append(filter)

        # make sure there is at least one filter defined
        assert my.filters

        """
        config = "<config>\n"
        config += "<filter>\n"

        # get all of the serialized versions of the filters
        """
        for filter in my.filters:
            config += filter.serialize() + "\n"
        """
        filter_data = FilterData.get()
        json = filter_data.serialize()
        value_type = "json"
        config += "<values type='%s'>%s</values>\n" % (value_type, json)
        config += "</filter>\n"
        config += "</config>\n"

        # format the xml
        xml = Xml()
        xml.read_string(config)

        if not my.view:
            saved_view = "saved_search:%s" % my.search_type
        else:
            saved_view = my.view
        #    if my.view.startswith("saved_search:"):
        #        saved_view = my.view
        #    else:
        #        saved_view = "saved_search:%s" % my.view

        # use widget config instead
        search = Search('config/widget_config')
        search.add_filter("view", saved_view)
        search.add_filter("search_type", my.search_type)
        if my.personal:
            search.add_user_filter()
        config = search.get_sobject()

        if not config:
            config = SearchType.create('config/widget_config')
            config.set_value("view", saved_view)
            config.set_value("search_type", my.search_type)
            if my.personal:
                config.set_user()

        config.set_value("config", xml.to_string())
        config.commit()
Пример #5
0
    def execute(my):
        my.init()

        # create the filters
        my.filters = []
        """
        for element_name in my.config.get_element_names():
            
            filter = my.config.get_display_widget(element_name)
            my.filters.append(filter)

        # make sure there is at least one filter defined
        assert my.filters

        """
        config = "<config>\n"
        config += "<filter>\n"

        # get all of the serialized versions of the filters
        """
        for filter in my.filters:
            config += filter.serialize() + "\n"
        """
        filter_data = FilterData.get()
        json = filter_data.serialize()
        value_type = "json"
        config += "<values type='%s'>%s</values>\n" % (value_type, json)
        config += "</filter>\n"
        config += "</config>\n"

        # format the xml
        xml = Xml()
        xml.read_string(config)

        if not my.view:
            saved_view = "saved_search:%s" % my.search_type
        else:
            saved_view = my.view
        #    if my.view.startswith("saved_search:"):
        #        saved_view = my.view
        #    else:
        #        saved_view = "saved_search:%s" % my.view

        # use widget config instead
        search = Search("config/widget_config")
        search.add_filter("view", saved_view)
        search.add_filter("search_type", my.search_type)
        if my.personal:
            search.add_user_filter()
        config = search.get_sobject()

        if not config:
            config = SearchType.create("config/widget_config")
            config.set_value("view", saved_view)
            config.set_value("search_type", my.search_type)
            if my.personal:
                config.set_user()

        config.set_value("config", xml.to_string())
        config.commit()
Пример #6
0
    def set_filter_data(search_type, view=None):
        '''set filter data based on some saved search values in wdg_settings'''

        # NOTE - This is MMS specific and is deprecated and will be deleted
        # DISABLING FOR Job and Request until job_detail stops stack tracing
        # This is due to mixing of searches between job and request in the
        # job detail.  Cannot find the issue.
        # 1) FilterData is global: should be scoped by search type
        # 2) After introduction of scroll bars, it started stack tracing
        # It looks like the state is not being properly passed through

        # temp fix to avoid cross contamination of filter data for Planners UI
        if search_type in ['MMS/job', 'MMS/request'] or view == '_planner':
            return

        filter_data = FilterData.get()
        if not filter_data.get_data():
            # use widget settings
            key = SearchWdg._get_key(search_type, view)
            data = WidgetSettings.get_value_by_key(key)
            if data:

                try:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                except SetupException, e:
                    print "This filter data is causing error:", data
                    print e
Пример #7
0
    def set_filter_data(search_type, view=None):
        '''set filter data based on some saved search values in wdg_settings'''

        # NOTE - This is MMS specific and is deprecated and will be deleted
        # DISABLING FOR Job and Request until job_detail stops stack tracing
        # This is due to mixing of searches between job and request in the
        # job detail.  Cannot find the issue.
        # 1) FilterData is global: should be scoped by search type
        # 2) After introduction of scroll bars, it started stack tracing
        # It looks like the state is not being properly passed through

        # temp fix to avoid cross contamination of filter data for Planners UI
        if search_type in ['MMS/job','MMS/request'] or view == '_planner':
            return
        
        filter_data = FilterData.get()
        if not filter_data.get_data():
            # use widget settings
            key = SearchWdg._get_key(search_type, view)
            data = WidgetSettings.get_value_by_key(key)
            if data:
              
                try:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                except SetupException, e:
                    print "This filter data is causing error:", data
                    print e
Пример #8
0
    def get_process(my):
        '''Get from the ProcessFilterWdg in SObjectLoadWdg,
            otherwise get from FilterData'''

        process = ''

        # Ususally there is no pipeline defined for prod/shot_instance
        # so get from prod/shot
        search_type = my.search_type
        if search_type == 'prod/shot_instance':
            search_type = 'prod/shot'

        state = Container.get("global_state")
        if state:
            process = state.get('process')
        else:

            # get it from FilterData
            data = FilterData.get()
            values = data.get_values_by_prefix('view_action_option')
            if values:
                process = values[0].get('load_%s_process' % search_type)

        if not process:
            from pyasm.prod.web import ProcessFilterWdg
            process_filter = ProcessFilterWdg(None, search_type)
            process = process_filter.get_value()
        return process
Пример #9
0
    def alter_search(my, search):
        '''
        from tactic.ui.filter import BaseFilterElementWdg
        config = my.get_config()
        element_names = config.get_element_names()
        for element_name in element_names:
            widget = config.get_display_widget(element_name)

            if isinstance(widget, BaseFilterElementWdg):
                widget.alter_search(search)

        '''


        from tactic.ui.panel import CustomLayoutWdg


        # define a standard search action
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        config = my.get_config()

        data_list = filter_data.get_values_by_prefix(my.prefix)
        #columns = search.get_columns()

        element_data_dict = {}
        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



        element_names = config.get_element_names()
        if not element_names:
            element_names = ['keywords']

        for element_name in element_names:

            widget = config.get_display_widget(element_name)
            if not widget:
                widget = KeywordFilterElementWdg(column='code|description')
                widget.set_name(element_name)

            data = element_data_dict.get(element_name)
            if not data:
                data = {}
            widget.set_values(data)

            if isinstance(widget, KeywordFilterElementWdg):
                if not data.get("keywords") and my.kwargs.get("keywords"):
                    widget.set_value("value", my.kwargs.get("keywords"))

            widget.alter_search(search)

        return
Пример #10
0
    def alter_search(my, search):
        '''
        from tactic.ui.filter import BaseFilterElementWdg
        config = my.get_config()
        element_names = config.get_element_names()
        for element_name in element_names:
            widget = config.get_display_widget(element_name)

            if isinstance(widget, BaseFilterElementWdg):
                widget.alter_search(search)

        '''


        from tactic.ui.panel import CustomLayoutWdg


        # define a standard search action
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        config = my.get_config()

        data_list = filter_data.get_values_by_prefix(my.prefix)
        #columns = search.get_columns()

        element_data_dict = {}
        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



        element_names = config.get_element_names()
        if not element_names:
            element_names = ['keywords']

        for element_name in element_names:

            widget = config.get_display_widget(element_name)
            if not widget:
                widget = KeywordFilterElementWdg(mode="keyword")
                widget.set_name(element_name)

            data = element_data_dict.get(element_name)
            if not data:
                data = {}
            widget.set_values(data)

            if isinstance(widget, KeywordFilterElementWdg):
                if not data.get("keywords") and my.kwargs.get("keywords"):
                    widget.set_value("value", my.kwargs.get("keywords"))

            widget.alter_search(search)

        return
Пример #11
0
    def alter_search(self, search):

        user = Environment.get_user_name()
        from pyasm.security import Login
        user = Login.get_by_login(user)
        search.add_filter("login", user.get_value("login"))

        import datetime
        from dateutil import parser
        filter_data = FilterData.get()
        values = filter_data.get_values_by_index("week", 0)
        date_string = values.get("calendar")
        if date_string:
            date = parser.parse(date_string)
        else:
            date = datetime.datetime.now()

        from tactic.ui.report import MMSUtility
        #start_wday, end_wday = self.get_week_range(date_string)
        start_wday, end_wday = MMSUtility.get_week_range(date)

        one_day = datetime.timedelta(days=1)

        column = "work_performed_date"

        # KEEP it simple for now
        search.add_op("begin")
        search.add_filter(column, start_wday, op='>=')
        search.add_filter(column, end_wday, op='<=')
        search.add_op("and")
        '''
        search.add_op("begin")
        search.add_filter(column, start_wday + one_day, op='>=')
        search.add_filter(column, end_wday - one_day, op='<=')
        search.add_op("and")

        search.add_op("begin")
        search.add_filter(column, start_wday, op='>=')
        search.add_filter(column, start_wday+one_day, op='<=')
        search.add_filter("shift", "pm", op='=')
        search.add_op("and")

        # FIXME: have to add this extra "or" because we don't support multiple
        # begins??
        search.add_op("or")
 
        search.add_op("begin")
        search.add_filter(column, end_wday, op='>=')
        search.add_filter(column, end_wday+one_day, op='<=')
        search.add_filter("shift", "am", op='=')
        search.add_op("and")
 
        search.add_op("or")
        '''

        search.add_order_by(column)
        search.add_order_by("work_start_time")
        search.add_order_by("shift")
Пример #12
0
    def get_title(my):
        from tactic.ui.filter import FilterData
        values = FilterData.get().get_values_by_index(my.prefix, 0)
        selected_year = ''
        date = None
        selected_date_value = values.get(my.CAL_NAME)

        work_date_selector = CalendarInputWdg(my.CAL_NAME)
        if selected_date_value:
            selected_date = Date(db_date=selected_date_value)
        else:
            selected_date = Date()
        #my.mode = my.sel.get_value()

        week = int(selected_date.get_week())

        year = int(selected_date.get_year())
        weekday_list = Calendar.get_monthday_time(year, week)

        div = DivWdg()
        if my.mode == 'day':
            spacer = FloatDivWdg('&nbsp;', width=my.DAY_TITLE_WIDTH)
            div.add(spacer)
            my.weekday = int(selected_date.get_weekday(is_digit=True))
            month = selected_date.get_month(is_digit=False)
            month_div = FloatDivWdg(css='center_content')
            month_div.add(month)
            div.add_style('width: 15em')
        else:
            month_list = []
            for item in weekday_list:
                month, day, time = item
                if month not in month_list:
                    month_list.append(month)

            month_div = FloatDivWdg(width=my.WEEK_TITLE_WIDTH,
                                    css='right_content')
            month_div.add(' / '.join(month_list))
            div.add_style('width: 45em')

        div.add(month_div)

        for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR):
            if my.weekday != None and idx != my.weekday:
                continue
            total = FloatDivWdg(width=50, css='center_content')
            span = SpanWdg(weekday_list[idx][1])
            if i in ["sat", "sun"]:
                span.add_style('color', '#995151')
            span.add(HtmlElement.br())

            weekday_span = SpanWdg('%s' % i.capitalize(), css='smaller')
            span.add(weekday_span)
            total.add(span)
            div.add(total)

        return div
Пример #13
0
    def get_title(my):
        from tactic.ui.filter import FilterData
        values = FilterData.get().get_values_by_index(my.prefix, 0)
        selected_year = ''
        date = None
        selected_date_value = values.get(my.CAL_NAME)
 
        work_date_selector = CalendarInputWdg(my.CAL_NAME)
        if selected_date_value:
            selected_date = Date(db_date=selected_date_value)
        else:
            selected_date = Date()
        #my.mode = my.sel.get_value()

        week = int(selected_date.get_week())

        year = int(selected_date.get_year())
        weekday_list = Calendar.get_monthday_time(year, week)

        div = DivWdg() 
        if my.mode == 'day':
            spacer = FloatDivWdg('&nbsp;', width=my.DAY_TITLE_WIDTH)
            div.add(spacer)
            my.weekday = int(selected_date.get_weekday(is_digit=True))
            month = selected_date.get_month(is_digit=False)
            month_div = FloatDivWdg(css='center_content')          
            month_div.add(month)
            div.add_style('width: 15em')
        else:
            month_list = []
            for item in weekday_list:  
                 month, day, time = item
                 if month not in month_list:
                     month_list.append(month)

            month_div = FloatDivWdg(width=my.WEEK_TITLE_WIDTH, css='right_content')
            month_div.add(' / '.join(month_list))
            div.add_style('width: 45em')
       
        div.add(month_div)

        for idx, i in enumerate(TimecardWdg.WEEK_CALENDAR):
            if my.weekday != None and idx != my.weekday:
                continue
            total = FloatDivWdg(width=50, css='center_content')
            span = SpanWdg(weekday_list[idx][1])
            if i in ["sat", "sun"]:
                span.add_style('color', '#995151')
            span.add(HtmlElement.br())

            weekday_span = SpanWdg('%s' %i.capitalize(), css='smaller')
            span.add(weekday_span)
            total.add(span)
            div.add(total)
        
        return div
Пример #14
0
    def get_process(my):
        process_select = Container.get('process_filter')
        process = ''
        if process_select:
            process = process_select.get_value()
        else:
            # get it from FilterData
            data = FilterData.get()
            values = data.get_values_by_prefix('view_action_option')
            if values:
                process = values[0].get('load_asset_process')

        return process
Пример #15
0
    def get_process(my):
        process_select = Container.get('process_filter')
        process = ''
        if process_select:
            process = process_select.get_value()
        else:
            # get it from FilterData
            data = FilterData.get()
            values = data.get_values_by_prefix('view_action_option')
            if values:
                process = values[0].get('load_asset_process')

        return process
Пример #16
0
    def execute(self):
        self.init()

        # create the filters
        self.filters = []

        config = "<config>\n"
        config += "<filter>\n"

        # get all of the serialized versions of the filters
        filter_data = FilterData.get()
        json = filter_data.serialize()
        value_type = "json"
        config += "<values type='%s'>%s</values>\n" % (value_type, json)
        config += "</filter>\n"
        config += "</config>\n"
        

        # format the xml
        xml = Xml()
        xml.read_string(config)


        if not self.view:
            saved_view = "saved_search:%s" % self.search_type
        else:
            saved_view = self.view
        #    if self.view.startswith("saved_search:"):
        #        saved_view = self.view
        #    else:
        #        saved_view = "saved_search:%s" % self.view

        # use widget config instead
        search = Search('config/widget_config')
        search.add_filter("view", saved_view)
        search.add_filter("search_type", self.search_type)
        if self.personal:
            search.add_user_filter()
        config = search.get_sobject()

        if not config:
            config = SearchType.create('config/widget_config')
            config.set_value("view", saved_view)
            config.set_value("search_type", self.search_type)
            if self.personal:
                config.set_user()

        config.set_value("category", "search_filter")
        config.set_value("config", xml.to_string())
        config.commit()
Пример #17
0
    def set_filter_data(search_type, view=None):
        '''set filter data based on some saved search values in wdg_settings'''

        filter_data = FilterData.get()
        if not filter_data.get_data():
            # use widget settings
            key = SearchWdg._get_key(search_type, view)
            data = WidgetSettings.get_value_by_key(key)
            if data:

                try:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                except SetupException, e:
                    print "This filter data is causing error:", data
                    print e
Пример #18
0
    def set_filter_data(search_type, view=None):
        '''set filter data based on some saved search values in wdg_settings'''

        filter_data = FilterData.get()
        if not filter_data.get_data():
            # use widget settings
            key = SearchWdg._get_key(search_type, view)
            data = WidgetSettings.get_value_by_key(key)
            if data:
              
                try:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                except SetupException, e:
                    print "This filter data is causing error:", data
                    print e
Пример #19
0
    def get_content_wdg(my):
        div = DivWdg()
        div.add_class("spt_tile_layout_top")
        inner = DivWdg()
        div.add(inner)

        # 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 )


        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")

        
        inner.add_style("margin-left: 20px")

        if my.sobjects:
            inner.add( my.get_scale_wdg() )

            for sobject in my.sobjects:
                kwargs = my.kwargs.copy()
                tile = my.get_tile_wdg(sobject)
                inner.add(tile)
        else:
            table = Table()
            inner.add(table)
            my.handle_no_results(table)


        inner.add("<br clear='all'/>")
        return div
Пример #20
0
    def init(self):
        self.view = self.kwargs.get('view')
        self.simple_search_view = self.kwargs.get('simple_search_view')
        self.search_type = self.kwargs.get('search_type')
        self.asset_search_type = self.kwargs.get('asset_search_type')
        if not self.asset_search_type:
            self.asset_search_type = 'prod/asset'
        self.instance_search_type = self.kwargs.get('instance_search_type')
        if not self.instance_search_type:
            self.instance_search_type = 'prod/shot_instance'

        #self.load_script = self.kwargs.get('load_script')
        #self.load_script_path = self.kwargs.get('load_script_path')
        self.is_refresh = self.kwargs.get('is_refresh') == 'true'
        self.state = Container.get_full_dict("global_state")
        self.process = self.state.get("process")

        values = FilterData.get().get_values_by_index('shot_filter', 0)
        self.shot_code = values.get('shot_code')
Пример #21
0
    def init(my):
        my.view = my.kwargs.get('view')
        my.simple_search_view = my.kwargs.get('simple_search_view')
        my.search_type = my.kwargs.get('search_type')
        my.asset_search_type = my.kwargs.get('asset_search_type')
        if not my.asset_search_type:
            my.asset_search_type = 'prod/asset'
        my.instance_search_type = my.kwargs.get('instance_search_type')
        if not my.instance_search_type:
            my.instance_search_type = 'prod/shot_instance'

        #my.load_script = my.kwargs.get('load_script')
        #my.load_script_path = my.kwargs.get('load_script_path')
        my.is_refresh = my.kwargs.get('is_refresh')=='true'
        my.state = Container.get_full_dict("global_state")
        my.process = my.state.get("process")

        values = FilterData.get().get_values_by_index('shot_filter', 0)
        my.shot_code = values.get('shot_code')
Пример #22
0
    def init(self):
        self.view = self.kwargs.get('view')
        self.simple_search_view = self.kwargs.get('simple_search_view')
        self.search_type = self.kwargs.get('search_type')
        self.asset_search_type = self.kwargs.get('asset_search_type')
        if not self.asset_search_type:
            self.asset_search_type = 'prod/asset'
        self.instance_search_type = self.kwargs.get('instance_search_type')
        if not self.instance_search_type:
            self.instance_search_type = 'prod/shot_instance'

        #self.load_script = self.kwargs.get('load_script')
        #self.load_script_path = self.kwargs.get('load_script_path')
        self.is_refresh = self.kwargs.get('is_refresh')=='true'
        self.state = Container.get_full_dict("global_state")
        self.process = self.state.get("process")

        values = FilterData.get().get_values_by_index('shot_filter', 0)
        self.shot_code = values.get('shot_code')
Пример #23
0
    def alter_task_search(my, search, prefix='children', prefix_namespace='' ):
        from tactic.ui.filter import FilterData, BaseFilterWdg, GeneralFilterWdg
        filter_data = FilterData.get()
        parent_search_type = get_search_type()
        
        if not filter_data.get_data():
            # use widget settings
            key = "last_search:%s" % parent_search_type
            data = WidgetSettings.get_value_by_key(key)
            if data:
                filter_data = FilterData(data)
            filter_data.set_to_cgi()

        
        filter_mode_prefix = 'filter_mode'
        if prefix_namespace:
            filter_mode_prefix = '%s_%s' %(prefix_namespace, filter_mode_prefix)
        
        filter_mode = 'and'
        filter_mode_value = filter_data.get_values_by_index(filter_mode_prefix, 0)
        if filter_mode_value:
            filter_mode = filter_mode_value.get('filter_mode')
       
        if prefix_namespace:
            prefix = '%s_%s' %(prefix_namespace, prefix)
        values_list = BaseFilterWdg.get_search_data_list(prefix, \
                search_type=my.get_searchable_search_type())
        if values_list:
            
            search.add_op('begin')
            GeneralFilterWdg.alter_sobject_search( search, values_list, prefix)
            if filter_mode != 'custom': 
                search.add_op(filter_mode)
        
        
        return search
Пример #24
0
    def alter_task_search(self, search, prefix='children', prefix_namespace='' ):
        from tactic.ui.filter import FilterData, BaseFilterWdg, GeneralFilterWdg
        filter_data = FilterData.get()
        parent_search_type = get_search_type()
        
        if not filter_data.get_data():
            # use widget settings
            key = "last_search:%s" % parent_search_type
            data = WidgetSettings.get_value_by_key(key)
            if data:
                filter_data = FilterData(data)
            filter_data.set_to_cgi()

        
        filter_mode_prefix = 'filter_mode'
        if prefix_namespace:
            filter_mode_prefix = '%s_%s' %(prefix_namespace, filter_mode_prefix)
        
        filter_mode = 'and'
        filter_mode_value = filter_data.get_values_by_index(filter_mode_prefix, 0)
        if filter_mode_value:
            filter_mode = filter_mode_value.get('filter_mode')
       
        if prefix_namespace:
            prefix = '%s_%s' %(prefix_namespace, prefix)
        values_list = BaseFilterWdg.get_search_data_list(prefix, \
                search_type=self.get_searchable_search_type())
        if values_list:
            
            search.add_op('begin')
            GeneralFilterWdg.alter_sobject_search( search, values_list, prefix)
            if filter_mode != 'custom': 
                search.add_op(filter_mode)
        
        
        return search
Пример #25
0
    def alter_search(self, search):

        user = Environment.get_user_name()
        from pyasm.security import Login
        user = Login.get_by_login(user)
        search.add_filter("login", user.get_value("login"))


        import datetime
        from dateutil import parser
        filter_data = FilterData.get()
        values = filter_data.get_values_by_index("week", 0)
        date_string = values.get("calendar")
        if date_string:
            date = parser.parse(date_string)
        else:
            date = datetime.datetime.now()

        from tactic.ui.report import MMSUtility
        #start_wday, end_wday = self.get_week_range(date_string)
        start_wday, end_wday = MMSUtility.get_week_range(date)

        one_day = datetime.timedelta(days=1)

        column = "work_performed_date"

        # KEEP it simple for now
        search.add_op("begin")
        search.add_filter(column, start_wday, op='>=')
        search.add_filter(column, end_wday, op='<=')
        search.add_op("and")

        '''
        search.add_op("begin")
        search.add_filter(column, start_wday + one_day, op='>=')
        search.add_filter(column, end_wday - one_day, op='<=')
        search.add_op("and")

        search.add_op("begin")
        search.add_filter(column, start_wday, op='>=')
        search.add_filter(column, start_wday+one_day, op='<=')
        search.add_filter("shift", "pm", op='=')
        search.add_op("and")

        # FIXME: have to add this extra "or" because we don't support multiple
        # begins??
        search.add_op("or")
 
        search.add_op("begin")
        search.add_filter(column, end_wday, op='>=')
        search.add_filter(column, end_wday+one_day, op='<=')
        search.add_filter("shift", "am", op='=')
        search.add_op("and")
 
        search.add_op("or")
        '''


        search.add_order_by(column)
        search.add_order_by("work_start_time")
        search.add_order_by("shift")
Пример #26
0
    def get_display(self):


        from tactic.ui.report import MMSUtility
        import datetime
        date = datetime.datetime.now()
        start_wday, end_wday =  MMSUtility.get_week_range(date)

        self.prefix = 'week'
        top = DivWdg()
        top.add_class("spt_table_search")
        self.set_as_panel(top)

        from tactic.ui.container import RoundedCornerDivWdg
        inner = RoundedCornerDivWdg(corner_size=10, hex_color_code='949494')
        inner.set_dimensions(width_str="95%", content_height_str='95%', height_str="100%")
        inner.add_style("margin: 20px")
        top.add(inner)


        hidden = HiddenWdg("prefix", self.prefix)
        top.add(hidden)



        filter_data = FilterData.get()
        values = filter_data.get_values_by_index("week", 0)
        date_string = values.get("calendar")
        if not date_string:
            date_string = WebContainer.get_web().get_form_value("calendar")

        if date_string:
            date = parser.parse(date_string)
        else:
            date = datetime.datetime.now()

        week = 1


        table = Table()
        table.add_style("color: black")
        table.add_style("width: 600px")
        table.add_row()
        inner.add(table)


        #inner.add("Range: %s - %s<br/><br/>" % (start_wday, end_wday))


        table.add_cell("Week Of Date: <br/>")
        calendar = CalendarInputWdg('calendar')

        day_cbk = '''
        var top = spt.get_parent(bvr.src_el, '.spt_table_search');
        var week_el = top.getElement('.spt_calendar_week');
        var input_el = top.getElement('.spt_calendar_input');
        var value = input_el.value;
        var week = spt.date_util.ymd.get_week( value )
        week_el.innerHTML = week + '';
        '''
        calendar.add_day_cbk(day_cbk)


        #calendar.set_option("first_day_of_week", 4)
        calendar.set_value(date.strftime("%Y-%m-%d"))
        # TODO: set default
        table.add_cell( calendar )

        week = int(date.strftime("%W")) + 1

        table.add_cell("Week: ")
        #select = SelectWdg("week")
        #select.add_class("action inputfield")
        #select.set_option("values", range(1,53) )
        #select.set_value(week)
        #select.set_option( "size", "2" )
        text = DivWdg()
        text.add_class("spt_calendar_week")
        text.add_style("width", "25px")
        text.add(week)
        table.add_cell(text)

        table.add_cell( self.get_search_wdg() )

        return top
Пример #27
0
    def init(my):
        my.current_offset = 0
        my.count = None
        #my.text = TextWdg(my.search_limit_name)
        my.text = HiddenWdg(my.search_limit_name)
        my.text.add_style("width: 23px")
        my.text.add_style("margin-bottom: -1px")
        my.text.add_class("spt_search_limit_text")
        my.text.set_persist_on_submit(prefix=my.prefix)

        behavior = {
            'type':
            'keydown',
            'cbjs_action':
            '''
                 if (evt.key=='enter') {
                    // register this as changed item
                    var value = bvr.src_el.value;
                    
                        if (isNaN(value) || value.test(/[\.-]/)) {
                            spt.error('You have to use an integer.');
                        }
                }
        '''
        }

        my.text.add_behavior(behavior)

        # get the search limit that is passed in
        filter_data = FilterData.get()
        values = filter_data.get_values_by_prefix(my.prefix)
        if not values:
            # check web for embedded table
            web = WebContainer.get_web()
            values = {}
            limit_value = web.get_form_value("search_limit")
            label_value = web.get_form_value(my.label)
            if limit_value:
                values['search_limit'] = limit_value
            if label_value:
                values[my.label] = label_value
        else:
            values = values[0]

        my.values2 = filter_data.get_values_by_prefix("search_limit_simple")
        if not len(my.values2):
            my.values2 = {}
        else:
            my.values2 = my.values2[0]

        my.stated_search_limit = values.get("search_limit")
        """
        if not my.stated_search_limit:
            my.stated_search_limit = values.get("limit_select")
        if not my.stated_search_limit:
            my.stated_search_limit = values.get("custom_limit")
        """
        if my.stated_search_limit:
            my.stated_search_limit = int(my.stated_search_limit)
        else:
            my.stated_search_limit = 0

        # reused for alter_search() later
        my.values = values
Пример #28
0
    def init(my):
        my.scale_called = False
        my.scale = None
        top_view = my.kwargs.get("top_view")
        if top_view:
            kwargs = {
                'view': top_view,
            }
            from tactic.ui.panel import CustomLayoutWdg
            my.title_wdg = CustomLayoutWdg(**kwargs)
        else:
            my.title_wdg = None
        my.sticky_scale = my.kwargs.get('sticky_scale')
        if my.sticky_scale == 'local':
            # NOTE: each side bar link has a unique name on each level, but it's not always available
            # not in page refresh or built-in links
            # element = my.kwargs.get('element_name')
            my.scale_prefix = '%s:%s' %(my.search_type, my.view)
        else:
            my.scale_prefix = ''
        
        bottom_view = my.kwargs.get("bottom_view")
        if bottom_view:
            kwargs = {
                'view': bottom_view,
                'load': 'sequence',
            }
            from tactic.ui.panel import CustomLayoutWdg
            my.bottom = CustomLayoutWdg(**kwargs)
        else:
            my.bottom = None

        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        

        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")
        if my.scale == None:
            my.scale = 100


        my.aspect_ratio = my.kwargs.get('aspect_ratio')
        if my.aspect_ratio:
            parts = re.split('[\Wx]+', my.aspect_ratio)
            my.aspect_ratio = (int(parts[0]), int(parts[1]))
        else:
            my.aspect_ratio = (240, 160)

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

        my.top_styles = my.kwargs.get('styles')
        my.spacing = my.kwargs.get('spacing')
        if not my.spacing:
            my.spacing = '10'

        my.overlay_expr = my.kwargs.get('overlay_expr')
        my.overlay_color = my.kwargs.get('overlay_color')

        super(TileLayoutWdg, my).init()
Пример #29
0
    def init(my):

        my.user_override = my.kwargs.get('user_override') in ['true', True]

        custom_search_view = my.kwargs.get('custom_search_view')
        if not custom_search_view or not custom_search_view.strip():
            custom_search_view = 'search'

        # create a search for this search widget
        my.search_type = my.kwargs.get('search_type')
        my.search = Search(my.search_type)
        my.config = None

        # determine whether or not to use the last search.  If any kind of
        # state has been set, then ignore the last_search
        my.use_last_search = True
        parent_key = my.kwargs.get('parent_key')
        state = my.kwargs.get('state')
        if parent_key or state or my.kwargs.get('use_last_search') == False:
            my.use_last_search = False
       
        my.prefix_namespace = my.kwargs.get('prefix_namespace')


        # NOTE: this is still hard coded
        my.prefix = 'main_body'
        # if we are asking for a specific saved search
        save = my.kwargs.get('save')


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

        # get the config from a specific location

        # if the view is specified, use this view with the values
        # specified explicitly in this view
        my.config = None

        # see if a filter is explicitly passed in
        filter = my.kwargs.get('filter')
        my.limit = my.kwargs.get('limit')
        my.run_search_bvr = my.kwargs.get('run_search_bvr')

        # get from search view
     
        # filter can be either dict(data) or a list or
        # xml(filter wdg definition)
        if filter:
            if type(filter) == types.DictType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData([filter])
                filter_data.set_to_cgi()
            elif type(filter) == types.ListType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData(filter)
                filter_data.set_to_cgi()
        
            else:
                
                try:
                    filter_data = None

                    # TODO: remove this. This is for backward compatibilty
                    my.config = WidgetConfig.get(xml=filter, view='filter')
                    filter_data = FilterData.get()
                    if not filter_data.get_data():
                        # use widget settings
                        key = SearchWdg._get_key(my.search_type, my.view)

                        data = WidgetSettings.get_value_by_key(key)
                        if data:
                            filter_data = FilterData(data)
                        filter_data.set_to_cgi()

                except XmlException, e:
                    print "WARNING: non-xml filter detected!! %s" %filter
Пример #30
0
    def init(my):
        my.current_offset = 0
        my.count = None
        #my.text = TextWdg(my.search_limit_name)
        my.text = HiddenWdg(my.search_limit_name)
        my.text.add_style("width: 23px")
        my.text.add_style("margin-bottom: -1px")
        my.text.add_class("spt_search_limit_text")
        my.text.set_persist_on_submit(prefix=my.prefix)

        behavior = {
                'type': 'keydown',
                'cbjs_action': '''
                 if (evt.key=='enter') {
                    // register this as changed item
                    var value = bvr.src_el.value;
                    
                        if (isNaN(value) || value.test(/[\.-]/)) {
                            spt.error('You have to use an integer.');
                        }
                }
        '''}

        my.text.add_behavior(behavior)

        # get the search limit that is passed in
        filter_data = FilterData.get()
        values = filter_data.get_values_by_prefix(my.prefix)
        if not values:
            # check web for embedded table
            web = WebContainer.get_web()
            values = {}
            limit_value = web.get_form_value("search_limit")
            label_value = web.get_form_value(my.label)
            if limit_value:
                values['search_limit'] = limit_value
            if label_value:
                values[my.label] = label_value
        else:
            values = values[0]


        my.values2 = filter_data.get_values_by_prefix("search_limit_simple")
        if not len(my.values2):
            my.values2 = {}
        else:
            my.values2 = my.values2[0]


        my.stated_search_limit = values.get("search_limit")
        """
        if not my.stated_search_limit:
            my.stated_search_limit = values.get("limit_select")
        if not my.stated_search_limit:
            my.stated_search_limit = values.get("custom_limit")
        """
        if my.stated_search_limit:
            my.stated_search_limit = int(my.stated_search_limit)
        else:
            my.stated_search_limit = 0
      
        # reused for alter_search() later
        my.values = values
Пример #31
0
    def get_display(my):

        element_data_dict = {}

        config = my.get_config()
        element_names = config.get_element_names()
        content_wdg = DivWdg()


        if not element_names:
            element_names = ['keywords']

        my.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()
        data_list = filter_data.get_values_by_prefix(my.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_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 1px 0px 0px" )

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

        visible_rows = my.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 % 2 == 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()


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


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

            #title_td.add_style("border: solid 1px red")
            #element_td.add_style("border: solid 1px blue")
            #element_wdg.add_style("border: solid 1px yellow")


            if i == 0 and len(element_names) > 1:
                spacer = DivWdg()
                spacer.add_class("spt_spacer")
                spacer.add_style("border-style: solid")
                spacer.add_style("border-width: 0 1 0 0")
                #spacer.add_style("height: %spx" % (num_rows*20))
                spacer.add_style("height: %spx" % (num_rows*20))
                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_color("color", "color3")
            #element_wdg.add_color("background", "background3")
            #element_wdg.set_round_corners()
            #element_wdg.add_border()

            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", my.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, e:
                element_wdg.add(ExceptionWdg(e))
                continue


            if not widget:
                widget = KeywordFilterElementWdg()
                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: 5px")
            icon_div.add_class("spt_filter_top")


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

                if isinstance(widget, KeywordFilterElementWdg):
                    if not data.get("keywords") and my.kwargs.get("keywords"):
                        widget.set_value("value", my.kwargs.get("keywords"))
                    

            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, e:
                element_wdg.add(ExceptionWdg(e))
                continue
Пример #32
0
    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
Пример #33
0
    def init(my):

        my.user_override = my.kwargs.get('user_override') in ['true', True]

        custom_search_view = my.kwargs.get('custom_search_view')
        if not custom_search_view or not custom_search_view.strip():
            custom_search_view = 'search'

        # create a search for this search widget
        my.search_type = my.kwargs.get('search_type')
        my.search = Search(my.search_type)
        my.config = None

        # determine whether or not to use the last search.  If any kind of
        # state has been set, then ignore the last_search
        my.use_last_search = True
        parent_key = my.kwargs.get('parent_key')
        state = my.kwargs.get('state')
        if parent_key or state or my.kwargs.get('use_last_search') == False:
            my.use_last_search = False

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

        # NOTE: this is still hard coded
        my.prefix = 'main_body'
        # if we are asking for a specific saved search
        save = my.kwargs.get('save')

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

        # get the config from a specific location

        # if the view is specified, use this view with the values
        # specified explicitly in this view
        my.config = None

        # see if a filter is explicitly passed in
        filter = my.kwargs.get('filter')
        my.limit = my.kwargs.get('limit')
        my.run_search_bvr = my.kwargs.get('run_search_bvr')

        # get from search view

        # filter can be either dict(data) or a list or
        # xml(filter wdg definition)
        if filter:
            if type(filter) == types.DictType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData([filter])
                filter_data.set_to_cgi()
            elif type(filter) == types.ListType:
                my.config = my.get_default_filter_config()
                filter_data = FilterData(filter)
                filter_data.set_to_cgi()

            else:

                try:
                    filter_data = None

                    # TODO: remove this. This is for backward compatibilty
                    my.config = WidgetConfig.get(xml=filter, view='filter')
                    filter_data = FilterData.get()
                    if not filter_data.get_data():
                        # use widget settings
                        key = SearchWdg._get_key(my.search_type, my.view)

                        data = WidgetSettings.get_value_by_key(key)
                        if data:
                            filter_data = FilterData(data)
                        filter_data.set_to_cgi()

                except XmlException, e:
                    print "WARNING: non-xml filter detected!! %s" % filter
Пример #34
0
    def get_scale_wdg(my):

        if my.scale_called == True:
            return None
        my.scale_called = True


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

        div = DivWdg()
        if show_scale in [False, 'false']:
            div.add_style("display: none")
        div.add_style("padding: 5px")
        div.add_class("spt_table_search")
        hidden = HiddenWdg("prefix", "tile_layout")
        div.add(hidden)

        div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
spt.tile_layout = {}
spt.tile_layout.layout = null;

spt.tile_layout.set_layout = function(layout) {
    if (!layout.hasClass("spt_layout")) {
        layout = layout.getParent(".spt_layout");
    }
    spt.tile_layout.layout = layout;
    return layout;
}

spt.tile_layout.get_scale = function() {
    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    var value = scale_value.value;
    value = parseInt(value);
    return value;
}


spt.tile_layout.set_scale = function(scale) {

    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    scale_value.value = scale;

    var size_x = 240*scale/100;
    var size_y = 160*scale/100;

    //var top = bvr.src_el.getParent(".spt_tile_layout_top");
    var top = spt.tile_layout.layout;
    var els = top.getElements(".spt_tile_content");
    for (var i = 0; i < els.length; i++) {
        var el = els[i];
        el.setStyle( "width",  size_x);
        el.setStyle( "height", size_y);
    }

    spt.container.set_value("tile_layout::scale", scale);

}


spt.tile_layout.drag_start_x = null;
spt.tile_layout.drag_start_value = null;

spt.tile_layout.drag_setup = function(evt, bvr, mouse_411) {
    spt.tile_layout.set_layout(bvr.src_el);
    spt.tile_layout.drag_start_x = mouse_411.curr_x;
    var src_el = spt.behavior.get_bvr_src( bvr );
    if (!src_el.value) {
        src_el.value = 0;
    }
    spt.tile_layout.drag_start_value = src_el.value;
    src_el.focus();
    src_el.select();
}
spt.tile_layout.drag_motion = function(evt, bvr, mouse_411) {
    var start_value = spt.tile_layout.drag_start_value; 
    if (isNaN(parseInt(start_value))) {
        return;
    }
    var dx = mouse_411.curr_x - spt.tile_layout.drag_start_x;
    var increment = parseInt(dx / 5);
    var multiplier;
    if (increment < 0)
        multiplier = 0.975;
    else
        multiplier = 1 / 0.975;
    increment = Math.abs(increment);
    var scale = spt.tile_layout.drag_start_value;
    for (var i = 0; i < increment; i++) {
        scale = scale * multiplier;
    }
    scale = parseInt(scale);
    spt.tile_layout.set_scale(scale);

}


        ''' } )



        div.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        spt.tile_layout.set_layout(bvr.src_el);
        var scale = spt.container.get_value("tile_layout::scale");
        if (scale) {
            spt.tile_layout.set_scale(scale);
        }
        '''
        } )


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

        less_div = DivWdg()
        less_div.add("<input type='button' value='&lt;&lt;'/>")
        table.add_cell(less_div)

        less_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale * 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )


 
        value_wdg = TextWdg("scale")
        value_wdg.add_class("spt_scale_value")
        td = table.add_cell(value_wdg)
        td.add("&nbsp;%")
        td.add_style("padding: 3px 8px")



        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")


        if my.scale:
            value_wdg.set_value(my.scale)
        value_wdg.add_style("width: 24px")
        value_wdg.add_style("text-align: center")
        value_wdg.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )
        value_wdg.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        if (!value) {
            value = 100;
        }
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )



 
        value_wdg.add_behavior( {
            'type': 'smart_drag',
            'bvr_match_class': 'spt_scale_value',
            'ignore_default_motion' : True,
            "cbjs_setup": 'spt.tile_layout.drag_setup( evt, bvr, mouse_411 );',
            "cbjs_motion": 'spt.tile_layout.drag_motion( evt, bvr, mouse_411 );'
        } )



        more_div = DivWdg()
        more_div.add("<input type='button' value='&gt;&gt;'/>")
        table.add_cell(more_div)

        more_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale / 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )



        return div
Пример #35
0
class BaseConfigWdg(BaseRefreshWdg):
    def __init__(my, search_type, config_base, input_prefix='', config=None):

        if type(search_type) in types.StringTypes:
            my.search_type_obj = SearchType.get(search_type)
            my.search_type = search_type
        elif isinstance(search_type, SearchType):
            my.search_type_obj = search_type
            my.search_type = my.search_type_obj.get_base_key()
        elif inspect.isclass(search_type) and issubclass(search_type, SObject):
            my.search_type_obj = SearchType.get(search_type.SEARCH_TYPE)
            my.search_type = my.search_type_obj.get_base_key()
        else:
            raise LayoutException('search_type must be a string or an sobject')
        my.config = config
        my.config_base = config_base
        my.input_prefix = input_prefix
        my.element_names = []
        my.element_titles = []

        from pyasm.web import DivWdg
        my.top = DivWdg()

        # Layout widgets compartmentalize their widgets in sections for drawing
        my.sections = {}

        super(BaseConfigWdg, my).__init__()

    # NEED to add these because this is derived from HtmlElement and not
    # BaseRefreshWdg
    def add_style(my, name, value=None):
        return my.top.add_style(name, value=value)

    def add_class(my, class_name):
        return my.top.add_class(class_name)

    def has_class(my, class_name):
        return my.top.has_class(class_name)

    def add_behavior(my, behavior):
        return my.top.add_behavior(behavior)

    def add_relay_behavior(my, behavior):
        return my.top.add_relay_behavior(behavior)

    def get_default_display_handler(cls, element_name):
        raise Exception("Must override 'get_default_display_handler()'")

    get_default_display_handler = classmethod(get_default_display_handler)

    def get_config_base(my):
        return my.config_base

    def get_config(my):
        return my.config

    def get_view(my):
        return my.config_base

    def remap_display_handler(my, display_handler):
        '''Provide an opportunity to remap a display handler for newer
        layouts engines using older configs'''
        return display_handler

    def init(my):

        # create all of the display elements
        if not my.config:
            # it shouldn't use the my.search_type_obj here as it would absorb the project info
            my.config = WidgetConfigView.get_by_search_type(
                my.search_type, my.config_base)
        my.element_names = my.config.get_element_names()
        my.element_titles = my.config.get_element_titles()

        # TODO: should probably be all the attrs
        my.element_widths = my.config.get_element_widths()

        simple_view = my.kwargs.get("show_simple_view")
        if simple_view == "true":
            simple_view = True
        else:
            simple_view = False

        # go through each element name and construct the handlers
        for idx, element_name in enumerate(my.element_names):

            # check to see if these are removed for this production
            #if element_name in invisible_elements:
            #    continue

            simple_element = None

            display_handler = my.config.get_display_handler(element_name)
            new_display_handler = my.remap_display_handler(display_handler)
            if new_display_handler:
                display_handler = new_display_handler

            if not display_handler:
                # else get it from default of this type
                display_handler = my.get_default_display_handler(element_name)

            # get the display options
            display_options = my.config.get_display_options(element_name)
            try:
                if not display_handler:
                    element = my.config.get_display_widget(element_name)
                else:
                    element = WidgetConfig.create_widget(
                        display_handler, display_options=display_options)
            except Exception, e:
                from tactic.ui.common import WidgetTableElementWdg
                element = WidgetTableElementWdg()
                # FIXME: not sure why this doesn't work
                #from pyasm.widget import ExceptionWdg
                #log = ExceptionWdg(e)
                #element.add(log)
                # FIXME: not sure why this doesn't work
                from pyasm.widget import IconWdg
                icon = IconWdg("Error", IconWdg.ERROR)
                element.add(icon)
                element.add(e)

            # skip the empty elements like ThumbWdg
            if simple_element and not element.is_simple_viewable():
                continue
            # make simple_element the element if it exists
            if simple_element:
                element = simple_element
            # if the element failed to create, then continue
            if element == None:
                continue

            element.set_name(element_name)
            title = my.element_titles[idx]
            element.set_title(title)

            # FIXME: this causes a circular reference which means the
            # Garbage collector can't clean it up
            # make sure the element knows about its layout engine
            element.set_layout_wdg(my)

            # TODO: should convert this to ATTRS or someting like that.  Not
            # just width
            element.width = my.element_widths[idx]

            if my.input_prefix:
                element.set_input_prefix(my.input_prefix)

            # get the display options
            #display_options = my.config.get_display_options(element_name)
            #for key in display_options.keys():
            element.set_options(display_options)

            my.add_widget(element, element_name)

            # layout widgets also categorize their widgets based on type
            if element_name == "Filter":
                section_name = 'filter'
            else:
                section_name = 'default'
            section = my.sections.get(section_name)
            if not section:
                section = []
                my.sections[section_name] = section
            section.append(element)

        # go through each widget and pass them the filter_data object
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        if not filter_data:
            filter_data = {}
        for widget in my.widgets:
            widget.set_filter_data(filter_data)

        # initialize all of the child widgets
        super(BaseConfigWdg, my).init()
Пример #36
0
    def get_display(my):

        element_data_dict = {}

        config = my.get_config()
        element_names = config.get_element_names()
        content_wdg = DivWdg()


        if not element_names:
            element_names = ['keywords']

        my.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()
        data_list = filter_data.get_values_by_prefix(my.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_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 1px 0px 0px" )

        table = Table()
        table.add_color("color", "color")
        elements_wdg.add(table)
       
        num_rows = int(len(element_names)/2)+1
        project_code = Project.get_project_code()
        # my.search_type could be the same as my.base_search_type
        full_search_type = SearchType.build_search_type(my.search_type, project_code)
        titles = config.get_element_titles() 
        for i, element_name in enumerate(element_names):
            attrs = config.get_element_attributes(element_name)
            if i % 2 == 0:
                table.add_row()

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


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


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

            #title_td.add_style("border: solid 1px red")
            #element_td.add_style("border: solid 1px blue")
            #element_wdg.add_style("border: solid 1px yellow")


            if i == 0 and len(element_names) > 1:
                spacer = DivWdg()
                spacer.add_style("border-style: solid")
                spacer.add_style("border-width: 0 1 0 0")
                spacer.add_style("height: %spx" % (num_rows*20))
                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", num_rows)

            #element_wdg.add_color("color", "color3")
            #element_wdg.add_color("background", "background3")
            #element_wdg.set_round_corners()
            #element_wdg.add_border()

            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", my.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, e:
                element_wdg.add(ExceptionWdg(e))
                continue


            if not widget:
                widget = KeywordFilterElementWdg()
                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: 5px")
            icon_div.add_class("spt_filter_top")


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

                if isinstance(widget, KeywordFilterElementWdg):
                    if not data.get("keywords") and my.kwargs.get("keywords"):
                        widget.set_value("value", my.kwargs.get("keywords"))
                    

            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, e:
                element_wdg.add(ExceptionWdg(e))
                continue
Пример #37
0
    def get_display(self):

        widget = DivWdg()
        self.set_as_panel(
            widget,
            class_name='spt_view_panel spt_panel spt_app_asset_inst_panel')

        parent_search_type = self.search_type

        if self.show_search:
            # Have to limit this search to just its parent.. cuz if the target is prod/shot_instance
            # and its parent search is ShotFilterWdg, it's hard to isolate what shot has been selected
            search_bvr = {
                'type':
                'click_up',
                'cbjs_action':
                'spt.dg_table.search_cbk(evt, bvr)',
                'override_class_name':
                'tactic.ui.cgapp.AppAssetInstancePanelWdg',
                'override_target':
                "bvr.src_el.getParent('.spt_app_asset_inst_panel')"
            }

            search_wdg = SearchWdg(search_type=parent_search_type, view='search_shot_loader', parent_key='', filter=''\
            , display='block', custom_filter_view='', state=None, run_search_bvr=search_bvr)
            widget.add(HtmlElement.spacer_div(1, 10))
            widget.add(search_wdg)

            # if there is result, it could only be one shot
            search = search_wdg.get_search()
            shots = search.get_sobjects()

            if not self.shot and len(shots) == 1:
                self.shot = shots[0]

        # create the asset table
        table_id = "main_body_asset_instance_table"

        if not self.shot:
            return widget
        # get any parent shots
        parent_code = self.shot.get_value("parent_code")
        shot_code = self.shot.get_code()

        # add the search make sure set elements are not shown
        search = Search(self.instance_search_type)
        if parent_code != "":
            search.add_filters(self.shot.get_foreign_key(),
                               [shot_code, parent_code])
        else:
            search.add_filter(self.shot.get_foreign_key(), shot_code)

        search.add_where("\"type\" in ('set_item', 'asset')")
        search.add_order_by('asset_code')

        instances = search.get_sobjects()

        # if parent shot and current shot has the same instance, hide the
        # parent's one

        top_instances = []
        for instance in instances:
            if instance.get_value('type') != 'set_item':
                top_instances.append(instance)

        #instances = ShotInstance.filter_instances(instances, shot_code)
        top_instances = ShotInstance.filter_instances(top_instances, shot_code)
        # TODO: just add asset name to the ShotInstance table
        # get the original asset names

        aux_data = ShotInstance.get_aux_data(top_instances,
                                             self.asset_search_type)

        values = FilterData.get().get_values_by_index('view_action_option', 0)
        state = {}

        if not self.show_search:
            if values:
                state['process'] = values.get('load_%s_process' %
                                              parent_search_type)
            else:
                process_filter = ProcessFilterWdg(None, parent_search_type)
                state['process'] = process_filter.get_value()

        Container.put("global_state", state)

        from tactic.ui.cgapp import CGAppLoaderWdg
        cg_wdg = CGAppLoaderWdg(view='load',
                                search_type=self.instance_search_type)
        widget.add(cg_wdg)

        if not top_instances:
            widget.add('No Asset Instances in Shot.')
        else:
            asset_table = TableLayoutWdg(table_id = table_id, search_type=self.instance_search_type,\
                view="load", inline_search=False, aux_info = aux_data, mode='simple')

            #asset_table = ViewPanelWdg( search_type=search_type,  inline_search=False, \
            #        show_general_search=False, view='load', state=state, mode='simple')

            asset_table.set_sobjects(top_instances)
            widget.add(asset_table)

            shot_inst_names = [inst.get_code() for inst in instances]

            self.add_unassigned_instances(widget, shot_inst_names)
        return widget
Пример #38
0
    def get_display(my):

        element_data_dict = {}

        config = my.get_config()
        element_names = config.get_element_names()
        content_wdg = DivWdg()


        if not element_names:
            element_names = ['keywords']

        my.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()
        data_list = filter_data.get_values_by_prefix(my.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 1px 0px 0px" )

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

        visible_rows = my.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 % 2 == 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()


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


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

            #title_td.add_style("border: solid 1px red")
            #element_td.add_style("border: solid 1px blue")
            #element_wdg.add_style("border: solid 1px yellow")


            if i == 0 and len(element_names) > 1:
                spacer = DivWdg()
                spacer.add_class("spt_spacer")
                spacer.add_style("border-style: solid")
                spacer.add_style("border-width: 0 1 0 0")
                #spacer.add_style("height: %spx" % (num_rows*20))
                spacer.add_style("height: %spx" % (num_rows*20))
                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_color("color", "color3")
            #element_wdg.add_color("background", "background3")
            #element_wdg.set_round_corners()
            #element_wdg.add_border()

            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", my.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, e:
                element_wdg.add(ExceptionWdg(e))
                continue


            if not widget:
                # the default for KeywordFilterElementWdg is mode=keyword
                if not my.column_choice:
                    my.column_choice = my.get_search_col(my.search_type)
                widget = KeywordFilterElementWdg(column=my.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: 5px")
            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 = my.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, e:
                element_wdg.add(ExceptionWdg(e))
                continue
Пример #39
0
    def init(my):
        my.scale_called = False
        my.scale = None
        top_view = my.kwargs.get("top_view")
        if top_view:
            kwargs = {
                'view': top_view,
            }
            from tactic.ui.panel import CustomLayoutWdg
            my.title_wdg = CustomLayoutWdg(**kwargs)
        else:
            my.title_wdg = None
        my.sticky_scale = my.kwargs.get('sticky_scale')
        if my.sticky_scale == 'local':
            # NOTE: each side bar link has a unique name on each level, but it's not always available
            # not in page refresh or built-in links
            # element = my.kwargs.get('element_name')
            my.scale_prefix = '%s:%s' %(my.search_type, my.view)
        else:
            my.scale_prefix = ''
        
        bottom_view = my.kwargs.get("bottom_view")
        if bottom_view:
            kwargs = {
                'view': bottom_view,
                'load': 'sequence',
            }
            from tactic.ui.panel import CustomLayoutWdg
            my.bottom = CustomLayoutWdg(**kwargs)
        else:
            my.bottom = None

        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        

        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")
        if my.scale == None:
            my.scale = 100


        my.aspect_ratio = my.kwargs.get('aspect_ratio')
        if my.aspect_ratio:
            parts = re.split('[\Wx]+', my.aspect_ratio)
            my.aspect_ratio = (int(parts[0]), int(parts[1]))
        else:
            my.aspect_ratio = (240, 160)

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

        my.top_styles = my.kwargs.get('styles')
        my.spacing = my.kwargs.get('spacing')
        if not my.spacing:
            my.spacing = '10'

        super(TileLayoutWdg, my).init()
Пример #40
0
    def init(self):

        self.user_override = self.kwargs.get('user_override') in ['true', True]

        custom_search_view = self.kwargs.get('custom_search_view')
        if not custom_search_view or not custom_search_view.strip():
            custom_search_view = 'search'

        # create a search for this search widget
        self.search_type = self.kwargs.get('search_type')

        self.search = self.kwargs.get("search")
        if not self.search:
            self.search = Search(self.search_type)
        self.config = None

        # determine whether or not to use the last search.  If any kind of
        # state has been set, then ignore the last_search
        self.use_last_search = True
        parent_key = self.kwargs.get('parent_key')
        state = self.kwargs.get('state')
        if parent_key or state or self.kwargs.get('use_last_search') in [False, 'false']:
            self.use_last_search = False
       
        self.prefix_namespace = self.kwargs.get('prefix_namespace')


        # NOTE: this is still hard coded
        self.prefix = 'main_body'
        # if we are asking for a specific saved search
        save = self.kwargs.get('save')


        self.view = self.kwargs.get('view')

        # get the config from a specific location

        # if the view is specified, use this view with the values
        # specified explicitly in this view
        self.config = None

        # see if a filter is explicitly passed in
        filter = self.kwargs.get('filter')
        self.limit = self.kwargs.get('limit')
        self.run_search_bvr = self.kwargs.get('run_search_bvr')

        # get from search view
     
        # filter can be either dict(data) or a list or
        # xml(filter wdg definition)
        if filter:
            if type(filter) == types.DictType:
                self.config = self.get_default_filter_config()
                filter_data = FilterData([filter])
                filter_data.set_to_cgi()
            elif type(filter) == types.ListType:
                self.config = self.get_default_filter_config()
                filter_data = FilterData(filter)
                filter_data.set_to_cgi()
        
            else:
                
                try:
                    filter_data = None

                    # TODO: remove this. This is for backward compatibilty
                    self.config = WidgetConfig.get(xml=filter, view='filter')
                    filter_data = FilterData.get()
                    if not filter_data.get_data():
                        # use widget settings
                        key = SearchWdg._get_key(self.search_type, self.view)

                        data = WidgetSettings.get_value_by_key(key)
                        if data:
                            filter_data = FilterData(data)
                        filter_data.set_to_cgi()

                except XmlException as e:
                    print("WARNING: non-xml filter detected!!")

        
        # NOTE: this is only used to maintain backwards compatibility
        # plus it is needed for link_search: which contains the filter_config (old way of doing it)
        if not self.config:# and self.view:
            """
            if ':' in self.view: # avoid view of a SearchWdg like link_search:<search_type>:<view>
                search_view = custom_search_view
            else:
                search_view = self.view
            """
            search_view = custom_search_view
            config_view = WidgetConfigView.get_by_search_type(self.search_type, view=search_view)
            # get the self.config first for the display of SearchWdg
            # then get the filter data below if there is any
            if config_view.get_config().has_view(search_view):
                self.config = config_view.get_config()   

            try:
                search = Search('config/widget_config')
                search.add_filter("view", self.view)
                search.add_filter("search_type", self.search_type)
                config_sobjs = search.get_sobjects()
                from pyasm.search import WidgetDbConfig
                config_sobj = WidgetDbConfig.merge_configs(config_sobjs)
                #config_sobj = config_sobjs[0]
            except SearchException as e:
                print("WARNING: ", e)
                config_sobj = None


            if config_sobj:
                config_xml = config_sobj.get_xml_value("config")

                if not config_view.get_config().has_view(self.view):
                    # make sure it does have the old way of storing filter
                    # elements instead of just filter data
                    if config_xml.get_nodes("config/filter/element"):
                        self.config = WidgetConfig.get(xml=config_xml, view='filter')
                    
                #self.config = self.get_default_filter_config()

                # set the form variables for the filters
                data = config_xml.get_value("config/filter/values")
                # link_search with specific search params takes precesdence
                # TODO: make a distinction between search definition and alter
                # search data provided by user
                if data and not self.user_override:
                    filter_data = FilterData(data)
                    filter_data.set_to_cgi()
                else:    
                    self.set_filter_data(self.search_type, self.view)

            else:
                if self.use_last_search: 
                    self.set_filter_data(self.search_type, self.view)
        if not self.config:
            # get the approprate filter definition
            self.config = self.get_default_filter_config()
            if self.use_last_search: 
                self.set_filter_data(self.search_type, self.view)


        if not self.config:
            return


        self.num_filters_enabled = 0

        # create the filters
        self.filters = []
        security = Environment.get_security()
        element_names = self.config.get_element_names()
        #element_names = ["Keywords", "Related"]

        for element_name in element_names:
            filter = self.config.get_display_widget(element_name)

            if filter and filter.is_visible():
                self.filters.append(filter)

        # make sure there is at least one filter defined
        #assert self.filters

        # just for drawing purpose
        if self.kwargs.get('skip_search') == True:
            return

        try:
            self.alter_search()
            self.set_persistent_value()

        except SearchInputException as e:
            self.clear_search_data(self.search_type)
            raise SearchInputException("%s If this problem persists, this view may contain invalid data in &lt; values &gt;. Clean up the data in Widget Config for the view [%s]."%( e.__str__(), self.view)) 
        except:
            self.clear_search_data(self.search_type)
            raise
Пример #41
0
    def get_display(self):

        from tactic.ui.report import MMSUtility
        import datetime
        date = datetime.datetime.now()
        start_wday, end_wday = MMSUtility.get_week_range(date)

        self.prefix = 'week'
        top = DivWdg()
        top.add_class("spt_table_search")
        self.set_as_panel(top)

        from tactic.ui.container import RoundedCornerDivWdg
        inner = RoundedCornerDivWdg(corner_size=10, hex_color_code='949494')
        inner.set_dimensions(width_str="95%",
                             content_height_str='95%',
                             height_str="100%")
        inner.add_style("margin: 20px")
        top.add(inner)

        hidden = HiddenWdg("prefix", self.prefix)
        top.add(hidden)

        filter_data = FilterData.get()
        values = filter_data.get_values_by_index("week", 0)
        date_string = values.get("calendar")
        if not date_string:
            date_string = WebContainer.get_web().get_form_value("calendar")

        if date_string:
            date = parser.parse(date_string)
        else:
            date = datetime.datetime.now()

        week = 1

        table = Table()
        table.add_style("color: black")
        table.add_style("width: 600px")
        table.add_row()
        inner.add(table)

        #inner.add("Range: %s - %s<br/><br/>" % (start_wday, end_wday))

        table.add_cell("Week Of Date: <br/>")
        calendar = CalendarInputWdg('calendar')

        day_cbk = '''
        var top = spt.get_parent(bvr.src_el, '.spt_table_search');
        var week_el = top.getElement('.spt_calendar_week');
        var input_el = top.getElement('.spt_calendar_input');
        var value = input_el.value;
        var week = spt.date_util.ymd.get_week( value )
        week_el.innerHTML = week + '';
        '''
        calendar.add_day_cbk(day_cbk)

        #calendar.set_option("first_day_of_week", 4)
        calendar.set_value(date.strftime("%Y-%m-%d"))
        # TODO: set default
        table.add_cell(calendar)

        week = int(date.strftime("%W")) + 1

        table.add_cell("Week: ")
        #select = SelectWdg("week")
        #select.add_class("action inputfield")
        #select.set_option("values", range(1,53) )
        #select.set_value(week)
        #select.set_option( "size", "2" )
        text = DivWdg()
        text.add_class("spt_calendar_week")
        text.add_style("width", "25px")
        text.add(week)
        table.add_cell(text)

        table.add_cell(self.get_search_wdg())

        return top
Пример #42
0
    def get_display(my):
        
        widget = DivWdg()
        my.set_as_panel(widget, class_name='spt_view_panel spt_panel spt_app_asset_inst_panel')
        
        parent_search_type= my.search_type
        
        if my.show_search:
            # Have to limit this search to just its parent.. cuz if the target is prod/shot_instance
            # and its parent search is ShotFilterWdg, it's hard to isolate what shot has been selected
            search_bvr = {
                'type':         'click_up',
                'cbjs_action':  'spt.dg_table.search_cbk(evt, bvr)',
                'override_class_name': 'tactic.ui.cgapp.AppAssetInstancePanelWdg',
                'override_target': "bvr.src_el.getParent('.spt_app_asset_inst_panel')"
            }

            search_wdg = SearchWdg(search_type=parent_search_type, view='search_shot_loader', parent_key='', filter=''\
            , display='block', custom_filter_view='', state=None, run_search_bvr=search_bvr)
            widget.add( HtmlElement.spacer_div(1,10) )
            widget.add(search_wdg)


            # if there is result, it could only be one shot
            search = search_wdg.get_search()
            shots = search.get_sobjects()
            
            if not my.shot and len(shots) == 1:
                my.shot= shots[0]

        # create the asset table
        table_id = "main_body_asset_instance_table" 
              
        if not my.shot:
            return widget
        # get any parent shots
        parent_code = my.shot.get_value("parent_code")
        shot_code = my.shot.get_code()

        # add the search make sure set elements are not shown
        search = Search(my.instance_search_type)
        if parent_code != "":
            search.add_filters(my.shot.get_foreign_key(), [shot_code,parent_code] )
        else:
            search.add_filter(my.shot.get_foreign_key(), shot_code )

        search.add_where("\"type\" in ('set_item', 'asset')")
        search.add_order_by('asset_code')
        
        instances = search.get_sobjects()

        # if parent shot and current shot has the same instance, hide the 
        # parent's one
        
        top_instances = []
        for instance in instances:
            if instance.get_value('type') != 'set_item':
                top_instances.append(instance)

        #instances = ShotInstance.filter_instances(instances, shot_code)
        top_instances = ShotInstance.filter_instances(top_instances, shot_code)
        # TODO: just add asset name to the ShotInstance table
        # get the original asset names

        aux_data = ShotInstance.get_aux_data(top_instances, my.asset_search_type)

        values = FilterData.get().get_values_by_index('view_action_option', 0)
        state = {}
        
        if not my.show_search:
            if values:
                state['process'] = values.get('load_%s_process'% parent_search_type)
            else:
                process_filter = ProcessFilterWdg(None, parent_search_type)
                state['process'] = process_filter.get_value()

        Container.put("global_state", state)
        
        from tactic.ui.cgapp import CGAppLoaderWdg
        cg_wdg = CGAppLoaderWdg(view='load', search_type=my.instance_search_type)
        widget.add(cg_wdg)

        if not top_instances:
            widget.add('No Asset Instances in Shot.')
        else:
            asset_table = TableLayoutWdg(table_id = table_id, search_type=my.instance_search_type,\
                view="load", inline_search=False, aux_info = aux_data, mode='simple')

            #asset_table = ViewPanelWdg( search_type=search_type,  inline_search=False, \
            #        show_general_search=False, view='load', state=state, mode='simple') 

            asset_table.set_sobjects(top_instances)
            widget.add(asset_table)

            shot_inst_names = [inst.get_code() for inst in instances]
            
            my.add_unassigned_instances(widget, shot_inst_names)
        return widget
Пример #43
0
    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
Пример #44
0
    def init(self):

        # create all of the display elements
        if not self.config:
            # it shouldn't use the self.search_type_obj here as it would absorb the project info
            self.config = WidgetConfigView.get_by_search_type(self.search_type, self.config_base)
        self.element_names = self.config.get_element_names()
        self.element_titles = self.config.get_element_titles()  

        # TODO: should probably be all the attrs
        self.element_widths = self.config.get_element_widths()  

       
        simple_view = self.kwargs.get("show_simple_view")
        if simple_view == "true":
            simple_view = True
        else:
            simple_view = False


        self.extra_data = self.kwargs.get("extra_data")
        if self.extra_data and isinstance(self.extra_data, basestring):
            try:
                self.extra_data = jsonloads(self.extra_data)
            except:
                self.extra_data = self.extra_data.replace("'", '"')
                self.extra_data = jsonloads(self.extra_data)



        # go through each element name and construct the handlers
        for idx, element_name in enumerate(self.element_names):

            # check to see if these are removed for this production
            #if element_name in invisible_elements:
            #    continue

            simple_element = None

            display_handler = self.config.get_display_handler(element_name)
            new_display_handler = self.remap_display_handler(display_handler)
            if new_display_handler:
                display_handler = new_display_handler

            if not display_handler:
                # else get it from default of this type
                display_handler = self.get_default_display_handler(element_name)

            # get the display options
            display_options = self.config.get_display_options(element_name)

            # add in extra_data
            if self.extra_data:
                for key, value in self.extra_data.items():
                    display_options[key] = value

            try:
                if not display_handler:
                    element = self.config.get_display_widget(element_name)
                else:
                    display_options['element_name'] = element_name
                    element = WidgetConfig.create_widget( display_handler, display_options=display_options )
            except Exception as e:
                from tactic.ui.common import WidgetTableElementWdg
                element = WidgetTableElementWdg()
                # FIXME: not sure why this doesn't work
                #from pyasm.widget import ExceptionWdg
                #log = ExceptionWdg(e)
                #element.add(log)
                # FIXME: not sure why this doesn't work
                from pyasm.widget import IconWdg
                icon = IconWdg("Error", IconWdg.ERROR)
                element.add(icon)
                element.add(e)

            # skip the empty elements like ThumbWdg
            if simple_element and not element.is_simple_viewable():
                continue
            # make simple_element the element if it exists
            if simple_element:
                element = simple_element
            # if the element failed to create, then continue
            if element == None:
                continue


            element.set_name(element_name)
            title = self.element_titles[idx]
            element.set_title(title)

            # FIXME: this causes a circular reference which means the
            # Garbage collector can't clean it up
            # make sure the element knows about its layout engine
            element.set_layout_wdg(self)


            # TODO: should convert this to ATTRS or someting like that.  Not
            # just width
            if idx >= len(self.element_widths):
                element.width = 150
            else:
                element.width = self.element_widths[idx]

            if self.input_prefix:
                element.set_input_prefix(self.input_prefix)


            # get the display options
            #display_options = self.config.get_display_options(element_name)
            #for key in display_options.keys():
            element.set_options(display_options)

            self.add_widget(element,element_name)

            # layout widgets also categorize their widgets based on type
            if element_name == "Filter":
                section_name = 'filter'
            else:
                section_name = 'default'
            section = self.sections.get(section_name)
            if not section:
                section = []
                self.sections[section_name] = section
            section.append(element)


        # go through each widget and pass them the filter_data object
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        if not filter_data:
            filter_data = {}
        for widget in self.widgets:
            widget.set_filter_data(filter_data)



        # initialize all of the child widgets
        super(BaseConfigWdg,self).init()
Пример #45
0
    def get_content_wdg(my):
        div = DivWdg()
        div.add_class("spt_tile_layout_top")
        inner = DivWdg()
        div.add(inner)


        # set up the context menus
        show_context_menu = my.kwargs.get("show_context_menu")
        if show_context_menu in ['false', False]:
            show_context_menu = False
        else:
            show_context_menu = True

        menus_in = {}
        if show_context_menu:
            menus_in['DG_HEADER_CTX'] = [ my.get_smart_header_context_menu_data() ]
            menus_in['DG_DROW_SMENU_CTX'] = [ my.get_data_row_smart_context_menu_details() ]
        if menus_in:
            SmartMenu.attach_smart_context_menu( inner, menus_in, False )





        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")


        temp = my.kwargs.get("temp")
        has_loading = False

        
        inner.add_style("margin-left: 20px")

        if my.sobjects:
            inner.add( my.get_scale_wdg() )

            for row, sobject in enumerate(my.sobjects):

                if False and not temp and row > 4: 
                    tile_wdg = DivWdg()
                    inner.add(tile_wdg)
                    tile_wdg.add_style("width: 120px")
                    tile_wdg.add_style("height: 120px")
                    tile_wdg.add_style("float: left")
                    tile_wdg.add_style("padding: 20px")
                    tile_wdg.add_style("text-align: center")
                    tile_wdg.add('<img src="/context/icons/common/indicator_snake.gif" border="0"/>')
                    tile_wdg.add(" Loading ...")
                    tile_wdg.add_attr("spt_search_key", sobject.get_search_key())
                    tile_wdg.add_class("spt_loading")
                    has_loading = True
                    continue


                kwargs = my.kwargs.copy()
                tile = my.get_tile_wdg(sobject)
                inner.add(tile)
        else:
            table = Table()
            inner.add(table)
            my.handle_no_results(table)


        chunk_size = 5
        if has_loading:
            inner.add_behavior( {
            'type': 'load',
            'chunk': chunk_size,
            'cbjs_action': '''
            var layout = bvr.src_el.getParent(".spt_layout");
            spt.table.set_layout(layout);
            var rows = layout.getElements(".spt_loading");

            var jobs = [];
            var count = 0;
            var chunk = bvr.chunk;
            while (true) {
                var job_item = rows.slice(count, count+chunk);
                if (job_item.length == 0) {
                    break;
                }
                jobs.push(job_item);
                count += chunk;
            }

            var count = -1;
            var func = function() {
                count += 1;
                var rows = jobs[count];
                if (! rows || rows.length == 0) {
                    return;
                }
                for (var i = 0; i < rows.length; i++) {
                    rows[i].removeClass("spt_loading");
                }
                spt.table.refresh_rows(rows, null, null, {on_complete: func});
            }
            func();

            '''
            } )





        inner.add("<br clear='all'/>")
        return div