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 -r1.11 -r1.12 --- openacs-4/packages/xowiki/tcl/form-field-procs.tcl 9 Jul 2007 12:47:15 -0000 1.11 +++ openacs-4/packages/xowiki/tcl/form-field-procs.tcl 10 Jul 2007 14:15:28 -0000 1.12 @@ -66,19 +66,6 @@ switch -glob $s { optional {my set required false} required {my set required true} - hidden {my class [self class]::hidden} - inform {my class [self class]::inform} - text {my class [self class]::text} - textarea {my class [self class]::textarea} - richtext {my class [self class]::richtext} - boolean {my class [self class]::boolean} - scale {my class [self class]::scale} - numeric {my class [self class]::text; #for the time being - } - select {my class [self class]::select} - #scale {my class [self class]::scale} - month {my class [self class]::month} - date {my class [self class]::date} label=* {my label [lindex [split $s =] 1]} help_text=* {my help_text [lindex [split $s =] 1]} *=* { @@ -98,7 +85,13 @@ my msg "Error during setting attribute [lindex $l 0] to value [lindex $l 1]: $errMsg" } } - default {my msg "Ignoring unknown spec for entry [my name]: '$s'"} + default { + if {[my isclass [self class]::$s]} { + my class [self class]::$s + } else { + my msg "Ignoring unknown spec for entry [my name]: '$s'" + } + } } } ::xotcl::Class::Parameter searchDefaults [self]; # todo will be different in xotcl 1.6.* @@ -142,9 +135,14 @@ return $spec } + FormField instproc render {} { + my render_form_widget + } + FormField instproc render_form_widget {} { # todo: for all types - set atts [list type text] + #my msg type=[my type] + set atts [list type [my type]] foreach att {size id name value} { if {[my exists $att]} {lappend atts $att [my set $att]} } @@ -190,23 +188,26 @@ Class FormField::hidden -superclass FormField FormField::hidden instproc initialize {} { - my instvar widget_type - set widget_type text(hidden) + my type hidden + my set widget_type text(hidden) } + FormField::hidden instproc render_item {} { + # don't render the labels + my render_form_widget + } + Class FormField::inform -superclass FormField FormField::inform instproc initialize {} { - my instvar widget_type - set widget_type text(inform) + my set widget_type text(inform) } Class FormField::text -superclass FormField -parameter { {size 80} } FormField::text instproc initialize {} { - my instvar widget_type html - set widget_type text - foreach p [list size] {if {[my exists $p]} {set html($p) [my $p]}} + my set widget_type text + foreach p [list size] {if {[my exists $p]} {my set html($p) [my $p]}} } Class FormField::textarea -superclass FormField -parameter { @@ -216,9 +217,8 @@ style } FormField::textarea instproc initialize {} { - my instvar widget_type options html - set widget_type text(textarea) - foreach p [list rows cols style] {if {[my exists $p]} {set html($p) [my $p]}} + my set widget_type text(textarea) + foreach p [list rows cols style] {if {[my exists $p]} {my set html($p) [my $p]}} } FormField::textarea instproc render_form_widget {} { ::html::div -class form-widget { @@ -237,29 +237,27 @@ {style "width: 100%"} } FormField::richtext instproc initialize {} { - my instvar widget_type options next - set widget_type richtext + my set widget_type richtext if {![my exists plugins]} { my plugins \ [parameter::get -parameter "XowikiXinhaDefaultPlugins" \ -default [parameter::get_from_package_key \ -package_key "acs-templating" -parameter "XinhaDefaultPlugins"]] } - set options [list] + my set options [list] foreach p [list editor plugins width height folder_id javascript] { - if {[my exists $p]} {lappend options $p [my $p]} + if {[my exists $p]} {my lappend options $p [my $p]} } } Class FormField::date -superclass FormField -parameter {format} FormField::date instproc initialize {} { - my instvar widget_type format - set widget_type date + my set widget_type date if {[my exists format]} { - set format [string map [list _ " "] [my format]] + my set format [string map [list _ " "] [my format]] } } @@ -279,7 +277,7 @@ #my msg "comparing value '$value' with rep '$rep'" if {$value eq $rep} {lappend atts checked checked} ::html::input $atts {} - html::t $label + html::t "$label " if {![my horizontal]} {html::br} } } Index: openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl,v diff -u -r1.70 -r1.71 --- openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl 7 Jul 2007 15:49:10 -0000 1.70 +++ openacs-4/packages/xowiki/tcl/xowiki-form-procs.tcl 10 Jul 2007 14:15:28 -0000 1.71 @@ -248,6 +248,20 @@ WikiForm instproc new_request {} { my instvar data + # + # get the defaults from the slots and set it in the data. + # This should not be necessary with xotocl 1.6.* + # + foreach f [my field_list] { + set s [$data find_slot $f] + if {$s ne "" && [$s exists default] && [$s default] ne ""} { + #my msg "new_request $f default = '[$s default]'" + $data set $f [$s default] + } + } + # + # set tthe following defaults manually + # $data set creator [::xo::get_user_name [::xo::cc user_id]] $data set nls_language [ad_conn locale] next 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 -r1.133 -r1.134 --- openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 9 Jul 2007 12:35:20 -0000 1.133 +++ openacs-4/packages/xowiki/tcl/xowiki-procs.tcl 10 Jul 2007 14:15:28 -0000 1.134 @@ -464,7 +464,12 @@ next } - Page instproc regsub_eval {re string cmd} { + Page instproc regsub_eval {{-noquote:boolean false} re string cmd} { + if {$noquote} { + set map { \[ \\[ \] \\] \$ \\$ \\ \\\\} + } else { + set map { \" \\\" \[ \\[ \] \\] \$ \\$ \\ \\\\} + } # my msg "re=$re, string=$string cmd=$cmd" # set c [regsub -all $re [string map { \[ \\[ \] \\] \ # \$ \\$ \\ \\\\} $string] \ @@ -473,9 +478,7 @@ # set s [subst $c] # my msg s=$s # return $s - subst [regsub -all $re [string map { \[ \\[ \] \\] \ - \$ \\$ \\ \\\\} $string] \ - "\[$cmd\]"] + uplevel [list subst [regsub -all $re [string map $map $string] "\[$cmd\]"]] } Page instproc error_during_render {msg} { @@ -683,7 +686,7 @@ if {[string first \{\{ $l] > -1 && [string first \}\} $l] == -1} continue set l [my regsub_eval $RE(anchor) $l {my anchor "\1" "\2"}] set l [my regsub_eval $RE(div) $l {my div "\2" "\3"}] - set l [my regsub_eval $RE(include) $l {my include "\1" "\2" "\3"}] + set l [my regsub_eval $RE(include) $l {my include "\\\1" "\2" "\3"}] regsub -all $RE(clean) $l {\1} l regsub -all $RE(clean2) $l { \1} l append content [string range $l 1 end] \n @@ -1214,32 +1217,47 @@ } FormInstance instproc form_attributes {} { + # + # this method returns the form attributes (not including _*) + # my instvar page_template 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] - set page_instance_form_atts [list] + #set field_names [list _name _title _description _creator _nls_language _page_order] + set field_names [list] if {$template ne ""} { foreach {var _} [my template_vars $template] { - if {[lsearch $dont_edit $var] == -1} {lappend page_instance_form_atts $var} + if {[string match _* $var]} continue + if {[lsearch $dont_edit $var] == -1} {lappend field_names $var} } } else { set form [lindex [my get_from_template form] 0] + 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 { - if {[$field nodeName] ne "input"} continue + 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 {[lsearch $page_instance_form_atts $att]} { - lappend page_instance_form_atts $att + if {[string match _* $att]} continue + if {[lsearch $page_instance_form_atts $att] > -1} { + lappend field_names $att } } } - return $page_instance_form_atts + return $field_names } + FormInstance instproc get_content {} { my instvar doc root package_id page_template set text [lindex [my get_from_template text] 0] @@ -1257,7 +1275,7 @@ } } - FormInstance instproc get_value {before varname } { + FormInstance instproc get_value {before varname} { #my msg "varname=$varname" array set __ia [my set instance_attributes] switch -glob $varname { @@ -1288,7 +1306,7 @@ } FormInstance instproc adp_subst {content} { - set content [my regsub_eval \ + set content [my regsub_eval -noquote true \ [template::adp_variable_regexp] $content {my get_value "\\\1" "\2"}] #regsub -all $content {\1@\2;noquote@} content return $content @@ -1321,16 +1339,6 @@ return [my item_id] } - # FormInstance ad_instproc save-form-data {} { -# Method to be called from a submit button of the form -# } { -# my instvar package_id name -# my save_data [::xo::cc form_parameter __object_name ""] -# my log "--forminstance redirect to [$package_id pretty_link $name]" -# $package_id returnredirect \ -# [my query_parameter "return_url" [$package_id pretty_link $name]] -# } - } source [file dirname [info script]]/xowiki-www-procs.tcl 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 -r1.66 -r1.67 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 9 Jul 2007 12:35:20 -0000 1.66 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 10 Jul 2007 14:15:28 -0000 1.67 @@ -73,6 +73,9 @@ return "
$footer
\n" } +} + +namespace eval ::xowiki { Page instproc view {{content ""}} { # view is used only for the toplevel call, when the xowiki page is viewed @@ -210,7 +213,11 @@ ns_return 200 [::xo::cc get_parameter content-type text/html] $content } } +} + +namespace eval ::xowiki { + Page instproc edit { {-new:boolean false} {-autoname:boolean false} @@ -334,14 +341,23 @@ my log "no pretty_name for variable $name in slot $slot" } + if {[$slot exists default]} { + #my msg "setting ff $name default = [$slot default]" + set default [$slot default] + } else { + set default "" + } + set f [FormField new -name $name \ -label $label \ -type [expr {[$slot exists datatype] ? [$slot set datatype] : "text"}] \ -help_text [expr {[$slot exists help_text] ? [$slot set help_text] : ""}] \ -validator [expr {[$slot exists validator] ? [$slot set validator] : ""}] \ -required [expr {[$slot exists required] ? [$slot set required] : "false"}] \ + -default $default \ -spec [join $spec_list ,] \ ] + $f destroy_on_cleanup eval $f configure $configuration return $f @@ -354,7 +370,7 @@ {-configuration ""} } { set short_spec [my get_short_spec $name] - #my msg "create form field, short_spec for '$name' = '$short_spec" + #my msg "create form field '$name', short_spec = '$short_spec" set spec_list [list] if {$short_spec ne ""} {lappend spec_list $short_spec} if {$spec ne ""} {lappend spec_list $spec} @@ -363,8 +379,25 @@ return $f } + PageInstance instproc lookup_form_field { + -name + form_fields + } { + set found 0 + foreach f $form_fields { + if {[$f name] eq $name} {set found 1; break} + } + if {!$found} { + error "No form field with name $name found" + } + return $f + } +} + +namespace eval ::xowiki { + FormInstance instproc create_category_fields {} { - set category_spec [my get_short_spec @categories] + set category_spec [my get_short_spec _categories] foreach f [split $category_spec ,] { if {$f eq "off"} {return [list]} } @@ -428,7 +461,11 @@ } } } +} + +namespace eval ::xowiki { + FormInstance ad_instproc set_form_data {} { Store the instance attributes in the form. } { @@ -438,28 +475,26 @@ my set_form_value $att $value } } +} - FormInstance ad_instproc get_form_data {} { + +namespace eval ::xowiki { + + FormInstance ad_instproc get_form_data {form_fields} { Get the values from the form and store it as instance attributes. } { set validation_errors 0 set category_ids [list] - set form_fields [my create_category_fields] - set form [lindex [my get_from_template form] 0] - 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" + #my msg "getting att=$att" switch -glob -- $att { __category_* { - foreach f $form_fields { - if {[$f name] eq $att} break - } + set f [my lookup_form_field -name $att $form_fields] set value [$f value [::xo::cc form_parameter $att]] foreach v $value {lappend category_ids $v} } @@ -468,23 +503,23 @@ } _* { # instance attribute fields - set f [my create_form_field -name $att -slot [my find_slot $name_map($att)]] - lappend form_fields $f + set f [my lookup_form_field -name $att $form_fields] set value [$f value [::xo::cc form_parameter $att]] - my set $name_map($att) $value + set varname [string range $att 1 end] + my set $varname $value } default { # user form content fields - set f [my create_form_field -name $att] - lappend form_fields $f + set f [my lookup_form_field -name $att $form_fields] set value [$f value [::xo::cc form_parameter $att]] + # my msg "value of $att is $value" set __ia($att) $value } } } foreach f $form_fields { - set validation_error [$f validate [self]] + 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 @@ -493,63 +528,112 @@ } #my log "--set instance attributes to [array get __ia]" my set instance_attributes [array get __ia] - return [list $validation_errors $form_fields $category_ids] + return [list $validation_errors $category_ids] } + FormInstance instproc form_field_as_html {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_form_field -name $name -slot [my find_slot $name]] + } + #my msg "$name $found [$f serialize]" + # render form field as html + set html [$f asHTML] + #my msg "$name $html" + return ${before}$html + } +} + +namespace eval ::xowiki { + + FormInstance instproc create_form_fields {field_names} { + + set form_fields [my create_category_fields] + set cr_field_spec [my get_short_spec _cr_fields] + set field_spec [my get_short_spec _fields] + + foreach att $field_names { + switch -glob -- $att { + __* {} + _* { + set varname [string range $att 1 end] + lappend form_fields [my create_form_field -name $att \ + -spec $cr_field_spec \ + -slot [my find_slot $varname]] + } + default { + lappend form_fields [my create_form_field -name $att \ + -spec $field_spec \ + -slot [my find_slot $att]] + } + } + } + return $form_fields + } + 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 ""} { - array set __ia [my set instance_attributes] - #set dont_edit [concat [[my info class] edit_atts] [list title] \ - # [::Generic::CrClass set common_query_atts]] + # + # Since we have no form, we create it on the fly + # from the template variables and the form field specifications. + # set template [lindex [my get_from_template text] 0] - #my msg template_vars=[my template_vars $template] + #TODO rethink. form-attributes are set below foreach {var _} [my template_vars $template] { switch -glob $var { - _* {} + _* { + # we need no variables for the instance attributes + } 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 formgiven 0 + } else { + set formgiven 1 } + set form_attributes [my form_attributes] 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 + lappend field_names _name + if {[$package_id show_page_order]} { lappend field_names _page_order } + lappend field_names _title + foreach fn $form_attributes { lappend field_names $fn } + foreach fn [list _description _nls_language] { lappend field_names $fn } + + set cr_fields [list] + foreach f $field_names { + if {![string match _* $f]} continue + lappend cr_fields $f } + #my msg form_atts=$form_attributes + #my msg cr_fields=$cr_fields + set form_fields [my create_form_fields $field_names] + if {$anon_instances} { + set f [my lookup_form_field -name _name $form_fields] + $f spec hidden + } + if {[my form_parameter __form_action ""] eq "save-form-data"} { - my msg "we have to validate" + #my msg "we have to validate" # # we have to valiate and save the form data # - foreach {validation_errors form_fields category_ids} [my get_form_data] break + 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 msg "$f: [$f name] '[$f set value]' err: [$f error_msg] " } @@ -561,24 +645,40 @@ # my instvar name my save_data [::xo::cc form_parameter __object_name ""] $category_ids - my log "--forminstance redirect to [$package_id pretty_link $name]" + #my log "--forminstance redirect to [$package_id pretty_link $name]" $package_id returnredirect \ [my query_parameter "return_url" [$package_id pretty_link $name]] return } } else { - set form_fields [my create_category_fields] - foreach {form_att att} $field_names { - if {[string match __ia* $att]} { - set value [set $att] - } else { - set value [my set $att] + # + # display the current values + # + array set __ia [my set instance_attributes] + foreach att $field_names { + switch -glob $att { + __* {} + _* { + set f [my lookup_form_field -name $att $form_fields] + set varname [string range $att 1 end] + $f value [my set $varname] + } + default { + set f [my lookup_form_field -name $att $form_fields] + if {[info exists __ia($att)]} { + $f value $__ia($att) + } + } } - lappend form_fields [my create_form_field -name $form_att -slot [my find_slot $att] \ - -configuration [list -value $value]] } } + + set form [my regsub_eval \ + [template::adp_variable_regexp] $form \ + {my form_field_as_html "\\\1" "\2" $form_fields}] + #my msg form=$form + dom parse -simple -html $form doc $doc documentElement root ::require_html_procs @@ -590,15 +690,11 @@ ::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 (for named entries, e.g. name and title) - foreach {form_att att} $field_names { - # try to find the field in the field_list (fields are found on validaton errors) - foreach f $form_fields { - if {[$f name] eq $form_att} { - $f render_item - break - } - } + # insert automatic form fields on top + foreach att $field_names { + if {$formgiven && ![string match _* $att]} continue + set f [my lookup_form_field -name $att $form_fields] + $f render_item } } $fcn #