xotcl.wu-wien.ac.at
Begin main content
Methods: Source: Variables:
[All Methods | Documented Methods | Hide Methods] [Display Source | Hide Source] [Show Variables | Hide Variables]

::xowiki::IncludeletClass[i] ::xowiki::includelet::form-usages

Class Hierarchy of ::xowiki::includelet::form-usages

  • ::xotcl::Object[i]
    Meta-class:
    ::xotcl::Class[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, 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
    • ::xo::Context[i]
      Meta-class:
      ::xotcl::Class[i]
      Parameter for instances:
      actual_query (default " "), locale, package_id (default "0"), parameter_declaration (default "")
      Methods for instances:
      exists_query_parameter, export_vars, get_all_query_parameter, get_parameters, initialize, original_url_and_query, process_query_parameter, query_parameter
      Methods to be applied on the class:
      Methods provided by the meta-class
      • ::xowiki::Includelet[i]
        Meta-class:
        ::xotcl::Class[i]
        Parameter for instances:
        __decoration (default "portlet"), id, name (default ""), parameter_declaration (default ""), title (default "")
        Methods for instances:
        category_clause, get_page_order, include_head_entries, initialize, js_name, resolve_page_name, screen_name
        Methods to be applied on the class (in addition to the methods provided by the meta-class):
        available_includelets, describe_includelets, glob_clause, html_encode, html_id, html_to_text, js_encode, js_name, listing, locale_clause, parent_id_clause, publish_status_clause, require_YUI_CSS, require_YUI_JS
        • ::xowiki::includelet::form-usages[i]
          Meta-class:
          ::xowiki::IncludeletClass[i]
          Parameter for instances:
          __decoration (default "plain"), parameter_declaration (default " {-form_item_id:integer} {-form} {-parent_id} {-package_ids ""} {-orderby "_last_modified,desc"} {-view_field _name} {-publish_status "all"} {-field_names} {-hidden_field_names ""} {-extra_form_constraints ""} {-inherit_from_forms ""} {-category_id} {-unless} {-where} {-csv true} {-voting_form} {-voting_form_form ""} {-voting_form_anon_instances "t"} {-generate} {-with_form_link true} {-with_categories} {-wf} {-buttons "edit delete"} {-renderer ""} ")
          Methods for instances:
          generate_voting_form, render
          Methods to be applied on the class:
          Methods provided by the meta-class

Class Relations

  • superclass: ::xowiki::Includelet[i]
::xowiki::IncludeletClass create ::xowiki::includelet::form-usages \
     -superclass ::xowiki::Includelet \
     -parameter {{__decoration plain} {parameter_declaration {
          {-form_item_id:integer}
          {-form}
          {-parent_id}
          {-package_ids ""}
          {-orderby "_last_modified,desc"}
	  {-view_field _name}
          {-publish_status "all"}
          {-field_names}
          {-hidden_field_names ""}
          {-extra_form_constraints ""}
          {-inherit_from_forms ""}
          {-category_id}
          {-unless}
          {-where}
          {-csv true}
          {-voting_form}
          {-voting_form_form ""}
          {-voting_form_anon_instances "t"}
          {-generate}
          {-with_form_link true}
          {-with_categories}
          {-wf}
          {-buttons "edit delete"}
          {-renderer ""}
        }}}

Methods

  • instproc generate_voting_form

    ::423385 instproc generate_voting_form {form_name form_form t1 field_names voting_form_anon_instances} {
        #my msg "generate_voting anon=$voting_form_anon_instances"
        set form "<form> How do you rate<br /> 
        <table rules='all' frame='box' cellspacing='1' cellpadding='1' border='0' style='border-style: none;'>
          <tbody> 
            <tr> 
              <td style='border-style: none;'> </td> 
              <td style='border-style: none; text-align: left; width: 150px;'>&nbsp;very good<br /></td> 
              <td align='right' style='border-style: none; text-align: right; width: 150px;'>&nbsp;very bad<br /></td> 
            </tr> \n"
     
        # We use here the table t1 to preserve sorting etc. 
        # The basic assumption is that every line of the table has an instance variable
        # corresponding to the wanted field name. This is guaranteed by the construction
        # in form-usages.
        set count 0
        set table_field_names [list]
        foreach t [$t1 children] {
          incr count
          lappend table_field_names $count
          # In most situations, it seems useful to have just one field in
          # the voting table. If there are multiple, we use a comma to
          # separate the values (looks bettern than separate columns).
          set field_contents [list]
          foreach __fn $field_names {
            lappend field_contents [$t set $__fn]
          }
          append form "<tr><td>[join $field_contents {, }]</td><td align='center' colspan='2'>@$count@</td></tr>\n"
        }
    
        append form "</tbody></table></form>\n"
        lappend table_field_names _last_modified _creation_user
    
        # Check, of we have a form for editing the generated form. If yes, we will
        # instantiate a form page from it.
        set form_form_id 0 
        if {$form_form ne ""} { 
          set form_form_id  [::xo::db::CrClass lookup -name $form_form -parent_id [[my package_id] folder_id]] 
        } 
        # The normal form requires for rich-text the 2 element list as content
        if {$form_form_id == 0} { set form [list $form text/html] }
    
        set item_id [::xo::db::CrClass lookup -name $form_name -parent_id [[my package_id] folder_id]]
        if {$item_id == 0} {
          
          if {$form_form_id == 0} {
            set f [::xowiki::Form new  -package_id [my package_id]  -parent_id [[my package_id] folder_id]  -name $form_name  -anon_instances $voting_form_anon_instances  -form $form  -form_constraints "@fields:scale,n=7,inline=true @cr_fields:hidden @categories:off\n @table:[join $table_field_names ,]"  ]
          } else {
            set f [::xowiki::FormPage new  -page_template $form_form_id  -package_id [my package_id]  -parent_id [[my package_id] folder_id]  -name $form_name]
            $f set_property anon_instances $voting_form_anon_instances
            $f set_property form $form
            $f set_property form_constraints "@fields:scale,n=7,inline=true @cr_fields:hidden @categories:off\n @table:[join $table_field_names ,]"
          }
          $f save_new
          set form_href [$f pretty_link]
          $f destroy
          set action created
        } else {
          ::xo::db::CrClass get_instance_from_db -item_id $item_id
          if {$form_form_id == 0} {
            $item_id form $form
          } else {
            $item_id set_property form $form
          }
          $item_id save
          set form_href [$item_id pretty_link]
          set action updated
        }
        return "#xowiki.form-$action# <a href='$form_href'>$form_name</a>"
      }
    
  • instproc render

    ::423385 instproc render {} {
        my get_parameters
    
        my instvar __including_page
        set o $__including_page
        ::xo::Page requireCSS "/resources/acs-templating/lists.css"
        set return_url [::xo::cc url]?[::xo::cc actual_query]
    
        if {[info exists parent_id]} {
          if {$parent_id eq "self"} {
            set parent_id [$__including_page item_id]
          }
        } else {
          set parent_id [$o parent_id]
        }
        
        if {![info exists form_item_id]} {
          # Start for search for form in the directory of the including
          # form.  The provided package_id and parent_id refers to the
          # form instances, not to the forms.
          set form_item_ids [::xowiki::Weblog instantiate_forms -parent_id $parent_id  -parent_id [$o parent_id]  -default_lang [$o lang]  -forms $form -package_id [$o package_id]]
        } else {
          set form_item_ids [list $form_item_id]
        }
    
        set form_constraints $extra_form_constraints\n
    
        if {$inherit_from_forms ne ""} {
          foreach inherit_form $inherit_from_forms {
            set inherit_form_id [::xowiki::Weblog instantiate_forms  -parent_id [$o parent_id]  -default_lang [$o lang]  -forms $inherit_form -package_id [$o package_id]]
            if {$inherit_form_id ne ""} {
              set p [$inherit_form_id property form_constraints]
              append form_constraints $p\n
            }
          }
        }
    
        foreach form_item $form_item_ids {
          append form_constraints [$form_item get_form_constraints -trylocal true] \n
        }
        #my msg fc=$form_constraints
    
        # 
        # The internal variables (instance attributes, etc) are prefixed
        # with an underscore. Therefore, we prefix here "orderby" as
        # well. For the provided table properties, prefixing happens in
        # the loop below.
        #
        set orderby _$orderby
    
        # load table properties; order_by won't work due to comma, but solve that later (TODO)
        set table_properties [::xowiki::PageInstance get_list_from_form_constraints  -name @table_properties  -form_constraints $form_constraints]
        foreach {attr value} $table_properties {
          switch $attr {
            orderby {set $attr _[::xowiki::formfield::FormField fc_decode $value]}
            buttons - publish_status - category_id - unless -
            where -   with_categories - with_form_link - csv - view_field - 
    	voting_form - voting_form_form - voting_form_anon_instances {
              set $attr $value
              #my msg " set $attr $value"
            }
            default {error "unknown table property '$attr' provided"}
          }
        }
    
        if {![info exists field_names]} {
          set fn [::xowiki::PageInstance get_short_spec_from_form_constraints  -name @table  -form_constraints $form_constraints]
          set raw_field_names [split $fn ,]
        } elseif {[string match "*,*" $field_names] } {
          set raw_field_names [split $field_names ,]
        } else {
          set raw_field_names $field_names
        }
    
        foreach fn $hidden_field_names {
          set __hidden($fn) 1
          lappend raw_field_names $fn
        }
    
        if {$raw_field_names eq ""} {
          set raw_field_names {_name _last_modified _creation_user}
        }
    
        # finally, evaluate conditions if included
        set field_names [list]
        foreach f $raw_field_names {
          set _ [string trim [::xowiki::formfield::FormField get_single_spec  -object $o -package_id $package_id $f]]
          if {$_ ne ""} {lappend field_names $_}
        }
    
        foreach form_item $form_item_ids {
          set form_fields [::xowiki::FormPage get_table_form_fields  -base_item $form_item  -field_names $field_names  -form_constraints $form_constraints]
          #$form_item show_fields $form_fields
          foreach f $form_fields {set __ff([$f name]) $f}
        }
        # if {[info exists __ff(_creation_user)]} {$__ff(_creation_user) label "By User"}
    
        # TODO: wiki-substitution is just foced in here. Maybe it makes
        # more sense to use it as a default for _text, but we have to
        # check all the nested cases to avoid double-substitutions.
        if {[info exists __ff(_text)]} {$__ff(_text) set wiki 1}
    
        foreach b $buttons {set use_button($b) 1}
    
        set cols ""
        if {[info exists use_button(edit)]} {
          append cols {AnchorField _edit -CSSclass edit-item-button -label ""  -html {style "padding: 2px;"} -no_csv 1 -richtext 1} \n
        }
        if {[info exists use_button(view)]} {
          append cols {AnchorField _view -CSSclass view-item-button -label ""  -html {style "padding: 2px;"} -no_csv 1 -richtext 1} \n
        }
        foreach fn $field_names {
          if {[info exists __hidden($fn)]} continue
          append cols [list AnchorField _$fn  -label [$__ff($fn) label]  -richtext 1  -orderby _$fn  ] \n
        }
        if {[info exists use_button(delete)]} {
          #append cols [list ImageField_DeleteIcon _delete -label "" -no_csv 1] \n
          append cols [list AnchorField _delete -CSSclass delete-item-button -label "" -no_csv 1 -richtext 1] \n
        }
    
        set cmd [list TableWidget t1 -volatile -columns $cols]
        if {$renderer ne ""} {
          lappend cmd -renderer $renderer
        } elseif {[info command ::xo::Table::YUIDataTableRenderer] ne ""} {
          lappend cmd -renderer YUIDataTableRenderer
        }
        eval $cmd
    
        #
        # Sorting is done for the time being in Tcl. This has the advantage
        # that page_order can be sorted with the special mixin and that
        # instance attributes can be used for sorting as well.
        #
        foreach {att order} [split $orderby ,] break
        if {$att eq "__page_order"} {
          t1 mixin add ::xo::OrderedComposite::IndexCompare
        }
        #my msg "order=[expr {$order eq {asc} ? {increasing} : {decreasing}}] $att"
        t1 orderby -order [expr {$order eq "asc" ? "increasing" : "decreasing"}] $att
    
        # 
        # Compute filter clauses
        #
        set init_vars [list]
        array set uc {tcl false h "" vars "" sql ""}
        if {[info exists unless]} {
          array set uc [::xowiki::FormPage filter_expression $unless ||]
          set init_vars [concat $init_vars $uc(vars)]
        }
        array set wc {tcl true h "" vars "" sql ""}
        if {[info exists where]} {
          array set wc [::xowiki::FormPage filter_expression $where &&]
          set init_vars [concat $init_vars $wc(vars)]
        }
        #my msg uc=[array get uc]
        #my msg wc=[array get wc]
    
        #
        # get an ordered composite of the base set (currently including extra_where clause)
        # 
        #my log "exists category_id [info exists category_id]"
        set extra_where_clause ""
        if {[info exists category_id]} {
          foreach {cnames extra_where_clause} [my category_clause $category_id bt.item_id] break
        }
    
        set items [::xowiki::FormPage get_form_entries  -base_item_ids $form_item_ids  -parent_id $parent_id  -form_fields $form_fields  -publish_status $publish_status  -extra_where_clause $extra_where_clause  -h_where [array get wc]  -from_package_ids $package_ids  -package_id $package_id]
    
        if {[info exists with_categories]} {
          if {$extra_where_clause eq ""} {
            set base_items $items
          } else {
            # difference to variable items: just the extra_where_clause
            set base_items [::xowiki::FormPage get_form_entries  -base_item_ids $form_item_ids  -parent_id $parent_id  -form_fields $form_fields  -publish_status $publish_status  -h_where [array get wc]  -from_package_ids $package_ids  -package_id $package_id]
          }
        }
        #my log "queries done"
        if {[info exists wf]} {
          set wf_link [$package_id pretty_link -parent_id $parent_id $wf]
        }
    
        foreach p [$items children] {
          $p set package_id $package_id
          array set __ia $init_vars
          array set __ia [$p instance_attributes]
          if {[expr $uc(tcl)]} continue
          #if {![expr $wc(tcl)]} continue ;# already handled in get_form_entries
    
          set page_link [$p pretty_link]
    
          if {[info exists wf]} {
    	set view_link $wf_link?m=create-or-use&p.form=[$p name]
          } else {
    	set view_link $page_link
          }
          t1 add
          set __c [t1 last_child]
    
          if {[info exists use_button(edit)]} {
    	$__c set _edit "&nbsp;"
    	$__c set _edit.title Edit
    	#set template_file view-default
    	$__c set _edit.href [$package_id make_link -link $page_link $p edit return_url template_file] 
          }
          if {[info exists use_button(delete)]} {
    	$__c set _delete "&nbsp;"
    	$__c set _delete.title Delete
    	$__c set _delete.href [$package_id make_link -link $page_link $p delete return_url] 
          }
          if {[info exists use_button(view)]} {
    	$__c set _view "&nbsp;"
    	$__c set _view.title View
    	$__c set _view.href $view_link
          } elseif {![info exists use_button(no-view)]} {
    	#
    	# Set always a view link, if we have no view button ...
    	#
    	if {[info exists __ff($view_field)]} {
    	  # .... on $view_field) (per default: _name) ....
    	  $__c set _$view_field.href $view_link
    	} else {
    	  # .... otherwise on the first form_field
    	  $__c set _[lindex $field_names 0].href $view_link
    	}
          }
    
          # set always last_modified for default sorting
          $__c set __last_modified [$p set last_modified]
    
    
          foreach __fn $field_names {
            $__ff($__fn) object $p
            $__c set _$__fn [$__ff($__fn) pretty_value [$p property $__fn]]
          }
          $__c set __name [$package_id external_name -parent_id [$p parent_id] [$p name]]
        }
    
        #
        # If there are multiple includelets on a single page,
        # we have to identify the right one for e.g. producing the
        # csv table. Therefore, we compute an includelet_key
        #
        my instvar name
        set includelet_key ""
        foreach var {name form_item_ids form publish_states field_names unless} {
          if {[info exists $var]} {append includelet_key $var : [set $var] ,}
        }
    
        if {[info exists voting_form]} {
          # if the user provided a voting form name without a language prefix,
          # add one.
          if {![regexp {^..:} $voting_form]} {
            set obj [my set __including_page]
            set voting_form [$obj lang]:$voting_form
          }
        }
    
        set given_includelet_key [::xo::cc query_parameter includelet_key ""]
        if {$given_includelet_key ne ""} {
          if {$given_includelet_key eq $includelet_key && [info exists generate]} {
            if {$generate eq "csv"} {
              return [t1 write_csv]
            } elseif {$generate eq "voting_form"} {
              return [my generate_voting_form $voting_form $voting_form_form t1 $field_names $voting_form_anon_instances]
            }
          }
          return ""
        }
    
        set links [list]
        set base [$form_item pretty_link]
        set label [$form_item name]
    
        if {$with_form_link} {
          append html [_ xowiki.entries_using_form [list form "<a href='$base'>$label</a>"]]
        }
        append html [t1 asHTML]
    
        if {$csv} {
          set csv_href "[::xo::cc url]?[::xo::cc actual_query]&includelet_key=[ns_urlencode $includelet_key]&generate=csv"
          lappend links "<a href='$csv_href'>csv</a>"
        }
        if {[info exists voting_form]} {
          set href "[::xo::cc url]?[::xo::cc actual_query]&includelet_key=[ns_urlencode $includelet_key]&generate=voting_form"
          lappend links " <a href='$href'>Generate Voting Form $voting_form</a>"
        }
        append html [join $links ,]
        #my log "render done"
    
        if {[info exists with_categories]} {
          set category_html [$o include [list categories -count 1 -tree_name $with_categories  -ordered_composite $base_items]]
          return "<div style='width: 15%; float: left;'>$category_html</div></div width='69%'>$html</div>\n"
        }
        return $html
      }
    

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