Index: openacs-4/packages/xowiki/tcl/form-field-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/form-field-procs.tcl,v diff -u -N -r1.9 -r1.10 --- openacs-4/packages/xowiki/tcl/form-field-procs.tcl 6 Jul 2007 13:35:12 -0000 1.9 +++ openacs-4/packages/xowiki/tcl/form-field-procs.tcl 9 Jul 2007 12:35:20 -0000 1.10 @@ -24,11 +24,13 @@ {help_text ""} {error_msg ""} {validator ""} + default } FormField instproc init {} { if {![my exists label]} {my label [string totitle [my name]]} if {![my exists id]} {my id [my name]} if {[my exists id]} {my set html(id) [my id]} + if {[my exists default]} {my set value [my default]} #my msg "calling config_from_spec '[my spec]'" my config_from_spec [my spec] } @@ -262,10 +264,25 @@ Class FormField::radio -superclass FormField -parameter { {options ""} + {horizontal false} } FormField::radio instproc initialize {} { my set widget_type text(radio) } + FormField::radio instproc render_form_widget {} { + set value [my value] + ::html::div -class form-widget { + foreach o [my options] { + foreach {label rep} $o break + set atts [list id [my id]:$rep name [my name] type radio value $rep] + #my msg "comparing value '$value' with rep '$rep'" + if {$value eq $rep} {lappend atts checked checked} + ::html::input $atts {} + html::t $label + if {![my horizontal]} {html::br} + } + } + } Class FormField::select -superclass FormField -parameter { {options ""} @@ -280,13 +297,13 @@ if {[my multiple]} {lappend atts multiple [my multiple]} ::html::select $atts { foreach o [my options] { - foreach {name value} $o break - set atts [list value $value] + foreach {label rep} $o break + set atts [list value $rep] #my msg "lsearch {[my value]} $value ==> [lsearch [my value] $value]" - if {[lsearch [my value] $value] > -1} { + if {[lsearch [my value] $rep] > -1} { lappend atts selected on } - ::html::option $atts {::html::t $name} + ::html::option $atts {::html::t $label} }}} } @@ -301,7 +318,9 @@ next } - Class FormField::boolean -superclass FormField -superclass FormField::radio + Class FormField::boolean -superclass FormField::radio -parameter { + {default t} + } FormField::boolean instproc initialize {} { # should be with cvs head message catalogs: # my options {{#acs-kernel.common_No# f} {#acs-kernel.common_Yes# t}} Index: openacs-4/packages/xowiki/tcl/xowiki-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-procs.tcl,v diff -u -N -r1.132 -r1.133 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 6 Jul 2007 20:27:04 -0000 1.132 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 9 Jul 2007 12:35:20 -0000 1.133 @@ -465,7 +465,15 @@ } Page instproc regsub_eval {re string cmd} { - subst [regsub -all $re [string map { \" \\\" \[ \\[ \] \\] \ +# my msg "re=$re, string=$string cmd=$cmd" +# set c [regsub -all $re [string map { \[ \\[ \] \\] \ +# \$ \\$ \\ \\\\} $string] \ +# "\[$cmd\]"] +# my msg c=$c +# set s [subst $c] +# my msg s=$s +# return $s + subst [regsub -all $re [string map { \[ \\[ \] \\] \ \$ \\$ \\ \\\\} $string] \ "\[$cmd\]"] } @@ -1249,7 +1257,43 @@ } } + FormInstance instproc get_value {before varname } { + #my msg "varname=$varname" + array set __ia [my set instance_attributes] + switch -glob $varname { + _* {set value [my set [string range $varname 1 end]]} + default { + if {[info exists __ia($varname)]} { + set value [set __ia($varname)] + } elseif {[my exists $varname]} { + set value [my $varname] + } else { + set value "**** unknown variable '$varname' ****" + } + } + } + set f [my create_form_field -name $varname -slot [my find_slot $varname] \ + -configuration [list -value $value]] + set value [$f pretty_value $value] + #my msg [$f serialize] + + #set short_spec [my get_short_spec $name] + #if {$short_spec ne ""} { + # set f [FormField new -volatile -name $name -spec $short_spec] + # return [$f pretty_value $value] + #} + + return $before$value + } + + FormInstance instproc adp_subst {content} { + set content [my regsub_eval \ + [template::adp_variable_regexp] $content {my get_value "\\\1" "\2"}] + #regsub -all $content {\1@\2;noquote@} content + return $content + } + FormInstance instproc save_data {old_name category_ids} { my log "-- [self args]" my instvar package_id name Index: openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl,v diff -u -N -r1.65 -r1.66 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 7 Jul 2007 16:50:35 -0000 1.65 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 9 Jul 2007 12:35:20 -0000 1.66 @@ -354,6 +354,7 @@ {-configuration ""} } { set short_spec [my get_short_spec $name] + #my msg "create form field, short_spec for '$name' = '$short_spec" set spec_list [list] if {$short_spec ne ""} {lappend spec_list $short_spec} if {$spec ne ""} {lappend spec_list $spec} @@ -446,79 +447,105 @@ set category_ids [list] set form_fields [my create_category_fields] set form [lindex [my get_from_template form] 0] - if {$form ne ""} { - array set name_map { - "_name" name "_title" title "_page_order" page_order - "_description" description "_nls_language" nls_language - } - array set __ia [my set instance_attributes] - # we have a form, we get for the time being all variables - foreach att [::xo::cc array names form_parameter] { - switch -glob -- $att { - __form_action - __object_name {} - __category_* { - foreach f $form_fields { - if {[$f name] eq $att} break - } - set value [$f value [::xo::cc form_parameter $att]] - foreach v $value {lappend category_ids $v} + array set name_map { + "_name" name "_title" title "_page_order" page_order + "_description" description "_nls_language" nls_language + } + array set __ia [my set instance_attributes] + # we have a form and get all form variables + foreach att [::xo::cc array names form_parameter] { + my msg "getting att=$att" + switch -glob -- $att { + __category_* { + foreach f $form_fields { + if {[$f name] eq $att} break } - _* { - # instance attribute fields - set f [my create_form_field -name $att -slot [my find_slot $name_map($att)]] - lappend form_fields $f - set value [$f value [::xo::cc form_parameter $att]] - my set $name_map($att) $value - } - default { - # user form content fields - set f [my create_form_field -name $att] - lappend form_fields $f - set value [$f value [::xo::cc form_parameter $att]] - set __ia($att) $value - } + set value [$f value [::xo::cc form_parameter $att]] + foreach v $value {lappend category_ids $v} } + __* { + # other internal variables (like __object names) are ignored + } + _* { + # instance attribute fields + set f [my create_form_field -name $att -slot [my find_slot $name_map($att)]] + lappend form_fields $f + set value [$f value [::xo::cc form_parameter $att]] + my set $name_map($att) $value + } + default { + # user form content fields + set f [my create_form_field -name $att] + lappend form_fields $f + set value [$f value [::xo::cc form_parameter $att]] + set __ia($att) $value + } } - - foreach f $form_fields { + } + + foreach f $form_fields { set validation_error [$f validate [self]] - #my msg "validation of [$f name] with value '[$f value]' returns $validation_error" - if {$validation_error ne ""} { - $f error_msg $validation_error - incr validation_errors - } + #my msg "validation of [$f name] with value '[$f value]' returns $validation_error" + if {$validation_error ne ""} { + $f error_msg $validation_error + incr validation_errors } - #my log "--set instance attributes to [array get __ia]" - my set instance_attributes [array get __ia] } + #my log "--set instance attributes to [array get __ia]" + my set instance_attributes [array get __ia] return [list $validation_errors $form_fields $category_ids] } - FormInstance instproc edit { + FormInstance instproc edit { {-validation_errors ""} } { my instvar page_template doc root package_id set form [lindex [my get_from_template form] 0] set anon_instances [my get_from_template anon_instances] + set page_instance_form_atts [list] + #if {$form eq ""} { + # # + # # nothing to do here, use standard ad_form behavior + # # + # #next -autoname $anon_instances -form_constraints $form_constraints + # return [next -autoname $anon_instances] + #} if {$form eq ""} { - # - # nothing to do here, use standard ad_form behavior - # - #next -autoname $anon_instances -form_constraints $form_constraints - return [next -autoname $anon_instances] + array set __ia [my set instance_attributes] + #set dont_edit [concat [[my info class] edit_atts] [list title] \ + # [::Generic::CrClass set common_query_atts]] + set template [lindex [my get_from_template text] 0] + #my msg template_vars=[my template_vars $template] + foreach {var _} [my template_vars $template] { + switch -glob $var { + _* {} + default { + set varname __ia($var) + lappend page_instance_form_atts $var $varname + if {![info exists $varname]} {set $varname ""} + } + } + #if {[lsearch $dont_edit $var] == -1} { + # set varname __ia($var) + #} + } + #my msg page_instance_form_atts=$page_instance_form_atts + set form "
" } - set field_names [list _title title _description description _nls_language nls_language] - if {[$package_id show_page_order]} { - set field_names [linsert $field_names 0 _page_order page_order] + set field_names [list] + if {!$anon_instances} { lappend field_names _name name } + if {[$package_id show_page_order]} { lappend field_names _page_order page_order } + lappend field_names _title title + foreach fn $page_instance_form_atts { lappend field_names $fn } + foreach fn [list _description description _nls_language nls_language] { + lappend field_names $fn } - if {!$anon_instances} { - set field_names [linsert $field_names 0 _name name] - } 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 # @@ -542,7 +569,11 @@ } else { set form_fields [my create_category_fields] foreach {form_att att} $field_names { - set value [my set $att] + if {[string match __ia* $att]} { + set value [set $att] + } else { + set value [my set $att] + } lappend form_fields [my create_form_field -name $form_att -slot [my find_slot $att] \ -configuration [list -value $value]] }