Index: openacs-4/contrib/packages/simulation/www/simplay/task-detail.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/task-detail.tcl,v diff -u -r1.11 -r1.12 --- openacs-4/contrib/packages/simulation/www/simplay/task-detail.tcl 16 Jan 2004 10:20:39 -0000 1.11 +++ openacs-4/contrib/packages/simulation/www/simplay/task-detail.tcl 21 Jan 2004 11:17:34 -0000 1.12 @@ -1,107 +1,146 @@ ad_page_contract { - Details for a task + 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 + item_id:optional } simulation::case::assert_user_may_play_role -case_id $case_id -role_id $role_id 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 { ![empty_string_p $action(assigned_role_id)] } { - set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_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 title "Task" -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"] $title] +set action(recipient_role) "" -ad_form -name action -edit_buttons { { Send ok } } -export { case_id role_id enabled_action_id } -form { - {pretty_name:text(inform) - {label "Task"} - } - {description:richtext,optional - {label "Description"} - {mode display} - } - {documents:text(inform),optional - {label "Documents"} - } - {sender_name:text(inform),optional - {label "From"} - } - {recipient_name:text(inform),optional - {label "To"} - } - {subject:text - {label "Subject"} - {html {size 80}} - } - {body:richtext - {label "Body"} - {html {cols 60 rows 20}} - } - {attachments:integer(checkbox),multiple,optional - {label "Attachments"} - {options $attachment_options} - } -} -on_request { - set pretty_name $action(pretty_name) - set description [template::util::richtext::create $action(description) $action(description_mime_type)] +if { ![empty_string_p $action(recipient_role)] } { + # We have a recipient role - use message form - set documents {} - db_foreach documents { - select cr.title as object_title, - 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 - } { - set object_url [simulation::object::url \ - -name $object_name] - append documents "$object_title
" - } - - if { ![empty_string_p $action(recipient)] } { - set recipient_name [simulation::role::get_element -role_id $action(recipient) -element pretty_name] - } if { ![empty_string_p $action(assigned_role_id)] } { - simulation::role::get -role_id $action(assigned_role_id) -array sender_role - set sender_name $sender_role(pretty_name) + set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_id)] } -} -on_submit { - set body_text [template::util::richtext::get_property "contents" $body] - set body_mime_type [template::util::richtext::get_property "format" $body] + set form_id action - db_transaction { + ad_form -name $form_id -edit_buttons { { Send ok } } -export { case_id role_id enabled_action_id } \ + -form { + {pretty_name:text(inform) + {label "Task"} + } + {description:richtext,optional + {label "Description"} + {mode display} + } + {documents:text(inform),optional + {label "Documents"} + } + {sender_name:text(inform),optional + {label "From"} + } + {recipient_name:text(inform),optional + {label "To"} + } + {subject:text + {label "Subject"} + {html {size 80}} + } + {body:richtext + {label "Body"} + {html {cols 60 rows 20}} + } + {attachments:integer(checkbox),multiple,optional + {label "Attachments"} + {options $attachment_options} + } + } -on_request { + set pretty_name $action(pretty_name) + set description [template::util::richtext::create $action(description) $action(description_mime_type)] + + set documents {} + db_foreach documents { + select cr.title as object_title, + 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 + } { + set object_url [simulation::object::url \ + -name $object_name] + append documents "$object_title
" + } + + if { ![empty_string_p $action(recipient)] } { + set recipient_name [simulation::role::get_element -role_id $action(recipient) -element pretty_name] + } + if { ![empty_string_p $action(assigned_role_id)] } { + simulation::role::get -role_id $action(assigned_role_id) -array sender_role + set sender_name $sender_role(pretty_name) + } + } -on_submit { + + set body_text [template::util::richtext::get_property "contents" $body] + set body_mime_type [template::util::richtext::get_property "format" $body] + + db_transaction { - workflow::case::action::execute \ - -case_id $case_id \ - -action_id $action_id \ - -comment $body_text \ - -comment_mime_type $body_mime_type + workflow::case::action::execute \ + -case_id $case_id \ + -action_id $action_id \ + -comment $body_text \ + -comment_mime_type $body_mime_type - simulation::message::new \ - -from_role_id $action(assigned_role_id) \ - -to_role_id $action(recipient) \ - -case_id $case_id \ - -subject $subject \ - -body $body_text \ - -body_mime_type $body_mime_type \ - -attachments $attachments - } + simulation::message::new \ + -from_role_id $action(assigned_role_id) \ + -to_role_id $action(recipient) \ + -case_id $case_id \ + -subject $subject \ + -body $body_text \ + -body_mime_type $body_mime_type \ + -attachments $attachments + } - ad_returnredirect [export_vars -base tasks { case_id role_id }] - ad_script_abort + ad_returnredirect [export_vars -base tasks { case_id role_id }] + ad_script_abort + } + + set focus "action.subject" +} else { + # No recipient role - use upload document form + + set workflow_id [workflow::case::get_element -case_id $case_id -element workflow_id] + + set form_id document + + ad_form -name $form_id -export { case_id role_id workflow_id enabled_action_id } -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) + } -on_submit { + + db_transaction { + simulation::ui::forms::document_upload::insert_document \ + $case_id $role_id $item_id $document_file $title $description + + workflow::case::action::execute \ + -case_id $case_id \ + -action_id $action_id \ + -comment "Document [lindex $document_file 0] uploaded" \ + -comment_mime_type "text/plain" + } + + ad_returnredirect [export_vars -base tasks { case_id role_id }] + } + + set focus "document.document_file" }