def get_display(my): my.context = '' sobject = my.get_current_sobject() if sobject.get_base_search_type() in ['sthpw/task', 'sthpw/note']: my.process = sobject.get_value('process') my.context = sobject.get_value('context') if not my.process: my.process = '' sobject_mode = my.kwargs.get("sobject_mode") if not sobject_mode: sobject_mode = "parent" #sobject_mode = "connect" if sobject_mode == "parent": parent = sobject.get_parent() elif sobject_mode == "connect": parent = Search.eval("@SOBJECT(connect)", sobject, single=True) elif sobject_mode == "expression": expression = "???" parent = Search.eval("@SOBJECT(connect)", sobject, single=True) else: parent = sobject if not parent: return DivWdg() search_key = SearchKey.get_by_sobject(parent) else: my.process = my.get_option('process') if not my.process: my.process = "publish" search_key = SearchKey.get_by_sobject(sobject) #my.behavior['process'] = my.process #my.behavior['context'] = my.context #my.behavior['search_key'] = search_key # set the atrs div = super(CheckinButtonElementWdg, my).get_display() div.add_attr("spt_process", my.process) div.add_attr("spt_context", my.context) div.add_attr("spt_search_key", search_key) return div
def execute(self): self.search_key_list = self.kwargs.get('search_key_list') web = WebContainer.get_web() skip_duplicated = web.get_form_value('skip_duplicated') == 'on' pipeline_mode = web.get_form_value('pipeline_mode') sobjects = SearchKey.get_by_search_keys(self.search_key_list) count = 0 offset = 0 for sobject in sobjects: if isinstance(sobject, Task): raise TacticException('Creation of task for [Task] is not allowed') sk = SearchKey.get_by_sobject(sobject) if not sobject.has_value('pipeline_code'): #raise TacticException('Creation of task is not allowed for item with no pipeline_code attribute.') pipeline_code = '__default__' sobject.set_value("pipeline_code", pipeline_code) else: pipeline_code = sobject.get_value('pipeline_code') input_name = '%s|task_process'% pipeline_code contexts = [] process_names = web.get_form_values(input_name) process_names = [name for name in process_names if name] if pipeline_mode == 'context': # when pipeline_mode is context, we only specify contexts # in add_initial_tasks contexts = process_names[:] process_names = [] tasks = Task.add_initial_tasks(sobject, sobject.get_value('pipeline_code'), processes=process_names, contexts=contexts, skip_duplicate=skip_duplicated, mode=pipeline_mode, start_offset=offset) count += len(tasks) offset += 5 self.add_description("%s Tasks added in total." % count)
def get_display(my): div = DivWdg() sobject = my.get_current_sobject() search_key = SearchKey.get_by_sobject(sobject) if sobject.is_admin(): return "ADMIN" icon = IconButtonWdg("Global Permissions", IconWdg.EDIT) icon.add_behavior( { "type": "click_up", "cbjs_action": "spt.popup.get_widget(evt, bvr)", "options": { "class_name": "tactic.ui.panel.SecurityManagerWdg", "title": "Permisssion Manager", "popup_id": "Permission Manager" }, "args": { "search_key": search_key } } ) div.add(icon) return div
def get_action_html(my): search_key = SearchKey.get_by_sobject(my.sobjects[0]) behavior_submit = { 'type': 'click_up', 'cb_fire_named_event': 'append_pressed', 'element_names': my.element_names, 'search_key': search_key, 'input_prefix': my.input_prefix } behavior_cancel = { 'type': 'click_up', 'cb_fire_named_event': 'preclose_edit_popup', 'cbjs_postaction': "spt.popup.destroy( spt.popup.get_popup( $('edit_popup') ) );" } button_list = [{'label': "%s/Close" % my.mode.capitalize(), 'bvr': behavior_submit}, {'label': "Cancel", 'bvr': behavior_cancel}] edit_close = TextBtnSetWdg( buttons=button_list, spacing =6, size='large', \ align='center',side_padding=10) div = DivWdg() div.add_styles('height: 35px; margin-top: 10px;') div.center() div.add(edit_close) return div
def add_sobject_to_cache(self, sobject): '''add an sobject to the cache. This is useful if a new sobject has been inserted and it is too expensive to have to recache the entire table just for this one entry''' # make sure this sobject's search type is the same as the search type # for this cache search_type = sobject.get_base_search_type() assert search_type == self.search_type # FIXME: add to all of the caches for key, cache in self.caches.items(): if key == 'search_key': # add to the search_key cache search_key = SearchKey.get_by_sobject(sobject) cache[search_key] = sobject elif key == 'code': # add to the code cache code = sobject.get_code() cache[code] = sobject else: value = sobject.get_value(key) cache[value] = sobject # make sure this cache is set to dirty so other processes update self.make_dirty()
def execute(my): my.search_key_list = my.kwargs.get('search_key_list') web = WebContainer.get_web() skip_duplicated = web.get_form_value('skip_duplicated') == 'on' pipeline_mode = web.get_form_value('pipeline_mode') sobjects = SearchKey.get_by_search_keys(my.search_key_list) count = 0 offset = 0 for sobject in sobjects: if isinstance(sobject, Task): raise TacticException('Creation of task for [Task] is not allowed') sk = SearchKey.get_by_sobject(sobject) if not sobject.has_value('pipeline_code'): #raise TacticException('Creation of task is not allowed for item with no pipeline_code attribute.') pipeline_code = '__default__' sobject.set_value("pipeline_code", pipeline_code) else: pipeline_code = sobject.get_value('pipeline_code') input_name = '%s|task_process'% pipeline_code contexts = [] process_names = web.get_form_values(input_name) process_names = [name for name in process_names if name] if pipeline_mode == 'context': # when pipeline_mode is context, we only specify contexts # in add_initial_tasks contexts = process_names[:] process_names = [] tasks = Task.add_initial_tasks(sobject, sobject.get_value('pipeline_code'), processes=process_names, contexts=contexts, skip_duplicate=skip_duplicated, mode=pipeline_mode, start_offset=offset) count += len(tasks) offset += 5 my.add_description("%s Tasks added in total." % count)
def add_header(self, table, title): table.add_style('width', '50em') parent_st = self.kwargs.get('parent_search_type') parent_sid = self.kwargs.get('parent_search_id') parent_context = '' parent_version = '' sobj = Search.get_by_id(parent_st, parent_sid) sobj_code = 'New' sobj_title = '' if sobj: sobj_code = sobj.get_code() sobj_title = sobj.get_search_type_obj().get_title() if isinstance(sobj, Snapshot): parent_context = sobj.get_context() parent_version = sobj.get_version() th = table.add_header( "Add Submission for %s [%s]" % (sobj_title, sobj_code)) th.set_attr("colspan", "2") hidden = HiddenWdg('parent_search_type', parent_st ) th.add(hidden) hidden = HiddenWdg('parent_search_id', parent_sid ) th.add(hidden) hidden = HiddenWdg('parent_context', parent_context ) th.add(hidden) hidden = HiddenWdg('parent_version', parent_version ) th.add(hidden) if sobj: hidden = HiddenWdg('parent_search_key', SearchKey.get_by_sobject(sobj) ) th.add(hidden)
def add_header(my, table, title): table.add_style('width', '50em') parent_st = my.kwargs.get('parent_search_type') parent_sid = my.kwargs.get('parent_search_id') parent_context = '' parent_version = '' sobj = Search.get_by_id(parent_st, parent_sid) sobj_code = 'New' sobj_title = '' if sobj: sobj_code = sobj.get_code() sobj_title = sobj.get_search_type_obj().get_title() if isinstance(sobj, Snapshot): parent_context = sobj.get_context() parent_version = sobj.get_version() th = table.add_header("Add Submission for %s [%s]" % (sobj_title, sobj_code)) th.set_attr("colspan", "2") hidden = HiddenWdg('parent_search_type', parent_st) th.add(hidden) hidden = HiddenWdg('parent_search_id', parent_sid) th.add(hidden) hidden = HiddenWdg('parent_context', parent_context) th.add(hidden) hidden = HiddenWdg('parent_version', parent_version) th.add(hidden) if sobj: hidden = HiddenWdg('parent_search_key', SearchKey.get_by_sobject(sobj)) th.add(hidden)
def get_section_wdg(self, sobject): parent_key = SearchKey.get_by_sobject(sobject) section_id = "wow" title = "" view = "children" target_id = "sobject_relation" kwargs = { 'section_id': section_id, 'title': title, 'view': view, 'target_id': target_id, 'width': '125', 'parent_key': parent_key } section_div = DivWdg() section_div.add_style("display: block") section_div.set_id(section_id) section_div.set_attr('spt_class_name', "tactic.ui.panel.ChildrenBookmarkMenuWdg") for name, value in kwargs.items(): if name == "config": continue section_div.set_attr("spt_%s" % name, value) section_wdg = SObjectChildrenMenuWdg(**kwargs) section_div.add(section_wdg) return section_div
def add_sobject_to_cache(my, sobject): '''add an sobject to the cache. This is useful if a new sobject has been inserted and it is too expensive to have to recache the entire table just for this one entry''' # make sure this sobject's search type is the same as the search type # for this cache search_type = sobject.get_base_search_type() assert search_type == my.search_type # FIXME: add to all of the caches for key, cache in my.caches.items(): if key == 'search_key': # add to the search_key cache search_key = SearchKey.get_by_sobject(sobject) cache[search_key] = sobject elif key == 'code': # add to the code cache code = sobject.get_code() cache[code] = sobject else: value = sobject.get_value(key) cache[value] = sobject # make sure this cache is set to dirty so other processes update my.make_dirty()
def get_section_wdg(my, sobject): parent_key = SearchKey.get_by_sobject(sobject) section_id = "wow" title = "" view = "children" target_id = "sobject_relation" kwargs = { 'section_id': section_id, 'title': title, 'view': view, 'target_id': target_id, 'width': '125', 'parent_key': parent_key } section_div = DivWdg() section_div.add_style("display: block") section_div.set_id(section_id) section_div.set_attr('spt_class_name', "tactic.ui.panel.ChildrenBookmarkMenuWdg") for name, value in kwargs.items(): if name == "config": continue section_div.set_attr("spt_%s" % name, value) section_wdg = SObjectChildrenMenuWdg(**kwargs) section_div.add(section_wdg) return section_div
def get_display(my): sobject = my.get_current_sobject() my.search_key = SearchKey.get_by_sobject(sobject) div = DivWdg() div.add_class("hand") title = "Show Item Details" if my.widget: widget = my.widget else: widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM) code = sobject.get_code() name = sobject.get_value("name", no_exception=True) if not name: name = code widget.add_behavior( { 'type': 'click_up', 'search_key': my.search_key, 'code': code, 'name': name, 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.TaskDetailPanelWdg'; var kwargs = { search_key: bvr.search_key, }; var mode = ''; var layout = bvr.src_el.getParent(".spt_tool_top"); if (layout != null) { mode = 'tool' } if (mode == 'tool') { spt.app_busy.show("Loading ..."); var layout = bvr.src_el.getParent(".spt_tool_top"); var element = layout.getElement(".spt_tool_content"); spt.panel.load(element, class_name, kwargs); spt.app_busy.hide(); } else { var element_name = "detail_"+bvr.code; var title = "Detail ["+bvr.name+"]"; spt.tab.add_new(element_name, title, class_name, kwargs); } ''' } ) div.add(widget) return div
def get_no_icon_wdg(my, missing=False): sobject = my.get_current_sobject() if not sobject: return '' div = my.top div.add_style("position: relative") div.add_style("margin: 3px") div.add_class("spt_thumb_top") div.set_id( "thumb_%s" % sobject.get_search_key() ) icon_size = my.get_icon_size() if icon_size: div.add_style("%s: %s" % (my.aspect, icon_size) ) if missing: img = HtmlElement.img(ThumbWdg.get_missing_image()) elif sobject.get_value("_is_collection", no_exception=True): img = HtmlElement.img("/context/icons/mime-types/folder2.jpg") else: img = HtmlElement.img(ThumbWdg.get_no_image()) img.add_class("spt_image") #from tactic.ui.table import SObjectDetailElementWdg #detail = SObjectDetailElementWdg() #detail.set_widget(img) #detail.set_sobject(sobject) #div.add(detail) div.add(img) div.add_class("hand") if my.SQL_ERROR: warning_div = DivWdg('<i>-- preprocess error --</i>') warning_div.add_styles('position: absolute; z-index: 100; float: left; top: 0; left: 0; font-size: smaller;') div.add_style('position: relative') div.add(warning_div) search_key = SearchKey.get_by_sobject(sobject) code = sobject.get_code() detail = my.get_option("detail") if detail != 'false': my.add_icon_behavior(div, sobject) unit = None if isinstance(icon_size, basestring): icon_size, unit = my.split_icon_size(icon_size) img.add_style("%s: 100%%" % my.aspect ) else: img.add_style("%s: %s" % (my.aspect, my.get_icon_size()) ) img.add_style("min-%s: 15px" % my.aspect) return div
def get_custom_layout_wdg(my, layout_view): content_div = DivWdg() from tactic.ui.panel import CustomLayoutWdg layout = CustomLayoutWdg(view=layout_view) content_div.add(layout) for widget in my.widgets: name = widget.get_name() if my.input_prefix: widget.set_input_prefix(my.input_prefix) layout.add_widget(widget, name) search_key = SearchKey.get_by_sobject(my.sobjects[0], use_id=True) search_type = my.sobjects[0].get_base_search_type() element_names = my.element_names[:] for element_name in my.skipped_element_names: element_names.remove(element_name) config_xml = my.kwargs.get("config_xml") bvr = { 'type': 'click_up', 'mode': my.mode, 'element_names': element_names, 'search_key': search_key, 'input_prefix': my.input_prefix, 'view': my.view, 'config_xml': config_xml } if my.mode == 'insert': bvr['refresh'] = 'true' # for adding parent relationship in EditCmd if my.parent_key: bvr['parent_key'] = my.parent_key hidden_div = DivWdg() hidden_div.add_style("display: none") content_div.add(hidden_div) hidden = TextAreaWdg("__data__") hidden_div.add(hidden) hidden.set_value( jsondumps(bvr) ) show_action = my.kwargs.get("show_action") if show_action in [True, 'true']: content_div.add( my.get_action_html() ) return content_div
def get_item_div(my, sobject): ''' get the item div the sobject''' top = DivWdg() top.add_style("padding: 3px 2px") top.add_class("spt_drop_item") top.add_class("SPT_DROP_ITEM") item_div = DivWdg() top.add(item_div, "item_div") item_div.add_style("text-overflow: ellipsis") item_div.add_style("white-space: nowrap") item_div.add_style("width: 80%") item_div.add_attr('title', 'Click to remove') item_div.add_style("display", "inline-block") item_div.add_style("vertical-align", "top") item_div.add_style("overflow", "hidden") icon_div = DivWdg() top.add(icon_div) icon = IconWdg(icon="BS_REMOVE") icon_div.add(icon) icon_div.add_behavior({ 'type': 'click_up', #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)''' 'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)''' }) icon.add_style("opacity: 0.3") icon_div.add_class("hand") icon_div.add_style("display", "inline-block") icon_div.add_style("vertical-align", "top") #icon_div.add_border() #my.menu.set_over(item_div, event="mousein") #my.menu.set_out(top, event="mouseleave") # set this as the place for the display value to go item_div.add_class("spt_drop_display_value") add_icon = True ExpressionParser.clear_cache() if sobject: if add_icon: my._add_icon(sobject, item_div) if my.display_expr: display_value = Search.eval(my.display_expr, sobjects=sobject, single=True) else: display_value = sobject.get_display_value() if isinstance(display_value, list): display_value = display_value[0] item_div.add(display_value) my.values.append(SearchKey.get_by_sobject(sobject)) return top
def get_item_div(self, sobject): ''' get the item div the sobject''' top = DivWdg() top.add_style("padding: 3px 2px") top.add_class("spt_drop_item") top.add_class("SPT_DROP_ITEM") item_div = DivWdg() top.add(item_div, "item_div") item_div.add_style("text-overflow: ellipsis") item_div.add_style("white-space: nowrap") item_div.add_style("width: 80%") item_div.add_attr('title','Click to remove') item_div.add_style("display", "inline-block") item_div.add_style("vertical-align", "top") item_div.add_style("overflow", "hidden") icon_div = DivWdg() top.add(icon_div) icon = IconWdg(icon="BS_REMOVE") icon_div.add(icon) icon_div.add_behavior( { 'type': 'click_up', #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)''' 'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)''' } ) icon.add_style("opacity: 0.3") icon_div.add_class("hand") icon_div.add_style("display", "inline-block") icon_div.add_style("vertical-align", "top") #icon_div.add_border() #self.menu.set_over(item_div, event="mousein") #self.menu.set_out(top, event="mouseleave") # set this as the place for the display value to go item_div.add_class("spt_drop_display_value") add_icon = True ExpressionParser.clear_cache() if sobject: if add_icon: self._add_icon(sobject, item_div) if self.display_expr: display_value = Search.eval(self.display_expr, sobjects = sobject, single=True) else: display_value = sobject.get_display_value() if isinstance(display_value, list): display_value = display_value[0] item_div.add( display_value ) self.values.append( SearchKey.get_by_sobject(sobject) ) return top
def get_no_icon_wdg(my, missing=False): sobject = my.get_current_sobject() if not sobject: return '' div = my.top div.add_style("position: relative") div.add_style("margin: 3px") div.add_class("spt_thumb_top") div.set_id( "thumb_%s" % sobject.get_search_key() ) icon_size = my.get_icon_size() if icon_size: div.add_style("%s: %s" % (my.aspect, icon_size) ) if missing: img = HtmlElement.img(ThumbWdg.get_missing_image()) else: img = HtmlElement.img(ThumbWdg.get_no_image()) img.add_class("spt_image") #from tactic.ui.table import SObjectDetailElementWdg #detail = SObjectDetailElementWdg() #detail.set_widget(img) #detail.set_sobject(sobject) #div.add(detail) div.add(img) div.add_class("hand") if my.SQL_ERROR: warning_div = DivWdg('<i>-- preprocess error --</i>') warning_div.add_styles('position: absolute; z-index: 100; float: left; top: 0; left: 0; font-size: smaller;') div.add_style('position: relative') div.add(warning_div) search_key = SearchKey.get_by_sobject(sobject) code = sobject.get_code() detail = my.get_option("detail") if detail != 'false': my.add_icon_behavior(div, sobject) if type(icon_size) == types.StringType and icon_size.endswith("%"): img.add_style("%s: 100%%" % my.aspect ) else: img.add_style("%s: %spx" % (my.aspect, my.get_icon_size()) ) img.add_style("min-%s: 15px" % my.aspect) return div
def get_no_icon_wdg(my, missing=False): sobject = my.get_current_sobject() if not sobject: return '' div = my.top div.add_style("position: relative") div.add_style("margin: 3px") div.set_id( "thumb_%s" % sobject.get_search_key() ) icon_size = my.get_icon_size() if icon_size: div.add_style("%s: %s" % (my.aspect, icon_size) ) if missing: img = HtmlElement.img(ThumbWdg.get_missing_image()) else: img = HtmlElement.img(ThumbWdg.get_no_image()) img.add_class("spt_image") #from tactic.ui.table import SObjectDetailElementWdg #detail = SObjectDetailElementWdg() #detail.set_widget(img) #detail.set_sobject(sobject) #div.add(detail) div.add(img) div.add_class("hand") if my.SQL_ERROR: warning_div = DivWdg('<i>-- preprocess error --</i>') warning_div.add_styles('position: absolute; z-index: 100; float: left; top: 0; left: 0; font-size: smaller;') div.add_style('position: relative') div.add(warning_div) search_key = SearchKey.get_by_sobject(sobject) code = sobject.get_code() detail = my.get_option("detail") if detail != 'false': my.add_icon_behavior(div, sobject) if type(icon_size) == types.StringType and icon_size.endswith("%"): img.add_style("%s: 100%%" % my.aspect ) else: img.add_style("%s: %spx" % (my.aspect, my.get_icon_size()) ) img.add_style("min-%s: 15px" % my.aspect) return div
def get_history_wdg(my, sobject): # special for snapshots as well content_id ='summary_hist_%s' %sobject.get_id() title_id = 'hist_head_%s' %sobject.get_id() hist_head = DivWdg() hist_head.add_style('height','1.8em') hist_title = my._get_title_span("Checkin History") swap_wdg = my._get_swap_wdg(title_id) """ dyn_load = AjaxLoader(display_id=content_id) dyn_load.add_element_name('parent_key') args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load.set_load_class('pyasm.flash.widget.FlashAssetHistoryWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) """ # Load once feature is not implemented yet parent_key = SearchKey.get_by_sobject(sobject) dynamic_class = 'pyasm.flash.widget.FlashAssetHistoryWdg' on_script = ''' spt.panel.is_refreshing = true; var el_id = '%s'; spt.panel.show_progress(el_id); var kwargs = {'parent_key': '%s'}; setTimeout( function() { spt.panel.load(el_id, '%s', kwargs, {}, false); spt.panel.is_refreshing = false; }, 100 ); ''' % (content_id, parent_key, dynamic_class) on_script = "%s;spt.show_block('%s')" %(on_script, content_id) toggle_script = "spt.toggle_show_hide('%s')" %content_id swap_wdg.add_action_script(on_script, toggle_script) hist_head.add(swap_wdg) hist_head.add(hist_title) my.add_title_style(hist_title, title_id, swap_wdg) hist_div = DivWdg(id=content_id) hist_div.add_style('display','none') return hist_head, hist_div
def get_table(my, sobject, snapshots): parent_key = SearchKey.get_by_sobject(sobject) table = TableLayoutWdg(table_id='snapshot_history_table', search_type='sthpw/snapshot', view='checkin_history', show_search_limit=False, show_gear=False, show_insert=False, parent_key=parent_key, mode='simple') table.set_sobjects(snapshots) return table """
def get_history_wdg(self, sobject): # special for snapshots as well content_id = 'summary_hist_%s' % sobject.get_id() title_id = 'hist_head_%s' % sobject.get_id() hist_head = DivWdg() hist_head.add_style('height', '1.8em') hist_title = self._get_title_span("Checkin History") swap_wdg = self._get_swap_wdg(title_id) """ dyn_load = AjaxLoader(display_id=content_id) dyn_load.add_element_name('parent_key') args_dict = {'search_type': sobject.get_search_type()} args_dict['search_id'] = sobject.get_id() dyn_load.set_load_class('pyasm.flash.widget.FlashAssetHistoryWdg', load_args=args_dict) on_script = dyn_load.get_on_script(load_once=True) """ # Load once feature is not implemented yet parent_key = SearchKey.get_by_sobject(sobject) dynamic_class = 'pyasm.flash.widget.FlashAssetHistoryWdg' on_script = ''' spt.panel.is_refreshing = true; var el_id = '%s'; spt.panel.show_progress(el_id); var kwargs = {'parent_key': '%s'}; setTimeout( function() { spt.panel.load(el_id, '%s', kwargs, {}, false); spt.panel.is_refreshing = false; }, 100 ); ''' % (content_id, parent_key, dynamic_class) on_script = "%s;spt.show_block('%s')" % (on_script, content_id) toggle_script = "spt.toggle_show_hide('%s')" % content_id swap_wdg.add_action_script(on_script, toggle_script) hist_head.add(swap_wdg) hist_head.add(hist_title) self.add_title_style(hist_title, title_id, swap_wdg) hist_div = DivWdg(id=content_id) hist_div.add_style('display', 'none') return hist_head, hist_div
def get_table(my, sobject, snapshots): parent_key = SearchKey.get_by_sobject(sobject) table = TableLayoutWdg( table_id="snapshot_history_table", search_type="sthpw/snapshot", view="checkin_history", show_search_limit=False, show_gear=False, show_insert=False, parent_key=parent_key, mode="simple", ) table.set_sobjects(snapshots) return table """
def add_icon_behavior(my, widget, sobject): search_key = SearchKey.get_by_sobject(sobject) code = sobject.get_code() widget.add_attr("spt_search_key", search_key) widget.add_attr("spt_code", code) script_path = my.options.get("script_path") class_name = my.options.get("detail_class_name") if script_path: widget.add_class("spt_thumb_script_path") else: widget.add_class("spt_thumb_detail_class_name") return """
def get_instance_wdg(my, instance_type): sorted_instances = my._get_sorted_instances() content_div = Widget() for instance in sorted_instances: item_div = my.get_item_div(instance) item_div.add_attr( "spt_search_key", SearchKey.get_by_sobject(instance) ) item_div.add_class("spt_drop_item") # no need for that #item_div.add(' ') content_div.add(item_div) value_wdg = my.get_value_wdg() json = jsondumps(my.values) json = json.replace('"', '"') value_wdg.set_value(json) return content_div
def get_instance_wdg(self, instance_type): sorted_instances = self._get_sorted_instances() content_div = Widget() for instance in sorted_instances: item_div = self.get_item_div(instance) item_div.add_attr( "spt_search_key", SearchKey.get_by_sobject(instance) ) item_div.add_class("spt_drop_item") # no need for that #item_div.add(' ') content_div.add(item_div) value_wdg = self.get_value_wdg() json = jsondumps(self.values) json = json.replace('"', '"') value_wdg.set_value(json) return content_div
def get_item_div(my, sobject): ''' get the item div the sobject''' top = DivWdg() top.add_attr('title', 'Click to remove') # FIXME: put this here for now top.add_behavior({ 'type': 'click_up', #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)''' 'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)''' }) top.add_class("spt_drop_item") top.add_class("SPT_DROP_ITEM") item_div = DivWdg() item_div.add_class("hand") item_div.add_style("float: clear") top.add(item_div, "item_div") #my.menu.set_over(item_div, event="mousein") #my.menu.set_out(top, event="mouseleave") # set this as the place for the display value to go item_div.add_class("spt_drop_display_value") add_icon = True ExpressionParser.clear_cache() if sobject: if add_icon: my._add_icon(sobject, item_div) if my.display_expr: display_value = Search.eval(my.display_expr, sobjects=sobject, single=True) else: display_value = sobject.get_display_value() if isinstance(display_value, list): display_value = display_value[0] item_div.add(display_value) my.values.append(SearchKey.get_by_sobject(sobject)) return top
def get_item_div(my, sobject): ''' get the item div the sobject''' top = DivWdg() top.add_style("padding: 3px 2px") top.add_attr('title','Click to remove') # FIXME: put this here for now top.add_behavior( { 'type': 'click_up', #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)''' 'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)''' } ) top.add_class("spt_drop_item") top.add_class("SPT_DROP_ITEM") item_div = DivWdg() item_div.add_class("hand") item_div.add_style("float: clear") top.add(item_div, "item_div") #my.menu.set_over(item_div, event="mousein") #my.menu.set_out(top, event="mouseleave") # set this as the place for the display value to go item_div.add_class("spt_drop_display_value") add_icon = True ExpressionParser.clear_cache() if sobject: if add_icon: my._add_icon(sobject, item_div) if my.display_expr: display_value = Search.eval(my.display_expr, sobjects = sobject, single=True) else: display_value = sobject.get_display_value() if isinstance(display_value, list): display_value = display_value[0] item_div.add( display_value ) my.values.append( SearchKey.get_by_sobject(sobject) ) return top
def add_header(my, table, title): table.add_style('width', '50em') parent_st = my.kwargs.get('search_type') parent_sid = my.kwargs.get('search_id') sobj = Search.get_by_id(parent_st, parent_sid) sobj_code = 'New' sobj_title = '' if sobj: sobj_code = sobj.get_code() sobj_title = sobj.get_search_type_obj().get_title() th = table.add_header( "Append File for %s [%s]" % (sobj_title, sobj_code)) th.set_attr("colspan", "2") if sobj: hidden = HiddenWdg('parent_search_key', SearchKey.get_by_sobject(sobj) ) th.add(hidden)
def add_js_expression(my, widget, sobject, expression): js_expression, columns = my.convert_to_js(sobject, expression) element_name = my.get_name() for column in columns: # ignore itself #if column == element_name: # continue search_key = SearchKey.get_by_sobject(sobject) event_name = 'change|%s|%s' % (search_key, column) behavior = { 'type': 'listen', 'event_name': event_name, 'expression': js_expression, 'cbjs_action': 'spt.expression.calculate_cbk(evt, bvr)' } widget.add_behavior(behavior)
def add_js_expression(my, widget, sobject, expression): js_expression, columns = my.convert_to_js(sobject, expression) element_name = my.get_name() for column in columns: # ignore itself # if column == element_name: # continue search_key = SearchKey.get_by_sobject(sobject) event_name = "change|%s|%s" % (search_key, column) behavior = { "type": "listen", "event_name": event_name, "expression": js_expression, "cbjs_action": "spt.expression.calculate_cbk(evt, bvr)", } widget.add_behavior(behavior)
def add_js_expression(self, widget, sobject, expression): js_expression, columns = self.convert_to_js(sobject, expression) element_name = self.get_name() for column in columns: # ignore itself #if column == element_name: # continue search_key = SearchKey.get_by_sobject(sobject) event_name = 'change|%s|%s' % (search_key, column) behavior = { 'type': 'listen', 'event_name': event_name, 'expression': js_expression, 'cbjs_action': 'spt.expression.calculate_cbk(evt, bvr)' } widget.add_behavior(behavior)
def get_display(self): parent = self.get_current_sobject() parent_key = SearchKey.get_by_sobject(parent) div = DivWdg() from pyasm.widget import IconButtonWdg, IconWdg icon = IconButtonWdg("Add Task", IconWdg.ADD) div.add(icon) #div.add("Add Tasks") div.add_class("hand") div.add_behavior({ "type": "click_up", "parent_type": parent.get_base_search_type(), "cbfn_action": "spt.dg_table.add_tasks_cbk", }) content = DivWdg() content.add_class("content") div.add(content) return div
def get_display(my): parent = my.get_current_sobject() parent_key = SearchKey.get_by_sobject(parent) div = DivWdg() from pyasm.widget import IconButtonWdg, IconWdg icon = IconButtonWdg("Add Task", IconWdg.ADD) div.add(icon) #div.add("Add Tasks") div.add_class("hand") div.add_behavior( { "type": "click_up", "parent_type": parent.get_base_search_type(), "cbfn_action": "spt.dg_table.add_tasks_cbk", } ) content = DivWdg() content.add_class("content") div.add(content) return div
def get_display(my): sobject = my.get_current_sobject() my.search_key = SearchKey.get_by_sobject(sobject) div = DivWdg() div.add_class("hand") title = "Show Item Details" if my.widget: widget = my.widget else: widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM) code = sobject.get_code() name = sobject.get_value("name", no_exception=True) if not name: name = code widget.add_behavior({ 'type': 'click_up', 'search_key': my.search_key, 'code': code, 'name': name, 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.TaskDetailPanelWdg'; var kwargs = { search_key: bvr.search_key, }; var mode = ''; var layout = bvr.src_el.getParent(".spt_tool_top"); if (layout != null) { mode = 'tool' } if (mode == 'tool') { spt.app_busy.show("Loading ..."); var layout = bvr.src_el.getParent(".spt_tool_top"); var element = layout.getElement(".spt_tool_content"); spt.panel.load(element, class_name, kwargs); spt.app_busy.hide(); } else { var element_name = "detail_"+bvr.code; var title = "Detail ["+bvr.name+"]"; spt.tab.add_new(element_name, title, class_name, kwargs); } ''' }) div.add(widget) return div
def get_display(my): mode = my.get_option('mode') size = my.get_option('icon_size') if mode == 'add': my.set_option('icon', "CHECK_OUT") else: if size == 'large': my.set_option('icon', "CHECK_OUT_LG") else: my.set_option('icon', "CHECK_OUT_SM") top = DivWdg() icon = IconButtonWdg( "Checkout", eval( "IconWdg.%s" % my.get_option('icon') ) ) top.add(icon) my.process = my.get_option('process') my.context = '' transfer_mode = my.get_option('transfer_mode') sobject = my.get_current_sobject() if sobject.get_id() == -1: sobject = None snapshot_code = my.get_option("snapshot_code") sandbox_dir = my.get_option("sandbox_dir") if not sandbox_dir and sobject and isinstance(sobject, Snapshot): sandbox_dir = sobject.get_sandbox_dir(file_type='main') snapshot_code = sobject.get_code() lock_process = my.get_option("lock_process") sobject = my.get_current_sobject() search_key = SearchKey.get_by_sobject(sobject) if sobject.get_base_search_type() in ['sthpw/task', 'sthpw/note']: my.process = sobject.get_value('process') my.context = sobject.get_value('context') if not my.process: my.process = '' parent = sobject.get_parent() if not parent: return DivWdg() search_key = SearchKey.get_by_sobject(parent) else: my.process = my.get_option('process') search_key = SearchKey.get_by_sobject(sobject) checkout_script_path = my.get_option("checkout_script_path") checkout_panel_script_path = my.get_option("checkout_panel_script_path") lock_process = my.get_option("lock_process") if not checkout_script_path: checkout_script_path = '' if not checkout_panel_script_path: checkout_panel_script_path = '' # FIXME: this does not get passed through 'cuz get_display is overridden here # so passed in directly in the script below my.behavior['checkout_panel_script_path'] = checkout_panel_script_path my.behavior['checkout_script_path'] = checkout_script_path my.behavior['process'] = my.process my.behavior['context'] = my.context my.behavior['lock_process'] = lock_process my.behavior['search_key'] = search_key my.behavior['snapshot_code'] = snapshot_code my.behavior['sandbox_dir'] = sandbox_dir my.behavior['transfer_mode'] = transfer_mode #layout_wdg = my.get_layout_wdg() #state = layout_wdg.get_state() cbjs_action = ''' var kwargs = { search_key: '%(search_key)s', sandbox_dir: '%(sandbox_dir)s', process: '%(process)s', context: '%(context)s', lock_process: '%(lock_process)s', checkout_script_path: '%(checkout_script_path)s' }; var transfer_mode = bvr.transfer_mode; if (!transfer_mode) { transfer_mode = spt.Environment.get().get_transfer_mode(); } if (transfer_mode == null) { transfer_mode = 'web'; } // NOTE: reusing checkin transfer mode if (transfer_mode == 'copy') { transfer_mode = 'client_repo'; } var values = {}; var top = bvr.src_el.getParent(".spt_checkin_top"); script = spt.CustomProject.get_script_by_path(bvr.checkout_panel_script_path); if (script) { bvr['script'] = script; bvr.values = kwargs; spt.app_busy.show("Running Checkout Panel Script", kwargs.checkout_panel_script_path); setTimeout( function() { try { spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { throw(e); spt.alert('No script found. <checkout_panel_script_path> display option should refer to a valid script path.'); } spt.app_busy.hide(); }, 50); } else { if (bvr.snapshot_code) { if (!bvr.checkout_script_path){ spt.app_busy.show("Checking out files", 'To: '+ bvr.sandbox_dir); setTimeout( function() { try { var server = TacticServerStub.get(); file_types = ['main']; filename_mode = 'source'; // we want this undefined so the checkout // snapshot can deal with it correctly. Explicitly // putting in a dir will force it to go there, // regardless of naming conventions sandbox_dir = null; server.checkout_snapshot(bvr.snapshot_code, sandbox_dir, {mode: transfer_mode, filename_mode: filename_mode, file_types: file_types} ); var checkin_top = bvr.src_el.getParent(".spt_checkin_top"); if (checkin_top) { spt.app_busy.show("Reading file system ...") spt.panel.refresh(checkin_top); spt.app_busy.hide(); } } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } else { setTimeout( function() { try { bvr['script'] = bvr.checkout_script_path; bvr.values = kwargs; spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } } else { var class_name = 'tactic.ui.widget.CheckoutWdg'; var values = kwargs; bvr.values = values; var search_key = values.search_key; var sandbox_dir = values.sandbox_dir; var process = values.process; var context = values.context; var options = { 'show_publish': 'false', 'process': process, 'context': context, 'search_key': search_key, 'checkout_script_path': bvr.checkout_script_path, 'sandbox_dir': sandbox_dir }; var popup_id ='Check-out Widget'; spt.panel.load_popup(popup_id, class_name, options); } } ''' % (my.behavior) my.behavior['type'] = 'click_up' my.behavior['cbjs_action'] = cbjs_action icon.add_behavior(my.behavior) return top
def init(my): web = WebContainer.get_web() my.parent_key = my.kwargs.get('parent_key') my.append_context = my.kwargs.get('append_context') my.is_refresh = my.kwargs.get('is_refresh') == 'true' my.resize = my.kwargs.get('resize') == 'true' my.checkbox_name = my.kwargs.get('checkbox_name') my.orig_parent = None my.show_context = my.kwargs.get('show_context') if not my.show_context: my.show_context = web.get_form_value('show_context') my.show_context = my.show_context == 'true' my.view = my.kwargs.get('view') incoming_process = False if my.parent_key: my.parent = Search.get_by_search_key(my.parent_key) my.orig_parent = my.parent my.orig_parent_search_type = my.parent.get_search_type() my.parent_search_type = my.parent.get_search_type() my.parent_search_id = my.parent.get_id() else: my.parent_search_type = my.kwargs.get('search_type') my.orig_parent_search_type = my.parent_search_type my.parent_search_id = my.kwargs.get('search_id') my.parent = Search.get_by_id(my.parent_search_type, my.parent_search_id) my.orig_parent = my.parent if my.use_parent: my.parent = my.parent.get_parent() if not my.parent: raise TacticException( 'Try not to use the display option [use_parent] since the parent cannot be found.' ) if my.parent: my.parent_key = SearchKey.get_by_sobject(my.parent) if my.use_parent: my.kwargs['parent_key'] = my.parent_key my.kwargs['use_parent'] = 'false' my.process_names = [] my.checked_processes = [] # get the process names process_names = web.get_form_values('process_names') #process_names = my.kwargs.get('process_names') if not process_names: if my.orig_parent_search_type in ['sthpw/task', 'sthpw/snapshot']: #my.parent = my.parent.get_parent() # most tasks don't have context by default if my.orig_parent_search_type == 'sthpw/task': context = my.orig_parent.get_value('context') if not context: context = my.orig_parent.get_value('process') else: context = my.orig_parent.get_value('context') my.process_names = [context] my.child_mode = True my.kwargs['child_mode'] = 'true' else: my.pipeline_code = my.kwargs.get('pipeline_code') if not my.pipeline_code and my.parent.has_value( 'pipeline_code'): my.pipeline_code = my.parent.get_value('pipeline_code') pipeline = Pipeline.get_by_code(my.pipeline_code) if pipeline: my.process_names = pipeline.get_process_names() else: my.process_names = process_names incoming_process = True # if nothing is derived from pipeline, use defualts if not my.process_names: my.process_names = ['default'] if my.append_context and not incoming_process: contexts = my.append_context.split('|') my.process_names.extend(contexts)
def _test_file_naming(my): process = 'model' type = 'main' context = 'modeling' version = 10 file_name = 'testing_image.jpg' code = name = 'vehicle001' asset_library = 'vehicle' asset = SearchType.create( Asset.SEARCH_TYPE ) asset.set_value("code",code) asset.set_value("name",name) asset.set_value("asset_library",asset_library) asset.set_value("asset_type","asset") virtual_snapshot = Snapshot.create_new() virtual_snapshot_xml = '<snapshot process=\'%s\'><file type=\'%s\'/></snapshot>' % (process, type) virtual_snapshot.set_value("snapshot", virtual_snapshot_xml) virtual_snapshot.set_value("context", context) virtual_snapshot.set_value("version", version) virtual_snapshot.set_sobject(asset) file_obj = File(File.SEARCH_TYPE) file_obj.set_value("file_name", file_name) file_naming = Project.get_file_naming() file_naming.set_sobject(asset) file_naming.set_snapshot(virtual_snapshot) file_naming.set_file_object(file_obj) expected_file_name = 'vehicle001_%s_v%0.3d.jpg' %(context,version) file_name = file_naming.get_file_name() my.assertEquals(expected_file_name, file_name) # try a default directory name file_obj.set_value("file_name", "test_dir") file_obj.set_value("base_type", "directory") file_naming.set_file_object(file_obj) # this should adopt the original dir name in the prefix expected_file_name = 'test_dir_%s_v%0.3d' %(context,version) file_name = file_naming.get_default() my.assertEquals(expected_file_name, file_name) #2 try a different search_type unittest/person version = 9 file_obj.set_value("base_type", "file") # change a different input file name file_obj.set_value('file_name','some_maya_model.ma') # use a real snapshot virtual_snapshot.set_sobject(my.person) virtual_snapshot.set_value("version", version) # change to the test file naming class my.sobj.set_value('file_naming_cls', 'pyasm.biz.naming_test.TestFileNaming') my.sobj.commit() Project.set_project('unittest') file_naming = Project.get_file_naming() file_naming.set_sobject(my.person) file_naming.set_snapshot(virtual_snapshot) file_naming.set_file_object(file_obj) file_name = file_naming.get_file_name() expected_file_name = 'phil_main_v009.ma' my.assertEquals(expected_file_name, file_name) # get_preallocated_path type = 'ma' #file_obj.set_value('type', type) #file_naming.set_file_object(file_obj) preallocated = my.snapshot.get_preallocated_path(file_type='maya', file_name='what.ma',ext='ma') preallocated_file_name = os.path.basename(preallocated) my.assertEquals("phil_main_v001.ma", preallocated_file_name) preallocated = my.snapshot.get_preallocated_path(file_type='houdini', file_name='what.otl',ext='otl') preallocated_file_name = os.path.basename(preallocated) my.assertEquals("phil_main_v001.otl", preallocated_file_name) preallocated = my.snapshot.get_preallocated_path(file_type='houdini', file_name='what_is.otl', ext='hipnc') preallocated_file_name = os.path.basename(preallocated) my.assertEquals("phil_main_v001.hipnc", preallocated_file_name) # try an empty file naming # change to the test file naming class my.sobj.set_value('file_naming_cls', 'pyasm.biz.naming_test.TestFileNaming2') my.sobj.commit() Project.set_project('unittest') file_naming = Project.get_file_naming() file_naming.set_sobject(my.person) file_naming.set_snapshot(virtual_snapshot) file_naming.set_file_object(file_obj) file_name = file_naming.get_file_name() preallocated = my.snapshot.get_preallocated_path(file_type='houdini', file_name='what_is.otl', ext='hipnc') if not os.path.exists(preallocated): os.makedirs(preallocated) from client.tactic_client_lib import TacticServerStub client = TacticServerStub.get() if os.path.isdir(preallocated): rtn = client.add_directory(my.snapshot.get_code(), preallocated, 'houdini', mode='preallocate') else: rtn = client.add_file(my.snapshot.get_code(), preallocated, 'houdini', mode='preallocate') rtn = client.get_snapshot(SearchKey.get_by_sobject(my.snapshot.get_parent()), context = 'naming_test', version = 1, include_files=True) files = rtn.get('__files__') # assuming the file is ordered by code # the 1st file obj is a file and 2nd file obj is a directory for idx, file in enumerate(files): if idx ==0: my.assertEquals(file.get('type'), 'main') my.assertEquals(file.get('base_type'), 'file') my.assertEquals(file.get('file_name'), 'naming_test_naming_test_v001.txt') elif idx ==1: my.assertEquals(file.get('type'), 'houdini') my.assertEquals(file.get('base_type'), 'directory') my.assertEquals(file.get('md5'), '') my.assertEquals(file.get('file_name'), '')
def get_group_wdg(self, prev_sobj): if not self.is_preprocessed: self.preprocess() sobject = self.get_current_sobject() ref_sobj = self.get_ref_obj(sobject) self.current_ref_sobj = ref_sobj if not ref_sobj: return "Undetermined parent: [%s]" % SearchKey.get_by_sobject(sobject) widget = DivWdg() # add add button #from tactic.ui.widget import TextBtnWdg, TextBtnSetWdg #buttons_list = [] #buttons_list.append( { # 'label': '+', 'tip': 'Add Another Item', # 'bvr': { 'cbjs_action': "spt.dg_table.add_item_cbk(evt, bvr)" } #} ) #add_btn = TextBtnSetWdg( float="right", buttons=buttons_list, # spacing=6, size='small', side_padding=0 ) #widget.add(add_btn) from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title='+', tip='Add Another Item', size='small') widget.add(button) button.add_style("float: right") button.add_behavior( { 'type': 'click_up', 'cbjs_action': "spt.dg_table.add_item_cbk(evt, bvr)" } ) label = "Attach" label_option = self.get_option("label") if label_option: label = label_option table = Table() table.add_color("color", "color") table.add_row() search_key = sobject.get_search_key() # add a thumbe widget thumb = ThumbWdg() thumb.set_icon_size(40) thumb.set_sobject(ref_sobj) thumb.set_option('latest_icon', 'true') table.add_cell(thumb) # add the text description name_span = DivWdg(ref_sobj.get_code()) name_span.add_style('margin-left: 20px') table.add_cell(name_span) if ref_sobj.has_value("name"): name_span.add( " - " ) name_span.add( ref_sobj.get_value("name") ) #status = ref_sobj.get_value("status", no_exception=True) #if status: # span = SpanWdg("(status:%s)" % ref_sobj.get_value("status")) # table.add_cell(span) if ref_sobj.has_value("description"): description_wdg = ExpandableTextWdg("description") description_wdg.set_max_length(200) description_wdg.set_sobject(ref_sobj) td = table.add_cell( description_wdg ) td.add_style("padding-left: 15px") # FIXME: not sure about the layout here #if ref_sobj.has_value("pipeline_code"): # pipeline_code = ref_sobj.get_value("pipeline_code") # span = SpanWdg("(pipeline:%s)" % pipeline_code ) # td = table.add_cell(span) # td.add_style("padding-left: 15px") widget.add(table) return widget
def get_display(my): my.sobject = my.get_sobject() top = DivWdg() top.add_class("spt_detail_top") top.add_color("background", "background") top.add_color("color", "color") if not my.sobject: top.add("No SObject defined for this widget") return top if my.parent: my.search_type = my.parent.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.parent) top.add_attr("spt_parent_key", my.search_key) my.pipeline_code = my.parent.get_value("pipeline_code", no_exception=True) my.full_search_type = my.parent.get_search_type() else: my.pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True) my.search_type = my.sobject.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.sobject) my.full_search_type = my.sobject.get_search_type() if not my.pipeline_code: my.pipeline_code = 'default' top.add_style("text-align: left") my.set_as_panel(top) table = Table() #from tactic.ui.container import ResizableTableWdg #table = ResizableTableWdg() table.add_color("background", "background") table.add_color("color", "color") top.add(table) table.set_max_width() table.add_row() # left #td = table.add_cell(resize=False) td = table.add_cell() #td.add_style("padding: 10px") td.add_style("width: 200px") td.add_style("min-width: 200px") td.add_style("vertical-align: top") #td.add_border() #td.add_style("border-style: solid") #td.add_style("border-width: 1px 0 1px 1px") #td.add_color("border-color", "border") #td.add_color("background", "background", -10) if my.parent: code = my.parent.get_code() else: code = my.sobject.get_code() # add the tile title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add_style("font-size: 1.4em") title.add("%s" % code) title.add_border() div = DivWdg() td.add(div) div.add_class("spt_sobject_detail_top") thumb_table = Table() div.add(thumb_table) thumb_table.add_row() thumb = ThumbWdg() # use a larger version for clearer display thumb.set_icon_type('web') # prefer to see the original image, then web thumb.set_option('image_link_order', 'main|web|.swf') thumb.set_option("detail", "false") thumb.set_option("icon_size", "100%") td = thumb_table.add_cell(thumb) td.add_style("vertical-align: top") td.add_style("width: 200px") td.add_style("padding: 20px") if my.parent: thumb.set_sobject(my.parent) else: thumb.set_sobject(my.sobject) sobject_info_wdg = my.get_sobject_info_wdg() sobject_info_wdg.add_style("width: 200px") td.add(sobject_info_wdg) if my.search_type == 'sthpw/task' and not my.parent: pass else: sobject_info_wdg = my.get_sobject_detail_wdg() td = table.add_cell() td.add(sobject_info_wdg) td.add_style("vertical-align: top") #td.add_color("background", "background", -10) td.add_style("overflow: hidden") #td.add_style("border-style: solid") #td.add_style("border-width: 1px 1px 1px 0px") #td.add_color("border-color", "border") # right td = table.add_cell() td.add_style("text-align: left") td.add_style("vertical-align: top") #td.add_color("background", "background", -10) td.add_class("spt_notes_wrapper") #td.add_border() # add the title title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add("Notes") title.add_border() notes_div = DivWdg() td.add(notes_div) from tactic.ui.widget.discussion_wdg import DiscussionWdg discussion_wdg = DiscussionWdg(search_key=my.search_key, context_hidden=False, show_note_expand=False) notes_div.add(discussion_wdg) notes_div.add_style("min-width: 300px") notes_div.add_style("height: 200") notes_div.add_style("overflow-y: auto") notes_div.add_class("spt_resizable") # get the process if my.parent: process = my.sobject.get_value("process") else: process = '' # content tr = table.add_row() td = table.add_cell() td.add_attr("colspan", "5") #td.add_attr("colspan", "3") # create a state for tab. The tab only passes a search key # parent key search_key = SearchKey.get_by_sobject(my.sobject) parent = my.sobject.get_parent() if parent: parent_key = parent.get_search_key() else: parent_key = "" state = { 'search_key': search_key, 'parent_key': parent_key, 'process': process, } WebState.get().push(state) config_xml = my.get_config_xml() config = WidgetConfig.get(view="tab", xml=config_xml) if process: custom_view = "tab_config_%s" % process else: custom_view = "tab_config" search = Search("config/widget_config") search.add_filter("category", "TabWdg") search.add_filter("search_type", my.search_type) search.add_filter("view", custom_view) custom_config_sobj = search.get_sobject() if custom_config_sobj: custom_config_xml = custom_config_sobj.get_value("config") custom_config = WidgetConfig.get(view=custom_view, xml=custom_config_xml) config = WidgetConfigView(search_type='TabWdg', view=custom_view, configs=[custom_config, config]) #menu = my.get_extra_menu() #tab = TabWdg(config=config, state=state, extra_menu=menu) tab = TabWdg(config=config, state=state, show_add=False, show_remove=False, tab_offset=5 ) tab.add_style("margin: 0px -2px -2px -2px") td.add(tab) td.add_style("padding-top: 10px") return top
def get_config_xml(my): process = my.sobject.get_value("process") context = my.sobject.get_value("context") process_title = "Process - %s" % (process) process_name = "process_%s" % process parent_key = '' if my.parent: parent_key = SearchKey.get_by_sobject(my.parent).replace( "&", "&") search_key = SearchKey.get_by_sobject(my.sobject).replace("&", "&") config_xml = [] config_xml.append(''' <config> <tab>''') config_xml.append(''' <element name="%s" title="%s"> <display class='tactic.ui.tools.SObjectSingleProcessDetailWdg'> <search_key>%s</search_key> <process>%s</process> <context>%s</context> </display> </element> ''' % (process_name, process_title, parent_key, process, context)) display_options = my.kwargs options_list = [] for key, value in display_options.items(): if key in [ 'search_key', 'process', 'parent_key', 'checkin_ui_options', 'checkin_script_path', 'checkin_script', 'checkin_relative_dir' ]: continue options_list.append('<%(key)s>%(value)s</%(key)s>' % ({ 'key': key, 'value': value })) """ config_xml.append( ''' <element name="checkout_%s" title="Checkout: %s "> <display class='tactic.ui.table.TaskCheckoutManageWdg'> <search_key>%s</search_key> <parent_key>%s</parent_key> %s </display> </element> ''' % (process_name, process_title, search_key, search_key, '\n'.join(options_list)) ) """ display_options = my.kwargs options_list = [] for key, value in display_options.items(): if key in ['search_key', 'process', 'show_versionless_folder']: continue options_list.append('<%(key)s>%(value)s</%(key)s>' % ({ 'key': key, 'value': value })) wdg_xml = ''' <element name="checkin_%s" title="Checkin: %s "> <display class='tactic.ui.widget.CheckinWdg'> <search_key>%s</search_key> <process>%s</process> <context>%s</context> %s </display> </element> ''' % (process_name, process_title, parent_key, process, context, '\n'.join(options_list)) config_xml.append(wdg_xml) config_xml.append(''' </tab> </config> ''') config_xml = "".join(config_xml) return config_xml
# try to get an icon first if isinstance(sobject, Snapshot): snapshot = sobject # check if the sobject actually exists try: snapshot.get_sobject() except SObjectNotFoundException, e: return IconWdg('sobject n/a for snapshot code[%s]' %snapshot.get_code(), icon=IconWdg.ERROR) except SearchException, e: return IconWdg('parent for snapshot [%s] not found' %snapshot.get_code(), icon=IconWdg.ERROR) else: # this is to limit unnecessary queries snapshot = None if my.data: search_key = SearchKey.get_by_sobject(sobject, use_id=False) snapshot = my.data.get(search_key) elif my.is_ajax(check_name=False) or redirect or redirect_expr: if my.show_latest_icon: icon_context = None snapshot = Snapshot.get_latest_by_sobject(sobject, icon_context, show_retired=False) # get the latest icon period if not snapshot and icon_context == 'icon': snapshot = Snapshot.get_latest_by_sobject(sobject, show_retired=False) if not snapshot: icon = my.get_no_icon_wdg() return icon
def get_action_html(my): search_key = SearchKey.get_by_sobject(my.sobjects[0], use_id=True) search_type = my.sobjects[0].get_base_search_type() div = DivWdg(css='centered') # construct the bvr element_names = my.element_names[:] for element_name in my.skipped_element_names: element_names.remove(element_name) bvr = { 'type': 'click_up', 'mode': my.mode, 'element_names': element_names, 'search_key': search_key, 'input_prefix': my.input_prefix, 'view': my.view } if my.mode == 'insert': bvr['refresh'] = 'true' # for adding parent relationship in EditCmd if my.parent_key: bvr['parent_key'] = my.parent_key hidden_div = DivWdg() hidden_div.add_style("display: none") div.add(hidden_div) hidden = TextAreaWdg("__data__") hidden_div.add(hidden) hidden.set_value( jsondumps(bvr) ) show_action = my.kwargs.get("show_action") if show_action in [False, 'false']: return div div.add_styles('height: 35px; margin-top: 5px;') div.add_named_listener('close_EditWdg', ''' var popup = spt.popup.get_popup( $('edit_popup') ); if (popup != null) { spt.popup.destroy(popup); } ''') # custom callbacks cbjs_cancel = my.kwargs.get('cbjs_cancel') if not cbjs_cancel: cbjs_cancel = ''' spt.named_events.fire_event('preclose_edit_popup', {}); spt.named_events.fire_event('close_EditWdg', {}) ''' # custom callbacks cbjs_insert_path = my.kwargs.get('cbjs_%s_path' % my.mode) cbjs_insert = None if cbjs_insert_path: script_obj = CustomScript.get_by_path(cbjs_insert_path) if script_obj: cbjs_insert = script_obj.get_value("script") # get it inline if not cbjs_insert: cbjs_insert = my.kwargs.get('cbjs_%s' % my.mode) # use a default if not cbjs_insert: mode_label = my.mode.capitalize() cbjs_insert = ''' spt.app_busy.show("%sing items", ""); spt.edit.edit_form_cbk(evt, bvr); spt.app_busy.hide(); '''%mode_label save_event = my.kwargs.get('save_event') if not save_event: save_event = div.get_unique_event("save") bvr['save_event'] = save_event bvr['named_event'] = 'edit_pressed' bvr['cbjs_action'] = cbjs_insert ok_btn_label = my.mode.capitalize() if ok_btn_label == 'Edit': ok_btn_label = 'Save' if ok_btn_label == 'Insert': ok_btn_label = 'Add' if my.kwargs.get('ok_btn_label'): ok_btn_label = my.kwargs.get('ok_btn_label') ok_btn_tip = ok_btn_label if my.kwargs.get('ok_btn_tip'): ok_btn_tip = my.kwargs.get('ok_btn_tip') cancel_btn_label = 'Cancel' if my.kwargs.get('cancel_btn_label'): cancel_btn_label = my.kwargs.get('cancel_btn_label') cancel_btn_tip = cancel_btn_label if my.kwargs.get('cancel_btn_tip'): cancel_btn_tip = my.kwargs.get('cancel_btn_tip') # create the buttons insert_button = ActionButtonWdg(title=ok_btn_label, tip=ok_btn_tip) insert_button.add_behavior(bvr) cancel_button = ActionButtonWdg(title=cancel_btn_label, tip=cancel_btn_tip) cancel_button.add_behavior({ 'type': 'click_up', 'cbjs_action': cbjs_cancel }) table = Table() table.add_style("margin-left: auto") table.add_style("margin-right: auto") table.add_style("margin-top: 15px") table.add_style("margin-bottom: 15px") table.add_row() table.add_cell(insert_button) table.add_cell(cancel_button) div.add(table) #div.add(SpanWdg(edit, css='med')) #div.add(SpanWdg(edit_close, css='med')) #div.add(SpanWdg(cancel, css='med')) return div
def get_action_html(my): search_key = SearchKey.get_by_sobject(my.sobjects[0]) search_type = my.sobjects[0].get_base_search_type() div = DivWdg(css='centered') div.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() } ) div.add_styles('height: 35px; margin-top: 10px;') div.add_named_listener('close_EditWdg', ''' var popup = bvr.src_el.getParent( ".spt_popup" ); if (popup) spt.popup.close(popup); ''') # custom callbacks cbjs_cancel = my.kwargs.get('cbjs_cancel') if not cbjs_cancel: cbjs_cancel = ''' spt.named_events.fire_event('preclose_edit_popup', {}); spt.named_events.fire_event('close_EditWdg', {}) ''' # custom callbacks cbjs_insert_path = my.kwargs.get('cbjs_%s_path' % my.mode) cbjs_insert = None if cbjs_insert_path: script_obj = CustomScript.get_by_path(cbjs_insert_path) cbjs_insert = script_obj.get_value("script") cbjs_insert = cbjs_insert.replace("'", '"') # get it inline if not cbjs_insert: cbjs_insert = my.kwargs.get('cbjs_%s' % my.mode) # use a default if not cbjs_insert: cbjs_insert = ''' spt.edit.edit_form_cbk(evt, bvr); ''' element_names = my.element_names[:] for element_name in my.skipped_element_names: element_names.remove(element_name) # Must not have postaction which closes the EditWdg before upload finishes from tactic.ui.widget import TextBtnWdg, TextBtnSetWdg bvr = { 'cbjs_action': cbjs_insert, 'named_event': 'close_EditWdg', 'element_names': element_names, 'search_key': search_key, 'input_prefix': my.input_prefix, 'view': my.view } keys = WebContainer.get_web().get_form_keys() for key in keys: bvr[key] = WebContainer.get_web().get_form_value(key) label = my.mode if label == 'edit': label = 'save' buttons_list = [ { 'label': label.capitalize(), 'tip': label.capitalize(), 'bvr': bvr }, { 'label': 'Cancel', 'tip': 'Cancel', 'bvr': { 'cbjs_action': cbjs_cancel } } ] buttons = TextBtnSetWdg( align="center", buttons=buttons_list, spacing=10, size='large', side_padding=4 ) div.add(buttons) return div
def get_display(my): sobject = my.get_current_sobject() use_parent = my.get_option("use_parent") use_parent = use_parent in ['true', True] #if use_parent in ['true', True]: # sobject = sobject.get_parent() # if not sobject: # return DivWdg() my.search_key = SearchKey.get_by_sobject(sobject) div = DivWdg() div.add_class("hand") div.add_style("width: 26px") div.add_style("margin-left: auto") div.add_style("margin-right: auto") target_id = "main_body" title = "Show Item Details" if my.widget: widget = my.widget else: widget = IconButtonWdg(title=title, icon="BS_SEARCH") code = sobject.get_code() name = sobject.get_value("name", no_exception=True) if not name: name = code tab_element_names = my.kwargs.get("tab_element_names") or "" detail_view = my.kwargs.get("detail_view") or "" widget.add_behavior({ 'type': 'click_up', 'search_key': my.search_key, 'use_parent': use_parent, 'tab_element_names': tab_element_names, 'detail_view': detail_view, 'show_task_process': my.show_task_process, 'code': code, 'name': name, 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.SObjectDetailWdg'; var kwargs = { search_key: bvr.search_key, use_parent: bvr.use_parent, tab_element_names: bvr.tab_element_names, show_task_process: bvr.show_task_process, detail_view: bvr.detail_view }; var mode = ''; var layout = bvr.src_el.getParent(".spt_tool_top"); if (layout != null) { mode = 'tool' } if (mode == 'tool') { spt.app_busy.show("Loading ..."); var layout = bvr.src_el.getParent(".spt_tool_top"); var element = layout.getElement(".spt_tool_content"); spt.panel.load(element, class_name, kwargs); spt.app_busy.hide(); } else { var element_name = "detail_"+bvr.code; var title = "Detail ["+bvr.name+"]"; spt.tab.add_new(element_name, title, class_name, kwargs); } ''' }) #link_wdg = my.get_link_wdg(target_id, title, widget) #div.add( link_wdg ) div.add(widget) return div
def init(self): # for snapshot and task # self.child_mode = self.kwargs.get('child_mode') == 'true' self.parent_key = self.kwargs.get('parent_key') self.append_context = self.kwargs.get('append_context') self.is_refresh = self.kwargs.get('is_refresh') == 'true' self.view = self.kwargs.get('view') if not self.view: self.view = 'table' self.orig_parent = None self.use_parent = False incoming_process = False if self.parent_key: self.parent = Search.get_by_search_key(self.parent_key) self.orig_parent = self.parent self.orig_parent_search_type = self.parent.get_search_type() self.parent_search_type = self.parent.get_search_type() self.parent_search_id = self.parent.get_id() else: self.parent_search_type = self.kwargs.get('search_type') self.orig_parent_search_type = self.parent_search_type self.parent_search_id = self.kwargs.get('search_id') self.parent = Search.get_by_id(self.parent_search_type, self.parent_search_id) self.orig_parent = self.parent if self.use_parent: self.parent = self.parent.get_parent() if not self.parent: raise TacticException( 'Try not to use the display option [use_parent] since the parent cannot be found.' ) if self.parent: self.parent_key = SearchKey.get_by_sobject(self.parent) if self.use_parent: self.kwargs['parent_key'] = self.parent_key self.kwargs['use_parent'] = 'false' self.process_names = [] self.checked_processes = [] # get the process names web = WebContainer.get_web() process_names = web.get_form_values('process_names') #process_names = self.kwargs.get('process_names') if not process_names: if self.orig_parent_search_type in [ 'sthpw/task', 'sthpw/snapshot' ]: #self.parent = self.parent.get_parent() # most tasks don't have context by default if self.orig_parent_search_type == 'sthpw/task': context = self.orig_parent.get_value('context') if not context: context = self.orig_parent.get_value('process') else: context = self.orig_parent.get_value('context') self.process_names = [context] self.child_mode = True self.kwargs['child_mode'] = 'true' else: self.pipeline_code = self.kwargs.get('pipeline_code') if not self.pipeline_code and self.parent.has_value( 'pipeline_code'): self.pipeline_code = self.parent.get_value('pipeline_code') pipeline = Pipeline.get_by_code(self.pipeline_code) if pipeline: self.process_names = pipeline.get_process_names() else: self.process_names = process_names incoming_process = True # if nothing is derived from pipeline, use defualts if not self.process_names: self.process_names = ['default'] if self.append_context and not incoming_process: contexts = self.append_context.split('|') self.process_names.extend(contexts)
def get_display(my): my.sobject = my.get_current_sobject() if not my.sobject: my.sobject = my.get_sobject_from_kwargs() if my.sobject and my.sobject.is_insert(): return DivWdg() if my.sobject: my.search_key = SearchKey.get_by_sobject(my.sobject) my.kwargs['search_key'] = my.search_key else: my.search_key = my.kwargs.get('search_key') html = my.kwargs.get('html') if not html: html = "" # DEPRECATED my.state = my.kwargs.get("state") my.state = BaseRefreshWdg.process_state(my.state) if not my.state: my.state = my.kwargs my.state['search_key'] = my.search_key my.view = my.kwargs.get('view') my.view = my.view.replace("/", ".") my.view_folder = "" if my.view.startswith("."): my.view_folder = my.kwargs.get("__view_folder__") if my.view_folder: my.view = "%s%s" % (my.view_folder, my.view) parts = my.view.split(".") my.view_folder = ".".join(parts[:-1]) if not my.view and not html: raise TacticException("No view defined in custom layout") # If html is not a string, then convert it? if not isinstance(html, basestring): html = str(html) my.view_attrs = {} my.category = my.kwargs.get("category") my.search_type = my.kwargs.get("search_type") my.encoding = my.kwargs.get("encoding") if not my.encoding: my.encoding = 'utf-8' my.plugin = None xml = None # if html is not provided, then get it from the config config = None if not html: if my.config != None: config = my.config else: config = my.kwargs.get("config") if not config: config = my.get_config() if not config: #div = DivWdg() #div.add("No config defined for view [%s] for custom layout" % my.view) #return div raise TacticException("No config defined for view [%s] for custom layout" % my.view) if isinstance(config, WidgetDbConfig): config_str = config.get_value("config") else: config_str = '' if config_str.startswith("<html>"): html = config_str my.def_config = None else: xml = config.get_xml() if my.def_config == None: my.def_config = my.get_def_config(xml) # get the view attributes if isinstance(config, WidgetConfigView): top_config = config.get_configs()[0] else: top_config = config view_node = top_config.get_view_node() if view_node is None: div = DivWdg("No view node found in xml. Invalid XML entry found") return div my.view_attrs = xml.get_attributes(view_node) nodes = xml.get_nodes("config/%s/html/*" % my.view) if not nodes: div = DivWdg("No definition found") return div # convert html tag to a div html = cStringIO.StringIO() for node in nodes: # unfortunately, html does not recognize <textarea/> # so we have to make sure it becomes <textarea></textarea> text = xml.to_string(node) text = text.encode('utf-8') keys = ['textarea','input'] for key in keys: p = re.compile("(<%s.*?/>)" % key) m = p.search(text) if m: for group in m.groups(): xx = group.replace("/", "") xx = "%s</%s>" % (xx, key) text = text.replace(group, xx) text = text.replace("<%s/>" % key, "<%s></%s>" % (key, key)) # add linebreaks to element tag key = 'element' # reg full tag <element><display...></element> p = re.compile(r"(<%s\b[^>]*>(?:.*?)</%s>)" % (key, key)) # short-hand tag <element/> p1 = re.compile("(</%s>|<%s.*?/>)" %(key, key)) m = p.search(text) m1 = p1.search(text) if m: for group in m.groups(): if group: text = text.replace(group, '\n%s\n'%group) if m1: for group in m1.groups(): if group: text = text.replace(group, '\n%s\n'%group) html.write(text) html = html.getvalue() my.config = config #my.def_config = config # This is unnessary? # try to get the sobject if this is in a table element widget if my.search_key: try: # this will raise an exception if it is not in a table element sobject = my.get_current_sobject() except: sobject = SearchKey.get_by_search_key(my.search_key) sobjects = [sobject] else: try: # this will raise an exception if it is not in a table element sobject = my.get_current_sobject() if sobject: sobjects = [sobject] else: sobjects = [] except: sobject = my.sobjects my.layout = my.get_layout_wdg() # preprocess using mako include_mako = my.kwargs.get("include_mako") if not include_mako: include_mako = my.view_attrs.get("include_mako") if xml: mako_node = xml.get_node("config/%s/mako" % my.view) if mako_node is not None: mako_str = xml.get_node_value(mako_node) html = "<%%\n%s\n%%>\n%s" % (mako_str, html) from pyasm.web import Palette num_palettes = Palette.num_palettes() #if include_mako in ['true', True]: if include_mako not in ['false', False]: html = html.replace("<", "<") html = html.replace(">", ">") html = my.process_mako(html) # preparse out expressions # use relative expressions - [expr]xxx[/expr] p = re.compile('\[expr\](.*?)\[\/expr\]') parser = ExpressionParser() matches = p.finditer(html) for m in matches: full_expr = m.group() expr = m.groups()[0] result = parser.eval(expr, sobjects, single=True, state=my.state) if isinstance(result, basestring): result = Common.process_unicode_string(result) else: result = str(result) html = html.replace(full_expr, result ) # use absolute expressions - [expr]xxx[/expr] p = re.compile('\[abs_expr\](.*?)\[\/abs_expr\]') parser = ExpressionParser() matches = p.finditer(html) for m in matches: full_expr = m.group() expr = m.groups()[0] result = parser.eval(expr, single=True) if isinstance(result, basestring): result = Common.process_unicode_string(result) else: result = str(result) html = html.replace(full_expr, result ) # need a top widget that can be used to refresh top = my.top my.set_as_panel(top) top.add_class("spt_custom_top") ignore_events = my.kwargs.get("ignore_events") in ['true', True] if ignore_events: top.add_style("pointer-events: none") # create the content div content = DivWdg() content.add_class("spt_custom_content") content.add_style("position: relative") if ignore_events: content.add_style("pointer-events: none") top.add(content) my.content = content is_test = Container.get("CustomLayout::is_test") if not is_test: is_test = my.kwargs.get("is_test") in [True, 'true'] if is_test: Container.put("CustomLayout::is_test", True) my.handle_is_test(content) html = my.replace_elements(html) content.add(html) if xml: my.add_behaviors(content, xml) # remove all the extra palettes created while True: extra_palettes = Palette.num_palettes() - num_palettes if extra_palettes > 0: Palette.pop_palette() else: break if my.kwargs.get("is_top") in ['true', True]: return html elif my.kwargs.get("is_refresh"): return content else: return top
def get_display(my): my.sobject = my.get_sobject() top = DivWdg() top.add_class("spt_detail_top") top.add_color("background", "background") top.add_color("color", "color") if not my.sobject: top.add("No SObject defined for this widget") return top if my.parent: my.search_type = my.parent.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.parent) top.add_attr("spt_parent_key", my.search_key) my.pipeline_code = my.parent.get_value("pipeline_code", no_exception=True) my.full_search_type = my.parent.get_search_type() else: my.pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True) my.search_type = my.sobject.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.sobject) my.full_search_type = my.sobject.get_search_type() if not my.pipeline_code: my.pipeline_code = 'default' top.add_style("text-align: left") my.set_as_panel(top) table = Table() #from tactic.ui.container import ResizableTableWdg #table = ResizableTableWdg() table.add_color("background", "background") table.add_color("color", "color") top.add(table) table.set_max_width() table.add_row() # left #td = table.add_cell(resize=False) td = table.add_cell() #td.add_style("padding: 10px") td.add_style("width: 200px") td.add_style("min-width: 200px") td.add_style("vertical-align: top") #td.add_border() #td.add_style("border-style: solid") #td.add_style("border-width: 1px 0 1px 1px") #td.add_color("border-color", "border") #td.add_color("background", "background", -10) if my.parent: code = my.parent.get_code() else: code = my.sobject.get_code() # add the tile title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add_style("font-size: 1.4em") title.add("%s" % code) title.add_border() div = DivWdg() td.add(div) div.add_class("spt_sobject_detail_top") thumb_table = Table() div.add(thumb_table) thumb_table.add_row() thumb = ThumbWdg() # use a larger version for clearer display thumb.set_icon_type('web') # prefer to see the original image, then web thumb.set_option('image_link_order', 'main|web|icon') thumb.set_option("detail", "false") thumb.set_option("icon_size", "100%") td = thumb_table.add_cell(thumb) td.add_style("vertical-align: top") td.add_style("width: 240px") td.add_style("padding: 15px") if my.parent: thumb.set_sobject(my.parent) else: thumb.set_sobject(my.sobject) sobject_info_wdg = my.get_sobject_info_wdg() sobject_info_wdg.add_style("width: 200px") td.add(sobject_info_wdg) if my.search_type == 'sthpw/task' and not my.parent: pass else: sobject_info_wdg = my.get_sobject_detail_wdg() td = table.add_cell() td.add(sobject_info_wdg) td.add_style("vertical-align: top") td.add_style("overflow: hidden") # right td = table.add_cell() td.add_style("text-align: left") td.add_style("vertical-align: top") #td.add_color("background", "background", -10) td.add_class("spt_notes_wrapper") #td.add_border() # add the title title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add("Notes") title.add_border() notes_div = DivWdg() td.add(notes_div) from tactic.ui.widget.discussion_wdg import DiscussionWdg discussion_wdg = DiscussionWdg(search_key=my.search_key, context_hidden=False, show_note_expand=False) notes_div.add(discussion_wdg) notes_div.add_style("min-width: 300px") notes_div.add_style("height: 200") notes_div.add_style("overflow-y: auto") notes_div.add_class("spt_resizable") # get the process if my.parent: process = my.sobject.get_value("process") else: process = '' # content tr = table.add_row() td = table.add_cell() td.add_attr("colspan", "5") #td.add_attr("colspan", "3") # create a state for tab. The tab only passes a search key # parent key search_key = SearchKey.get_by_sobject(my.sobject) parent = my.sobject.get_parent() if parent: parent_key = parent.get_search_key() else: parent_key = "" state = { 'search_key': search_key, 'parent_key': parent_key, 'process': process, } WebState.get().push(state) config_xml = my.get_config_xml() config = WidgetConfig.get(view="tab", xml=config_xml) if process: custom_view = "tab_config_%s" % process else: custom_view = "tab_config" search = Search("config/widget_config") search.add_filter("category", "TabWdg") search.add_filter("search_type", my.search_type) search.add_filter("view", custom_view) custom_config_sobj = search.get_sobject() if custom_config_sobj: custom_config_xml = custom_config_sobj.get_value("config") custom_config = WidgetConfig.get(view=custom_view, xml=custom_config_xml) config = WidgetConfigView(search_type='TabWdg', view=custom_view, configs=[custom_config, config]) #menu = my.get_extra_menu() #tab = TabWdg(config=config, state=state, extra_menu=menu) tab = TabWdg(config=config, state=state, show_add=False, show_remove=False, tab_offset=5) tab.add_style("margin: 0px -2px -2px -2px") td.add(tab) td.add_style("padding-top: 10px") return top
def get_config_xml(my): process = my.sobject.get_value("process") context = my.sobject.get_value("context") process_title = "Process - %s" % (process) process_name = "process_%s" % process parent_key = '' if my.parent: parent_key = SearchKey.get_by_sobject(my.parent).replace("&","&") search_key = SearchKey.get_by_sobject(my.sobject).replace("&","&") config_xml = [] config_xml.append( ''' <config> <tab>''' ) config_xml.append( ''' <element name="%s" title="%s"> <display class='tactic.ui.tools.SObjectSingleProcessDetailWdg'> <search_key>%s</search_key> <process>%s</process> <context>%s</context> </display> </element> ''' % (process_name, process_title, parent_key, process, context) ) display_options = my.kwargs options_list = [] for key, value in display_options.items(): if key in ['search_key','process', 'parent_key','checkin_ui_options','checkin_script_path','checkin_script','checkin_relative_dir']: continue options_list.append('<%(key)s>%(value)s</%(key)s>'%({'key':key, 'value': value})) """ config_xml.append( ''' <element name="checkout_%s" title="Checkout: %s "> <display class='tactic.ui.table.TaskCheckoutManageWdg'> <search_key>%s</search_key> <parent_key>%s</parent_key> %s </display> </element> ''' % (process_name, process_title, search_key, search_key, '\n'.join(options_list)) ) """ display_options = my.kwargs options_list = [] for key, value in display_options.items(): if key in ['search_key','process','show_versionless_folder']: continue options_list.append('<%(key)s>%(value)s</%(key)s>'%({'key':key, 'value': value})) wdg_xml = ''' <element name="checkin_%s" title="Checkin: %s "> <display class='tactic.ui.widget.CheckinWdg'> <search_key>%s</search_key> <process>%s</process> <context>%s</context> %s </display> </element> ''' % (process_name, process_title, parent_key, process, context, '\n'.join(options_list)) config_xml.append( wdg_xml) config_xml.append( ''' </tab> </config> ''' ) config_xml = "".join(config_xml) return config_xml
def init(my): # for snapshot and task my.child_mode = my.kwargs.get('child_mode') == 'true' my.search_key = my.kwargs.get('search_key') my.element_class = my.kwargs.get('element_class') my.use_parent = my.kwargs.get('use_parent') == 'true' my.append_context = my.kwargs.get('append_context') my.orig_parent = None incoming_process = False if my.search_key: # coming in as search_key but it's actually the note's parent my.parent = Search.get_by_search_key(my.search_key) my.orig_parent = my.parent my.orig_parent_search_type = my.parent.get_search_type() if my.use_parent: my.parent = my.parent.get_parent() if not my.parent: raise TacticException( 'Try not to set the display option [use_parent] to true since the parent cannot be found.' ) my.search_key = SearchKey.get_by_sobject(my.parent) # swap the kwargs key my.kwargs['search_key'] = my.search_key my.kwargs['use_parent'] = 'false' my.parent_search_type = my.parent.get_search_type() my.parent_search_id = my.parent.get_id() else: my.parent_search_type = my.kwargs.get('search_type') my.orig_parent_search_type = my.parent_search_type my.parent_search_id = my.kwargs.get('search_id') my.parent = Search.get_by_id(my.parent_search_type, my.parent_search_id) my.orig_parent = my.parent if my.use_parent: my.parent = my.parent.get_parent() if not my.parent: raise TacticException( 'Try not to use the display option [use_parent] since the parent cannot be found.' ) if my.parent: my.search_key = SearchKey.get_by_sobject(my.parent) if my.use_parent: my.kwargs['search_key'] = my.search_key my.kwargs['use_parent'] = 'false' my.process_names = [] # get the process names process_names = my.kwargs.get('process_names') if not process_names: if my.orig_parent_search_type in ['sthpw/task', 'sthpw/snapshot']: #my.parent = my.parent.get_parent() # most tasks don't have context by default if my.orig_parent_search_type == 'sthpw/task': context = my.orig_parent.get_value('context') if not context: context = my.orig_parent.get_value('process') else: context = my.orig_parent.get_value('context') my.process_names = [context] my.child_mode = True my.kwargs['child_mode'] = 'true' else: my.pipeline_code = my.kwargs.get('pipeline_code') if not my.pipeline_code and my.parent.has_value( 'pipeline_code'): my.pipeline_code = my.parent.get_value('pipeline_code') pipeline = Pipeline.get_by_code(my.pipeline_code) if pipeline: my.process_names = pipeline.get_process_names() else: my.process_names = process_names.split("|") incoming_process = True my.is_refresh = my.kwargs.get('is_refresh') # if nothing is derived from pipeline, use defualts if not my.process_names: my.process_names = ['default'] if my.append_context and not incoming_process: contexts = my.append_context.split('|') my.process_names.extend(contexts) # for proper refresh my.kwargs['process_names'] = '|'.join(my.process_names)
def handle_group_table(self, table, tbody, tr, td): # add some data about the sobject if not self.current_ref_sobj: return tbody.set_attr("spt_search_key", SearchKey.get_by_sobject(self.current_ref_sobj))
def get_action_wdg(my, name): '''get the action widget for ui option of note entry''' note_wdg = DivWdg() note_wdg.add_style("padding-top: 3px") # note options option = DivWdg(css='spt_uber_note_option') cb = CheckboxWdg('is_private') #cb.set_default_checked() checkbox_name = 'note_master_private_cb' master_cb = CheckboxWdg(checkbox_name) if master_cb.is_checked(): cb.set_default_checked() option.add_style('margin-right', '5px') option.add_style('float', 'right') option.add(cb) option.add('private') #commit = TextBtnWdg(label='save', size='small') commit = ActionButtonWdg(title='save', tip="Save Changes") commit.add_style('margin-top: -5px') commit.add_style('margin-bottom: 5px') commit.add_style('float: right') commit.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var td = bvr.src_el.getParent(".spt_table_td"); var text = td.getElement(".spt_note_text"); text.blur(); spt.dg_table.update_row(evt, bvr); td.setStyle('background-color',''); ''', 'cell_only': True }) #commit.set_scale("0.75") # do some gynastics to handle a refresh. if my.parent_wdg: info = my.parent_wdg.get_aux_info() sobject_dict = info.get('sobjects') sobject = sobject_dict.get(my.get_name()) parent = info.get('parent') else: sobject = None parent = None if not sobject: if my.parent_key: parent = SearchKey.get_by_search_key(my.parent_key) # get the latest note #search_key = my.kwargs.get("search_key") #if search_key: # sobject = SearchKey.get_by_search_key(search_key) search = Search('sthpw/note') search.add_parent_filter(parent) search.add_filter('context', name) # Make the assumption that the last one entered is by timestamp search.add_order_by('timestamp desc') sobject = search.get_sobject() # Show a history of notes if sobject: history = ActionButtonWdg(title='history', tip="Show note history") #history = TextBtnWdg(label='history', size='small') #history.get_top_el().add_style("margin-left: 4px") #history.get_top_el().add_style('float: left') history.add_style("float: left") history.add_style("margin-top: -5px") history.add_style("margin-bottom: 5px") note_wdg.add(history) my.parent_key = SearchKey.get_by_sobject(parent) context = name filter = '[{"prefix":"main_body","main_body_enabled":"on","main_body_column":"context","main_body_relation":"is","main_body_value":"%s"}]' % context history.add_behavior({ 'type': 'click_up', 'cbjs_action': "spt.popup.get_widget(evt, bvr)", 'options': { 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'title': 'Notes History', 'popup_id': 'Notes_History_%s' % context }, 'args': { 'search_type': 'sthpw/note', 'view': 'summary', 'parent_key': my.parent_key, 'filter': filter, } }) note_wdg.add(commit) note_wdg.add(option) note_wdg.add("<br clear='all'/>") from pyasm.biz import PrefSetting quick_text = PrefSetting.get_value_by_key('quick_text') if quick_text: quick_sel = SelectWdg('quick_text', label='quick: ') quick_sel.set_option('values', quick_text) quick_sel.add_empty_option('-- text --', '') quick_sel.add_behavior({ 'type': 'change', 'cbjs_action': '''var val = bvr.src_el.value; var text=bvr.src_el.getParent('.spt_note_top').getElement('.spt_note_text') text.value = text.value + val; ''' }) note_wdg.add(SpanWdg(quick_sel, css='small')) note_wdg.add(HtmlElement.br(2)) # Show the last note note_wdg.add("<i>Last note</i> ") if sobject: timestamp = sobject.get_value("timestamp") timestamp = parser.parse(timestamp) timestamp = timestamp.strftime("%m/%d %H:%M") timestamp_div = SpanWdg() timestamp_div.add("(%s)" % timestamp) note_wdg.add(timestamp_div) timestamp_div.add_style("font-size: 11px") timestamp_div.add_style("font-style: italic") # add a private tag access = sobject.get_value("access") if access == 'private': private = SpanWdg() #private.add_style('float: right') private.add(" <i>-- private --</i>") note_wdg.add(private) hr = DivWdg("<hr/>") hr.add_style("height: 1px") hr.add_style("margin-top: -5px") note_wdg.add(hr) div = DivWdg() note_wdg.add(div) div.add_style("max-height", "50px") div.add_style("overflow", "auto") div.add_style("padding: 3px") if sobject: value = sobject.get_value('note') from pyasm.web import WikiUtil value = WikiUtil().convert(value) div.add(value) else: no_notes = DivWdg() div.add(no_notes) no_notes.add('<i> -- No Notes --</i>') no_notes.add_style("font-size: 11px") no_notes.add_style("opacity: 0.7") return note_wdg
def get_display(my): mode = my.get_option('mode') size = my.get_option('icon_size') if mode == 'add': my.set_option('icon', "CHECK_OUT") else: if size == 'large': my.set_option('icon', "CHECK_OUT_LG") else: my.set_option('icon', "CHECK_OUT_SM") top = DivWdg() icon = IconButtonWdg("Checkout", eval("IconWdg.%s" % my.get_option('icon'))) top.add(icon) my.process = my.get_option('process') my.context = '' transfer_mode = my.get_option('transfer_mode') sobject = my.get_current_sobject() if sobject.get_id() == -1: sobject = None snapshot_code = my.get_option("snapshot_code") sandbox_dir = my.get_option("sandbox_dir") if not sandbox_dir and sobject and isinstance(sobject, Snapshot): sandbox_dir = sobject.get_sandbox_dir(file_type='main') snapshot_code = sobject.get_code() lock_process = my.get_option("lock_process") sobject = my.get_current_sobject() search_key = SearchKey.get_by_sobject(sobject) if sobject.get_base_search_type() in ['sthpw/task', 'sthpw/note']: my.process = sobject.get_value('process') my.context = sobject.get_value('context') if not my.process: my.process = '' parent = sobject.get_parent() if not parent: return DivWdg() search_key = SearchKey.get_by_sobject(parent) else: my.process = my.get_option('process') search_key = SearchKey.get_by_sobject(sobject) checkout_script_path = my.get_option("checkout_script_path") checkout_panel_script_path = my.get_option( "checkout_panel_script_path") lock_process = my.get_option("lock_process") if not checkout_script_path: checkout_script_path = '' if not checkout_panel_script_path: checkout_panel_script_path = '' # FIXME: this does not get passed through 'cuz get_display is overridden here # so passed in directly in the script below my.behavior['checkout_panel_script_path'] = checkout_panel_script_path my.behavior['checkout_script_path'] = checkout_script_path my.behavior['process'] = my.process my.behavior['context'] = my.context my.behavior['lock_process'] = lock_process my.behavior['search_key'] = search_key my.behavior['snapshot_code'] = snapshot_code my.behavior['sandbox_dir'] = sandbox_dir my.behavior['transfer_mode'] = transfer_mode #layout_wdg = my.get_layout_wdg() #state = layout_wdg.get_state() cbjs_action = ''' var kwargs = { search_key: '%(search_key)s', sandbox_dir: '%(sandbox_dir)s', process: '%(process)s', context: '%(context)s', lock_process: '%(lock_process)s', checkout_script_path: '%(checkout_script_path)s' }; var transfer_mode = bvr.transfer_mode; if (!transfer_mode) { transfer_mode = spt.Environment.get().get_transfer_mode(); } if (transfer_mode == null) { transfer_mode = 'web'; } // NOTE: reusing checkin transfer mode if (transfer_mode == 'copy') { transfer_mode = 'client_repo'; } var values = {}; var top = bvr.src_el.getParent(".spt_checkin_top"); script = spt.CustomProject.get_script_by_path(bvr.checkout_panel_script_path); if (script) { bvr['script'] = script; bvr.values = kwargs; setTimeout( function() { try { spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { throw(e); spt.alert('No script found. <checkout_panel_script_path> display option should refer to a valid script path.'); } spt.app_busy.hide(); }, 50); } else { if (bvr.snapshot_code) { if (!bvr.checkout_script_path){ spt.app_busy.show("Checking out files", 'To: '+ bvr.sandbox_dir); setTimeout( function() { try { var server = TacticServerStub.get(); file_types = ['main']; filename_mode = 'source'; // we want this undefined so the checkout // snapshot can deal with it correctly. Explicitly // putting in a dir will force it to go there, // regardless of naming conventions sandbox_dir = null; server.checkout_snapshot(bvr.snapshot_code, sandbox_dir, {mode: transfer_mode, filename_mode: filename_mode, file_types: file_types} ); var checkin_top = bvr.src_el.getParent(".spt_checkin_top"); if (checkin_top) { spt.app_busy.show("Reading file system ...") spt.panel.refresh(checkin_top); spt.app_busy.hide(); } } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } else { setTimeout( function() { try { bvr['script'] = bvr.checkout_script_path; bvr.values = kwargs; spt.CustomProject.exec_custom_script(evt, bvr); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); }, 50); } } else { var class_name = 'tactic.ui.widget.CheckoutWdg'; var values = kwargs; bvr.values = values; var search_key = values.search_key; var sandbox_dir = values.sandbox_dir; var process = values.process; var context = values.context; var options = { 'show_publish': 'false', 'process': process, 'context': context, 'search_key': search_key, 'checkout_script_path': bvr.checkout_script_path, 'sandbox_dir': sandbox_dir }; var popup_id ='Check-out Widget'; spt.panel.load_popup(popup_id, class_name, options); } } ''' % (my.behavior) my.behavior['type'] = 'click_up' my.behavior['cbjs_action'] = cbjs_action icon.add_behavior(my.behavior) return top
def _test_dir_naming(my): # change to the test dir naming class my.sobj.set_value('dir_naming_cls', 'pyasm.biz.naming_test.TestDirNaming') my.sobj.commit() # 1. try a different search_type unittest/person version = 9 code = 'phil2' process = 'model' type = 'main' context = 'modeling' asset = SearchType.create( 'unittest/person' ) asset.set_value("code",code) asset.set_value("name_first", "Philip") asset.commit() # change a different input file name file_obj = File(File.SEARCH_TYPE) # due to new restriction of set_sobject_value().. we can't use it any more #file_obj.set_sobject_value(asset) sk = SearchKey.get_by_sobject(asset, use_id =True) st = SearchKey.extract_search_type(sk) sid = SearchKey.extract_id(sk) file_obj.set_value('search_type', st) file_obj.set_value('search_id', sid) file_obj.set_value('file_name','some_maya_model.mb') file_obj.set_value('type', type) file_obj.set_value('base_type', 'file') file_obj.commit() virtual_snapshot = Snapshot.create_new() virtual_snapshot_xml = '<snapshot process=\'%s\'><file type=\'%s\' file_code=\'%s\'/></snapshot>' % (process, type, file_obj.get_code()) virtual_snapshot.set_value("snapshot", virtual_snapshot_xml) virtual_snapshot.set_value("context", context) virtual_snapshot.set_sobject(asset) virtual_snapshot.set_value("version", version) Project.set_project('unittest') dir_naming = Project.get_dir_naming() dir_naming.set_sobject(asset) dir_naming.set_snapshot(virtual_snapshot) dir_naming.set_file_object(file_obj) dir_name = dir_naming.get_dir() expected_dir_name = '/assets/phil2/mb.main/v009' expected_dir_name2 = '/phil2/mb.main/v009' my.assertEquals(expected_dir_name, dir_name) lib_paths = virtual_snapshot.get_all_lib_paths() sand_paths = virtual_snapshot.get_all_lib_paths(mode='sandbox') client_paths = virtual_snapshot.get_all_lib_paths(mode='client_repo') base_dir = Config.get_value("checkin", "asset_base_dir", sub_key='default') sand_base_dir = dir_naming.get_base_dir(protocol='sandbox') client_base_dir = dir_naming.get_base_dir(protocol='client_repo') my.assertEquals(lib_paths[0].startswith('%s%s'%(base_dir, expected_dir_name2)), True) my.assertEquals(sand_paths[0].startswith('%s%s'%(sand_base_dir[0], expected_dir_name2)), True) my.assertEquals(client_paths[0].startswith('%s%s'%(client_base_dir[0], expected_dir_name2)), True) # 2 get_preallocated_path # set version 1 here since it's the first snapshot for this sobject. # without a virtual file_object, the file_name is empty, and so the dir ma.maya is now .maya my.assertEquals("phil/.maya/v001", my.get_preallocated_dir()) # switch back to regular file naming my.sobj.set_value('file_naming_cls', 'pyasm.biz.naming_test.TestFileNaming') my.sobj.commit() my.assertEquals("phil/ma.maya/v001", my.get_preallocated_dir())