• Publicity: Public Only All

generic-procs.tcl

A simple OO interface for ad_form for acs_objects and content repository items.

This file defines the following Objects and Classes: ::Generic::Form[i], ::Generic::List[i]

Location:
packages/xotcl-core/tcl/generic-procs.tcl
Created:
2005-08-13
Author:
Gustaf Neumann
CVS Identification:
$Id: generic-procs.tcl,v 1.112.2.11 2023/02/27 18:40:21 gustafn Exp $

Procedures in this file

Detailed information

Class ::Generic::Form (public)

 ::xotcl::Class ::Generic::Form[i] [ -add_page_title add_page_title ] \
    [ -edit_page_title edit_page_title ] [ -data data ] \
    [ -folder_id folder_id ] [ -name name ] [ -package_id package_id ] \
    [ -submit_link submit_link ] [ -with_categories with_categories ]

This class was designed together with the content repository class ::xo::db::CrClass for the generation of HTML forms, but it can be used also with different classes. The only hard requirement is the presence of an 'item_id' form field. For generic acs_objects, 'item_id' will correspond to 'object_id' column in 'acs_objects' table. For content repository items, 'item_id' will be the column by the same name in cr_revisions/cr_items.

Switches:
-add_page_title
(optional)
page title when adding content items
-edit_page_title
(optional)
page title when editing content items
-data
(optional)
data object (e.g. instance if CrItem)
-folder_id
(optional)
associated folder id. Will default to data's 'parent_id' variable. If 'parent_id' is missing too, package's 'folder_id' will be used.
-name
(optional)
name of the form, used for naming the template, defaults to the object name
-package_id
(optional)
package_id of the object. Will default to data's 'package_id' variable
-submit_link
(optional)
link for page after submit
-with_categories
(optional)
display form with categories (default false)

Partial Call Graph (max 5 caller/called nodes):
%3 _ _ (public) ad_form ad_form (public) ad_returnredirect ad_returnredirect (public) ad_script_abort ad_script_abort (public) auth::require_login auth::require_login (public) Class ::Generic::Form Class ::Generic::Form Class ::Generic::Form->_ Class ::Generic::Form->ad_form Class ::Generic::Form->ad_returnredirect Class ::Generic::Form->ad_script_abort Class ::Generic::Form->auth::require_login

Testcases:
No testcase defined.

Class ::Generic::List (public)

 ::xotcl::Class ::Generic::List[i] [ -actions actions ] \
    [ -bulk_action_method bulk_action_method ] [ -elements elements ] \
    [ -rows_per_page rows_per_page ] [ -row_code row_code ] \
    [ -class class ] [ -no_create_p no_create_p ] \
    [ -create_url create_url ] [ -no_edit_p no_edit_p ] \
    [ -edit_url edit_url ] [ -edit_template edit_template ] \
    [ -no_delete_p no_delete_p ] [ -delete_url delete_url ] \
    [ -delete_template delete_template ] [ -package_id package_id ] \
    [ -html_class html_class ] [ -html_main_class html_main_class ] \
    [ -html_sub_class html_sub_class ]

Simple OO interface to template::list. This class has been built to allow quick creation of list UIs for generic acs_objects.

Many parameters are homonymous to those for template::list::create and work in the same way, unless stated differently in this documentation.

Despite the high number of object's members, most of them are there for backward compatibility with the procedural API and they seldom need to be specified.

An example of instantiation could just look as this:

    # Must be an existing acs_object class on the system.
    set class "::dev::Location"

    # As we are talking about acs_objects, our 'delete'
    # page could of course be the same for every object
    # in the system.
    ::Generic::List create list1  -class $class  -package_id $package_id  -rows_per_page $rows_per_page  -delete_url "../delete"  -elements {
          name {
            label "Name"
          }
          street {
            label "Street"
          }
          number {
            label "Number"
          }
          city {
            label "City"
          }
          region {
            label "Region"
          }
          country {
            label "Country"
          }
          coords {
            label "Coordinates"
          }
        } -orderby {
          default_value name
          name {
            label "Name"
            orderby_desc "name desc"
            orderby_asc "name asc"
          }
        } -row_code {
          set coords "$latitude $longitude"
        }

    list1 generate
    
