Begin main content
Methods: Source: Variables:
[All Methods | Documented Methods | Hide Methods] [Display Source | Hide Source] [Show Variables | Hide Variables]

::xotcl::Class[i] ::Generic::Form

Class Hierarchy of ::Generic::Form

  • ::xotcl::Object[i]
    Methods for instances:
    __api_make_doc, __api_make_forward_doc, __timediff, abstract, ad_doc, ad_forward, ad_proc, appendC, arrayC, asHTML, autonameC, check, classC, cleanupC, configureC, containsC, copyC, db_0or1rowC, db_1rowC, debug, defaultmethodC, destroyC, destroy_on_cleanup, dot_append_method, dotclass, dotcode, dotquote, dotquotel, ds, evalC, existsC, extractConfigureArg, filterC, filterguardC, filtersearch, forward, hasclass, incrC, infoC, init, instvarC, invarC, isclass, ismetaclass, ismixin, isobject, istype, lappendC, log, method, mixinC, mixinguardC, moveC, msg, noinitC, objectparameter, parametercmdC, proc, procsearch, qn, requireNamespaceC, residualargsC, self, serialize, setC, set_instance_vars_defaults, show-object, substC, traceC, unknown, unsetC, uplevelC, upvarC, volatileC, vwait
    Methods to be applied on the class (in addition to the methods provided by the meta-class):
    getExitHandler, setExitHandler, unsetExitHandler
    • ::Generic::Form[i]
      Parameter for instances:
      action (default "[::xo::cc url]"), add_page_title, data, edit_page_title, fields, folder_id (default "-100"), html (default ""), name (default "[namespace tail [self]]"), submit_link (default "."), validate (default ""), with_categories (default "false")
      Methods for instances:
      after_submit, edit_data, edit_request, form_vars, generate, init, new_data, new_request, on_submit, on_validation_error, request, set_form_data
      Methods to be applied on the class:
      Methods provided by the meta-class
Class for the simplified generation of forms. This class was designed together with the content repository class ::xo::db::CrClass.
  • fields: form elements as described in ad_form.
  • data: data object (e.g. instance if CrItem)
  • folder_id: associated folder id
  • name: of this form, used for naming the template, defaults to the object name
  • add_page_title: page title when adding content items
  • edit_page_title: page title when editing content items
  • with_categories: display form with categories (default false)
  • submit_link: link for page after submit
Defined in packages/xotcl-core/tcl/generic-procs.tcl

Class Relations

  • superclass: ::xotcl::Object[i]
  • subclass: ::xowiki::WikiForm[i]
