From b566c28054ef055146f3336b60fe75ddc000e97a Mon Sep 17 00:00:00 2001 From: Len Kranendonk Date: Thu, 15 Jan 2004 16:55:55 +0000 Subject: [PATCH] Templatized the Rich Text Editor support --- docs/changelog/6.x.x.txt | 1 + docs/upgrades/upgrade_5.9.9-6.0.0.sql | 12 ++++ lib/WebGUI/Form.pm | 94 ++++++++------------------- 3 files changed, 40 insertions(+), 67 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 5e337ab7a..c5cb1e331 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -31,3 +31,4 @@ - Added admin style option. - Added per page printable styles. - Wobject privileges are available per page rather than site-wide. + - Templatized the Rich Editor support. Tnx to Len Kranendonk diff --git a/docs/upgrades/upgrade_5.9.9-6.0.0.sql b/docs/upgrades/upgrade_5.9.9-6.0.0.sql index e007f2009..0707e2770 100644 --- a/docs/upgrades/upgrade_5.9.9-6.0.0.sql +++ b/docs/upgrades/upgrade_5.9.9-6.0.0.sql @@ -298,3 +298,15 @@ delete from international where languageId=1 and namespace='WebGUI' and internat insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1080,1,'WebGUI','Use admin style?', 1073161583,'A label asking the user if they want to use a seperate admin style from the main page style.'); insert into settings values ("useAdminStyle",1); insert into settings values ("adminStyleId",1000); +INSERT INTO template VALUES (3,'Midas','\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n','richEditor'); +INSERT INTO template VALUES (4,'Classic','\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n','richEditor'); +INSERT INTO template VALUES (2,'EditOnPro2','\r\n\r\n','richEditor'); +INSERT INTO template VALUES (1,'HTMLArea','\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n','richEditor'); +INSERT INTO template VALUES (5,'lastResort','\r\n\r\n\r\n\r\n\r\n\r\n','richEditor'); +UPDATE userProfileField set dataValues = '{\r\n1=>WebGUI::International::get(495), #htmlArea\r\n#2=>WebGUI::International::get(494), #editOnPro2\r\n3=>WebGUI::International::get(887), #midas\r\n4=>WebGUI::International::get(879), #classic\r\n5=>WebGUI::International::get(880),\r\nnone=>WebGUI::International::get(881)\r\n}', dataDefault = '[1]' where fieldName = 'richEditor'; +UPDATE userProfileData set fieldData = '1' where fieldName = 'richEditor' and fieldData = 'htmlArea'; +UPDATE userProfileData set fieldData = '2' where fieldName = 'richEditor' and fieldData = 'editOnPro2'; +UPDATE userProfileData set fieldData = '3' where fieldName = 'richEditor' and fieldData = 'midas'; +UPDATE userProfileData set fieldData = '4' where fieldName = 'richEditor' and fieldData = 'classic'; +UPDATE userProfileData set fieldData = '5' where fieldName = 'richEditor' and fieldData = 'lastResort'; + diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index 63b03f97d..0a1ceebae 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -959,67 +959,22 @@ NOTE: WebGUI uses a great variety of rich editors. Not all of them are capable o sub HTMLArea { my ($output, $rows, $columns, $htmlArea); my $browser = HTTP::BrowserDetect->new($session{env}{HTTP_USER_AGENT}); - my $button = '
'; - $output = ''; - if ($session{user}{richEditor} eq "editOnPro2") { - $output .= ''; - } elsif ($session{user}{richEditor} eq "htmlArea" && $browser->ie && $browser->version >= 5.5) { - if ($session{user}{richEditorMode} eq "popup" || $_[0]->{popupToggle}) { - $output .= ''; - $output .= $button; - } else { - $output .= _javascriptFile('htmlArea/editor.js'); - $output .= ''."\n"; - $htmlArea = 1; - } - } elsif ($session{user}{richEditor} eq "midas" && (($browser->ie && $browser->version >= 6) || ($browser->gecko && $browser->version >= 1.3))) { - $output .= ''; - $output .= $button; - } elsif ($session{user}{richEditor} eq "classic" && $browser->ie && $browser->version >= 5) { - $output .= ''; - $output .= $button; - } elsif ($session{user}{richEditor} eq "lastResort") { - $output .= ''; - $output .= $button; - } - $rows = $_[0]->{rows} || ($session{setting}{textAreaRows}+7); - $columns = $_[0]->{columns} || ($session{setting}{textAreaCols}+5); - $output .= textarea({ + my %var; + + # Store all scalar options in template variables + foreach (keys %{$_[0]}) { + $var{"form.".$_} = $_[0]->{$_} unless (ref $_[0]->{$_}); + } + + # Supported Rich Editors + $var{"htmlArea.supported"} = ($browser->ie && $browser->version >= 5.5); + $var{"midas.supported"} = (($browser->ie && $browser->version >= 6) || ($browser->gecko && $browser->version >= 1.3)); + $var{"classic.supported"} = ($browser->ie && $browser->version >= 5); + + # Textarea field + $rows = $_[0]->{rows} || ($session{setting}{textAreaRows}+7); + $columns = $_[0]->{columns} || ($session{setting}{textAreaCols}+5); + $var{textarea} = textarea({ name=>$_[0]->{name}, value=>$_[0]->{value}, wrap=>$_[0]->{wrap}, @@ -1027,12 +982,17 @@ sub HTMLArea { rows=>$rows, extras=>$_[0]->{extras}.' onBlur="fixChars(this.form.'.$_[0]->{name}.')"' }); - if ($htmlArea) { - $output .= ''."\n"; - } - return $output; + + # Other variables + $var{"popup"} = ($session{user}{richEditorMode} eq "popup" || $_[0]->{popupToggle}); + $var{"button"} = '
'; + + if ($session{user}{richEditor} eq 'none') { + return $var{textarea}; + } else { + return WebGUI::Template::process(WebGUI::Template::get($session{user}{richEditor},'richEditor'),\%var); + } } #-------------------------------------------------------------------