Index: openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/simulation-casting-3.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl 18 Dec 2003 08:31:03 -0000 1.6 +++ openacs-4/contrib/packages/simulation/www/siminst/simulation-casting-3.tcl 18 Dec 2003 15:22:56 -0000 1.7 @@ -8,51 +8,53 @@ workflow_id:integer } -set page_title "Choose actors" +set page_title "Map user groups to roles" set context [list [list "." "SimInst"] $page_title] -# Loop over all workflow roles and append the actor and "in groups of" widgets to the form set form [list] set eligible_groups [simulation::casting_groups -enrolled_only -workflow_id $workflow_id] foreach role_id [workflow::get_roles -workflow_id $workflow_id] { - set role_pretty_name [workflow::role::get_element -role_id $role_id -element pretty_name] - lappend form [list actor_${role_id}:text(select) \ - [list label $role_pretty_name] \ + set role_${role_id}_pretty_name [workflow::role::get_element -role_id $role_id -element pretty_name] + + lappend form [list parties_${role_id}:text(checkbox),multiple \ + [list label \$role_${role_id}_pretty_name] \ [list options $eligible_groups] ] - lappend form [list group_${role_id}:integer [list label "In groups of"] [list value 1] [list html {size 2}]] + lappend form [list users_per_case_${role_id}:integer [list label "Target number of users for this group per case"] [list value 1] [list html {size 2}]] } ad_form \ -name actors \ -export { workflow_id } \ -form $form \ -on_request { - simulation::template::get_role_group_mappings -workflow_id $workflow_id -array roles - + simulation::template::role_party_mappings -workflow_id $workflow_id -array roles + foreach role_id [array names roles] { - set party_id [lindex $roles($role_id) 0] - set group_size [lindex $roles($role_id) 1] + array set one_role $roles($role_id) - element set_properties actors actor_${role_id} -value $party_id - element set_properties actors group_${role_id} -value $group_size + element::set_values actors parties_${role_id} $one_role(parties) + element set_properties actors users_per_case_${role_id} -value $one_role(users_per_case) } } -on_submit { # Validation - # Make sure the number of users per case does not exceed the number of users - # in each group + # Make sure the number of users per case does not exceed the total number of users + # in the selected parties array set groups [simulation::casting_groups_with_counts -enrolled_only -workflow_id $workflow_id] set error_p 0 foreach role_id [workflow::get_roles -workflow_id $workflow_id] { - set group_size [set group_$role_id] - set group_id [set actor_$role_id] - set n_members [lindex $groups($group_id) 1] + set users_per_case [set users_per_case_$role_id] - if { $group_size > $n_members } { - template::form::set_error actors group_$role_id "Group size is larger than the number of users in the group: $n_members" + set n_members 0 + foreach party_id [set parties_$role_id] { + set n_members [expr $n_members + [lindex $groups($party_id) 1]] + } + + if { $users_per_case > $n_members } { + template::form::set_error actors users_per_case_$role_id "Number of users per case is larger than the number of users in the selected groups: $n_members" set error_p 1 break } @@ -61,14 +63,14 @@ break } - # TODO: move this code into the simulation::template::edit proc? Low priority. - # Clear out old mappings - simulation::template::delete_role_group_mappings -workflow_id $workflow_id + simulation::template::delete_role_party_mappings -workflow_id $workflow_id foreach role_id [workflow::get_roles -workflow_id $workflow_id] { - simulation::template::new_role_group_mapping \ + set role_edit(users_per_case) [set users_per_case_$role_id] + simulation::role::edit -role_id $role_id -array role_edit + + simulation::template::new_role_party_mappings \ -role_id $role_id \ - -group_id [set actor_$role_id] \ - -group_size [set group_$role_id] + -parties [set parties_$role_id] \ } ad_returnredirect .