Index: openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-pages.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-pages.xml,v diff -u -r1.10 -r1.11 --- openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-pages.xml 4 Feb 2004 16:47:34 -0000 1.10 +++ openacs-4/packages/acs-core-docs/www/xml/developers-guide/tutorial-pages.xml 12 Feb 2004 13:51:42 -0000 1.11 @@ -15,22 +15,10 @@ Install some API As a workaround for missing content-repository functionality, copy a provided file into the directory for tcl files: - cp /var/lib/aolserver/service0/packages/acs-core-docs/www/files/note-procs.tcl /var/lib/aolserver/service0/packages/myfirstpackage/tcl/ + cp /var/lib/aolserver/service0/packages/acs-core-docs/www/files/note-procs.tcl /var/lib/aolserver/service0/packages/myfirstpackage/tcl/ To make this file take effect, go to the APM and choose "Reload changed" for "MyFirstPackage". - Page Map - Our package will have two visible pages. The first shows a list of all objects; the second shows a single object in view or edit mode, and can also be used to add an object. The index page will display the list, but since we might reuse the list later, we'll put it in a seperate file and include it on the index page. -
- Page Map - - - - - -
-
- Build the "Index" page Each user-visible page in your package has, typically, three parts. The tcl file @@ -43,32 +31,139 @@ database-specific SQL. The default page in any directory is index, so we'll build that first, starting with the tcl file: - [service0 postgresql]$ cd /var/lib/aolserver/service0/packages/myfirstpackages/www + [service0 postgresql]$ cd /var/lib/aolserver/service0/myfirstpackages/www [service0 www]$ emacs index.tcl Paste this into the file. - example missing + ad_page_contract { + This is the main page for the package. It displays all of the Notes and provides links to edit them and to create new Notes. + + @author Your Name (you@example.com) + @cvs-id $Id$ +} + +set page_title [ad_conn instance_name] +set context [list] + +template::list::create \ + -name notes \ + -multirow notes \ + -actions { "Add a Note" note-edit} \ + -elements { + edit { + link_url_col edit_url + display_template { + <img src="/resources/acs-subsite/Edit16.gif" width="16" height="16" border="0"> + } + sub_class narrow + } + title { + label "Title" + } + delete { + link_url_col delete_url + display_template { + <img src="/resources/acs-subsite/Delete16.gif" width="16" height="16" border="0"> + } + sub_class narrow + } + } + +db_multirow \ + -extend { + edit_url + delete_url + } notes notes_select { + select ci.item_id, + n.title + from cr_items ci, + mfp_notesx n + where n.revision_id = ci.live_revision + } { + set edit_url [export_vars -base "note-edit" {item_id}] + set delete_url [export_vars -base "note-delete" {item_id}] + } + + Now index.adp: - example missing - You can test your work by viewing the page. - The index page includes the list page, which we put in /lib instead of /www to designate that it's available for reuse by other packages. - [service0 www]$ mkdir /var/lib/aolserver/service0/packages/myfirstpackage/lib -[service0 www]$ cd /var/lib/aolserver/service0/packages/myfirstpackage/lib -[service0 lib]$ emacs note-list.tcl - example missing -[service0 lib]$ emacs note-list.adp -example missing - Create the add/edit page. If note_id is passed in, - it display that note, and can change to edit mode if appropriate. Otherwise, it presents a form for adding notes. - [service0 lib]$ cd /var/lib/aolserver/service0/packages/myfirstpackage/www -[service0 www]$ emacs note-edit.tcl - example missing -[service0 www]$ emacs note-edit.adp - example missing + +<master> + <property name="title">@page_title;noquote@</property> + <property name="context">@context;noquote@</property> +<listtemplate name="notes"></listtemplate> + + Now we create the add/edit page. If note_id is passed in, + it edits that note. Otherwise, it presents a form for adding + notes. Edit + note-edit.tcl: + ad_page_contract { + This is the view-edit page for notes. + @author Your Name (you@example.com) + @cvs-id $Id$ + + @param item_id If present, assume we are editing that note. Otherwise, we are creating a new note. +} { + item_id:integer,optional +} + +ad_form -name note -form { + {item_id:key} + {title:text {label Title}} +} -new_request { + permission::require_permission -object_id [ad_conn package_id] -privilege create + set page_title "Add a Note" + set context [list $page_title] +} -edit_request { + permission::require_write_permission -object_id $item_id + mfp::note::get \ + -item_id $item_id \ + -array note_array + + set title $note_array(title) + + set page_title "Edit a Note" + set context [list $page_title] +} -new_data { + mfp::note::add \ + -title $title \ + -item_id $item_id + set message "Note $title added" +} -edit_data { + mfp::note::edit \ + -item_id $item_id \ + -title $title + set message "Note $title changed" +} -after_submit { + ad_returnredirect -message $message "." + ad_script_abort +} + And note-edit.adp: + <master> + <property name="title">@page_title;noquote@</property> + <property name="context">@context;noquote@</property> + <property name="focus">note.title</property> + +<formtemplate id="note"></formtemplate> And the delete page. Since it has no UI, there is only a - tcl page, and no adp page. -[service0 www]$ emacs note-delete.tcl - example missing + tcl page, and no adp page. Edit +note-delete.tcl: + ad_page_contract { + This deletes a note + + @author Your Name (you@example.com) + @cvs-id $Id$ + + @param item_id The item_id of the note to delete +} { + item_id:integer +} + +permission::require_write_permission -object_id $item_id +set title [item::get_title $item_id] +mfp::note::delete -item_id $item_id +ad_returnredirect -message "Item $title deleted." "." + +