...while the ADP template would include this:
    <listtemplate name="list1"></listtemplate>
    
Notice that in this case we didn't have to specify queries, nor populate any multirow by hand: they have come directly from class's data-model. A list built in this way will be paginated automatically.

Switches:
-actions
(optional)
Behaves as in template::list::create. If missing, can be automatically generated acting on create_url and no_create_p parameters (see below).
-bulk_action_method
(optional)
Behaves as in template::list::create, but will default to POST method, as it is safer with respect to possible high number of query parameters.
-elements
(optional)
Behaves as in template::list::create. It must be possible to build every element either through class's instance members, or programmatically (see row_code below).
-rows_per_page
(optional)
Behaves as template::list::create's page_size parameter. Pagination is automatically for this class. To turn it off, just set this parameter to "" .
-row_code
(optional)
This snippet will be executed for every instance/row in the list, so is similar in spirit to code_block argument for db_multirow. This will allow the user to build programmatically other elements outside object's data model, override edit and delete url and so on. Code will have access to every variable in the caller scope and to each instance's variable.
-class
(optional)
Is the class (descendant of acs_object) for which this list will be built.
-no_create_p
(optional)
Tells to the list we don't want instance creation action button to be built automatically.
-create_url
(optional)
When instance creation url is automatically built, tells the list to which url make it point.
-no_edit_p
(optional)
Tells to the list we don't want instance edit action button to be built automatically.
-edit_url
(optional)
When instance edit element is automatically built, tells the list to which url make it point. Page pointed must accept an item_id parameter, that will be the primary key of edited instance.
-edit_template
(optional)
When instance edit element is automatically built, use this template to build the element.
-no_delete_p
(optional)
Tells to the list we don't want instance delete action button to be built automatically.
-delete_url
(optional)
When instance delete url is automatically built, tells the list to which url make it point. Page pointed must accept an item_id parameter, that will be the primary key of deleted instance.
-delete_template
(optional)
When instance delete element is automatically built, use this template to build the element.
-package_id
(optional)
Is the package for this instance. It has no use for now.
-html_class
(optional)
Behaves as class parameter in template::list::create.
-html_main_class
(optional)
Behaves as main_class parameter in template::list::create.
-html_sub_class
(optional)
Behaves as sub_class parameter in template::list::create.
Author:
Antonio Pisano <antonio@elettrotecnica.it>

Partial Call Graph (max 5 caller/called nodes):
%3 _ _ (public) export_vars export_vars (public) nsf::object::alloc nsf::object::alloc nx::slotObj nx::slotObj template::add_confirm_handler template::add_confirm_handler (public) Class ::Generic::List Class ::Generic::List Class ::Generic::List->_ Class ::Generic::List->export_vars Class ::Generic::List->nsf::object::alloc Class ::Generic::List->nx::slotObj Class ::Generic::List->template::add_confirm_handler

Testcases:
No testcase defined.

Generic::Form instproc generate (public)

 <instance of Generic::Form[i]> generate [ -template template ] \
    [ -mode mode ] [ -export export ]

The method generate is used to actually generate the form template from the specifications and to set up page_title and context when appropriate.

Switches:
-template
(defaults to "formTemplate") (optional)
is the name of the Tcl variable to contain the filled in template
-mode
(defaults to "edit") (optional)
-export
(optional)
list of attribute value pairs to be exported to the form (nested list)

Partial Call Graph (max 5 caller/called nodes):
%3 test_xowiki_test_cases xowiki_test_cases (test xowiki) Generic::Form instproc generate Generic::Form instproc generate test_xowiki_test_cases->Generic::Form instproc generate ad_form ad_form (public) Generic::Form instproc generate->ad_form category::ad_form::add_widgets category::ad_form::add_widgets (public) Generic::Form instproc generate->category::ad_form::add_widgets category::ad_form::fill_widgets category::ad_form::fill_widgets (public) Generic::Form instproc generate->category::ad_form::fill_widgets category::ad_form::get_categories category::ad_form::get_categories (public) Generic::Form instproc generate->category::ad_form::get_categories category::map_object category::map_object (public) Generic::Form instproc generate->category::map_object

Testcases:
xowiki_test_cases
[ show source ]