Inicio de la navegación principal
Methods: | Source: | Variables: |
---|---|---|
[All Methods | Documented Methods | Hide Methods] | [Display Source | Hide Source] | [Show Variables | Hide Variables] |
Class Hierarchy of ::xowiki::FormPage
- ::xotcl::Object
![]()
- Meta-class:
- ::xotcl::Class
- Methods for instances:
- __api_make_doc, __api_make_forward_doc, __nextC, __timediff, abstract, ad_doc, ad_forward, ad_proc, appendC, arrayC, asHTML, autonameC, checkC, classC, cleanupC, configureC, contains, copy, db_1rowC, debug, defaultmethod, destroyC, destroy_on_cleanup, evalC, existsC, extractConfigureArg, filterC, filterguardC, filtersearchC, forwardC, hasclass, incrC, infoC, init, instvarC, invarC, isclassC, ismetaclassC, ismixinC, isobjectC, istypeC, lappendC, log, method, mixinC, mixinguardC, move, msg, noinitC, parametercmdC, procC, procsearchC, qn, requireNamespaceC, self, serialize, setC, substC, traceC, unsetC, uplevelC, upvarC, volatileC, vwaitC
- Methods to be applied on the class (in addition to the methods provided by the meta-class):
- __exitHandler, getExitHandler, setExitHandler, unsetExitHandler
- ::xo::db::Object
![]()
- ::xo::db::CrItem
![]()
- Meta-class:
- ::xo::db::CrClass
- Parameter for instances:
- package_id, parent_id (default "-100"), publish_status (default "ready")
- Methods for instances:
- current_user_id, delete, descriptionC, fix_content, initialize_loaded_object, item_idC, mime_typeC, nameC, nls_languageC, privilege=creator, publish_dateC, rename, revision_idC, revisions, save, save_new, set_live_revision, textC, titleC, update_attribute_from_slot, update_content, update_revision
- Methods to be applied on the class:
- Methods provided by the meta-class
- ::xowiki::Page
![]()
- Meta-class:
- ::xo::db::CrClass
- Parameter for instances:
- absolute_links (default "0"), do_substitutions (default "1"), lang (default "en"), render_adp (default "1")
- Methods for instances:
- adp_subst, anchor, build_instance_attribute_map, build_name, category_export, category_import, check_adp_include_path, condition=match, condition=regexp, copy_content_vars, create-new, create_form_field, create_form_fields, create_form_fields_from_form_constraints, create_raw_form_field, creation_userC, creatorC, default_instance_attributes, delete, delete-revision, demarshall, descripionC, diff, div, edit, error_during_render, error_in_includelet, exists_form_parameterC, exists_query_parameterC, field_names, find_slot, footer, form_field_index, form_parameterC, get_content, get_description, get_form_data, get_instance_attributes, get_rich_text_spec, htmlFooter, include, include_content, include_portlet, initialize_loaded_object, instantiate_includelet, is_new_entry, last_modifiedC, list, lookup_cached_form_field, lookup_form_field, make-live-revision, map_categories, map_party, marshall, mime_typeC, nameC, nls_languageC, page_idC, page_orderC, popular-tags, publish_dateC, query_parameterC, record_last_visited, regsub_eval, render, render_includelet, resolve_included_page_name, reverse_map_party, reverse_map_party_attribute, revisions, save, save-tags, save_attributes, save_data, save_new, set_content, show_fields, substitute_markup, textC, titleC, translate, unescape, unset_temporary_instance_variables, update_references, validate=form_constraints, validate=name, validate=page_order, view
- Methods to be applied on the class (in addition to the methods provided by the meta-class):
- container_already_rendered, get_tags, import, quoted_html_content, save_tags
- ::xowiki::PageInstance
![]()
- Meta-class:
- ::xo::db::CrClass
- Methods for instances:
- adp_subst, count_usages, create_raw_form_field, demarshall, get_content, get_field_label, get_field_type, get_form, get_form_constraints, get_from_template, get_short_spec, get_template_object, instance_attributesC, mime_typeC, page_instance_idC, page_templateC, template_vars, widget_spec_from_folder_object
- Methods to be applied on the class (in addition to the methods provided by the meta-class):
- get_list_from_form_constraints, get_short_spec_from_form_constraints
- ::xowiki::FormPage
![]()
- Meta-class:
- ::xo::db::CrClass
- Methods for instances:
- adp_subst, assigneeC, condition=in_state, create_category_fields, create_form_field, create_form_fields, demarshall, edit, exists_property, field_names, field_names_from_form, footer, form_attributes, form_field_as_html, form_fields_sanity_check, get_content, get_form_constraints, get_form_value, get_property, get_value, initialize, initialize_loaded_object, isform, load_values_into_form_fields, map_value, map_values, marshall, mime_typeC, post_process_dom_tree, post_process_form_fields, property, property_key, render_form_action_buttons, reverse_map_value, reverse_map_values, set_form_data, set_form_value, set_property, set_publish_status, stateC, xowiki_form_page_idC
- Methods to be applied on the class (in addition to the methods provided by the meta-class):
- filter_expression, get_form_entries, get_table_form_fields, h_double_quote
Class Relations
::xo::db::CrClass create ::xowiki::FormPage \ -superclass ::xowiki::PageInstance
::xowiki::FormPage proc filter_expression {input_expr logical_op} { array set tcl_op {= eq < < > > >= >= <= <=} array set sql_op {= = < < > > >= >= <= <=} array set op_map {contains,sql {$lhs_var like '%$rhs%'} contains,tcl {[lsearch $lhs_var {$rhs}] > -1}} #my msg unless=$unless #example for unless: wf_current_state = closed|accepted || x = 1 set tcl_clause [list] set h_clause [list] set vars [list] set sql_clause [list] foreach clause [split [string map [list $logical_op \x00] $input_expr] \x00] { if {[regexp {^(.*[^<>])\s*([=<>]|<=|>=|contains)\s*([^=]?.*)$} $clause _ lhs op rhs_expr]} { set lhs [string trim $lhs] if {[string range $lhs 0 0] eq "_"} { set lhs_var [string range $lhs 1 end] set rhs [split $rhs_expr |] if {[info exists op_map($op,sql)]} { lappend sql_clause [subst -nocommands $op_map($op,sql)] if {[my exists $lhs_var]} { set lhs_var "\[my set $lhs_var\]" lappend tcl_clause [subst -nocommands $op_map($op,tcl)] } else { my msg "ignoring unknown variable $lhs_var in expression" } } elseif {[llength $rhs]>1} { lappend sql_clause "$lhs_var in ('[join $rhs ',']')" } else { lappend sql_clause "$lhs_var $sql_op($op) '$rhs'" } } else { set hleft [my h_double_quote $lhs] lappend vars $lhs "" if {$op eq "contains"} { #make approximate query set lhs_var instance_attributes set rhs $rhs_expr lappend sql_clause [subst -nocommands $op_map($op,sql)] } set lhs_var "\$__ia($lhs)" foreach rhs [split $rhs_expr |] { if {[info exists op_map($op,tcl)]} { lappend tcl_clause [subst -nocommands $op_map($op,tcl)] } else { lappend tcl_clause "$lhs_var $tcl_op($op) {$rhs}" } if {$op eq "="} { # TODO: think about a solution for other operators with # hstore maybe: extracting it by a query via hstore and # compare in plain SQL lappend h_clause "$hleft=>[my h_double_quote $rhs]" } } } } else { my msg "ignoring $clause" } } if {[llength $tcl_clause] == 0} {set tcl_clause [list true]} #my msg sql=$sql_clause,tcl=$tcl_clause return [list tcl [join $tcl_clause $logical_op] h [join $h_clause ,] vars $vars sql $sql_clause] #my msg $expression }
::xowiki::FormPage proc get_form_entries {-base_item_id -package_id -form_fields {-publish_status ready} {-extra_where_clause {}} {-h_where {}} {-always_queried_attributes {_name _last_modified _creation_user}} {-orderby {}} {-page_size 20} {-page_number {}}} { # # Get query attributes for all tables (to allow e.g. sorting by time) # set sql_atts [list bt.instance_attributes ci.parent_id] foreach att $always_queried_attributes { set name [string range $att 1 end] if {$name eq "name"} { lappend sql_atts ci.$name } else { lappend sql_atts bt.$name } } # # Collect SQL attributes from form_fields # foreach f $form_fields { if {![$f exists __base_field]} continue set field_name [$f name] if {$field_name eq "_text"} { lappend sql_atts "bt.data as text" } elseif {$field_name eq "_publish_status"} { lappend sql_atts ci.[$f set __base_field] } elseif {[lsearch -exact $always_queried_attributes $field_name] == -1} { lappend sql_atts bt.[$f set __base_field] } } #my msg sql_atts=$sql_atts # # Build WHERE clause # set publish_status_clause [::xowiki::Includelet publish_status_clause -base_table ci $publish_status] set filter_clause "" array set wc $h_where set use_hstore [expr {[::xo::db::has_hstore] && [$package_id get_parameter use_hstore 0] }] if {$h_where ne "" && $use_hstore} { set filter_clause " and '$wc(h)' <@ bt.hkey" } #my msg "exists sql=[info exists wc(sql)]" if {$wc(sql) ne ""} { foreach filter $wc(sql) { append filter_clause "and $filter" } } #my msg filter_clause=$filter_clause # -parent_id empty means to get instances, regardless of # parent_id. Under the assumption, page_template constrains # the query enough to make it fast... set sql [::xowiki::FormPage instance_select_query -select_attributes $sql_atts -from_clause "" -where_clause " bt.page_template = $base_item_id $publish_status_clause $filter_clause $extra_where_clause" -orderby $orderby -with_subtypes false -parent_id "" -page_size $page_size -page_number $page_number -base_table xowiki_form_pagei ] my log $sql set items [::xowiki::FormPage instantiate_objects -sql $sql -object_class ::xowiki::FormPage] if {$h_where ne "" && !$use_hstore} { set init_vars $wc(vars) foreach p [$items children] { array set __ia $init_vars array set __ia [$p instance_attributes] if {![expr $wc(tcl)]} {$items delete $p} } } return $items }
::xowiki::FormPage proc get_table_form_fields {-base_item -field_names -form_constraints} { array set __att [list publish_status 1] foreach att [::xowiki::FormPage array names db_slot] {set __att($att) 1} foreach att [list last_modified creation_user] { set __att($att) 1 } # set cr_field_spec [::xowiki::PageInstance get_short_spec_from_form_constraints # -name @cr_fields # -form_constraints $form_constraints] # if some fields are hidden in the form, there might still be values (creation_user, etc) # maybe filter hidden? ignore for the time being. set cr_field_spec "" set field_spec [::xowiki::PageInstance get_short_spec_from_form_constraints -name @fields -form_constraints $form_constraints] foreach field_name $field_names { set short_spec [::xowiki::PageInstance get_short_spec_from_form_constraints -name $field_name -form_constraints $form_constraints] switch -glob -- $field_name { __* {error not_allowed} _* { set varname [string range $field_name 1 end] if {![info exists __att($varname)]} { error "unknown attribute $field_name" } set f [$base_item create_raw_form_field -name $field_name -slot [$base_item find_slot $varname] -spec $cr_field_spec,$short_spec] $f set __base_field $varname } default { set f [$base_item create_raw_form_field -name $field_name -slot "" -spec $field_spec,$short_spec] } } lappend form_fields $f } return $form_fields }
::xowiki::FormPage proc h_double_quote value { if {[regexp {[ ,\"\\=>]} $value]} { set value \"[string map [list \" \\\\\" \\ \\\\ ' \\\\'] $value]\" } return $value }
::xowiki::FormPage instproc adp_subst content { # Get the default field specs once and pass it to every field creation set field_spec [my get_short_spec @fields] set cr_field_spec [my get_short_spec @cr_fields] # Iterate over the variables for substitution set content [my regsub_eval -noquote true [template::adp_variable_regexp] " $content" {my get_value -field_spec $field_spec -cr_field_spec $cr_field_spec "\\\1" "\2"}] return [string range $content 1 end] }
::xowiki::FormPage instproc condition=in_state {query_context value} { # possible values can be or-ed together (e.g. initial|final) foreach v [split $value |] { #my msg "check [my state] eq $v" if {[my state] eq $v} {return 1} } return 0 }
::xowiki::FormPage instproc create_category_fields {} { set category_spec [my get_short_spec @categories] # Per default, no category fields in FormPages, since the can be # handled in more detail via form-fields. if {$category_spec eq ""} {return [list]} # a value of "off" turns the off as well foreach f [split $category_spec ,] { if {$f eq "off"} {return [list]} } set category_fields [list] set container_object_id [my package_id] set category_trees [category_tree::get_mapped_trees $container_object_id] set category_ids [category::get_mapped_categories [my item_id]] #my msg "mapped category ids=$category_ids" foreach category_tree $category_trees { foreach {tree_id tree_name subtree_id assign_single_p require_category_p} $category_tree break set options [list] #if {!$require_category_p} {lappend options [list "--" ""]} set value [list] foreach category [::xowiki::Category get_category_infos -subtree_id $subtree_id -tree_id $tree_id] { foreach {category_id category_name deprecated_p level} $category break if {[lsearch $category_ids $category_id] > -1} {lappend value $category_id} set category_name [ad_quotehtml [lang::util::localize $category_name]] if { $level>1 } { set category_name "[string repeat { } [expr {2*$level-4}]]..$category_name" } lappend options [list $category_name $category_id] } set f [::xowiki::formfield::FormField new -name "__category_${tree_name}_$tree_id" -locale [my nls_language] -label $tree_name -type select -value $value -required $require_category_p] #my msg "category field [my name] created, value '$value'" $f destroy_on_cleanup $f options $options $f multiple [expr {!$assign_single_p}] lappend category_fields $f } return $category_fields }
::xowiki::FormPage instproc create_form_field {{-cr_field_spec {}} {-field_spec {}} field_name} { if {$cr_field_spec eq ""} {set cr_field_spec [my get_short_spec @cr_fields]} if {$field_spec eq ""} {set field_spec [my get_short_spec @fields]} return [next -cr_field_spec $cr_field_spec -field_spec $field_spec $field_name] }
::xowiki::FormPage instproc create_form_fields field_names { set form_fields [my create_category_fields] foreach att $field_names { if {[string match "__*" $att]} continue lappend form_fields [my create_form_field -cr_field_spec [my get_short_spec @cr_fields] -field_spec [my get_short_spec @fields] $att] } return $form_fields }
::xowiki::FormPage instproc demarshall {-parent_id -package_id -creation_user {-create_user_ids 0}} { # reverse map assingees my reverse_map_party_attribute -attribute assignee -create_user_ids $create_user_ids # # The function will compute the category_ids, which are were used # to categorize this objects in the source instance. set category_ids [list] #my msg "[my name] check cm=[info exists ::__xowiki_reverse_category_map] && iam=[my exists __instance_attribute_map]" if {[info exists ::__xowiki_reverse_category_map] && [my exists __instance_attribute_map] } { #my msg "we have a instance_attribute_map" # # replace all symbolic category values by the mapped IDs # set ia [list] array set use [my set __instance_attribute_map] array set multiple_index [list category 2 party_id 1] foreach {name value} [my instance_attributes] { #my msg "use($name) --> [info exists use($name)]" if {[info exists use($name)]} { #my msg "try to map value '$value' (category tree: $use($name))" set map_type [lindex $use($name) 0] set multiple [lindex $use($name) $multiple_index($map_type)] if {$multiple eq ""} {set multiple 1} if {$multiple} { lappend ia $name [my reverse_map_values $map_type $value category_ids] } else { lappend ia $name [my reverse_map_value $map_type $value category_ids] } } else { # nothing to map lappend ia $name $value } } my set instance_attributes $ia #my msg "[my name] saving instance_attributes $ia" } set r [next] my set __category_ids [lsort -unique $category_ids] return $r }
::xowiki::FormPage instproc edit {{-validation_errors {}} {-disable_input_fields 0} {-view true}} { my instvar page_template doc root package_id ::xowiki::Form requireFormCSS set form [my get_form] set anon_instances [my get_from_template anon_instances f] #my msg form=$form #my msg anon_instances=$anon_instances # The following code should be obsolete # set form_id [my get_form_id] # if {![$form_id istype ::xowiki::Form]} { # set form "<FORM>[lindex [$form_id set text] 0]</FORM>" # } set field_names [my field_names -form $form] set form_fields [my create_form_fields $field_names] if {$form eq ""} { # # Since we have no form, we create it on the fly # from the template variables and the form field specifications. # set form "<FORM></FORM>" set formgiven 0 } else { set formgiven 1 } # check name field: # - if it is for anon instances, hide it, # - if it is required but hidden, show it anyway # (might happen, when e.g. set via @cr_fields ... hidden) set name_field [my lookup_form_field -name _name $form_fields] if {$anon_instances} { #$name_field config_from_spec hidden } else { if {[$name_field istype ::xowiki::formfield::hidden] && [$name_field required] == true} { $name_field config_from_spec text,required $name_field type text } } # include _text only, if explicitly needed (in form needed(_text)]" if {![my exists __field_needed(_text)]} { #my msg "setting text hidden" set f [my lookup_form_field -name _text $form_fields] $f config_from_spec hidden } #my show_fields $form_fields #my msg "__form_action [my form_parameter __form_action {}]" if {[my form_parameter __form_action ""] eq "save-form-data"} { #my msg "we have to validate" # # we have to valiate and save the form data # foreach {validation_errors category_ids} [my get_form_data $form_fields] break if {$validation_errors != 0} { #my msg "$validation_errors errors in $form_fields" #foreach f $form_fields { my log "$f: [$f name] '[$f set value]' err: [$f error_msg] " } # # In case we are triggered internally, we might not have a # a connection, so we don't present the form with the # error messages again, but we return simply the validation # problems. # if {[$package_id exists __batch_mode]} { set errors [list] foreach f $form_fields { if {[$f error_msg] ne ""} { lappend errors [list field [$f name] value [$f set value] error [$f error_msg]] } } set evaluation_errors "" if {[$package_id exists __evaluation_error]} { set evaluation_errors "\nEvaluation error: [$package_id set __evaluation_error]" $package_id unset __evaluation_error } error "[llength $errors] validation error(s): $errors $evaluation_errors" } # reset the name in error cases to the original one my set name [my form_parameter __object_name] } else { # # we have no validation erros, so we can save the content # my save_data -use_given_publish_date [expr {[lsearch $field_names _publish_date] > -1}] [::xo::cc form_parameter __object_name ""] $category_ids # The data might have references. We render do the rendering here # instead on every view (which would be safer, but slower). This is # roughly the counterpart to edit_data and save_data in ad_forms. set content [my render -update_references] #my msg "after save refs=[expr {[my exists references]?[my set references] : {NONE}}]" set redirect_method [my form_parameter __form_redirect_method "view"] #my msg "__form_redir=$redirect_method" #my msg "__form params= [::xo::cc array get form_parameter]" if {$redirect_method eq "__none"} { return } else { set url [$package_id pretty_link -lang en [my name]]?m=$redirect_method set return_url [$package_id get_parameter return_url $url] # we had query_parameter here. however, to be able to # process the output of ::xo::cc set_parameter ...., we # changed it to "parameter". #my msg "return_url=$return_url" $package_id returnredirect $return_url return } } } else { # # display the current values # if {[my is_new_entry [my name]]} { my set creator [::xo::get_user_name [::xo::cc user_id]] my set nls_language [ad_conn locale] #my set name [$package_id query_parameter name ""] # TODO: maybe use __object_name to for POST url to make code # more straightworward #set n [$package_id query_parameter name # [::xo::cc form_parameter __object_name ""]] #if {$n ne ""} { # my name $n #} } array set __ia [my set instance_attributes] my load_values_into_form_fields $form_fields foreach f $form_fields {set ff([$f name]) $f } # for named entries, just set the entry fields to empty, # without changing the instance variables if {[my is_new_entry [my name]]} { if {$anon_instances} { set name [autoname new -name [$page_template name] -parent_id $page_template] #my msg "generated name=$name, page_template-name=[$page_template name]" $ff(_name) value $name } else { $ff(_name) value "" } if {![$ff(_title) istype ::xowiki::formfield::hidden]} { $ff(_title) value "" } foreach var [list title detail_link text description] { if {[my exists_query_parameter $var]} { set value [my query_parameter $var] switch -- $var { detail_link { set f [my lookup_form_field -name $var $form_fields] $f value [$f convert_to_external $value] } title - text - description { set f [my lookup_form_field -name _$var $form_fields] } } $f value [$f convert_to_external $value] } } } } # some final sanity checks my form_fields_sanity_check $form_fields my post_process_form_fields $form_fields # The following command would be correct, but does not work due to a bug in # tdom. # set form [my regsub_eval # [template::adp_variable_regexp] $form # {my form_field_as_html -mode edit "\\\1" "\2" $form_fields}] # Due to this bug, we program around and replace the at-character # by \x003 to avoid conflict withe the input and we replace these # magic chars finally with the fields resulting from tdom. set form [string map [list @ \x003] $form] #my msg form=$form dom parse -simple -html $form doc $doc documentElement root ::require_html_procs $root firstChild fcn # # prepend some fields above the HTML contents of the form # $root insertBeforeFromScript { ::html::input -type hidden -name __object_name -value [my name] ::html::input -type hidden -name __form_action -value save-form-data # insert automatic form fields on top foreach att $field_names { #if {$formgiven && ![string match _* $att]} continue if {[my exists __field_in_form($att)]} continue set f [my lookup_form_field -name $att $form_fields] #my msg "insert auto_field $att" $f render_item } } $fcn # # append some fields after the HTML contents of the form # set submit_button_class "" set has_file 0 $root appendFromScript { # append category fields foreach f $form_fields { #my msg "[$f name]: is wym? [$f has_instance_variable editor wym]" if {[string match "__category_*" [$f name]]} { $f render_item } elseif {[$f has_instance_variable editor wym]} { set submit_button_class "wymupdate" } if {[$f has_instance_variable type file]} { set has_file 1 } } # insert unreported errors foreach f $form_fields { if {[$f set error_msg] ne "" && ![$f exists error_reported]} { $f render_error_msg } } # add a submit field(s) at bottom my render_form_action_buttons -CSSclass $submit_button_class } set form [lindex [$root selectNodes //form] 0] if {$form eq ""} { my msg "no form found in page [$page_template name]" } else { if {[my exists_query_parameter "return_url"]} { set return_url [my query_parameter "return_url"] } set url [export_vars -base [$package_id pretty_link [my name]] {{m "edit"} return_url}] $form setAttribute action $url method POST if {$has_file} {$form setAttribute enctype multipart/form-data} Form add_dom_attribute_value $form class "margin-form" } my set_form_data $form_fields if {$disable_input_fields} { # (a) disable explicit input fields foreach f $form_fields {$f disabled disabled} # (b) disable input in HTML-specified fields Form dom_disable_input_fields $root } my post_process_dom_tree $doc $root $form_fields set html [$root asHTML] set html [my regsub_eval {(^|[^\\])\x003([a-zA-Z0-9_:]+)\x003} $html {my form_field_as_html -mode edit "\\\1" "\2" $form_fields}] #my log "calling VIEW with HTML [string length $html]" if {$view} { my view $html } else { return $html } }
::xowiki::FormPage instproc exists_property name { return [my exists [my property_key $name]] }
::xowiki::FormPage instproc field_names {{-form {}}} { my instvar package_id foreach {form_vars needed_attributes} [my field_names_from_form -form $form] break #my msg "form_vars=$form_vars needed_attributes=$needed_attributes" my array unset __field_in_form my array unset __field_needed if {$form_vars} {foreach v $needed_attributes {my set __field_in_form($v) 1}} foreach v $needed_attributes {my set __field_needed($v) 1} # # Remove the fields already included in auto_fields form the needed_attributes. # The final list field_names determines the order of the fields in the form. # set auto_fields [list _name _page_order _creator _title _text _description _nls_language] set reduced_attributes $needed_attributes foreach f $auto_fields { set p [lsearch $reduced_attributes $f] if {$p > -1} { #if {$form_vars} { #set auto_field_in_form($f) 1 #} set reduced_attributes [lreplace $reduced_attributes $p $p] } } #my msg reduced_attributes=$reduced_attributes #my msg fields_from_form=[my array names __field_in_form] set field_names [list _name] if {[$package_id show_page_order]} { lappend field_names _page_order } lappend field_names _title _creator foreach fn $reduced_attributes { lappend field_names $fn } foreach fn [list _text _description _nls_language] { lappend field_names $fn } #my msg field_names=$field_names return $field_names }
::xowiki::FormPage instproc field_names_from_form {{-form {}}} { # # this method returns the form attributes (including _*) # my instvar page_template set allvars [concat [[my info class] array names db_slot] [::xo::db::CrClass set common_query_atts]] set template [lindex [my get_from_template text] 0] #set field_names [list _name _title _description _creator _nls_language _page_order] set field_names [list] if {$form eq ""} {set form [my get_form]} if {$form eq ""} { foreach {var _} [my template_vars $template] { #if {[string match _* $var]} continue if {[lsearch $allvars $var] == -1 && [lsearch $field_names $var] == -1} {lappend field_names $var} } set from_HTML_form 0 } else { foreach {match 1 att} [regexp -all -inline [template::adp_variable_regexp] $form] { #if {[string match _* $att]} continue lappend field_names $att } dom parse -simple -html $form doc $doc documentElement root set fields [$root selectNodes "//*\[@name != ''\]"] foreach field $fields { set node_name [$field nodeName] if {$node_name ne "input" && $node_name ne "textarea" && $node_name ne "select" } continue set att [$field getAttribute name] #if {[string match _* $att]} continue if {[lsearch $field_names $att] == -1} { lappend field_names $att } } set from_HTML_form 1 } return [list $from_HTML_form $field_names] }
::xowiki::FormPage instproc footer {} { if {[my exists __no_form_page_footer]} { next } else { set is_form [my property is_form__ 0] if {[my isform]} { return [my include [list form-menu -form_item_id [my item_id] -buttons [list new answers [list form [my page_template]]]]] } else { return [my include [list form-menu -form_item_id [my page_template] -buttons form]] } } }
::xowiki::FormPage instproc form_attributes {} { my log "DEPRECATRED, use 'field_names_from_form' instead " return [my field_names_from_form] }
::xowiki::FormPage instproc form_field_as_html {{-mode edit} before name form_fields} { set found 0 foreach f $form_fields { if {[$f name] eq $name} {set found 1; break} } if {!$found} { set f [my create_raw_form_field -name $name -slot [my find_slot $name]] } #my msg "$found $name mode=$mode type=[$f set type] value=[$f value] disa=[$f exists disabled]" if {$mode eq "edit" || [$f display_field]} { set html [$f asHTML] } else { set html @$name@ } #my msg "$name $html" return ${before}$html }
::xowiki::FormPage instproc form_fields_sanity_check form_fields { foreach f $form_fields { if {[$f exists disabled]} { # don't mark disabled fields as required if {[$f required]} { $f required false } #don't show the help-text, if you cannot input if {[$f help_text] ne ""} { $f help_text "" } } } }
::xowiki::FormPage instproc get_content {} { my instvar doc root package_id page_template set text [lindex [my get_from_template text] 0] if {$text ne ""} { #my msg "we have a template text='$text'" # we have a template return [next] } else { #my msg "we have a form '[my get_form]'" set form [my get_form] if {$form eq ""} {return ""} ::xowiki::Form requireFormCSS foreach {form_vars field_names} [my field_names_from_form -form $form] break my array unset __field_in_form if {$form_vars} {foreach v $field_names {my set __field_in_form($v) 1}} set form_fields [my create_form_fields $field_names] my load_values_into_form_fields $form_fields # deactivate form-fields and do some final sanity checks foreach f $form_fields {$f set_disabled 1} my form_fields_sanity_check $form_fields set form [my regsub_eval [template::adp_variable_regexp] $form {my form_field_as_html -mode display "\\\1" "\2" $form_fields}] # we parse the form just for the margin-form.... maybe regsub? dom parse -simple -html $form doc $doc documentElement root set form_node [lindex [$root selectNodes //form] 0] Form add_dom_attribute_value $form_node class "margin-form" # The following two commands are for non-generated form contents my set_form_data $form_fields Form dom_disable_input_fields $root # Return finally the result return [$root asHTML] } }
::xowiki::FormPage instproc get_form_constraints {{-trylocal false}} { # We define it as a method to ease overloading. #my msg "is_form=[my isform]" if {$trylocal && [my isform]} { return [my property form_constraints] } else { return [my get_from_template form_constraints] } }
::xowiki::FormPage instproc get_form_value att { my instvar root item_id set fields [$root selectNodes "//form//*\[@name='$att'\]"] if {$fields eq ""} {return ""} foreach field $fields { set type [expr {[$field hasAttribute type] ? [$field getAttribute type] : "text"}] switch $type { checkbox { #my msg "get_form_value not implemented for $type" } radio { #my msg "get_form_value not implemented for $type" } hidden - password - text { if {[$field hasAttribute value]} { return [$field getAttribute value] } } default { #my msg "can't handle $type so far $att=$value" } } } return "" }
::xowiki::FormPage instproc get_property {-source -name:required {-default {}}} { if {![info exists source]} { set page [self] } else { set page [my resolve_included_page_name $source] } return [$page property $name $default] }
::xowiki::FormPage instproc get_value {{-field_spec {}} {-cr_field_spec {}} before varname} { # # Read a property (instance attribute) and return # its pretty value in variable substitutions. # if {![my exists_property $varname]} { # We check for current_user here. In case the property does # not exist, we provide a value from the currently connected # user. if {$varname eq "current_user"} { set value [::xo::cc set untrusted_user_id] } else { set value "" } } else { set value [my property $varname] # todo: might be more efficient to check, if the field exists already set f [my create_form_field -cr_field_spec $cr_field_spec -field_spec $field_spec $varname] $f value $value if {[$f hide_value]} { set value "" } elseif {![$f exists show_raw_value]} { set value [$f pretty_value $value] } } return $before$value }
::xowiki::FormPage instproc initialize {} { # can be overloaded }
::xowiki::FormPage instproc initialize_loaded_object {} { if {[my exists page_template]} { ::xo::db::CrClass get_instance_from_db -item_id [my page_template] } my array set __ia [my instance_attributes] next }
::xowiki::FormPage instproc isform {} { return [my exists_property form_constraints] }
::xowiki::FormPage instproc load_values_into_form_fields form_fields { array set __ia [my set instance_attributes] foreach f $form_fields { set att [$f name] switch -glob $att { __* {} _* { set varname [string range $att 1 end] $f value [$f convert_to_external [my set $varname]] } default { if {[info exists __ia($att)]} { #my msg "setting $f ([$f info class]) value $__ia($att)" $f value [$f convert_to_external $__ia($att)] } } } } }
::xowiki::FormPage instproc map_value {map_type value} { my log "map_value $map_type, $value" if {$map_type eq "category" && $value ne ""} { # # map a category item # array set cm [my set __category_map] return $cm($value) } elseif {$map_type eq "party_id" && $value ne ""} { # # map a party_id # return [my map_party $value] } else { return $value } }
::xowiki::FormPage instproc map_values {map_type values} { # Map a list of values (for multi-valued form fields) # my log "map_values $map_type, $values" set mapped_values [list] foreach value $values {lappend mapped_values [my map_value $map_type $value]} return $mapped_values }
::xowiki::FormPage instproc marshall {} { # # Handle mapping from IDs to symbolic representations in # form-field values. We perform the mapping on xowiki::FormPages # and not on xowiki::Forms, since a single xowiki::FormPages might # use different xowiki::Forms in its life-cycle. # # Note, that only types of form-fields implied by the derived form # constraints are recognized. E.g. in workflows, it might be # necessary to move e.g. category definitions into the global form # constraints. # set form_fields [my create_form_fields_from_form_constraints [my get_form_constraints]] my build_instance_attribute_map $form_fields # In case we have a mapping from IDs to external values, use it # and rewrite instance attributes. Note, that the marshalled # objects have to be flushed from memory later since the # representation of instances_attributes is changed by this # method. # if {[my exists __instance_attribute_map]} { # my log "+++ we have an instance_attribute_map for [my name]" # my log "+++ starting with instance_attributes [my instance_attributes]" array set use [my set __instance_attribute_map] array set multiple_index [list category 2 party_id 1] set ia [list] foreach {name value} [my instance_attributes] { #my log "marshall check $name $value [info exists use($name)]" if {[info exists use($name)]} { set map_type [lindex $use($name) 0] set multiple [lindex $use($name) $multiple_index($map_type)] #my log "+++ marshall check $name $value m=?$multiple" if {$multiple} { lappend ia $name [my map_values $map_type $value] } else { lappend ia $name [my map_value $map_type $value] } } else { # nothing to map lappend ia $name $value } } my set instance_attributes $ia #my log "+++ setting instance_attributes $ia" } set old_assignee [my assignee] my set assignee [my map_party $old_assignee] set r [next] my set assignee $old_assignee return $r }
::xowiki::FormPage instproc post_process_dom_tree {dom_doc dom_root form_fields} { # Part of the input fields comes from HTML, part comes via $form_fields # We offer here the possibility to iterate over the dom tree before it # is presented; can be overloaded }
::xowiki::FormPage instproc post_process_form_fields form_fields { # We offer here the possibility to iterate over the form fields before it # before they are rendered }
::xowiki::FormPage instproc property {name {default {}}} { set key [my property_key $name] #my msg "$key [my exists $key] //[my array names __ia]//" if {[my exists $key]} { return [my set $key] } return $default }
::xowiki::FormPage instproc property_key name { if {[regexp {^_([^_].*)$} $name _ varname]} { return $varname } { return __ia($name) } }
::xowiki::FormPage instproc render_form_action_buttons {{-CSSclass {}}} { ::html::div -class form-button { set f [::xowiki::formfield::submit_button new -destroy_on_cleanup -name __form_button_ok -CSSclass $CSSclass] $f render_input } }
::xowiki::FormPage instproc reverse_map_value {map_type value category_ids_name} { # Perform the inverse function of map_value. During export, internal # representations are exchanged by string representations, which are # mapped here again to internal representations my upvar $category_ids_name category_ids if {[info exists ::__xowiki_reverse_category_map($value)]} { #my msg "map value '$value' (category tree: $use($name)) of [my name] to an ID" lappend category_ids $::__xowiki_reverse_category_map($value) return $::__xowiki_reverse_category_map($value) } elseif {$map_type eq "party_id"} { return [my reverse_map_party -entry $value -default_party $creation_user -create_user_ids $create_user_ids] } elseif {$value eq ""} { return "" } else { my msg "cannot map value '$value' (map_type $map_type) of [my name] to an ID; maybe there is some same_named category tree with less entries..." my msg "reverse category map has values [lsort [array names ::__xowiki_reverse_category_map]]" return "" } }
::xowiki::FormPage instproc reverse_map_values {map_type values category_ids_name} { # Apply reverse_map_value to a list of values (for multi-valued # form fields) my upvar $category_ids_name category_ids set mapped_values [list] foreach value $values {lappend mapped_values [my reverse_map_value $map_type $value category_ids]} return $mapped_values }
<instance of ::xowiki::FormPage> set_form_data form_fields
Store the instance attributes or default values in the form.
- Parameters:
- form_fields
::xowiki::FormPage instproc set_form_data form_fields { #my msg "set_form_value instance attributes = [my instance_attributes]" array set __ia [my instance_attributes] foreach f $form_fields { set att [$f name] # just handle fields of the form entry if {![my exists __field_in_form($att)]} continue #my msg "set form_value to form-field $att __ia($att)" if {[info exists __ia($att)]} { #my msg "my set_form_value from ia $att $__ia($att)" my set_form_value $att [$f convert_to_external $__ia($att)] } else { # do we have a value in the form? If yes, keep it. set form_value [my get_form_value $att] #my msg "no instance attribute, set form_value $att '[$f value]' form_value=$form_value" if {$att eq ""} { # we have no instance attributes, use the default value from the form field my set_form_value $att [$f convert_to_external [$f value]] } } } }
::xowiki::FormPage instproc set_form_value {att value} { #my msg "set_form_value $att $value" my instvar root item_id set fields [$root selectNodes "//form//*\[@name='$att'\]"] #my msg "found field = $fields xp=//*\[@name='$att'\]" foreach field $fields { # TODO missing: textarea if {[$field nodeName] ne "input"} continue set type [expr {[$field hasAttribute type] ? [$field getAttribute type] : "text"}] # the switch should be really different objects ad classes...., but thats HTML, anyhow. switch $type { checkbox { #my msg "$att: CHECKBOX value='$value', [$field hasAttribute checked], [$field hasAttribute value]" if {[$field hasAttribute value]} { set form_value [$field getAttribute value] #my msg "$att: form_value=$form_value, my value=$value" if {[lsearch -exact $value $form_value] > -1} { $field setAttribute checked true } elseif {[$field hasAttribute checked]} { $field removeAttribute checked } } else { #my msg "$att: CHECKBOX entry has no value" if {[catch {set f [expr {$value ? 1 : 0}]}]} {set f 1} if {$value eq "" || $f == 0} { if {[$field hasAttribute checked]} { $field removeAttribute checked } } else { $field setAttribute checked true } } } radio { set inputvalue [$field getAttribute value] #my msg "radio: compare input '$inputvalue' with '$value'" if {$inputvalue eq $value} { $field setAttribute checked true } } hidden - password - text { $field setAttribute value $value} default {my msg "can't handle $type so far $att=$value"} } } }
::xowiki::FormPage instproc set_property {{-new 0} name value} { if {[string match "_*" $name]} { set key [string range $name 1 end] set instance_attributes_refresh 0 } { set key __ia($name) set instance_attributes_refresh 1 } if {!$new && ![my exists $key]} { error "property '$name' ($key) does not exist. you might use flag '-new 1' for set_property to create new properties\n[lsort [my info vars]]" } my set $key $value if {$instance_attributes_refresh} { my instance_attributes [my array get __ia] } return $value }
::xowiki::FormPage instproc set_publish_status value { if {[lsearch -exact [list production ready] $value] == -1} { error "invalid value '$value'; use 'production' or 'ready'" } my set publish_status $value }
Methods: | Source: | Variables: |
---|---|---|
[All Methods | Documented Methods | Hide Methods] | [Display Source | Hide Source] | [Show Variables | Hide Variables] |