diff --git a/modules/node/handler/cms_node_type_webform_manager.e b/modules/node/handler/cms_node_type_webform_manager.e index 7ee2140..984f0d5 100644 --- a/modules/node/handler/cms_node_type_webform_manager.e +++ b/modules/node/handler/cms_node_type_webform_manager.e @@ -15,9 +15,10 @@ feature -- Forms ... local ti: WSF_FORM_TEXT_INPUT fset: WSF_FORM_FIELD_SET - ta, sum: WSF_FORM_TEXTAREA + ta, sum: CMS_FORM_TEXTAREA tselect: WSF_FORM_SELECT opt: WSF_FORM_SELECT_OPTION + full_format: FULL_HTML_CONTENT_FORMAT do create ti.make ("title") ti.set_label ("Title") @@ -30,10 +31,18 @@ feature -- Forms ... f.extend_html_text ("
") + -- Select field has to be initialized before textareas are replaced, because they depend on the selection of the field + create tselect.make ("format") + tselect.set_label ("Body's format") + tselect.set_is_required (True) + + + create full_format.default_create -- Main Content create ta.make ("body") ta.set_rows (10) ta.set_cols (70) + ta.show_as_editor_if_selected (tselect, full_format.name) if a_node /= Void then ta.set_text_value (a_node.content) end @@ -45,6 +54,8 @@ feature -- Forms ... create sum.make ("summary") sum.set_rows (10) sum.set_cols (70) + -- if full_html is selected + sum.show_as_editor_if_selected (tselect, full_format.name) if a_node /= Void then sum.set_text_value (a_node.summary) end @@ -58,14 +69,12 @@ feature -- Forms ... -- Add summary fset.extend (sum) fset.extend_html_text("
") - + -- Add content (body) fset.extend (ta) fset.extend_html_text ("
") - create tselect.make ("format") - tselect.set_label ("Body's format") - tselect.set_is_required (True) + across content_type.available_formats as c loop diff --git a/src/kernel/form/cms_editor.e b/src/kernel/form/cms_editor.e new file mode 100644 index 0000000..910ec42 --- /dev/null +++ b/src/kernel/form/cms_editor.e @@ -0,0 +1,108 @@ +note + description: "Class to import a WYSIWIG editor using javascript code" + author: "Dario Bösch + do + Result := "" + end + +feature -- Javascript + + javascript_replace_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING + -- + do + -- Replaces the textarea with an editor instance. Save the instance in a variable + Result := editor_variable(a_textarea) + " = CKEDITOR.replace( '" + a_textarea.name + "' );" + end + + javascript_restore_textarea (a_textarea : WSF_FORM_TEXTAREA) : STRING + -- + do + -- Replaces the textarea with an editor instance. Save the instance in a variable + Result := "if (" + editor_variable(a_textarea) + " != undefined) " + editor_variable(a_textarea) + ".destroy();" + end + +end diff --git a/src/kernel/form/cms_form_textarea.e b/src/kernel/form/cms_form_textarea.e new file mode 100644 index 0000000..4f68343 --- /dev/null +++ b/src/kernel/form/cms_form_textarea.e @@ -0,0 +1,82 @@ +note + description: "Extends the WSF form textarea with features to add a WYSIWIG editor." + author: "Dario Bösch + do + precursor(a_name) + + -- By default we don't replace the textarea by an editor + editor := False; + end + +feature -- Access + + editor : BOOLEAN + -- True if the textarea should be replaced by the editor. Default is false. + + format_field : detachable WSF_FORM_SELECT + -- Selection field for the format on that it depends, if the editor is shown or not. + + condition_value : detachable STRING + +feature -- Editor + + show_as_editor + -- The textarea will be replaced by a wysiwyg editor + do + editor := True + end + + show_as_editor_if_selected (a_select_field : WSF_FORM_SELECT; a_value : STRING) + -- Replaces the textarea only if a_select_field has a_value (or the value gets selected) + do + editor := True + format_field := a_select_field + condition_value := a_value + end + +feature -- Conversion + + + append_item_to_html (a_theme: WSF_THEME; a_html: STRING_8) + do + -- Add javascript to replace textarea with editor + precursor(a_theme, a_html) + if editor then + a_html.append (load_assets) + a_html.append ("") + end + end + +feature -- Javascript Output + + javascript_show_editor_on_full_html_select : STRING = "" + +end