def get_display(self): table = Table() table.set_id('prequal_eval_lines_table') if self.lines: self.set_header_rows(table) type_code_options = [('Film', 'film'), ('Video', 'video'), ('Telecine', 'telecine'), ('Audio', 'audio')] scale_select_options = [('1', '1'), ('2', '2'), ('3', '3'), ('FYI', 'fyi')] in_source_options = [('No', 'no'), ('Yes', 'yes')] for iterator, line in enumerate(self.lines): current_row = table.add_row() current_row.add_attr('code', line.get_code()) table.add_cell( self.get_timecode_textbox('timecode-{0}'.format(iterator), 150, line.get_value('timecode')) ) table.add_cell( self.get_text_input_wdg('field-{0}'.format(iterator), 30, line.get_value('field')) ) table.add_cell( self.get_description_select_wdg('prequal-line-description-{0}'.format(iterator), line.get_value('prequal_line_description_code')) ) table.add_cell( self.get_select_wdg('type-code-{0}'.format(iterator), type_code_options, line.get_value('type_code')) ) table.add_cell( self.get_select_wdg('scale-{0}'.format(iterator), scale_select_options, line.get_value('scale')) ) table.add_cell( self.get_text_input_wdg('sector-or-channel-{0}'.format(iterator), 150, line.get_value('sector_or_channel')) ) table.add_cell( self.get_select_wdg('in-source-{0}'.format(iterator), in_source_options, line.get_value('in_source').lower()) ) table.add_cell( self.get_remove_row_button(line.get_code()) ) else: table.add_cell("No PreQual Evaluation lines exist yet. Add one?") table.add_cell(self.get_add_row_button()) table.add_cell(self.get_add_multiple_rows_button()) main_div = DivWdg() main_div.set_id('prequal_eval_lines_div') main_div.add_style('margin', '10px') main_div.add(table) return main_div
def get_display(self): audio_configuration_table = Table() audio_configuration_table.set_id('audio_configuration_table') audio_configuration_table.add_style('margin', '10px') if self.lines: audio_configuration_table.add_row() audio_configuration_table.add_header('Audio Configuration') audio_configuration_table.add_row() audio_configuration_table.add_header('Channel') audio_configuration_table.add_header('Content') audio_configuration_table.add_header('Tone') audio_configuration_table.add_header('Peak') for iterator, line in enumerate(self.lines): current_row = audio_configuration_table.add_row() audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config( 'channel-{0}'.format(iterator), 150, line.get_value('channel'))) audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config( 'content-{0}'.format(iterator), 150, line.get_value('content'))) audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config( 'tone-{0}'.format(iterator), 150, line.get_value('tone'))) audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config( 'peak-{0}'.format(iterator), 150, line.get_value('peak'))) audio_configuration_table.add_cell( HiddenWdg('audio-line-code-{0}'.format(iterator), line.get_code())) audio_configuration_table.add_cell( self.get_remove_row_button(line.get_code())) else: audio_configuration_table.add( "No Audio Configuration lines exist yet. Add one?") audio_configuration_table.add(self.get_add_row_button()) main_div = DivWdg() main_div.set_id('audio_config_lines_div') main_div.add_style('margin', '10px') main_div.add(audio_configuration_table) return main_div
def get_display(self): audio_configuration_table = Table() audio_configuration_table.set_id('audio_configuration_table') audio_configuration_table.add_style('margin', '10px') if self.lines: audio_configuration_table.add_row() audio_configuration_table.add_header('Audio Configuration') audio_configuration_table.add_row() audio_configuration_table.add_header('Channel') audio_configuration_table.add_header('Content') audio_configuration_table.add_header('Tone') audio_configuration_table.add_header('Peak') for iterator, line in enumerate(self.lines): current_row = audio_configuration_table.add_row() audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config('channel-{0}'.format(iterator), 150, line.get_value('channel')) ) audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config('content-{0}'.format(iterator), 150, line.get_value('content')) ) audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config('tone-{0}'.format(iterator), 150, line.get_value('tone')) ) audio_configuration_table.add_cell( self.get_text_input_wdg_for_audio_config('peak-{0}'.format(iterator), 150, line.get_value('peak')) ) audio_configuration_table.add_cell( HiddenWdg('audio-line-code-{0}'.format(iterator), line.get_code()) ) audio_configuration_table.add_cell( self.get_remove_row_button(line.get_code()) ) else: audio_configuration_table.add("No Audio Configuration lines exist yet. Add one?") audio_configuration_table.add(self.get_add_row_button()) main_div = DivWdg() main_div.set_id('audio_config_lines_div') main_div.add_style('margin', '10px') main_div.add(audio_configuration_table) return main_div
def get_display(self): table = Table() table.set_id('element_eval_lines_table') if self.lines: self.set_header_rows(table) in_safe_options = [('Yes', True), ('No', False)] type_code_options = [('Film', 'film'), ('Video', 'video'), ('Telecine', 'telecine'), ('Audio', 'audio')] scale_select_options = [('1', '1'), ('2', '2'), ('3', '3'), ('FYI', 'fyi')] in_source_options = [ ('No', 'no'), ('Yes', 'yes'), ('New', 'new'), ('Approved', 'approved'), ('Fixed', 'fixed'), ('Not Fixed', 'not_fixed'), ('Approved by Production', 'approved_by_production'), ('Approved by Client', 'approved_by_client'), ('Approved as is', 'approved_as_is'), ('Approved by Territory', 'approved_by_territory'), ('From Approved Master', 'from_approved_master'), ('Improved', 'improved') ] for iterator, line in enumerate(self.lines): table.add_row() table.add_cell( self.get_text_input_for_element_eval_line_wdg( 'timecode-in-{0}'.format(iterator), line.get_value('timecode_in'), line.get_value('checked'), 150, timecode=True)) table.add_cell( self.get_text_input_for_element_eval_line_wdg( 'field-in-{0}'.format(iterator), line.get_value('field_in'), line.get_value('checked'), 50)) table.add_cell( self.get_text_input_for_element_eval_line_wdg( 'description-{0}'.format(iterator), line.get_value('description'), line.get_value('checked'), 400)) table.add_cell( self.get_select_wdg('in-safe-{0}'.format(iterator), in_safe_options, line.get_value('checked'), line.get_value('in_safe'))) table.add_cell( self.get_text_input_for_element_eval_line_wdg( 'timecode-out-{0}'.format(iterator), line.get_value('timecode_out'), line.get_value('checked'), 150, timecode=True)) table.add_cell( self.get_duration_wdg(line.get_value('timecode_in'), line.get_value('timecode_out'))) table.add_cell( self.get_select_wdg('type-code-{0}'.format(iterator), type_code_options, line.get_value('checked'), line.get_value('type_code'))) table.add_cell( self.get_select_wdg('scale-{0}'.format(iterator), scale_select_options, line.get_value('checked'), line.get_value('scale'))) table.add_cell( self.get_text_input_for_element_eval_line_wdg( 'sector-or-channel-{0}'.format(iterator), line.get_value('sector_or_channel'), line.get_value('checked'), 150)) table.add_cell( self.get_select_wdg('in-source-{0}'.format(iterator), in_source_options, line.get_value('checked'), line.get_value('in_source'))) table.add_cell( HiddenWdg('checked-{0}'.format(iterator), line.get_value('checked'))) table.add_cell( HiddenWdg('element-eval-line-code-{0}'.format(iterator), line.get_code())) table.add_cell(self.get_remove_row_button(line.get_code())) if not line.get_value('checked'): table.add_cell(self.get_row_checked_button( line.get_code())) else: table.add_cell("No Element Evaluation lines exist yet. Add one?") table.add_cell(self.get_add_row_button()) table.add_cell(self.get_add_multiple_rows_button()) main_div = DivWdg() main_div.set_id('element_eval_lines_div') main_div.add_style('margin', '10px') main_div.add(table) return main_div
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_upload_wdg(my): '''get search type select and upload wdg''' widget = DivWdg(css='spt_import_csv') widget.add_color('color','color') widget.add_color('background','background') widget.add_style('width: 600px') # get the search type title = DivWdg("<b>Select sType to import data into:</b> ") widget.add( title ) title.add_style("float: left") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") key='csv_import' table = Table() table.set_id('csv_main_body') table.add_style("margin: 10px 10px") table.add_col().set_attr('width','140') table.add_col().set_attr('width','400') table.add_row() table.add_header("Search Type: ").set_attr('align','left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align','left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align','left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) div = DivWdg() search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL) search_type_select.add_empty_option("-- Select --") if not search_type_select.get_value(): search_type_select.set_value(my.search_type) search_type_select.set_persist_on_submit() div.add(search_type_select) widget.add(div) search_type_select.add_behavior( {'type': 'change', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } ) if my.search_type: sobj = None try: sobj = SObjectFactory.create(my.search_type) except ImportError: widget.add(HtmlElement.br()) widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) return widget required_columns = sobj.get_required_columns() if required_columns: widget.add(HtmlElement.br()) req_span = SpanWdg("Required Columns: ", css='med') req_span.add_color('color','color') widget.add(req_span) #required_columns = ['n/a'] req_span.add(', '.join(required_columns)) widget.add( HtmlElement.br() ) if my.file_path: hidden = HiddenWdg("file_path", my.file_path) widget.add(hidden) if my.web_url: file_span = FloatDivWdg('URL: <i>%s</i> ' %my.web_url, css='med') else: file_span = FloatDivWdg('File uploaded: <i>%s</i> ' %os.path.basename(my.file_path), css='med') file_span.add_color('color','color') file_span.add_style('margin: 8px 0 0 10px') file_span.add_style('font-size: 14px') widget.add(file_span) button = ActionButtonWdg(title='Change') button.add_style('float','left') button.add_behavior( {'type': 'click_up', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } ) widget.add(button) widget.add("<br clear='all'/>") widget.add(HtmlElement.br()) return widget widget.add("<br/>") widget.add_style("overflow-y: auto") msg = DivWdg() widget.add(msg) msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>") msg.add_border() msg.add_style("width: 400px") msg.add_color("background", "background3") msg.add_style("padding: 20px") msg.add_style("margin: 30 auto") msg.add_style("text-align: center") ticket = Environment.get_security().get_ticket_key() on_complete = '''var server = TacticServerStub.get(); var file = spt.html5upload.get_file(); if (file) { var file_name = file.name; // clean up the file name the way it is done in the server file_name = spt.path.get_filesystem_name(file_name); var server = TacticServerStub.get(); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; values['html5_ticket'] = '%s'; try { var info = spt.panel.load('csv_import_main', class_name, {}, values); spt.app_busy.hide(); } catch(e) { spt.alert(spt.exception.handler(e)); } } else { alert('Error: file object cannot be found.') } spt.app_busy.hide();'''%ticket from tactic.ui.input import UploadButtonWdg browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\ on_complete=on_complete, ticket=ticket) browse.add_style('float: left') msg.add(browse) # this is now only used in the copy and paste Upload button for backward-compatibility upload_wdg = SimpleUploadWdg(key=key, show_upload=False) upload_wdg.add_style('display: none') msg.add(upload_wdg) #widget.add(span) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Published URL: </b>") text = TextWdg("web_url") msg.add(text) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Copy and Paste from a Spreadsheet: </b>") text = TextAreaWdg("data") text.add_style('width: 33em') text.add_class("spt_import_cut_paste") msg.add(text) button = ActionButtonWdg(title="Parse") button.add_style("margin: 5px auto") msg.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_import_top"); var el = top.getElement(".spt_import_cut_paste"); var applet = spt.Applet.get(); var value = el.value; var csv = []; // convert to a csv file! lines = value.split("\\n"); for (var i = 0; i < lines.length; i++) { if (lines[i] == '') { continue; } var parts = lines[i].split("\\t"); var new_line = []; for (var j = 0; j < parts.length; j++) { if (parts[j] == '') { new_line.push(''); } else { new_line.push('"'+parts[j]+'"'); } } new_line = new_line.join(","); csv.push(new_line); } csv = csv.join("\\n") // FIXME: need to get a local temp directory var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv"; applet.create_file(path, csv); // upload the file applet.upload_file(path) applet.rmtree(path); var top = bvr.src_el.getParent(".spt_import_csv"); var hidden = top.getElement(".spt_upload_hidden"); hidden.value = path; var file_name = spt.path.get_basename(hidden.value); file_name = spt.path.get_filesystem_name(file_name); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; var info = spt.panel.load('csv_import_main', class_name, {}, values); ''' } ) return widget
def get_example_display(my): div = DivWdg() # Smart Menu data ... dog_menus = [ my.get_sm_dog_main_menu_details(), my.get_sm_dog_submenu_one_details(), my.get_sm_dog_submenu_two_details() ] cat_menus = [ my.get_sm_cat_main_menu_details() ] SmartMenu.attach_smart_context_menu( div, { 'DOG': dog_menus, 'CAT': cat_menus }, False ) table = Table(css="maq_view_table") table.set_id( "main_body_table" ) table.add_class("spt_table") table.add_behavior( { "type": "smart_drag", "bvr_match_class": "SPT_DO_RESIZE", "cbjs_setup": 'spt.dg_table.resize_column_setup( evt, bvr, mouse_411 );', "cbjs_motion": 'spt.dg_table.resize_column_motion( evt, bvr, mouse_411 );' } ) table.add_behavior( { "type": "smart_drag", "bvr_match_class": "SPT_DO_DRAG", "use_copy": 'true', "use_delta": 'true', 'dx': 10, 'dy': 10, "drop_code": 'TableExampleSwitchContents', "cbjs_action": "spt.ui_play.drag_cell_drop_action( evt, bvr );", "copy_styles": 'background: blue; opacity: .5; border: 1px solid black; text-align: left;' } ) row = table.add_row() for c in range(10): th = table.add_header() th.set_attr('col_idx', str(c)) th.add_class("cell_left") th.add_styles("width: 150px; cursor: default;") # @@@ th.add_behavior( { "type": "move", "cbjs_action": ''' // log.debug( "(x,y) = (" + mouse_411.curr_x + "," + mouse_411.curr_y + ")" ); spt.ui_play.header_half_move_cbk( evt, bvr, mouse_411 ); ''', "cbjs_action_on": ''' // log.debug( "START MY MOVE!" ); ''', "cbjs_action_off": ''' // log.debug( "DONE MY MOVE!" ); spt.ui_play.header_half_move_off_cbk( evt, bvr, mouse_411 ); ''' } ) if (c%2): th.add("H%s (Cat)" % c) else: th.add("H%s (Dog)" % c) th_resize = table.add_cell() th_resize.set_attr('col_idx', str(c+1)) th_resize.add_class("SPT_DO_RESIZE cell_right") th_resize.add_styles("width: 4px; cursor: col-resize;") for r in range(19): row = table.add_row() for c in range(10): col = table.add_cell() col.set_attr('col_idx', str(c)) col.set_attr('SPT_ACCEPT_DROP', 'TableExampleSwitchContents') col.add_class("SPT_DO_DRAG cell_left") col.add_styles("cursor: pointer;") col.add("(%s,%s)" % (r,c)) if (c % 2) == 0: SmartMenu.assign_as_local_activator( col, "DOG" ) else: SmartMenu.assign_as_local_activator( col, "CAT" ) resize = table.add_cell() resize.set_attr('col_idx', str(c+1)) resize.add_class("SPT_DO_RESIZE cell_right") resize.add_styles("width: 6px; cursor: col-resize;") div.add( table ) return div
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_upload_wdg(my): '''get search type select and upload wdg''' widget = DivWdg(css='spt_import_csv') widget.add_color('color','color') widget.add_color('background','background') widget.add_style('width: 600px') # get the search type title = DivWdg("<b>Select sType to import data into:</b> ") widget.add( title ) title.add_style("float: left") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") key='csv_import' table = Table() table.set_id('csv_main_body') table.add_style("margin: 10px 10px") table.add_col().set_attr('width','140') table.add_col().set_attr('width','400') table.add_row() table.add_header("Search Type: ").set_attr('align','left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align','left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align','left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) div = DivWdg() search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL) search_type_select.add_empty_option("-- Select --") if not search_type_select.get_value(): search_type_select.set_value(my.search_type) search_type_select.set_persist_on_submit() div.add(search_type_select) widget.add(div) search_type_select.add_behavior( {'type': 'change', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } ) if my.search_type: sobj = None try: sobj = SObjectFactory.create(my.search_type) except ImportError: widget.add(HtmlElement.br()) widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) return widget required_columns = sobj.get_required_columns() if required_columns: widget.add(HtmlElement.br()) req_span = SpanWdg("Required Columns: ", css='med') req_span.add_color('color','color') widget.add(req_span) #required_columns = ['n/a'] req_span.add(', '.join(required_columns)) widget.add( HtmlElement.br() ) if my.file_path: hidden = HiddenWdg("file_path", my.file_path) widget.add(hidden) if my.web_url: file_span = FloatDivWdg('URL: <i>%s</i> ' %my.web_url, css='med') else: file_span = FloatDivWdg('File uploaded: <i>%s</i> ' %os.path.basename(my.file_path), css='med') file_span.add_color('color','color') file_span.add_style('margin: 8px 0 0 10px') file_span.add_style('font-size: 14px') widget.add(file_span) button = ActionButtonWdg(title='Change') button.add_style('float','left') button.add_behavior( {'type': 'click_up', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } ) widget.add(button) widget.add("<br clear='all'/>") widget.add(HtmlElement.br()) return widget widget.add("<br/>") widget.add_style("overflow-y: auto") msg = DivWdg() widget.add(msg) msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>") msg.add_border() msg.add_style("width: 400px") msg.add_color("background", "background3") msg.add_style("padding: 20px") msg.add_style("margin: 30 auto") msg.add_style("text-align: center") ticket = Environment.get_security().get_ticket_key() on_complete = '''var server = TacticServerStub.get(); var file = spt.html5upload.get_file(); if (file) { var file_name = file.name; // clean up the file name the way it is done in the server //file_name = spt.path.get_filesystem_name(file_name); var server = TacticServerStub.get(); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; values['html5_ticket'] = '%s'; try { var info = spt.panel.load('csv_import_main', class_name, {}, values); spt.app_busy.hide(); } catch(e) { spt.alert(spt.exception.handler(e)); } } else { alert('Error: file object cannot be found.') } spt.app_busy.hide();'''%ticket from tactic.ui.input import UploadButtonWdg browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\ on_complete=on_complete, ticket=ticket) browse.add_style('float: left') msg.add(browse) # this is now only used in the copy and paste Upload button for backward-compatibility upload_wdg = SimpleUploadWdg(key=key, show_upload=False) upload_wdg.add_style('display: none') msg.add(upload_wdg) #widget.add(span) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Published URL: </b>") text = TextWdg("web_url") msg.add(text) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Copy and Paste from a Spreadsheet: </b>") text = TextAreaWdg("data") text.add_style('width: 33em') text.add_class("spt_import_cut_paste") msg.add(text) button = ActionButtonWdg(title="Parse") button.add_style("margin: 5px auto") msg.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_import_top"); var el = top.getElement(".spt_import_cut_paste"); var applet = spt.Applet.get(); var value = el.value; var csv = []; // convert to a csv file! lines = value.split("\\n"); for (var i = 0; i < lines.length; i++) { if (lines[i] == '') { continue; } var parts = lines[i].split("\\t"); var new_line = []; for (var j = 0; j < parts.length; j++) { if (parts[j] == '') { new_line.push(''); } else { new_line.push('"'+parts[j]+'"'); } } new_line = new_line.join(","); csv.push(new_line); } csv = csv.join("\\n") // FIXME: need to get a local temp directory var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv"; applet.create_file(path, csv); // upload the file applet.upload_file(path) applet.rmtree(path); var top = bvr.src_el.getParent(".spt_import_csv"); var hidden = top.getElement(".spt_upload_hidden"); hidden.value = path; var file_name = spt.path.get_basename(hidden.value); file_name = spt.path.get_filesystem_name(file_name); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; var info = spt.panel.load('csv_import_main', class_name, {}, values); ''' } ) return widget
def get_example_display(my): div = DivWdg() # Smart Menu data ... dog_menus = [ my.get_sm_dog_main_menu_details(), my.get_sm_dog_submenu_one_details(), my.get_sm_dog_submenu_two_details() ] cat_menus = [my.get_sm_cat_main_menu_details()] SmartMenu.attach_smart_context_menu(div, { 'DOG': dog_menus, 'CAT': cat_menus }, False) table = Table(css="maq_view_table") table.set_id("main_body_table") table.add_class("spt_table") table.add_behavior({ "type": "smart_drag", "bvr_match_class": "SPT_DO_RESIZE", "cbjs_setup": 'spt.dg_table.resize_column_setup( evt, bvr, mouse_411 );', "cbjs_motion": 'spt.dg_table.resize_column_motion( evt, bvr, mouse_411 );' }) table.add_behavior({ "type": "smart_drag", "bvr_match_class": "SPT_DO_DRAG", "use_copy": 'true', "use_delta": 'true', 'dx': 10, 'dy': 10, "drop_code": 'TableExampleSwitchContents', "cbjs_action": "spt.ui_play.drag_cell_drop_action( evt, bvr );", "copy_styles": 'background: blue; opacity: .5; border: 1px solid black; text-align: left;' }) row = table.add_row() for c in range(10): th = table.add_header() th.set_attr('col_idx', str(c)) th.add_class("cell_left") th.add_styles("width: 150px; cursor: default;") # @@@ th.add_behavior({ "type": "move", "cbjs_action": ''' // log.debug( "(x,y) = (" + mouse_411.curr_x + "," + mouse_411.curr_y + ")" ); spt.ui_play.header_half_move_cbk( evt, bvr, mouse_411 ); ''', "cbjs_action_on": ''' // log.debug( "START MY MOVE!" ); ''', "cbjs_action_off": ''' // log.debug( "DONE MY MOVE!" ); spt.ui_play.header_half_move_off_cbk( evt, bvr, mouse_411 ); ''' }) if (c % 2): th.add("H%s (Cat)" % c) else: th.add("H%s (Dog)" % c) th_resize = table.add_cell() th_resize.set_attr('col_idx', str(c + 1)) th_resize.add_class("SPT_DO_RESIZE cell_right") th_resize.add_styles("width: 4px; cursor: col-resize;") for r in range(19): row = table.add_row() for c in range(10): col = table.add_cell() col.set_attr('col_idx', str(c)) col.set_attr('SPT_ACCEPT_DROP', 'TableExampleSwitchContents') col.add_class("SPT_DO_DRAG cell_left") col.add_styles("cursor: pointer;") col.add("(%s,%s)" % (r, c)) if (c % 2) == 0: SmartMenu.assign_as_local_activator(col, "DOG") else: SmartMenu.assign_as_local_activator(col, "CAT") resize = table.add_cell() resize.set_attr('col_idx', str(c + 1)) resize.add_class("SPT_DO_RESIZE cell_right") resize.add_styles("width: 6px; cursor: col-resize;") div.add(table) return div