Index: openacs-4/packages/edit-this-page/Changes
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/Changes,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/edit-this-page/Changes	4 Apr 2003 15:56:20 -0000	1.3
+++ openacs-4/packages/edit-this-page/Changes	23 Sep 2003 19:13:19 -0000	1.4
@@ -1,5 +1,9 @@
 Edit This Page version history
+22 September 2003
 
+-Added support for enhanched text widget to content attribute
+-Converted etp-edit to use ad_form/form-builder
+
 25 January 2003
 -Oracle is broken. We will fix it later.
 -Changed base content type to be etp_page_revision, all custom types should
Index: openacs-4/packages/edit-this-page/edit-this-page.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/edit-this-page.info,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/edit-this-page/edit-this-page.info	17 May 2003 10:30:36 -0000	1.7
+++ openacs-4/packages/edit-this-page/edit-this-page.info	23 Sep 2003 19:13:19 -0000	1.8
@@ -7,7 +7,7 @@
     <initial-install-p>f</initial-install-p>
     <singleton-p>f</singleton-p>
 
-    <version name="1.4" url="http://openacs.org/repository/download/apm/edit-this-page-1.4.apm">
+    <version name="1.5" url="http://openacs.org/repository/download/apm/edit-this-page-1.5.apm">
     <database-support>
         <database>postgresql</database>
     </database-support>
Index: openacs-4/packages/edit-this-page/sql/postgresql/edit-this-page-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/sql/postgresql/edit-this-page-create.sql,v
diff -u -r1.12 -r1.13
--- openacs-4/packages/edit-this-page/sql/postgresql/edit-this-page-create.sql	17 May 2003 10:31:27 -0000	1.12
+++ openacs-4/packages/edit-this-page/sql/postgresql/edit-this-page-create.sql	23 Sep 2003 19:13:20 -0000	1.13
@@ -72,6 +72,53 @@
 end;
 ' language 'plpgsql';
 
+create or replace function etp__create_page(integer, integer, varchar, varchar, varchar)
+returns integer as '
+declare
+  p_item_id alias for $1;	
+  p_package_id alias for $2;
+  p_name alias for $3;
+  p_title alias for $4;
+  p_content_type alias for $5;  -- default null -> use content_revision
+  v_item_id integer;
+  v_revision_id integer;
+  v_folder_id integer;
+begin
+  if p_item_id is null then
+      v_item_id := acs_object__new(null, ''content_item'', now(), null, null, p_package_id);
+  else 
+      v_item_id := acs_object__new(p_item_id, ''content_item'', now(), null, null, p_package_id);
+  end if;
+
+  v_folder_id := etp__get_folder_id(p_package_id);
+
+-- due to a change in acs_object__delete we can reference the actual
+-- object type we want
+-- using this we can more easily search, but we will have to create a service
+-- contract for each custom content type
+-- we define a default etp_page_revision and service contract to go with it
+-- make sure to subtype from etp_page_revision for any custom types
+-- 2003-01-12 DaveB
+
+  insert into cr_items (
+    item_id, parent_id, name, content_type
+  ) values (
+    v_item_id, v_folder_id, p_name, p_content_type
+  );
+
+  v_revision_id := acs_object__new(null, p_content_type, now(), null, null, v_item_id);
+
+  insert into cr_revisions (revision_id, item_id, title, 
+                            publish_date, mime_type) 
+  values (v_revision_id, v_item_id, p_title, now(), ''text/html'');
+
+  update cr_items set live_revision = v_revision_id
+                  where item_id = v_item_id;
+
+  return 1;
+end;
+' language 'plpgsql';
+
 create function etp__create_extlink(integer, varchar, varchar, varchar)
 returns integer as '
 declare
@@ -179,7 +226,58 @@
 end;
 ' language 'plpgsql';
 
+create or replace function etp__create_new_revision(integer, varchar, integer, integer)
+returns integer as '
+declare
+  p_package_id alias for $1;
+  p_name alias for $2;
+  p_user_id alias for $3;
+  p_revision_id alias for $4;
+  v_revision_id integer;
+  v_item_id integer;
+  v_content_type varchar;
+begin
 
