Index: openacs-4/contrib/packages/simulation/lib/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-template-tasks.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/contrib/packages/simulation/lib/sim-template-tasks.tcl 15 Dec 2003 15:28:20 -0000 1.12 +++ openacs-4/contrib/packages/simulation/lib/sim-template-tasks.tcl 16 Dec 2003 18:34:00 -0000 1.13 @@ -87,7 +87,7 @@ } { set "label_state_$state_id" $pretty_name lappend elements state_$state_id \ - [list label "\"Edit\" \${label_state_$state_id}" \ + [list label "\"Edit\" \${label_state_$state_id} \"Delete\"" \ html { align center } \ display_template " Index: openacs-4/contrib/packages/simulation/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/action-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/contrib/packages/simulation/tcl/action-procs.tcl 15 Dec 2003 15:28:20 -0000 1.5 +++ openacs-4/contrib/packages/simulation/tcl/action-procs.tcl 16 Dec 2003 18:34:00 -0000 1.6 @@ -8,67 +8,152 @@ namespace eval simulation::action {} - -# TODO: add simulation::action::new - ad_proc -public simulation::action::edit { - {-action_id:required} + {-operation "update"} + {-action_id {}} {-workflow_id {}} - {-array:required} + {-array {}} {-internal:boolean} } { - Edit an action. Mostly a wrapper for FSM, plus some simulation-specific stuff. + Edit an action. - Available attributes: recipient (role_id), recipient_role (role short_name), attachment_num + @param operation insert, update, delete + + @param action_id For update/delete: The action to update or delete. + For insert: Optionally specify a pre-generated action_id for the action. + + @param workflow_id For update/delete: Optionally specify the workflow_id. If not specified, we will execute a query to find it. + For insert: The workflow_id of the new action. + + @param array For insert/update: Name of an array in the caller's namespace with attributes to insert/update. + + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. + + @return action_id + + @see workflow::action::fsm::edit } { - upvar 1 $array org_row - if { ![array exists org_row] } { - error "Array $array does not exist or is not an array" + switch $operation { + update - delete { + if { [empty_string_p $action_id] } { + error "You must specify the action_id of the action to $operation." + } + } + insert {} + default { + error "Illegal operation '$operation'" + } } - array set row [array get org_row] + switch $operation { + insert - update { + upvar 1 $array org_row + if { ![array exists org_row] } { + error "Array $array does not exist or is not an array" + } + array set row [array get org_row] + } + } + switch $operation { + insert { + if { [empty_string_p $workflow_id] } { + error "You must supply workflow_id" + } + } + update - delete { + if { [empty_string_p $workflow_id] } { + set workflow_id [workflow::action::get_element \ + -action_id $action_id \ + -element workflow_id] + } + } + } - set set_clauses [list] - - # Handle attributes in sim_tasks table - if { [info exists row(recipient_role)] } { - if { [empty_string_p $row(recipient_role)] } { - set row(recipient) [db_null] - } else { - # Get role_id by short_name - set row(recipient) [workflow::role::get_id \ + # Parse column values + switch $operation { + insert - update { + # Special-case: array entry recipient_role (short_name) and recipient (state_id) -- DB column is recipient (state_id) + if { [info exists row(recipient_role)] } { + if { [info exists row(role)] } { + error "You cannot supply both recipient_role (takes short_name) and recipient (takes state_id)" + } + if { [empty_string_p $row(recipient_role)] } { + set row(recipient) [db_null] + } else { + # Get role_id by short_name + set row(recipient) [workflow::role::get_id \ -workflow_id $workflow_id \ -short_name $row(recipient_role)] - } - unset row(recipient_role) - } + } + unset row(recipient_role) + } - foreach attr { - recipient attachment_num - } { - if { [info exists row($attr)] } { - set varname attr_$attr - # Convert the Tcl value to something we can use in the query - set $varname $row($attr) - # Add the column to the SET clause - lappend set_clauses "$attr = :$varname" - unset row($attr) + set update_clauses [list] + set insert_names [list] + set insert_values [list] + + # Handle columns in the sim_tasks table + foreach attr { + recipient attachment_num + } { + if { [info exists row($attr)] } { + set varname attr_$attr + # Convert the Tcl value to something we can use in the query + switch $attr { + default { + set $varname $row($attr) + } + } + # Add the column to the insert/update statement + switch $attr { + default { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } + } + unset row($attr) + } + } } } - + db_transaction { - if { [llength $set_clauses] > 0 } { - db_dml edit_sim_role " - update sim_tasks - set [join $set_clauses ", "] - where task_id = :action_id - " - } + # Base row + set action_id [workflow::action::fsm::edit \ + -internal \ + -operation $operation \ + -action_id $action_id \ + -workflow_id $workflow_id \ + -array row] - workflow::action::fsm::edit \ - -internal \ - -action_id $action_id \ - -workflow_id $workflow_id \ - -array row + # sim_tasks row + switch $operation { + insert { + lappend insert_names task_id + lappend insert_values :action_id + + db_dml insert_action " + insert into sim_tasks + ([join $insert_names ", "]) + values + ([join $insert_values ", "]) + " + } + update { + if { [llength $update_clauses] > 0 } { + db_dml update_action " + update sim_tasks + set [join $update_clauses ", "] + where task_id = :action_id + " + } + } + delete { + # Handled through cascading delete + } + } if { !$internal_p } { workflow::definition_changed_handler -workflow_id $workflow_id @@ -78,4 +163,30 @@ if { !$internal_p } { workflow::flush_cache -workflow_id $workflow_id } + + return $action_id } + + +ad_proc -public simulation::action::get { + {-action_id:required} + {-array:required} +} { + Get information about a simulation action +} { + upvar 1 $array row + + workflow::action::fsm::get -action_id $action_id -array row + + db_1row select_action { + select recipient, + (select short_name + from workflow_roles + where role_id = recipient) as recipient_role, + attachment_num + from sim_tasks + where task_id = :action_id + } -column_array local_row + + array set row [array get local_row] +} Index: openacs-4/contrib/packages/simulation/tcl/role-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/role-procs.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/contrib/packages/simulation/tcl/role-procs.tcl 12 Dec 2003 12:21:39 -0000 1.7 +++ openacs-4/contrib/packages/simulation/tcl/role-procs.tcl 16 Dec 2003 18:34:00 -0000 1.8 @@ -8,52 +8,147 @@ namespace eval simulation::role {} -ad_proc -public simulation::role::new { - {-template_id:required} - {-short_name {}} - {-pretty_name:required} +ad_proc -public simulation::role::edit { + {-operation "update"} + {-role_id {}} + {-workflow_id {}} + {-array {}} + {-internal:boolean} } { - Create a new simulation role for a given simulation template. - Will map the character to the template if this - is not already done. + Edit a role. - @author Peter Marklund -} { - db_transaction { - set role_id [workflow::role::new \ - -workflow_id $template_id \ - -short_name $short_name \ - -pretty_name $pretty_name] + @param operation insert, update, delete - db_dml insert_sim_role { - insert into sim_roles (role_id) values (:role_id) - } - } -} + @param role_id For update/delete: The role to update or delete. + For insert: Optionally specify a pre-generated role_id for the role. -ad_proc -public simulation::role::delete { - {-role_id:required} + @param workflow_id For update/delete: Optionally specify the workflow_id. If not specified, we will execute a query to find it. + For insert: The workflow_id of the new role. + + @param array For insert/update: Name of an array in the caller's namespace with attributes to insert/update. + + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. + + @return role_id + + @see workflow::role::fsm::edit } { + switch $operation { + update - delete { + if { [empty_string_p $role_id] } { + error "You must specify the role_id of the role to $operation." + } + } + insert {} + default { + error "Illegal operation '$operation'" + } + } + switch $operation { + insert - update { + upvar 1 $array org_row + if { ![array exists org_row] } { + error "Array $array does not exist or is not an array" + } + array set row [array get org_row] + } + } + switch $operation { + insert { + if { [empty_string_p $workflow_id] } { + error "You must supply workflow_id" + } + } + update { + if { [empty_string_p $workflow_id] } { + set workflow_id [workflow::role::get_element \ + -role_id $role_id \ + -element workflow_id] + } + } + } + + # Parse column values + switch $operation { + insert - update { + set update_clauses [list] + set insert_names [list] + set insert_values [list] + + # Handle columns in the sim_tasks table + foreach attr { + character_id + } { + if { [info exists row($attr)] } { + set varname attr_$attr + # Convert the Tcl value to something we can use in the query + switch $attr { + default { + set $varname $row($attr) + } + } + # Add the column to the insert/update statement + switch $attr { + default { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } + } + unset row($attr) + } + } + } + } + db_transaction { - workflow::role::delete -role_id $role_id + # Base row + set role_id [workflow::role::edit \ + -internal \ + -operation $operation \ + -role_id $role_id \ + -workflow_id $workflow_id \ + -array row] - db_dml delete_sim_role { - delete from sim_roles where role_id = :role_id + # sim_roles row + switch $operation { + insert { + lappend insert_names role_id + lappend insert_values :role_id + + db_dml insert_role " + insert into sim_roles + ([join $insert_names ", "]) + values + ([join $insert_values ", "]) + " + } + update { + if { [llength $update_clauses] > 0 } { + db_dml update_role " + update sim_roles + set [join $update_clauses ", "] + where task_id = :role_id + " + } + } + delete { + # Handled through cascading delete + } } + + if { !$internal_p } { + workflow::definition_changed_handler -workflow_id $workflow_id + } } -} -ad_proc -public simulation::role::edit { - {-role_id:required} - {-character_id:required} -} { - Edit a simulation role. -} { - db_dml edit_sim_role { - update sim_roles - set character_id = :character_id - where role_id = :role_id + if { !$internal_p } { + workflow::flush_cache -workflow_id $workflow_id } + + return $role_id } ad_proc -public simulation::role::get { @@ -63,10 +158,16 @@ Get information about a simulation role } { upvar 1 $array row + + workflow::role::get -role_id $role_id -array row + db_1row select_sim_role { select role_id, character_id from sim_roles where role_id = :role_id - } -column_array row + } -column_array local_row + + array set row [array get local_row] } + Index: openacs-4/contrib/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.tcl,v diff -u -r1.17 -r1.18 --- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 16 Dec 2003 16:30:47 -0000 1.17 +++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 16 Dec 2003 18:34:00 -0000 1.18 @@ -22,22 +22,201 @@ @author Peter Marklund } { + # Wrapper for simulation::template::edit + + foreach elm { pretty_name short_name sim_type suggested_duration package_key object_id } { + set row($elm) [set $elm] + } + + set workflow_id [simulation::template::edit \ + -operation "insert" \ + -array row] + + return $workflow_id +} + +ad_proc -public simulation::template::edit { + {-operation "update"} + {-workflow_id {}} + {-array {}} + {-internal:boolean} +} { + Edit a workflow. + + @param operation insert, update, delete + + @param workflow_id For update/delete: The workflow to update or delete. + + @param array For insert/update: Name of an array in the caller's namespace with attributes to insert/update. + + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. + + @return workflow_id + + @see workflow::edit +} { + switch $operation { + update - delete { + if { [empty_string_p $workflow_id] } { + error "You must specify the workflow_id of the workflow to $operation." + } + } + insert {} + default { + error "Illegal operation '$operation'" + } + } + switch $operation { + insert - update { + upvar 1 $array org_row + if { ![array exists org_row] } { + error "Array $array does not exist or is not an array" + } + array set row [array get org_row] + } + } + + # Parse column values + switch $operation { + insert - update { + set update_clauses [list] + set insert_names [list] + set insert_values [list] + + # Handle columns in the sim_tasks table + foreach attr { + sim_type suggested_duration + enroll_type casting_type + enroll_start enroll_end send_start_note_date case_start case_end + } { + if { [info exists row($attr)] } { + set varname attr_$attr + # Convert the Tcl value to something we can use in the query + switch $attr { + suggested_duration { + if { [empty_string_p $row($attr)] } { + set $varname [db_null] + } else { + set $varname "interval '[db_quote $row($attr)]'" + } + } + default { + set $varname $row($attr) + } + } + # Add the column to the insert/update statement + switch $attr { + enroll_start - enroll_end - send_start_note_date - case_start - case_end { + lappend update_clauses "$attr = to_date('[db_quote $row($attr)]', 'YYYY-MM-DD')" + lappend insert_names $attr + lappend insert_values "to_date('[db_quote $row($attr)]', 'YYYY-MM-DD')" + } + suggested_duration { + if { [empty_string_p $row($attr)] } { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } else { + lappend update_clauses "$attr = [set $varname]" + lappend insert_names $attr + lappend insert_values [set $varname] + } + } + default { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } + } + unset row($attr) + } + } + # Handle auxillary rows + array set aux [list] + foreach attr { + enrolled invited auto-enroll + } { + if { [info exists row($attr)] } { + set aux($attr) $row($attr) + unset row($attr) + } + } + + } + } + db_transaction { - set workflow_id [workflow::new \ - -short_name $short_name \ - -pretty_name $pretty_name \ - -package_key $package_key \ - -object_id $object_id] + # Base row + set workflow_id [workflow::edit \ + -internal \ + -operation $operation \ + -workflow_id $workflow_id \ + -array row] + + # sim_tasks row + switch $operation { + insert { + lappend insert_names simulation_id + lappend insert_values :workflow_id + + db_dml insert_workflow " + insert into sim_simulations + ([join $insert_names ", "]) + values + ([join $insert_values ", "]) + " + } + update { + if { [llength $update_clauses] > 0 } { + db_dml update_workflow " + update sim_simulations + set [join $update_clauses ", "] + where simulation_id = :workflow_id + " + } + } + delete { + # Handled through cascading delete + } + } - insert_sim \ - -workflow_id $workflow_id \ - -sim_type $sim_type \ - -suggested_duration $suggested_duration + # Update sim_party_sim_map table + foreach map_type { enrolled invited auto-enroll } { + if { [info exists aux($map_type)] } { + # Clear out old mappings first + db_dml clear_old_mappings { + delete from sim_party_sim_map + where simulation_id = :workflow_id + and type = :map_type + } + + # Map each party + foreach party_id $aux(enroll_groups) { + db_dml map_party_to_template { + insert into sim_party_sim_map + (simulation_id, party_id, type) + values (:workflow_id, :party_id, :map_type) + } + } + } + unset aux($map_type) + } + + if { !$internal_p } { + workflow::definition_changed_handler -workflow_id $workflow_id + } } + if { !$internal_p } { + workflow::flush_cache -workflow_id $workflow_id + } + return $workflow_id } + ad_proc -public simulation::template::new_from_spec { {-package_key {}} {-object_id {}} @@ -70,6 +249,7 @@ return $workflow_id } +# TODO: Get rid of this -- still called from clone and new_from_spec ad_proc -private simulation::template::insert_sim { {-workflow_id:required} {-sim_type "dev_template"} @@ -91,109 +271,10 @@ db_dml new_sim " insert into sim_simulations (simulation_id, sim_type, suggested_duration) - values (:workflow_id, :sim_type, interval '[db_quote $suggested_duration]')" + values (:workflow_id, :sim_type, interval '[db_quote $suggested_duration]')" } } -ad_proc -public simulation::template::edit { - {-workflow_id:required} - {-array:required} -} { - Edit a new simulation template. TODO: need better tests for duration before passing it into the database. - - @param workflow_id The id of the template to edit. - @param array The name of an array in the callers scope that contains properties to edit. - - @return nothing - - @author Joel Aufrecht -} { - upvar $array edit_array - - db_transaction { - - # Update workflows table - - # TODO: this should be in a new API call, workflow::edit - set set_clauses [list] - foreach col {short_name pretty_name package_key object_id description} { - if { [info exists edit_array($col)] } { - lappend set_clauses "$col = :$col" - set $col $edit_array($col) - } - } - - if { [llength $set_clauses] > 0 } { - db_dml edit_workflow " - update workflows - set [join $set_clauses ", "] - where workflow_id=:workflow_id" - } - - # Update sim_simulations table - - set set_clauses [list] - foreach col {sim_type enroll_type casting_type} { - if { [info exists edit_array($col)] } { - lappend set_clauses "$col = :$col" - set $col $edit_array($col) - } - } - - if { [info exists edit_array(suggested_duration)] } { - if { [empty_string_p $edit_array($col)] } { - lappend set_clauses "$col = null" - } else { - lappend set_clauses "$col = (interval '$edit_array($col)')" - } - - set parties $edit_array(suggested_duration) - } - - foreach col {enroll_start enroll_end send_start_note_date case_start case_end} { - if { [info exists edit_array($col)] } { - lappend set_clauses "$col = to_date(:$col, 'YYYY-MM-DD')" - set $col $edit_array($col) - } - } - - if { [llength $set_clauses] > 0 } { - db_dml edit_sim " - update sim_simulations - set [join $set_clauses ", "] - where simulation_id=:workflow_id - " - } - - # Update sim_party_sim_map table - - foreach map_type {enrolled invited auto-enroll} { - - if { [info exists edit_array($map_type)] } { - - # Clear out old mappings first - db_dml clear_old_mappings { - delete from sim_party_sim_map - where simulation_id = :workflow_id - and type = :map_type - } - - # Map each party - foreach party_id $edit_array(enroll_groups) { - db_dml map_party_to_template { - insert into sim_party_sim_map - (simulation_id, party_id, type) - values (:workflow_id, :party_id, :map_type) - } - } - } - } - - # TODO: invite_groups - } -} - - ad_proc -public simulation::template::delete_role_group_mappings { {-workflow_id} } { @@ -239,6 +320,7 @@ } } +# TODO: Fix the cascading clone API situation ad_proc -public simulation::template::clone { {-workflow_id:required} {-package_key {}} @@ -312,7 +394,10 @@ } { upvar $array row - db_1row select_template {} -column_array row + workflow::get -array row -workflow_id $workflow_id + + db_1row select_template {} -column_array local_row + array set row [array get local_row] } ad_proc -public simulation::template::get_parties { @@ -387,28 +472,14 @@ return [expr [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]] } -ad_proc -public simulation::template::get_workflow_id_from_action { - {-action_id:required} -} { - Given an action_id, return the workflow_id - - @param action_id ID of action in workflow -} { - return [db_string select_workflow_id { - select wa.workflow_id - from workflow_actions wa - where wa.action_id = :action_id - }] -} - ad_proc -public simulation::template::delete { {-workflow_id:required} } { Delete a simulation template. @author Peter Marklund } { - workflow::delete -workflow_id $workflow_id + simulation::template::edit -workflow_id $workflow_id -operation delete } ad_proc -public simulation::template::associate_object { @@ -444,7 +515,6 @@ and object_id = :object_id } # no special error handling because the delete is pretty safe - } ad_proc -public simulation::template::start { Index: openacs-4/contrib/packages/simulation/www/simbuild/role-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/role-delete.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/simbuild/role-delete.tcl 2 Dec 2003 17:24:32 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/simbuild/role-delete.tcl 16 Dec 2003 18:34:00 -0000 1.3 @@ -6,7 +6,7 @@ } { {confirm_p:boolean "f"} role_id:integer - {return_url "."} + {return_url ""} } set package_id [ad_conn package_id] @@ -19,16 +19,21 @@ or st.recipient = :role_id " ] +workflow::role::get -role_id $role_id -array role_array +set name $role_array(pretty_name) +set workflow_id $role_array(workflow_id) + +if { [empty_string_p $return_url] } { + set return_url [export_vars -base template-edit { workflow_id }] +} + if { [template::util::is_true $confirm_p] || $num_of_tasks == 0 } { - permission::require_write_permission -object_id $role_id - simulation::role::delete -role_id $role_id + permission::require_write_permission -object_id $workflow_id + simulation::role::edit -operation "delete" -role_id $role_id ad_returnredirect $return_url } -workflow::role::get -role_id $role_id -array role_array -set name $role_array(pretty_name) -set workflow_id $role_array(workflow_id) -workflow::get -workflow_id $workflow_id -array sim_template_array +workflow::get -workflow_id $workflow_id -array sim_template_array set page_title "Delete $name" set context [list [list "." "Sim Templates"] [list "template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] Index: openacs-4/contrib/packages/simulation/www/simbuild/role-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/role-edit.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/contrib/packages/simulation/www/simbuild/role-edit.tcl 10 Dec 2003 16:06:46 -0000 1.6 +++ openacs-4/contrib/packages/simulation/www/simbuild/role-edit.tcl 16 Dec 2003 18:34:00 -0000 1.7 @@ -46,11 +46,15 @@ {html {size 20}} } } -edit_request { - workflow::role::get -role_id $role_id -array role_array + simulation::role::get -role_id $role_id -array role_array set workflow_id $role_array(workflow_id) + permission::require_write_permission -object_id $workflow_id + set pretty_name $role_array(pretty_name) + workflow::get -workflow_id $workflow_id -array sim_template_array + set page_title "Edit Role template $pretty_name" set context [list [list "." "Sim Templates"] [list "template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] @@ -62,26 +66,27 @@ } -new_data { permission::require_write_permission -object_id $workflow_id - simulation::role::new \ - -template_id $workflow_id \ - -pretty_name $pretty_name + set operation "insert" } -edit_data { - workflow::role::get -role_id $role_id -array role_array # We use role_array(workflow_id) here, which is gotten from the DB, and not # workflow_id, which is gotten from the form, because the workflow_id from the form # could be spoofed - permission::require_write_permission -object_id $role_array(workflow_id) + workflow::role::get -role_id $role_id -array role_array + set workflow_id $role_array(workflow_id) + permission::require_write_permission -object_id $workflow_id + set operation "update" +} -after_submit { set row(pretty_name) $pretty_name set row(short_name) {} - workflow::role::edit \ - -role_id $role_id \ - -workflow_id $workflow_id \ - -array row - -} -after_submit { + set role_id [simulation::role::edit \ + -operation $operation \ + -role_id $role_id \ + -workflow_id $workflow_id \ + -array row] + ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort } Index: openacs-4/contrib/packages/simulation/www/simbuild/state-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/state-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/simbuild/state-delete.tcl 16 Dec 2003 18:34:00 -0000 1.1 @@ -0,0 +1,16 @@ +ad_page_contract { + Delete a state + +} { + state_id:integer + {return_url ""} +} + +set workflow_id [workflow::state::fsm::get_element -state_id $state_id -element workflow_id] +permission::require_write_permission -object_id $workflow_id +workflow::state::fsm::edit -operation "delete" -state_id $state_id + +if { [empty_string_p $return_url] } { + set return_url [export_vars -base template-edit { workflow_id }] +} +ad_returnredirect $return_url Index: openacs-4/contrib/packages/simulation/www/simbuild/state-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/state-edit.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/www/simbuild/state-edit.tcl 9 Dec 2003 15:58:13 -0000 1.1 +++ openacs-4/contrib/packages/simulation/www/simbuild/state-edit.tcl 16 Dec 2003 18:34:00 -0000 1.2 @@ -75,27 +75,25 @@ permission::require_write_permission -object_id $workflow_id } -new_data { permission::require_write_permission -object_id $workflow_id - # create the state - set state_id [workflow::state::fsm::new \ - -workflow_id $workflow_id \ - -pretty_name $pretty_name] - + set operation "insert" } -edit_data { # We use state_array(workflow_id) here, which is gotten from the DB, and not # workflow_id, which is gotten from the form, because the workflow_id from the form # could be spoofed - permission::require_write_permission -object_id $state_array(workflow_id) - + set workflow_id $state_array(workflow_id) + permission::require_write_permission -object_id $workflow_id + set operation "update" +} -after_submit { set row(pretty_name) $pretty_name set row(short_name) {} - workflow::state::fsm::edit \ - -state_id $state_id \ - -workflow_id $state_array(workflow_id) \ - -array row + set state_id [workflow::state::fsm::edit \ + -operation $operation \ + -state_id $state_id \ + -workflow_id $workflow_id \ + -array row] -} -after_submit { ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort } Index: openacs-4/contrib/packages/simulation/www/simbuild/task-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/task-delete.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/simbuild/task-delete.tcl 2 Dec 2003 17:24:32 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/simbuild/task-delete.tcl 16 Dec 2003 18:34:00 -0000 1.3 @@ -3,10 +3,14 @@ } { action_id:integer - {return_url "."} + {return_url ""} } -permission::require_write_permission -object_id $action_id -workflow::action::fsm::delete -action_id $action_id +set workflow_id [workflow::action::get_element -action_id $action_id -element workflow_id] +permission::require_write_permission -object_id $workflow_id +simulation::action::edit -operation "delete" -action_id $action_id -ad_returnredirect $return_url \ No newline at end of file +if { [empty_string_p $return_url] } { + set return_url [export_vars -base template-edit { workflow_id }] +} +ad_returnredirect $return_url Index: openacs-4/contrib/packages/simulation/www/simbuild/task-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/task-edit.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/contrib/packages/simulation/www/simbuild/task-edit.tcl 16 Dec 2003 17:58:08 -0000 1.12 +++ openacs-4/contrib/packages/simulation/www/simbuild/task-edit.tcl 16 Dec 2003 18:34:00 -0000 1.13 @@ -43,7 +43,7 @@ set package_id [ad_conn package_id] if { ![ad_form_new_p -key action_id] } { - workflow::action::fsm::get -action_id $action_id -array task_array + simulation::action::get -action_id $action_id -array task_array set workflow_id $task_array(workflow_id) } @@ -132,26 +132,16 @@ } -edit_request { set workflow_id $task_array(workflow_id) permission::require_write_permission -object_id $workflow_id - set pretty_name $task_array(pretty_name) set description [template::util::richtext::create $task_array(description) $task_array(description_mime_type)] - set new_state_id $task_array(new_state_id) - - db_1row select_recipient { - select recipient as recipient_role_id, attachment_num - from sim_tasks - where task_id = :action_id - } - if { ![empty_string_p $recipient_role_id] } { - set recipient_role [workflow::role::get_element -role_id $recipient_role_id -element short_name] - } else { - set recipient_role {} + foreach elm { + pretty_name new_state_id + assigned_role recipient_role + assigned_state_ids enabled_state_ids + attachment_num + } { + set $elm $task_array($elm) } - - set assigned_role $task_array(assigned_role) - - set assigned_state_ids $task_array(assigned_state_ids) - set enabled_state_ids $task_array(enabled_state_ids) } -new_request { permission::require_write_permission -object_id $workflow_id @@ -162,63 +152,37 @@ set description_mime_type [template::util::richtext::get_property format $description] set description [template::util::richtext::get_property contents $description] - if { ![empty_string_p $recipient_role] } { - set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role] - } else { - set recipient_role_id [db_null] + foreach elm { + pretty_name assigned_role description description_mime_type + enabled_state_ids assigned_state_ids new_state_id + recipient_role attachment_num + } { + set row($elm) [set $elm] } + set row(short_name) {} + } -new_data { permission::require_write_permission -object_id $workflow_id - # create the task + set operation "insert" - db_transaction { - set action_id [workflow::action::fsm::new \ - -workflow_id $workflow_id \ - -pretty_name $pretty_name \ - -assigned_role $assigned_role \ - -description $description \ - -description_mime_type $description_mime_type \ - -enabled_state_ids $enabled_state_ids \ - -assigned_state_ids $assigned_state_ids \ - -new_state_id $new_state_id] - - # TODO - put this stuff into simulation api and change previous call - # and then add extra data for simulation - # because workflow::action::fsm::new wants role.short_name instead of - # role_id, we stay consistent for recipient_role - - array unset row - set row(recipient_role) $recipient_role - set row(attachment_num) $attachment_num - - simulation::action::edit \ - -action_id $action_id \ - -workflow_id $workflow_id \ - -array row - } } -edit_data { # We use task_array(workflow_id) here, which is gotten from the DB, and not # workflow_id, which is gotten from the form, because the workflow_id from the form # could be spoofed - permission::require_write_permission -object_id $task_array(workflow_id) + set workflow_id $task_array(workflow_id) - # TODO: Set short_name right, - # or leave blank and have the workflow API construct a short_name + permission::require_write_permission -object_id $workflow_id - # TODO: enabled_states, assigned_states - array unset row - foreach col { pretty_name assigned_role recipient_role description description_mime_type enabled_state_ids assigned_state_ids attachment_num } { - set row($col) [set $col] - } - set row(short_name) {} - set row(new_state_id) $new_state_id + set operation "update" - simulation::action::edit \ - -action_id $action_id \ - -workflow_id $task_array(workflow_id) \ - -array row - } -after_submit { + + set action_id [simulation::action::edit \ + -operation $operation \ + -workflow_id $workflow_id \ + -action_id $action_id \ + -array row] + ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort } Index: openacs-4/contrib/packages/simulation/www/simbuild/template-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-delete.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/simbuild/template-delete.tcl 2 Dec 2003 17:24:32 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-delete.tcl 16 Dec 2003 18:34:00 -0000 1.3 @@ -14,6 +14,6 @@ set page_title "Deleting template \"$template_name\"" set template_list_url . -set context [list [list $template_list_url "Templates"] $page_title] +set context [list [list $template_list_url "SimBuild"] $page_title] simulation::template::delete -workflow_id $workflow_id Index: openacs-4/contrib/packages/simulation/www/simbuild/template-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-edit.adp,v diff -u -r1.9 -r1.10 --- openacs-4/contrib/packages/simulation/www/simbuild/template-edit.adp 11 Dec 2003 14:24:29 -0000 1.9 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-edit.adp 16 Dec 2003 18:34:00 -0000 1.10 @@ -1,7 +1,7 @@ @page_title;noquote@ @context;noquote@ - sim_template.name + sim_template.pretty_name Index: openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-edit.tcl,v diff -u -r1.11 -r1.12 --- openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl 15 Dec 2003 14:50:12 -0000 1.11 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl 16 Dec 2003 18:34:00 -0000 1.12 @@ -35,7 +35,7 @@ ad_form -name sim_template -mode $mode -cancel_url $cancel_url -form { {workflow_id:key} - {name:text,optional + {pretty_name:text,optional {label "Template Name"} {html {size 40}} } @@ -60,64 +60,69 @@ {suggested_duration:text,optional {label "Suggested Duration"} } - {description:text(textarea),optional - {label "TODO: Description and
Description-mime-type"} + {description:richtext(richtext),optional + {label "Description"} {html {cols 60 rows 8}} } } -edit_request { permission::require_write_permission -object_id $workflow_id + simulation::template::get -workflow_id $workflow_id -array sim_template_array - set name $sim_template_array(pretty_name) - set description $sim_template_array(description) + set pretty_name $sim_template_array(pretty_name) + + set description [template::util::richtext::create $sim_template_array(description) $sim_template_array(description_mime_type)] + # translate sim_type to ready/not-ready - # TODO: we should only see ready_template and dev_template here, so maybe assert that? - if {$sim_template_array(sim_type) == "ready_template"} { - set template_ready_p "t" - } else { - set template_ready_p "f" + + if { [lsearch { dev_template ready_template } $sim_template_array(sim_type)] == -1 } { + error "Can only handle dev_template and ready_template sim_types here." } + set template_ready_p [db_boolean [string equal $sim_template_array(sim_type) "ready_template"]] + set suggested_duration $sim_template_array(suggested_duration) } -new_request { permission::require_permission -object_id $package_id -privilege sim_template_create - + +} -on_submit { + set description_mime_type [template::util::richtext::get_property format $description] + set description [template::util::richtext::get_property contents $description] } -new_data { permission::require_permission -object_id $package_id -privilege sim_template_create - set workflow_id [simulation::template::new \ - -short_name $name \ - -pretty_name $name \ - -suggested_duration $suggested_duration \ - -package_key $package_key \ - -object_id $package_id] + set operation "insert" + + set row(package_key) $package_key + set row(object_id) $package_id + set row(sim_type) "dev_template" } -edit_data { - if {$template_ready_p == "t"} { - set sim_type "ready_template" + if { [template::util::is_true $template_ready_p] } { + set row(sim_type) "ready_template" } else { - set sim_type "dev_template" + set row(sim_type) "dev_template" } permission::require_write_permission -object_id $workflow_id + set operation "update" - set simulation(short_name) $name - set simulation(pretty_name $name - set simulation(sim_type) $sim_type - set simulation(suggested_duration) $suggested_duration - set simulation(package_key) $package_key - set simulation(object_id) $package_id - set simulation(description) $description - simulation::template::edit \ - -workflow_id $workflow_id \ - -array simulation - } -after_submit { + set row(short_name) {} + foreach elm { pretty_name suggested_duration description description_mime_type } { + set row($elm) [set $elm] + } + + set workflow_id [simulation::template::edit \ + -operation $operation \ + -workflow_id $workflow_id \ + -array row] + ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort @@ -143,7 +148,7 @@ set page_title "New Simulation Template" } edit { - set page_title "Editing $name" + set page_title "Editing $pretty_name" } } Index: openacs-4/contrib/packages/simulation/www/simbuild/template-load.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-load.adp,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/www/simbuild/template-load.adp 11 Dec 2003 15:32:43 -0000 1.1 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-load.adp 16 Dec 2003 18:34:00 -0000 1.2 @@ -1,7 +1,7 @@ @page_title;noquote@ @context;noquote@ - load.spec + load.pretty_name Index: openacs-4/packages/simulation/lib/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-template-tasks.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/packages/simulation/lib/sim-template-tasks.tcl 15 Dec 2003 15:28:20 -0000 1.12 +++ openacs-4/packages/simulation/lib/sim-template-tasks.tcl 16 Dec 2003 18:34:00 -0000 1.13 @@ -87,7 +87,7 @@ } { set "label_state_$state_id" $pretty_name lappend elements state_$state_id \ - [list label "\"Edit\" \${label_state_$state_id}" \ + [list label "\"Edit\" \${label_state_$state_id} \"Delete\"" \ html { align center } \ display_template " Index: openacs-4/packages/simulation/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/Attic/action-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/simulation/tcl/action-procs.tcl 15 Dec 2003 15:28:20 -0000 1.5 +++ openacs-4/packages/simulation/tcl/action-procs.tcl 16 Dec 2003 18:34:00 -0000 1.6 @@ -8,67 +8,152 @@ namespace eval simulation::action {} - -# TODO: add simulation::action::new - ad_proc -public simulation::action::edit { - {-action_id:required} + {-operation "update"} + {-action_id {}} {-workflow_id {}} - {-array:required} + {-array {}} {-internal:boolean} } { - Edit an action. Mostly a wrapper for FSM, plus some simulation-specific stuff. + Edit an action. - Available attributes: recipient (role_id), recipient_role (role short_name), attachment_num + @param operation insert, update, delete + + @param action_id For update/delete: The action to update or delete. + For insert: Optionally specify a pre-generated action_id for the action. + + @param workflow_id For update/delete: Optionally specify the workflow_id. If not specified, we will execute a query to find it. + For insert: The workflow_id of the new action. + + @param array For insert/update: Name of an array in the caller's namespace with attributes to insert/update. + + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. + + @return action_id + + @see workflow::action::fsm::edit } { - upvar 1 $array org_row - if { ![array exists org_row] } { - error "Array $array does not exist or is not an array" + switch $operation { + update - delete { + if { [empty_string_p $action_id] } { + error "You must specify the action_id of the action to $operation." + } + } + insert {} + default { + error "Illegal operation '$operation'" + } } - array set row [array get org_row] + switch $operation { + insert - update { + upvar 1 $array org_row + if { ![array exists org_row] } { + error "Array $array does not exist or is not an array" + } + array set row [array get org_row] + } + } + switch $operation { + insert { + if { [empty_string_p $workflow_id] } { + error "You must supply workflow_id" + } + } + update - delete { + if { [empty_string_p $workflow_id] } { + set workflow_id [workflow::action::get_element \ + -action_id $action_id \ + -element workflow_id] + } + } + } - set set_clauses [list] - - # Handle attributes in sim_tasks table - if { [info exists row(recipient_role)] } { - if { [empty_string_p $row(recipient_role)] } { - set row(recipient) [db_null] - } else { - # Get role_id by short_name - set row(recipient) [workflow::role::get_id \ + # Parse column values + switch $operation { + insert - update { + # Special-case: array entry recipient_role (short_name) and recipient (state_id) -- DB column is recipient (state_id) + if { [info exists row(recipient_role)] } { + if { [info exists row(role)] } { + error "You cannot supply both recipient_role (takes short_name) and recipient (takes state_id)" + } + if { [empty_string_p $row(recipient_role)] } { + set row(recipient) [db_null] + } else { + # Get role_id by short_name + set row(recipient) [workflow::role::get_id \ -workflow_id $workflow_id \ -short_name $row(recipient_role)] - } - unset row(recipient_role) - } + } + unset row(recipient_role) + } - foreach attr { - recipient attachment_num - } { - if { [info exists row($attr)] } { - set varname attr_$attr - # Convert the Tcl value to something we can use in the query - set $varname $row($attr) - # Add the column to the SET clause - lappend set_clauses "$attr = :$varname" - unset row($attr) + set update_clauses [list] + set insert_names [list] + set insert_values [list] + + # Handle columns in the sim_tasks table + foreach attr { + recipient attachment_num + } { + if { [info exists row($attr)] } { + set varname attr_$attr + # Convert the Tcl value to something we can use in the query + switch $attr { + default { + set $varname $row($attr) + } + } + # Add the column to the insert/update statement + switch $attr { + default { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } + } + unset row($attr) + } + } } } - + db_transaction { - if { [llength $set_clauses] > 0 } { - db_dml edit_sim_role " - update sim_tasks - set [join $set_clauses ", "] - where task_id = :action_id - " - } + # Base row + set action_id [workflow::action::fsm::edit \ + -internal \ + -operation $operation \ + -action_id $action_id \ + -workflow_id $workflow_id \ + -array row] - workflow::action::fsm::edit \ - -internal \ - -action_id $action_id \ - -workflow_id $workflow_id \ - -array row + # sim_tasks row + switch $operation { + insert { + lappend insert_names task_id + lappend insert_values :action_id + + db_dml insert_action " + insert into sim_tasks + ([join $insert_names ", "]) + values + ([join $insert_values ", "]) + " + } + update { + if { [llength $update_clauses] > 0 } { + db_dml update_action " + update sim_tasks + set [join $update_clauses ", "] + where task_id = :action_id + " + } + } + delete { + # Handled through cascading delete + } + } if { !$internal_p } { workflow::definition_changed_handler -workflow_id $workflow_id @@ -78,4 +163,30 @@ if { !$internal_p } { workflow::flush_cache -workflow_id $workflow_id } + + return $action_id } + + +ad_proc -public simulation::action::get { + {-action_id:required} + {-array:required} +} { + Get information about a simulation action +} { + upvar 1 $array row + + workflow::action::fsm::get -action_id $action_id -array row + + db_1row select_action { + select recipient, + (select short_name + from workflow_roles + where role_id = recipient) as recipient_role, + attachment_num + from sim_tasks + where task_id = :action_id + } -column_array local_row + + array set row [array get local_row] +} Index: openacs-4/packages/simulation/tcl/role-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/Attic/role-procs.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/simulation/tcl/role-procs.tcl 12 Dec 2003 12:21:39 -0000 1.7 +++ openacs-4/packages/simulation/tcl/role-procs.tcl 16 Dec 2003 18:34:00 -0000 1.8 @@ -8,52 +8,147 @@ namespace eval simulation::role {} -ad_proc -public simulation::role::new { - {-template_id:required} - {-short_name {}} - {-pretty_name:required} +ad_proc -public simulation::role::edit { + {-operation "update"} + {-role_id {}} + {-workflow_id {}} + {-array {}} + {-internal:boolean} } { - Create a new simulation role for a given simulation template. - Will map the character to the template if this - is not already done. + Edit a role. - @author Peter Marklund -} { - db_transaction { - set role_id [workflow::role::new \ - -workflow_id $template_id \ - -short_name $short_name \ - -pretty_name $pretty_name] + @param operation insert, update, delete - db_dml insert_sim_role { - insert into sim_roles (role_id) values (:role_id) - } - } -} + @param role_id For update/delete: The role to update or delete. + For insert: Optionally specify a pre-generated role_id for the role. -ad_proc -public simulation::role::delete { - {-role_id:required} + @param workflow_id For update/delete: Optionally specify the workflow_id. If not specified, we will execute a query to find it. + For insert: The workflow_id of the new role. + + @param array For insert/update: Name of an array in the caller's namespace with attributes to insert/update. + + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. + + @return role_id + + @see workflow::role::fsm::edit } { + switch $operation { + update - delete { + if { [empty_string_p $role_id] } { + error "You must specify the role_id of the role to $operation." + } + } + insert {} + default { + error "Illegal operation '$operation'" + } + } + switch $operation { + insert - update { + upvar 1 $array org_row + if { ![array exists org_row] } { + error "Array $array does not exist or is not an array" + } + array set row [array get org_row] + } + } + switch $operation { + insert { + if { [empty_string_p $workflow_id] } { + error "You must supply workflow_id" + } + } + update { + if { [empty_string_p $workflow_id] } { + set workflow_id [workflow::role::get_element \ + -role_id $role_id \ + -element workflow_id] + } + } + } + + # Parse column values + switch $operation { + insert - update { + set update_clauses [list] + set insert_names [list] + set insert_values [list] + + # Handle columns in the sim_tasks table + foreach attr { + character_id + } { + if { [info exists row($attr)] } { + set varname attr_$attr + # Convert the Tcl value to something we can use in the query + switch $attr { + default { + set $varname $row($attr) + } + } + # Add the column to the insert/update statement + switch $attr { + default { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } + } + unset row($attr) + } + } + } + } + db_transaction { - workflow::role::delete -role_id $role_id + # Base row + set role_id [workflow::role::edit \ + -internal \ + -operation $operation \ + -role_id $role_id \ + -workflow_id $workflow_id \ + -array row] - db_dml delete_sim_role { - delete from sim_roles where role_id = :role_id + # sim_roles row + switch $operation { + insert { + lappend insert_names role_id + lappend insert_values :role_id + + db_dml insert_role " + insert into sim_roles + ([join $insert_names ", "]) + values + ([join $insert_values ", "]) + " + } + update { + if { [llength $update_clauses] > 0 } { + db_dml update_role " + update sim_roles + set [join $update_clauses ", "] + where task_id = :role_id + " + } + } + delete { + # Handled through cascading delete + } } + + if { !$internal_p } { + workflow::definition_changed_handler -workflow_id $workflow_id + } } -} -ad_proc -public simulation::role::edit { - {-role_id:required} - {-character_id:required} -} { - Edit a simulation role. -} { - db_dml edit_sim_role { - update sim_roles - set character_id = :character_id - where role_id = :role_id + if { !$internal_p } { + workflow::flush_cache -workflow_id $workflow_id } + + return $role_id } ad_proc -public simulation::role::get { @@ -63,10 +158,16 @@ Get information about a simulation role } { upvar 1 $array row + + workflow::role::get -role_id $role_id -array row + db_1row select_sim_role { select role_id, character_id from sim_roles where role_id = :role_id - } -column_array row + } -column_array local_row + + array set row [array get local_row] } + Index: openacs-4/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.tcl,v diff -u -r1.17 -r1.18 --- openacs-4/packages/simulation/tcl/template-procs.tcl 16 Dec 2003 16:30:47 -0000 1.17 +++ openacs-4/packages/simulation/tcl/template-procs.tcl 16 Dec 2003 18:34:00 -0000 1.18 @@ -22,22 +22,201 @@ @author Peter Marklund } { + # Wrapper for simulation::template::edit + + foreach elm { pretty_name short_name sim_type suggested_duration package_key object_id } { + set row($elm) [set $elm] + } + + set workflow_id [simulation::template::edit \ + -operation "insert" \ + -array row] + + return $workflow_id +} + +ad_proc -public simulation::template::edit { + {-operation "update"} + {-workflow_id {}} + {-array {}} + {-internal:boolean} +} { + Edit a workflow. + + @param operation insert, update, delete + + @param workflow_id For update/delete: The workflow to update or delete. + + @param array For insert/update: Name of an array in the caller's namespace with attributes to insert/update. + + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. + + @return workflow_id + + @see workflow::edit +} { + switch $operation { + update - delete { + if { [empty_string_p $workflow_id] } { + error "You must specify the workflow_id of the workflow to $operation." + } + } + insert {} + default { + error "Illegal operation '$operation'" + } + } + switch $operation { + insert - update { + upvar 1 $array org_row + if { ![array exists org_row] } { + error "Array $array does not exist or is not an array" + } + array set row [array get org_row] + } + } + + # Parse column values + switch $operation { + insert - update { + set update_clauses [list] + set insert_names [list] + set insert_values [list] + + # Handle columns in the sim_tasks table + foreach attr { + sim_type suggested_duration + enroll_type casting_type + enroll_start enroll_end send_start_note_date case_start case_end + } { + if { [info exists row($attr)] } { + set varname attr_$attr + # Convert the Tcl value to something we can use in the query + switch $attr { + suggested_duration { + if { [empty_string_p $row($attr)] } { + set $varname [db_null] + } else { + set $varname "interval '[db_quote $row($attr)]'" + } + } + default { + set $varname $row($attr) + } + } + # Add the column to the insert/update statement + switch $attr { + enroll_start - enroll_end - send_start_note_date - case_start - case_end { + lappend update_clauses "$attr = to_date('[db_quote $row($attr)]', 'YYYY-MM-DD')" + lappend insert_names $attr + lappend insert_values "to_date('[db_quote $row($attr)]', 'YYYY-MM-DD')" + } + suggested_duration { + if { [empty_string_p $row($attr)] } { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } else { + lappend update_clauses "$attr = [set $varname]" + lappend insert_names $attr + lappend insert_values [set $varname] + } + } + default { + lappend update_clauses "$attr = :$varname" + lappend insert_names $attr + lappend insert_values :$varname + } + } + unset row($attr) + } + } + # Handle auxillary rows + array set aux [list] + foreach attr { + enrolled invited auto-enroll + } { + if { [info exists row($attr)] } { + set aux($attr) $row($attr) + unset row($attr) + } + } + + } + } + db_transaction { - set workflow_id [workflow::new \ - -short_name $short_name \ - -pretty_name $pretty_name \ - -package_key $package_key \ - -object_id $object_id] + # Base row + set workflow_id [workflow::edit \ + -internal \ + -operation $operation \ + -workflow_id $workflow_id \ + -array row] + + # sim_tasks row + switch $operation { + insert { + lappend insert_names simulation_id + lappend insert_values :workflow_id + + db_dml insert_workflow " + insert into sim_simulations + ([join $insert_names ", "]) + values + ([join $insert_values ", "]) + " + } + update { + if { [llength $update_clauses] > 0 } { + db_dml update_workflow " + update sim_simulations + set [join $update_clauses ", "] + where simulation_id = :workflow_id + " + } + } + delete { + # Handled through cascading delete + } + } - insert_sim \ - -workflow_id $workflow_id \ - -sim_type $sim_type \ - -suggested_duration $suggested_duration + # Update sim_party_sim_map table + foreach map_type { enrolled invited auto-enroll } { + if { [info exists aux($map_type)] } { + # Clear out old mappings first + db_dml clear_old_mappings { + delete from sim_party_sim_map + where simulation_id = :workflow_id + and type = :map_type + } + + # Map each party + foreach party_id $aux(enroll_groups) { + db_dml map_party_to_template { + insert into sim_party_sim_map + (simulation_id, party_id, type) + values (:workflow_id, :party_id, :map_type) + } + } + } + unset aux($map_type) + } + + if { !$internal_p } { + workflow::definition_changed_handler -workflow_id $workflow_id + } } + if { !$internal_p } { + workflow::flush_cache -workflow_id $workflow_id + } + return $workflow_id } + ad_proc -public simulation::template::new_from_spec { {-package_key {}} {-object_id {}} @@ -70,6 +249,7 @@ return $workflow_id } +# TODO: Get rid of this -- still called from clone and new_from_spec ad_proc -private simulation::template::insert_sim { {-workflow_id:required} {-sim_type "dev_template"} @@ -91,109 +271,10 @@ db_dml new_sim " insert into sim_simulations (simulation_id, sim_type, suggested_duration) - values (:workflow_id, :sim_type, interval '[db_quote $suggested_duration]')" + values (:workflow_id, :sim_type, interval '[db_quote $suggested_duration]')" } } -ad_proc -public simulation::template::edit { - {-workflow_id:required} - {-array:required} -} { - Edit a new simulation template. TODO: need better tests for duration before passing it into the database. - - @param workflow_id The id of the template to edit. - @param array The name of an array in the callers scope that contains properties to edit. - - @return nothing - - @author Joel Aufrecht -} { - upvar $array edit_array - - db_transaction { - - # Update workflows table - - # TODO: this should be in a new API call, workflow::edit - set set_clauses [list] - foreach col {short_name pretty_name package_key object_id description} { - if { [info exists edit_array($col)] } { - lappend set_clauses "$col = :$col" - set $col $edit_array($col) - } - } - - if { [llength $set_clauses] > 0 } { - db_dml edit_workflow " - update workflows - set [join $set_clauses ", "] - where workflow_id=:workflow_id" - } - - # Update sim_simulations table - - set set_clauses [list] - foreach col {sim_type enroll_type casting_type} { - if { [info exists edit_array($col)] } { - lappend set_clauses "$col = :$col" - set $col $edit_array($col) - } - } - - if { [info exists edit_array(suggested_duration)] } { - if { [empty_string_p $edit_array($col)] } { - lappend set_clauses "$col = null" - } else { - lappend set_clauses "$col = (interval '$edit_array($col)')" - } - - set parties $edit_array(suggested_duration) - } - - foreach col {enroll_start enroll_end send_start_note_date case_start case_end} { - if { [info exists edit_array($col)] } { - lappend set_clauses "$col = to_date(:$col, 'YYYY-MM-DD')" - set $col $edit_array($col) - } - } - - if { [llength $set_clauses] > 0 } { - db_dml edit_sim " - update sim_simulations - set [join $set_clauses ", "] - where simulation_id=:workflow_id - " - } - - # Update sim_party_sim_map table - - foreach map_type {enrolled invited auto-enroll} { - - if { [info exists edit_array($map_type)] } { - - # Clear out old mappings first - db_dml clear_old_mappings { - delete from sim_party_sim_map - where simulation_id = :workflow_id - and type = :map_type - } - - # Map each party - foreach party_id $edit_array(enroll_groups) { - db_dml map_party_to_template { - insert into sim_party_sim_map - (simulation_id, party_id, type) - values (:workflow_id, :party_id, :map_type) - } - } - } - } - - # TODO: invite_groups - } -} - - ad_proc -public simulation::template::delete_role_group_mappings { {-workflow_id} } { @@ -239,6 +320,7 @@ } } +# TODO: Fix the cascading clone API situation ad_proc -public simulation::template::clone { {-workflow_id:required} {-package_key {}} @@ -312,7 +394,10 @@ } { upvar $array row - db_1row select_template {} -column_array row + workflow::get -array row -workflow_id $workflow_id + + db_1row select_template {} -column_array local_row + array set row [array get local_row] } ad_proc -public simulation::template::get_parties { @@ -387,28 +472,14 @@ return [expr [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]] } -ad_proc -public simulation::template::get_workflow_id_from_action { - {-action_id:required} -} { - Given an action_id, return the workflow_id - - @param action_id ID of action in workflow -} { - return [db_string select_workflow_id { - select wa.workflow_id - from workflow_actions wa - where wa.action_id = :action_id - }] -} - ad_proc -public simulation::template::delete { {-workflow_id:required} } { Delete a simulation template. @author Peter Marklund } { - workflow::delete -workflow_id $workflow_id + simulation::template::edit -workflow_id $workflow_id -operation delete } ad_proc -public simulation::template::associate_object { @@ -444,7 +515,6 @@ and object_id = :object_id } # no special error handling because the delete is pretty safe - } ad_proc -public simulation::template::start { Index: openacs-4/packages/simulation/www/simbuild/role-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/role-delete.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/www/simbuild/role-delete.tcl 2 Dec 2003 17:24:32 -0000 1.2 +++ openacs-4/packages/simulation/www/simbuild/role-delete.tcl 16 Dec 2003 18:34:00 -0000 1.3 @@ -6,7 +6,7 @@ } { {confirm_p:boolean "f"} role_id:integer - {return_url "."} + {return_url ""} } set package_id [ad_conn package_id] @@ -19,16 +19,21 @@ or st.recipient = :role_id " ] +workflow::role::get -role_id $role_id -array role_array +set name $role_array(pretty_name) +set workflow_id $role_array(workflow_id) + +if { [empty_string_p $return_url] } { + set return_url [export_vars -base template-edit { workflow_id }] +} + if { [template::util::is_true $confirm_p] || $num_of_tasks == 0 } { - permission::require_write_permission -object_id $role_id - simulation::role::delete -role_id $role_id + permission::require_write_permission -object_id $workflow_id + simulation::role::edit -operation "delete" -role_id $role_id ad_returnredirect $return_url } -workflow::role::get -role_id $role_id -array role_array -set name $role_array(pretty_name) -set workflow_id $role_array(workflow_id) -workflow::get -workflow_id $workflow_id -array sim_template_array +workflow::get -workflow_id $workflow_id -array sim_template_array set page_title "Delete $name" set context [list [list "." "Sim Templates"] [list "template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] Index: openacs-4/packages/simulation/www/simbuild/role-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/role-edit.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/simulation/www/simbuild/role-edit.tcl 10 Dec 2003 16:06:46 -0000 1.6 +++ openacs-4/packages/simulation/www/simbuild/role-edit.tcl 16 Dec 2003 18:34:00 -0000 1.7 @@ -46,11 +46,15 @@ {html {size 20}} } } -edit_request { - workflow::role::get -role_id $role_id -array role_array + simulation::role::get -role_id $role_id -array role_array set workflow_id $role_array(workflow_id) + permission::require_write_permission -object_id $workflow_id + set pretty_name $role_array(pretty_name) + workflow::get -workflow_id $workflow_id -array sim_template_array + set page_title "Edit Role template $pretty_name" set context [list [list "." "Sim Templates"] [list "template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] @@ -62,26 +66,27 @@ } -new_data { permission::require_write_permission -object_id $workflow_id - simulation::role::new \ - -template_id $workflow_id \ - -pretty_name $pretty_name + set operation "insert" } -edit_data { - workflow::role::get -role_id $role_id -array role_array # We use role_array(workflow_id) here, which is gotten from the DB, and not # workflow_id, which is gotten from the form, because the workflow_id from the form # could be spoofed - permission::require_write_permission -object_id $role_array(workflow_id) + workflow::role::get -role_id $role_id -array role_array + set workflow_id $role_array(workflow_id) + permission::require_write_permission -object_id $workflow_id + set operation "update" +} -after_submit { set row(pretty_name) $pretty_name set row(short_name) {} - workflow::role::edit \ - -role_id $role_id \ - -workflow_id $workflow_id \ - -array row - -} -after_submit { + set role_id [simulation::role::edit \ + -operation $operation \ + -role_id $role_id \ + -workflow_id $workflow_id \ + -array row] + ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort } Index: openacs-4/packages/simulation/www/simbuild/state-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/state-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/simbuild/state-delete.tcl 16 Dec 2003 18:34:00 -0000 1.1 @@ -0,0 +1,16 @@ +ad_page_contract { + Delete a state + +} { + state_id:integer + {return_url ""} +} + +set workflow_id [workflow::state::fsm::get_element -state_id $state_id -element workflow_id] +permission::require_write_permission -object_id $workflow_id +workflow::state::fsm::edit -operation "delete" -state_id $state_id + +if { [empty_string_p $return_url] } { + set return_url [export_vars -base template-edit { workflow_id }] +} +ad_returnredirect $return_url Index: openacs-4/packages/simulation/www/simbuild/state-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/state-edit.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simulation/www/simbuild/state-edit.tcl 9 Dec 2003 15:58:13 -0000 1.1 +++ openacs-4/packages/simulation/www/simbuild/state-edit.tcl 16 Dec 2003 18:34:00 -0000 1.2 @@ -75,27 +75,25 @@ permission::require_write_permission -object_id $workflow_id } -new_data { permission::require_write_permission -object_id $workflow_id - # create the state - set state_id [workflow::state::fsm::new \ - -workflow_id $workflow_id \ - -pretty_name $pretty_name] - + set operation "insert" } -edit_data { # We use state_array(workflow_id) here, which is gotten from the DB, and not # workflow_id, which is gotten from the form, because the workflow_id from the form # could be spoofed - permission::require_write_permission -object_id $state_array(workflow_id) - + set workflow_id $state_array(workflow_id) + permission::require_write_permission -object_id $workflow_id + set operation "update" +} -after_submit { set row(pretty_name) $pretty_name set row(short_name) {} - workflow::state::fsm::edit \ - -state_id $state_id \ - -workflow_id $state_array(workflow_id) \ - -array row + set state_id [workflow::state::fsm::edit \ + -operation $operation \ + -state_id $state_id \ + -workflow_id $workflow_id \ + -array row] -} -after_submit { ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort } Index: openacs-4/packages/simulation/www/simbuild/task-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/task-delete.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/www/simbuild/task-delete.tcl 2 Dec 2003 17:24:32 -0000 1.2 +++ openacs-4/packages/simulation/www/simbuild/task-delete.tcl 16 Dec 2003 18:34:00 -0000 1.3 @@ -3,10 +3,14 @@ } { action_id:integer - {return_url "."} + {return_url ""} } -permission::require_write_permission -object_id $action_id -workflow::action::fsm::delete -action_id $action_id +set workflow_id [workflow::action::get_element -action_id $action_id -element workflow_id] +permission::require_write_permission -object_id $workflow_id +simulation::action::edit -operation "delete" -action_id $action_id -ad_returnredirect $return_url \ No newline at end of file +if { [empty_string_p $return_url] } { + set return_url [export_vars -base template-edit { workflow_id }] +} +ad_returnredirect $return_url Index: openacs-4/packages/simulation/www/simbuild/task-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/task-edit.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/packages/simulation/www/simbuild/task-edit.tcl 16 Dec 2003 17:58:08 -0000 1.12 +++ openacs-4/packages/simulation/www/simbuild/task-edit.tcl 16 Dec 2003 18:34:00 -0000 1.13 @@ -43,7 +43,7 @@ set package_id [ad_conn package_id] if { ![ad_form_new_p -key action_id] } { - workflow::action::fsm::get -action_id $action_id -array task_array + simulation::action::get -action_id $action_id -array task_array set workflow_id $task_array(workflow_id) } @@ -132,26 +132,16 @@ } -edit_request { set workflow_id $task_array(workflow_id) permission::require_write_permission -object_id $workflow_id - set pretty_name $task_array(pretty_name) set description [template::util::richtext::create $task_array(description) $task_array(description_mime_type)] - set new_state_id $task_array(new_state_id) - - db_1row select_recipient { - select recipient as recipient_role_id, attachment_num - from sim_tasks - where task_id = :action_id - } - if { ![empty_string_p $recipient_role_id] } { - set recipient_role [workflow::role::get_element -role_id $recipient_role_id -element short_name] - } else { - set recipient_role {} + foreach elm { + pretty_name new_state_id + assigned_role recipient_role + assigned_state_ids enabled_state_ids + attachment_num + } { + set $elm $task_array($elm) } - - set assigned_role $task_array(assigned_role) - - set assigned_state_ids $task_array(assigned_state_ids) - set enabled_state_ids $task_array(enabled_state_ids) } -new_request { permission::require_write_permission -object_id $workflow_id @@ -162,63 +152,37 @@ set description_mime_type [template::util::richtext::get_property format $description] set description [template::util::richtext::get_property contents $description] - if { ![empty_string_p $recipient_role] } { - set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role] - } else { - set recipient_role_id [db_null] + foreach elm { + pretty_name assigned_role description description_mime_type + enabled_state_ids assigned_state_ids new_state_id + recipient_role attachment_num + } { + set row($elm) [set $elm] } + set row(short_name) {} + } -new_data { permission::require_write_permission -object_id $workflow_id - # create the task + set operation "insert" - db_transaction { - set action_id [workflow::action::fsm::new \ - -workflow_id $workflow_id \ - -pretty_name $pretty_name \ - -assigned_role $assigned_role \ - -description $description \ - -description_mime_type $description_mime_type \ - -enabled_state_ids $enabled_state_ids \ - -assigned_state_ids $assigned_state_ids \ - -new_state_id $new_state_id] - - # TODO - put this stuff into simulation api and change previous call - # and then add extra data for simulation - # because workflow::action::fsm::new wants role.short_name instead of - # role_id, we stay consistent for recipient_role - - array unset row - set row(recipient_role) $recipient_role - set row(attachment_num) $attachment_num - - simulation::action::edit \ - -action_id $action_id \ - -workflow_id $workflow_id \ - -array row - } } -edit_data { # We use task_array(workflow_id) here, which is gotten from the DB, and not # workflow_id, which is gotten from the form, because the workflow_id from the form # could be spoofed - permission::require_write_permission -object_id $task_array(workflow_id) + set workflow_id $task_array(workflow_id) - # TODO: Set short_name right, - # or leave blank and have the workflow API construct a short_name + permission::require_write_permission -object_id $workflow_id - # TODO: enabled_states, assigned_states - array unset row - foreach col { pretty_name assigned_role recipient_role description description_mime_type enabled_state_ids assigned_state_ids attachment_num } { - set row($col) [set $col] - } - set row(short_name) {} - set row(new_state_id) $new_state_id + set operation "update" - simulation::action::edit \ - -action_id $action_id \ - -workflow_id $task_array(workflow_id) \ - -array row - } -after_submit { + + set action_id [simulation::action::edit \ + -operation $operation \ + -workflow_id $workflow_id \ + -action_id $action_id \ + -array row] + ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort } Index: openacs-4/packages/simulation/www/simbuild/template-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-delete.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/www/simbuild/template-delete.tcl 2 Dec 2003 17:24:32 -0000 1.2 +++ openacs-4/packages/simulation/www/simbuild/template-delete.tcl 16 Dec 2003 18:34:00 -0000 1.3 @@ -14,6 +14,6 @@ set page_title "Deleting template \"$template_name\"" set template_list_url . -set context [list [list $template_list_url "Templates"] $page_title] +set context [list [list $template_list_url "SimBuild"] $page_title] simulation::template::delete -workflow_id $workflow_id Index: openacs-4/packages/simulation/www/simbuild/template-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-edit.adp,v diff -u -r1.9 -r1.10 --- openacs-4/packages/simulation/www/simbuild/template-edit.adp 11 Dec 2003 14:24:29 -0000 1.9 +++ openacs-4/packages/simulation/www/simbuild/template-edit.adp 16 Dec 2003 18:34:00 -0000 1.10 @@ -1,7 +1,7 @@ @page_title;noquote@ @context;noquote@ - sim_template.name + sim_template.pretty_name Index: openacs-4/packages/simulation/www/simbuild/template-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-edit.tcl,v diff -u -r1.11 -r1.12 --- openacs-4/packages/simulation/www/simbuild/template-edit.tcl 15 Dec 2003 14:50:12 -0000 1.11 +++ openacs-4/packages/simulation/www/simbuild/template-edit.tcl 16 Dec 2003 18:34:00 -0000 1.12 @@ -35,7 +35,7 @@ ad_form -name sim_template -mode $mode -cancel_url $cancel_url -form { {workflow_id:key} - {name:text,optional + {pretty_name:text,optional {label "Template Name"} {html {size 40}} } @@ -60,64 +60,69 @@ {suggested_duration:text,optional {label "Suggested Duration"} } - {description:text(textarea),optional - {label "TODO: Description and
Description-mime-type"} + {description:richtext(richtext),optional + {label "Description"} {html {cols 60 rows 8}} } } -edit_request { permission::require_write_permission -object_id $workflow_id + simulation::template::get -workflow_id $workflow_id -array sim_template_array - set name $sim_template_array(pretty_name) - set description $sim_template_array(description) + set pretty_name $sim_template_array(pretty_name) + + set description [template::util::richtext::create $sim_template_array(description) $sim_template_array(description_mime_type)] + # translate sim_type to ready/not-ready - # TODO: we should only see ready_template and dev_template here, so maybe assert that? - if {$sim_template_array(sim_type) == "ready_template"} { - set template_ready_p "t" - } else { - set template_ready_p "f" + + if { [lsearch { dev_template ready_template } $sim_template_array(sim_type)] == -1 } { + error "Can only handle dev_template and ready_template sim_types here." } + set template_ready_p [db_boolean [string equal $sim_template_array(sim_type) "ready_template"]] + set suggested_duration $sim_template_array(suggested_duration) } -new_request { permission::require_permission -object_id $package_id -privilege sim_template_create - + +} -on_submit { + set description_mime_type [template::util::richtext::get_property format $description] + set description [template::util::richtext::get_property contents $description] } -new_data { permission::require_permission -object_id $package_id -privilege sim_template_create - set workflow_id [simulation::template::new \ - -short_name $name \ - -pretty_name $name \ - -suggested_duration $suggested_duration \ - -package_key $package_key \ - -object_id $package_id] + set operation "insert" + + set row(package_key) $package_key + set row(object_id) $package_id + set row(sim_type) "dev_template" } -edit_data { - if {$template_ready_p == "t"} { - set sim_type "ready_template" + if { [template::util::is_true $template_ready_p] } { + set row(sim_type) "ready_template" } else { - set sim_type "dev_template" + set row(sim_type) "dev_template" } permission::require_write_permission -object_id $workflow_id + set operation "update" - set simulation(short_name) $name - set simulation(pretty_name $name - set simulation(sim_type) $sim_type - set simulation(suggested_duration) $suggested_duration - set simulation(package_key) $package_key - set simulation(object_id) $package_id - set simulation(description) $description - simulation::template::edit \ - -workflow_id $workflow_id \ - -array simulation - } -after_submit { + set row(short_name) {} + foreach elm { pretty_name suggested_duration description description_mime_type } { + set row($elm) [set $elm] + } + + set workflow_id [simulation::template::edit \ + -operation $operation \ + -workflow_id $workflow_id \ + -array row] + ad_returnredirect [export_vars -base "template-edit" { workflow_id }] ad_script_abort @@ -143,7 +148,7 @@ set page_title "New Simulation Template" } edit { - set page_title "Editing $name" + set page_title "Editing $pretty_name" } } Index: openacs-4/packages/simulation/www/simbuild/template-load.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-load.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simulation/www/simbuild/template-load.adp 11 Dec 2003 15:32:43 -0000 1.1 +++ openacs-4/packages/simulation/www/simbuild/template-load.adp 16 Dec 2003 18:34:00 -0000 1.2 @@ -1,7 +1,7 @@ @page_title;noquote@ @context;noquote@ - load.spec + load.pretty_name