Index: openacs-4/packages/acs-templating/resources/forms/coddo.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/resources/forms/coddo.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-templating/resources/forms/coddo.adp 12 May 2002 20:57:02 -0000 1.2 +++ openacs-4/packages/acs-templating/resources/forms/coddo.adp 2 Jan 2003 17:10:39 -0000 1.3 @@ -49,7 +49,7 @@ \@formgroup.widget@ - \@formgroup.label@ + @@ -97,7 +97,21 @@ -
+ + + + + + + + + + + + + + +
Index: openacs-4/packages/acs-templating/resources/forms/grid.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/resources/forms/grid.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-templating/resources/forms/grid.adp 5 Jul 2002 15:56:53 -0000 1.2 +++ openacs-4/packages/acs-templating/resources/forms/grid.adp 2 Jan 2003 17:10:39 -0000 1.3 @@ -36,7 +36,7 @@ ~formgroup id=@elements.id@> - +
+formgroup.widget++formgroup.label++formgroup.widget+
@@ -70,7 +70,21 @@ - + + + + + + + + + + + + + + + Index: openacs-4/packages/acs-templating/resources/forms/plain.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/resources/forms/plain.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-templating/resources/forms/plain.adp 19 Jul 2002 23:17:15 -0000 1.3 +++ openacs-4/packages/acs-templating/resources/forms/plain.adp 2 Jan 2003 17:10:39 -0000 1.4 @@ -39,7 +39,7 @@ - +
\@formgroup.widget@\@formgroup.label@

@@ -79,7 +79,21 @@ -
+ + + + + + + + + + + + + + +
Index: openacs-4/packages/acs-templating/resources/forms/plainest.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/resources/forms/plainest.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-templating/resources/forms/plainest.adp 19 Jul 2002 23:17:15 -0000 1.1 +++ openacs-4/packages/acs-templating/resources/forms/plainest.adp 2 Jan 2003 17:10:39 -0000 1.2 @@ -39,7 +39,7 @@ - +
\@formgroup.widget@\@formgroup.label@