+  select max(r.revision_id)
+    into v_revision_id
+    from cr_revisions r, cr_items i
+   where i.name = p_name
+     and i.parent_id = etp__get_folder_id(p_package_id)
+     and r.item_id = i.item_id;
+
+  select item_id
+    into v_item_id
+    from cr_revisions
+   where revision_id = v_revision_id;
+
+  select object_type
+    into v_content_type
+    from acs_objects
+   where object_id = v_revision_id;
+
+  -- cannot use acs_object__new because it creates attributes with their
+  -- default values, which is not what we want.
+
+
+  insert into acs_objects (object_id, object_type, creation_date, creation_user, context_id)
+  values (p_revision_id, v_content_type, now(), p_user_id, v_item_id);
+
+  insert into cr_revisions (revision_id, item_id, title, description, content, mime_type) 
+  select p_revision_id, item_id, title, description, content, mime_type
+    from cr_revisions r
+   where r.revision_id = v_revision_id;
+
+  -- copy extended attributes to the new revision, if there are any
+  insert into acs_attribute_values (object_id, attribute_id, attr_value)
+  select p_revision_id as object_id, attribute_id, attr_value
+    from acs_attribute_values
+   where object_id = v_revision_id;
+
+  return 1;
+end;
+' language 'plpgsql';
+
+
 create function etp__get_folder_id (integer)
 returns integer as '
 declare
Index: openacs-4/packages/edit-this-page/sql/postgresql/upgrade/upgrade-1.3.sql-1.5.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/sql/postgresql/upgrade/Attic/upgrade-1.3.sql-1.5.sql,v
diff -u
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/edit-this-page/sql/postgresql/upgrade/upgrade-1.3.sql-1.5.sql	23 Sep 2003 19:13:20 -0000	1.1
@@ -0,0 +1,50 @@
+--add new pl/pgsql proc
+--Dave Bauer dave@thedesignexperience.org
+--2003-09-22
+
+create or replace function etp__create_page(integer, integer, varchar, varchar, varchar)
+returns integer as '
+declare
+  p_item_id alias for $1;	
+  p_package_id alias for $2;
+  p_name alias for $3;
+  p_title alias for $4;
+  p_content_type alias for $5;  -- default null -> use content_revision
+  v_item_id integer;
+  v_revision_id integer;
+  v_folder_id integer;
+begin
+  if p_item_id is null then
+      v_item_id := acs_object__new(null, ''content_item'', now(), null, null, p_package_id);
+  else 
+      v_item_id := acs_object__new(p_item_id, ''content_item'', now(), null, null, p_package_id);
+  end if;
+
+  v_folder_id := etp__get_folder_id(p_package_id);
+
+-- due to a change in acs_object__delete we can reference the actual
+-- object type we want
+-- using this we can more easily search, but we will have to create a service
+-- contract for each custom content type
+-- we define a default etp_page_revision and service contract to go with it
+-- make sure to subtype from etp_page_revision for any custom types
+-- 2003-01-12 DaveB
+
+  insert into cr_items (
+    item_id, parent_id, name, content_type
+  ) values (
+    v_item_id, v_folder_id, p_name, p_content_type
+  );
+
+  v_revision_id := acs_object__new(null, p_content_type, now(), null, null, v_item_id);
+
+  insert into cr_revisions (revision_id, item_id, title, 
+                            publish_date, mime_type) 
+  values (v_revision_id, v_item_id, p_title, now(), ''text/html'');
+
+  update cr_items set live_revision = v_revision_id
+                  where item_id = v_item_id;
+
+  return 1;
+end;
+' language 'plpgsql';
Index: openacs-4/packages/edit-this-page/tcl/etp-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/tcl/etp-procs-postgresql.xql,v
diff -u -r1.10 -r1.11
--- openacs-4/packages/edit-this-page/tcl/etp-procs-postgresql.xql	4 Apr 2003 15:20:28 -0000	1.10
+++ openacs-4/packages/edit-this-page/tcl/etp-procs-postgresql.xql	23 Sep 2003 19:13:20 -0000	1.11
@@ -48,6 +48,7 @@
 <fullquery name="etp::make_page.page_create">      
 <querytext>
 	select etp__create_page(
+	  :item_id,
 	  :package_id,
 	  :name,
           :title,
@@ -74,7 +75,7 @@
 
 <fullquery name="etp::get_pa.get_page_attributes">      
 <querytext>
-	select i.item_id, i.name, r.revision_id, r.title, 
+	select i.item_id, i.name, r.revision_id, r.title, r.mime_type,
 	       r.description, r.publish_date, r.content $extended_attributes
 	  from cr_items i, cr_revisions r
 	 where i.parent_id = etp__get_folder_id(:package_id)
@@ -86,7 +87,7 @@
  
 <fullquery name="etp::get_pa.get_page_attributes_other_revision">      
 <querytext>
-	select i.item_id, i.name, r.revision_id, r.title, 
+	select i.item_id, i.name, r.revision_id, r.title, r.mime_type,
 	       r.description, r.publish_date, r.content $extended_attributes
 	  from cr_items i, cr_revisions r
 	 where i.parent_id = etp__get_folder_id(:package_id)
@@ -166,4 +167,10 @@
    </querytext>
 </partialquery>
 
+<fullquery name="etp::get_folder_id.get_folder_id">
+	<querytext>
+	select etp__get_folder_id(:package_id)
+	</querytext>
+</fullquery>
+
 </queryset>
Index: openacs-4/packages/edit-this-page/tcl/etp-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/tcl/etp-procs.tcl,v
diff -u -r1.13 -r1.14
--- openacs-4/packages/edit-this-page/tcl/etp-procs.tcl	7 Jul 2003 16:17:16 -0000	1.13
+++ openacs-4/packages/edit-this-page/tcl/etp-procs.tcl	23 Sep 2003 19:13:20 -0000	1.14
@@ -183,7 +183,7 @@
 }
 
 
