def get_related_wdg(my, aliases): div = DivWdg() div.add("<b>Related links</b>:  ") div.add_style("margin-top: 5px") div.add_style("margin-bottom: 5px") div.add_style("margin-left: 10px") titles = [Common.get_display_title(x.replace("-"," ")) for x in aliases] for alias, title in zip(aliases, titles): link_div = SpanWdg() div.add(link_div) link_div.add_color("background", "background") link_div.add(title) link_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("%s"); ''' % alias } ) link_div.add_class("spt_link") link_div.add_class("hand") return div
def get_related_wdg(my, aliases): div = DivWdg() div.add("<b>Related links</b>:  ") div.add_style("margin-top: 5px") div.add_style("margin-bottom: 5px") div.add_style("margin-left: 10px") titles = [ Common.get_display_title(x.replace("-", " ")) for x in aliases ] for alias, title in zip(aliases, titles): link_div = SpanWdg() div.add(link_div) link_div.add_color("background", "background") link_div.add(title) link_div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("%s"); ''' % alias }) link_div.add_class("spt_link") link_div.add_class("hand") return div
def set_text_link(self, widget, div, image_link): '''override how the text link is drawn''' div.add_style('float', 'left') div.add_style('margin-left', '10px') filename = os.path.basename(image_link) if len(filename) > 40: filename = "%s..." % (filename[0:40]) span = SpanWdg(css='med') #href = HtmlElement.href(filename, image_link) href = SpanWdg(filename) href.add_color("color", "color") span.add(href) widget.add(span) span.add_tip('Right-click and choose [Save Link As..] to save to disk.')
target = xml.get_attribute(node, "target") if target: target = xml.set_attribute(node, "href", "/doc/%s" % link_rel_path) continue # get a unique id for the node unique_id = my.top.generate_unique_id(base='replace') xml.set_attribute(node, "id", unique_id) div = SpanWdg() elements.append(div) div.add_class("spt_replace_element") div.add_attr("spt_replace_id", unique_id) div.add_class("hand") div.add_class("spt_link") div.add_color("background", "background") text = xml.get_node_value(node) div.add(text) div.add_behavior( { 'type': 'click_up', 'rel_path': link_rel_path, 'cbjs_action': ''' spt.help.set_top(); spt.help.load_rel_path( bvr.rel_path ); ''' } ) # dummy div to get color div = DivWdg()
def get_viewer(my): top = DivWdg(css='spt_single_note_viewer_top') # draw checkbox options swap = SwapDisplayWdg() title = SpanWdg('context') title.add_color('color', 'color') div = DivWdg(css='spt_context_cb') div.add_color('color', 'color') SwapDisplayWdg.create_swap_title(title, swap, div, is_open=False) checkbox_name = 'split_screen' checked_process_names = [] if my.show_context: top.add(swap) top.add(title) top.add(div) #checkbox_name = 'note_context_cb' checkbox_name = my.checkbox_name cb = CheckboxWdg(checkbox_name) cb.persistence = True cb.persistence_obj = cb checked_process_names = cb.get_values() for value in my.process_names: #my.checked_process_names = web.get_form_values('process_names') cb = CheckboxWdg(checkbox_name, label=value) if value in checked_process_names: my.checked_processes.append(value) # FIXME: this is very tenous. Accessing private members to # override behavior cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.set_option('value', value) cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_single_note_viewer_top") var table_top = top.getElement('.spt_note_viewer_table'); var cbs = top.getElement('.spt_context_cb'); var values = spt.api.Utility.get_input_values(cbs); var processes = values.%s; var kwargs = { process_names: processes}; spt.input.save_selected(bvr, '%s','%s'); spt.panel.refresh(table_top, kwargs, false); ''' % (checkbox_name, checkbox_name, key) }) div.add(cb) else: web = WebContainer.get_web() checked_process_names = web.get_form_values('process_names') table_top = DivWdg(css='spt_note_viewer_table') expression = "@SOBJECT(sthpw/note['context','in','%s'])" % '|'.join( checked_process_names) table_id = 'main_table1' table = TableLayoutWdg(table_id=table_id, search_type='sthpw/note', view=my.view,\ show_row_select=True, show_insert=False, state={'parent_key': my.parent_key}, inline_search=False, show_refresh=True, expression=expression ) if my.resize: from tactic.ui.container import ResizeScrollWdg inner_wdg = ResizeScrollWdg(width='500px', height='500px', scroll_bar_size_str='thick', scroll_expansion='inside') inner_wdg.add(table) table_top.add(inner_wdg) else: table_top.add(table) my.set_as_panel(table_top) top.add(table_top) 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_display(self): config_search_type = "config/widget_config" configs = [] all_element_names = [] from tactic.ui.panel import SideBarBookmarkMenuWdg SideBarBookmarkMenuWdg.add_internal_config(configs, ['definition']) for internal_config in configs: all_element_names = internal_config.get_element_names() search = Search(config_search_type) search.add_filter("search_type", 'SideBarWdg') search.add_filter("view", 'definition') search.add_filter("login", None) config = search.get_sobject() element_names = [] if config: element_names = config.get_element_names() for name in element_names: if 'separator' in name: element_names.remove(name) all_element_names.extend(element_names) all_element_names = [str(name) for name in all_element_names] all_element_names = Common.get_unique_list(all_element_names) widget = DivWdg(css='spt_load_test_top') span = SpanWdg( 'This loads all the pages defined in the Project views in popups. It will take a few minutes.' ) widget.add(span) widget.add('<br/>') div = ActionButtonWdg(title='Run') web = WebContainer.get_web() base_url = web.get_base_url().to_string() base_url = '%s/tactic/%s' % (base_url, Project.get_project_code()) div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var element_names = eval(%s); var all_element_names = eval(%s); var top = spt.get_parent(bvr.src_el, '.spt_load_test_top'); var cb = spt.get_element(top, '.spt_input') if (cb.checked) element_list = all_element_names; else element_list = element_names for (var k=0; k < element_list.length; k++) { var name = element_list[k]; //if (k > 3) break; var url = '%s/#/link/' + name; var bvr2 = { title: name, target_id: 'TEST', options: {'link': name, 'title': name, 'path': '/Link Test/' + name }, is_popup: true}; spt.side_bar.display_link_cbk(null, bvr2); } ''' % (element_names, all_element_names, base_url) }) widget.add('<br/>') cb = CheckboxWdg('include_internal', label='include built-in pages') span = SpanWdg(cb, css='med') span.add_color('color', 'color') widget.add(span) widget.add(div) widget.add('<br/>') widget.add('<br/>') return widget
def get_display(self): config_search_type = "config/widget_config" configs = [] all_element_names = [] from tactic.ui.panel import SideBarBookmarkMenuWdg SideBarBookmarkMenuWdg.add_internal_config(configs, ['definition']) for internal_config in configs: all_element_names = internal_config.get_element_names() search = Search(config_search_type) search.add_filter("search_type", 'SideBarWdg') search.add_filter("view", 'definition') search.add_filter("login", None) config = search.get_sobject() element_names = [] if config: element_names = config.get_element_names() for name in element_names: if 'separator' in name: element_names.remove(name) all_element_names.extend(element_names) all_element_names = [str(name) for name in all_element_names] all_element_names = Common.get_unique_list(all_element_names) widget = DivWdg(css='spt_load_test_top') span =SpanWdg('This loads all the pages defined in the Project views in popups. It will take a few minutes.') widget.add(span) widget.add('<br/>') div = ActionButtonWdg(title='Run') web = WebContainer.get_web() base_url = web.get_base_url().to_string() base_url = '%s/tactic/%s' %(base_url, Project.get_project_code()) div.add_behavior({'type': 'click_up', 'cbjs_action': ''' var element_names = eval(%s); var all_element_names = eval(%s); var top = spt.get_parent(bvr.src_el, '.spt_load_test_top'); var cb = spt.get_element(top, '.spt_input') if (cb.checked) element_list = all_element_names; else element_list = element_names for (var k=0; k < element_list.length; k++) { var name = element_list[k]; //if (k > 3) break; var url = '%s/#/link/' + name; var bvr2 = { title: name, target_id: 'TEST', options: {'link': name, 'title': name, 'path': '/Link Test/' + name }, is_popup: true}; spt.side_bar.display_link_cbk(null, bvr2); } ''' %(element_names, all_element_names, base_url)}) widget.add('<br/>') cb = CheckboxWdg('include_internal', label='include built-in pages') span = SpanWdg(cb, css='med') span.add_color('color','color') widget.add(span) widget.add(div) widget.add('<br/>') widget.add('<br/>') return widget
def get_display(self): #WebContainer.register_cmd("pyasm.admin.UndoLogCbk") # add a time filter div = DivWdg() div.add_color('background', 'background', -10) div.add_color('color', 'color') div.add_style("padding: 15px") div.add_border() project = '' # add a project filter if self.all_namespaces_flag: span = SpanWdg("Project: ") span.add_color('color', 'color') project_select = FilterSelectWdg("project") project_select.add_empty_option(label="-- All Projects --") project_select.set_option("query", "sthpw/project|code|title") span.add(project_select) div.add(span) project = project_select.get_value() else: from pyasm.biz import Project project = Project.get_global_project_code() # add a time filter from pyasm.prod.web import DateFilterWdg select = DateFilterWdg("undo_time_filter", label="Show Transaction Log From: ") select.set_label( ["1 Hour Ago", "Today", "1 Day Ago", "1 Week Ago", "1 Month Ago"]) select.set_value(["1 Hour", "today", "1 Day", "1 Week", "1 Month"]) select.set_option("default", "1 Hour") div.add(select) time_interval = select.get_value() self.add(div) if not self.all_users_flag: user = Environment.get_user_name() else: span = SpanWdg(css="med") span.add("User: "******"user") user_select.set_option("query", "sthpw/login|login|login") user_select.add_empty_option() span.add(user_select) div.add(span) user = user_select.get_value() transaction_log = TransactionLog.get( user_name=user, \ namespace=project, time_interval=time_interval) from tactic.ui.panel import FastTableLayoutWdg, TableLayoutWdg table = FastTableLayoutWdg(search_type="sthpw/transaction_log", view="table", show_shelf='false', show_select="false") #table = TableLayoutWdg(search_type="sthpw/transaction_log", view="table", mode='simple', show_row_select="false") table.set_sobjects(transaction_log) #table.set_refresh_mode("table") self.add(table) return super(UndoLogWdg, self).get_display()
def _handle_files(self, snapshot, widget, upstream, recursive=True): web_dir = snapshot.get_web_dir() xml = snapshot.get_xml_value("snapshot") # handle files files = xml.get_nodes("snapshot/file") for file in files: file_code = Xml.get_attribute(file, "file_code") file_type = Xml.get_attribute(file, "type") file_range = Xml.get_attribute(file, "file_range") #file_range = "1-4/1" dir = snapshot.get_client_lib_dir(file_type=file_type) lib_dir = snapshot.get_lib_dir(file_type=file_type) open_button = IconButtonWdg( "Explore: %s" % dir, IconWdg.LOAD, False) if dir == lib_dir: open_button.add_behavior({'type':'click_up', 'cbjs_action': '''var applet = spt.Applet.get(); spt.alert('You are not allowed to browse directories on a web server.'); '''}) else: open_button.add_behavior({'type':'click_up', 'dir' : dir, 'cbjs_action': ''' var applet = spt.Applet.get(); var dir = bvr.dir; applet.open_explorer(dir);'''}) open_button.add_class('small') open_button.add_style('float: left') widget.add(open_button) if file_range: file_name = Xml.get_attribute(file, "name") widget.add("%s [code = %s, type = %s]" % (file_name, file_code, file_type)) widget.add(HtmlElement.br(2)) # display all of the paths file_names = FileGroup.expand_paths( file_name, FileRange.get(file_range) ) for file_name in file_names: #link = HtmlElement.href(file_name, "%s/%s" % (web_dir, file_name), target="_blank" ) link = SpanWdg(file_name) link.add_color("color", "color") widget.add(link) widget.add(HtmlElement.br()) else: thumb = DependencyThumbWdg() thumb.set_show_filename(True) thumb.set_sobject(snapshot) thumb.set_icon_size(15) thumb.set_image_link_order([file_type]) thumb.set_option('detail', 'false') widget.add(SpanWdg(thumb, css='small')) widget.add("[code = %s, type = %s]" % ( file_code, file_type)) widget.add(HtmlElement.br()) block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") nodes = xml.get_nodes("snapshot/file[@file_code='%s']/ref" % file_code) widget.add(HtmlElement.br(clear="all")) # handle sub refs for node in nodes: self._handle_ref_node(node, block, upstream, recursive) block.add(HtmlElement.br()) if nodes: widget.add(block) widget.add(HtmlElement.br()) files = xml.get_nodes("snapshot/unknown_ref") if files: widget.add(HtmlElement.b("Unknown ref.")) for file in files: block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") block.add( IconWdg( "Unknown", IconWdg.UNKNOWN) ) path = Xml.get_attribute(file, "path") block.add(path) widget.add(block)
def get_display(self): #WebContainer.register_cmd("pyasm.admin.UndoLogCbk") # add a time filter div = DivWdg() div.add_color('background','background', -10) div.add_color('color','color') div.add_style("padding: 15px") div.add_border() project = '' # add a project filter if self.all_namespaces_flag: span = SpanWdg("Project: ") span.add_color('color','color') project_select = FilterSelectWdg("project") project_select.add_empty_option(label="-- All Projects --") project_select.set_option("query", "sthpw/project|code|title") span.add(project_select) div.add(span) project = project_select.get_value() else: from pyasm.biz import Project project = Project.get_global_project_code() # add a time filter from pyasm.prod.web import DateFilterWdg select = DateFilterWdg("undo_time_filter", label="Show Transaction Log From: ") select.set_label(["1 Hour Ago", "Today", "1 Day Ago", "1 Week Ago", "1 Month Ago"]) select.set_value(["1 Hour", "today", "1 Day", "1 Week", "1 Month"]) select.set_option("default", "1 Hour") div.add(select) time_interval = select.get_value() self.add(div) if not self.all_users_flag: user = Environment.get_user_name() else: span = SpanWdg(css="med") span.add("User: "******"user") user_select.set_option("query", "sthpw/login|login|login") user_select.add_empty_option() span.add(user_select) div.add(span) user = user_select.get_value() transaction_log = TransactionLog.get( user_name=user, \ namespace=project, time_interval=time_interval) from tactic.ui.panel import FastTableLayoutWdg, TableLayoutWdg table = FastTableLayoutWdg(search_type="sthpw/transaction_log", view="table", show_shelf='false', show_select="false") #table = TableLayoutWdg(search_type="sthpw/transaction_log", view="table", mode='simple', show_row_select="false") table.set_sobjects(transaction_log) #table.set_refresh_mode("table") self.add(table) return super(UndoLogWdg, self).get_display()
if target: target = xml.set_attribute(node, "href", "/doc/%s" % link_rel_path) continue # get a unique id for the node unique_id = my.top.generate_unique_id(base='replace') xml.set_attribute(node, "id", unique_id) div = SpanWdg() elements.append(div) div.add_class("spt_replace_element") div.add_attr("spt_replace_id", unique_id) div.add_class("hand") div.add_class("spt_link") div.add_color("background", "background") text = xml.get_node_value(node) div.add(text) div.add_behavior({ 'type': 'click_up', 'rel_path': link_rel_path, 'cbjs_action': ''' spt.help.set_top(); spt.help.load_rel_path( bvr.rel_path ); ''' })
def get_viewer(self): top = DivWdg(css='spt_single_note_viewer_top') # draw checkbox options swap = SwapDisplayWdg() title = SpanWdg('context') title.add_color('color','color') div = DivWdg(css='spt_context_cb') div.add_color('color','color') SwapDisplayWdg.create_swap_title(title, swap, div, is_open=False) checkbox_name = 'split_screen' checked_process_names = [] if self.show_context: top.add(swap) top.add(title) top.add(div) #checkbox_name = 'note_context_cb' checkbox_name = self.checkbox_name cb = CheckboxWdg(checkbox_name) cb.persistence = True cb.persistence_obj = cb checked_process_names = cb.get_values() for value in self.process_names: #self.checked_process_names = web.get_form_values('process_names') cb = CheckboxWdg(checkbox_name, label=value) if value in checked_process_names: self.checked_processes.append(value) # FIXME: this is very tenous. Accessing private members to # override behavior cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.set_option('value', value) cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_single_note_viewer_top") var table_top = top.getElement('.spt_note_viewer_table'); var cbs = top.getElement('.spt_context_cb'); var values = spt.api.Utility.get_input_values(cbs); var processes = values.%s; var kwargs = { process_names: processes}; spt.input.save_selected(bvr, '%s','%s'); spt.panel.refresh(table_top, kwargs, false); ''' % (checkbox_name, checkbox_name, key) }) div.add(cb) else: web = WebContainer.get_web() checked_process_names = web.get_form_values('process_names') table_top = DivWdg(css='spt_note_viewer_table') expression = "@SOBJECT(sthpw/note['context','in','%s'])" %'|'.join(checked_process_names) table_id = 'main_table1' table = TableLayoutWdg(table_id=table_id, search_type='sthpw/note', view=self.view,\ show_row_select=True, show_insert=False, state={'parent_key': self.parent_key}, inline_search=False, show_refresh=True, expression=expression ) if self.resize: from tactic.ui.container import ResizeScrollWdg inner_wdg = ResizeScrollWdg( width='500px', height='500px', scroll_bar_size_str='thick', scroll_expansion='inside' ) inner_wdg.add(table) table_top.add(inner_wdg) else: table_top.add(table) self.set_as_panel(table_top) top.add(table_top) 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