def get_save_wdg(my): from tactic.ui.container import DialogWdg dialog = DialogWdg(display=False, width=200, offset={ 'x': 0, 'y': 50 }, show_pointer=False) dialog_id = dialog.get_id() title = 'Save a New View' dialog.add_title(title) div = DivWdg() dialog.add(div) div.add_style("padding: 5 5 5 20") div.add_color("background", "background") my.table_id = my.kwargs.get("table_id") from tactic.ui.panel import ViewPanelSaveWdg save_wdg = ViewPanelSaveWdg(search_type=my.kwargs.get("search_type"), dialog_id=dialog_id, table_id=my.table_id) div.add(save_wdg) return dialog
def get_save_wdg(my): from tactic.ui.container import DialogWdg dialog = DialogWdg(display=False, width=200, offset={'x':0,'y':50}, show_pointer=False) dialog_id = dialog.get_id() title = 'Save a New View' dialog.add_title(title) div = DivWdg() dialog.add(div) div.add_style("padding: 5 5 5 20") div.add_color("background", "background") my.table_id = my.kwargs.get("table_id") from tactic.ui.panel import ViewPanelSaveWdg save_wdg = ViewPanelSaveWdg( search_type=my.kwargs.get("search_type"), dialog_id=dialog_id, table_id=my.table_id ) div.add(save_wdg) return dialog
def get_display(my): search_type = my.kwargs.get('search_type') top = my.top top.add_class("spt_dialog") button = IconButtonWdg(title='Add to Collection', icon="BS_TH_LARGE", show_arrow=True) top.add(button) detail_wdg = DivWdg() top.add(detail_wdg) dialog = DialogWdg() top.add(dialog) dialog.set_as_activator(button, offset={'x':-25,'y': 0}) dialog.add_title("Collections") dialog_content = CollectionAddDialogWdg(search_type= search_type) dialog.add(dialog_content) return top
def get_display(my): search_type = my.kwargs.get('search_type') top = my.top top.add_class("spt_dialog") button = IconButtonWdg(title='Add to Collection', icon="BS_TH_LARGE", show_arrow=True) top.add(button) detail_wdg = DivWdg() top.add(detail_wdg) dialog = DialogWdg() top.add(dialog) dialog.set_as_activator(button, offset={'x': -25, 'y': 0}) dialog.add_title("Collections") dialog_content = CollectionAddDialogWdg(search_type=search_type) dialog.add(dialog_content) return top
def get_display(my): if my.is_refresh: top = Widget() my.add(top) else: container = DivWdg() my.add(container) #parent = SearchKey.get_by_search_key(my.search_key) top = DivWdg() container.add(top) my.set_as_panel(top) top.add_style("margin-top: -2px") top.add_class("spt_uber_notes_top") from tactic.ui.app import HelpButtonWdg help_button = HelpButtonWdg(alias="note-sheet-widget") top.add(help_button) help_button.add_style("float: right") table_id = 'sub_table' view = 'table' span = DivWdg(css='spt_input_group') top.add(span) span.add_border() span.add_style("height: 27px") span.add_style("padding: 5px") button_div = DivWdg() span.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-right: 10px") table = Table() button_div.add(table) table.add_row() from tactic.ui.widget import SingleButtonWdg refresh = SingleButtonWdg(title="Refresh", icon=IconWdg.REFRESH) table.add_cell(refresh) refresh.add_style("float: left") refresh.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var tbody = top.getElements('.spt_table_tbody')[2]; var values = spt.api.Utility.get_input_values(tbody); spt.panel.refresh(top, values, false); ''' }) save = SingleButtonWdg(title="Save", icon=IconWdg.SAVE) table.add_cell(save) save.add_style("float: left") save.add_behavior({ 'type': 'click_up', 'update_current_only': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var table = top.getElement(".spt_table"); bvr.src_el = table; spt.dg_table.update_row(evt, bvr) ''' }) process = SingleButtonWdg(title="Show Processes", icon=IconWdg.PROCESS, show_arrow=True) table.add_cell(process) from tactic.ui.container import DialogWdg process_dialog = DialogWdg(display=False) span.add(process_dialog) process_dialog.set_as_activator(process) process_dialog.add_title("Processes") process_div = DivWdg() process_dialog.add(process_div) #process_div.add_style("padding: 5px") process_div.add_color("background", "background") process_div.add_color("color", "color") process_div.add_border() refresh = ActionButtonWdg(title="Refresh") refresh.add_style('margin: 0 auto 10px auto') process_div.add(refresh) refresh.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var tbody = top.getElements('.spt_table_tbody')[2]; var values = spt.api.Utility.get_input_values(tbody); spt.panel.refresh(top, values, false); ''' }) process_div.add("<hr/>") selected_process_names = [] step = 0 for idx, value in enumerate(my.process_names): checkbox_name = 'note_process_cb' if my.child_mode: selected_process_names.append(value) #break cb = CheckboxWdg(checkbox_name, label=value) cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.set_option('value', value) #cb.set_persistence() cb.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.input.save_selected(bvr, '%s','%s'); ''' % (checkbox_name, key) }) # only 1 is selected in child_mode if cb.is_checked(): selected_process_names.append(value) if idx == 0 or idx == 10 * step: # add a new inner div inner_div = my._get_inner_div() process_div.add(inner_div, 'inner%s' % step) step += 1 inner_div.add(cb) inner_div.add("<br/>") # if less than 10, make it wider if len(my.process_names) < 10: inner_div.add_style('width: 100px') # add a master private checkbox if not my.child_mode: checkbox_name = 'note_master_private_cb' cb = CheckboxWdg(checkbox_name, label='make notes private') cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var tbody = top.getElements('.spt_table_tbody')[2]; var inputs = spt.api.Utility.get_inputs(tbody,'is_private'); for (var i = 0; i < inputs.length; i++) inputs[i].checked = bvr.src_el.checked; spt.input.save_selected(bvr, '%s','%s'); ''' % (checkbox_name, key) }) cb_span = DivWdg(cb, css='small') cb_span.add_styles( 'border-left: 1px dotted #bbb; margin-left: 10px') span.add(cb_span) main_config_view = my._get_main_config(view, selected_process_names) sobject_dict = {} # TODO: do a union all search or by order number = 1 for value in selected_process_names: search = Search('sthpw/note') search.add_filter('project_code', Project.get_project_code()) search.add_filter('context', value) search.add_filter('search_type', my.parent_search_type) search.add_filter('search_id', my.parent_search_id) search.add_order_by('timestamp desc') search.add_limit(1) sobject = search.get_sobject() if sobject: sobject_dict[value] = sobject #sobjects = search.get_sobjects() # virtual sobject for placeholder, we can put more than 1 maybe? sobject = SearchType.create('sthpw/note') edit_config = my._get_edit_config('edit', selected_process_names) edit_configs = {'sthpw/note': edit_config} Container.put("CellEditWdg:configs", edit_configs) table = TableLayoutWdg(table_id=table_id, search_type='sthpw/note', view='table', config=main_config_view, aux_info={ 'sobjects': sobject_dict, 'parent': my.parent }, mode="simple", show_row_select=False, show_insert=False, show_commit_all=True, show_refresh='false', state={'parent_key': my.search_key}) table.set_sobject(sobject) top.add(table) return super(NoteSheetWdg, my).get_display()
def get_display(my): web = WebContainer.get_web() tactic_header = Table() tactic_header.add_row() tactic_header.add_color("color", "color2") # tactic logo and release info skin = web.get_skin() src = '/context/skins/' + skin + '/images/tactic_logo.png' img = HtmlElement.img(src) img.add_class('hand') img.add_attr('title', 'Go to home page') img.add_behavior({'type': 'click_up', 'cbjs_action': "window.location='/tactic/'"}) rel_div = DivWdg() rel_div.add(" "*3) rel_div.add("Release: %s" %Environment.get_release_version() ) rel_div.add_style("font-size: 9px") # Need this to override the above color in add_looks rel_div.add_color("color", "color2") tactic_wdg = Table() tactic_wdg.add_style("width: 180px") tactic_wdg.add_row() td = tactic_wdg.add_cell( img ) td.set_style("width:100px") tactic_wdg.add_row() td = tactic_wdg.add_cell( rel_div ) td.set_style("text-align: left") td = tactic_header.add_cell( tactic_wdg ) # add the project thumb and title project = Project.get() if my.show_project: thumb_div = DivWdg() td = tactic_header.add_cell( thumb_div ) thumb_div.add_style("height: 28px") thumb_div.add_style("overflow: hidden") thumb_div.add_border(modifier=-10) thumb_div.add_style("-moz-border-radius: 3px") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_sobject(project) thumb.set_icon_size("45") td.set_style("vertical-align: top; padding-right:14px;padding-left: 3px") td = tactic_header.add_cell( project.get_value("title") ) #td.add_looks( "fnt_title_1" ) td.add_style("font-size: 20px") td.add_style("white-space: nowrap") td.add_style("padding-left: 14px") # project selection td = tactic_header.add_cell() project_div = DivWdg() project_div.add_style("margin-top: -5px") project_div.add(ProjectSelectWdg() ) td.add( project_div ) td.set_style("padding-left: 14px") # Global Actions Gear Menu (contains links to Documentation) ... action_bar_btn_dd = PageHeaderGearMenuWdg() action_div = DivWdg(action_bar_btn_dd) action_div.add_style("margin-top: -5px") td = tactic_header.add_cell( action_div ) if PrefSetting.get_value_by_key('subscription_bar') == 'true': from message_wdg import SubscriptionBarWdg sub = SubscriptionBarWdg(mode='popup') tactic_header.add_cell(sub) # user login # user user = Environment.get_login() full_name = user.get_full_name() user_div = SpanWdg( HtmlElement.b( "%s " % full_name) , css='hand') user_div.set_style("padding-right:10px") # signout login = Environment.get_security().get_login() search_key = SearchKey.get_by_sobject(login) span = SpanWdg() span.add( user_div ) user_div.add_attr('spt_nudge_menu_vert', '20') td = tactic_header.add_cell(span) td.set_style("width:100%; text-align:right; white-space: nowrap") from tactic.ui.widget import SingleButtonWdg button = SingleButtonWdg(title='My Account', icon=IconWdg.USER, show_arrow=True) button_div = DivWdg(button) button_div.add_style("margin-top: -5px") button.add_attr('spt_nudge_menu_horiz', '-80') button.add_attr('spt_nudge_menu_vert', '10') td = tactic_header.add_cell(button_div) menus = my.get_smart_menu() # TODO: this part seems redundant to attach to both SmartMenu.add_smart_menu_set(user_div, [menus]) SmartMenu.assign_as_local_activator(user_div, None, True) SmartMenu.add_smart_menu_set(button, [menus]) SmartMenu.assign_as_local_activator(button, None, True) td.set_style("width:100%;") button = SingleButtonWdg(title='Help', icon=IconWdg.HELP_BUTTON, show_arrow=False) #button.add_behavior( { #'type': 'click_up', #'cbjs_action': ''' #window.open("/doc/") #''' #} ) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_help") ''' } ) from tactic.ui.container import DialogWdg help_dialog = DialogWdg(z_index=900, show_pointer=False) td.add(help_dialog) help_dialog.add_title("Help") help_dialog.add_class("spt_help") # container for help help_div = DivWdg() help_dialog.add(help_div) from help_wdg import HelpWdg help_wdg = HelpWdg() help_div.add(help_wdg) button_div = DivWdg(button) button_div.add_style("margin-top: -5px") td = tactic_header.add_cell(button_div) td.set_style("width:100%; text-align:right; white-space: nowrap") # Layout the Main Header Table main_div = DivWdg() # TEST: NEW LAYOUT if Config.get_value("install", "layout") == "fixed": main_div.add_style("position: fixed") main_div.add_style("z-index: 100") main_div.add_style("width: 100%") license = Environment.get_security().get_license() if not license.is_licensed(): from tactic.ui.app import LicenseManagerWdg license_manager = LicenseManagerWdg(use_popup=True) main_div.add(license_manager) # create the header table tactic_header_div = DivWdg() tactic_header_div.add(tactic_header) tactic_header_div.add_gradient("background", "background2", 10, -10) main_div.add(tactic_header_div) main_div.add( my.get_js_popup() ) """ main_div.add( HelpPopupWdg() ) # FIXME: is this even used at all? action_bar_popup = PopupWdg( id="ActionBarWdg_popup", allow_page_activity=True, width="636px" ) action_bar_popup.add_title( "TACTIC™ Action Bar" ) action_bar_popup.add( ActionBarWdg() ) main_div.add( action_bar_popup ) """ # FIXME(?): does this CommonPopup need to be at z_start=300? By default popups will be at z_start=200 popup = PopupWdg( id="CommonPopup", allow_page_activity=True, width="600px", z_start=300 ) popup.add('Tools', 'title') main_div.add( popup ) return main_div
def get_display(my): search_type = my.kwargs.get("search_type") search = Search(search_type) if not search.column_exists("_is_collection"): return my.top search.add_filter("_is_collection", True) collections = search.get_sobjects() top = my.top top.add_class("spt_dialog") button = IconButtonWdg(title='Add to Collection', icon="BS_TH_LARGE", show_arrow=True) top.add(button) detail_wdg = DivWdg() top.add(detail_wdg) dialog = DialogWdg() top.add(dialog) dialog.set_as_activator(button, offset={'x':-25,'y': 0}) dialog.add_title("Collections") dialog.add("<div style='margin: 10px'><b>Add selected items to a collection</b></div>") add_div = DivWdg() dialog.add(add_div) icon = IconWdg(name="Add new collection", icon="BS_PLUS") icon.add_style("opacity: 0.6") icon.add_style("padding-right: 3px") add_div.add(icon) add_div.add("Create new Collection") add_div.add_style("text-align: center") add_div.add_style("background-color: #EEEEEE") add_div.add_style("padding: 5px") add_div.add_style("height: 20px") add_div.add_class("hand") insert_view = "edit_collection" add_div.add_behavior( { 'type': 'click_up', 'insert_view': insert_view, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_table_top"); var table = top.getElement(".spt_table"); var search_type = top.getAttribute("spt_search_type"); // Hide the dialog when popup loads. var dialog_top = bvr.src_el.getParent(".spt_dialog_top"); dialog_top.style.visibility = "hidden"; kwargs = { search_type: search_type, mode: "insert", view: bvr.insert_view, save_event: bvr.event_name, show_header: false, 'num_columns': 2, default: { _is_collection: true } }; spt.panel.load_popup("Add New Collection", "tactic.ui.panel.EditWdg", kwargs); ''' } ) content_div = DivWdg() dialog.add(content_div) content_div.add_style("width: 270px") content_div.add_style("padding: 5px") content_div.add_style("padding-bottom: 0px") custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_dialog"); var input = top.getElement(".spt_main_search"); var search_value = input.value.toLowerCase(); var collections = top.getElements(".spt_collection_div"); var num_result = 0; for (i = 0; i < collections.length; i++) { // Access the Collection title (without number count) var collection_title = collections[i].attributes[0].value.toLowerCase(); if (collection_title.indexOf(search_value) != '-1') { collections[i].style.display = "block"; num_result += 1; } else { collections[i].style.display = "none"; } } // if no search results, display all if (num_result == 0) { for (i = 0; i < collections.length; i++) { collections[i].style.display = "block"; } } ''' filters = [] filters.append(("_is_collection",True)) filters.append(("status","Verified")) text = LookAheadTextInputWdg( search_type = "workflow/asset", column="name", icon="BS_SEARCH", icon_pos="right", width="100%", hint_text="'Enter' to search for Colllection...", value_column="name", filters=filters, custom_cbk=custom_cbk, is_collection=True ) text.add_class("spt_main_search") content_div.add(text) # set minimum if there is at least one collection if len(collections) > 0: content_div.add_style("min-height: 300") content_div.add_style("max-height: 300") content_div.add_style("overflow-y: auto") content_div.add("<br clear='all'/>") for collection in collections: 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_code()) num_items = search.get_count() collection_div = DivWdg() collection_div.add_class("spt_collection_div") content_div.add(collection_div) collection_div.add_style("margin: 3px 5px 0px 5px") go_wdg = DivWdg() collection_div.add(go_wdg) go_wdg.add_style("float: right") icon = IconWdg(name="View Collection", icon="BS_CHEVRON_RIGHT") go_wdg.add(icon) #go_wdg.add_behavior( { # 'type': 'click_upX', # 'cbjs_action': ''' # alert("Not Implemented"); # ''' #} ) name = collection.get_value("name") # Adding Collection title (without the number count) as an attribute collection_div.set_attr("collection_name", name) if not name: name = collection.get_value("code") check_div = DivWdg() collection_div.add(check_div) check = CheckboxWdg("collection_key") check.add_class("spt_collection_checkbox") check_div.add(check) check_div.add_style("float: left") check_div.add_style("margin-right: 5px") check_div.add_style("margin-top: -3px") check.add_attr("collection_key", collection.get_search_key() ) info_div = DivWdg() collection_div.add(info_div) info_div.add(name) if num_items: info_div.add(" (%s)" % num_items) collection_div.add("<hr/>") add_button = DivWdg() add_button.add("Add") add_button.add_style("margin: 0px 10px 10px 10px") add_button.add_style("width: 50px") add_button.add_class("btn btn-primary") dialog.add(add_button) add_button.add_behavior( { 'type': 'click', 'cbjs_action': ''' var search_keys = spt.table.get_selected_search_keys(false); if (search_keys.length == 0) { spt.notify.show_message("No assets selected."); return; } var top = bvr.src_el.getParent(".spt_dialog"); var checkboxes = top.getElements(".spt_collection_checkbox"); var cmd = "tactic.ui.panel.CollectionAddCmd"; var server = TacticServerStub.get(); var is_checked = false; var dialog_top = bvr.src_el.getParent(".spt_dialog_top"); for (i = 0; i < checkboxes.length; i++) { var checked_collection_attr = checkboxes[i].attributes; var collection_key = checked_collection_attr[3].value; // Preventing a collection being added to itself, check if search_keys contain collection_key. if (search_keys.indexOf(collection_key) != -1) { spt.notify.show_message("Collection cannot be added to itself."); return; } if (checkboxes[i].checked == true) { // if there is at least one checkbox selected, set is_checked to 'true' is_checked = true; var search_keys = spt.table.get_selected_search_keys(false); var kwargs = { collection_key: collection_key, search_keys: search_keys } server.execute_cmd(cmd, kwargs); } } if (is_checked == false) { spt.notify.show_message("No collection selected."); return; } else { spt.notify.show_message("Assets added to Collection."); // refresh dialog_top, so users can see the number change in Collections spt.panel.refresh(dialog_top); } ''' } ) return top
def get_display(self): category = "FreeformWdg" search_type = self.get_value("search_type") if not search_type: search_type = "sthpw/login" view = self.get_value("view") if not view: view = 'freeform' search = Search("config/widget_config") search.add_filter("search_type", search_type) search.add_filter("view", view) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = "<config/>" top = self.top self.set_as_panel(top) top.add_class("spt_freeform_top") inner = DivWdg() top.add(inner) table = ResizableTableWdg() table.add_color("background", "background") inner.add(table) table.add_row() table.set_max_width() td = table.add_cell() td.add_attr("colspan", "5") td.add_color("background", "background3") td.add_color("color", "color") td.add_style("padding", "10px") td.add("Search Type: ") select = SelectWdg("search_type") project = Project.get() search_types = project.get_search_types() values = [x.get_base_key() for x in search_types] labels = [ "%s (%s)" % (x.get_title(), x.get_base_key()) for x in search_types ] select.set_option("values", values) select.set_option("labels", labels) if search_type: select.set_value(search_type) td.add(select) td.add(" " * 10) td.add("View: ") text = TextWdg("view") td.add(text) if view: text.set_value(view) button = ActionButtonWdg(title="Load") button.add_style("float: left") td.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Loading View"); var top = bvr.src_el.getParent(".spt_freeform_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) table.add_row() left = table.add_cell() left.add_style("vertical-align: top") left.add_border() left.add_color("color", "color") left.add_color("background", "background") left.add_style("min-width: 150px") left_div = DivWdg() left.add(left_div) left_div.add_style("min-height: 300px") left_div.add_style("min-width: 150px") left_div.add_style("width: 150px") title = DivWdg() left_div.add(title) title.add_style("font-weight: bold") title.add_style("font-size: 14px") title.add_style("width: 100%") title.add("Elements") title.add_gradient("background", "background", -5) title.add_style("padding: 10px 5px 5px 5px") title.add_style("height: 25px") title.add_style("margin-bottom: 10px") left.add_behavior({ 'type': 'smart_click_up', 'bvr_match_class': 'SPT_ELEMENT_CLICK', 'cbjs_action': r''' var top = bvr.src_el.getParent(".spt_freeform_top"); var template_top = top.getElement(".spt_freeform_template_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); var element_name = bvr.src_el.getAttribute("spt_element_name"); var template_els = template_top.getElements(".spt_element"); var els = canvas.getElements(".spt_element"); // get the highest number var number = 0; for ( var i = 0; i < els.length; i++) { var el = els[i]; var name = el.getAttribute("spt_element_name"); var num = name.match(/(\d+)/); if (!num) continue; num = parseInt(num); if (num > number) { number = num; } } number = number + 1; for ( var i = 0; i < template_els.length; i++) { var el = template_els[i]; if (el.getAttribute("spt_element_name") == element_name) { var clone = spt.behavior.clone(el); canvas.appendChild(clone); clone.setStyle("top", "30px"); clone.setStyle("left", "30px"); clone.setStyle("position", "absolute"); var new_name = element_name + number; clone.setAttribute("spt_element_name", new_name) clone.attrs = {}; var number = Math.floor(Math.random()*10001) clone.setAttribute("spt_element_id", "element"+number); spt.freeform.select(clone); break; } } ''' }) values = [ 'Label', 'Box', 'Text', 'TextArea', 'Button', 'Preview', 'Image', 'HTML', 'Table', 'Border', 'Custom Layout' ] names = [ 'label', 'box', 'text', 'textarea', 'button', 'preview', 'image', 'html', 'table', 'border', 'custom' ] icons = [IconWdg.VIEW] for name, value in zip(names, values): element_div = DivWdg() left_div.add(element_div) element_div.add_style("padding: 3px") element_div.add_class("SPT_DTS") element_div.add_class("hand") icon = IconWdg(name, IconWdg.VIEW) element_div.add(icon) element_div.add(value) element_div.add_class("SPT_ELEMENT_CLICK") element_div.add_attr("spt_element_name", name) element_div.add_style("padding-left: 10px") hover = element_div.get_color("background", -10) element_div.add_behavior({ 'type': 'hover', 'hover': hover, 'cbjs_action_over': '''bvr.src_el.setStyle("background", bvr.hover)''', 'cbjs_action_out': '''bvr.src_el.setStyle("background", "")''' }) element_div.add_class("hand") element_div.add_behavior({ 'type': 'drag', "drag_el": '@', "cb_set_prefix": 'spt.freeform.create_element_drag' }) """ button = ActionButtonWdg(title="Save") left_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_freeform_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); spt.freeform.init(canvas); var xml = spt.freeform.export(); var search_type = canvas.getAttribute("spt_search_type"); var view = canvas.getAttribute("spt_view"); if (!search_type || !view) { alert("Cannot find search type or view"); return; } var server = TacticServerStub.get(); var sobject = server.get_unique_sobject("config/widget_config", {search_type: search_type, view: view} ); server.update(sobject, {config: xml} ); ''' } ) """ from tactic.ui.container import DialogWdg dialog = DialogWdg(display=False, show_pointer=False) dialog.add_title("Properties") self.dialog_id = dialog.get_id() left.add(dialog) attr_div = self.get_attr_wdg() dialog.add(attr_div) template_div = DivWdg() left.add(template_div) template_div.add_class("spt_freeform_template_top") template_div.add_style("display: none") template_config_xml = self.get_template_config_xml() freeform_layout = FreeFormCanvasWdg(search_type=search_type, view="freeform", config_xml=template_config_xml, dialog_id=self.dialog_id) template_div.add(freeform_layout) # handle the canvas canvas = table.add_cell(resize=False) canvas.add(self.get_action_wdg()) canvas.add_style("overflow: hidden") canvas.add_style("vertical-align: top") canvas.add_color("background", "background") canvas.add_color("color", "color") canvas_div = DivWdg() canvas_div.add_style("margin: 20px") canvas_div.add_style("width: 90%") canvas_div.add_style("min-width: 300px") canvas_div.add_style("padding: 10px") canvas_div.add_style("height: 100%") canvas_div.add_class("spt_freeform_canvas_top") canvas.add(canvas_div) freeform_layout = FreeFormCanvasWdg(search_type=search_type, view=view, config_xml=config_xml, dialog_id=self.dialog_id) canvas_div.add(freeform_layout) table.add_resize_row() if self.kwargs.get("is_refresh") in [True, "true"]: return inner else: return top
def get_display(my): category = "FreeformWdg" search_type = my.get_value("search_type") if not search_type: search_type = "sthpw/login" view = my.get_value("view") if not view: view = "freeform" search = Search("config/widget_config") search.add_filter("search_type", search_type) search.add_filter("view", view) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = "<config/>" top = my.top my.set_as_panel(top) top.add_class("spt_freeform_top") inner = DivWdg() top.add(inner) table = ResizableTableWdg() table.add_color("background", "background") inner.add(table) table.add_row() table.set_max_width() td = table.add_cell() td.add_attr("colspan", "5") td.add_color("background", "background3") td.add_color("color", "color") td.add_style("padding", "10px") td.add("Search Type: ") select = SelectWdg("search_type") project = Project.get() search_types = project.get_search_types() values = [x.get_base_key() for x in search_types] labels = ["%s (%s)" % (x.get_title(), x.get_base_key()) for x in search_types] select.set_option("values", values) select.set_option("labels", labels) if search_type: select.set_value(search_type) td.add(select) td.add(" " * 10) td.add("View: ") text = TextWdg("view") td.add(text) if view: text.set_value(view) button = ActionButtonWdg(title="Load") button.add_style("float: left") td.add(button) button.add_behavior( { "type": "click_up", "cbjs_action": """ spt.app_busy.show("Loading View"); var top = bvr.src_el.getParent(".spt_freeform_top"); spt.panel.refresh(top); spt.app_busy.hide(); """, } ) table.add_row() left = table.add_cell() left.add_style("vertical-align: top") left.add_border() left.add_color("color", "color") left.add_color("background", "background") left.add_style("min-width: 150px") left_div = DivWdg() left.add(left_div) left_div.add_style("min-height: 300px") left_div.add_style("min-width: 150px") left_div.add_style("width: 150px") title = DivWdg() left_div.add(title) title.add_style("font-weight: bold") title.add_style("font-size: 14px") title.add_style("width: 100%") title.add("Elements") title.add_gradient("background", "background", -5) title.add_style("padding: 10px 5px 5px 5px") title.add_style("height: 25px") title.add_style("margin-bottom: 10px") left.add_behavior( { "type": "smart_click_up", "bvr_match_class": "SPT_ELEMENT_CLICK", "cbjs_action": r""" var top = bvr.src_el.getParent(".spt_freeform_top"); var template_top = top.getElement(".spt_freeform_template_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); var element_name = bvr.src_el.getAttribute("spt_element_name"); var template_els = template_top.getElements(".spt_element"); var els = canvas.getElements(".spt_element"); // get the highest number var number = 0; for ( var i = 0; i < els.length; i++) { var el = els[i]; var name = el.getAttribute("spt_element_name"); var num = name.match(/(\d+)/); if (!num) continue; num = parseInt(num); if (num > number) { number = num; } } number = number + 1; for ( var i = 0; i < template_els.length; i++) { var el = template_els[i]; if (el.getAttribute("spt_element_name") == element_name) { var clone = spt.behavior.clone(el); canvas.appendChild(clone); clone.setStyle("top", "30px"); clone.setStyle("left", "30px"); clone.setStyle("position", "absolute"); var new_name = element_name + number; clone.setAttribute("spt_element_name", new_name) clone.attrs = {}; var number = Math.floor(Math.random()*10001) clone.setAttribute("spt_element_id", "element"+number); spt.freeform.select(clone); break; } } """, } ) values = [ "Label", "Box", "Text", "TextArea", "Button", "Preview", "Image", "HTML", "Table", "Border", "Custom Layout", ] names = ["label", "box", "text", "textarea", "button", "preview", "image", "html", "table", "border", "custom"] icons = [IconWdg.VIEW] for name, value in zip(names, values): element_div = DivWdg() left_div.add(element_div) element_div.add_style("padding: 3px") element_div.add_class("SPT_DTS") element_div.add_class("hand") icon = IconWdg(name, IconWdg.VIEW) element_div.add(icon) element_div.add(value) element_div.add_class("SPT_ELEMENT_CLICK") element_div.add_attr("spt_element_name", name) element_div.add_style("padding-left: 10px") hover = element_div.get_color("background", -10) element_div.add_behavior( { "type": "hover", "hover": hover, "cbjs_action_over": """bvr.src_el.setStyle("background", bvr.hover)""", "cbjs_action_out": """bvr.src_el.setStyle("background", "")""", } ) element_div.add_class("hand") element_div.add_behavior( {"type": "drag", "drag_el": "@", "cb_set_prefix": "spt.freeform.create_element_drag"} ) """ button = ActionButtonWdg(title="Save") left_div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_freeform_top"); var canvas_top = top.getElement(".spt_freeform_canvas_top"); var canvas = canvas_top.getElement(".spt_freeform_canvas"); spt.freeform.init(canvas); var xml = spt.freeform.export(); var search_type = canvas.getAttribute("spt_search_type"); var view = canvas.getAttribute("spt_view"); if (!search_type || !view) { alert("Cannot find search type or view"); return; } var server = TacticServerStub.get(); var sobject = server.get_unique_sobject("config/widget_config", {search_type: search_type, view: view} ); server.update(sobject, {config: xml} ); ''' } ) """ from tactic.ui.container import DialogWdg dialog = DialogWdg(display=False, show_pointer=False) dialog.add_title("Properties") my.dialog_id = dialog.get_id() left.add(dialog) attr_div = my.get_attr_wdg() dialog.add(attr_div) template_div = DivWdg() left.add(template_div) template_div.add_class("spt_freeform_template_top") template_div.add_style("display: none") template_config_xml = my.get_template_config_xml() freeform_layout = FreeFormCanvasWdg( search_type=search_type, view="freeform", config_xml=template_config_xml, dialog_id=my.dialog_id ) template_div.add(freeform_layout) # handle the canvas canvas = table.add_cell(resize=False) canvas.add(my.get_action_wdg()) canvas.add_style("overflow: hidden") canvas.add_style("vertical-align: top") canvas.add_color("background", "background") canvas.add_color("color", "color") canvas_div = DivWdg() canvas_div.add_style("margin: 20px") canvas_div.add_style("width: 90%") canvas_div.add_style("min-width: 300px") canvas_div.add_style("padding: 10px") canvas_div.add_style("height: 100%") canvas_div.add_class("spt_freeform_canvas_top") canvas.add(canvas_div) freeform_layout = FreeFormCanvasWdg( search_type=search_type, view=view, config_xml=config_xml, dialog_id=my.dialog_id ) canvas_div.add(freeform_layout) table.add_resize_row() if my.kwargs.get("is_refresh") in [True, "true"]: return inner else: return top
def get_display(self): if self.is_refresh: top = Widget() self.add(top) else: container = DivWdg() self.add(container) #parent = SearchKey.get_by_search_key(self.search_key) top = DivWdg() container.add(top) self.set_as_panel(top) top.add_style("margin-top: -2px") top.add_class("spt_uber_notes_top") from tactic.ui.app import HelpButtonWdg help_button = HelpButtonWdg(alias="note-sheet-widget") top.add(help_button) help_button.add_style("float: right") table_id = 'sub_table' view = 'table' span = DivWdg(css='spt_input_group') top.add(span) span.add_border() span.add_style("height: 27px") span.add_style("padding: 5px") button_div = DivWdg() span.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-right: 10px") table = Table() button_div.add(table) table.add_row() from tactic.ui.widget import SingleButtonWdg refresh = SingleButtonWdg(title="Refresh", icon=IconWdg.REFRESH) table.add_cell(refresh) refresh.add_style("float: left") refresh.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var tbody = top.getElements('.spt_table_tbody')[2]; var values = spt.api.Utility.get_input_values(tbody); spt.panel.refresh(top, values, false); ''' }) save = SingleButtonWdg(title="Save", icon=IconWdg.SAVE) table.add_cell(save) save.add_style("float: left") save.add_behavior( { 'type': 'click_up', 'update_current_only': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var table = top.getElement(".spt_table"); bvr.src_el = table; spt.dg_table.update_row(evt, bvr) ''' }) process = SingleButtonWdg(title="Show Processes", icon=IconWdg.PROCESS, show_arrow=True) table.add_cell(process) from tactic.ui.container import DialogWdg process_dialog = DialogWdg(display=False) span.add(process_dialog) process_dialog.set_as_activator(process) process_dialog.add_title("Processes") process_div = DivWdg() process_dialog.add(process_div) #process_div.add_style("padding: 5px") process_div.add_color("background", "background") process_div.add_color("color", "color") process_div.add_border() refresh = ActionButtonWdg(title="Refresh") refresh.add_style('margin: 0 auto 10px auto') process_div.add(refresh) refresh.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var tbody = top.getElements('.spt_table_tbody')[2]; var values = spt.api.Utility.get_input_values(tbody); spt.panel.refresh(top, values, false); ''' } ) process_div.add("<hr/>") selected_process_names = [] step = 0 for idx, value in enumerate(self.process_names): checkbox_name = 'note_process_cb' if self.child_mode: selected_process_names.append(value) #break cb = CheckboxWdg(checkbox_name, label=value) cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.set_option('value', value) #cb.set_persistence() cb.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.input.save_selected(bvr, '%s','%s'); ''' % (checkbox_name, key) }) # only 1 is selected in child_mode if cb.is_checked(): selected_process_names.append(value) if idx == 0 or idx == 10 * step: # add a new inner div inner_div = self._get_inner_div() process_div.add(inner_div, 'inner%s'%step) step += 1 inner_div.add(cb) inner_div.add("<br/>") # if less than 10, make it wider if len(self.process_names) < 10: inner_div.add_style('width: 100px') # add a master private checkbox if not self.child_mode: checkbox_name = 'note_master_private_cb' cb = CheckboxWdg(checkbox_name, label='make notes private') cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_uber_notes_top"); var tbody = top.getElements('.spt_table_tbody')[2]; var inputs = spt.api.Utility.get_inputs(tbody,'is_private'); for (var i = 0; i < inputs.length; i++) inputs[i].checked = bvr.src_el.checked; spt.input.save_selected(bvr, '%s','%s'); '''%(checkbox_name, key) }) cb_span = DivWdg(cb, css='small') cb_span.add_styles('border-left: 1px dotted #bbb; margin-left: 10px') span.add(cb_span) main_config_view = self._get_main_config(view, selected_process_names) sobject_dict = {} # TODO: do a union all search or by order number = 1 for value in selected_process_names: search = Search('sthpw/note') search.add_filter('project_code', Project.get_project_code()) search.add_filter('context', value) search.add_filter('search_type',self.parent_search_type) search.add_filter('search_id',self.parent_search_id) search.add_order_by('timestamp desc') search.add_limit(1) sobject = search.get_sobject() if sobject: sobject_dict[value] = sobject #sobjects = search.get_sobjects() # virtual sobject for placeholder, we can put more than 1 maybe? sobject = SearchType.create('sthpw/note') edit_config = self._get_edit_config('edit', selected_process_names) edit_configs = {'sthpw/note': edit_config} Container.put("CellEditWdg:configs", edit_configs) table = TableLayoutWdg(table_id=table_id, search_type='sthpw/note', view='table', config=main_config_view, aux_info={'sobjects': sobject_dict, 'parent': self.parent}, mode="simple", show_row_select=False, show_insert=False, show_commit_all=True, show_refresh='false', state={'parent_key': self.search_key} ) table.set_sobject(sobject) top.add(table) return super(NoteSheetWdg, self).get_display()
def get_display(my): search_type = my.kwargs.get("search_type") search = Search(search_type) if not search.column_exists("_is_collection"): return my.top search.add_filter("_is_collection", True) collections = search.get_sobjects() top = my.top top.add_class("spt_dialog") button = IconButtonWdg(title='Add to Collection', icon="BS_TH_LARGE", show_arrow=True) top.add(button) detail_wdg = DivWdg() top.add(detail_wdg) dialog = DialogWdg() top.add(dialog) dialog.set_as_activator(button, offset={'x': -25, 'y': 0}) dialog.add_title("Collections") dialog.add( "<div style='margin: 10px'><b>Add selected items to a collection</b></div>" ) add_div = DivWdg() dialog.add(add_div) icon = IconWdg(name="Add new collection", icon="BS_PLUS") icon.add_style("opacity: 0.6") icon.add_style("padding-right: 3px") add_div.add(icon) add_div.add("Create new Collection") add_div.add_style("text-align: center") add_div.add_style("background-color: #EEEEEE") add_div.add_style("padding: 5px") add_div.add_style("height: 20px") add_div.add_class("hand") insert_view = "edit_collection" add_div.add_behavior({ 'type': 'click_up', 'insert_view': insert_view, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_table_top"); var table = top.getElement(".spt_table"); var search_type = top.getAttribute("spt_search_type"); // Hide the dialog when popup loads. var dialog_top = bvr.src_el.getParent(".spt_dialog_top"); dialog_top.style.visibility = "hidden"; kwargs = { search_type: search_type, mode: "insert", view: bvr.insert_view, save_event: bvr.event_name, show_header: false, 'num_columns': 2, default: { _is_collection: true } }; spt.panel.load_popup("Add New Collection", "tactic.ui.panel.EditWdg", kwargs); ''' }) content_div = DivWdg() dialog.add(content_div) content_div.add_style("width: 270px") content_div.add_style("padding: 5px") content_div.add_style("padding-bottom: 0px") custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_dialog"); var input = top.getElement(".spt_main_search"); var search_value = input.value.toLowerCase(); var collections = top.getElements(".spt_collection_div"); var num_result = 0; for (i = 0; i < collections.length; i++) { // Access the Collection title (without number count) var collection_title = collections[i].attributes[0].value.toLowerCase(); if (collection_title.indexOf(search_value) != '-1') { collections[i].style.display = "block"; num_result += 1; } else { collections[i].style.display = "none"; } } // if no search results, display all if (num_result == 0) { for (i = 0; i < collections.length; i++) { collections[i].style.display = "block"; } } ''' filters = [] filters.append(("_is_collection", True)) filters.append(("status", "Verified")) text = LookAheadTextInputWdg( search_type="workflow/asset", column="name", icon="BS_SEARCH", icon_pos="right", width="100%", hint_text="'Enter' to search for Colllection...", value_column="name", filters=filters, custom_cbk=custom_cbk, is_collection=True) text.add_class("spt_main_search") content_div.add(text) # set minimum if there is at least one collection if len(collections) > 0: content_div.add_style("min-height: 300") content_div.add_style("max-height: 300") content_div.add_style("overflow-y: auto") content_div.add("<br clear='all'/>") for collection in collections: 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_code()) num_items = search.get_count() collection_div = DivWdg() collection_div.add_class("spt_collection_div") content_div.add(collection_div) collection_div.add_style("margin: 3px 5px 0px 5px") go_wdg = DivWdg() collection_div.add(go_wdg) go_wdg.add_style("float: right") icon = IconWdg(name="View Collection", icon="BS_CHEVRON_RIGHT") go_wdg.add(icon) #go_wdg.add_behavior( { # 'type': 'click_upX', # 'cbjs_action': ''' # alert("Not Implemented"); # ''' #} ) name = collection.get_value("name") # Adding Collection title (without the number count) as an attribute collection_div.set_attr("collection_name", name) if not name: name = collection.get_value("code") check_div = DivWdg() collection_div.add(check_div) check = CheckboxWdg("collection_key") check.add_class("spt_collection_checkbox") check_div.add(check) check_div.add_style("float: left") check_div.add_style("margin-right: 5px") check_div.add_style("margin-top: -3px") check.add_attr("collection_key", collection.get_search_key()) info_div = DivWdg() collection_div.add(info_div) info_div.add(name) if num_items: info_div.add(" (%s)" % num_items) collection_div.add("<hr/>") add_button = DivWdg() add_button.add("Add") add_button.add_style("margin: 0px 10px 10px 10px") add_button.add_style("width: 50px") add_button.add_class("btn btn-primary") dialog.add(add_button) add_button.add_behavior({ 'type': 'click', 'cbjs_action': ''' var search_keys = spt.table.get_selected_search_keys(false); if (search_keys.length == 0) { spt.notify.show_message("No assets selected."); return; } var top = bvr.src_el.getParent(".spt_dialog"); var checkboxes = top.getElements(".spt_collection_checkbox"); var cmd = "tactic.ui.panel.CollectionAddCmd"; var server = TacticServerStub.get(); var is_checked = false; var dialog_top = bvr.src_el.getParent(".spt_dialog_top"); for (i = 0; i < checkboxes.length; i++) { var checked_collection_attr = checkboxes[i].attributes; var collection_key = checked_collection_attr[3].value; // Preventing a collection being added to itself, check if search_keys contain collection_key. if (search_keys.indexOf(collection_key) != -1) { spt.notify.show_message("Collection cannot be added to itself."); return; } if (checkboxes[i].checked == true) { // if there is at least one checkbox selected, set is_checked to 'true' is_checked = true; var search_keys = spt.table.get_selected_search_keys(false); var kwargs = { collection_key: collection_key, search_keys: search_keys } server.execute_cmd(cmd, kwargs); } } if (is_checked == false) { spt.notify.show_message("No collection selected."); return; } else { spt.notify.show_message("Assets added to Collection."); // refresh dialog_top, so users can see the number change in Collections spt.panel.refresh(dialog_top); } ''' }) return top