-ad_proc -public make_page { name {title "Untitled"} } {
+ad_proc -public make_page { name {title "Untitled"} {item_id ""}} {
     @author Luke Pond
     @creation-date 2001-05-31
     @param name the name of the page you wish to create 
@@ -318,6 +318,8 @@
 	db_1row get_page_attributes_other_revision "" -column_array pa
     }
 
+	    set pa(content) [template::util::richtext get_property html_value [list $pa(content) $pa(mime_type)]]
+
     # add in the context bar
     if { $name == "index" } {
 	set cb [ad_context_bar]
@@ -698,4 +700,11 @@
     }
 }
 
+ad_proc -public get_folder_id { package_id } {
+    @param package_id
+    @returns content folder associated with package_id etp package instance
+} {
+    return [db_exec_plsql get_folder_id ""]
 }
+
+}
Fisheye: Tag 1.4 refers to a dead (removed) revision in file `openacs-4/packages/edit-this-page/www/etp-edit-2.tcl'.
Fisheye: No comparison available.  Pass `N' to diff?
Index: openacs-4/packages/edit-this-page/www/etp-edit-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/www/etp-edit-postgresql.xql,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/edit-this-page/www/etp-edit-postgresql.xql	18 Dec 2001 19:28:00 -0000	1.3
+++ openacs-4/packages/edit-this-page/www/etp-edit-postgresql.xql	23 Sep 2003 19:13:20 -0000	1.4
@@ -10,12 +10,12 @@
 
 <fullquery name="get_standard_attribute">
 <querytext>
-        select $attribute as value, r.title as page_title
+        select $attribute as value, r.title as page_title, mime_type
           from cr_revisions r, cr_items i
          where i.parent_id = etp__get_folder_id(:package_id)
            and i.name = :name
            and i.item_id = r.item_id
-	   and r.revision_id = :revision_id
+	   and r.revision_id = :old_revision_id
 </querytext>
 </fullquery>
 
@@ -27,8 +27,15 @@
 	 where i.parent_id = etp__get_folder_id(:package_id)
 	   and i.name = :name
 	   and i.item_id = r.item_id
-	   and r.revision_id = :revision_id
+	   and r.revision_id = :old_revision_id
 </querytext>
 </fullquery>
+
+
+<fullquery name="create_new_revision">
+<querytext>
+select etp__create_new_revision(:package_id, :name, :user_id, :revision_id);
+</querytext>
+</fullquery>
  
 </queryset>
