Index: openacs-4/packages/acs-core-docs/www/tutorial-wysiwyg-editor.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/tutorial-wysiwyg-editor.adp,v diff -u -r1.4.2.4 -r1.4.2.5 --- openacs-4/packages/acs-core-docs/www/tutorial-wysiwyg-editor.adp 27 Apr 2022 16:52:20 -0000 1.4.2.4 +++ openacs-4/packages/acs-core-docs/www/tutorial-wysiwyg-editor.adp 13 Jul 2023 12:43:23 -0000 1.4.2.5 @@ -1,11 +1,11 @@ -{/doc/acs-core-docs {ACS Core Documentation}} {Enabling WYSIWYG} +{/doc/acs-core-docs/ {ACS Core Documentation}} {Enabling WYSIWYG} Enabling WYSIWYG

@@ -16,15 +16,17 @@ OpenACS docs are written by the named authors, and may be edited by OpenACS documentation staff.

Most of the forms in OpenACS are created using the form builder, see the section -called “Using Form Builder: building html forms dynamically”. -For detailed information on the API take a look here.

The following section shows how you can modify your form to +called “Using Form Builder: building html forms +dynamically”. For detailed information on the API +take a look here.

The following section shows how you can modify your form to allow WYSIWYG functionalities.

Convert your page to use ad_form (some changes but worth it)

Here an examples. From:

         template::form create my_form
         template::element create my_form my_form_id -label "The ID" -datatype integer -widget hidden
         template::element create my_form my_input_field_1 -html { size 30 } -label "Label 1" -datatype text -optional
         template::element create my_form my_input_field_2 -label "Label 2" -datatype text -help_text "Some Help" -after_html {<a name="#">Anchor</a>}
-        

To:

+        
+

To:

         ad_form -name my_form -form {
                 my_form_id:key(acs_object_id_seq)
                 {my_input_field_1:text,optional
@@ -36,17 +38,20 @@
                    {after_html
                {<a name="#">Anchor</a>}}}
         } ...
-        
+ +

Warning

You must not give your form the same name that your page has. Otherwise HTMLArea won't load.

Convert your textarea widget to a richtext widget and enable htmlarea.

The htmlarea_p-flag can be used to prevent WYSIWYG functionality. Defaults to true if left away.

From:

         {my_input_field_2:text
-        

To:

+        
+

To:

         {my_input_field_2:richtext(richtext)
                         {htmlarea_p "t"}
-        

The richtext widget presents a list with two elements: text and + +

The richtext widget presents a list with two elements: text and content type. To learn more on existing content types search in Google for "MIME-TYPES" or take a look at the cr_mime_types table.

Make sure that both values are passed as a list to your @@ -60,14 +65,16 @@ -on_request block. If you have the format stored in the database pass this as well else use "text/html":

         set my_input_field_2 [template::util::richtext::create $my_input_field_2 "text/html"]
-        

Now make sure that your SQL queries that do the data + +

Now make sure that your SQL queries that do the data manipulation retrieve the correct value. If you simply use my_input_field_2 you will store a list. Thus you need to add an -on_submit block:

         set my_input_field_2 [ template::util::richtext::get_property contents $my_input_field_2]
         set format [ template::util::richtext::get_property format $my_input_field_2] #This is optional
-        

Now the correct values for my_input_field_2 and format + +

Now the correct values for my_input_field_2 and format are passed to the -new_data and -edit_data blocks which don't need to get touched.

To make HTMLArea optional per package instance define a string @@ -79,10 +86,12 @@ ... {htmlarea_p $use_wysiwyg_p} -

The -on_request switch should set this + +

The -on_request switch should set this value for your form.

         set htmlarea_p $use_wysiwyg_p
-        

All you need now is a configuration page where the user can + +

All you need now is a configuration page where the user can change this setting. Create a configure.tcl file:

 ad_page_contract {
 
@@ -117,13 +126,15 @@
         <property name="context">\@context\@</property>
 
         <formtemplate id="categories_mode"></formtemplate>
-        

And finally reference this page from your admin page

+        
+

And finally reference this page from your admin page

         #TCL:
         set return_url [ad_conn url]
 
         #ADP:
         <a href=configure?<%=[export_vars -url {return_url}]%>>Configure</a>
-        
+ +