def _get_inner_div(self): '''get the inner div for the process dialog''' inner_div = FloatDivWdg() inner_div.add_style("padding: 5px") inner_div.add_style('height: 260px') inner_div.add_color("background", "background") inner_div.add_color("color", "color") return inner_div
def _get_inner_div(my): '''get the inner div for the process dialog''' inner_div = FloatDivWdg() inner_div.add_style("padding: 5px") inner_div.add_style('height: 260px') inner_div.add_color("background", "background") inner_div.add_color("color", "color") return inner_div
def get_display(my): assert my.load_script widget = DivWdg() widget.add_style('float', 'right') load_button = TextOptionBtnWdg(label=' Load ', size='medium') load_button.get_top_el().add_style('float', 'left') load_button.get_top_el().set_id(my.LOAD_BUTTON_ID) load_button.add_behavior( {'type': "click_up", "cbjs_action": "setTimeout(function() {%s}, 200) "% my.load_script }) widget.add(load_button) arrow_button = load_button.get_option_widget() #widget.add(arrow_button) suffix = "ASSET_LOADER_FUNCTIONS" menus_in = [ my.smart_menu_data ] SmartMenu.add_smart_menu_set( arrow_button, menus_in) SmartMenu.assign_as_local_activator(arrow_button, None, True) #SmartMenu.attach_smart_context_menu( load_button, menus_in, False ) x_div = FloatDivWdg("x") x_div.add_color('color','color') x_div.add_style('margin-right: 6px') widget.add(x_div) multiplier = TextWdg() multiplier.set_id("load_multiplier") multiplier.set_option("size", "1.5") multiplier.add_style("font-size: 0.8em") multiplier.add_style("float: left") multiplier.add_class("load_multiplier") widget.add( multiplier ) return widget
def get_display(my): #content.add_event("oncontextmenu", "spt.side_bar.manage_context_menu_action_cbk(); return false") context_menu = DivWdg() context_menu.add_class('spt_menu_top') context_menu.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.finger_menu = {}; spt.finger_menu.timeout_id = -1; ''' }) context_menu.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' if (spt.finger_menu.timeout_id != -1) { clearTimeout(spt.finger_menu.timeout_id); spt.finger_menu.timeout_id = -1; } ''' }) #context_menu.set_box_shadow(color='#fff') # this may not be needed as it is set in JS context_menu.add_style("z-index: 200") # set up what happens when the mouse leaves the actual menu my._set_menu_out(context_menu) width = my.kwargs.get('width') height = my.kwargs.get('height') if not height: height = 20 if not width: width = 35 font_size = my.kwargs.get('font_size') if not font_size: font_size = 'smaller' force = my.kwargs.get("force") if my.mode == 'horizontal': div = DivWdg(css='spt_finger_menu') if force: div.add_attr("spt_finger_force", force) div.add_style("border-color: #aaa") div.add_style("border-style: solid") if force == "left": div.add_style("border-width: 1px 0px 1px 1px") div.add_style("border-radius: 12px 0px 0px 12px") else: div.add_style("border-width: 1px 1px 1px 0px") div.add_style("border-radius: 0px 12px 12px 0px") div.set_box_shadow(value="0px 0px 2px 1px") #div.add_style("z-index: 1000") total_width = width * len(my.items) + 15 div.add_style('width', total_width) div.add_styles('height: %spx; padding: 2px;' % height) context_menu.add(div) div.add_color('background', 'background', -10) palette = div.get_palette() sb_title_bg = palette.color('side_bar_title') bg_color = div.get_color('background', -10) color = div.get_color('color') for item in my.items: mouse_enter_bvr = { 'type': 'mouseenter', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': 'white'})''' % sb_title_bg } mouse_leave_bvr = { 'type': 'mouseleave', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': '%s'})''' % (bg_color, color) } menu_item = FloatDivWdg(css='unselectable hand') menu_item.add_color('background', 'background', -10) menu_item.add(item.get_option('label')) menu_item.add_behavior(mouse_enter_bvr) menu_item.add_behavior(mouse_leave_bvr) # add the passed-in bvr bvr = item.get_option('bvr_cb') menu_item.add_behavior(bvr) menu_item.add_styles( 'margin: 0px 0 0 0; padding: 2px 0 2px 0; text-align: center; font-size: %s; width: %s; height: %spx' % (font_size, width, height - 4)) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);''' }) div.add(menu_item) else: # this width only matters in vertical mode context_menu.add_style("width: %s" % width) menu_table = Table() menu_table.add_styles( "text-align: left; text-indent: 4px; border-collapse: collapse; cell-padding: 8px; border-radius: 32px;" ) context_menu.add(menu_table) my._add_spacer_row(menu_table, 3, width) for widget in my.widgets: tbody = menu_table.add_tbody() tbody.add_style("display", "table-row-group") tr = menu_table.add_row() tr.add_looks("smenu") #tr.add_class( "SPT_SMENU_ENTRY" ) hover_bvr = {'type': 'hover', 'add_looks': 'smenu_hilite'} #'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );', #'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' } tr.add_behavior(hover_bvr) menu_item = menu_table.add_cell() font_size = '4px' menu_item.add_styles( 'padding: 0px 0 0 6px; font-size: %s; width: %s; height: 16px' % (font_size, width)) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);''' }) menu_item.add(widget) my._add_spacer_row(menu_table, 3, width) return context_menu
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(my): #content.add_event("oncontextmenu", "spt.side_bar.manage_context_menu_action_cbk(); return false") context_menu = DivWdg() context_menu.add_class('spt_menu_top') context_menu.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.finger_menu = {}; spt.finger_menu.timeout_id = -1; ''' } ) context_menu.add_behavior( { 'type': 'mouseover', 'cbjs_action': ''' if (spt.finger_menu.timeout_id != -1) { clearTimeout(spt.finger_menu.timeout_id); spt.finger_menu.timeout_id = -1; } ''' } ) #context_menu.set_box_shadow(color='#fff') # this may not be needed as it is set in JS context_menu.add_style("z-index: 200") # set up what happens when the mouse leaves the actual menu my._set_menu_out(context_menu) width = my.kwargs.get('width') height = my.kwargs.get('height') if not height: height = 20 if not width: width = 35 font_size = my.kwargs.get('font_size') if not font_size: font_size = 'smaller' force = my.kwargs.get("force") if my.mode == 'horizontal': div = DivWdg(css='spt_finger_menu') if force: div.add_attr("spt_finger_force", force) div.add_style("border-color: #aaa") div.add_style("border-style: solid") if force == "left": div.add_style("border-width: 1px 0px 1px 1px") div.add_style("border-radius: 12px 0px 0px 12px") else: div.add_style("border-width: 1px 1px 1px 0px") div.add_style("border-radius: 0px 12px 12px 0px") div.set_box_shadow(value="0px 0px 2px 1px") #div.add_style("z-index: 1000") total_width = width * len(my.items) + 15 div.add_style('width', total_width) div.add_styles('height: %spx; padding: 2px;' %height) context_menu.add(div) div.add_color('background','background', -10) palette = div.get_palette() sb_title_bg = palette.color('side_bar_title') bg_color = div.get_color('background', -10) color = div.get_color('color') for item in my.items: mouse_enter_bvr = {'type':'mouseenter', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': 'white'})''' %sb_title_bg} mouse_leave_bvr = {'type':'mouseleave', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': '%s'})''' %(bg_color, color)} menu_item = FloatDivWdg(css='unselectable hand') menu_item.add_color('background','background', -10) menu_item.add(item.get_option('label')) menu_item.add_behavior( mouse_enter_bvr ) menu_item.add_behavior( mouse_leave_bvr ) # add the passed-in bvr bvr = item.get_option('bvr_cb') menu_item.add_behavior(bvr ) menu_item.add_styles('margin: 0px 0 0 0; padding: 2px 0 2px 0; text-align: center; font-size: %s; width: %s; height: %spx'%(font_size, width, height-4)) menu_item.add_behavior({'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''}) div.add(menu_item) else: # this width only matters in vertical mode context_menu.add_style("width: %s" %width) menu_table = Table() menu_table.add_styles( "text-align: left; text-indent: 4px; border-collapse: collapse; cell-padding: 8px; border-radius: 32px;" ) context_menu.add(menu_table) my._add_spacer_row(menu_table, 3, width) for widget in my.widgets: tbody = menu_table.add_tbody() tbody.add_style("display","table-row-group") tr = menu_table.add_row() tr.add_looks( "smenu" ) #tr.add_class( "SPT_SMENU_ENTRY" ) hover_bvr = {'type':'hover', 'add_looks': 'smenu_hilite'} #'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );', #'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' } tr.add_behavior( hover_bvr ) menu_item = menu_table.add_cell() font_size = '4px' menu_item.add_styles('padding: 0px 0 0 6px; font-size: %s; width: %s; height: 16px'%(font_size, width)) menu_item.add_behavior({'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''}) menu_item.add(widget) my._add_spacer_row(menu_table, 3, width) return context_menu
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