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_wdg(my, 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 = my.get_context_data(search_type, my.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 my.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 ) my.sub_context_select = sub_context #filter_div.add_style('padding-right','10px') return filter_div
class TaskAssetCreateSelectWdg(CreateSelectWdg): ''' Create a list of asset for multi task creations''' 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) def get_delimiter(self): return '||' def get_search_key(self): search_key = '%s|%s' % (self.web.get_form_value('ref_search_type'), \ self.web.get_form_value('search_id')) return search_key def get_item_list(self, items): self.select = SelectWdg(self.SELECT_NAME) self.select.set_attr("size", '%s' %(len(items)+1)) if items == ['']: return self.select self.select.set_option('values', items) code_col = self.web.get_form_value('code_col') labels = [] # assume they are all the same search type search_ids = [item.split("|", 1)[1] for item in items] search_type = '' if items: search_type = items[0].split('|', 1)[0] if search_type and search_ids: sobjs = Search.get_by_id(search_type, search_ids) for sobj in sobjs: name = sobj.get_name() code = sobj.get_code() if code_col and sobj.has_value(code_col): code = sobj.get_value(code_col) if name == code: labels.append(code) else: labels.append('%s - %s' %(code, name)) self.select.set_option('labels', labels) return self.select def get_type_select(self, item_type): return FloatDivWdg(' ', width=100) def draw_widgets(self, widget, delete_widget, item_span): '''actually drawing the widgets''' widget.add(item_span) widget.add(HtmlElement.br(2)) widget.add(SpanWdg(self.select, css='med')) widget.add(delete_widget) widget.add(HtmlElement.br(2)) def get_sequence_wdg(self): text_span = SpanWdg('New item ') current = self.get_my_sobject() search_type = get_search_type() select = SelectWdg(self.NEW_ITEM) select.set_option('web_state', self.get_option('web_state') ) # get all of the options for this search type search = Search(search_type) search.add_order_by("code") sobjects = search.get_sobjects() if not sobjects: raise SetupException("No Assets defined. Please create assets to add tasks to") values = [x.get_search_key() for x in sobjects] labels = [] code_col = self.web.get_form_value('code_col') for x in sobjects: name = x.get_name() code = x.get_code() if code_col and x.has_value(code_col): code = x.get_value(code_col) if name == code: labels.append(code) else: labels.append("%s - %s" % (code, name) ) select.set_option("values", values) select.set_option("labels", labels) # transfer the options for key, value in self.options.items(): select.set_option(key, value) # extra code not needed here. setting web_state to true in the config # is sufficient, still not perfect yet. if not current: pass else: search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") ) select.set_value(search_key) button = self.get_sequence_button() text_span.add(select) text_span.add(button) return text_span def get_sequence_button(self): # add button widget = Widget() from pyasm.prod.web import ProdIconButtonWdg add = ProdIconButtonWdg('Add') script = ["append_item('%s','%s')" % (self.SELECT_NAME, self.NEW_ITEM )] script.append( self.get_refresh_script() ) add.add_event('onclick', ';'.join(script)) widget.add(add) hint = HintWdg('Add one or more items to the list.', title='Tip') widget.add(hint) return widget