Index: openacs-4/packages/acs-core-docs/www/tutorial-categories.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/tutorial-categories.adp,v diff -u -r1.4.2.7 -r1.4.2.8 --- openacs-4/packages/acs-core-docs/www/tutorial-categories.adp 27 Apr 2022 16:52:20 -0000 1.4.2.7 +++ openacs-4/packages/acs-core-docs/www/tutorial-categories.adp 13 Jul 2023 12:43:23 -0000 1.4.2.8 @@ -1,11 +1,11 @@ -{/doc/acs-core-docs {ACS Core Documentation}} {Categories} +{/doc/acs-core-docs/ {ACS Core Documentation}} {Categories} Categories

@@ -36,10 +36,12 @@ Management pages. Add the following snippet to your /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/www/admin/index.tcl file:

                   set category_map_url [export_vars -base "[site_node::get_package_url -package_key categories]cadmin/one-object" { { object_id $package_id } }]
-          

and the following snippet to your /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/www/admin/index.adp + +

and the following snippet to your /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/www/admin/index.adp file:

                   <a href="\@category_map_url\@">#­categories.Site_wide_Categories#</a>
-          

The link created by the above code (category_map_url) will take the admin to + +

The link created by the above code (category_map_url) will take the admin to the generic admin UI where he can pick category trees that make sense for this application. The same UI also includes facilities to build and edit category trees. Notice that the only parameter in @@ -77,7 +79,8 @@ ad_returnredirect "." ad_script_abort } -

While the category::ad_form::add_widgets proc is + +

While the category::ad_form::add_widgets proc is taking care to extend your form with associated categories you need to ensure that your items are mapped to the corresponding category object yourself.

@@ -92,8 +95,10 @@ need the extra features of ad_form. The form calls itself, but with hidden variables carrying both note_id and confirm_p. If confirm_p is present, we delete the record, set redirection back to the index, and abort -script execution.

The database commands:

[$OPENACS_SERVICE_NAME\@yourserver www]$ emacs note-delete.xql
-
<?xml version="1.0"?>
+script execution.

The database commands:

+[$OPENACS_SERVICE_NAME\@yourserver www]$ emacs note-delete.xql
+
+<?xml version="1.0"?>
 <queryset>
   <fullquery name="do_delete">
     <querytext>
@@ -105,14 +110,17 @@
       select samplenote__name(:note_id)
     </querytext>
   </fullquery>
-</queryset>

And the adp page:

[$OPENACS_SERVICE_NAME\@yourserver www]$ emacs note-delete.adp
+</queryset>
+

And the adp page:

+[$OPENACS_SERVICE_NAME\@yourserver www]$ emacs note-delete.adp
 
 <master>
 <property name="title">\@title\@</property>
 <property name="context">{\@title\@}</property>
 <h2>\@title\@</h2>
 <formtemplate id="note-del-confirm"></formtemplate>
-</form>

The ADP is very simple. The formtemplate tag outputs the HTML form +</form> +

The ADP is very simple. The formtemplate tag outputs the HTML form generated by the ad_form command with the matching name. Test it by adding the new files in the APM and then deleting a few samplenotes.

@@ -124,12 +132,14 @@ and the default value "0".

Add the following lines to your index.tcl:

           set return_url [ns_conn url]
           set use_categories_p [parameter::get -parameter "EnableCategoriesP"]
-          

Change your to this:

+          
+

Change your to this:

                         <a href=configure?<%=[export_vars -url {return_url}]%>>Configure</a>
                         <if \@use_categories_p\@>
                         <a href="\@category_map_url\@">#­categories.Site_wide_Categories#</a>
                         </if>
-          

Now create a configure page

+          
+

Now create a configure page

                 ad_page_contract {
                         This page allows an admin to change the categories usage mode.
                         } {
@@ -154,27 +164,31 @@
                                 ns_returnredirect $return_url
                         }
                         }
-           

and add this to its corresponding ADP page

+           
+

and add this to its corresponding ADP page

                 <master>
                         <property name="title">\@title\@</property>
                         <property name="context">\@context\@</property>
 
                         <formtemplate id="categories_mode"></formtemplate>
-              

Reference this page from your admin page

+              
+

Reference this page from your admin page

                 #TCL:
                 set return_url [ad_conn url]
 
                 #ADP:
                 <a href=configure?<%=[export_vars -url {return_url}]%>>Configure</a>
-                

Change the note-edit.tcl:

+                
+

Change the note-edit.tcl:

                 # Use Categories?
                 set use_categories_p [parameter::get -parameter "EnableCategoriesP" -default 0]
                 if { $use_categories_p == 1 } {
                         # YOUR NEW FORM DEFINITION
                 } else {
                 # YOUR OLD FORM DEFINITION
                 }
-        
+ +
  • You can filter your notes using categories. The below example does not support multiple filters and displays a category in a flat @@ -185,7 +199,8 @@ YOURPARAMS {category_id:integer,optional {}} } -

    Now you have to check whether categories are enabled or not. If + +

    Now you have to check whether categories are enabled or not. If this is the case and a category id is passed you need to extend your sql select query to support filtering. One way would be to extend the mfp::note::get proc @@ -209,7 +224,8 @@ } else { # OLD STUFF } -

    Also you need to make sure that the user can see the + +

    Also you need to make sure that the user can see the corresponding categories. Add the following snippet to the end of your index page:

               # Site-Wide Categories
    @@ -243,7 +259,8 @@
                             set tree_name [category_tree::get_name $tree_id]
                     }
                     }
    -                

    and to the corresponding index ADP page:

    +                
    +

    and to the corresponding index ADP page:

                     <if \@use_categories_p\@>
                             <multiple name="categories">
                             <h2>\@categories.tree_name\@
    @@ -252,16 +269,19 @@
                             </group>
                     </multiple>
                     <a href="\@package_url\@view?\@YOURPARAMS\@">All Items</if>
    -          

    Finally you need an index.vuh in your www folder to rewrite the -URLs correctly, the section called “Using .vuh -files for pretty URLs”:

    +          
    +

    Finally you need an index.vuh in your www folder to rewrite the +URLs correctly, the section called +“Using .vuh files for pretty +URLs”:

               set url /[ad_conn extra_url]
     
               if {[regexp {^/+cat/+([^/]+)/*} $url ignore_whole category_id]} {
                   rp_form_put category_id $category_id
               }
               rp_internal_redirect "/packages/YOURPACKAGE/www/index"          
    -          

    Now when ever the user select a category only notes that belong + +

    Now when ever the user select a category only notes that belong to this category are displayed.