Index: openacs-4/packages/simulation/tcl/sim-action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/sim-action-procs.tcl,v diff -u -N -r1.10.2.1 -r1.10.2.2 --- openacs-4/packages/simulation/tcl/sim-action-procs.tcl 31 Oct 2006 10:13:02 -0000 1.10.2.1 +++ openacs-4/packages/simulation/tcl/sim-action-procs.tcl 19 Feb 2007 15:10:55 -0000 1.10.2.2 @@ -126,7 +126,7 @@ # Handle auxillary rows array set aux [list] foreach attr { - recipients + recipients attachments } { if { [info exists row($attr)] } { set aux($attr) $row($attr) @@ -201,6 +201,26 @@ } unset aux(recipients) } + + if { [info exists aux(attachments)] && [llength aux(attachments)] > 0 } { + db_dml delete_old_attachments { + delete from sim_task_object_map + where task_id = :action_id + } + set i 1 + foreach attachment $aux(attachments) { + set attachment_id [db_string get_id {select item_id from cr_items where name = :attachment}] + + if { ![empty_string_p $attachment_id] } { + db_dml insert_rel { + insert into sim_task_object_map (task_id, object_id, order_n, relation_tag) + values (:action_id, :attachment_id, :i, 'attachment') + } + } + + incr i + } + } } } @@ -307,7 +327,22 @@ lappend spec $name $row($name) } } + + set attachments [db_list attachments { + select ci.name as object_name + from sim_task_object_map m, + cr_items ci, + cr_revisions cr + where m.task_id = :action_id + and m.relation_tag = 'attachment' + and ci.item_id = m.object_id + and cr.revision_id = ci.live_revision + order by m.order_n}] + if { [llength $attachments] > 0 } { + lappend spec attachments $attachments + } + return $spec } 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 -N -r1.38.2.1 -r1.38.2.2 --- openacs-4/packages/simulation/www/simbuild/task-edit.tcl 31 Oct 2006 10:13:03 -0000 1.38.2.1 +++ openacs-4/packages/simulation/www/simbuild/task-edit.tcl 19 Feb 2007 15:10:56 -0000 1.38.2.2 @@ -52,12 +52,18 @@ } } +set prop_options [simulation::object::get_object_type_options -object_type "sim_prop" -null_label "--Not Yet Selected--"] + +set prop_count [llength $prop_options] + workflow::get -workflow_id $workflow_id -array sim_template_array if { ![ad_form_new_p -key action_id] } { set page_title "Edit Task $task_array(pretty_name)" + set attachment_count [db_string att_count {select count(*) + 5 from sim_task_object_map + where task_id = :action_id}] } else { - + set attachment_count 5 set page_title "Add Task to $sim_template_array(pretty_name)" } @@ -227,17 +233,33 @@ } } -if { [string equal $trigger_type "user"] } { - ad_form -extend -name task -form { - {attachment_num:integer(text) - {label "Number of attachments"} - {help_text "These are placeholders that are matched to props by the case author during SimInst"} - {html {size 2}} - } +if { [string equal $trigger_type "user"] } { + if { ![ad_form_new_p -key action_id] } { + + db_foreach attachments { + select a.action_id, + m.object_id, + m.order_n + from workflow_actions a, + sim_task_object_map m + where a.action_id = :action_id + and m.task_id = a.action_id + and m.relation_tag = 'attachment' + } { + set attachment_${order_n} $object_id + } } -} else { - ad_form -extend -name task -form { - {attachment_num:integer(hidden) {value 0}} + for { set i 1 } { $i <= [set attachment_count] } { incr i } { + set help_text [ad_decode $i 1 "Select from existing attachments or add a new prop and refresh this page." \ + 5 "You can add more attachments by saving the task and returning to this form." \ + ""] + + ad_form -extend -name task -form \ + [list [list attachment_${i}:integer(select),optional \ + {label "Attachment $i"} \ + {options $prop_options} \ + {help_text $help_text}]] } } @@ -277,7 +299,7 @@ foreach elm { pretty_name new_state_id assigned_role recipient_roles - attachment_num trigger_type parent_action_id + trigger_type parent_action_id } { set $elm $task_array($elm) } @@ -290,8 +312,6 @@ } -new_request { permission::require_write_permission -object_id $workflow_id - set attachment_num 0 - set trigger_type "user" set task_type "message" } -on_refresh { @@ -371,7 +391,23 @@ -action_id $action_id \ -array row] + db_dml delete_all_relations { + delete from sim_task_object_map + where task_id = :action_id + } + for { set i 1 } { $i <= [set attachment_count] } { incr i } { + set elm "attachment_$i" + set related_object_id [set $elm] + + if { ![empty_string_p $related_object_id] } { + db_dml insert_rel { + insert into sim_task_object_map (task_id, object_id, order_n, relation_tag) + values (:action_id, :related_object_id, :i, 'attachment') + } + } + } + # Let's mark this template edited set sim_type "dev_template" Index: openacs-4/packages/simulation/www/siminst/map-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/map-tasks.tcl,v diff -u -N -r1.16.2.1 -r1.16.2.2 --- openacs-4/packages/simulation/www/siminst/map-tasks.tcl 10 Dec 2006 21:05:32 -0000 1.16.2.1 +++ openacs-4/packages/simulation/www/siminst/map-tasks.tcl 19 Feb 2007 15:10:56 -0000 1.16.2.2 @@ -80,6 +80,15 @@ set default_text_$row(action_id) [template::util::richtext::create $row(default_text) $row(default_text_mime_type)] } + set current_action_id $row(action_id) + set attachment_count_$row(action_id) [db_string att_count {select count(*) from sim_task_object_map + where task_id = :current_action_id}] + + if { $row(attachment_num) < [set attachment_count_$row(action_id)] } { + set row(attachment_num) [set attachment_count_$row(action_id)] + } + + # Save attachment_num for later ad_form -extend -name tasks -form \ [list [list attachment_num_$row(action_id):integer(hidden),optional \