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
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_sequence_wdg(my): text_span = SpanWdg('New item ') current = my.get_my_sobject() search_type = get_search_type() select = SelectWdg(my.NEW_ITEM) select.set_option('web_state', my.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 = my.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 my.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 = my.get_sequence_button() text_span.add(select) text_span.add(button) return text_span
def get_sequence_wdg(my): text_span = SpanWdg('New item ') current = my.get_my_sobject() search_type = get_search_type() select = SelectWdg(my.NEW_ITEM) select.set_option('web_state', my.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 = my.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 my.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 = my.get_sequence_button() text_span.add(select) text_span.add(button) return text_span
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_hier_sel(my, search_type): sel = SelectWdg(my.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(my.related_search_type) return sel
def _add_week(my, main_div, week, widget): '''add week display''' week_name = 'week_%s' % my.task.get_search_key() year_name = 'year_%s' % my.task.get_search_key() weeks = [i for i in xrange(1, 53)] week_filter = SelectWdg(week_name) week_filter.add_class('med') week_filter.set_option('values', weeks) week_filter.set_value(week) #widget.add_ajax_input(week_text) # add the name to the TimecardHourCmd widget.get_cmd().add_element_name(week_name) refresh_script = widget.get_refresh_script() week_filter.add_event('onchange', refresh_script) script = [ TimecardTaskRowWdg.get_script(week_name, year_name, add=False) ] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_LEFT) link = HtmlElement.js_href(';'.join(script), data=img) div = _get_div(20) div.add(link) main_div.add(div) div = _get_div(70) div.add("Wk ") div.add(week_filter) main_div.add(div) div = _get_div(20) script = [ TimecardTaskRowWdg.get_script(week_name, year_name, add=True) ] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_RIGHT) link = HtmlElement.js_href(';'.join(script), data=img) div.add(link) main_div.add(div)
def _add_week(my, main_div, week, widget): '''add week display''' week_name = 'week_%s' %my.task.get_search_key() year_name = 'year_%s' %my.task.get_search_key() weeks = [i for i in xrange(1, 53)] week_filter = SelectWdg(week_name) week_filter.add_class('med') week_filter.set_option('values', weeks) week_filter.set_value(week) #widget.add_ajax_input(week_text) # add the name to the TimecardHourCmd widget.get_cmd().add_element_name(week_name) refresh_script = widget.get_refresh_script() week_filter.add_event('onchange', refresh_script) script = [TimecardTaskRowWdg.get_script(week_name, year_name, add=False)] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_LEFT) link = HtmlElement.js_href(';'.join(script), data=img) div = _get_div(20) div.add(link) main_div.add(div) div = _get_div(70) div.add("Wk ") div.add(week_filter) main_div.add(div) div = _get_div(20) script = [TimecardTaskRowWdg.get_script(week_name, year_name, add=True)] script.append(refresh_script) img = IconWdg(icon=IconWdg.ARROW_RIGHT) link = HtmlElement.js_href(';'.join(script), data=img) div.add(link) main_div.add(div)
def get_display(my): current = my.get_current_sobject() parent_search_type = current.get_value('search_type') if not parent_search_type: return "No parent type" search_type = parent_search_type web = WebContainer.get_web() is_edit = not current.is_insert() # start a search search = Search(search_type) widget = Widget() # avoid a search key == '|' parent_search_key = '' if is_edit and current.get_value("search_type"): parent_search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") ) #parent_search_key = web.get_form_value("edit|parent") my.categorize(widget, search_type, search) select = SelectWdg(my.get_input_name()) widget.add(select) select.set_option('web_state', my.get_option('web_state') ) search.add_order_by("code") sobjects = [] if is_edit: if parent_search_key: sobjects = [Search.get_by_search_key(parent_search_key)] else: sobjects = search.get_sobjects() # Task planner task don't have a parent if not sobjects and search_type !='sthpw/task': span = SpanWdg("No Parents Defined. Parents for this task should be inserted first.") span.add_style("color: #f44") widget.add(span) return widget values = [x.get_search_key() for x in sobjects] labels = [] code_col = my.get_option('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 my.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 current.is_insert(): pass else: select.set_value(parent_search_key) return widget
def get_display(self): current = self.get_current_sobject() parent_search_type = current.get_value('search_type') if not parent_search_type: return "No parent type" search_type = parent_search_type web = WebContainer.get_web() is_edit = not current.is_insert() # start a search search = Search(search_type) widget = Widget() # avoid a search key == '|' parent_search_key = '' if is_edit and current.get_value("search_type"): parent_search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") ) #parent_search_key = web.get_form_value("edit|parent") self.categorize(widget, search_type, search) select = SelectWdg(self.get_input_name()) widget.add(select) select.set_option('web_state', self.get_option('web_state') ) search.add_order_by("code") sobjects = [] if is_edit: if parent_search_key: sobjects = [Search.get_by_search_key(parent_search_key)] else: sobjects = search.get_sobjects() # Task planner task don't have a parent if not sobjects and search_type !='sthpw/task': span = SpanWdg("No Parents Defined. Parents for this task should be inserted first.") span.add_style("color: #f44") widget.add(span) return widget values = [x.get_search_key() for x in sobjects] labels = [] code_col = self.get_option('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 current.is_insert(): pass else: select.set_value(parent_search_key) return widget