@@ -79,7 +79,21 @@ -
+ + + + + + + + + + + + + + +
Index: openacs-4/packages/acs-templating/resources/forms/standard-lars.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/resources/forms/Attic/standard-lars.adp,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-templating/resources/forms/standard-lars.adp 30 Nov 2002 17:24:05 -0000 1.7 +++ openacs-4/packages/acs-templating/resources/forms/standard-lars.adp 2 Jan 2003 17:10:39 -0000 1.8 @@ -1,20 +1,19 @@ - - +
- + Index: openacs-4/packages/acs-templating/resources/forms/wizard.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/resources/forms/wizard.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-templating/resources/forms/wizard.adp 5 Jul 2002 15:56:53 -0000 1.2 +++ openacs-4/packages/acs-templating/resources/forms/wizard.adp 2 Jan 2003 17:10:39 -0000 1.3 @@ -53,7 +53,7 @@ - + @@ -102,7 +102,21 @@ - + Index: openacs-4/packages/acs-templating/tcl/0-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/Attic/0-procs.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-templating/tcl/0-procs.tcl 14 Sep 2002 18:13:47 -0000 1.7 +++ openacs-4/packages/acs-templating/tcl/0-procs.tcl 2 Jan 2003 17:11:09 -0000 1.8 @@ -53,7 +53,7 @@ # default settings variable defaults - set defaults [list method post section {}] + set defaults [list method post section {} mode edit buttons { { "OK" ok } }] } namespace eval wizard { Index: openacs-4/packages/acs-templating/tcl/date-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/date-procs.tcl,v diff -u -r1.15 -r1.16 --- openacs-4/packages/acs-templating/tcl/date-procs.tcl 18 Nov 2002 18:01:07 -0000 1.15 +++ openacs-4/packages/acs-templating/tcl/date-procs.tcl 2 Jan 2003 17:11:09 -0000 1.16 @@ -729,7 +729,7 @@ } ad_proc -public template::widget::dateFragment { - element_reference fragment size type value } { + element_reference fragment size type value {mode edit} } { Create an input widget for the given date fragment If type is "t", uses a text widget for the fragment, with the given size. @@ -742,39 +742,52 @@ set value [template::util::date::get_property $fragment $value] set value [template::util::leadingTrim $value] - if { [info exists element(${fragment}_interval)] } { - set interval $element(${fragment}_interval) + if { ![string equal $mode "edit"] } { + set output {} + append output "" + append output $value + return $output } else { - # Display text entry for some elements, or if the type is text - if { [string equal $type t] || - [regexp "year|short_year" $fragment] } { - return "\n" - } else { - # Use a default range for others - set interval [template::util::date::defaultInterval $fragment] - } + if { [info exists element(${fragment}_interval)] } { + set interval $element(${fragment}_interval) + } else { + # Display text entry for some elements, or if the type is text + if { [string equal $type t] || + [regexp "year|short_year" $fragment] } { + return "\n" + } else { + # Use a default range for others + set interval [template::util::date::defaultInterval $fragment] + } + } + return [template::widget::numericRange "$element(name).$fragment" \ + $interval $size $value] } - - return [template::widget::numericRange "$element(name).$fragment" \ - $interval $size $value] } ad_proc -public template::widget::ampmFragment { - element_reference fragment size type value } { + element_reference fragment size type value {mode edit} } { Create a widget that shows the am/pm selection } { upvar $element_reference element set value [template::util::date::get_property $fragment $value] - return [template::widget::menu \ - "$element(name).$fragment" { {A.M. am} {P.M. pm}} $value {}] + if { ![string equal $mode "edit"] } { + set output {} + append output "" + append output $value + return $output + } else { + return [template::widget::menu \ + "$element(name).$fragment" { {A.M. am} {P.M. pm}} $value {}] + } } ad_proc -public template::widget::monthFragment { - element_reference fragment size type value } { + element_reference fragment size type value {mode edit} } { Create a month entry widget with short or long month names } { @@ -784,13 +797,22 @@ set value [template::util::date::get_property $fragment $value] - set options [list [list "--" {}]] - for { set i 1 } { $i <= 12 } { incr i } { - lappend options [list [template::util::date::monthName $i $size] $i] + if { ![string equal $mode "edit"] } { + set output {} + if { [exists_and_not_null value] } { + append output "" + append output [template::util::date::monthName $value $size] + } + return $output + } else { + set options [list [list "--" {}]] + for { set i 1 } { $i <= 12 } { incr i } { + lappend options [list [template::util::date::monthName $i $size] $i] + } + + return [template::widget::menu \ + "$element(name).$fragment" $options $value {} ] } - - return [template::widget::menu \ - "$element(name).$fragment" $options $value {} ] } @@ -890,12 +912,14 @@ # Output the widget set fragment_def $template::util::date::fragment_widgets([string toupper $token]) set fragment [lindex $fragment_def 1] + append output [template::widget::[lindex $fragment_def 0] \ element \ $fragment \ [lindex $fragment_def 2] \ $type \ - $value] + $value \ + $element(mode)] # Output the separator if { [string equal $sep " "] } { Index: openacs-4/packages/acs-templating/tcl/element-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/element-procs.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-templating/tcl/element-procs.tcl 24 Sep 2002 09:06:04 -0000 1.9 +++ openacs-4/packages/acs-templating/tcl/element-procs.tcl 2 Jan 2003 17:11:09 -0000 1.10 @@ -122,11 +122,15 @@ variable defaults array set opts $defaults - template::util::get_opts $args + # By default, the form/edit mode is set to the empty string + # Can be set to something else if you want + set opts(mode) {} # set the form section set opts(section) $form_properties(section) + template::util::get_opts $args + # set a name if none specified if { ! [info exists opts(name)] } { set opts(name) $opts(id) } @@ -151,8 +155,16 @@ # check for submission if { [template::form is_submission $form_id] || [info exists opts(param)] } { validate $form_id $element_id - } + } elseif { ![empty_string_p [ns_queryget "__edit"]] } { + # If the magic __edit button was hit, try to get values from the form still + # but don't do any validation + set opts(values) [querygetall opts] + # be careful not to clobber a default value if one has been specified + if { [llength $opts(values)] || ! [info exists opts(value)] } { + set opts(value) [lindex $opts(values) 0] + } + } } ad_proc -public template::element::set_properties { form_id element_id args } { @@ -360,6 +372,7 @@ if { ! [eval $v_code] } { # value is invalid according to custom validation code + # Do some expansion on $value, ${value}, $label, and ${label} lappend v_errors [string map [list \$value $value \${value} $value \$label $label \${label} $label] $v_message] set formerror($element_id:$v_name) [lindex $v_errors end] } Index: openacs-4/packages/acs-templating/tcl/form-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/form-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/packages/acs-templating/tcl/form-procs.tcl 21 Nov 2002 15:09:48 -0000 1.8 +++ openacs-4/packages/acs-templating/tcl/form-procs.tcl 2 Jan 2003 17:11:09 -0000 1.9 @@ -76,15 +76,18 @@ upvar #$level $id:submission submission if { [string equal $id request] } { - # request is the magic ID for the form holding query parameters set submission 1 - } else { - set submission [string equal $id [ns_queryget form:id]] } + if { ![empty_string_p [ns_queryget "__edit"]] } { + # The magic button named __edit means we should now be in edit mode + set submission 0 + set opts(mode) "edit" + } + # add elements specified at the time the form is created if { [info exists opts(elements)] } { @@ -136,7 +139,14 @@ upvar #$level $element_ref elements:${elements:rowcount} set "elements:${elements:rowcount}(rownum)" ${elements:rowcount} } - + + set buttons:rowcount 0 + foreach button $form_properties(buttons) { + incr buttons:rowcount + set "buttons:${buttons:rowcount}(label)" [lindex $button 0] + set "buttons:${buttons:rowcount}(name)" [lindex $button 1] + } + if { [string equal $style {}] } { set style standard } set file_stub [template::get_resource_path]/forms/$style @@ -226,6 +236,9 @@ if { [info exists $id:error] } { uplevel #$level "upvar 0 $id:error formerror" + + # There were errors on the form, force edit mode + set properties(mode) edit } else { @@ -235,6 +248,19 @@ if { [info exists formerror] } { unset formerror } } + # Propagate form mode to all form elements + foreach element_ref $elements { + + # get a reference by element ID + upvar #$level $element_ref element + + # Check if the element has an empty string mode, and in + # that case, set to form mode + if { [string equal $element(mode) {}] } { + set element(mode) $properties(mode) + } + } + # get any additional attributes developer specified to include in form tag if { [info exists properties(html)] } { array set attributes $properties(html) Index: openacs-4/packages/acs-templating/tcl/parse-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/parse-procs.tcl,v diff -u -r1.11 -r1.12 --- openacs-4/packages/acs-templating/tcl/parse-procs.tcl 12 Nov 2002 15:42:41 -0000 1.11 +++ openacs-4/packages/acs-templating/tcl/parse-procs.tcl 2 Jan 2003 17:11:09 -0000 1.12 @@ -408,7 +408,7 @@ # substitute array variable references # loop to handle the case of adjacent variable references, like @a@@b@ - while {[regsub -all [template::adp_array_variable_regexp] $code {\1$\2(\3)} code]} {} + while {[regsub -all [template::adp_array_variable_regexp] $code {\1${\2(\3)}} code]} {} # substitute simple variable references while {[regsub -all [template::adp_variable_regexp] $code {\1${\2}} code]} {} @@ -430,7 +430,7 @@ @author Peter Marklund (peter@collaboraid.biz) @creation-date 25 October 2002 } { - return {(^|[^\\])@([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)@} + return {(^|[^\\])@([a-zA-Z0-9_:]+)\.([a-zA-Z0-9_:]+)@} } ad_proc -public template::adp_variable_regexp {} { Index: openacs-4/packages/acs-templating/tcl/widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/widget-procs.tcl,v diff -u -r1.14 -r1.15 --- openacs-4/packages/acs-templating/tcl/widget-procs.tcl 15 Sep 2002 20:48:59 -0000 1.14 +++ openacs-4/packages/acs-templating/tcl/widget-procs.tcl 2 Jan 2003 17:11:09 -0000 1.15 @@ -38,31 +38,39 @@ upvar $element_reference element - if { [info exists element(html)] } { - array set attributes $element(html) - } - - array set attributes $tag_attributes - - set output "" } - - append output ">" - - if { [info exists element(value)] } { - # As per scottwseago's request - append output [ad_quotehtml $element(value)] - } - - append output "" - + return $output } @@ -94,22 +102,43 @@ set attributes(id) "$element(form_id):elements:$element(name):$element(value)" } - set output "" + # This is ugly, but it works: Only export the value when we're on a selected option + append output "\[ad_decode \$checked \"checked\" \"\" \"\"\]" + } + default { + if { [info exists element(value)] } { + append output [ad_quotehtml $element(value)] + append output "" + } + } + } + } else { + set output "" } - append output " />" - return $output } @@ -180,41 +209,59 @@ } ad_proc -public template::widget::menu { widget_name options_list values_list \ - attribute_reference } { + attribute_reference {mode edit} } { upvar $attribute_reference attributes - - set output "\n" + + foreach option $options_list { + + set label [lindex $option 0] + set value [lindex $option 1] + + append output " \n" + } + + append output "" } - append output "" - return $output } @@ -229,7 +276,7 @@ array set attributes $tag_attributes return [template::widget::menu \ - $element(name) $element(options) $element(values) attributes] + $element(name) $element(options) $element(values) attributes $element(mode)] } ad_proc -public template::widget::multiselect { element_reference tag_attributes } { @@ -255,7 +302,7 @@ } return [template::widget::menu \ - $element(name) $element(options) $element(values) attributes] + $element(name) $element(options) $element(values) attributes $element(mode)] } ad_proc -public template::data::transform::search { element_ref } { @@ -330,38 +377,6 @@ return [list $value] } - - -ad_proc -public template::widget::textarea { element_reference tag_attributes } { - - upvar $element_reference element - - if { [info exists element(html)] } { - array set attributes $element(html) - } - - array set attributes $tag_attributes - - set output "" - return $output -} - ad_proc -public template::widget::comment { element_reference tag_attributes } { upvar $element_reference element @@ -382,25 +397,8 @@ append output "