Index: openacs-4/packages/edit-this-page/www/etp-edit.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/www/etp-edit.adp,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/edit-this-page/www/etp-edit.adp	19 Jun 2003 01:12:30 -0000	1.4
+++ openacs-4/packages/edit-this-page/www/etp-edit.adp	23 Sep 2003 19:13:20 -0000	1.5
@@ -1,15 +1,4 @@
 <master src="etp-master">
 <property name="title">@page_title;noquote@</property>
 <property name="context">@context;noquote@</property>
-
-<form method="post" action="etp-edit-2">
-@form_vars;noquote@
-<table>
-<tr><td>
-@widget;noquote@
-</td></tr>
-<tr><td align=center>
-<input type="submit" value="Submit">
-</td></tr>
-</table>
-</form>
\ No newline at end of file
+<formtemplate id="etp-edit"></formtemplate>
Index: openacs-4/packages/edit-this-page/www/etp-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/edit-this-page/www/etp-edit.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/edit-this-page/www/etp-edit.tcl	11 Aug 2003 21:06:57 -0000	1.6
+++ openacs-4/packages/edit-this-page/www/etp-edit.tcl	23 Sep 2003 19:13:20 -0000	1.7
@@ -18,72 +18,156 @@
 etp::check_write_access
 
 set package_id [ad_conn package_id]
-set revision_id [etp::get_latest_revision_id $package_id $name]
+set user_id [ad_conn user_id]
+set old_revision_id [etp::get_latest_revision_id $package_id $name]
+
 set content_type [etp::get_content_type $name]
 set attribute_desc [etp::get_attribute_desc $attribute $content_type]
 
-ns_log Notice "etp-edit: attr_desc is $attribute_desc"
 set attribute_title [etp::get_attribute_pretty_name $attribute_desc $name]
+set type [etp::get_attribute_data_type $attribute_desc]
+set html [etp::get_attribute_html $attribute_desc]
+#transform old style ETP html attributes to ad_form style
+regsub -all "=" $html " " html
+set default [etp::get_attribute_default $attribute_desc]
 
-# figure out the attribute's value
+set element $attribute
 
