Index: openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-procs.tcl,v diff -u -r1.8 -r1.9 --- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 10 Nov 2003 16:56:56 -0000 1.8 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 12 Nov 2003 13:14:07 -0000 1.9 @@ -9,14 +9,108 @@ namespace eval simulation {} namespace eval simulation::action {} namespace eval simulation::object_type {} -namespace eval simulation::template {} namespace eval simulation::character {} namespace eval simulation::role {} ad_proc -public simulation::package_key {} { return simulation } +ad_proc -public simulation::include_contract { args } { + Used to define which parameters an include expecs. + + @param args A list where the first element is an explanation of what the + include does, who wrote it when etc. The second element is the optional + param spec which is an array list where the keys are parameter (variable) + names and the values are array lists where the keys + are parameter attributes. Examples below. + +
+      simulation::include_contract {
+          Displays a list of templates
+
+          @author Joel Aufrecht
+          @creation-date 2003-11-12
+          @cvs-id $Id$
+       } {
+           display_mode {
+               allowed_values {edit display}
+               default_value display
+           }
+           size {
+               allowed_values {short long}
+               default_value long
+           }
+       }     
+    
+ +
+      simulation::include_contract {
+          A list of all objects associated with the Simulation Template
+
+          @author Joel Aufrecht
+          @creation-date 2003-11-12
+          @cvs-id $Id$
+      } {
+          workflow_id {}
+      }     
+    
+ +

+ The following attributes can be used for parameters: + +

+

+ +

+ TODO: Have Lars review this proc and then move it into core +

+ + @author Peter Marklund +} { + set description [lindex $args 0] + if { [llength $args] == 1 } { + # No spec + return + } + + set spec [lindex $args 1] + array set spec_array $spec + + foreach param_name [array names spec_array] { + array unset param_array + array set param_array $spec_array($param_name) + + upvar $param_name param + + if { ![info exists param_array(required_p)] } { + set param_array(required_p) 1 + } + + # Set default values + if { ![info exists param] && [info exists param_array(default_value)] } { + set param $param_array(default_value) + } + + # Check required params are there + if { [string equal $param_array(required_p) 1] && ![info exists param] } { + error "Required parameter $param_name not provide to include" + } + + # Check param has valid value + if { [info exists param] && [info exists param_array(allowed_values)] } { + if { [lsearch -exact $param_array(allowed_values) $param] == -1 } { + error "Parameter $param_name passed to include has invalid value \"$param\". Valid values are: [join $param_array(allowed_values) ", "]" + } + } + } +} + ad_proc -public simulation::object_type::get_options { } { Generate a list of object types formatted as an option list for form-builder's widgets. foo. @@ -87,42 +181,6 @@ workflow::action::flush_cache -workflow_id $workflow_id } -ad_proc -public simulation::template::associate_object { - -template_id:required - -object_id:required -} { - Associate an object with a simulation template. Succeeds if the record is added or already exists. -} { - set exists_p [db_string row_exists { - select count(*) - from sim_workflow_object_map - where workflow_id = :template_id - and object_id = :object_id - }] - - if { ! $exists_p } { - db_dml add_object_to_workflow_insert { - insert into sim_workflow_object_map - values (:template_id, :object_id) - } - } -} - -ad_proc -public simulation::template::dissociate_object { - -template_id:required - -object_id:required -} { - Dissociate an object with a simulation template -} { - db_dml remove_object_from_workflow_delete { - delete from sim_workflow_object_map - where workflow_id = :template_id - and object_id = :object_id - } - # no special error handling because the delete is pretty safe - -} - template_tag relation { params } { publish::process_tag relation $params }