def get_display(my): search_key = my.kwargs.get("search_key") msg = None base_search_type = SearchKey.extract_search_type(search_key) sobject = SearchKey.get_by_search_key(search_key) process_div = DivWdg() process_div.add_style('padding-top: 10px') if 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 parent: search_key = SearchKey.get_by_sobject(parent) else: msg = "Parent for [%s] not found"%search_key else: my.process = my.kwargs.get('process') top = my.top top.add_class('spt_simple_checkin') top.add_color("background", "background") top.add_styles("position: relative") content = DivWdg(msg) top.add(content) #content.add_border() #content.add_color("background", "background3") #content.add_color("color", "background3") content.add_style("width: 600px") content.add_styles("margin-left: auto; margin-right: auto;") content.add_style("height: 200px") from tactic.ui.widget import CheckinWdg content.add_behavior( { 'type': 'load', 'cbjs_action': CheckinWdg.get_onload_js() } ) button_div = DivWdg() content.add(process_div) content.add(button_div) button = IconWdg(title="Check-In", icon=IconWdg.CHECK_IN_3D_LG) title = Common.get_display_title(my.checkin_action) button.add_attr('title', title) button_div.add(button) button_div.set_box_shadow("1px 1px 1px 1px") button_div.add_style("width: 60px") button_div.add_style("height: 60px") button_div.add_style("float: left") button_div.add_style("background: white") button_div.add_class("hand") button_div.add_style("padding: 2px 3px 0 0") button_div.add_style("margin: 20px 60px 20px 200px") button_div.add_style("text-align: center") button_div.add("Check-in") # to be consistent with Check-in New File if my.process: checkin_process = my.process else: # Dont' specify, the user can choose later in check-in widget checkin_process = '' button.add_behavior( { 'type': 'click_up', 'search_key': search_key, 'process': checkin_process, 'context': my.context, 'cbjs_action': ''' var class_name = 'tactic.ui.widget.CheckinWdg'; var applet = spt.Applet.get(); spt.app_busy.show("Choose file(s) to check in") var current_dir = null; var is_sandbox = false; var refresh = false var values = spt.checkin.browse_folder(current_dir, is_sandbox, refresh); if (!values) { spt.app_busy.hide(); return; } var file_paths = values.file_paths; if (file_paths.length == 0) { spt.alert("You need to select files(s) to check in."); spt.app_busy.hide(); return; } spt.app_busy.hide(); var args = { 'search_key': bvr.search_key, 'show_links': false, 'show_history': false, 'close_on_publish': true } if (bvr.process) args.process = bvr.process; if (bvr.context) args.context = bvr.context; var kwargs = {}; kwargs.values = values; spt.panel.load_popup("Check-in", class_name, args, kwargs); /* var options= { title: "Check-in Widget", class_name: 'tactic.ui.widget.CheckinWdg', popup_id: 'checkin_widget' }; var bvr2 = {}; bvr2.options = options; bvr2.values = values; bvr2.args = args; spt.popup.get_widget({}, bvr2) */ ''' } ) button_div = DivWdg() content.add(button_div) button = IconWdg(title="Check-Out", icon=IconWdg.CHECK_OUT_3D_LG) button_div.add(button) button_div.set_box_shadow("1px 1px 1px 1px") button_div.add_style("width: 60px") button_div.add_style("height: 60px") button_div.add_style("float: left") button_div.add_style("margin: 20px") button_div.add_style("padding: 2px 3px 0 0") button_div.add_style("background: white") button_div.add_class("hand") button_div.add_style("text-align: center") button_div.add("Check-out") sobject = SearchKey.get_by_search_key(search_key) # snapshot is retrieved for getting the process informatoin, they are not being used # for loading as real_time snapshot query option is used. search = Search("sthpw/snapshot") search.add_sobject_filter(sobject) if my.process: search.add_filter("process", my.process) search.add_filter("is_latest", True) snapshot = search.get_sobject() if not my.process and snapshot: my.process = snapshot.get_value('process') # for old process-less snapshots if not my.process: my.process = snapshot.get_value('context') process_wdg = DivWdg(HtmlElement.b(checkin_process)) if checkin_process: width = len(checkin_process)*10 else: width = 10 process_wdg.add_styles('margin-left: auto; margin-right: auto; text-align: center; width: %s'%width) process_div.add(process_wdg) # DO NOT pass in snapshot_code, get it in real time snapshot_codes = [] show_status = True if my.checkout_action == 'latest': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status) bvr = {'snapshot_codes': snapshot_codes, 'real_time': True, 'file_types': ['main'], 'filename_mode': 'repo', 'cbjs_action': cbjs_action} elif my.checkout_action == 'latest (version_omitted)': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status) bvr = {'snapshot_codes':snapshot_codes, 'real_time': True, 'file_types': ['main'], 'filename_mode': 'versionless', 'cbjs_action': cbjs_action} elif my.checkout_action == 'latest versionless': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status) bvr = {'snapshot_codes':snapshot_codes, 'real_time': True, 'versionless': True, 'file_types': ['main'], 'filename_mode': 'versionless', 'cbjs_action': cbjs_action} elif my.checkout_action == 'open file browser': bvr = { 'cbjs_action': ''' var class_name = 'tactic.ui.checkin.SObjectDirListWdg'; var kwargs = { search_keys: [bvr.search_key], process: '%s' }; spt.panel.load_popup("Check-out", class_name, kwargs); '''%my.process } bvr.update({ 'type': 'click_up', 'search_key': search_key}) button.add_behavior(bvr) title = Common.get_display_title(my.checkout_action) button.add_attr('title', title) #TODO: remove these margin-top which is used to compensate all the ButtonNewWdg top extra white space content.add("<br clear='all'/>") status_div = DivWdg() status_div.add_style('margin: 20px 0 0 10px') status_div.add_style('width: 100%') text_info = FloatDivWdg() text_info.add_styles('padding: 4px; width: 500px') text_info.add_style('margin-top: 8px') text_info.add_attr('title','Displays the last checked out file path') text_info.add_border() text_info.set_round_corners() text_content = DivWdg() text_content.add(' ') text_content.add_class('spt_status_area') text_info.add(text_content) label = FloatDivWdg('path:') label.add_style('margin: 12px 6px 0 6px') # button button = ButtonNewWdg(title="Explore", icon=IconWdg.FOLDER_GO) button.add_style('padding-bottom: 15px') button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var applet = spt.Applet.get(); var status_div = bvr.src_el.getParent('.spt_simple_checkin').getElement('.spt_status_area'); var value = status_div.get('text'); var dir_name = spt.path.get_dirname(value); if (dir_name) applet.open_explorer(dir_name); ''' } ) status_div.add(label) status_div.add(text_info) content.add(status_div) content.add(button) content.add_behavior({'type':'load', 'cbjs_action': ''' if (!spt.Applet.applet) { spt.api.app_busy_show('Initializing Java', 'Please wait...'); var exec = function() {var applet = spt.Applet.get()}; spt.api.app_busy_hide(exec); }'''}) return top
def get_display(self): element_data_dict = {} config = self.get_config() element_names = config.get_element_names() content_wdg = DivWdg() content_wdg.add_class("spt_simple_search_top") onload_js = DivWdg() content_wdg.add(onload_js) onload_js.add_behavior({ 'type': 'load', 'cbjs_action': self.get_onload_js() }) if not element_names: element_names = ['keywords'] self.set_content(content_wdg) # this is somewhat duplicated logic from alter_search, but since this is called # in ViewPanelWdg, it's a diff instance and needs to retrieve again filter_data = FilterData.get() filter_view = self.kwargs.get("filter_view") if filter_view: search = Search("config/widget_config") search.add_filter("view", filter_view) search.add_filter("category", "search_filter") search.add_filter("search_type", self.search_type) filter_config = search.get_sobject() if filter_config: filter_xml = filter_config.get_xml_value("config") filter_value = filter_xml.get_value("config/filter/values") if filter_value: data_list = jsonloads(filter_value) else: data_list = filter_data.get_values_by_prefix(self.prefix) for data in data_list: handler = data.get("handler") element_name = data.get("element_name") if not element_name: continue element_data_dict[element_name] = data elements_wdg = DivWdg() content_wdg.add(elements_wdg) elements_wdg.add_color("color", "color") elements_wdg.add_style("padding-top: 10px") elements_wdg.add_style("padding-bottom: 15px") #elements_wdg.add_color("background", "background3", 0) elements_wdg.add_color("background", "background", -3) elements_wdg.add_border() if len(element_names) == 1: elements_wdg.add_style("border-width: 0px 0px 0px 0px") elements_wdg.add_style("padding-right: 50px") else: elements_wdg.add_style("border-width: 0px 0px 0px 0px") table = Table() table.add_color("color", "color") elements_wdg.add(table) table.add_class("spt_simple_search_table") columns = self.kwargs.get("columns") if not columns: columns = 2 else: columns = int(columns) num_rows = int(len(element_names) / columns) + 1 tot_rows = int(len(element_names) / columns) + 1 project_code = Project.get_project_code() # self.search_type could be the same as self.base_search_type full_search_type = SearchType.build_search_type( self.search_type, project_code) visible_rows = self.kwargs.get("visible_rows") if visible_rows: visible_rows = int(visible_rows) num_rows = visible_rows else: visible_rows = 0 titles = config.get_element_titles() row_count = 0 for i, element_name in enumerate(element_names): attrs = config.get_element_attributes(element_name) if i % columns == 0: if visible_rows and row_count == visible_rows: tr, td = table.add_row_cell("+ more ...") td.add_class("hand") td.add_class("SPT_DTS") td.add_class("spt_toggle") td.add_style("padding-left: 10px") td.add_behavior({ 'type': 'click_up', 'visible_rows': visible_rows, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_simple_search_table"); var expand = true; var rows = top.getElements(".spt_simple_search_row"); for (var i = 0; i < rows.length; i++) { var row = rows[i]; if (row.getStyle("display") == "none") { row.setStyle("display", ""); } else { row.setStyle("display", "none"); expand = false; } } var spacer = top.getElements(".spt_spacer"); var cell = top.getElement(".spt_toggle"); if (expand) { spacer.setStyle("height", (rows.length+bvr.visible_rows)*20); cell.innerHTML = "- less ..."; } else { spacer.setStyle("height", bvr.visible_rows*20); cell.innerHTML = "+ more ..."; } ''' }) tr = table.add_row() if visible_rows and row_count >= visible_rows: tr.add_class("spt_simple_search_row") tr.add_style("display: none") tr.add_style("height: 0px") row_count += 1 icon_td = table.add_cell() title_td = table.add_cell() element_td = table.add_cell() # need to add these to all the elements because it is all separated # by table tds icon_td.add_class("spt_element_item") icon_td.add_attr("spt_element_name", element_name) title_td.add_class("spt_element_item") title_td.add_attr("spt_element_name", element_name) element_td.add_class("spt_element_item") element_td.add_attr("spt_element_name", element_name) # show the title title_td.add_style("text-align: left") title_td.add_style("padding-right: 5px") title_td.add_style("min-width: 60px") element_wdg = DivWdg() if attrs.get('view') == 'false': element_wdg.add_style('display: none') element_td.add(element_wdg) if i >= 0 and i < columns - 1 and len(element_names) > 1: spacer = DivWdg() spacer.add_class("spt_spacer") spacer.add_style("border-style: solid") spacer.add_style("border-width: 0 0 0 0") #spacer.add_style("height: %spx" % (num_rows*20)) spacer.add_style("height: %spx" % (num_rows * 10)) spacer.add_style("width: 10px") spacer.add_style("border-color: %s" % spacer.get_color("border")) spacer.add(" ") td = table.add_cell(spacer) td.add_attr("rowspan", tot_rows) element_wdg.add_style("padding: 4px 10px 4px 5px") element_wdg.add_class("spt_table_search") element_wdg.add_style("margin: 1px") element_wdg.add_style("min-height: 20px") element_wdg.add_style("min-width: 250px") # this is done at get_top() #element_wdg.add_class("spt_search") element_wdg.add(HiddenWdg("prefix", self.prefix)) display_handler = config.get_display_handler(element_name) element_wdg.add(HiddenWdg("handler", display_handler)) element_wdg.add(HiddenWdg("element_name", element_name)) from pyasm.widget import ExceptionWdg try: widget = config.get_display_widget(element_name) if widget: widget.set_title(titles[i]) except Exception as e: element_wdg.add(ExceptionWdg(e)) continue if not widget: # the default for KeywordFilterElementWdg is mode=keyword if not self.column_choice: self.column_choice = self.get_search_col(self.search_type) widget = KeywordFilterElementWdg(column=self.column_choice) widget.set_name(element_name) from pyasm.widget import IconWdg icon_div = DivWdg() icon_td.add(icon_div) icon_div.add_style("width: 20px") icon_div.add_style("margin-top: -2px") icon_div.add_style("padding-left: 6px") icon_div.add_class("spt_filter_top") widget.set_show_title(False) #element_wdg.add("%s: " % title) data = element_data_dict.get(element_name) view_panel_keywords = self.kwargs.get("keywords") #user data takes precedence over view_panel_keywords if isinstance(widget, KeywordFilterElementWdg): if view_panel_keywords: widget.set_value("value", view_panel_keywords) if data: widget.set_values(data) if isinstance( widget, KeywordFilterElementWdg ) and not full_search_type.startswith('sthpw/sobject_list'): widget.set_option('filter_search_type', full_search_type) try: if attrs.get('view') != 'false': title_td.add(widget.get_title_wdg()) element_wdg.add(widget.get_buffer_display()) except Exception as e: element_wdg.add(ExceptionWdg(e)) continue icon = IconWdg("Filter Set", "BS_ASTERISK") #icon.add_style("color", "#393") icon_div.add(icon) icon.add_class("spt_filter_set") icon.add_class("hand") icon.add_attr("spt_element_name", element_name) icon.add_behavior({ 'type': 'click', 'cbjs_action': ''' var element_name = bvr.src_el.getAttribute("spt_element_name"); spt.simple_search.clear_element(element_name); ''' }) if not widget.is_set(): icon.add_style("display: none") else: color = icon_div.get_color("background", -10) icon_td.add_style("background-color", color) title_td.add_style("background-color", color) element_td.add_style("background-color", color) #elements_wdg.add("<br clear='all'/>") top = self.get_top() return top
def get_display(self): element_data_dict = {} config = self.get_config() element_names = config.get_element_names() content_wdg = DivWdg() content_wdg.add_class("spt_simple_search_top") onload_js = DivWdg() content_wdg.add(onload_js) onload_js.add_behavior( { 'type': 'load', 'cbjs_action': self.get_onload_js() } ) if not element_names: element_names = ['keywords'] self.set_content(content_wdg) # this is somewhat duplicated logic from alter_search, but since this is called # in ViewPanelWdg, it's a diff instance and needs to retrieve again filter_data = FilterData.get() filter_view = self.kwargs.get("filter_view") if filter_view: search = Search("config/widget_config") search.add_filter("view", filter_view) search.add_filter("category", "search_filter") search.add_filter("search_type", self.search_type) filter_config = search.get_sobject() if filter_config: filter_xml = filter_config.get_xml_value("config") filter_value = filter_xml.get_value("config/filter/values") if filter_value: data_list = jsonloads(filter_value) else: data_list = filter_data.get_values_by_prefix(self.prefix) for data in data_list: handler = data.get("handler") element_name = data.get("element_name") if not element_name: continue element_data_dict[element_name] = data elements_wdg = DivWdg() content_wdg.add(elements_wdg) elements_wdg.add_color("color", "color") elements_wdg.add_style("padding-top: 10px") elements_wdg.add_style("padding-bottom: 15px") #elements_wdg.add_color("background", "background3", 0) elements_wdg.add_color("background", "background", -3) elements_wdg.add_border() if len(element_names) == 1: elements_wdg.add_style("border-width: 0px 0px 0px 0px" ) elements_wdg.add_style("padding-right: 50px" ) else: elements_wdg.add_style("border-width: 0px 0px 0px 0px" ) table = Table() table.add_color("color", "color") elements_wdg.add(table) table.add_class("spt_simple_search_table") columns = self.kwargs.get("columns") if not columns: columns = 2 else: columns = int(columns) num_rows = int(len(element_names)/columns)+1 tot_rows = int(len(element_names)/columns)+1 project_code = Project.get_project_code() # self.search_type could be the same as self.base_search_type full_search_type = SearchType.build_search_type(self.search_type, project_code) visible_rows = self.kwargs.get("visible_rows") if visible_rows: visible_rows = int(visible_rows) num_rows = visible_rows else: visible_rows = 0 titles = config.get_element_titles() row_count = 0 for i, element_name in enumerate(element_names): attrs = config.get_element_attributes(element_name) if i % columns == 0: if visible_rows and row_count == visible_rows: tr, td = table.add_row_cell("+ more ...") td.add_class("hand") td.add_class("SPT_DTS") td.add_class("spt_toggle") td.add_style("padding-left: 10px") td.add_behavior( { 'type': 'click_up', 'visible_rows': visible_rows, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_simple_search_table"); var expand = true; var rows = top.getElements(".spt_simple_search_row"); for (var i = 0; i < rows.length; i++) { var row = rows[i]; if (row.getStyle("display") == "none") { row.setStyle("display", ""); } else { row.setStyle("display", "none"); expand = false; } } var spacer = top.getElements(".spt_spacer"); var cell = top.getElement(".spt_toggle"); if (expand) { spacer.setStyle("height", (rows.length+bvr.visible_rows)*20); cell.innerHTML = "- less ..."; } else { spacer.setStyle("height", bvr.visible_rows*20); cell.innerHTML = "+ more ..."; } ''' } ) tr = table.add_row() if visible_rows and row_count >= visible_rows: tr.add_class("spt_simple_search_row") tr.add_style("display: none") tr.add_style("height: 0px") row_count += 1 icon_td = table.add_cell() title_td = table.add_cell() element_td = table.add_cell() # need to add these to all the elements because it is all separated # by table tds icon_td.add_class("spt_element_item") icon_td.add_attr("spt_element_name", element_name) title_td.add_class("spt_element_item") title_td.add_attr("spt_element_name", element_name) element_td.add_class("spt_element_item") element_td.add_attr("spt_element_name", element_name) # show the title title_td.add_style("text-align: left") title_td.add_style("padding-right: 5px") title_td.add_style("min-width: 60px") element_wdg = DivWdg() if attrs.get('view') == 'false': element_wdg.add_style('display: none') element_td.add(element_wdg) if i >= 0 and i < columns -1 and len(element_names) > 1: spacer = DivWdg() spacer.add_class("spt_spacer") spacer.add_style("border-style: solid") spacer.add_style("border-width: 0 0 0 0") #spacer.add_style("height: %spx" % (num_rows*20)) spacer.add_style("height: %spx" % (num_rows*10)) spacer.add_style("width: 10px") spacer.add_style("border-color: %s" % spacer.get_color("border") ) spacer.add(" ") td = table.add_cell(spacer) td.add_attr("rowspan", tot_rows) element_wdg.add_style("padding: 4px 10px 4px 5px") element_wdg.add_class("spt_table_search") element_wdg.add_style("margin: 1px") element_wdg.add_style("min-height: 20px") element_wdg.add_style("min-width: 250px") # this is done at get_top() #element_wdg.add_class("spt_search") element_wdg.add( HiddenWdg("prefix", self.prefix)) display_handler = config.get_display_handler(element_name) element_wdg.add( HiddenWdg("handler", display_handler)) element_wdg.add( HiddenWdg("element_name", element_name)) from pyasm.widget import ExceptionWdg try: widget = config.get_display_widget(element_name) if widget: widget.set_title(titles[i]) except Exception as e: element_wdg.add(ExceptionWdg(e)) continue if not widget: # the default for KeywordFilterElementWdg is mode=keyword if not self.column_choice: self.column_choice = self.get_search_col(self.search_type) widget = KeywordFilterElementWdg(column=self.column_choice) widget.set_name(element_name) from pyasm.widget import IconWdg icon_div = DivWdg() icon_td.add(icon_div) icon_div.add_style("width: 20px") icon_div.add_style("margin-top: -2px") icon_div.add_style("padding-left: 6px") icon_div.add_class("spt_filter_top") widget.set_show_title(False) #element_wdg.add("%s: " % title) data = element_data_dict.get(element_name) view_panel_keywords = self.kwargs.get("keywords") #user data takes precedence over view_panel_keywords if isinstance(widget, KeywordFilterElementWdg): if view_panel_keywords: widget.set_value("value", view_panel_keywords) if data: widget.set_values(data) if isinstance(widget, KeywordFilterElementWdg) and not full_search_type.startswith('sthpw/sobject_list'): widget.set_option('filter_search_type', full_search_type) try: if attrs.get('view') != 'false': title_td.add(widget.get_title_wdg()) element_wdg.add(widget.get_buffer_display()) except Exception as e: element_wdg.add(ExceptionWdg(e)) continue icon = IconWdg("Filter Set", "BS_ASTERISK") #icon.add_style("color", "#393") icon_div.add(icon) icon.add_class("spt_filter_set") icon.add_class("hand") icon.add_attr("spt_element_name", element_name) icon.add_behavior( { 'type': 'click', 'cbjs_action': ''' var element_name = bvr.src_el.getAttribute("spt_element_name"); spt.simple_search.clear_element(element_name); ''' } ) if not widget.is_set(): icon.add_style("display: none") else: color = icon_div.get_color("background", -10) icon_td.add_style("background-color", color) title_td.add_style("background-color", color) element_td.add_style("background-color", color) #elements_wdg.add("<br clear='all'/>") top = self.get_top() return top