def get_ajax_script(my, tab_name): widget = my.get_widget(tab_name) # load tab thru ajax ajax = AjaxLoader(my.content_div_id) load_args = None widget_class = widget.get_class_name() ajax.set_load_class(widget_class, load_args) if isinstance(widget, MethodWdg): ajax.set_option('method', widget.get_function_name()) for input in my.inputs: ajax.add_element_name(input) for name, value in my.options.items(): ajax.set_option(name, value) script = [] if my.preload_script: script.append(my.preload_script) script.append(ajax.get_on_script()) script.append(my._get_update_script(tab_name)) return ';'.join(script)
def _get_update_script(my, tab_name): '''script to update widget settings''' ajax = AjaxLoader('update') marshaller = ajax.register_cmd("pyasm.command.WidgetSettingsCmd") marshaller.set_option("widget_name", my.tab_key) #marshaller.set_option("key", my.url.get_base()) marshaller.set_option("key", my.__class__.__name__) marshaller.set_option("value", tab_name) return ajax.get_on_script(True)
def get_refresh_script(sobject, icon_size=None, show_progress=True): print "DEPRECATED: Snapshot.get_refresh_script!" # get the ajax loader for the thumbnail ajax = AjaxLoader("thumb_%s" % sobject.get_search_key() ) ajax.set_load_class("pyasm.widget.ThumbWdg") ajax.set_option("search_type", sobject.get_search_type() ) ajax.set_option("search_id", sobject.get_id() ) if icon_size: ajax.set_option("icon_size", icon_size ) return ajax.get_on_script(show_progress=show_progress)
def _get_update_script(my, tab_name ): '''script to update widget settings''' ajax = AjaxLoader('update') marshaller = ajax.register_cmd("pyasm.command.WidgetSettingsCmd") marshaller.set_option("widget_name", my.tab_key) #marshaller.set_option("key", my.url.get_base()) marshaller.set_option("key", my.__class__.__name__) marshaller.set_option("value", tab_name) return ajax.get_on_script(True)
def setup_ajax(my, display_id): # set up ajax ajax = AjaxLoader() ajax.set_load_class(Common.get_full_class_name(my)) ajax.set_display_id(display_id) ajax_inputs = my.get_ajax_inputs() for input in ajax_inputs: ajax.set_option(input, my.__dict__.get(input)) ajax_elements = my.get_ajax_elements() for element in ajax_elements: ajax.add_element_name(element) return ajax.get_on_script()
def get_planned_wdg(self, sobject): search_type = sobject.get_search_type() search_id = sobject.get_id() content_id = 'summary_planned_%s' % sobject.get_id() title_id = 'planned_head_%s' % sobject.get_id() head = DivWdg() head.add_style('height', '1.8em') title = self._get_title_span() dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load.set_load_method('_get_planned_wdg') dyn_load.set_load_class('pyasm.prod.web.ShotDetailWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = self._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" % content_id) head.add(swap_wdg) head.add(title) title.add("Assigned Asset Instances") self.add_title_style(title, title_id, swap_wdg) div = DivWdg(id=content_id) div.add_style("width: 98%") div.add_style("margin-left: auto") div.add_style('display', 'none') return head, div
def get_planned_wdg(my, sobject): search_type = sobject.get_search_type() search_id = sobject.get_id() content_id ='summary_planned_%s' %sobject.get_id() title_id = 'planned_head_%s' %sobject.get_id() head = DivWdg() head.add_style('height','1.8em') title = my._get_title_span() dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load.set_load_method('_get_planned_wdg') dyn_load.set_load_class('pyasm.prod.web.ShotDetailWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = my._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" %content_id) head.add(swap_wdg) head.add(title) title.add("Assigned Asset Instances") my.add_title_style(title, title_id, swap_wdg) div = DivWdg(id=content_id) div.add_style("width: 98%") div.add_style("margin-left: auto") div.add_style('display','none') return head, div
def get_display(my): div = DivWdg() select = SelectWdg("browser_search_type") select.add_empty_option("<- Select ->") search = Search("sthpw/search_object") search.add_order_by("search_type") search_types = my.get_option("search_types") if search_types: search_types = search_types.split("|") search.add_filters("search_type", search_types) select.set_persist_on_submit() select.set_search_for_options(search,"search_type","title") div.add(select) text = TextWdg("browser_search_text") text.set_persist_on_submit() div.add(text) # draw the sobjects sobject_element_id = "sobject_browser" button = ButtonWdg("Search") div.add(button) ajax = AjaxLoader() ajax.set_display_id(sobject_element_id) ajax.set_load_class("pyasm.widget.SObjectBrowserListWdg") ajax.add_element_name("browser_search_type") ajax.add_element_name("browser_search_text") script = ajax.get_on_script() button.add_event("onclick", script) div2 = DivWdg() div2.add_style("display: block") div2.set_id(sobject_element_id) div.add(div2) return div
def get_sobject_wdg(self, sobject, search_type, view="table", title="", show_count=True): key = search_type search_type_obj = SearchType.get(search_type) if not title: title = search_type_obj.get_title() content_id = 'sub_sobj_%s_%s' % (key, sobject.get_id()) title_id = '%s_head_%s' % (key, sobject.get_id()) div = DivWdg(id=content_id) div.add_style('display', 'none') #div.add_style('width','100%') head = DivWdg() head.add_style('height', '1.8em') title_span = self._get_title_span(title) dyn_load = AjaxLoader(display_id=content_id) args_dict = {'sobj_search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() args_dict['search_type'] = search_type args_dict['view'] = view dyn_load.set_load_method('_get_sobject_wdg') dyn_load.set_load_class(Common.get_full_class_name(self), load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = self._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" % content_id) head.add(swap_wdg) head.add(title_span) self.add_title_style(title_span, title_id, swap_wdg) if show_count: search = self._get_sobject_search(sobject, search_type) title_span.add(" ( %s )" % search.get_count()) return head, div
def get_display(self): div = DivWdg() select = SelectWdg("browser_search_type") select.add_empty_option("<- Select ->") search = Search("sthpw/search_object") search.add_order_by("search_type") search_types = self.get_option("search_types") if search_types: search_types = search_types.split("|") search.add_filters("search_type", search_types) select.set_persist_on_submit() select.set_search_for_options(search,"search_type","title") div.add(select) text = TextWdg("browser_search_text") text.set_persist_on_submit() div.add(text) # draw the sobjects sobject_element_id = "sobject_browser" button = ButtonWdg("Search") div.add(button) ajax = AjaxLoader() ajax.set_display_id(sobject_element_id) ajax.set_load_class("pyasm.widget.SObjectBrowserListWdg") ajax.add_element_name("browser_search_type") ajax.add_element_name("browser_search_text") script = ajax.get_on_script() button.add_event("onclick", script) div2 = DivWdg() div2.add_style("display: block") div2.set_id(sobject_element_id) div.add(div2) return div
def get_sobject_history_wdg(my, sobject): search_type = sobject.get_search_type() search_id = sobject.get_id() content_id = 'summary_sobject_history_%s' % sobject.get_id() title_id = 'sobject_history_head_%s' % sobject.get_id() head = DivWdg() head.add_style('height', '1.8em') title = my._get_title_span() dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load.set_load_method('_get_sobject_history_wdg') dyn_load.set_load_class('pyasm.prod.web.AssetDetailWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = my._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" % content_id) head.add(swap_wdg) head.add(title) title.add("Transaction History") search = Search("sthpw/sobject_log") search.add_filter("search_type", search_type) search.add_filter("search_id", search_id) count = search.get_count() title.add(" ( %s )" % count) my.add_title_style(title, title_id, swap_wdg) div = DivWdg(id=content_id) div.add_style("width: 100%") div.add_style("margin-left: auto") div.add_style('display', 'none') return head, div
def get_dailies_wdg(self, sobject): search_type = sobject.get_search_type() search_id = sobject.get_id() dailies_head = DivWdg() dailies_head.add_style('height', '1.8em') dailies_title = self._get_title_span() content_id = 'summary_dailies_%s' % sobject.get_id() title_id = 'dailies_head_%s' % sobject.get_id() args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load = AjaxLoader(display_id=content_id) dyn_load.set_load_method('_get_dailies_wdg') dyn_load.set_load_class('pyasm.prod.web.AssetDetailWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = self._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" % content_id) dailies_head.add(swap_wdg) dailies_head.add(dailies_title) dailies_title.add("Dailies") search = Search("prod/submission") search.add_filter("search_type", search_type) search.add_filter("search_id", search_id) count = search.get_count() dailies_title.add(" ( %s )" % count) self.add_title_style(dailies_title, title_id, swap_wdg) dailies_div = DivWdg(id=content_id) dailies_div.add_style("width: 98%") dailies_div.add_style("margin-left: auto") dailies_div.add_style('display', 'none') return dailies_head, dailies_div
def get_sobject_wdg(my, sobject, search_type, view="table", title="", show_count=True): key = search_type search_type_obj = SearchType.get(search_type) if not title: title = search_type_obj.get_title() content_id ='sub_sobj_%s_%s' % (key, sobject.get_id()) title_id = '%s_head_%s' % (key, sobject.get_id()) div = DivWdg(id=content_id) div.add_style('display','none') #div.add_style('width','100%') head = DivWdg() head.add_style('height','1.8em') title_span = my._get_title_span(title) dyn_load = AjaxLoader(display_id=content_id) args_dict = {'sobj_search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() args_dict['search_type'] = search_type args_dict['view'] = view dyn_load.set_load_method('_get_sobject_wdg') dyn_load.set_load_class(Common.get_full_class_name(my), load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = my._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" %content_id) head.add(swap_wdg) head.add(title_span) my.add_title_style(title_span, title_id, swap_wdg) if show_count: search = my._get_sobject_search(sobject, search_type) title_span.add(" ( %s )" % search.get_count() ) return head, div
def get_dailies_wdg(my, sobject): search_type = sobject.get_search_type() search_id = sobject.get_id() dailies_head = DivWdg() dailies_head.add_style('height','1.8em') dailies_title = my._get_title_span() content_id ='summary_dailies_%s' %sobject.get_id() title_id = 'dailies_head_%s' %sobject.get_id() args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load = AjaxLoader(display_id=content_id) dyn_load.set_load_method('_get_dailies_wdg') dyn_load.set_load_class('pyasm.prod.web.AssetDetailWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = my._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" %content_id) dailies_head.add(swap_wdg) dailies_head.add(dailies_title) dailies_title.add("Dailies") search = Search("prod/submission") search.add_filter("search_type", search_type) search.add_filter("search_id", search_id) count = search.get_count() dailies_title.add( " ( %s )" % count ) my.add_title_style(dailies_title, title_id, swap_wdg) dailies_div = DivWdg(id=content_id) dailies_div.add_style("width: 98%") dailies_div.add_style("margin-left: auto") dailies_div.add_style('display','none') return dailies_head, dailies_div
def get_sobject_history_wdg(self, sobject): search_type = sobject.get_search_type() search_id = sobject.get_id() content_id ='summary_sobject_history_%s' %sobject.get_id() title_id = 'sobject_history_head_%s' %sobject.get_id() head = DivWdg() head.add_style('height','1.8em') title = self._get_title_span() dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load.set_load_method('_get_sobject_history_wdg') dyn_load.set_load_class('pyasm.prod.web.AssetDetailWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) swap_wdg = self._get_swap_wdg(title_id) swap_wdg.add_action_script(on_script, "toggle_display('%s')" %content_id) head.add(swap_wdg) head.add(title) title.add("Transaction History") search = Search("sthpw/sobject_log") search.add_filter("search_type", search_type) search.add_filter("search_id", search_id) count = search.get_count() title.add( " ( %s )" % count ) self.add_title_style(title, title_id, swap_wdg) div = DivWdg(id=content_id) div.add_style("width: 100%") div.add_style("margin-left: auto") div.add_style('display','none') return head, div
def setup_ajax(self, display_id): # set up ajax ajax = AjaxLoader() ajax.set_load_class(Common.get_full_class_name(self)) ajax.set_display_id(display_id) ajax_inputs = self.get_ajax_inputs() for input in ajax_inputs: ajax.set_option(input, self.__dict__.get(input)) ajax_elements = self.get_ajax_elements() for element in ajax_elements: ajax.add_element_name(element) return ajax.get_on_script()
def get_display(my): my.task_per_process_dict = {} # get the sobject and relevent parameters sobject = my.get_current_sobject() search_type = sobject.get_search_type() if my.pipeline_code: pipeline = Pipeline.get_by_code(my.pipeline_code) else: pipeline = Pipeline.get_by_sobject(sobject, allow_default=True) if not pipeline: # while default is auto-generated, an empty pipeline code will trigger this Environment.add_warning('missing pipeline code', \ "Pipeline code is empty for [%s]" %sobject.get_code()) return if my.include_sub_task_value: my.recurse = True processes = pipeline.get_processes(recurse=my.recurse) # filter out process names if my.process_names != None: filtered_processes = [] for process in processes: if process.get_name() in my.process_names: filtered_processes.append(process) processes = filtered_processes # draw the proceses top = DivWdg() action = DivWdg() action.add_style("float: right") top.add(action) table = Table() table.add_style("font-size: 11px") top.add(table) #if my.max_count: # percent_width = float(len(processes)) / float(my.max_count+1) * 100 #else: # percent_width = 100 # we want them more squeezed together when in abbr mode if my.label_select_value != 'abbr': percent_width = 100 table.add_style("width: %d%%" % percent_width) tr = table.add_row() for process in processes: completion_wdg = my.get_completion(sobject, process,\ len(processes)) if not completion_wdg: continue td = table.add_cell( completion_wdg ) td.add_style('border-width: 0px') tr = table.add_row(css='underline') tr.add_color("color", "color") label_format = my.get_option("label_format") if not label_format: label_format = my.label_select_value tup_list = my._get_labels(processes, label_format, show_sub_pipeline=my.is_ajax()) style = '' for i, tup in enumerate(tup_list): name, process = tup span = SpanWdg() child_pipeline = process.get_child_pipeline() if child_pipeline: title = SpanWdg() title.add("[%s]" % name) title.add_style("margin-left: -5px") swap = SwapDisplayWdg.get_triangle_wdg() content_id = '%s_%s' %(sobject.get_search_key(), child_pipeline.get_id()) content_id = my.generate_unique_id(content_id) content = DivWdg(id=content_id) SwapDisplayWdg.create_swap_title(title, swap, content) dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() args_dict['pipeline_skey'] = child_pipeline.get_search_key() dyn_load.set_load_method('_get_child_wdg') dyn_load.set_load_class('pyasm.widget.ParallelStatusWdg', load_args=args_dict) dyn_load.add_element_name('cal_sub_task') on_script = dyn_load.get_on_script(load_once=True) swap.add_action_script(on_script, "set_display_off('%s')" %content_id) script = "if ($(%s).getStyle('display')=='none') {%s}" \ %(swap.swap1_id, on_script) title.add_event('onclick', script) span.add(swap) span.add(title) span.add(HtmlElement.br()) span.add(HtmlElement.br()) span.add(content) else: span.add(name) if my.task_per_process_dict.get(process) == 0: span.add_class('unused') if label_format == 'small' or label_format == 'abbr': span.add_class('smaller') if not label_format == "none": table.add_cell(span) return top
def get_display(self): self.task_per_process_dict = {} # get the sobject and relevent parameters sobject = self.get_current_sobject() search_type = sobject.get_search_type() if self.pipeline_code: pipeline = Pipeline.get_by_code(self.pipeline_code) else: pipeline = Pipeline.get_by_sobject(sobject, allow_default=True) if not pipeline: # while default is auto-generated, an empty pipeline code will trigger this Environment.add_warning('missing pipeline code', \ "Pipeline code is empty for [%s]" %sobject.get_code()) return if self.include_sub_task_value: self.recurse = True processes = pipeline.get_processes(recurse=self.recurse) # filter out process names if self.process_names != None: filtered_processes = [] for process in processes: if process.get_name() in self.process_names: filtered_processes.append(process) processes = filtered_processes # draw the proceses top = DivWdg() action = DivWdg() action.add_style("float: right") top.add(action) table = Table() table.add_style("font-size: 11px") top.add(table) #if self.max_count: # percent_width = float(len(processes)) / float(self.max_count+1) * 100 #else: # percent_width = 100 # we want them more squeezed together when in abbr mode if self.label_select_value != 'abbr': percent_width = 100 table.add_style("width: %d%%" % percent_width) tr = table.add_row() for process in processes: completion_wdg = self.get_completion(sobject, process,\ len(processes)) if not completion_wdg: continue td = table.add_cell(completion_wdg) td.add_style('border-width: 0px') tr = table.add_row(css='underline') tr.add_color("color", "color") label_format = self.get_option("label_format") if not label_format: label_format = self.label_select_value tup_list = self._get_labels(processes, label_format, show_sub_pipeline=self.is_ajax()) style = '' for i, tup in enumerate(tup_list): name, process = tup span = SpanWdg() child_pipeline = process.get_child_pipeline() if child_pipeline: title = SpanWdg() title.add("[%s]" % name) title.add_style("margin-left: -5px") swap = SwapDisplayWdg.get_triangle_wdg() content_id = '%s_%s' % (sobject.get_search_key(), child_pipeline.get_id()) content_id = self.generate_unique_id(content_id) content = DivWdg(id=content_id) SwapDisplayWdg.create_swap_title(title, swap, content) dyn_load = AjaxLoader(display_id=content_id) args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() args_dict['pipeline_skey'] = child_pipeline.get_search_key() dyn_load.set_load_method('_get_child_wdg') dyn_load.set_load_class('pyasm.widget.ParallelStatusWdg', load_args=args_dict) dyn_load.add_element_name('cal_sub_task') on_script = dyn_load.get_on_script(load_once=True) swap.add_action_script(on_script, "set_display_off('%s')" % content_id) script = "if ($(%s).getStyle('display')=='none') {%s}" \ %(swap.swap1_id, on_script) title.add_event('onclick', script) span.add(swap) span.add(title) span.add(HtmlElement.br()) span.add(HtmlElement.br()) span.add(content) else: span.add(name) if self.task_per_process_dict.get(process) == 0: span.add_class('unused') if label_format == 'small' or label_format == 'abbr': span.add_class('smaller') if not label_format == "none": table.add_cell(span) return top