Class ::xowiki::includelet::form-usages
::xowiki::includelet::form-usages
create ... \
[ -__decoration (default "plain") ] \
[ -parameter_declaration (default "
{-form_item_id:integer,1..n}
{-form}
{-parent_id}
{-package_ids ""}
{-orderby "_raw_last_modified,desc"}
{-view_field _name}
{-publish_status "all"}
{-field_names}
{-hidden_field_names "_last_modified"}
{-extra_form_constraints ""}
{-inherit_from_forms ""}
{-category_id}
{-unless}
{-where}
{-extra_where_clause {}}
{-csv true}
{-voting_form}
{-voting_form_form ""}
{-voting_form_anon_instances "t"}
{-generate}
{-with_form_link true}
{-with_categories}
{-wf}
{-bulk_actions ""}
{-buttons "edit delete"}
{-renderer ""}
{-return_url}
{-date_format}
{-with_checkboxes:boolean false}
") ]
Show usages of the specified form.
Defined in /var/www/openacs.org/packages/xowiki/tcl/includelet-procs.tclClass Relations
- class: ::xowiki::IncludeletClass
![[i]](/resources/acs-subsite/ZoomIn16.gif)
- superclass: ::xowiki::Includelet
![[i]](/resources/acs-subsite/ZoomIn16.gif)
::xowiki::IncludeletClass create ::xowiki::includelet::form-usages \
-superclass ::xowiki::Includelet
Methods (to be applied on instances)
__decoration (setter)
generate_voting_form (scripted)
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;'> very good<br /></td>
<td align='right' style='border-style: none; text-align: right; width: 150px;'> very bad<br /></td>
</tr> \n"
set count 0
set table_field_names [list]
foreach t [$t1 children] {
incr count
lappend table_field_names $count
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
set form_form_id 0
if {$form_form ne ""} {
set form_form_id [::xo::db::CrClass lookup -name $form_form -parent_id [::${:package_id} folder_id]]
}
if {$form_form_id == 0} { set form [list $form text/html] }
set item_id [::xo::db::CrClass lookup -name $form_name -parent_id [::${:package_id} folder_id]]
if {$item_id == 0} {
if {$form_form_id == 0} {
set f [::xowiki::Form new -package_id ${:package_id} -parent_id [::${: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 ${:package_id} -parent_id [::${: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='[ns_quotehtml $form_href]'>[ns_quotehtml $form_name]</a>"parameter_declaration (setter)
render (scripted)
:get_parameters
set o ${:__including_page}
::xo::Page requireCSS "/resources/acs-templating/lists.css"
if {[info exists return_url]} {
if {$return_url eq ""} {
unset return_url
} else {
}
} else {
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]
} elseif {$parent_id eq "*"} {
set query_parent_id $parent_id
set parent_id [$o parent_id]
}
} else {
set parent_id [$o parent_id]
}
if {![info exists query_parent_id]} {
set query_parent_id $parent_id
}
if {![info exists form_item_id]} {
set form_item_ids [::$package_id instantiate_forms -parent_id $parent_id -default_lang [$o lang] -forms $form ]
if {$form_item_ids eq ""} {
return -code error "could not load form '$form' (default-language [$o lang])"
}
} else {
set form_item_ids $form_item_id
}
set form_constraints $extra_form_constraints\n
set inherit_form_ids {}
if {$inherit_from_forms ne ""} {
foreach inherit_form $inherit_from_forms {
set inherit_form_id [::$package_id instantiate_forms -parent_id [$o parent_id] -default_lang [$o lang] -forms $inherit_form]
if {$inherit_form_id ne ""} {
if {[::$inherit_form_id istype ::xowiki::FormPage]} {
set p [::$inherit_form_id property form_constraints]
} else {
set p [::$inherit_form_id form_constraints]
}
append form_constraints $p\n
lappend inherit_form_ids $inherit_form_id
}
}
}
foreach form_item $form_item_ids {
append form_constraints [$form_item get_form_constraints -trylocal true] \n
}
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
}
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
}
if {$raw_field_names eq ""} {
set raw_field_names {_name _last_modified _creation_user}
}
foreach fn $hidden_field_names {
lappend raw_field_names $fn
}
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 $_}
}
if {[llength $inherit_form_ids] > 0} {
set item_ids $inherit_form_ids
} else {
set item_ids $form_item_ids
}
set form_fields ""
foreach form_item $item_ids {
set form_field_objs [::xowiki::FormPage get_table_form_fields -base_item $form_item -field_names $field_names -form_constraints $form_constraints -nls_language [${:__including_page} nls_language] ]
foreach f $form_field_objs {
dict set form_fields [$f name] $f
}
}
if {[dict exists $form_fields _text]} {
[dict get $form_fields _text] set wiki 1
}
if {[dict exists $form_fields _last_modified] && [info exists date_format]} {
[dict get $form_fields _last_modified] display_format $date_format
}
set table_widget [::xowiki::TableWidget create_from_form_fields -form_field_objs $form_field_objs -package_id $package_id -buttons $buttons -hidden_field_names $hidden_field_names -bulk_actions $bulk_actions -renderer $renderer -orderby $orderby -with_checkboxes $with_checkboxes]
if {[info exists voting_form]} {
if {![regexp {^..:} $voting_form]} {
set voting_form [${:__including_page} lang]:$voting_form
}
dict set voting_dict voting_form $voting_form
dict set voting_dict renderer [list [self] generate_voting_form $voting_form $voting_form_form $table_widget $field_names $voting_form_anon_instances]
} else {
set voting_dict ""
}
set filters [::xowiki::FormPage compute_filter_clauses {*}[expr {[info exists unless] ? [list -unless $unless] : ""}] {*}[expr {[info exists where] ? [list -where $where] : ""}]]
if {[info exists with_categories] && [info exists category_id]} {
append extra_where_clause [expr {$extra_where_clause ne "" ? " and " : ""}] [lindex [:category_clause $category_id item_id] 1]
}
set items [::xowiki::FormPage get_form_entries -base_item_ids $form_item_ids -parent_id $query_parent_id -form_fields $form_field_objs -publish_status $publish_status -extra_where_clause $extra_where_clause -h_where [dict get $filters wc] -h_unless [dict get $filters uc] -from_package_ids $package_ids -package_id $package_id]
if {[info exists wf]} {
set wf_link [::$package_id pretty_link -parent_id $parent_id -path_encode false $wf]
}
set HTML [$table_widget render_page_items_as_table -form_field_objs $form_field_objs -return_url [ad_return_url] -package_id $package_id -items $items -init_vars [dict get $filters init_vars] -view_field $view_field -buttons $buttons -include_object_id_attribute [expr {$with_checkboxes || [llength $bulk_actions] > 0}] -form_item_ids $form_item_ids -with_form_link $with_form_link -csv $csv {*}[expr {[info exists generate] ? [list -generate $generate] : ""}] -voting_dict $voting_dict ]
$table_widget destroy
return $HTML