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 "\n" -} elseif {$type == "string" && [regexp -nocase {(rows|cols)} $html]} { - set widget "\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 "\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] } - - -