Index: openacs-4/contrib/misc/wizard-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/misc/wizard-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/contrib/misc/wizard-procs.tcl 28 Jul 2003 17:05:26 -0000 1.3 +++ openacs-4/contrib/misc/wizard-procs.tcl 3 Aug 2003 14:36:49 -0000 1.4 @@ -13,74 +13,74 @@ ad_proc -public template::wizard { command args } { alias proc to call the real template::wizard::proc } { - eval wizard::$command $args + eval wizard::$command $args } # create a wizard from a set of steps ad_proc -public template::wizard::create { args } {
example: - template::wizard create -action "wizard" -name my_wizard -params { - my_param1 my_param2 - } -steps { - 1 -label "Step 1" -url "step1" - 2 -label "Step 2" -url "step2" - 3 -label "Step 3" -url "step3" - } + template::wizard create -action "wizard" -name my_wizard -params { + my_param1 my_param2 + } -steps { + 1 -label "Step 1" -url "step1" + 2 -label "Step 2" -url "step2" + 3 -label "Step 3" -url "step3" + }
Set a wizard's param for passthrough
+Set a wizard's param for passthrough
-Normally you place this in the steps of the wizard where the - form has been processed. A param - is normally used when you want to reuse a value across the steps.
+Normally you place this in the steps of the wizard where the + form has been processed. A param + is normally used when you want to reuse a value across the steps.
-Note: if you are to use "template::wizard set_param" on a wizard file ex. - (wizard.tcl). Make sure to do it before "template::wizard get_current_step". - So when "template::wizard get_current_step" redirects it will properly set - the correct values of the param to the new value.
+Note: if you are to use "template::wizard set_param" on a wizard file ex. + (wizard.tcl). Make sure to do it before "template::wizard get_current_step". + So when "template::wizard get_current_step" redirects it will properly set + the correct values of the param to the new value.
} { - set level [template::adp_level] + set level [template::adp_level] - upvar #$level wizard:params params - set params($name) $value + upvar #$level wizard:params params + set params($name) $value } @@ -144,23 +144,23 @@ ad_proc -private template::wizard::add { step_id args } { Append a step to a wizard } { - get_reference + get_reference - lappend steps $step_id + lappend steps $step_id - # add the reference to the steps lookup array for the wizard - upvar #$level wizard:$step_id opts wizard:rowcount rowcount - incr rowcount - set opts(id) $step_id - set opts(rownum) $rowcount - set opts(link) [get_forward_url $opts(id)] + # add the reference to the steps lookup array for the wizard + upvar #$level wizard:$step_id opts wizard:rowcount rowcount + incr rowcount + set opts(id) $step_id + set opts(rownum) $rowcount + set opts(link) [get_forward_url $opts(id)] - # copy the reference for access as a multirow data source as well - upvar #$level wizard:$rowcount props + # copy the reference for access as a multirow data source as well + upvar #$level wizard:$rowcount props - template::util::get_opts $args + template::util::get_opts $args - array set props [array get opts] + array set props [array get opts] } @@ -177,65 +177,65 @@ are preserved. Once the form is finished processing the wizard will take over and rewrite the url. } { - get_reference + get_reference - upvar #$level wizard:current_id current_id - set current_id [ns_queryget wizard_step${wizard_name} [lindex $steps 0]] + upvar #$level wizard:current_id current_id + set current_id [ns_queryget wizard_step${wizard_name} [lindex $steps 0]] - upvar #$level wizard:visited_step visited_step - set visited_step [get_visited_step] + upvar #$level wizard:visited_step visited_step + set visited_step [get_visited_step] - # if there is no step state, we are likely in the first step. - # lets redirect with the proper state vars - if {[string equal [ns_queryget wizard_step${wizard_name}] ""]} { - template::forward [get_forward_url $current_id] - } + # if there is no step state, we are likely in the first step. + # lets redirect with the proper state vars + if {[string equal [ns_queryget wizard_step${wizard_name}] ""]} { + template::forward [get_forward_url $current_id] + } - # get a reference to the step - upvar #$level wizard:$current_id step + # get a reference to the step + upvar #$level wizard:$current_id step - upvar #$level wizard:current_url current_url + upvar #$level wizard:current_url current_url - # lets see if this step exists, if not we are finished with wizard and pass the steps - if [info exists step(url)] { - set current_url $step(url) - } else { - # if we have set_finish_url then we redirect to that url when we are finished - # otherwise increment the parent wizard step - if {[info exists wizard_finish_url]} { - template::forward $wizard_finish_url - } else { + # lets see if this step exists, if not we are finished with wizard and pass the steps + if [info exists step(url)] { + set current_url $step(url) + } else { + # if we have set_finish_url then we redirect to that url when we are finished + # otherwise increment the parent wizard step + if {[info exists wizard_finish_url]} { + template::forward $wizard_finish_url + } else { - # lets set the current wizard name to the parent wizard - set parent_wizard [lindex $wizards 0] - set wizard_name $parent_wizard + # lets set the current wizard name to the parent wizard + set parent_wizard [lindex $wizards 0] + set wizard_name $parent_wizard - # lets now increment step of the parent wizard - set parent_step [expr [ns_queryget wizard_step${parent_wizard}] + 1] - template::forward [get_forward_url $parent_step] - } - - } + # lets now increment step of the parent wizard + set parent_step [expr [ns_queryget wizard_step${parent_wizard}] + 1] + template::forward [get_forward_url $parent_step] + } + + } - # check for a "back" submission and forward immediately if so - # also check if we are backing up the current wizard or another wizard - - if { [ns_queryexists wizard_submit_back] && [string equal $wizard_name [ns_queryget wizard_name]]} { + # check for a "back" submission and forward immediately if so + # also check if we are backing up the current wizard or another wizard + + if { [ns_queryexists wizard_submit_back] && [string equal $wizard_name [ns_queryget wizard_name]]} { - set last_index [expr [lsearch -exact $steps $current_id] - 1] - set last_id [lindex $steps $last_index] - template::forward [get_forward_url $last_id] - } + set last_index [expr [lsearch -exact $steps $current_id] - 1] + set last_id [lindex $steps $last_index] + template::forward [get_forward_url $last_id] + } } ad_proc -private template::wizard::current_step {} { convinience method to get the step for the http params or from the wizard step definition } { - get_reference + get_reference - return [ns_queryget wizard_step${wizard_name} [lindex $steps 0]] + return [ns_queryget wizard_step${wizard_name} [lindex $steps 0]] } @@ -271,9 +271,9 @@ get the current wizard name } { - get_reference + get_reference - return $wizard_name + return $wizard_name } @@ -334,227 +334,243 @@ } { - variable default_button_labels + variable default_button_labels - get_reference - upvar 2 wizard_submit_buttons buttons - set buttons [list] + get_reference + upvar 2 wizard_submit_buttons buttons + set buttons [list] - set param_level [template::adp_level] - upvar #$param_level wizard:params params + set param_level [template::adp_level] + upvar #$param_level wizard:params params - template::util::get_opts $args - - # Handle the -buttons parameter - if { ![info exists opts(buttons)] } { - # jkyamog - is this really correct? when no buttons is present we put all of the buttons? - upvar 0 default_button_labels button_labels - } else { - foreach pair $opts(buttons) { - # If provided with just a name, use default label - if { [llength $pair] == 1 } { - set button_labels($pair) $default_button_labels($pair) - } else { - set button_labels([lindex $pair 0]) [lindex $pair 1] - } + template::util::get_opts $args + + # Handle the -buttons parameter + if { ![info exists opts(buttons)] } { + # jkyamog - is this really correct? when no buttons is present we put all of the buttons? + upvar 0 default_button_labels button_labels + } else { + foreach pair $opts(buttons) { + # If provided with just a name, use default label + if { [llength $pair] == 1 } { + set button_labels($pair) $default_button_labels($pair) + } else { + set button_labels([lindex $pair 0]) [lindex $pair 1] + } + } } - } - # Add a hidden element for the current wizard name - template::element create $form_id wizard_name -widget hidden -value $wizard_name -datatype keyword + # Add a hidden element for the current wizard name + template::element create $form_id wizard_name -widget hidden -value $wizard_name -datatype keyword - set current_id [current_step] + set current_id [current_step] - # Add a hidden element with the current ID - template::element create $form_id wizard_step${wizard_name} -widget hidden -value $current_id -datatype keyword + # Add a hidden element with the current ID + template::element create $form_id wizard_step${wizard_name} -widget hidden -value $current_id -datatype keyword - set step_index [expr [lsearch -exact $steps $current_id] + 1] + set step_index [expr [lsearch -exact $steps $current_id] + 1] - # If not the first one and it is allowed than add a "Back" button - if { $step_index > 1 && [info exists button_labels(back)] } { - template::element create $form_id wizard_submit_back -widget submit \ - -label $button_labels(back) -optional -datatype text + # If not the first one and it is allowed than add a "Back" button + if { $step_index > 1 && [info exists button_labels(back)] } { + template::element create $form_id wizard_submit_back -widget submit \ + -label $button_labels(back) -optional -datatype text - lappend buttons wizard_submit_back - } + lappend buttons wizard_submit_back + } - # If iteration is allowed than add a "Repeat" button - upvar #$level wizard:$current_id step - if { [info exists step(repeat)] && [info exists button_labels(repeat)]} { - template::element create $form_id wizard_submit_repeat -widget submit \ - -label $button_labels(repeat) -optional -datatype text - lappend buttons wizard_submit_repeat - } + # If iteration is allowed than add a "Repeat" button + upvar #$level wizard:$current_id step + if { [info exists step(repeat)] && [info exists button_labels(repeat)]} { + template::element create $form_id wizard_submit_repeat -widget submit \ + -label $button_labels(repeat) -optional -datatype text + lappend buttons wizard_submit_repeat + } - # If not the last one than add a "Next" button - if { $step_index < [llength $steps] && [info exists button_labels(next)] } { - template::element create $form_id wizard_submit_next -widget submit \ - -label $button_labels(next) -optional -datatype text - lappend buttons wizard_submit_next - } + # If not the last one than add a "Next" button + if { $step_index < [llength $steps] && [info exists button_labels(next)] } { + template::element create $form_id wizard_submit_next -widget submit \ + -label $button_labels(next) -optional -datatype text + lappend buttons wizard_submit_next + } - # Always finish - if { [info exists button_labels(finish) ] } { - template::element create $form_id wizard_submit_finish -widget submit \ - -label $button_labels(finish) -optional -datatype text - lappend buttons wizard_submit_finish - } + # Always finish + if { [info exists button_labels(finish) ] } { + template::element create $form_id wizard_submit_finish -widget submit \ + -label $button_labels(finish) -optional -datatype text + lappend buttons wizard_submit_finish + } - # Create hidden variables for wizard parameters - set levels [get_wizards_levels] - lappend levels $level + # Create hidden variables for wizard parameters + set levels [get_wizards_levels] + lappend levels $level - foreach onelevel $levels { - upvar #$onelevel wizard:properties properties - foreach param $properties(params) { - if { ![template::element::exists $form_id $param] } { - if { [info exists params($param)] } { - template::element create $form_id $param -widget hidden -datatype text -optional -param -value $params($param) - } else { - template::element create $form_id $param -widget hidden -datatype text -optional -param - } - } - } + foreach onelevel $levels { + upvar #$onelevel wizard:properties properties + foreach param $properties(params) { + if { ![template::element::exists $form_id $param] } { + if { [info exists params($param)] } { + template::element create $form_id $param -widget hidden -datatype text -optional -param -value $params($param) + } else { + template::element create $form_id $param -widget hidden -datatype text -optional -param + } + } + } - } + } - # Create hidden variables for the other wizard steps and visited steps - foreach one_wizard $wizards { - if { ![template::element::exists $form_id wizard_step${one_wizard}] } { - template::element create $form_id wizard_step${one_wizard} -widget hidden \ - -datatype keyword -value [ns_queryget wizard_step${one_wizard}] - } - if { ![template::element::exists $form_id wizard_visitedstep${one_wizard}] } { - template::element create $form_id wizard_visitedstep${one_wizard} -widget hidden \ - -datatype keyword -value [ns_queryget wizard_visitedstep${one_wizard}] - } - } + # Create hidden variables for the other wizard steps and visited steps + foreach one_wizard $wizards { + if { ![template::element::exists $form_id wizard_step${one_wizard}] } { + template::element create $form_id wizard_step${one_wizard} -widget hidden \ + -datatype keyword -value [ns_queryget wizard_step${one_wizard}] + } + if { ![template::element::exists $form_id wizard_visitedstep${one_wizard}] } { + template::element create $form_id wizard_visitedstep${one_wizard} -widget hidden \ + -datatype keyword -value [ns_queryget wizard_visitedstep${one_wizard}] + } + } } ad_proc -private template::wizard::get_reference {} { Get a reference to the wizard steps (internal helper) } { - - uplevel { + + uplevel { - variable parse_level - set level $parse_level + variable parse_level + set level $parse_level - upvar #$level wizard:steps steps wizard:properties properties wizard:name wizard_name wizard:wizards wizards wizard:finish_url wizard_finish_url - if { ! [info exists steps] } { - error "Wizard does not exist" + upvar #$level wizard:steps steps wizard:properties properties wizard:name wizard_name wizard:wizards wizards wizard:finish_url wizard_finish_url + if { ! [info exists steps] } { + error "Wizard does not exist" + } } - } } ad_proc -public template::wizard::exists {} { @return 1 if a wizard is currently defined } { - variable parse_level + variable parse_level - if { ![info exists parse_level] } { - return 0 - } + if { ![info exists parse_level] } { + return 0 + } - upvar #$parse_level wizard:steps steps + upvar #$parse_level wizard:steps steps - return [info exists steps] + return [info exists steps] } -ad_proc -public template::wizard::forward {} { +ad_proc -public template::wizard::forward { {cache_p "f"} {persistent_p "f"} {excluded_vars ""} } { call when a step has been validated and completed. checks which submit button was pressed and proceeds accordingly. } { - get_reference + get_reference - upvar #$level wizard:current_id current_id - set current_index [expr [lsearch -exact $steps $current_id] + 1] + upvar #$level wizard:current_id current_id + set current_index [expr [lsearch -exact $steps $current_id] + 1] - if { [ns_queryexists wizard_submit_next] } { + if { [ns_queryexists wizard_submit_next] } { - # figure out the next step and go there + # figure out the next step and go there - set next_id [lindex $steps $current_index] - template::forward [get_forward_url $next_id] + set next_id [lindex $steps $current_index] + template::forward [get_forward_url $next_id] $cache_p $persistent_p $excluded_vars - } elseif { [ns_queryexists wizard_submit_back] } { + } elseif { [ns_queryexists wizard_submit_back] } { - set last_id [lindex $steps [expr $current_index - 2]] - template::forward [get_forward_url $last_id] + set last_id [lindex $steps [expr $current_index - 2]] + template::forward [get_forward_url $last_id] $cache_p $persistent_p $excluded_vars - } elseif { [ns_queryexists wizard_submit_repeat] } { - - template::forward "[get_forward_url $current_id]&wizard_submit_repeat=t" + } elseif { [ns_queryexists wizard_submit_repeat] } { + + template::forward "[get_forward_url $current_id]&wizard_submit_repeat=t" $cache_p $persistent_p $excluded_vars - } elseif { [ns_queryexists wizard_submit_finish] } { + } elseif { [ns_queryexists wizard_submit_finish] } { -# template::forward $properties(action) -# NOTE : we are changing the behaviour of wizard, when its finish it will not reset and go back -# to step 1, it will blindly go forward and we will catch this on get_current_step - set next_id [expr $current_index + 1] - template::forward [get_forward_url $next_id] - } + # template::forward $properties(action) + # NOTE : we are changing the behaviour of wizard, when its finish it will not reset and go back + # to step 1, it will blindly go forward and we will catch this on get_current_step + set next_id [expr $current_index + 1] + template::forward [get_forward_url $next_id] $cache_p $persistent_p $excluded_vars + } } ad_proc -public template::wizard::get_forward_url { step_id } { Build the redirect URL for the next step } { - get_reference + variable parse_level + get_reference - set param_level [template::adp_level] - upvar #$param_level wizard:params params + set level [template::adp_level] - set url [ns_conn url]?wizard_step${wizard_name}=$step_id&wizard_name=$wizard_name - - # create the wizards and keep track of their steps too - foreach one_wizard $wizards { - append url "&wizard_step${one_wizard}=[ns_queryget wizard_step${one_wizard}]" - append url "&wizard_visitedstep${one_wizard}=[ns_queryget wizard_visitedstep${one_wizard}]" - } + upvar #$level wizard:params params - # check for passthrough parameters + set url [ns_conn url]?wizard_step=$step_id - set levels [get_wizards_levels] - lappend levels $level - set allparams {} + set multiple_listed [list] - foreach onelevel $levels { - upvar #$onelevel wizard:properties properties - if { [info exists properties(params)] } { - foreach param $properties(params) { + # check for passthrough parameters - if { [info exists params($param)] } { - set value $params($param) - } else { - set value [ns_queryget $param] - } - # we will only append unique params - if {[lsearch $allparams $param] == -1} { - append url "&$param=[ns_urlencode $value]" - lappend allparams $param - } - } - } - } + if { [info exists properties(params)] } { + foreach param $properties(params) { + upvar #$level $param value + set flags [split [lindex [split $param ":"] 1] ","] + if { [lsearch -exact [split [lindex [split $param ":"] 1] ","] "array"] != -1 || [array exists value] } { + # Array + foreach {index array_value} [array get value] { + if { [info exists array_value] && ![empty_string_p $array_value] } { + append url "&$param.$index=[ns_urlencode $array_value]" + } else { + append url "&$param.$index=" + } + } + } else { + # Normal Variable + if { [lsearch -exact [split [lindex [split $param ":"] 1] ","] "multiple"] != -1 } { + # Multiple + set param [lindex [split $param ":"] 0] + if { [lsearch -exact $multiple_listed $param] == -1 } { + foreach check_param $properties(params) { + if { [string equal [lindex [split $check_param ":"] 0] $param] } { + set value_list [ns_querygetall $param] + for { set i 0 } { $i < [llength $value_list] } { incr i } { + append url "&$param=[ns_urlencode [lindex $value_list $i]]" + } + } + } + lappend multiple_listed $param + } + } else { + # Normal Var + if { [info exists params($param)] } { + append url "&$param=[ns_urlencode $params($param)]" + } else { + append url "&$param=[ns_urlencode [ns_queryget $param]]" + } + } + } + } + } - return $url + return $url } ad_proc -public template::wizard::get_action_url {} { Retreive the URL to the action } { - - get_reference - return $properties(action) +get_reference + +return $properties(action) } @@ -573,7 +589,7 @@ } { get_reference - + # check the old visited step on the the state manager set visited_step [ad_get_client_property -default "" $key ${wizard_name}visited] if {![string equal $visited_step ""]} {