$element(header)

" } - append output "" - return $output } Index: openacs-4/packages/acs-templating/www/doc/demo/display-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/doc/demo/display-edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-templating/www/doc/demo/display-edit.adp 2 Jan 2003 17:11:32 -0000 1.1 @@ -0,0 +1,15 @@ + + + + + +

Customize a Sandwich

+
+ +
+ + Index: openacs-4/packages/acs-templating/www/doc/demo/display-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/doc/demo/display-edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-templating/www/doc/demo/display-edit.tcl 2 Jan 2003 17:11:32 -0000 1.1 @@ -0,0 +1,49 @@ +ad_page_contract { + @cvs-id $Id$ +} { + {grid ""} + cancel:optional +} -properties {} + +if { [info exists cancel] } { + ad_returnredirect [ad_conn url] + ad_script_abort +} + +form create sandwich -mode display + +element create sandwich grid \ + -label "grid" -optional \ + -datatype text -widget hidden + +element create sandwich nickname -html { size 30 } \ + -label "Sandwich Name" -datatype text -section "Name" + +element create sandwich protein \ + -label "Protein" -datatype text -widget radio \ + -options { {Bacon bacon} {Chicken chicken} {Beef beef} } -section "Contents" + +element create sandwich vitamins \ + -label "Vitamins" -datatype text -widget checkbox -optional \ + -options { {Lettuce lettuce} {Tomato tomato} \ + {Pickle pickle} {Sprouts sprouts} } -section "Contents" + +element create sandwich comments \ + -label "Comments" -datatype text -widget textarea -optional -section "Details" -help_text "For your own sake." + +element create sandwich creation_date \ + -label "Created date" -datatype date -widget date -optional -format {Month DD, YYYY} -section "Details" + + + +# Set defaults +if { [form is_request sandwich] } { + element set_properties sandwich vitamins -value {tomato} + # or: element set_value sandwich vitamins tomato + element set_properties sandwich grid -value $grid +} + +# Choose standard or gridded output +if { [string equal [element get_value sandwich grid] t] } { + ad_return_template sandwich-grid +} Index: openacs-4/packages/acs-templating/www/doc/demo/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/www/doc/demo/index.html,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-templating/www/doc/demo/index.html 13 Mar 2001 22:59:27 -0000 1.1 +++ openacs-4/packages/acs-templating/www/doc/demo/index.html 2 Jan 2003 17:11:32 -0000 1.2 @@ -434,6 +434,15 @@ + + + + + + + + +
- +
- +
- + @@ -103,18 +102,27 @@ - + -
@elements.section@
@elements.section@
- - + + + + + + + + + + + + +
-
Index: openacs-4/packages/acs-templating/resources/forms/standard.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/resources/forms/standard.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-templating/resources/forms/standard.adp 18 Nov 2002 18:01:06 -0000 1.3 +++ openacs-4/packages/acs-templating/resources/forms/standard.adp 2 Jan 2003 17:10:39 -0000 1.4 @@ -88,7 +88,21 @@

+ + + + + + + + + + + + + +
 \@formgroup.widget@\@formgroup.label@   

+ + + + + + + + + + + + + +
View
A form with display/edit modesViewSubmitSubmitView