::xotcl::Class create ::Generic::Form \
     -superclass ::xotcl::Object \
     -parameter {{action "[::xo::cc url]"} add_page_title data edit_page_title fields \
       {folder_id -100} {html ""} {name {[namespace tail [self]]}} {submit_link "."} {validate ""} \
       {with_categories false}}


  • instproc after_submit

    ::xowiki::policy5 instproc after_submit item_id {
        my instvar data
        set link [my submit_link]
        if {$link eq "view"} {
          set link [export_vars -base $link {item_id}]
        #ns_log notice "-- redirect to $link // [string match *\?* $link]"
        ad_returnredirect $link
  • instproc edit_data

    ::xowiki::policy5 instproc edit_data {} {
        #my log "--- edit_data --- setting form vars=[my form_vars]"
        my instvar data
        foreach __var [my form_vars] {
          $data set $__var [my var $__var]
        $data initialize_loaded_object
        db_transaction {
          $data save
          set old_name [::xo::cc form_parameter __object_name ""]
          set new_name [$data set name]
          if {$old_name ne $new_name} {
            #my msg "rename from $old_name to $new_name"
            $data rename -old_name $old_name -new_name $new_name
        return [$data set item_id]
  • instproc edit_request

    ::xowiki::policy5 instproc edit_request item_id {
        #my log "--- edit_request ---"
        my request write
        my set_form_data
  • instproc form_vars

    ::xowiki::policy5 instproc form_vars {} {
        set vars [list]
        foreach varspec [my fields] {
          lappend vars [lindex [split [lindex $varspec 0] :] 0]
        return $vars
  • instproc generate (public)

    <instance of ::Generic::Form[i]> generate [ -template template ] \
        [ -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.

    -template (defaults to "formTemplate") (optional)
    -export (optional)
    ::xowiki::policy5 instproc generate {{-template "formTemplate"} -export} {
        # set form name for adp file
        my set $template [my name]
        my instvar data folder_id
        set object_type [[$data info class] object_type]
        if {[catch {set object_name [$data set name]}]} {set object_name ""}
        #my log "-- $data, cl=[$data info class] [[$data info class] object_type]"
        #my log "--e [my name] final fields [my fields]"
        set exports [list [list object_type $object_type]  [list folder_id $folder_id]  [list __object_name $object_name]] 
        if {[info exists export]} {foreach pair $export {lappend exports $pair}}
        ad_form -name [my name] -form [my fields]  -export $exports -action [my action] -html [my html]
        set new_data            "set item_id \[[self] new_data\]"
        set edit_data           "set item_id \[[self] edit_data\]"
        set new_request         "[self] new_request"
        set edit_request        "[self] edit_request \$item_id"
        set after_submit        "[self] after_submit \$item_id"
        set on_validation_error "[self] on_validation_error"
        set on_submit           "[self] on_submit \$item_id"
        if {[my with_categories]} {
          set coid [expr {[$data exists item_id] ? [$data set item_id] : ""}]
          category::ad_form::add_widgets -form_name [my name]  -container_object_id [$data package_id]  -categorized_object_id $coid
          append new_data {
            category::map_object -remove_old -object_id $item_id $category_ids
            #ns_log notice "-- new data category::map_object -remove_old -object_id $item_id $category_ids"
            #db_dml [my qn insert_asc_named_object]  #    "insert into acs_named_objects (object_id,object_name,package_id)  #     values (:item_id, :name, :package_id)"
          append edit_data {
            #db_dml [my qn update_asc_named_object]  #    "update acs_named_objects set object_name = :name,  #        package_id = :package_id where object_id = :item_id"
            #ns_log notice "-- edit data category::map_object -remove_old -object_id $item_id $category_ids"
            category::map_object -remove_old -object_id $item_id $category_ids
          append on_submit {
            set category_ids [category::ad_form::get_categories  -container_object_id $package_id]
        #ns_log notice "-- ad_form new_data=<$new_data> edit_data=<$edit_data> edit_request=<$edit_request>"
        # action blocks must be added last
        ad_form -extend -name [my name]  -validate [my validate]  -new_data $new_data -edit_data $edit_data -on_submit $on_submit  -new_request $new_request -edit_request $edit_request  -on_validation_error $on_validation_error -after_submit $after_submit
  • instproc init

    ::xowiki::policy5 instproc init {} {
        set level [template::adp_level]
        my forward var uplevel #$level set 
        my instvar data folder_id
        set package_id [$data package_id]
        set folder_id [expr {[$data exists parent_id] ? [$data parent_id] : [$package_id folder_id]}]
        set class     [$data info class]
        if {![my exists add_page_title]} {
          my set add_page_title [_ xotcl-core.create_new_type  [list type [$class pretty_name]]]
        if {![my exists edit_page_title]} {
          my set edit_page_title [_ xotcl-core.edit_type  [list type [$class pretty_name]]]
        # check, if the specified fields are available from the data source
        # and ignore the unavailable entries
        set checked_fields [list]
        set available_atts [$class array names db_slot]
        #my log "-- available atts <$available_atts>"
        lappend available_atts [$class id_column] item_id
        if {![my exists fields]} {my mkFields}
        #my log --fields=[my fields]
  • instproc new_data

    ::xowiki::policy5 instproc new_data {} {
        my instvar data
        #my log "--- new_data ---"
        foreach __var [my form_vars] {
          $data set $__var [my var $__var]
        $data initialize_loaded_object
        $data save_new
        return [$data set item_id]
  • instproc new_request

    ::xowiki::policy5 instproc new_request {} {
        #my log "--- new_request ---"
        my request create
        my set_form_data
  • instproc on_submit

    ::xowiki::policy5 instproc on_submit item_id {
        # The content of this proc is strictly speaking not necessary.
        # However, on redirects after a submit to the same page, it
        # ensures the setting of edit_form_page_title and context
        my request write
  • instproc on_validation_error

    ::xowiki::policy5 instproc on_validation_error {} {
        my instvar edit_form_page_title context
        #my log "-- "
        set edit_form_page_title [my edit_page_title]
        set context [list $edit_form_page_title]
  • instproc request

    ::xowiki::policy5 instproc request privilege {
        my instvar edit_form_page_title context data
        set package_id [$data package_id]
        if {[my isobject ::$package_id] && ![::$package_id exists policy]} {
          # not needed, if governed by a policy
          permission::require_permission  -object_id $package_id  -privilege $privilege
        set edit_form_page_title [if {$privilege eq "create"}  {my add_page_title} {my edit_page_title}]
        set context [list $edit_form_page_title]
  • instproc set_form_data

    ::xowiki::policy5 instproc set_form_data {} {
        my instvar data
        foreach var [[$data info class] array names db_slot] {
          if {[$data exists $var]} {
            my var $var [list [$data set $var]]

Methods: Source: Variables:
[All Methods | Documented Methods | Hide Methods] [Display Source | Hide Source] [Show Variables | Hide Variables]