def get_display(my): top = my.top view = my.kwargs.get("view") top.add_class("spt_help_edit_content") search = Search("config/widget_config") search.add_filter("category", "HelpWdg") search.add_filter("view", view) sobject = search.get_sobject() if not sobject: value = "" search_key = "" else: xml_value = sobject.get_xml_value("config") value = xml_value.get_value("config/%s/html/div" % (view) ) search_key = sobject.get_search_key() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>View: %s</b>" % view) title_wdg.add_style("font-style: bold") title_wdg.add_style("padding: 5px") title_wdg.add_gradient("background", "background", 0, -10) hidden = HiddenWdg("view") top.add(hidden) hidden.set_value(view) text = TextAreaWdg("content") text_id = text.set_unique_id() text.set_value(value) from tactic.ui.widget import ActionButtonWdg if sobject: delete_button = ActionButtonWdg(title="Delete") top.add(delete_button) delete_button.add_style("float: right") delete_button.add_style("margin-top: -3px") delete_button.add_behavior( { 'type': 'click_up', 'search_key': search_key, 'cbjs_action': ''' if (!confirm("Are you sure you wish to delete this help page?")) { return; } var server = TacticServerStub.get(); server.delete_sobject(bvr.search_key); var top = bvr.src_el.getParent(".spt_help_edit_top"); spt.panel.refresh(top); ''' }) test_button = ActionButtonWdg(title="Preview") top.add(test_button) test_button.add_style("float: right") test_button.add_style("margin-top: -3px") test_button.add_behavior( { 'type': 'click_up', 'text_id': text_id, 'cbjs_action': ''' var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()"; var text_value = eval( cmd ); bvr.options = {}; bvr.options.html = text_value; spt.named_events.fire_event("show_help", bvr) ''' }) save_button = ActionButtonWdg(title="Save") top.add(save_button) save_button.add_style("float: right") save_button.add_style("margin-top: -3px") top.add("<br/>") save_button.add_behavior( { 'type': 'click_up', 'text_id': text_id, 'cbjs_action': ''' spt.app_busy.show("Saving Help", " ") var top = bvr.src_el.getParent(".spt_help_edit_content"); var values = spt.api.Utility.get_input_values(top, null, false); var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()"; var text_value = eval( cmd ); values.content = text_value; var command = "tactic.ui.app.HelpEditCbk"; var kwargs = values; var server = TacticServerStub.get(); server.execute_cmd(command, kwargs); setTimeout("spt.app_busy.hide()", 200) ''' } ) #top.add("Style: ") #select = SelectWdg("style") #top.add(select) #select.set_option("values", "text|html") top.add("<br/>") top.add(text) text.set_value(value) text.add_style("width: 100%") text.add_style("height: 100%") text.add_style("min-height: 500px") text.add_style("display: none") text.add_behavior( { 'type': 'load', 'color': text.get_color("background", -10), 'text_id': text_id, 'cbjs_action': ''' var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); setTimeout( function() { CKEDITOR.on( 'instanceReady', function( ev ) { ev.editor.dataProcessor.writer.indentationChars = ' '; }); var config = { toolbar: 'Full', uiColor: bvr.color, height: '500px' }; config.toolbar_Full = [ ['Source'], ['Cut','Copy','Paste'], ['Undo','Redo','-','Find','Replace'], ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], '/', ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['HorizontalRule','SpecialChar'], ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks'] ]; CKEDITOR.replace(bvr.text_id, config ); bvr.src_el.setStyle("display", ""); }, 500); ''' } ) return top
class CKEditorWdg(BaseRefreshWdg): def init(self): name = self.kwargs.get("name") assert(name) self.text = TextAreaWdg(name) self.text_id = self.kwargs.get("text_id") if not self.text_id: self.text_id = self.text.set_unique_id() def get_display(self): top = self.top top.add_style("min-width: 600px") top.add_class("spt_ckeditor_top") top.add_attr("text_id", self.text_id) top.add(self.text) value = self.kwargs.get("value") if value: self.text.set_value(value) self.text.add_style("width: 100%") self.text.add_style("height: 100%") self.text.add_style("min-height: 500px") self.text.add_style("display: none") self.text.set_id(self.text_id) self.text.add_behavior( { 'type': 'load', 'color': self.text.get_color("background", -10), 'text_id': self.text_id, 'cbjs_action': ''' /* var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); */ var init = function() { CKEDITOR.on( 'instanceReady', function( ev ) { ev.editor.dataProcessor.writer.indentationChars = ' '; }); var config = { toolbar: 'Full', uiColor: bvr.color, height: '800px' }; /* config.toolbar_Full = [ ['Source'], //['Cut','Copy','Paste'], ['Undo','Redo','-','Find','Replace'], ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], '/', ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['HorizontalRule','SpecialChar'], ['Styles','Format','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks'] ]; */ config.toolbar_Full = [ { name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] }, { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] }, { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, '/', { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv', '-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] }, '/', { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] }, { name: 'colors', items : [ 'TextColor','BGColor' ] }, { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } ]; config.entities = false; config.basicEntities = false; config.extraAllowedContent = 'iframe[*]'; config.allowedContent = true; config.enterMode = CKEDITOR.ENTER_BR; var instance = CKEDITOR.instances[ bvr.text_id ]; if (instance) instance.destroy(); CKEDITOR.replace(bvr.text_id, config ); //var html = ''; //editor = CKEDITOR.appendTo( bvr.text_id, config, html ); bvr.src_el.setStyle("display", "none"); spt.ckeditor = {}; spt.ckeditor.get_value = function(text_id) { var text_value = CKEDITOR.instances[ text_id ].getData(); return text_value; } spt.ckeditor.set_value = function(text_id, data) { CKEDITOR.instances[ text_id ].setData(data); } } spt.dom.load_js(['ckeditor/ckeditor.js'], init); ''' } ) return top
def get_display(my): top = my.top view = my.kwargs.get("view") top.add_class("spt_help_edit_content") search = Search("config/widget_config") search.add_filter("category", "HelpWdg") search.add_filter("view", view) sobject = search.get_sobject() if not sobject: value = "" search_key = "" else: xml_value = sobject.get_xml_value("config") value = xml_value.get_value("config/%s/html/div" % (view)) search_key = sobject.get_search_key() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>View: %s</b>" % view) title_wdg.add_style("font-style: bold") title_wdg.add_style("padding: 5px") title_wdg.add_gradient("background", "background", 0, -10) hidden = HiddenWdg("view") top.add(hidden) hidden.set_value(view) text = TextAreaWdg("content") text_id = text.set_unique_id() text.set_value(value) from tactic.ui.widget import ActionButtonWdg if sobject: delete_button = ActionButtonWdg(title="Delete") top.add(delete_button) delete_button.add_style("float: right") delete_button.add_style("margin-top: -3px") delete_button.add_behavior({ 'type': 'click_up', 'search_key': search_key, 'cbjs_action': ''' if (!confirm("Are you sure you wish to delete this help page?")) { return; } var server = TacticServerStub.get(); server.delete_sobject(bvr.search_key); var top = bvr.src_el.getParent(".spt_help_edit_top"); spt.panel.refresh(top); ''' }) test_button = ActionButtonWdg(title="Preview") top.add(test_button) test_button.add_style("float: right") test_button.add_style("margin-top: -3px") test_button.add_behavior({ 'type': 'click_up', 'text_id': text_id, 'cbjs_action': ''' var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()"; var text_value = eval( cmd ); bvr.options = {}; bvr.options.html = text_value; spt.named_events.fire_event("show_help", bvr) ''' }) save_button = ActionButtonWdg(title="Save") top.add(save_button) save_button.add_style("float: right") save_button.add_style("margin-top: -3px") top.add("<br/>") save_button.add_behavior({ 'type': 'click_up', 'text_id': text_id, 'cbjs_action': ''' spt.app_busy.show("Saving Help", " ") var top = bvr.src_el.getParent(".spt_help_edit_content"); var values = spt.api.Utility.get_input_values(top, null, false); var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()"; var text_value = eval( cmd ); values.content = text_value; var command = "tactic.ui.app.HelpEditCbk"; var kwargs = values; var server = TacticServerStub.get(); server.execute_cmd(command, kwargs); setTimeout("spt.app_busy.hide()", 200) ''' }) #top.add("Style: ") #select = SelectWdg("style") #top.add(select) #select.set_option("values", "text|html") top.add("<br/>") top.add(text) text.set_value(value) text.add_style("width: 100%") text.add_style("height: 100%") text.add_style("min-height: 500px") text.add_style("display: none") text.add_behavior({ 'type': 'load', 'color': text.get_color("background", -10), 'text_id': text_id, 'cbjs_action': ''' var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); setTimeout( function() { CKEDITOR.on( 'instanceReady', function( ev ) { ev.editor.dataProcessor.writer.indentationChars = ' '; }); var config = { toolbar: 'Full', uiColor: bvr.color, height: '500px' }; config.toolbar_Full = [ ['Source'], ['Cut','Copy','Paste'], ['Undo','Redo','-','Find','Replace'], ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], '/', ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['HorizontalRule','SpecialChar'], ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks'] ]; CKEDITOR.replace(bvr.text_id, config ); bvr.src_el.setStyle("display", ""); }, 500); ''' }) return top
class CKEditorWdg(BaseRefreshWdg): def init(self): name = self.kwargs.get("name") assert (name) self.text = TextAreaWdg(name) self.text_id = self.kwargs.get("text_id") if not self.text_id: self.text_id = self.text.set_unique_id() def get_display(self): top = self.top top.add_style("min-width: 600px") top.add_class("spt_ckeditor_top") top.add_attr("text_id", self.text_id) top.add(self.text) value = self.kwargs.get("value") if value: self.text.set_value(value) self.text.add_style("width: 100%") self.text.add_style("height: 100%") self.text.add_style("min-height: 500px") self.text.add_style("display: none") self.text.set_id(self.text_id) self.text.add_behavior({ 'type': 'load', 'color': self.text.get_color("background", -10), 'text_id': self.text_id, 'cbjs_action': ''' /* var js_file = "ckeditor/ckeditor.js"; var url = "/context/spt_js/" + js_file; var js_el = document.createElement("script"); js_el.setAttribute("type", "text/javascript"); js_el.setAttribute("src", url); var head = document.getElementsByTagName("head")[0]; head.appendChild(js_el); */ var init = function() { CKEDITOR.on( 'instanceReady', function( ev ) { ev.editor.dataProcessor.writer.indentationChars = ' '; }); var config = { toolbar: 'Full', uiColor: bvr.color, height: '800px' }; /* config.toolbar_Full = [ ['Source'], //['Cut','Copy','Paste'], ['Undo','Redo','-','Find','Replace'], ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], '/', ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['HorizontalRule','SpecialChar'], ['Styles','Format','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks'] ]; */ config.toolbar_Full = [ { name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] }, { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] }, { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, '/', { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv', '-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] }, '/', { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] }, { name: 'colors', items : [ 'TextColor','BGColor' ] }, { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } ]; config.entities = false; config.basicEntities = false; config.extraAllowedContent = 'iframe[*]'; config.allowedContent = true; config.enterMode = CKEDITOR.ENTER_BR; var instance = CKEDITOR.instances[ bvr.text_id ]; if (instance) instance.destroy(); CKEDITOR.replace(bvr.text_id, config ); //var html = ''; //editor = CKEDITOR.appendTo( bvr.text_id, config, html ); bvr.src_el.setStyle("display", "none"); spt.ckeditor = {}; spt.ckeditor.get_value = function(text_id) { var text_value = CKEDITOR.instances[ text_id ].getData(); return text_value; } spt.ckeditor.set_value = function(text_id, data) { CKEDITOR.instances[ text_id ].setData(data); } } spt.dom.load_js(['ckeditor/ckeditor.js'], init); ''' }) return top