def get_display(my): sobject = my.get_current_sobject() widget_class = my.get_option("class") if widget_class == '': raise WidgetException("No widget class defined") url = WebContainer.get_web().get_widget_url() url.set_option("widget", widget_class) url.set_option("search_key", sobject.get_search_key()) ref = url.get_url() iframe = Container.get("iframe") iframe.set_width(90) action = iframe.get_on_script(ref) info_type = my.get_option("info_type") button = IconButtonWdg("%s info" % info_type, IconWdg.INFO) button.add_event("onclick", "%s" % (action)) button.add_style("margin: 3px 5px") return button
def get_display(my): sobject = my.get_current_sobject() widget_class = my.get_option("class") if widget_class == '': raise WidgetException("No widget class defined") url = WebContainer.get_web().get_widget_url() url.set_option("widget", widget_class) url.set_option("search_key", sobject.get_search_key()) ref = url.get_url() iframe = Container.get("iframe") iframe.set_width(90) action = iframe.get_on_script(ref) info_type = my.get_option("info_type") button = IconButtonWdg("%s info" % info_type, IconWdg.INFO) button.add_event("onclick", "%s" % (action) ) button.add_style("margin: 3px 5px") return button
def init(my): my.name = "iframe%s" % (my.generate_unique_id()) my.img_span_name = '%s_loading' %my.name my.iframe = HtmlElement.iframe() my.iframe.set_id(my.name) my.iframe.set_attr('name',my.name) # To adjust the real-time size of the overlay box, do it in get_on_script my.overlay = OverlayWdg(name='%s_shadowbox'%my.name, \ width=my.width * 1.0, display=False, iframe_name=my.name ) my.overlay.add(my.iframe) my.shadowbox = my.overlay.get_shadow_box() tall_control = IconButtonWdg(name='taller', icon='/context/icons/common/dn_button.png') tall_control.add_style("float: right") tall_control.add_event("onclick", my.get_taller_script(my.name, my.shadowbox.name) ) short_control = IconButtonWdg(name='shorter', icon='/context/icons/common/up_button.png') short_control.add_style("float: right") short_control.add_style("padding-bottom: 4px") short_control.add_event("onclick", my.get_shorter_script(my.name, my.shadowbox.name) ) control = DivWdg() control.add_style('margin-top: -30px') control.add(short_control) control.add(tall_control) if not WebContainer.get_web().is_IE(): my.shadowbox.set_control(control) my.overlay.add(my._get_loading_span()) my.add(my.overlay)
def init(self): self.name = "iframe%s" % (self.generate_unique_id()) self.img_span_name = '%s_loading' % self.name self.iframe = HtmlElement.iframe() self.iframe.set_id(self.name) self.iframe.set_attr('name', self.name) # To adjust the real-time size of the overlay box, do it in get_on_script self.overlay = OverlayWdg(name='%s_shadowbox'%self.name, \ width=self.width * 1.0, display=False, iframe_name=self.name ) self.overlay.add(self.iframe) self.shadowbox = self.overlay.get_shadow_box() tall_control = IconButtonWdg( name='taller', icon='/context/icons/common/dn_button.png') tall_control.add_style("float: right") tall_control.add_event( "onclick", self.get_taller_script(self.name, self.shadowbox.name)) short_control = IconButtonWdg( name='shorter', icon='/context/icons/common/up_button.png') short_control.add_style("float: right") short_control.add_style("padding-bottom: 4px") short_control.add_event( "onclick", self.get_shorter_script(self.name, self.shadowbox.name)) control = DivWdg() control.add_style('margin-top: -30px') control.add(short_control) control.add(tall_control) if not WebContainer.get_web().is_IE(): self.shadowbox.set_control(control) self.overlay.add(self._get_loading_span()) self.add(self.overlay)
def get_display(my): web = WebContainer.get_web() widget = DivWdg() widget.add_class("spt_search_limit_top") #widget.add_style("border", "solid 1px blue") widget.add_color("background", "background") widget.add_color("color", "color") widget.add_style("padding: 5px") hidden = HiddenWdg("prefix", my.prefix) widget.add(hidden) if not my.search and not my.sobjects: widget.add("No search or sobjects found") return widget # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count(no_exception=True) # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if not limit: limit = 50 my.search_limit = limit if my.refresh: prev = SpanWdg( IconButtonWdg("Prev", IconWdg.LEFT, False ) ) prev.add_style("margin-left: 8px") prev.add_style("margin-right: 6px") prev.add_style("margin-top: -2px") next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) next.add_style("margin-left: 6px") prev.add_behavior( { 'type': 'click_up', 'cbjs_action': my.refresh_script } ) next.add_behavior( { 'type': 'click_up', 'cbjs_action': my.refresh_script } ) else: # the old code pre 2.5 prev = IconButtonWdg("Prev", IconWdg.LEFT, False ) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name,"") prev.add(hidden) prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right" ) hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name,"") next.add(hidden) next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \ %(hidden_name, my.refresh_script)) showing_wdg = DivWdg() widget.add(showing_wdg) showing_wdg.add_style("padding: 10px") showing_wdg.add_style("margin: 10px") showing_wdg.add_color("background", "background", -5) showing_wdg.add_border() label_span = SpanWdg("Showing: ") showing_wdg.add(label_span) showing_wdg.add( prev ) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset+1 if not limit: # prevent error in ItemsNavigatorWdg if a search encounters query error limit = 50 my.search_limit = limit right_bound = min(my.current_offset+limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: showing_wdg.add( current_value ) else: # add a range selector using ItemsNavigatorWdg from pyasm.widget import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit) selector.select.add_behavior( { 'type': 'change', 'cbjs_action': my.refresh_script } ) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) showing_wdg.add( selector) showing_wdg.add( next ) #showing_wdg.add( " x ") showing_wdg.add(my.text) my.text.add_style("margin-top: -3px") my.text.set_attr("size", "1") my.text.add_attr("title", "Set number of items per page") widget.add("<hr/>") # set the limit set_limit_wdg = my.get_set_limit_wdg() widget.add(set_limit_wdg) from tactic.ui.widget.button_new_wdg import ActionButtonWdg button = ActionButtonWdg(title='Search') widget.add(button) button.add_style("float: right") button.add_style("margin-top: 8px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var select = top.getElement(".spt_search_limit_select"); var value = select.value; if (value == 'Custom') { custom = top.getElement(".spt_search_limit_custom_text"); value = custom.value; } if (value == '') { value = 20; } var text = top.getElement(".spt_search_limit_text"); text.value = value; spt.dg_table.search_cbk({}, bvr) ''' } ) offset_wdg = HiddenWdg("%s_last_search_offset" %my.label) offset_wdg.set_value(my.current_offset) widget.add(offset_wdg) widget.add("<br clear='all'/>") return widget
def get_display(my): web = WebContainer.get_web() widget = DivWdg() widget.add_class("spt_search_limit_top") #widget.add_style("border", "solid 1px blue") widget.add_color("background", "background") widget.add_color("color", "color") widget.add_style("padding: 5px") hidden = HiddenWdg("prefix", my.prefix) widget.add(hidden) if not my.search and not my.sobjects: widget.add("No search or sobjects found") return widget # my.count should have been set in alter_search() # which can be called explicitly thru this instance, my. if not my.count: my.count = my.search.get_count(no_exception=True) # if my.sobjects exist thru inheriting from parent widgets # or explicitly set, (this is not mandatory though) if my.sobjects and len(my.sobjects) < my.search_limit: limit = len(my.sobjects) elif my.search and my.count < my.search_limit: # this is only true if the total result of the search is # less than the limit and so this wdg will not display limit = my.count else: limit = my.search_limit if not limit: limit = 50 my.search_limit = limit if my.refresh: prev = SpanWdg(IconButtonWdg("Prev", IconWdg.LEFT, False)) prev.add_style("margin-left: 8px") prev.add_style("margin-right: 6px") prev.add_style("margin-top: -2px") next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right") next.add_style("margin-left: 6px") prev.add_behavior({ 'type': 'click_up', 'cbjs_action': my.refresh_script }) next.add_behavior({ 'type': 'click_up', 'cbjs_action': my.refresh_script }) else: # the old code pre 2.5 prev = IconButtonWdg("Prev", IconWdg.LEFT, False) hidden_name = my.prev_hidden_name hidden = HiddenWdg(hidden_name, "") prev.add(hidden) prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\ %(hidden_name, my.refresh_script)) next = IconButtonWdg("Next", IconWdg.RIGHT, False, icon_pos="right") hidden_name = my.next_hidden_name hidden = HiddenWdg(hidden_name, "") next.add(hidden) next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \ %(hidden_name, my.refresh_script)) showing_wdg = DivWdg() widget.add(showing_wdg) showing_wdg.add_style("padding: 10px") showing_wdg.add_style("margin: 10px") showing_wdg.add_color("background", "background", -5) showing_wdg.add_border() label_span = SpanWdg("Showing: ") showing_wdg.add(label_span) showing_wdg.add(prev) # this min calculation is used so that if my.sobjects is not set # above for the calculation of the limit, which will make the last # set of range numbers too big left_bound = my.current_offset + 1 if not limit: # prevent error in ItemsNavigatorWdg if a search encounters query error limit = 50 my.search_limit = limit right_bound = min(my.current_offset + limit, my.count) if left_bound > right_bound: left_bound = 1 current_value = "%d - %d" % (left_bound, right_bound) if my.style == my.SIMPLE: showing_wdg.add(current_value) else: # add a range selector using ItemsNavigatorWdg from pyasm.widget import ItemsNavigatorWdg selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit) selector.select.add_behavior({ 'type': 'change', 'cbjs_action': my.refresh_script }) selector.set_style(my.style) selector.set_value(current_value) selector.set_display_label(False) showing_wdg.add(selector) showing_wdg.add(next) #showing_wdg.add( " x ") showing_wdg.add(my.text) my.text.add_style("margin-top: -3px") my.text.set_attr("size", "1") my.text.add_attr("title", "Set number of items per page") widget.add("<hr/>") # set the limit set_limit_wdg = my.get_set_limit_wdg() widget.add(set_limit_wdg) from tactic.ui.widget.button_new_wdg import ActionButtonWdg button = ActionButtonWdg(title='Search') widget.add(button) button.add_style("float: right") button.add_style("margin-top: 8px") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_search_limit_top"); var select = top.getElement(".spt_search_limit_select"); var value = select.value; if (value == 'Custom') { custom = top.getElement(".spt_search_limit_custom_text"); value = custom.value; } if (value == '') { value = 20; } var text = top.getElement(".spt_search_limit_text"); text.value = value; spt.dg_table.search_cbk({}, bvr) ''' }) offset_wdg = HiddenWdg("%s_last_search_offset" % my.label) offset_wdg.set_value(my.current_offset) widget.add(offset_wdg) widget.add("<br clear='all'/>") return widget
def get_preview_wdg(self): widget = Widget() web = WebContainer.get_web() csv_parser = CsvParser(self.file_path) csv_parser.parse() csv_titles = csv_parser.get_titles() csv_data = csv_parser.get_data() ajax = AjaxCmd() ajax.set_option("search_type", self.search_type) ajax.set_option("file_path", self.file_path) ajax.add_element_name("has_title") event = WebContainer.get_event_container() caller = event.get_event_caller(SiteMenuWdg.EVENT_ID) div = ajax.generate_div() div.set_post_ajax_script(caller) widget.add(div) columns = [] num_columns = len(csv_titles) ajax.set_option("num_columns", num_columns) for i in range(0, num_columns): column = web.get_form_value("column_%s" % i) if column: column = csv_titles[i] else: column = web.get_form_value("column_new_%s" % i) columns.append(column) ajax.add_element_name("column_%s" % i) ajax.add_element_name("new_column_%s" % i) ajax.register_cmd("pyasm.command.csv_import_cmd.CsvImportCmd") import_button = IconButtonWdg("Import", IconWdg.REFRESH, True) import_button.add_event("onclick", ajax.get_on_script(show_progress=False)) import_button.add_style("float: right") widget.add(import_button) preview_submit = IconSubmitWdg("Preview", IconWdg.REFRESH, True) preview_submit.add_style("float: right") widget.add(preview_submit) sobject_title = self.search_type_obj.get_title() widget.add("<p>4. Import</p>") widget.add(HtmlElement.br()) widget.add( "<p>The following table will be imported into %s (Showing Max: 100)</p>" % sobject_title) table = Table(css="table") table.add_style("width: 100%") table.add_row() for i, title in enumerate(columns): if not title: title = "<b style='color:red'>*</b>" table.add_header(title) for i, row in enumerate(csv_data): if i > 100: break table.add_row() for j, cell in enumerate(row): table.add_cell(cell) widget.add(table) return widget
def get_buttons_wdg(my): buttons_div = DivWdg() buttons_div.add_style("margin-left: 20px") buttons_div.add_style("margin-right: 20px") # add brush size text_note_wdg = DivWdg() text_note_wdg.add("<b>Text Note</b>") buttons_div.add(text_note_wdg) text_note = TextAreaWdg("spt_text_note") text_note.add_style("width: 400px") text_note.add_class("spt_text_note") buttons_div.add(text_note) from pyasm.widget import IconButtonWdg, IconWdg save_button = IconButtonWdg("Export", IconWdg.SAVE) save_button.add_style("float: right") buttons_div.add(save_button) script = ''' try { function getFlashMovie(movieName) { var isIE = navigator.appName.indexOf("Microsoft") != -1; return (isIE) ? window[movieName] : document[movieName]; } spt.app_busy.show("Exporting Visual Note", " ") var data = getFlashMovie("visual_notes_wdg").visual_notes_export(); var applet = spt.Applet.get(); var server = TacticServerStub.get(); //server.start(); var search_key = bvr.kwargs.search_key; var txt_path = "c:/sthpw/sandbox/temp/visual_notes/visual_notes_temp.txt" var jpg_path = "c:/sthpw/sandbox/temp/visual_notes/visual_notes_temp.jpg" applet.create_file(txt_path, data); applet.decodeFileToFile(txt_path, jpg_path); var top_el = bvr.src_el.getParent(".spt_visual_notes_top"); var context = bvr.kwargs.context; var snapshot = server.simple_checkin(search_key, context, jpg_path); //var note_context = context + "|note"; var note_context = context; var note = top_el.getElement(".spt_text_note").value; var note_sobj = server.insert("sthpw/note", { note: note, context: note_context}, {parent_key: search_key} ); server.connect_sobjects( snapshot, note_sobj); //server.finish("Visual Notes"); spt.app_busy.hide(); alert("Visual note added for [" + context + "]"); } catch(err) { spt.app_busy.hide(); alert(err); } ''' save_button.add_behavior( { 'type': 'click_up', 'cbjs_action': script, 'kwargs': { 'search_key': my.search_key, 'context': my.note_context } }) return buttons_div
def get_preview_wdg(my): widget = Widget() web = WebContainer.get_web() csv_parser = CsvParser(my.file_path) csv_parser.parse() csv_titles = csv_parser.get_titles() csv_data = csv_parser.get_data() ajax = AjaxCmd() ajax.set_option("search_type", my.search_type) ajax.set_option("file_path", my.file_path) ajax.add_element_name("has_title") event = WebContainer.get_event_container() caller = event.get_event_caller(SiteMenuWdg.EVENT_ID) div = ajax.generate_div() div.set_post_ajax_script(caller) widget.add(div) columns = [] num_columns = len(csv_titles) ajax.set_option("num_columns", num_columns) for i in range(0, num_columns): column = web.get_form_value("column_%s" % i) if column: column = csv_titles[i] else: column = web.get_form_value("column_new_%s" % i) columns.append(column) ajax.add_element_name("column_%s" % i) ajax.add_element_name("new_column_%s" % i) ajax.register_cmd("pyasm.command.csv_import_cmd.CsvImportCmd") import_button = IconButtonWdg("Import", IconWdg.REFRESH, True) import_button.add_event("onclick", ajax.get_on_script(show_progress=False)) import_button.add_style("float: right") widget.add( import_button ) preview_submit = IconSubmitWdg("Preview", IconWdg.REFRESH, True) preview_submit.add_style("float: right") widget.add(preview_submit) sobject_title = my.search_type_obj.get_title() widget.add("<p>4. Import</p>") widget.add(HtmlElement.br()) widget.add("<p>The following table will be imported into %s (Showing Max: 100)</p>" % sobject_title) table = Table(css="table") table.add_style("width: 100%") table.add_row() for i, title in enumerate(columns): if not title: title = "<b style='color:red'>*</b>" table.add_header(title) for i, row in enumerate(csv_data): if i > 100: break table.add_row() for j, cell in enumerate(row): table.add_cell(cell) widget.add(table) return widget