-if { [lsearch -exact {title description content} $attribute] >= 0 } {
-    # value is stored in cr_revisions table
+# see if a select-list callback function was specified
+if { [info commands $default] != "" } {
+    set query_results [eval $default option_list $attribute_id]
+    set widget select
+} elseif {$type == "string" && [regexp -nocase {(rows|cols)} $html]} {
+    if {[string equal $attribute content]} {
 
-    db_1row get_standard_attribute ""
+    set widget "(richtext)"
 
+    set type richtext
 } else {
-    # value is stored in acs_attribute_values
-    set attribute_id [etp::get_attribute_id $attribute_desc]
-    db_1row get_extended_attribute ""
+    set widget "(textarea)"
 }
+   
+} elseif {$type == "date"} {
+	set widget "(date),to_sql(linear_date),from_sql(sql_date)"
+    set widget_extra [list format "Month DD YYYY"]
+    set element datevalue
 
+} else {
+    set widget "(text)"
+}
+# to set values, we'll use -edit_request block or -on_request block.
+# we really need to grab the item_id/revision_id
 
-# TODO: need to implement select lists also
-# TODO: what about default values?
+set widget_list [list $element:${type}${widget} [list label "$attribute_title"] [list html $html] ]
 
-set type [etp::get_attribute_data_type $attribute_desc]
-set html [etp::get_attribute_html $attribute_desc]
-set default [etp::get_attribute_default $attribute_desc]
+if {[exists_and_not_null widget_extra]} {
+    lappend widget_list $widget_extra
+}
 
-ns_log Notice "default is $default; [info commands $default]"
 
-# see if a select-list callback function was specified
-if { [info commands $default] != "" } {
-    set query_results [eval $default option_list $attribute_id]
-    set widget "<select name=\"$attribute\">\n"
-    foreach pair $query_results {
-	if {[lindex $pair 0] == $value} {
-	    append widget "<option value=\"[lindex $pair 0]\" selected>[lindex $pair 1]</option>\n"
+# build dynamic form spec list
+set form_list [list revision_id:key]
+lappend form_list $widget_list
+
+ad_form -export { name attribute  widget} -form $form_list -edit_request {
+
+
+    if { [lsearch -exact {title description content} $attribute] >= 0 } {
+	# value is stored in cr_revisions table
+
+	db_1row get_standard_attribute ""
+
+    } else {
+	# value is stored in acs_attribute_values
+	set attribute_id [etp::get_attribute_id $attribute_desc]
+	db_1row get_extended_attribute ""
+    }
+    if {[string equal $widget "(richtext)"]} {
+	set $element [template::util::richtext create $value $mime_type]
+    } else {
+	set $element $value
+    }
+
+} -new_request {
+
+
+
+    if { [lsearch -exact {title description content} $attribute] >= 0 } {
+	# value is stored in cr_revisions table
+
+	db_1row get_standard_attribute ""
+
+    } else {
+	# value is stored in acs_attribute_values
+	set attribute_id [etp::get_attribute_id $attribute_desc]
+	db_1row get_extended_attribute ""
+    }
+	if {[string equal $widget "(richtext)"]} {
+	    set $element [template::util::richtext create $value $mime_type]
 	} else {
-	    append widget "<option value=\"[lindex $pair 0]\">[lindex $pair 1]</option>\n"
+	    set $element $value
 	}
+
+} -new_data {
+    # usually we are creating a new revision
+
+    if {[info exists datevalue]} {
+	set date_string $datevalue(date)
+	# The date is given in YYYY-MM-DD.  Transform to desired format.
+	set date_format [etp::get_application_param date_format]
+	set value $date_string
+    } else {
+	set value [template::util::richtext get_property contents [set $element]]
+	set mime_type [template::util::richtext get_property format [set $element]]
+	set extra_sql " , mime_type=:mime_type"
     }
-    append widget "</select>\n"
-} elseif {$type == "string" && [regexp -nocase {(rows|cols)} $html]} {
-    set widget "<textarea name=\"$attribute\" $html>[ad_quotehtml $value]</textarea>\n"
-} elseif {$type == "date"} {
-    if [empty_string_p $value] {
-	set widget [ad_dateentrywidget datevalue]
+
+    db_exec_plsql create_new_revision ""
+
+    set attribute_id [etp::get_attribute_id $attribute_desc]
+    if { $attribute_id == -1} {
+	# standard attribute
+
+	# DRB: The following code's an absolute hack, but then again the original
+	# code's pretty much an absolute hack, too.   We need to sit down and make
+	# some decisions about how to stuff Oracle clob and PG (and other reasonable
+	# RDBMS's) long text type in an RDBMS-independent fashion.
+
+	# This isn't as ugly as it could be in the sense that the test for clobness is
+	# encapsulated in the query file.    So maybe it's not quite as ugly a hack
+	# as I make it out to be ... you decide!
+
+	if { ![empty_string_p [db_map update_${attribute}_attribute_clob]] } {
+	    db_dml update_${attribute}_attribute_clob "" -blobs  [list $value]
+	} else {
+	    db_dml update_attribute ""
+	}
+
     } else {
-	# Put the date back into YYYY-MM-DD format
-	set date_format [etp::get_application_param date_format]
-	set value [db_string transform_date ""]
-	set widget [ad_dateentrywidget datevalue $value]
+	# extended_attribute
+	db_transaction {
+	    db_dml delete_ext_attribute ""
+	    db_dml insert_ext_attribute ""
+	}
     }
-} else {
-    set widget "<input type=\"text\" name=\"$attribute\" value=\"[ad_quotehtml $value]\" $html>\n"
+
+    # As a convenience, if you change the Title of an index page, 
+    # we also update the package instance name so that the context bar
+    # reflects the new title.  Note this is something you can't do through
+    # the Site Map UI.
+
+    if { $name == "index" && $attribute == "title" } {
+	db_dml update_package_instance_name ""
+    }
+
+    ad_returnredirect "etp?[export_url_vars name]"
 }
 
-set form_vars [export_form_vars name attribute]
 
-set page_title "$attribute_title for page '$page_title'"
+set page_title "$attribute_title for page \"$page_title\""
 
 if {$name == "index"} {
     set context [list [list "etp?[export_url_vars name]" Edit] $attribute_title]
 } else {
     set context [list [list $name $name] [list "etp?[export_url_vars name]" Edit] $attribute_title]
 }
-
-
-