def get_display(self): parser = self.kwargs.get("parser") self.search_key = self.kwargs.get("search_key") sobject = Search.get_by_search_key(self.search_key) if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject elif sobject.get_base_search_type() == "sthpw/file": # if it is a file object snapshot = sobject.get_parent() else: snapshots = Snapshot.get_by_sobject(sobject, is_latest=True) snapshot = snapshots[0] # Extension determine UI class for preview thumb_path = snapshot.get_web_path_by_type("icon") web_src = snapshot.get_web_path_by_type("web") from pyasm.biz import File file_type = "main" lib_path = snapshot.get_lib_path_by_type(file_type) src = snapshot.get_web_path_by_type(file_type) if not web_src: web_src = src parts = os.path.splitext(src) ext = parts[1] ext = ext.lstrip(".") ext = ext.lower() #parent = snapshot.get_parent() top = self.top self.set_as_panel(top) if ext == "pdf": iframe = HtmlElement.iframe() iframe.set_attr('src', src) iframe.add_style("width: 100%") iframe.add_style("height: 800px") top.add(iframe) return top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) tr = table.add_row() # These bvrs allow for smooth switching if switching between files # like in the RepoBrowserWdg tr.add_style("height: 200px") load_height_bvr = { 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' } tr.add_behavior(load_height_bvr) unload_height_bvr = { 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' } tr.add_behavior(unload_height_bvr) table.add_style("width: 100%") table.add_style("text-align", "center") from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color( "background", "background", ) td.add_style("vertical-align: middle") td.add_style("height: inherit") td.add_style("overflow-x: auto") if ext in ['txt', 'html', 'ini']: content_div = DivWdg() f = open(lib_path, 'r') content = f.read(10000) f.close() if not content: text = "No Content" else: size = os.path.getsize(lib_path) from pyasm.common import FormatValue value = FormatValue().get_format_value(size, "KB") content_div.add("Showing first 10K of %s<hr/>" % value) text = TextAreaWdg() text.add(content) text.add_style("width: 100%") text.add_style("height: 100%") text.add_style("padding: 10px") text.add_style("border: none") text.add_attr("readonly", "true") content_div.add(text) td.add(content_div) content_div.add_style("color", "#000") content_div.add_style("width", "auto") content_div.add_style("margin", "20px") content_div.add_style("height", "100%") elif ext in File.IMAGE_EXT or ext == "gif": if lib_path.find("#") != -1: img = DivWdg() file_range = snapshot.get_file_range() file_range_div = DivWdg() file_range_div.add("File Range: %s" % file_range.get_display()) img.add(file_range_div) file_range_div.add_style("font-size: 1.4em") file_range_div.add_style("margin: 15px 0px") """ left_chevron = IconWdg("Previous", "BS_CHEVRON_LEFT") file_range_div.add(left_chevron) right_chevron = IconWdg("Next", "BS_CHEVRON_RIGHT") file_range_div.add(right_chevron) """ expanded_paths = snapshot.get_expanded_web_paths() lib_paths = snapshot.get_expanded_lib_paths() lib_path = lib_paths[0] items_div = DivWdg() img.add(items_div) items_div.add_style("width: auto") for path in expanded_paths: item = HtmlElement.img(src=path) items_div.add(item) item.add_style("max-height: 300px") item.add_style("height: auto") item.add_style("width: 32%") item.add_style("margin: 2px") item.add_style("display: inline-block") #item.add_class("spt_resizable") img.add_style("margin: 20px") img.add_style("max-height: 400px") img.add_style("overflow-y: auto") img.add_style("overflow-hidden: auto") img.add_style("text-align: left") else: if ext == "gif": img = HtmlElement.img(src=src) else: img = HtmlElement.img(src=web_src) img.add_style("height: inherit") img.add_style("width: auto") td.add(img) elif ext in File.VIDEO_EXT: embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path, preload="auto", controls=True) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_behavior(load_height_bvr) embed_wdg.add_behavior(unload_height_bvr) else: thumb_table = DivWdg() td.add(thumb_table) thumb_table.add_behavior({ 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' }) thumb_table.add_class("hand") thumb_table.add_style("width: 200px") thumb_table.add_style("height: 125px") thumb_table.add_style("padding: 5px") thumb_table.add_style("margin-left: 20px") thumb_table.add_style("display: inline-block") thumb_table.add_style("vertical-align: top") thumb_table.add_style("overflow-y: hidden") from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() thumb_table.add(thumb) thumb.set_sobject(snapshot) table.add_row() td = table.add_cell() from tactic.ui.checkin import PathMetadataWdg from tactic.ui.checkin import SnapshotMetadataWdg from pyasm.widget import SelectWdg select = SelectWdg(name="parser") select.add_style("width: 125px") select.add_style("margin-top: 0px") select.add_style("margin-right: 10px") select.add_empty_option("-- Metadata --") td.add(select) select.add_style("float: right") select.set_option("values", ["IPTC", "EXIF", "XMP", "ImageMagick", "PIL"]) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var parser = bvr.src_el.value; spt.panel.refresh_element(bvr.src_el, {parser: parser}) ''' }) if parser: select.set_value(parser) title_div = DivWdg() td.add(title_div) title_div.add("<div style='font-size: 16px'>File Metadata</div>") title_div.add("<div>Metadata extracted directly from the file</div>") title_div.add("<hr/>") title_div.add_style("text-align: left") title_div.add_style("margin: 0px 10px") metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") metadata_div.add_style("margin: 20px 0px 20px 10px") metadata_div.add_style("text-align: left") use_tactic_tags = self.kwargs.get("use_tactic_tags") server_src = lib_path # get it dynamically by path metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags, search_key=self.search_key) metadata_div.add(metadata_wdg) top.add("<br/>") 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() if my.parent: code = my.parent.get_value("code", no_exception=True) name = my.parent.get_value("name", no_exception=True) search_type_obj = my.parent.get_search_type_obj() else: code = my.sobject.get_value("code", no_exception=True) name = my.sobject.get_value("name", no_exception=True) search_type_obj = my.sobject.get_search_type_obj() # add the title td = table.add_cell() td.add_attr("colspan", "3") title = DivWdg() search = Search("sthpw/snapshot") search.add_filter("search_type", "sthpw/search_type") search.add_filter("search_code", search_type_obj.get_value("code")) if search.get_sobject(): thumb = ThumbWdg() title.add(thumb) thumb.set_icon_size(30) thumb.set_sobject(search_type_obj) thumb.add_style("float: left") td.add(title) title.add_color("background", "background3") title.add_style("height: 20px") title.add_style("padding: 6px") title.add_style("font-weight: bold") title.add_style("font-size: 1.4em") stype_title = search_type_obj.get_value("title") if stype_title: title.add("%s: " % stype_title) if name: title.add("%s" % name) if code: title.add(" <i style='font-size: 0.8; opacity: 0.7'>(%s)</i>" % code) elif code: title.add("%s" % code) else: title.add("(No name)") title.add_border() table.add_row() # left td = table.add_cell() td.add_style("width: 300px") td.add_style("min-width: 300px") td.add_style("vertical-align: top") div = DivWdg() td.add(div) div.add_class("spt_sobject_detail_top") thumb_table = Table() div.add(thumb_table) thumb_table.add_row() from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() # use a larger version for clearer display #thumb.set_icon_type('web') if my.parent: thumb.set_sobject(my.parent) search_key = my.parent.get_search_key() else: thumb.set_sobject(my.sobject) search_key = my.sobject.get_search_key() gallery_div = DivWdg() div.add(gallery_div) gallery_div.add_class("spt_tile_gallery") thumb_table.add_behavior({ 'type': 'click_up', 'search_key': search_key, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_sobject_detail_top"); var gallery_el = top.getElement(".spt_tile_gallery"); var class_name = 'tactic.ui.widget.gallery_wdg.GalleryWdg'; var kwargs = { search_key: bvr.search_key, search_keys: [bvr.search_key], }; spt.panel.load(gallery_el, class_name, kwargs); ''' }) # 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: auto") td.add_style("padding: 15px") sobject_info_wdg = my.get_sobject_info_wdg() sobject_info_wdg.add_style("width: auto") 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_class("spt_notes_wrapper") 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_key = "" if search_key.startswith("sthpw/"): parent = my.sobject.get_parent() if parent: parent_key = parent.get_search_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_display(my): collection = my.kwargs.get("collection") path = my.kwargs.get("path") search_type = collection.get_base_search_type() parts = search_type.split("/") collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1]) search = Search(collection_type) search.add_filter("parent_code", collection.get_value("code")) search.add_column("search_code") items = search.get_sobjects() codes = [x.get_value("search_code") for x in items] count = search.get_count() # find the children that are actually collections search = Search(search_type) search.add_filter("_is_collection", True) search.add_filters("code", codes) has_child_collections = search.get_count() > 0 top = my.top collection_top = top collection_top.add_class("spt_collection_div_top") collection_div = DivWdg() name = collection.get_value("name") # Adding Collection title (without the number count) as an attribute collection_top.set_attr("collection_name", name) collection_top.add(collection_div) collection_top.add_class("tactic_hover") collection_top.add_class("hand") collection_div.add_class("spt_collection_item") collection_div.add_attr("spt_collection_key", collection.get_search_key()) collection_div.add_attr("spt_collection_code", collection.get_code()) collection_div.add_attr("spt_collection_path", path) # This is for Drag and Drop from a tile widget collection_div.add_class("spt_tile_top") collection_div.add_attr("spt_search_key", collection.get_search_key()) collection_div.add_attr("spt_search_code", collection.get_code()) collection_div.add_attr("spt_name", name) collection_div.add_style("height: 20px") collection_div.add_style("padding-top: 10px") if has_child_collections: icon_div = DivWdg() icon = IconWdg(name="View Collection", icon="BS_CHEVRON_DOWN") icon_div.add(icon) icon.add_style("float: right") icon.add_style("margin-top: -20px") collection_top.add(icon_div) icon_div.add_class("spt_collection_open") icon_div.add_attr("spt_collection_key", collection.get_search_key()) icon_div.add_attr("spt_collection_path", path) from tactic.ui.panel import ThumbWdg2 thumb_wdg = ThumbWdg2() thumb_wdg.set_sobject(collection) collection_div.add(thumb_wdg) thumb_wdg.add_style("width: 45px") thumb_wdg.add_style("float: left") thumb_wdg.add_style("margin-top: -10px") if count: count_div = DivWdg() collection_div.add(count_div) #count_div.add_style("margin-top: -10px") #count_div.add_style("margin-left: -10px") count_div.add_style("width: 15px") count_div.add_style("height: 15px") count_div.add_style("font-size: 0.8em") count_div.add_style("border-radius: 10px") count_div.add_style("background: #DDD") count_div.add_style("position: absolute") count_div.add_style("text-align: center") count_div.add_style("margin-left: 23px") count_div.add_style("margin-top: -8px") count_div.add_style("box-shadow: 0px 0px 3px rgba(0,0,0,0.5)") expression = "@COUNT(%s['parent_code','%s'])" % ( collection_type, collection.get_code()) count_div.add(count) count_div.add_update({ #'expr_key': collection.get_search_key(), 'expression': expression, 'interval': 2 }) name = collection.get_value("name") collection_div.add(name) return top
def get_display(my): search_type_obj = SearchType.get(my.search_type) sobj_title = search_type_obj.get_title() my.color_mode = my.kwargs.get("color_mode") if not my.color_mode: my.color_mode = "default" top_div = my.top top_div.add_class("spt_edit_top") if not my.is_refresh: my.set_as_panel(top_div) content_div = DivWdg() content_div.add_class("spt_edit_top") content_div.add_class("spt_edit_form_top") content_div.set_attr("spt_search_key", my.search_key) if not Container.get_dict("JSLibraries", "spt_edit"): content_div.add_behavior({ 'type': 'load', 'cbjs_action': my.get_onload_js() }) layout_view = my.kwargs.get("layout_view") if layout_view: layout_wdg = my.get_custom_layout_wdg(layout_view) content_div.add(layout_wdg) return content_div # add close listener # NOTE: this is an absolute search, but is here for backwards # compatibility content_div.add_named_listener( 'close_EditWdg', ''' var popup = bvr.src_el.getParent( ".spt_popup" ); if (popup) spt.popup.close(popup); ''') attrs = my.config.get_view_attributes() default_access = attrs.get("access") if not default_access: default_access = "edit" project_code = Project.get_project_code() security = Environment.get_security() base_key = search_type_obj.get_base_key() key = {'search_type': base_key, 'project': project_code} access = security.check_access("sobject", key, "edit", default=default_access) if not access: my.is_disabled = True else: my.is_disabled = False disable_wdg = None if my.is_disabled: # TODO: This overlay doesn't work in IE, size, position, # and transparency all fail. disable_wdg = DivWdg(id='edit_wdg') disable_wdg.add_style("position: absolute") disable_wdg.add_style("height: 90%") disable_wdg.add_style("width: 100%") disable_wdg.add_style("left: 0px") #disable_wdg.add_style("bottom: 0px") #disable_wdg.add_style("top: 0px") disable_wdg.add_style("opacity: 0.2") disable_wdg.add_style("background: #fff") #disable_wdg.add_style("-moz-opacity: 0.2") disable_wdg.add_style("filter: Alpha(opacity=20)") disable_wdg.add("<center>EDIT DISABLED</center>") content_div.add(disable_wdg) attrs = my.config.get_view_attributes() #inner doesn't get styled. inner = DivWdg() content_div.add(inner) menu = my.get_header_context_menu() menus = [menu.get_data()] menus_in = { 'HEADER_CTX': menus, } SmartMenu.attach_smart_context_menu(inner, menus_in, False) #insert the header before body into inner show_header = my.kwargs.get("show_header") if show_header not in ['false', False]: my.add_header(inner, sobj_title) #insert table into a body container so styling gets applied table = Table() body_container = DivWdg() body_container.add_class("spt_popup_body") body_container.add(table) inner.add(body_container) if my.color_mode == "default": table.add_color("background", "background") elif my.color_mode == "transparent": table.add_style("background", "transparent") table.add_color("color", "color") width = attrs.get('width') if not width: width = my.kwargs.get("width") if not width: width = 600 height = attrs.get('height') if height: table.add_style("height: %s" % height) tr = table.add_row() stype_type = search_type_obj.get_value("type", no_exception=True) if my.mode != 'insert' and stype_type in ['media'] and my.sobjects: td = table.add_cell() width += 300 from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() thumb.set_sobject(my.sobjects[0]) td.add(thumb) thumb.add_style("margin: 0px 10px") path = thumb.get_lib_path() td.add_style("padding: 10px") td.add_attr("rowspan", len(my.widgets) + 2) td.add_style("min-width: 250px") td.add_style("vertical-align: top") td.add_border(direction="right") if path: td.add("<h3>File Information</h3>") td.add("<br/>") from pyasm.checkin import BaseMetadataParser parser = BaseMetadataParser.get_parser_by_path(path) data = parser.get_tactic_metadata() data_table = Table() data_table.add_style("margin: 15px") td.add(data_table) for name, value in data.items(): data_table.add_row() display_name = Common.get_display_title(name) dtd = data_table.add_cell("%s: " % display_name) dtd.add_style("width: 150px") dtd.add_style("padding: 3px") dtd = data_table.add_cell(value) dtd.add_style("padding: 3px") else: td.add("<h3>No Image</h3>") td.add("<br/>") # set the width table.add_style("width: %s" % width) single = my.kwargs.get("single") if single in ['false', False] and my.mode == 'insert': multi_div = DivWdg() multi_div.add_style("text-align: left") multi_div.add_style("padding: 5px 10px") multi_div.add("<b>Specify number of new items to add: </b>") multi_div.add(" " * 4) multi_text = TextWdg("multiplier") multi_text.add_class("form-control") multi_div.add(multi_text) multi_text.add_style("display: inline-block") multi_text.add_style("width: 60px") tr, td = table.add_row_cell(multi_div) if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1px") td.add_style("border-style: solid") td.add_style("padding: 8 3 8 3") td.add_color("background", "background3") td.add_color("color", "color3") security = Environment.get_security() # break the widgets up in columns num_columns = attrs.get('num_columns') if not num_columns: num_columns = my.kwargs.get('num_columns') if not num_columns: num_columns = 1 else: num_columns = int(num_columns) # go through each widget and draw it index = 0 for i, widget in enumerate(my.widgets): # since a widget name called code doesn't necessariy write to code column, it is commented out for now """ key = { 'search_type' : search_type_obj.get_base_key(), 'column' : widget.get_name(), 'project': project_code} # check security on widget if not security.check_access( "sobject_column",\ key, "edit"): my.skipped_element_names.append(widget.get_name()) continue """ if not hasattr(widget, 'set_input_prefix'): msg = DivWdg( "Warning: The widget definition for [%s] uses [%s] and is not meant for use in Edit Layout. Please revise the edit_definition in widget config." % (widget.get_name(), widget.__class__.__name__)) msg.add_style('color: orange') content_div.add(msg) content_div.add(HtmlElement.br()) continue if my.input_prefix: widget.set_input_prefix(my.input_prefix) # Bootstrap widget.add_class("form-control") if not isinstance(widget, CheckboxWdg): widget.add_style("width: 100%") if isinstance(widget, EditTitleWdg): tr, td = table.add_row_cell() tr.add_color("background", "background", -5) td.add_style("height", "30px") td.add_style("padding", "0px 10px") td.add(widget) index = 0 continue if isinstance(widget, HiddenWdg): content_div.add(widget) continue # Set up any validations configured on the widget ... from tactic.ui.app import ValidationUtil v_util = ValidationUtil(widget=widget) v_bvr = v_util.get_validation_bvr() if v_bvr: if (isinstance(widget, CalendarInputWdg)): widget.set_validation(v_bvr.get('cbjs_validation'), v_bvr.get('validation_warning')) else: widget.add_behavior(v_bvr) widget.add_behavior(v_util.get_input_onchange_bvr()) new_row = index % num_columns == 0 if new_row: tr = table.add_row() if my.color_mode == "default": if index % 2 == 0: tr.add_color("background", "background") else: tr.add_color("background", "background", -1) index += 1 show_title = widget.get_option("show_title") if not show_title: show_title = my.kwargs.get("show_title") if show_title in ['false', False]: show_title = False else: show_title = True if show_title: title = widget.get_title() td = table.add_cell(title) td.add_style("padding: 15px 15px 10px 5px") td.add_style("vertical-align: top") title_width = my.kwargs.get("title_width") if title_width: td.add_style("width: %s" % title_width) else: td.add_style("width: 150px") security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): SmartMenu.assign_as_local_activator(td, 'HEADER_CTX') if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1") td.add_style("border-style: solid") td.add_style("text-align: right") hint = widget.get_option("hint") if hint: #hint_wdg = HintWdg(hint) #hint_wdg.add_style("float: right") #td.add( hint_wdg ) td.add_attr("title", hint) if not show_title: th, td = table.add_row_cell(widget) continue else: td = table.add_cell(widget) #td = table.add_cell( widget.get_value() ) td.add_style("min-width: 300px") td.add_style("padding: 10px 25px 10px 5px") td.add_style("vertical-align: top") if my.color_mode == "default": td.add_color("border-color", "table_border", default="border") td.add_style("border-width: 1") td.add_style("border-style: solid") if not my.is_disabled and not my.mode == 'view': inner.add(my.get_action_html()) if my.input_prefix: prefix = HiddenWdg("input_prefix", my.input_prefix) tr, td = table.add_row_cell() td.add(prefix) top_div.add(content_div) return top_div