Index: openacs-4/packages/lars-blogger/www/entry-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/lars-blogger/www/entry-edit.tcl,v
diff -u -r1.15 -r1.16
--- openacs-4/packages/lars-blogger/www/entry-edit.tcl 8 Jan 2004 09:08:07 -0000 1.15
+++ openacs-4/packages/lars-blogger/www/entry-edit.tcl 28 Jan 2004 16:13:14 -0000 1.16
@@ -1,5 +1,10 @@
+# As we are using the formbuilder return_url, title, title_url and
+# content are not necessary in ad_page_contract. However Lars says it
+# is convenient to have them here so people can create custom bookmarks
+# to this page that prefill these values:
+
ad_page_contract {} {
- {entry_id:integer ""}
+ {entry_id:integer,optional}
{return_url ""}
{title:allhtml ""}
{title_url ""}
@@ -12,6 +17,15 @@
# Must have create on the package
permission::require_permission -object_id [ad_conn package_id] -privilege create
+# This can't go into -edit_request and -new_request blocks b/c we'll
+# need it sooner.
+
+if {[ad_form_new_p -key entry_id]} {
+ set page_title "Add Blog Entry"
+} else {
+ set page_title "Edit Blog Entry"
+}
+
# If we're in DisplayUserP mode, the user must have a screen name setup
if { [parameter::get -parameter "DisplayUsersP" -default 0] } {
acs_user::get -user_id [ad_conn user_id] -array user_info
@@ -31,134 +45,114 @@
set package_id [ad_conn package_id]
set now_ansi [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]
-form create entry -cancel_url [ad_decode $return_url "" "." $return_url]
+ad_form -name entry \
+ -cancel_url [ad_decode $return_url "" "." $return_url] \
+ -form {entry_id:key(acs_object_id_seq)
+ {title:text
+ {label Title}
+ {html {size 50}}}
+ {title_url:text,optional
+ {label "Title URL"}
+ {html {size 50}}}
+ } \
+ -export {return_url}
-element create entry title -label "Title" -datatype text -html { size 50 }
-element create entry title_url -label "Title URL" -datatype text -html { size 50 } -optional
-
# If categories are enabled, set up a select-box with option.
+
if { [string equal [lars_blog_categories_p] "1"] } {
set options_list [db_list_of_lists categories {}]
if { [llength $options_list] > 0 } {
set option_list [concat [list [list None ""]] $options_list]
- element create entry category_id -label "Category" -datatype integer -widget select -options $option_list -optional
+ ad_form -extend -name entry \
+ -form {{category_id:integer(select),optional
+ {label Category}
+ {options $options_list}}
+ }
} else {
- element create entry category_id -datatype integer -widget hidden -value {} -optional
+
+ ad_form -extend -name entry -form {category_id:integer(hidden),optional}
+
}
}
-element create entry content -label "Content" -datatype richtext -widget richtext -html { cols 80 rows 20 }
+ad_form -extend -name entry -form {
+ {content:richtext(richtext)
+ {html {cols 80 rows 20}}
+ {label "Content"}
+ }
+}
-element create entry entry_date -label "Entry date" -datatype text \
- -help_text "Format: YYYY-MM-DD HH24:MI:SS" \
- -html { size 20 } \
- -after_html {(Set to now)}
-
-element create entry draft_p -label "Post Status" -datatype text -widget select -options { { "Draft" "t" } { "Publish" "f" } }
-
-element create entry entry_id -widget hidden -datatype text
-element create entry insert_or_update -widget hidden -datatype text
-element create entry return_url -widget hidden -datatype text -value $return_url
-
-if { [form is_request entry] } {
-
- if { [empty_string_p $entry_id] } {
- set insert_or_update insert
- set entry_id [db_nextval "acs_object_id_seq"]
- element set_properties entry entry_date -value $now_ansi
- element set_properties entry draft_p -value "t"
-
- # Prefill title and content with supplied values
- foreach element { title title_url } {
- if { [exists_and_not_null $element] } {
- element set_value entry $element [set $element]
- }
+ad_form -extend -name entry -form {
+ {entry_date:text
+ {label "Entry date"}
+ {help_text "Format: YYYY-MM-DD HH24:MI:SS"}
+ {html {size 20}}
+ {after_html
+ {(Set to now)}
}
- if { [exists_and_not_null content] } {
- element set_value entry content [template::util::richtext::create $content]
- }
- } else {
- set insert_or_update update
-
+ }
+ {draft_p:text(select)
+ {options {{"Draft" "t"} {"Publish" "f"}}}
+ {label "Post Status"}
+ }
+} \
+ -new_request {
+ set entry_date $now_ansi
+ } \
+ -edit_request {
permission::require_write_permission -object_id $entry_id
lars_blogger::entry::get \
-entry_id $entry_id \
-array row
-
- element set_value entry title $row(title)
- element set_value entry title_url $row(title_url)
+ set title $row(title)
+ set title_url $row(title_url)
+ set category_id $row(category_id)
+ set content [
+ template::util::richtext::create \
+ $row(content) $row(content_format)
+ ]
+ set entry_date $row(entry_date_ansi)
+ set draft_p $row(draft_p)
- element set_value entry category_id $row(category_id)
- element set_value entry content [template::util::richtext::create $row(content) $row(content_format)]
-
- element set_value entry entry_date $row(entry_date_ansi)
- element set_value entry draft_p $row(draft_p)
- }
-
- element set_properties entry entry_id -value $entry_id
- element set_properties entry insert_or_update -value $insert_or_update
-}
-
-
-if { [form is_valid entry] } {
- set entry_id [element get_value entry entry_id]
- set title [element get_value entry title]
- set title_url [element get_value entry title_url]
- set category_id [element get_value entry category_id]
- set content [template::util::richtext::get_property contents [element get_value entry content]]
- set content_format [template::util::richtext::get_property format [element get_value entry content]]
- set entry_date [element get_value entry entry_date]
- set draft_p [element get_value entry draft_p]
- set draft_p [ad_decode $draft_p "" "f" $draft_p]
-
- set return_url [element get_value entry return_url]
- set insert_or_update [element get_value entry insert_or_update]
-
- if { [string equal $insert_or_update "insert"] } {
+ } \
+ -on_submit {
+ set content_body [
+ template::util::richtext::get_property contents $content
+ ]
+ set content_format [
+ template::util::richtext::get_property format $content
+ ]
+ set entry_date [element get_value entry entry_date]
+ set draft_p [element get_value entry draft_p]
+ set draft_p [ad_decode $draft_p "" "f" $draft_p]
+ } \
+ -new_data {
lars_blogger::entry::new \
- -entry_id $entry_id \
- -package_id $package_id \
- -title $title \
- -title_url $title_url \
- -category_id $category_id \
- -content $content \
- -content_format $content_format \
- -entry_date $entry_date \
- -draft_p "$draft_p"
- } else {
- permission::require_write_permission -object_id $entry_id
-
+ -entry_id $entry_id \
+ -package_id $package_id \
+ -title $title \
+ -title_url $title_url \
+ -category_id $category_id \
+ -content $content_body \
+ -content_format $content_format \
+ -entry_date $entry_date \
+ -draft_p "$draft_p"
+ } \
+ -edit_data {
lars_blogger::entry::edit \
-entry_id $entry_id \
-title $title \
-title_url $title_url \
-category_id $category_id \
- -content $content \
+ -content $content_body \
-content_format $content_format \
-entry_date $entry_date \
-draft_p $draft_p
+ } \
+ -after_submit {
+ ad_returnredirect $return_url
+ ad_script_abort
}
-
- if { [empty_string_p $return_url] } {
- set return_url "one-entry?[export_vars { entry_id }]"
- }
- ad_returnredirect $return_url
- ad_script_abort
-}
-
-if { ![form is_request entry] && ![form is_valid entry] } {
- set insert_or_update [element get_value entry insert_or_update]
-}
-
-switch -- $insert_or_update {
- insert {
- set page_title "Add Blog Entry"
- }
- update {
- set page_title "Edit Blog Entry"
- }
-}
-
set context [list $page_title]