Fisheye: Tag 1.3 refers to a dead (removed) revision in file `openacs-4/packages/notes/www/add-edit-oracle.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/notes/www/add-edit-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/notes/www/add-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/www/add-edit.adp,v diff -u -r1.4 -r1.5 --- openacs-4/packages/notes/www/add-edit.adp 21 Sep 2003 22:16:52 -0000 1.4 +++ openacs-4/packages/notes/www/add-edit.adp 10 Feb 2004 19:39:49 -0000 1.5 @@ -1,6 +1,6 @@ -@title@ +@page_title@ @context;noquote@ - + Index: openacs-4/packages/notes/www/add-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/www/add-edit.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/notes/www/add-edit.tcl 21 Sep 2003 22:16:52 -0000 1.7 +++ openacs-4/packages/notes/www/add-edit.tcl 10 Feb 2004 19:39:49 -0000 1.8 @@ -1,91 +1,123 @@ # packages/notes/www/add-edit.tcl ad_page_contract { - @author rhs@mit.edu + @author Don Baccus (dhogaza@pacifier.com) @creation-date 2000-10-23 @cvs-id $Id$ -} { + + Example script that allows for the creation or editing of a simple note + object type, using ad_form and package Tcl API tools. + +} -query { note_id:integer,notnull,optional } -properties { context:onevalue + page_title:onevalue } +# When using ad_form to generate or edit acs_objects, the object type's +# key column must be specified in ad_page_contract as is done above, +# and defined with the type "key" in ad_form. This enables the use of +# the various request and submission code blocks. + set package_id [ad_conn package_id] -if {[info exists note_id]} { - ad_require_permission $note_id write +ad_form -form { - set context [list "Edit Note"] -} else { - ad_require_permission $package_id create - - set context [list "New Note"] -} + # The "note" object type's key -template::form create new_note + {note_id:key} -if {[template::form is_request new_note] && [info exists note_id]} { + # "title" is of type text and will use a "text" widget. - template::element create new_note note_id \ - -widget hidden \ - -datatype number \ - -value $note_id + {title:text \ + {label Title} + {html {size 20}} + } - db_1row note_select { - select title, body - from notes - where note_id = :note_id - } -} else { - set title {} - set body {} -} + # "body" is of type text and will use a "textarea" widget. -template::element create new_note title \ - -datatype text \ - -label "Title" \ - -html { size 20 } \ - -value $title + {body:text(textarea) \ + {label Body} + {html {rows 10 cols 40 wrap soft}} + } -template::element create new_note body \ - -widget textarea \ - -datatype text \ - -label "Body" \ - -html { rows 10 cols 40 wrap soft } \ - -value $body +} -new_request { + # By convention packages only allow a user to create new objects if the user has + # the "create" privilege on the package instance itself. -if [template::form is_valid new_note] { - form get_values new_note title body + permission::require_permission -object_id $package_id -privilege create - set user_id [ad_conn user_id] - set peeraddr [ad_conn peeraddr] + # Customize the page title to reflect the fact that this form is used to + # create a new note. - if [info exists note_id] { - db_dml note_update { - update notes - set title = :title, - body = :body - where note_id = :note_id + set page_title "New Note" + +} -edit_request { + + permission::require_permission -object_id $note_id -privilege write + + # Customize the page title to reflect the fact that this form is used to + # edit an existing note. + + set page_title "Edit Note" + + # Fill the form with the values from the note we're editing. + + db_1row note_select {} + +} -on_validation_error { + + # There was an error in the form, let the page title reflect this. + + set page_title "Error in submission" + +} -new_data { + + # Create a new note. + + # Generate the new object automatically from the data set in the form. Standard + # acs_object attributes like creation_user are set automatically. + + package_instantiate_object -var_list [list [list context_id $package_id]] \ + -form_id add-edit \ + note + +} -edit_data { + + # Currently we need to update our object manually ... + + set modifying_user [ad_conn user_id] + set modifying_ip [ad_conn peeraddr] + + db_transaction { + db_dml object_update {} + db_dml note_update {} } - } else { - db_exec_plsql new_note { - declare - id integer; - begin - id := note.new( - owner_id => :user_id, - title => :title, - body => :body, - creation_user => :user_id, - creation_ip => :peeraddr, - context_id => :package_id - ); - end; - } - } - ad_returnredirect "./" +} -after_submit { + + # We've successfully processed the submission, send the user back to the index page. + + ad_returnredirect "./" + + # ad_returnredirect returns after redirecting the user, so abort the script rather + # than fall through to the display code. Failure to abort the script will burden + # your server with needless template processing, though the user won't notice due to + # having been redirected. + + ad_script_abort + } +# The following is only executed if we did not process a valid submission, in other +# words on the initial "new" or "edit" form request or after a submission which +# contained errors. Add the page title to the breadcrumb context bar. + +set context [list $page_title] + +# Display the form, blank if we're processing a "new" request, filled with data if we're +# processing an "edit" request or a submitted form that contains errors. + ad_return_template Index: openacs-4/packages/notes/www/add-edit.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/www/add-edit.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/notes/www/add-edit.xql 3 May 2001 18:23:35 -0000 1.1 +++ openacs-4/packages/notes/www/add-edit.xql 10 Feb 2004 19:39:49 -0000 1.2 @@ -1,27 +1,30 @@ - - - - select title, body - from notes - where note_id = :note_id - - - - - - - - - update notes - set title = :title, - body = :body + + + select title, body + from notes where note_id = :note_id - - - + + + + + update acs_objects + set modifying_user = :modifying_user, + modifying_ip = :modifying_ip + where object_id = :note_id + + + + + + update notes + set title = :title, + body = :body + where note_id = :note_id + + Index: openacs-4/packages/notes/www/delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/www/delete.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/notes/www/delete.tcl 30 Sep 2003 12:10:08 -0000 1.4 +++ openacs-4/packages/notes/www/delete.tcl 10 Feb 2004 19:39:49 -0000 1.5 @@ -11,10 +11,6 @@ ad_require_permission $note_id delete -db_exec_plsql note_delete { - begin - note.del(:note_id); - end; -} +package_exec_plsql -var_list [list [list note_id $note_id]] note del ad_returnredirect "./" Index: openacs-4/packages/notes/www/index-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/www/index-oracle.xql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/notes/www/index-oracle.xql 30 Nov 2002 17:39:52 -0000 1.2 +++ openacs-4/packages/notes/www/index-oracle.xql 10 Feb 2004 19:39:49 -0000 1.3 @@ -1,34 +1,35 @@ -oracle8.1.6 + oracle8.1.6 - - - - select note_id, owner_id, title, body, - decode(acs_permission.permission_p(note_id, - :user_id, - 'write'), - 't', 1, - 'f', 0) as write_p, - decode(acs_permission.permission_p(note_id, - :user_id, - 'admin'), - 't', 1, - 'f', 0) as admin_p, - decode(acs_permission.permission_p(note_id, - :user_id, - 'delete'), - 't', 1, - 'f', 0) as delete_p - from notes n, acs_objects o - where n.note_id = o.object_id - and o.context_id = :package_id - and acs_permission.permission_p(note_id, :user_id, 'read') = 't' - order by creation_date - - - - + + + select note_id, title, body, + decode(acs_permission.permission_p(note_id, + :user_id, + 'write'), + 't', 1, + 'f', 0) as write_p, + decode(acs_permission.permission_p(note_id, + :user_id, + 'admin'), + 't', 1, + 'f', 0) as admin_p, + decode(acs_permission.permission_p(note_id, + :user_id, + 'delete'), + 't', 1, + 'f', 0) as delete_p + from notes n, acs_objects o + where n.note_id = o.object_id + and o.context_id = :package_id + and exists (select 1 + from acs_object_party_privilege_map + where object_id = note_id + and party_id = :user_id + and privilege = 'read') + order by creation_date + + Index: openacs-4/packages/notes/www/index-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/www/index-postgresql.xql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/notes/www/index-postgresql.xql 3 May 2001 18:23:35 -0000 1.1 +++ openacs-4/packages/notes/www/index-postgresql.xql 10 Feb 2004 19:39:49 -0000 1.2 @@ -1,24 +1,28 @@ - postgresql7.1 + postgresql7.1 - - - select note_id, owner_id, title, body, - case when acs_permission__permission_p(note_id,:user_id,'write')='t' - then 1 else 0 end as write_p, - case when acs_permission__permission_p(note_id,:user_id,'admin')='t' - then 1 else 0 end as admin_p, - case when acs_permission__permission_p(note_id,:user_id,'delete')='t' - then 1 else 0 end as delete_p - from notes n, acs_objects o - where n.note_id = o.object_id - and o.context_id = :package_id - and acs_permission__permission_p(note_id, :user_id, 'read') = 't' - order by creation_date + + - - + select note_id, title, body, + case when acs_permission__permission_p(note_id,:user_id,'write')='t' + then 1 else 0 end as write_p, + case when acs_permission__permission_p(note_id,:user_id,'admin')='t' + then 1 else 0 end as admin_p, + case when acs_permission__permission_p(note_id,:user_id,'delete')='t' + then 1 else 0 end as delete_p + from notes n, acs_objects o + where n.note_id = o.object_id + and o.context_id = :package_id + and exists (select 1 + from acs_object_party_privilege_map + where object_id = note_id + and party_id = :user_id + and privilege = 'read') + order by creation_date + + Index: openacs-4/packages/notes/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notes/www/index.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/notes/www/index.tcl 21 Sep 2003 22:16:52 -0000 1.5 +++ openacs-4/packages/notes/www/index.tcl 10 Feb 2004 19:39:49 -0000 1.6 @@ -17,31 +17,8 @@ set context [list] set create_p [ad_permission_p $package_id create] -db_multirow notes notes { - select note_id, owner_id, title, body, - decode(acs_permission.permission_p(note_id, - :user_id, - 'write'), - 't', 1, - 'f', 0) as write_p, - decode(acs_permission.permission_p(note_id, - :user_id, - 'admin'), - 't', 1, - 'f', 0) as admin_p, - decode(acs_permission.permission_p(note_id, - :user_id, - 'delete'), - 't', 1, - 'f', 0) as delete_p - from notes n, acs_objects o - where n.note_id = o.object_id - and o.context_id = :package_id - and acs_permission.permission_p(note_id, :user_id, 'read') = 't' - order by creation_date -} { +db_multirow notes notes {} { set body [ad_text_to_html -- $body] } - ad_return_template