def get_display(my): widget = DivWdg(id='new_item_panel') widget.add_class("new_item_panel") widget.add_class("spt_new_item_top") div = DivWdg() div.add_color("background", "background") div.add_color("color", "color") div.add_style("padding", "5px") div.add_border() if my.is_personal: is_personal = 'true' else: is_personal = 'false' if my.type == 'new_folder': #div.set_attr('spt_view', 'new_folder') div.add(HtmlElement.b('Create New Folder')) div.add(HtmlElement.br(2)) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) """ # add exisiting views in the div for checking with client's input # add exiting views: from panel_wdg import ViewPanelSaveWdg views = ViewPanelSaveWdg.get_existing_views(my.is_personal) hidden = HiddenWdg('existing_views', '|'.join(views)) div.add(hidden) """ text2 = TextWdg("new_title") text2.add_class("spt_new_item_title") span = SpanWdg("Title: ") span.set_id('create_new_title') #span.add_style('display: none') span.add_style('padding-left: 8px') span.add(text2) div.add(span) div.add(HtmlElement.br(2)) div.add_style("width: 350px") action = ''' var top = bvr.src_el.getParent(".spt_new_item_top"); var name_el = top.getElement(".spt_new_item_name"); var title = bvr.src_el.value; var name = title.replace(/[\?.!@#$%^&*()'"]/g, ""); name = name.replace(/ /g, "_"); name = name.toLowerCase(); name_el.value = name; ''' # change the name based on the title text2.add_behavior({'type': 'change', 'cbjs_action': action}) div.add( "The name of the folder is a hidden name that is used by other elements to refer to uniquely to this item.<br/><br/>" ) text = TextWdg('new_name') text.add_class("spt_new_item_name") span = SpanWdg('Name: ') span.add(text) div.add(span) div.add(HtmlElement.br(2)) #script = "spt.side_bar.manage_section_action_cbk({'value':'predefined'},'project_view');" #link = HtmlElement.js_href(script, data='[ Predefined View ]') #div3 = DivWdg('Optional: drag existing elements from Project Views or %s into this new folder' %link.get_buffer_display()) #div.add(div3) #item_div = DivWdg(css='spt_new_item spt_side_bar_content') #div.add(item_div) div.add("<hr/>") #save_div = SpanWdg(css='med hand') #div.add(save_div) #save_div.add(IconWdg('Save Folder', IconWdg.SAVE)) save_button = ActionButtonWdg(title='Create', tip='Create a new folder') div.add(save_button) bvr = { "type": "click_up", "view": my.view, "is_personal": is_personal == 'true', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_new_item_top"); var name_el = top.getElement(".spt_new_item_name"); var name_value = name_el.value; if (name_value == "") { var title_el = top.getElement(".spt_new_item_title"); var title = title_el.value; var name = spt.convert_to_alpha_numeric(title); name_el.value = name; } if (name_value == "") { spt.alert("Please fill in a value for name."); return; } spt.side_bar.manage_section_action_cbk( { 'value':'save_folder'}, bvr.view, bvr.is_personal); ''' } save_button.add_behavior(bvr) div.add(HtmlElement.br()) elif my.type == 'new_link': div.set_attr('spt_view', 'new_link') div.add(HtmlElement.b('Create New Link')) div.add(HtmlElement.br()) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) text = TextWdg('new_link_title') span = SpanWdg('Title: ') span.add(text) div.add(span) div.add(HtmlElement.br(2)) cb = CheckboxWdg('include_search_view', label='Include Saved Search') cb.set_default_checked() div.add(cb) div.add(HtmlElement.br(2)) div.add("Select a search type and view of this link") div.add(HtmlElement.br()) select = SelectWdg("new_search_type") select.add_empty_option("-- Select Search type --") security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): search_types = Project.get().get_search_types( include_sthpw=True, include_config=True) else: search_types = Project.get().get_search_types() values = [x.get_value("search_type") for x in search_types] labels = [ "%s (%s)" % (x.get_value("search_type"), x.get_title()) for x in search_types ] values.append("CustomLayoutWdg") labels.append("CustomLayoutWdg") select.set_option("values", values) select.set_option("labels", labels) #security = Environment.get_security() #if security.check_access("builtin", "view_site_admin", "allow"): # select_mode = SearchTypeSelectWdg.ALL #else: # select_mode = SearchTypeSelectWdg.ALL_BUT_STHPW #select = SearchTypeSelectWdg(name='new_search_type', \ # mode=select_mode) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".new_item_panel"); var link_view_select = top.getElement(".link_view_select"); var input = spt.api.Utility.get_input(top, 'new_search_type'); var values = {'search_type': input.value, 'is_refresh': 'true'}; spt.panel.refresh(link_view_select, values);''' }) div.add(HtmlElement.br()) div.add(select) div.add(HtmlElement.br()) link_view_sel = NewLinkViewSelectWdg() div.add(HtmlElement.br()) div.add(link_view_sel) div.add(HtmlElement.br()) #select.add_behavior('change') div.add(HtmlElement.hr()) div.add(HtmlElement.br()) #save_div = DivWdg(css='med hand') #div.add(save_div) #save_button = ProdIconButtonWdg('Save Link', IconWdg.SAVE) #save_div.add(save_button) save_button = ActionButtonWdg(title='Create', tip='Create a new link') div.add(save_button) bvr = { "type": "click_up", 'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\ "'value':'save_link'},'%s', %s);" %(my.view, is_personal)} save_button.add_behavior(bvr) div.add(HtmlElement.br(1)) elif my.type == 'new_separator': div.set_attr('spt_view', 'new_separator') div.add(HtmlElement.b('Creating New Separator. . .')) div.add(HtmlElement.br()) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) # since it's automated, this button is not needed """ save_div = SpanWdg(css='med hand') save_div.add(IconWdg('Save', IconWdg.SAVE)) bvr = { "type": "click_up",\ 'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\ "'value':'save_separator'},'%s');" %my.view} save_div.add_behavior(bvr) div.add(save_div) """ widget.add(div) return widget
def get_display(my): widget = DivWdg(id='new_item_panel') widget.add_class("new_item_panel") widget.add_class("spt_new_item_top") div = DivWdg() div.add_color("background", "background") div.add_color("color", "color") div.add_style("padding", "5px") div.add_border() if my.is_personal: is_personal = 'true' else: is_personal = 'false' if my.type == 'new_folder': #div.set_attr('spt_view', 'new_folder') div.add(HtmlElement.b('Create New Folder')) div.add(HtmlElement.br(2)) """ # add exisiting views in the div for checking with client's input # add exiting views: from panel_wdg import ViewPanelSaveWdg views = ViewPanelSaveWdg.get_existing_views(my.is_personal) hidden = HiddenWdg('existing_views', '|'.join(views)) div.add(hidden) """ text2 = TextWdg("new_title") text2.add_class("spt_new_item_title") span = SpanWdg("Title: ") span.set_id('create_new_title') #span.add_style('display: none') span.add_style('padding-left: 8px') span.add(text2) div.add(span) div.add(HtmlElement.br(2)) div.add_style("width: 350px") action = ''' var top = bvr.src_el.getParent(".spt_new_item_top"); var name_el = top.getElement(".spt_new_item_name"); var title = bvr.src_el.value; var name = title.replace(/[\?.!@#$%^&*()'"]/g, ""); name = name.replace(/ /g, "_"); name = name.toLowerCase(); name_el.value = name; ''' # change the name based on the title text2.add_behavior( { 'type': 'change', 'cbjs_action': action } ) div.add("The name of the folder is a hidden name that is used by other elements to refer to uniquely to this item.<br/><br/>") text = TextWdg('new_name') text.add_class("spt_new_item_name") span = SpanWdg('Name: ') span.add(text) div.add(span) div.add(HtmlElement.br(2)) #script = "spt.side_bar.manage_section_action_cbk({'value':'predefined'},'project_view');" #link = HtmlElement.js_href(script, data='[ Predefined View ]') #div3 = DivWdg('Optional: drag existing elements from Project Views or %s into this new folder' %link.get_buffer_display()) #div.add(div3) #item_div = DivWdg(css='spt_new_item spt_side_bar_content') #div.add(item_div) div.add("<hr/>") #save_div = SpanWdg(css='med hand') #div.add(save_div) #save_div.add(IconWdg('Save Folder', IconWdg.SAVE)) save_button = ActionButtonWdg(title='Create', tip='Create a new folder') div.add(save_button) bvr = { "type": "click_up", "view": my.view, "is_personal": is_personal == 'true', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_new_item_top"); var name_el = top.getElement(".spt_new_item_name"); var name_value = name_el.value; if (name_value == "") { var title_el = top.getElement(".spt_new_item_title"); var title = title_el.value; var name = spt.convert_to_alpha_numeric(title); name_el.value = name; } if (name_value == "") { spt.alert("Please fill in a value for name."); return; } spt.side_bar.manage_section_action_cbk( { 'value':'save_folder'}, bvr.view, bvr.is_personal); ''' } save_button.add_behavior(bvr) div.add(HtmlElement.br()) elif my.type == 'new_link': div.set_attr('spt_view', 'new_link') div.add(HtmlElement.b('Create New Link')) div.add(HtmlElement.br()) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) text = TextWdg('new_link_title') span = SpanWdg('Title: ') span.add(text) div.add(span) div.add(HtmlElement.br(2)) cb = CheckboxWdg('include_search_view', label='Include Saved Search') cb.set_default_checked() div.add(cb) div.add(HtmlElement.br(2)) div.add("Select a search type and view of this link") div.add(HtmlElement.br()) select = SelectWdg("new_search_type") select.add_empty_option("-- Select Search type --") security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): search_types = Project.get().get_search_types(include_sthpw=True, include_config=True) else: search_types = Project.get().get_search_types() values = [x.get_value("search_type") for x in search_types] labels = ["%s (%s)" % (x.get_value("search_type"), x.get_title()) for x in search_types] values.append("CustomLayoutWdg") labels.append("CustomLayoutWdg") select.set_option("values", values) select.set_option("labels", labels) #security = Environment.get_security() #if security.check_access("builtin", "view_site_admin", "allow"): # select_mode = SearchTypeSelectWdg.ALL #else: # select_mode = SearchTypeSelectWdg.ALL_BUT_STHPW #select = SearchTypeSelectWdg(name='new_search_type', \ # mode=select_mode) select.add_behavior({'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".new_item_panel"); var link_view_select = top.getElement(".link_view_select"); var input = spt.api.Utility.get_input(top, 'new_search_type'); var values = {'search_type': input.value, 'is_refresh': 'true'}; spt.panel.refresh(link_view_select, values);''' }) div.add(HtmlElement.br()) div.add(select) div.add(HtmlElement.br()) link_view_sel = NewLinkViewSelectWdg() div.add(HtmlElement.br()) div.add(link_view_sel) div.add(HtmlElement.br()) #select.add_behavior('change') div.add(HtmlElement.hr()) div.add(HtmlElement.br()) #save_div = DivWdg(css='med hand') #div.add(save_div) #save_button = ProdIconButtonWdg('Save Link', IconWdg.SAVE) #save_div.add(save_button) save_button = ActionButtonWdg(title='Create', tip='Create a new link') div.add(save_button) bvr = { "type": "click_up", 'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\ "'value':'save_link'},'%s', %s);" %(my.view, is_personal)} save_button.add_behavior(bvr) div.add(HtmlElement.br(1)) elif my.type == 'new_separator': div.set_attr('spt_view', 'new_separator') div.add(HtmlElement.b('Creating New Separator. . .')) div.add(HtmlElement.br()) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) # since it's automated, this button is not needed """ save_div = SpanWdg(css='med hand') save_div.add(IconWdg('Save', IconWdg.SAVE)) bvr = { "type": "click_up",\ 'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\ "'value':'save_separator'},'%s');" %my.view} save_div.add_behavior(bvr) div.add(save_div) """ widget.add(div) return widget
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): top = my.top top.add_color("background", "background") top.add_color("color", "color") top.add_style("padding: 10px") top.add_style("min-width: 400px") from tactic.ui.app import HelpButtonWdg help_wdg = HelpButtonWdg(alias="exporting-csv-data") top.add(help_wdg) help_wdg.add_style("float: right") help_wdg.add_style("margin-top: -3px") if not my.check(): top.add(DivWdg('Error: %s' %my.error_msg)) top.add(HtmlElement.br(2)) return super(CsvExportWdg, my).get_display() if my.search_type_list and my.search_type_list[0] != my.search_type: st = SearchType.get(my.search_type_list[0]) title_div =DivWdg('Exporting related items [%s]' % st.get_title()) top.add(title_div) top.add(HtmlElement.br()) my.search_type = my.search_type_list[0] my.view = my.related_view if my.mode != 'export_all': num = len(my.selected_search_keys) else: search = Search(my.search_type) num = search.get_count() msg_div = DivWdg('Total: %s items to export'% num) msg_div.add_style("font-size: 12px") msg_div.add_style("font-weight: bold") msg_div.add_style('margin-left: 4px') top.add(msg_div) if num > 300: msg_div.add_behavior({'type':'load', 'cbjs_action': "spt.alert('%s items are about to be exported. It may take a while.')" %num}) top.add(HtmlElement.br()) div = DivWdg(css='spt_csv_export', id='csv_export_action') div.add_color("background", "background", -10) div.add_style("padding: 10px") div.add_style("margin: 5px") div.add_styles('max-height: 350px; overflow: auto') table = Table( css='minimal') table.add_color("color", "color") div.add(table) table.set_id('csv_export_table') table.center() cb_name = 'csv_column_name' master_cb = CheckboxWdg('master_control') master_cb.set_checked() master_cb.add_behavior({'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_csv_export'),'%s'); for (var i = 0; i < inputs.length; i++) inputs[i].checked = !inputs[i].checked; ''' %cb_name}) span = SpanWdg('Select Columns To Export') span.add_style('font-weight','600') table.add_row_cell(span) table.add_row_cell(HtmlElement.br()) tr = table.add_row() tr.add_style('border-bottom: 1px groove #777') td = table.add_cell(master_cb) label = HtmlElement.i('toggle all') label.add_style('color: #888') table.add_cell(label) col1 = table.add_col() col1.add_style('width: 35px') col2 = table.add_col() if not my.search_type or not my.view: return table # use overriding element names and derived titles if available config = WidgetConfigView.get_by_search_type(my.search_type, my.view) if my.element_names and config: filtered_columns = my.element_names titles = [] for name in my.element_names: title = config.get_element_title(name) titles.append(title) else: # excluding FunctionalTableElement filtered_columns = [] titles = [] if not config: columns = search.get_columns() filtered_columns = columns titles = ['n/a'] * len(filtered_columns) else: columns = config.get_element_names() filtered_columns = columns titles = config.get_element_titles() """ # commented out until it is decided 2.5 widgets will # use this class to differentiate between reg and functional element from pyasm.widget import FunctionalTableElement for column in columns: widget = config.get_display_widget(column) if isinstance(widget, FunctionalTableElement): continue filtered_columns.append(column) """ for idx, column in enumerate(filtered_columns): table.add_row() cb = CheckboxWdg(cb_name) cb.set_option('value', column) cb.set_checked() table.add_cell(cb) title = titles[idx] table.add_cell('<b>%s</b> (%s) '%(title, column)) action_div = DivWdg() widget = DivWdg() table.add_row_cell(widget) widget.add_style("margin: 20px 0 10px 0px") cb = CheckboxWdg('include_id', label=" Include ID") cb.set_default_checked() widget.add(cb) hint = HintWdg('To update entries with specific ID later, please check this option. For new inserts in this or other table later on, uncheck this option.') widget.add(hint) label = string.capwords(my.mode.replace('_', ' ')) button = ActionButtonWdg(title=label) is_export_all = my.mode == 'export_all' button.add_behavior({ 'type': "click_up", 'cbfn_action': 'spt.dg_table_action.csv_export', 'element': 'csv_export', 'column_names': 'csv_column_name', 'search_type': my.search_type, 'view': my.view, 'search_keys' : my.selected_search_keys, 'is_export_all' : is_export_all }) my.close_action = "var popup = bvr.src_el.getParent('.spt_popup');spt.popup.close(popup)" if my.close_action: close_button = ActionButtonWdg(title='Close') close_button.add_behavior({ 'type': "click", 'cbjs_action': my.close_action }) table = Table() action_div.add(table) table.center() table.add_row() td = table.add_cell(button) td.add_style("width: 130px") table.add_cell(close_button) action_div.add("<br clear='all'/>") top.add(div) top.add(HtmlElement.br()) top.add(action_div) return top
def get_first_row_wdg(my): # read the csv file #my.file_path = "" div = DivWdg(id='csv_import_main') div.add_class('spt_panel') div.add( my.get_upload_wdg() ) if not my.search_type: return div if not my.file_path: return div if not my.file_path.endswith(".csv"): div.add('<br>') div.add( "Uploaded file [%s] is not a csv file. Refreshing in 3 seconds. . ."% os.path.basename(my.file_path)) div.add_behavior( {'type': 'load', \ 'cbjs_action': "setTimeout(function() {spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});}, 3000);" %(Common.get_full_class_name(my), my.search_type) } ) return div if not os.path.exists(my.file_path): raise TacticException("Path '%s' does not exist" % my.file_path) div.add(HtmlElement.br(2)) # NOT NEEDED: clear the widget settings before drawing #expr = "@SOBJECT(sthpw/wdg_settings['key','EQ','pyasm.widget.input_wdg.CheckboxWdg|column_enabled_']['login','$LOGIN']['project_code','$PROJECT'])" #sobjs = Search.eval(expr) #for sobj in sobjs: # sobj.delete(log=False) div.add( HtmlElement.b("The following is taken from the first line in the uploaded csv file. Select the appropriate column to match.") ) div.add(HtmlElement.br()) """ text = HtmlElement.b("Make sure you have all the required columns** in the csv.") text.add_style('text-align: left') div.add(text) """ div.add(HtmlElement.br(2)) option_div_top = DivWdg() option_div_top.add_color('color','color') option_div_top.add_color('background','background', -5) option_div_top.add_style("padding: 10px") option_div_top.add_border() option_div_top.add_style("width: 300px") swap = SwapDisplayWdg(title="Parsing Options") option_div_top.add(swap) option_div_top.add_style("margin-right: 30px") my.search_type_obj = SearchType.get(my.search_type) option_div = DivWdg() swap.set_content_id(option_div.set_unique_id() ) option_div.add_style("display: none") option_div.add_style('margin-left: 14px') option_div.add_style('margin-top: 10px') option_div.add_style("font-weight: bold") option_div_top.add(option_div) # first row and second row #option_div.add( HtmlElement.br() ) option_div.add(SpanWdg("Use Title Row: ", css='small')) title_row_checkbox = CheckboxWdg("has_title") title_row_checkbox.set_default_checked() title_row_checkbox.add_behavior({'type' : 'click_up', 'propagate_evt': 'true', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(title_row_checkbox) option_div.add( HintWdg("Set this to use the first row as a title row to match up columns in the database") ) option_div.add( HtmlElement.br(2) ) option_div.add(SpanWdg("Use Lowercase Title: ", css='small')) lower_title_checkbox = CheckboxWdg("lowercase_title") lower_title_checkbox.add_behavior({'type' : 'click_up', 'propagate_evt': 'true', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(lower_title_checkbox) option_div.add( HtmlElement.br(2) ) option_div.add(SpanWdg("Sample Data Row: ", css='small')) data_row_text = SelectWdg("data_row") data_row_text.set_option('values', '1|2|3|4|5') data_row_text.set_value('1') data_row_text.add_behavior({'type' : 'change', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(data_row_text) option_div.add( HintWdg("Set this as a sample data row for display here") ) option_div.add( HtmlElement.br(2) ) # encoder option_div.add(SpanWdg("Encoder: ", css='small')) select_wdg = SelectWdg('encoder') select_wdg.set_option('values', ['','utf-8', 'iso_8859-1']) select_wdg.set_option('labels', ['ASCII (default)','UTF-8','Excel ISO 8859-1']) select_wdg.add_behavior({'type' : 'change', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(select_wdg) option_div.add( HtmlElement.br(2) ) option_div.add(SpanWdg("Identifying Column: ", css='small')) select_wdg = SelectWdg('id_col') select_wdg.set_option('empty','true') #columns = my.search_type_obj.get_columns() columns = SearchType.get_columns(my.search_type) # make sure it starts off with id, code where applicable if 'code' in columns: columns.remove('code') columns.insert(0, 'code') if 'id' in columns: columns.remove('id') columns.insert(0, 'id') select_wdg.set_option('values', columns) option_div.add(select_wdg) option_div.add( HintWdg("Set which column to use for identifying an item to update during CSV Import") ) option_div.add( HtmlElement.br(2) ) div.add(option_div_top) my.has_title = title_row_checkbox.is_checked() # need to somehow specify defaults for columns div.add(my.get_preview_wdg()) return div
def get_action_wdg(self, 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 self.parent_wdg: info = self.parent_wdg.get_aux_info() sobject_dict = info.get('sobjects') sobject = sobject_dict.get(self.get_name()) parent = info.get('parent') else: sobject = None parent = None if not sobject: if self.parent_key: parent = SearchKey.get_by_search_key(self.parent_key) # get the latest note #search_key = self.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) self.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': self.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): top = my.top top.add_color("background", "background") top.add_color("color", "color") top.add_style("padding: 10px") top.add_style("min-width: 400px") from tactic.ui.app import HelpButtonWdg help_wdg = HelpButtonWdg(alias="exporting-csv-data") top.add(help_wdg) help_wdg.add_style("float: right") help_wdg.add_style("margin-top: -3px") if not my.check(): top.add(DivWdg('Error: %s' %my.error_msg)) top.add(HtmlElement.br(2)) return super(CsvExportWdg, my).get_display() if my.search_type_list and my.search_type_list[0] != my.search_type: st = SearchType.get(my.search_type_list[0]) title_div =DivWdg('Exporting related items [%s]' % st.get_title()) top.add(title_div) top.add(HtmlElement.br()) my.search_type = my.search_type_list[0] my.view = my.related_view if my.mode != 'export_all': num = len(my.selected_search_keys) else: search = Search(my.search_type) num = search.get_count() msg_div = DivWdg('Total: %s items to export'% num) msg_div.add_style("font-size: 12px") msg_div.add_style("font-weight: bold") msg_div.add_style('margin-left: 4px') top.add(msg_div) if num > 300: msg_div.add_behavior({'type':'load', 'cbjs_action': "spt.alert('%s items are about to be exported. It may take a while.')" %num}) top.add(HtmlElement.br()) div = DivWdg(css='spt_csv_export', id='csv_export_action') div.add_color("background", "background", -10) div.add_style("padding: 10px") div.add_style("margin: 5px") div.add_styles('max-height: 350px; overflow: auto') table = Table( css='minimal') table.add_color("color", "color") div.add(table) table.set_id('csv_export_table') table.center() cb_name = 'csv_column_name' master_cb = CheckboxWdg('master_control') master_cb.set_checked() master_cb.add_behavior({'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_csv_export'),'%s'); for (var i = 0; i < inputs.length; i++) inputs[i].checked = !inputs[i].checked; ''' %cb_name}) span = SpanWdg('Select Columns To Export') span.add_style('font-weight','600') table.add_row_cell(span) table.add_row_cell(HtmlElement.br()) tr = table.add_row() tr.add_style('border-bottom: 1px groove #777') td = table.add_cell(master_cb) label = HtmlElement.i('toggle all') label.add_style('color: #888') table.add_cell(label) col1 = table.add_col() col1.add_style('width: 35px') col2 = table.add_col() if not my.search_type or not my.view: return table # use overriding element names and derived titles if available config = WidgetConfigView.get_by_search_type(my.search_type, my.view) if my.element_names and config: filtered_columns = my.element_names titles = [] for name in my.element_names: title = config.get_element_title(name) titles.append(title) else: # excluding FunctionalTableElement filtered_columns = [] titles = [] if not config: columns = search.get_columns() filtered_columns = columns titles = ['n/a'] * len(filtered_columns) else: columns = config.get_element_names() filtered_columns = columns titles = config.get_element_titles() """ # commented out until it is decided 2.5 widgets will # use this class to differentiate between reg and functional element from pyasm.widget import FunctionalTableElement for column in columns: widget = config.get_display_widget(column) if isinstance(widget, FunctionalTableElement): continue filtered_columns.append(column) """ for idx, column in enumerate(filtered_columns): table.add_row() cb = CheckboxWdg(cb_name) cb.set_option('value', column) cb.set_checked() table.add_cell(cb) title = titles[idx] table.add_cell('<b>%s</b> (%s) '%(title, column)) action_div = DivWdg() widget = DivWdg() table.add_row_cell(widget) widget.add_style("margin: 20px 0 10px 0px") cb = CheckboxWdg('include_id', label=" Include ID") cb.set_default_checked() widget.add(cb) hint = HintWdg('To update entries with specific ID later, please check this option. For new inserts in this or other table later on, uncheck this option.') widget.add(hint) label = string.capwords(my.mode.replace('_', ' ')) button = ActionButtonWdg(title=label, size='l') is_export_all = my.mode == 'export_all' button.add_behavior({ 'type': "click_up", 'cbfn_action': 'spt.dg_table_action.csv_export', 'element': 'csv_export', 'column_names': 'csv_column_name', 'search_type': my.search_type, 'view': my.view, 'search_keys' : my.selected_search_keys, 'is_export_all' : is_export_all }) my.close_action = "var popup = bvr.src_el.getParent('.spt_popup');spt.popup.close(popup)" if my.close_action: close_button = ActionButtonWdg(title='Close') close_button.add_behavior({ 'type': "click", 'cbjs_action': my.close_action }) table = Table() action_div.add(table) table.center() table.add_row() td = table.add_cell(button) td.add_style("width: 130px") table.add_cell(close_button) action_div.add("<br clear='all'/>") top.add(div) top.add(HtmlElement.br()) top.add(action_div) if my.is_test: rtn_data = {'columns': my.element_names, 'count': len(my.selected_search_keys)} if my.mode == 'export_matched': rtn_data['sql'] = my.table.search_wdg.search.get_statement() from pyasm.common import jsondumps rtn_data = jsondumps(rtn_data) return rtn_data return top
def get_first_row_wdg(my): # read the csv file #my.file_path = "" div = DivWdg(id='csv_import_main') div.add_class('spt_panel') div.add( my.get_upload_wdg() ) if not my.search_type: return div if not my.file_path: return div if not my.file_path.endswith(".csv"): div.add('<br/>') div.add( "Uploaded file [%s] is not a csv file. Refreshing in 3 seconds. . ."% os.path.basename(my.file_path)) div.add_behavior( {'type': 'load', \ 'cbjs_action': "setTimeout(function() {spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});}, 3000);" %(Common.get_full_class_name(my), my.search_type) } ) return div if not os.path.exists(my.file_path): raise TacticException("Path '%s' does not exist" % my.file_path) div.add(HtmlElement.br(2)) # NOT NEEDED: clear the widget settings before drawing #expr = "@SOBJECT(sthpw/wdg_settings['key','EQ','pyasm.widget.input_wdg.CheckboxWdg|column_enabled_']['login','$LOGIN']['project_code','$PROJECT'])" #sobjs = Search.eval(expr) #for sobj in sobjs: # sobj.delete(log=False) div.add( HtmlElement.b("The following is taken from the first line in the uploaded csv file. Select the appropriate column to match.") ) div.add(HtmlElement.br()) """ text = HtmlElement.b("Make sure you have all the required columns** in the csv.") text.add_style('text-align: left') div.add(text) """ div.add(HtmlElement.br(2)) option_div_top = DivWdg() option_div_top.add_color('color','color') option_div_top.add_color('background','background', -5) option_div_top.add_style("padding: 10px") option_div_top.add_border() option_div_top.add_style("width: 300px") swap = SwapDisplayWdg(title="Parsing Options") option_div_top.add(swap) option_div_top.add_style("margin-right: 30px") my.search_type_obj = SearchType.get(my.search_type) option_div = DivWdg() swap.set_content_id(option_div.set_unique_id() ) option_div.add_style("display: none") option_div.add_style('margin-left: 14px') option_div.add_style('margin-top: 10px') option_div.add_style("font-weight: bold") option_div_top.add(option_div) # first row and second row #option_div.add( HtmlElement.br() ) option_div.add(SpanWdg("Use Title Row: ", css='small')) title_row_checkbox = CheckboxWdg("has_title") title_row_checkbox.set_default_checked() title_row_checkbox.add_behavior({'type' : 'click_up', 'propagate_evt': 'true', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(title_row_checkbox) option_div.add( HintWdg("Set this to use the first row as a title row to match up columns in the database") ) option_div.add( HtmlElement.br(2) ) option_div.add(SpanWdg("Use Lowercase Title: ", css='small')) lower_title_checkbox = CheckboxWdg("lowercase_title") lower_title_checkbox.add_behavior({'type' : 'click_up', 'propagate_evt': 'true', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(lower_title_checkbox) option_div.add( HtmlElement.br(2) ) option_div.add(SpanWdg("Sample Data Row: ", css='small')) data_row_text = SelectWdg("data_row") data_row_text.set_option('values', '1|2|3|4|5') data_row_text.set_value('1') data_row_text.add_behavior({'type' : 'change', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(data_row_text) option_div.add( HintWdg("Set this as a sample data row for display here") ) option_div.add( HtmlElement.br(2) ) # encoder option_div.add(SpanWdg("Encoder: ", css='small')) select_wdg = SelectWdg('encoder') select_wdg.set_option('values', ['','utf-8', 'iso_8859-1']) select_wdg.set_option('labels', ['ASCII (default)','UTF-8','Excel ISO 8859-1']) select_wdg.add_behavior({'type' : 'change', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(select_wdg) option_div.add( HtmlElement.br(2) ) option_div.add(SpanWdg("Identifying Column: ", css='small')) select_wdg = SelectWdg('id_col') select_wdg.set_option('empty','true') #columns = my.search_type_obj.get_columns() columns = SearchType.get_columns(my.search_type) # make sure it starts off with id, code where applicable if 'code' in columns: columns.remove('code') columns.insert(0, 'code') if 'id' in columns: columns.remove('id') columns.insert(0, 'id') select_wdg.set_option('values', columns) option_div.add(select_wdg) option_div.add( HintWdg("Set which column to use for identifying an item to update during CSV Import") ) option_div.add( HtmlElement.br(2) ) # triggers mode option_div.add(SpanWdg("Triggers: ", css='small')) select_wdg = SelectWdg('triggers_mode') select_wdg.set_option('values', ['','False', 'True', 'none']) select_wdg.set_option('labels', ['- Select -','Internal Triggers Only','All Triggers','No Triggers']) select_wdg.add_behavior({'type' : 'change', 'cbjs_action': "spt.panel.refresh('preview_data',\ spt.api.Utility.get_input_values('csv_import_main'))"}) option_div.add(select_wdg) option_div.add( HtmlElement.br(2) ) div.add(option_div_top) my.has_title = title_row_checkbox.is_checked() # need to somehow specify defaults for columns div.add(my.get_preview_wdg()) return div