def init_setup(my): hidden = HiddenWdg(my.DELETE_MODE) my.add_ajax_input(hidden) hidden = HiddenWdg(my.NEW_ITEM) my.add_ajax_input(hidden) hidden = HiddenWdg(my.NEW_ITEM_LABEL) my.add_ajax_input(hidden) hidden = HiddenWdg("code_col") my.add_ajax_input(hidden) if not my.is_from_ajax(): hidden.set_value(my.get_option('code_col')) my.add(hidden) hidden = HiddenWdg('ref_search_type') my.add_ajax_input(hidden) if not my.is_from_ajax(): hidden.set_value(my.web.get_form_value('ref_search_type')) my.add(hidden) hidden = HiddenWdg('search_id') my.add_ajax_input(hidden) if my.is_from_ajax(): col_name = my.web.get_form_value('col_name') else: col_name = my.get_name() my.col_name = HiddenWdg('col_name', col_name) my.add_ajax_input(my.col_name) my.select_items = HiddenWdg('%s|%s' %(col_name, my.SELECT_ITEMS)) my.add_ajax_input(my.select_items)
def init(self): from input_wdg import HiddenWdg if self.add_hidden: self.hidden = HiddenWdg(self.value, "") self.add(self.hidden) self.add_event("onclick", "submit_icon_button('%s','%s')" % \ (self.submit_name,self.value) )
def __init__(self, prefix='', refresh=True): name = 'show_retired' if prefix: name = '%s_show_retired' % prefix self.hidden = HiddenWdg(name, '') if refresh: self.hidden.set_persistence() self.refresh = refresh super(RetiredFilterWdg, self).__init__()
def add_inputs(self): ''' register the inputs ''' hidden = HiddenWdg("%s_process" %self.PUBLISH_TYPE, self.process) self.add_ajax_input(hidden) hidden = HiddenWdg("search_type" ,self.search_type) self.add_ajax_input(hidden) self.related_search_type_wdg = HiddenWdg(self.RELATED_SEARCH_TYPE ,self.related_search_type) self.add_ajax_input(self.related_search_type_wdg) div_id='process_context_wdg' self.main_div = DivWdg(id=div_id) self.set_ajax_top(self.main_div)
def add_inputs(my): ''' register the inputs ''' hidden = HiddenWdg("%s_process" % my.PUBLISH_TYPE, my.process) my.add_ajax_input(hidden) hidden = HiddenWdg("search_type", my.search_type) my.add_ajax_input(hidden) my.related_search_type_wdg = HiddenWdg(my.RELATED_SEARCH_TYPE, my.related_search_type) my.add_ajax_input(my.related_search_type_wdg) div_id = 'process_context_wdg' my.main_div = DivWdg(id=div_id) my.set_ajax_top(my.main_div)
def get_post_data(self): ''' get the post data for this AjaxWdg''' widget = Widget() hidden = HiddenWdg('skey_UserAssignWdg_%s' %self.task.get_id(), self.task.get_search_key()) widget.add(hidden) key = 'post_script_UserAssignCommand_%s' % self.task.get_value('search_id') # avoid duplication dict_key = 'UserAssignCommand_ps:%s' %Environment.get_user_name() if not Container.get_dict(dict_key, key): hidden = HiddenWdg(key, self.post_script) widget.add(hidden) Container.put_dict(dict_key, key, self.post_script) return widget
class IconSubmitWdg(IconButtonWdg): def __init__(self, name=None, icon=None, long=False, icon_pos="left", \ add_hidden=True, value=None): self.add_hidden = add_hidden self.hidden = None if not value: self.value = name else: self.value = value # for some reason, self.name gets reset to empty self.name = name self.submit_name = name super(IconSubmitWdg, self).__init__(name, icon, long, icon_pos) def init(self): from input_wdg import HiddenWdg if self.add_hidden: self.hidden = HiddenWdg(self.value, "") self.add(self.hidden) self.add_event("onclick", "submit_icon_button('%s','%s')" % \ (self.submit_name,self.value) ) def get_display(self): return super(IconSubmitWdg, self).get_display() def get_value(self): return self.hidden.get_value()
class IconSubmitWdg(IconButtonWdg): def __init__(self, name=None, icon=None, long=False, icon_pos="left", \ add_hidden=True, value=None): self.add_hidden = add_hidden self.hidden = None if not value: self.value = name else: self.value = value # for some reason, self.name gets reset to empty self.name = name self.submit_name = name super(IconSubmitWdg,self).__init__(name,icon,long,icon_pos) def init(self): from input_wdg import HiddenWdg if self.add_hidden: self.hidden = HiddenWdg(self.value,"") self.add( self.hidden ) self.add_event("onclick", "submit_icon_button('%s','%s')" % \ (self.submit_name,self.value) ) def get_display(self): return super(IconSubmitWdg,self).get_display() def get_value(self): return self.hidden.get_value()
def get_display(self): search_type = self.search_type related_search_type = self.related_search_type_wdg.get_value() if related_search_type: search_type = related_search_type hier_sel = self.get_hier_sel(search_type) selected_related_search_type = hier_sel.get_value() process_wdg = self.get_process_wdg(search_type) context_wdg = self.get_context_wdg(search_type) widget = self.main_div if self.is_from_ajax(True): widget = Widget() else: self.set_ajax_top(widget) hidden = HiddenWdg("search_type" ,search_type) widget.add(hidden) hier_sel.add_event('onchange', self.get_refresh_script(show_progress=False)) widget.add(hier_sel) #Tooltip doesn't work too well #hint = HintWdg('Related search type you can optionally select to drive the process') widget.add(HtmlElement.br(2)) widget.add(process_wdg) widget.add(context_wdg) return widget
def init_setup(self): '''set the ajax top and register some inputs''' div_id = self.USER_ASSIGN_WDG_ID self.main_div = DivWdg(id=div_id) self.set_ajax_top(self.main_div) # register the inputs first hidden = HiddenWdg('skey_UserAssignWdg_%s' %self.task.get_id()) self.add_ajax_input(hidden) hidden = HiddenWdg('post_script_UserAssignCommand_%s' %self.task.get_value('search_id')) self.add_ajax_input(hidden) hidden = HiddenWdg(self.TARGET_TASK_ID) self.add_ajax_input(hidden)
def init(self): from input_wdg import HiddenWdg if self.add_hidden: self.hidden = HiddenWdg(self.value,"") self.add( self.hidden ) self.add_event("onclick", "submit_icon_button('%s','%s')" % \ (self.submit_name,self.value) )
def init(my): from input_wdg import HiddenWdg if my.add_hidden: my.hidden = HiddenWdg(my.value,"") my.add( my.hidden ) my.add_event("onclick", "submit_icon_button('%s','%s')" % \ (my.submit_name,my.value) )
class RetiredFilterWdg(SwapDisplayWdg): ''' a button that triggers the display of retired items''' def __init__(self, prefix='', refresh=True): name = 'show_retired' if prefix: name = '%s_show_retired' % prefix self.hidden = HiddenWdg(name, '') if refresh: self.hidden.set_persistence() self.refresh = refresh super(RetiredFilterWdg, self).__init__() def _get_script(self, value): script = "var x=get_elements('%s'); x.set_value('%s')"\ %(self.hidden.get_name(), value) if self.refresh: script = "%s;document.form.submit()" % script return script def get_display(self): on_icon = IconWdg('click to show retired', icon="/context/icons/common/hide_retire.png") off_icon = IconWdg('click to hide retired', icon=IconWdg.RETIRE) off_icon.add(self.hidden) on_script = self._get_script('true') off_script = self._get_script('false') # swap the icons if it is clicked on if self.get_value() == 'true': self.set_display_widgets(off_icon, on_icon) self.add_action_script(off_script, on_script) else: self.set_display_widgets(on_icon, off_icon) self.add_action_script(on_script, off_script) return super(RetiredFilterWdg, self).get_display() def get_value(self): return self.hidden.get_value() def alter_search(self, search): if self.get_value() == 'true': search.set_show_retired(True)
class RetiredFilterWdg(SwapDisplayWdg): ''' a button that triggers the display of retired items''' def __init__(self, prefix='', refresh=True): name = 'show_retired' if prefix: name = '%s_show_retired' %prefix self.hidden = HiddenWdg(name,'') if refresh: self.hidden.set_persistence() self.refresh = refresh super(RetiredFilterWdg, self).__init__() def _get_script(self, value): script = "var x=get_elements('%s'); x.set_value('%s')"\ %(self.hidden.get_name(), value) if self.refresh: script = "%s;document.form.submit()" %script return script def get_display(self): on_icon = IconWdg('click to show retired', icon="/context/icons/common/hide_retire.png") off_icon = IconWdg('click to hide retired', icon=IconWdg.RETIRE) off_icon.add(self.hidden) on_script = self._get_script('true') off_script = self._get_script('false') # swap the icons if it is clicked on if self.get_value()=='true': self.set_display_widgets(off_icon, on_icon) self.add_action_script(off_script, on_script) else: self.set_display_widgets(on_icon, off_icon) self.add_action_script(on_script, off_script) return super(RetiredFilterWdg, self).get_display() def get_value(self): return self.hidden.get_value() def alter_search(self, search): if self.get_value() == 'true': search.set_show_retired(True)
def __init__(my, prefix='', refresh=True): name = 'show_retired' if prefix: name = '%s_show_retired' % prefix my.hidden = HiddenWdg(name, '') if refresh: my.hidden.set_persistence() my.refresh = refresh super(RetiredFilterWdg, my).__init__()
def __init__(self, prefix='', refresh=True): name = 'show_retired' if prefix: name = '%s_show_retired' %prefix self.hidden = HiddenWdg(name,'') if refresh: self.hidden.set_persistence() self.refresh = refresh super(RetiredFilterWdg, self).__init__()
def get_display(my): # add the popup div = my.main_div cmd = my.get_cmd() my.attached_sobj = my.task.get_parent() # assign post ajax script since this widget is dynamically generated hidden = HiddenWdg('post_script_UserAssignCommand_%s' % my.attached_sobj.get_id()) my.post_script = [hidden.get_value()] # add SiteMenu refresh event_container = WebContainer.get_event_container() caller = event_container.get_event_caller(SiteMenuWdg.EVENT_ID) my.post_script.append(caller) progress = cmd.generate_div() progress.set_post_ajax_script(';'.join(my.post_script)) from pyasm.prod.web import UserSelectWdg filter = UserSelectWdg(my.ASSIGNMENT_ID, label='assign to: ') #filter.persistence = False script = [cmd.get_on_script(show_progress=False)] script.append(UserAssignContainerWdg.get_off_script()) filter.set_event('onchange', ';'.join(script)) filter.add_empty_option('-- unassigned --', '') status = my.task.get_value('assigned') filter.set_value(status) div.add(filter) div.add(progress) div.add(HiddenWdg(my.TARGET_TASK_ID, my.task.get_search_key())) my.add(div) return super(UserAssignWdg, my).get_display()
def get_display(my): # add the popup div = my.main_div cmd = my.get_cmd() my.attached_sobj = my.task.get_parent() # assign post ajax script since this widget is dynamically generated hidden = HiddenWdg('post_script_UserAssignCommand_%s' % my.attached_sobj.get_id()) my.post_script = [hidden.get_value()] # add SiteMenu refresh event_container = WebContainer.get_event_container() caller = event_container.get_event_caller(SiteMenuWdg.EVENT_ID) my.post_script.append(caller) progress = cmd.generate_div() progress.set_post_ajax_script(';'.join(my.post_script)) from pyasm.prod.web import UserSelectWdg filter = UserSelectWdg(my.ASSIGNMENT_ID, label = 'assign to: ') #filter.persistence = False script = [cmd.get_on_script(show_progress=False)] script.append(UserAssignContainerWdg.get_off_script()) filter.set_event('onchange', ';'.join(script)) filter.add_empty_option('-- unassigned --', '') status = my.task.get_value('assigned') filter.set_value(status) div.add(filter) div.add(progress) div.add(HiddenWdg(my.TARGET_TASK_ID, my.task.get_search_key())) my.add(div) return super(UserAssignWdg, my).get_display()
def init_setup(self, widget): self.reset_ajax() hidden = HiddenWdg('skey_SObjectTaskTableElement_%s' \ %self.sobject.get_id(), self.sobject.get_search_key()) widget.add(hidden) # add the search_key input self.add_ajax_input(hidden) # add the filter inputs hidden = HiddenWdg('task_status') self.add_ajax_input(hidden) hidden = HiddenWdg('show_assigned_only') self.add_ajax_input(hidden) hidden = MultiSelectWdg('user_filter') self.add_ajax_input(hidden) hidden = HiddenWdg('show_all_tasks') self.add_ajax_input(hidden) hidden = HiddenWdg('show_sub_tasks') self.add_ajax_input(hidden)
def get_display(my): new_tab_names = my.tab_names app_css = app_style = None if WebContainer.get_web().get_app_name_by_uri() != 'Browser': app_css = 'smaller' app_style = 'padding: 0px 2px 3px 2px' div = my.div div.set_style("margin-top: 10px; margin-bottom: 20px") # add some spacing span = SpanWdg(css='tab_front') div.add(span) selected_widget = None # figure out which is the selected one selected_index = 0 for i in range(0, len(new_tab_names)): tab_name = new_tab_names[i] if tab_name == my.tab_value: selected_index = i break for i in range(0, len(new_tab_names)): tab_name = new_tab_names[i] widget = my.get_widget(tab_name) tab = SpanWdg() if i == selected_index: # selected tab tab.set_class("%s_selected" %my.get_style_prefix()) if app_style: tab.add_style(app_style) selected_widget = widget else: # unselected tab tab.set_class("%s_unselected" %my.get_style_prefix()) if app_style: tab.add_style(app_style) tab.add( my.get_header(tab_name, selected_index, app_css)) div.add(tab) # FIXME: hide this for now #div.add( my.get_add_tab_wdg() ) tab_hidden = HiddenWdg(my.tab_key) tab_hidden.set_persistence() # explicitly records this value for init-type submit tab_hidden._set_persistent_values([my.tab_value]) # TODO: not sure if this is legal ... This is rather redundant, # but set_value is a pretty complex function. In the end this # forces it to be set to a value even though widget settings is disabled value = tab_hidden.get_value() if value: tab_hidden.set_value(value) div.add(tab_hidden) # if an error occured, draw the error if my.error_wdg: div.add(my.error_wdg) else: # display the content content_div = HtmlElement.div() if my.content_height: content_div.add_style("height: %spx" % my.content_height) content_div.add_style("padding: 10px 0 10px 0") content_div.add_style("overflow: auto") content_div.add_style("border-style: solid") content_div.set_class("%s_content" %my.get_style_prefix()) content_div.add_style("display: block") try: content = my.get_content(selected_widget) if isinstance( content, Widget): content = content.get_buffer_display() except Exception, e: my.handle_exception(e) # TODO: need some way to make this automatic in Widget. #if my.tab_path: # last_buffer = len(my.tab_path)+1 # buffer = my.get_buffer_on_exception(last_buffer) #else: buffer = my.get_buffer_on_exception() div.add(buffer) content = my.error_wdg content_div.add( content ) div.add(content_div)
def class_init(my): '''this is used for tab redirection. The set_redirect() takes presecedence''' tab_redirect = HiddenWdg(my.TAB_REDIRECT) my.div.add(tab_redirect)
def get_display(my): new_tab_names = my.tab_names app_css = app_style = None if WebContainer.get_web().get_app_name_by_uri() != 'Browser': app_css = 'smaller' app_style = 'padding: 0px 2px 3px 2px' div = my.div div.set_style("margin-top: 10px; margin-bottom: 20px") # add some spacing span = SpanWdg(css='tab_front') div.add(span) selected_widget = None # figure out which is the selected one selected_index = 0 for i in range(0, len(new_tab_names)): tab_name = new_tab_names[i] if tab_name == my.tab_value: selected_index = i break for i in range(0, len(new_tab_names)): tab_name = new_tab_names[i] widget = my.get_widget(tab_name) tab = SpanWdg() if i == selected_index: # selected tab tab.set_class("%s_selected" % my.get_style_prefix()) if app_style: tab.add_style(app_style) selected_widget = widget else: # unselected tab tab.set_class("%s_unselected" % my.get_style_prefix()) if app_style: tab.add_style(app_style) tab.add(my.get_header(tab_name, selected_index, app_css)) div.add(tab) # FIXME: hide this for now #div.add( my.get_add_tab_wdg() ) tab_hidden = HiddenWdg(my.tab_key) tab_hidden.set_persistence() # explicitly records this value for init-type submit tab_hidden._set_persistent_values([my.tab_value]) # TODO: not sure if this is legal ... This is rather redundant, # but set_value is a pretty complex function. In the end this # forces it to be set to a value even though widget settings is disabled value = tab_hidden.get_value() if value: tab_hidden.set_value(value) div.add(tab_hidden) # if an error occured, draw the error if my.error_wdg: div.add(my.error_wdg) else: # display the content content_div = HtmlElement.div() if my.content_height: content_div.add_style("height: %spx" % my.content_height) content_div.add_style("padding: 10px 0 10px 0") content_div.add_style("overflow: auto") content_div.add_style("border-style: solid") content_div.set_class("%s_content" % my.get_style_prefix()) content_div.add_style("display: block") try: content = my.get_content(selected_widget) if isinstance(content, Widget): content = content.get_buffer_display() except Exception, e: my.handle_exception(e) # TODO: need some way to make this automatic in Widget. #if my.tab_path: # last_buffer = len(my.tab_path)+1 # buffer = my.get_buffer_on_exception(last_buffer) #else: buffer = my.get_buffer_on_exception() div.add(buffer) content = my.error_wdg content_div.add(content) div.add(content_div)
def init_setup(my): hidden = HiddenWdg(my.DELETE_MODE) my.add_ajax_input(hidden) hidden = HiddenWdg(my.NEW_ITEM) my.add_ajax_input(hidden) hidden = HiddenWdg(my.NEW_ITEM_LABEL) my.add_ajax_input(hidden) hidden = HiddenWdg("code_col") my.add_ajax_input(hidden) if not my.is_from_ajax(): hidden.set_value(my.get_option('code_col')) my.add(hidden) hidden = HiddenWdg('ref_search_type') my.add_ajax_input(hidden) if not my.is_from_ajax(): hidden.set_value(my.web.get_form_value('ref_search_type')) my.add(hidden) hidden = HiddenWdg('search_id') my.add_ajax_input(hidden) if my.is_from_ajax(): col_name = my.web.get_form_value('col_name') else: col_name = my.get_name() my.col_name = HiddenWdg('col_name', col_name) my.add_ajax_input(my.col_name) my.select_items = HiddenWdg('%s|%s' % (col_name, my.SELECT_ITEMS)) my.add_ajax_input(my.select_items)
class ProcessContextWdg(AjaxWdg): '''A schema search type driven process/context select widget''' PUBLISH_TYPE = "asset" RELATED_SEARCH_TYPE = "related_search_type" def init(self): ''' initializes a few variables ''' self.search_type = '' self.process = '' self.related_search_type = '' self.related_search_type_wdg = None def init_cgi(self): #keys = self.web.get_form_keys() self.search_type = self.web.get_form_value('search_type') self.related_search_type = self.web.get_form_value(self.RELATED_SEARCH_TYPE) self.process = self.web.get_form_value("%s_process" %self.PUBLISH_TYPE) #if self.search_type: self.add_inputs() def set_search_type(self, search_type): self.search_type = search_type self.add_inputs() def add_inputs(self): ''' register the inputs ''' hidden = HiddenWdg("%s_process" %self.PUBLISH_TYPE, self.process) self.add_ajax_input(hidden) hidden = HiddenWdg("search_type" ,self.search_type) self.add_ajax_input(hidden) self.related_search_type_wdg = HiddenWdg(self.RELATED_SEARCH_TYPE ,self.related_search_type) self.add_ajax_input(self.related_search_type_wdg) div_id='process_context_wdg' self.main_div = DivWdg(id=div_id) self.set_ajax_top(self.main_div) def get_display(self): search_type = self.search_type related_search_type = self.related_search_type_wdg.get_value() if related_search_type: search_type = related_search_type hier_sel = self.get_hier_sel(search_type) selected_related_search_type = hier_sel.get_value() process_wdg = self.get_process_wdg(search_type) context_wdg = self.get_context_wdg(search_type) widget = self.main_div if self.is_from_ajax(True): widget = Widget() else: self.set_ajax_top(widget) hidden = HiddenWdg("search_type" ,search_type) widget.add(hidden) hier_sel.add_event('onchange', self.get_refresh_script(show_progress=False)) widget.add(hier_sel) #Tooltip doesn't work too well #hint = HintWdg('Related search type you can optionally select to drive the process') widget.add(HtmlElement.br(2)) widget.add(process_wdg) widget.add(context_wdg) return widget def get_hier_sel(self, search_type): sel = SelectWdg(self.RELATED_SEARCH_TYPE, label='Related Search Type: ') sel.add_empty_option() schema = Schema.get() search_type_list = [search_type] if schema: parent_search_type = schema.get_parent_type(search_type) if parent_search_type: search_type_list.append(parent_search_type) child_types = schema.get_child_types(search_type) search_type_list.extend(child_types) sel.set_option('values', search_type_list) sel.set_value(self.related_search_type) return sel def get_process_wdg(self, search_type): '''this should appear in front of the context_filter_wdg''' from pyasm.prod.web import ProcessSelectWdg self.process_select = ProcessSelectWdg(label='Process: ', \ search_type=search_type, css='', has_empty=False, \ name="%s_process" %self.PUBLISH_TYPE) self.process_select.add_empty_option('- Select -') self.process_select.set_event('onchange',\ self.get_refresh_script(show_progress=False)) self.process_select.set_value(self.process) #self.process_select.set_persistence() #self.process_select.set_submit_onchange() # this is only applicable in Shot Tab ''' filter = Container.get('process_fitter') if filter: self.process_select.set_value(filter.get_value()) ''' div = DivWdg(self.process_select) div.add_style('padding-right','10px') return div def get_context_wdg(self, search_type): '''drop down which selects which context to checkin''' # add a filter # use a regular SelectWdg with submit instead of FilterSelectWdg filter_div = FloatDivWdg("Context / subcontext:") select = SelectWdg("publish_context") labels, values = self.get_context_data(search_type, self.process) select.set_option("values", "|".join(values)) select.set_option("labels", "|".join(labels)) select.append_option('publish','publish') select.add_style("font-size: 0.8em") select.add_style("margin: 0px 3px") # explicitly set the value current = select.get_value() if current in values: context = current elif values: context = values[0] else: context = "" web = WebContainer.get_web() web.set_form_value("publish_context", context) select.set_value( context ) # set it to a instance variable self.context_select = select filter_div.add(select) # if specified, add a sub_context base_search_type = SearchType(search_type).get_base_key() settings = ProdSetting.get_value_by_key("%s/sub_context" % context,\ base_search_type) filter_div.add( "/ ") sub_context = None if settings: sub_context = SelectWdg("publish_sub_context") sub_context.set_option("values", settings) sub_context.set_submit_onchange() sub_context.add_empty_option("<- Select ->") else: # provide a text field sub_context = TextWdg("publish_sub_context") sub_context.set_attr('size','10') sub_context.set_persistence() filter_div.add( sub_context ) self.sub_context_select = sub_context #filter_div.add_style('padding-right','10px') return filter_div def get_context_data(self, search_type='', process=''): '''get the labels and values of contexts that can be checked in with this widget''' # TODO: this also shows input contexts ... it should only show output # contexts if not search_type: search_type = self.search_type pipelines = Pipeline.get_by_search_type(search_type, Project.get_project_code() ) if not pipelines: return [], [] # account for sub-pipeline if '/' in process: process = process.split('/', 1)[1] contexts = [] for pipeline in pipelines: pipeline_contexts = [] pipeline_processes = pipeline.get_process_names() if process: if process not in pipeline_processes: continue pipeline_contexts = pipeline.get_output_contexts(process) else: pipeline_contexts = pipeline.get_all_contexts() for context in pipeline_contexts: # for now, cut out the sub_context, until the pipeline # completely defines the sub contexts as well if context.find("/") != -1: parts = context.split("/") context = parts[0] if context not in contexts: contexts.append(context) labels = contexts values = contexts return labels, values
def get_display(my): web = WebContainer.get_web() widget = Widget() div = SpanWdg(css='med') div.set_attr("nowrap", "1") limit_wdg = my.text limit_wdg.add_event( 'onchange', 'if (this.value < 20 || !Common.validate_int(this.value)) this.value=20 ' ) limit_wdg.add_style("margin-top: -3px") limit_wdg.set_attr("size", "1") #limit_wdg.set_value(my.search_limit) offset_wdg = HiddenWdg("%s_last_search_offset" % my.label) offset_wdg.set_value(my.current_offset) #div.add(limit_wdg) div.add(offset_wdg) if my.search or my.sobjects: # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count() # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if my.current_offset == 0 and limit < my.search_limit: return None if my.refresh: prev = IconSubmitWdg("Prev", IconWdg.LEFT, False) next = IconSubmitWdg("Next", IconWdg.RIGHT, False, icon_pos="right") else: prev = IconButtonWdg("Prev", IconWdg.LEFT, False) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name, "") prev.add(hidden) prev.add_event('onclick',"get_elements('%s').set_value('Prev');%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right") hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name, "") next.add(hidden) next.add_event('onclick',"get_elements('%s').set_value('Next');%s" \ %(hidden_name, my.refresh_script)) label_span = SpanWdg("Showing:") label_span.add_style('color', '#c2895d') div.add(label_span) div.add(prev) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset + 1 right_bound = min(my.current_offset + limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: div.add(current_value) else: # add a range selector using ItemsNavigatorWdg from input_wdg import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit, refresh=my.refresh) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) if my.refresh_script: selector.set_refresh_script(my.refresh_script) div.add(selector) div.add(" - ") div.add(limit_wdg) div.add(next) widget.add(div) return widget
def get_display(my): web = WebContainer.get_web() widget = Widget() div = SpanWdg(css='med') div.set_attr("nowrap", "1") limit_wdg = my.text limit_wdg.add_event('onchange', 'if (this.value < 20 || !Common.validate_int(this.value)) this.value=20 ') limit_wdg.add_style("margin-top: -3px") limit_wdg.set_attr("size", "1") #limit_wdg.set_value(my.search_limit) offset_wdg = HiddenWdg("%s_last_search_offset" %my.label) offset_wdg.set_value(my.current_offset) #div.add(limit_wdg) div.add(offset_wdg) if my.search or my.sobjects: # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count() # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if my.current_offset == 0 and limit < my.search_limit: return None if my.refresh: prev = IconSubmitWdg("Prev", IconWdg.LEFT, False ) next = IconSubmitWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) else: prev = IconButtonWdg("Prev", IconWdg.LEFT, False ) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name,"") prev.add(hidden) prev.add_event('onclick',"get_elements('%s').set_value('Prev');%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name,"") next.add(hidden) next.add_event('onclick',"get_elements('%s').set_value('Next');%s" \ %(hidden_name, my.refresh_script)) label_span = SpanWdg("Showing:") label_span.add_style('color','#c2895d') div.add(label_span) div.add( prev ) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset+1 right_bound = min(my.current_offset+limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: div.add( current_value ) else: # add a range selector using ItemsNavigatorWdg from input_wdg import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit, refresh=my.refresh) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) if my.refresh_script: selector.set_refresh_script(my.refresh_script) div.add( selector) div.add( " - ") div.add( limit_wdg) div.add( next ) widget.add(div) return widget
def init_setup(self): hidden = HiddenWdg(self.DELETE_MODE) self.add_ajax_input(hidden) hidden = HiddenWdg(self.NEW_ITEM) self.add_ajax_input(hidden) hidden = HiddenWdg(self.NEW_ITEM_LABEL) self.add_ajax_input(hidden) hidden = HiddenWdg("code_col") self.add_ajax_input(hidden) if not self.is_from_ajax(): hidden.set_value(self.get_option('code_col')) self.add(hidden) hidden = HiddenWdg('ref_search_type') self.add_ajax_input(hidden) if not self.is_from_ajax(): hidden.set_value(self.web.get_form_value('ref_search_type')) self.add(hidden) hidden = HiddenWdg('search_id') self.add_ajax_input(hidden) if self.is_from_ajax(): col_name = self.web.get_form_value('col_name') else: col_name = self.get_name() self.col_name = HiddenWdg('col_name', col_name) self.add_ajax_input(self.col_name) self.select_items = HiddenWdg('%s|%s' %(col_name, self.SELECT_ITEMS)) self.add_ajax_input(self.select_items)