Index: openacs-4/packages/xowiki/tcl/repeat-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/repeat-procs.tcl,v diff -u -N -r1.6 -r1.7 --- openacs-4/packages/xowiki/tcl/repeat-procs.tcl 7 Aug 2017 23:48:30 -0000 1.6 +++ openacs-4/packages/xowiki/tcl/repeat-procs.tcl 21 Oct 2017 16:49:45 -0000 1.7 @@ -17,32 +17,31 @@ # - maybe deactivate container display for "repeat=1..1" ::xowiki::formfield::FormField instproc repeat {range} { - if {[my exists __initialized_repeat]} return + if {[info exists :__initialized_repeat]} return - set oldClass [my info class] - my class ::xowiki::formfield::repeatContainer + set oldClass [:info class] + :class ::xowiki::formfield::repeatContainer - if {$oldClass ne [my info class]} { - my reset_parameter - my set __state reset + if {$oldClass ne [:info class]} { + :reset_parameter + set :__state reset } if {$range ne ""} { - my instvar min max if {[regexp {^(\d*)[.][.](\d*)$} $range _ low high]} { - if {$low ne ""} {set min $low} - if {$high ne ""} {set max $high} - if {$min > $max} { - error "invalid range '$range' specified (lower limit $min must not be larger than higher limit $max)" + if {$low ne ""} {set :min $low} + if {$high ne ""} {set :max $high} + if {${:min} > ${:max}} { + error "invalid range '$range' specified (lower limit ${:min} must not be larger than higher limit ${:max})" } - if {$min < 0 || $max < 1} { - error "invalid range '$range' specified (max $max must be at least 1) " + if {${:min} < 0 || ${:max} < 1} { + error "invalid range '$range' specified (max ${:max} must be at least 1) " } } else { error "invalid range '$range' specified (must be of form 'min..max')" } } - my initialize + :initialize } ########################################################### @@ -63,7 +62,7 @@ # set result {} set is_required false - foreach s [split [my spec] ,] { + foreach s [split [:spec] ,] { # don't propagate "repeat" and "label" properties if { [string match "repeat=*" $s] || [string match "label=*" $s] } continue if { "required" eq $s} {set is_required true; continue} @@ -77,15 +76,15 @@ ::xo::Page requireJS "/resources/xowiki/jquery/jquery.min.js" #::xo::Page requireJS "/resources/ajaxhelper/jquery/jquery-1.11.1.min.js" - if {[my exists __initialized_repeat]} {return} + if {[info exists :__initialized_repeat]} {return} next - my set __initialized_repeat 1 + set :__initialized_repeat 1 # # Derive the spec of the contained items from the spec of the # container. # - lassign [my item_spec] isRequired itemSpec + lassign [:item_spec] isRequired itemSpec # # Use item .0 as template for other items in .js (e.g. blank an @@ -107,23 +106,23 @@ # support do incrementally add form fields in js, we have to # generate it here. # - set max [my max] + set max [:max] } else { - #set max [my max] - set max [my min] ;# use dynamic repeat fields: if set to min, repeat fields will be created on demand + #set max [:max] + set max [:min] ;# use dynamic repeat fields: if set to min, repeat fields will be created on demand } #ns_log notice "dynamic repeat MAX=$max FORMACTION <$formAction>" for {set i 1} {$i <= $max} {incr i} { - set componentItemSpec [my component_item_spec $i $itemSpec $isRequired] + set componentItemSpec [:component_item_spec $i $itemSpec $isRequired] #ns_log notice "dynamic repeat componentItemSpec $componentItemSpec" lappend componentItemSpecs $componentItemSpec } - my create_components $componentItemSpecs + :create_components $componentItemSpecs # # Deactivate template item # - set componentList [my components] + set componentList [:components] if {[llength $componentList] > 0} { [lindex $componentList 0] set_disabled true [lindex $componentList 0] set_is_repeat_template true @@ -135,7 +134,7 @@ # Return a single itemspec suited for the nth component, derived # from the repeatable formfield spec. # - if {$i <= [my min] && $isRequired} { + if {$i <= [:min] && $isRequired} { set componentItemSpec [list $i $itemSpec,required,label=$i] } else { set componentItemSpec [list $i $itemSpec,label=$i] @@ -147,10 +146,10 @@ # # Require the nth component of a repeat field # - lassign [my item_spec] isRequired itemSpec - set componentItemSpec [my component_item_spec $i $itemSpec $isRequired] + lassign [:item_spec] isRequired itemSpec + set componentItemSpec [:component_item_spec $i $itemSpec $isRequired] #ns_log notice "dynamic repeat field: add component on the fly: $componentItemSpec" - my add_component $componentItemSpec + :add_component $componentItemSpec } repeatContainer instproc set_compound_value value { @@ -162,7 +161,7 @@ set availableComponents [llength ${:components}] #ns_log notice "[self] repeatContainer set_compound_value <$value> have $availableComponents needed $neededComponents" if {$neededComponents > $availableComponents} { - lassign [my item_spec] isRequired itemSpec + lassign [:item_spec] isRequired itemSpec for {set i $availableComponents} {$i < $neededComponents} {incr i} { :require_component $i } @@ -172,15 +171,15 @@ } repeatContainer instproc convert_to_internal {} { - set values [my value] - my trim_values + set values [:value] + :trim_values set r [next] - #my msg name=[my name],value=[my get_compound_value] + #my msg name=[:name],value=[:get_compound_value] # # remove "unneeded" entries from instance attributes # - [my object] instvar instance_attributes + [:object] instvar instance_attributes foreach {name value} $values { if {[dict exists $instance_attributes $name]} { dict unset instance_attributes $name @@ -192,17 +191,17 @@ repeatContainer instproc trim_values {} { # Trim trailing values idential to default. # Trimming the components list seems sufficient. - set count [my count_values [my value]] - my set components [lrange [my components] 0 $count] + set count [:count_values [:value]] + set :components [lrange [:components] 0 $count] } repeatContainer instproc count_values {values} { set count 1 set highestCount 1 - if {![my required]} {set highestCount [my min]} + if {![:required]} {set highestCount [:min]} # The first pair is the default from the template field (.0) set default [lindex $values 1] - foreach f [lrange [my components] 1 end] {name value} [lrange $values 2 end] { + foreach f [lrange [:components] 1 end] {name value} [lrange $values 2 end] { if {[$f required] || ($value ne "" && ![$f same_value $value $default])} {set highestCount $count} incr count } @@ -215,22 +214,21 @@ # Render content of the container within in a fieldset, # without labels for the contained items. # - html::fieldset [my get_attributes id {CSSclass class}] { + html::fieldset [:get_attributes id {CSSclass class}] { set i 0 - my instvar min max name - set clientData "{'min':$min,'max':$max, 'name':'$name'}" - set CSSclass "[my form_widget_CSSclass] repeatable" - set providedValues [my count_values [my value]] - if {$min > $providedValues} { - set nrItems $min + set clientData "{'min':${:min},'max':${:max}, 'name':'${:name}'}" + set CSSclass "[:form_widget_CSSclass] repeatable" + set providedValues [:count_values [:value]] + if {${:min} > $providedValues} { + set nrItems ${:min} } else { set nrItems $providedValues } incr nrItems - set containerIsDisabled [expr {[my exists disabled] && [my disabled] != "false"}] - set containerIsPrototype [string match "*.0*" $name] + set containerIsDisabled [expr {[info exists :disabled] && [:disabled] != "false"}] + set containerIsPrototype [string match "*.0*" ${:name}] set isPrototypeElement 0 - foreach c [my components] { + foreach c [:components] { set atts [list class $CSSclass] lappend atts data-repeat $clientData if {$i == 0 || $i >= $nrItems} { @@ -244,7 +242,7 @@ ::html::a -href "#" \ -id $del_id \ -class "repeat-del-link" { - html::t [my repeat_remove_label] + html::t [:repeat_remove_label] } template::add_event_listener \ -id $del_id \ @@ -255,14 +253,14 @@ } #ns_log notice "repeat container $c [$c name] isDisabled $containerIsDisabled containerIsPrototype $containerIsPrototype" if {!$containerIsDisabled || $containerIsPrototype } { - set hidden [expr {[my count_values [my value]] == $max ? "display: none;" : ""}] - set add_id "repeat-add-link-[my id]" - ns_log notice "... add another for $name" + set hidden [expr {[:count_values [:value]] == ${:max} ? "display: none;" : ""}] + set add_id "repeat-add-link-[:id]" + ns_log notice "... add another for ${:name}" html::a -href "#" \ -id $add_id \ -style $hidden \ -class "repeat-add-link" { - html::t [my repeat_add_label] + html::t [:repeat_add_label] } template::add_event_listener \ -id $add_id \ @@ -272,7 +270,7 @@ } repeatContainer instproc validate {obj} { - foreach c [lrange [my components] 1 [my count_values [my value]]] { + foreach c [lrange [:components] 1 [:count_values [:value]]] { set result [$c validate $obj] if {$result ne ""} { return $result @@ -287,7 +285,7 @@ # set ff [dict create {*}$v] set html "
    \n" - foreach c [lrange [my components] 1 [my count_values [my value]]] { + foreach c [lrange [:components] 1 [:count_values [:value]]] { if {[dict exists $ff [$c set name]]} { append html "
  1. [$c pretty_value [dict get $ff [$c set name]]]
  2. \n" } @@ -303,12 +301,12 @@ # - view mode: the fields were deactivted (made insensitive); # this means: keep the old value - if {[my exists disabled]} {return $default} else {return ""} + if {[info exists :disabled]} {return $default} else {return ""} } Class create repeattest -superclass CompoundField repeattest instproc initialize {} { - my create_components [subst { + :create_components [subst { {sub {text,repeat=1..4}} }] next