Index: openacs-4/packages/simulation/www/simplay/task-detail.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/task-detail.tcl,v diff -u -r1.19 -r1.20 --- openacs-4/packages/simulation/www/simplay/task-detail.tcl 30 Jan 2004 11:23:25 -0000 1.19 +++ openacs-4/packages/simulation/www/simplay/task-detail.tcl 4 Mar 2004 12:09:44 -0000 1.20 @@ -2,31 +2,102 @@ Details for a task. If there is a recipient_role a message is created. If there is not recipient role we upload a document instead. } { - case_id:integer - role_id:integer - enabled_action_id:integer + {enabled_action_id:integer,multiple ""} + {enabled_action_ids ""} item_id:optional + {bulk_p 0} + {return_url ""} } -simulation::case::assert_user_may_play_role -case_id $case_id -role_id $role_id +# FIXME: I am exporting the enabled_action_id list as the string variable enabled_action_ids in +# the forms as I can't export multiples. Here I'm recreating the list again. This is convoluted. +if { ![empty_string_p $enabled_action_ids] } { + set enabled_action_id [split $enabled_action_ids] +} -workflow::case::enabled_action_get -enabled_action_id $enabled_action_id -array enabled_action -set action_id $enabled_action(action_id) -simulation::action::get -action_id $action_id -array action +if { [llength $enabled_action_id] > 1 } { + set bulk_p 1 +} +if { !$bulk_p } { + workflow::case::enabled_action_get -enabled_action_id $enabled_action_id -array enabled_action + + set action_id $enabled_action(action_id) + set case_id $enabled_action(case_id) + simulation::action::get -action_id $action_id -array action + set role_id $action(assigned_role_id) + + simulation::case::assert_user_may_play_role -case_id $case_id -role_id $action(assigned_role_id) + + set common_enabled_action_ids [list [list $enabled_action_id $case_id]] + + if { [empty_string_p $return_url] } { + set return_url [export_vars -base tasks { case_id role_id }] + } + +} else { + # Only admin users can neglect to provide case_id and role_id + permission::require_permission -object_id [ad_conn package_id] -privilege sim_adminplayer + + # If we are taking action on more than one task, extract the subset of the tasks that + # have the same action_id + set common_action_id "" + set common_enabled_action_ids [list] + set ignored_enabled_action_ids [list] + set task_list [db_list_of_lists select_tasks " + select wcea.enabled_action_id, + wcea.action_id, + wcea.case_id + from workflow_case_enabled_actions wcea + where wcea.enabled_action_id in ('[join $enabled_action_id "', '"]') + "] + foreach task $task_list { + set one_enabled_action_id [lindex $task 0] + set one_action_id [lindex $task 1] + set one_case_id [lindex $task 2] + + if { [empty_string_p $common_action_id] } { + set common_action_id $one_action_id + set case_id $one_case_id + } + + if { [string equal $common_action_id $one_action_id] } { + lappend common_enabled_action_ids [list $one_enabled_action_id $one_case_id] + } else { + lappend ignored_enabled_action_ids $one_enabled_action_id + } + } + + set common_actions_count [llength $common_enabled_action_ids] + set ignored_actions_count [llength $ignored_enabled_action_ids] + + set action_id $common_action_id + + simulation::action::get -action_id $action_id -array action + + if { [empty_string_p $return_url] } { + set return_url [export_vars -base tasks-bulk { {workflow_id $action(workflow_id)} }] + } +} + set page_title $action(pretty_name) set context [list [list . "SimPlay"] [list [export_vars -base case { case_id role_id }] "Case"] [list [export_vars -base tasks { case_id role_id }] "Tasks"] $page_title] +set documents_pre_form "" if { ![empty_string_p $action(recipients)] } { # We have recipient roles - use message form - if { ![empty_string_p $action(assigned_role_id)] } { - set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_id)] + if { !$bulk_p } { + if { ![empty_string_p $action(assigned_role_id)] } { + set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_id)] + } + } else { + set attachment_options {} } set form_id action - ad_form -name $form_id -edit_buttons { { Send ok } } -export { case_id role_id enabled_action_id } \ + ad_form -name $form_id -edit_buttons { { Send ok } } -export { case_id role_id {enabled_action_ids $enabled_action_id} bulk_p} \ -form { {pretty_name:text(inform) {label "Task"} @@ -77,27 +148,32 @@ set body_text [template::util::richtext::get_property "contents" $body] set body_mime_type [template::util::richtext::get_property "format" $body] - + db_transaction { - set entry_id [workflow::case::action::execute \ + foreach one_action $common_enabled_action_ids { + set enabled_action_id [lindex $one_action 0] + set case_id [lindex $one_action 1] + + set entry_id [workflow::case::action::execute \ -enabled_action_id $enabled_action_id \ -comment $body_text \ -comment_mime_type $body_mime_type] - foreach recipient_id $action(recipients) { - simulation::message::new \ - -from_role_id $action(assigned_role_id) \ - -to_role_id $recipient_id \ - -case_id $case_id \ - -subject $subject \ - -body $body_text \ - -body_mime_type $body_mime_type \ - -attachments $attachments \ - -entry_id $entry_id - } + foreach recipient_id $action(recipients) { + simulation::message::new \ + -from_role_id $action(assigned_role_id) \ + -to_role_id $recipient_id \ + -case_id $case_id \ + -subject $subject \ + -body $body_text \ + -body_mime_type $body_mime_type \ + -attachments $attachments \ + -entry_id $entry_id + } + } } - ad_returnredirect [export_vars -base tasks { case_id role_id }] + ad_returnredirect $return_url ad_script_abort } @@ -109,7 +185,7 @@ set form_id document - ad_form -name $form_id -export { case_id role_id workflow_id enabled_action_id } -html {enctype multipart/form-data} \ + ad_form -name $form_id -export { case_id role_id workflow_id {enabled_action_ids $enabled_action_id} bulk_p} -html {enctype multipart/form-data} \ -form [concat {{pretty_name:text(inform) {label "Task"}}} [simulation::ui::forms::document_upload::form_block]] \ -on_request { set pretty_name $action(pretty_name) @@ -118,19 +194,23 @@ } -on_submit { db_transaction { - set entry_id [workflow::case::action::execute \ + foreach one_action $common_enabled_action_ids { + set case_id [lindex $one_action 1] + + set entry_id [workflow::case::action::execute \ -case_id $case_id \ -action_id $action_id \ -comment "Document [lindex $document_file 0] uploaded" \ -comment_mime_type "text/plain"] - simulation::ui::forms::document_upload::insert_document \ - $case_id $role_id $item_id $document_file $title $entry_id + simulation::ui::forms::document_upload::insert_document \ + $case_id $action(assigned_role_id) $item_id $document_file $title $entry_id + } } - ad_returnredirect [export_vars -base tasks { case_id role_id }] + ad_returnredirect $return_url + ad_script_abort } set focus "document.document_file" } -