Index: openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 24 Oct 2003 10:28:27 -0000 1.3 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 29 Oct 2003 12:57:13 -0000 1.4 @@ -7,13 +7,15 @@ } namespace eval simulation {} +namespace eval simulation::action {} namespace eval simulation::object_type {} +namespace eval simulation::template {} ad_proc -public simulation::object_type::get_options { } { - Generate a list of object types formatted as an option list for form-builder's widgets. + Generate a list of object types formatted as an option list for form-builder's widgets. foo. } { - set sim_types { sim_character sim_prop sim_home sim_stylesheet } + set sim_types { sim_character sim_prop sim_home sim_stylesheet image } return [db_list_of_lists object_types " select ot.pretty_name, @@ -23,4 +25,103 @@ "] } +ad_proc -public simulation::action::edit { + {-action_id:required} + {-sort_order {}} + {-short_name:required} + {-pretty_name:required} + {-pretty_past_tense {}} + {-edit_fields {}} + {-allowed_roles {}} + {-assigned_role {}} + {-privileges {}} + {-enabled_states {}} + {-assigned_states {}} + {-new_state {}} + {-callbacks {}} + {-always_enabled_p f} + {-initial_action_p f} + {-recipient_role:required {}} +} { + Edit an action. Mostly a wrapper for fsm, plus some simulation-specific stuff. +} { + # should call API, but API doesn't exist yet + # deferring at the moment since we're only changing two fields in this + # prototype UI anyway. But it would look like this: + + # workflow::action::fsm::edit \ + # -workflow_id $workflow_id + # -short_name $name \ + # -pretty_name $name \ + # -assigned_role $assigned_role + + set workflow_id [workflow::action::get_workflow_id -action_id $action_id] + + set assigned_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $assigned_role ] + set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role ] + + db_transaction { + db_dml edit_workflow_action { + update workflow_actions + set short_name = :short_name, + pretty_name = :pretty_name, + assigned_role = :assigned_role_id + where action_id = :action_id + } + + db_dml edit_sim_role { + update sim_tasks + set recipient = :recipient_role_id + where task_id = :action_id + } + } + + workflow::action::flush_cache -workflow_id $workflow_id +} + +ad_proc -public simulation::template::associate_object { + -template_id:required + -object_id:required +} { + Associate an object with a simulation template. Succeeds if the record is added or already exists. +} { + + with_catch errmsg { + db_dml add_object_to_workflow_insert { + insert into sim_workflow_object_map + values (:template_id, :object_id) + } + } { + # can only be 0 or 1 due to table constraints + set exists_p [db_string row_exists { + select count(*) + from sim_workflow_object_map + where workflow_id = :template_id + and object_id = :object_id + }] + + if { $exists_p } { + # the record already exists. Return normally + } { + # the record didn't exist, so pass on the error + global errorInfo + error $errmsg $errorInfo + } + } +} + +ad_proc -public simulation::template::dissociate_object { + -template_id:required + -object_id:required +} { + Dissociate an object with a simulation template +} { + db_dml remove_object_from_workflow_delete { + delete from sim_workflow_object_map + where workflow_id = :template_id + and object_id = :object_id + } + # no special error handling because the delete is pretty safe + +} Index: openacs-4/contrib/packages/simulation/www/object-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/object-edit.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/contrib/packages/simulation/www/object-edit.tcl 27 Oct 2003 12:41:24 -0000 1.10 +++ openacs-4/contrib/packages/simulation/www/object-edit.tcl 29 Oct 2003 12:57:13 -0000 1.11 @@ -258,9 +258,10 @@ set attributes [list] foreach attribute_name $attr_names { - lappend attributes $attribute_name [set attr__${content_type}__${attribute_name}] + lappend attributes [list $attribute_name [set attr__${content_type}__${attribute_name}]] } + } -new_data { permission::require_permission -privilege create -object_id [ad_conn package_id] @@ -276,39 +277,42 @@ } } - set item_id [bcms::item::create_item \ - -item_name $name \ - -parent_id $parent_id \ - -content_type $content_type] - - switch $content_method($content_type) { - richtext { - set content_text [template::util::richtext::get_property contents $content_elm] - set mime_type [template::util::richtext::get_property format $content_elm] + db_transaction { + + set item_id [bcms::item::create_item \ + -item_name $name \ + -parent_id $parent_id \ + -content_type $content_type] + + switch $content_method($content_type) { + richtext { + set content_text [template::util::richtext::get_property contents $content_elm] + set mime_type [template::util::richtext::get_property format $content_elm] + } + textarea { + set content_text $content_elm + set mime_type "text/plain" + } } - textarea { - set content_text $content_elm - set mime_type "text/plain" + + if { $content_type == "sim_stylesheet" } { + set mime_type "text/css" } - } + + set revision_id [bcms::revision::add_revision \ + -item_id $item_id \ + -title $title \ + -content_type $content_type \ + -mime_type $mime_type \ + -content $content_text \ + -description $description \ + -additional_properties $attributes] - if { $content_type == "sim_stylesheet" } { - set mime_type "text/css" + bcms::revision::set_revision_status \ + -revision_id $revision_id \ + -status "live" } - - set revision_id [bcms::revision::add_revision \ - -item_id $item_id \ - -title $title \ - -content_type $content_type \ - -mime_type $mime_type \ - -content $content_text \ - -description $description \ - -additional_properties $attributes] - bcms::revision::set_revision_status \ - -revision_id $revision_id \ - -status "live" - } -edit_request { permission::require_write_permission -object_id $item_id @@ -342,22 +346,22 @@ } } + db_transaction { - set revision_id [bcms::revision::add_revision \ - -item_id $item_id \ - -title $title \ - -content_type $content_type \ - -mime_type $mime_type \ - -content $content_text \ - -description $description \ - -additional_properties $attributes] + set revision_id [bcms::revision::add_revision \ + -item_id $item_id \ + -title $title \ + -content_type $content_type \ + -mime_type $mime_type \ + -content $content_text \ + -description $description \ + -additional_properties $attributes] - bcms::revision::set_revision_status \ - -revision_id $revision_id \ - -status "live" - + bcms::revision::set_revision_status \ + -revision_id $revision_id \ + -status "live" + } - } -after_submit { ad_returnredirect object-list ad_script_abort Index: openacs-4/contrib/packages/simulation/www/role-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/role-delete.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/role-delete.adp 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,19 @@ + + @page_title;noquote@ + @context;noquote@ + +

@name@ has dependent tasks. Do you want to delete this role +and all related tasks? + +

Related Tasks

+ + + +

+ » Delete @name@ and tasks +

+ +

+ » Cancel +

+ Index: openacs-4/contrib/packages/simulation/www/role-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/role-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/role-delete.tcl 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,37 @@ +ad_page_contract { + Delete a role. + + Determine if a role has tasks. If show, display all those + tasks and ask for confirmation. If not, delete on the first pass. +} { + {confirm_p:boolean "f"} + role_id:integer + {return_url "sim-template-list"} +} + +set package_id [ad_conn package_id] +set num_of_tasks [db_string task_count " +select count(*) + from workflow_actions wa, + sim_tasks st + where st.task_id = wa.action_id + and wa.assigned_role = :role_id + or st.recipient = :role_id + " + ] +if { [template::util::is_true $confirm_p] || $num_of_tasks == 0 } { + + simulation::role::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 + +set page_title "Delete $name" +set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + +set delete_url [export_vars -base [ad_conn url] { role_id return_url { confirm_p 1 } }] +set cancel_url $return_url Index: openacs-4/contrib/packages/simulation/www/role-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/role-edit.adp,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/www/role-edit.adp 24 Oct 2003 09:46:13 -0000 1.1 +++ openacs-4/contrib/packages/simulation/www/role-edit.adp 29 Oct 2003 12:57:13 -0000 1.2 @@ -4,4 +4,3 @@ object.title - Index: openacs-4/contrib/packages/simulation/www/role-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/role-edit.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/role-edit.tcl 27 Oct 2003 07:31:55 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/role-edit.tcl 29 Oct 2003 12:57:13 -0000 1.3 @@ -1,11 +1,12 @@ ad_page_contract { - Add/edit template. + Add/edit role. - @creation-date 2003-10-13 + @creation-date 2003-10-27 @cvs-id $Id$ } { workflow_id:optional role_id:optional + {limit_characters_p "0"} } -validate { workflow_id_or_role_id { if { ![exists_and_not_null workflow_id] && @@ -20,30 +21,51 @@ # preparation # ###################################################################### -# TODO: one of workflow_id or role_id is required -# enforce this in page contract validation -# redirect to sim-template-list if both missing set package_key [ad_conn package_key] set package_id [ad_conn package_id] #--------------------------------------------------------------------- # Get a list of relevant characters #--------------------------------------------------------------------- -# TODO: make sure this query (and other queries to cr) get only the live -# record from cr_revisions # deliberately not checking to see if character is already cast in sim # because no reason not to have same character in multiple roles (?) -set char_options [db_list_of_lists character_option_list " +# if we are limiting to only characters already in the sim, +# create the sql filter and generate a link to end the filter +# if not, create the opposite filter and link + +if { $limit_characters_p } { + set char_options [db_list_of_lists character_option_list { select ci.name, - cr.item_id - from cr_revisions cr, - cr_items ci + ci.item_id + from cr_items ci, + sim_workflow_object_map swom where ci.content_type = 'sim_character' - and ci.item_id = cr.item_id -"] + and ci.item_id = swom.object_id + and swom.workflow_id = :workflow_id + order by upper(ci.name) + }] + set toggle_text "show all" +} else { + set char_options [db_list_of_lists character_option_list { + select ci.name, + ci.item_id + from cr_items ci + where ci.content_type = 'sim_character' + order by upper(ci.name) + }] + set toggle_text "(limit to characters
in template
)" +} + +set character_filter_html "$toggle_text" + + ###################################################################### # # role @@ -61,14 +83,14 @@ ad_form -name role -cancel_url sim-template-list -form { {role_id:key} {workflow_id:integer(hidden),optional} + {character_id:text(select) + {label "Character
$character_filter_html"} + {options $char_options} + } {name:text {label "Role Name"} {html {size 20}} } - {character_id:text(select) - {label "Character"} - {options $char_options} - } } -edit_request { workflow::role::get -role_id $role_id -array role_array set workflow_id $role_array(workflow_id) @@ -81,6 +103,13 @@ set page_title "Add Role to $sim_template_array(pretty_name)" set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] } -new_data { + + db_transaction { + + simulation::template::associate_object \ + -template_id $workflow_id \ + -object_id $character_id + # create the role set role_id [workflow::role::new \ -workflow_id $workflow_id \ @@ -91,6 +120,8 @@ insert into sim_roles values (:role_id, :character_id) } + +} } -after_submit { ad_returnredirect [export_vars -base "sim-template-edit" { workflow_id }] ad_script_abort Index: openacs-4/contrib/packages/simulation/www/sim-template-add-objects-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-add-objects-2.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/www/sim-template-add-objects-2.tcl 24 Oct 2003 09:46:13 -0000 1.1 +++ openacs-4/contrib/packages/simulation/www/sim-template-add-objects-2.tcl 29 Oct 2003 12:57:13 -0000 1.2 @@ -15,9 +15,8 @@ # ###################################################################### -db_dml add_object_to_workflow_insert " -insert into sim_workflow_object_map -values (:workflow_id, :item_id) -" +simulation::template::associate_object \ + -template_id $workflow_id \ + -object_id $item_id ad_returnredirect "sim-template-edit?workflow_id=$workflow_id" \ No newline at end of file Index: openacs-4/contrib/packages/simulation/www/sim-template-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-edit.adp,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/sim-template-edit.adp 27 Oct 2003 07:31:55 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/sim-template-edit.adp 29 Oct 2003 12:57:13 -0000 1.3 @@ -11,4 +11,5 @@

Roles

Tasks

+ \ No newline at end of file Index: openacs-4/contrib/packages/simulation/www/sim-template-tasks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-tasks.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/sim-template-tasks.adp 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,2 @@ +

+

Add a task Index: openacs-4/contrib/packages/simulation/www/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-tasks.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/sim-template-tasks.tcl 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,78 @@ +# an includelet + +# the includelet can be a full +if { ![exists_and_not_null usage_mode] } { + set usage_mode normal +} + +############################################################## +# +# tasks +# +# A list of all tasks associated with the Simulation Template +# +############################################################## + +#------------------------------------------------------------- +# tasks list +#------------------------------------------------------------- +# TODO: missing: discription, type +# how is type going to work? open question pending prototyping + +set hide_edit_p 1 + +template::list::create \ + -name tasks \ + -multirow tasks \ + -no_data "No tasks in this Simulation Template" \ + -elements { + edit { + hide_p $hide_edit_p + sub_class narrow + link_url_col edit_url + display_template { + Edit + } + } + name { + label "Name" + } + assigned_name { + label "Assigned to" + } + recipient_name { + label "Recipient" + } + delete { + sub_class narrow + link_url_col delete_url + display_template { + Edit + } + } + } + +#------------------------------------------------------------- +# tasks db_multirow +#------------------------------------------------------------- +# TODO: fix this so it returns rows when it should + +db_multirow -extend { edit_url delete_url } tasks select_tasks " + select wa.action_id, + wa.pretty_name as name, + (select pretty_name + from workflow_roles + where role_id = wa.assigned_role) as assigned_name, + (select pretty_name + from workflow_roles + where role_id = st.recipient) as recipient_name, + wa.sort_order + from workflow_actions wa, + sim_tasks st + where wa.workflow_id = :workflow_id + and st.task_id = wa.action_id + [template::list::orderby_clause -orderby -name "tasks"] +" { + set edit_url [export_vars -base "task-edit" { action_id }] + set delete_url [export_vars -base "task-delete" { action_id }] +} Index: openacs-4/contrib/packages/simulation/www/task-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/task-edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/task-edit.adp 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,7 @@ + + @page_title;noquote@ + @context;noquote@ + object.title + + + Index: openacs-4/contrib/packages/simulation/www/task-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/task-edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/task-edit.tcl 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,128 @@ +ad_page_contract { + Add/edit task. + + @creation-date 2003-10-27 + @cvs-id $Id: task-edit.tcl,v 1.1 2003/10/29 12:57:13 joela Exp $ +} { + workflow_id:optional + action_id:optional +} -validate { + workflow_id_or_task_id { + if { ![exists_and_not_null workflow_id] && + ![exists_and_not_null action_id]} { + ad_complain "Either task_id or workflow_id is required." + } + } +} + +###################################################################### +# +# preparation +# +###################################################################### + +set package_key [ad_conn package_key] +set package_id [ad_conn package_id] + +# this part may be superfluous since we do the same thing in edit mode +# TODO - if so, cut it +if { ![exists_and_not_null workflow_id] } { + set workflow_id [db_string get_workflow_from_role "select workflow_id + from workflow_actions + where action_id = :action_id" + ] +} + +workflow::get -workflow_id $workflow_id -array workflow + +#--------------------------------------------------------------------- +# Get a list of relevant roles +#--------------------------------------------------------------------- +# TODO: make sure this query (and other queries to cr) get only the live +# record from cr_revisions +# deliberately not checking to see if character is already cast in sim +# because no reason not to have same character in multiple tasks (?) + +set role_options [db_list_of_lists role_option_list " + select wr.pretty_name, + wr.short_name + from workflow_roles wr + where wr.workflow_id = :workflow_id +"] + +###################################################################### +# +# task +# +# a form showing fields for a task in a workflow +# includes add and edit modes and handles form submission +# display mode is only in list form via sim-template-edit +# +###################################################################### + +#--------------------------------------------------------------------- +# task form +#--------------------------------------------------------------------- + +ad_form -name task -cancel_url sim-template-list -form { + {action_id:key} + {workflow_id:integer(hidden),optional} + {name:text + {label "Task"} + {html {size 20}} + } + {assigned_role:text(select) + {label "Assigned To"} + {options $role_options} + } + {recipient_role:text(select) + {label "Recipient"} + {options $role_options} + } +} -edit_request { + + # Retrieve the task and populate the form + workflow::action::fsm::get -action_id $action_id -array task_array + set workflow_id $task_array(workflow_id) + set name $task_array(pretty_name) + workflow::get -workflow_id $workflow_id -array sim_template_array + set page_title "Edit Task $name" + set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + +} -new_request { + + # Set up the page for a new task + workflow::get -workflow_id $workflow_id -array sim_template_array + set page_title "Add Task to $sim_template_array(pretty_name)" + set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + +} -new_data { + + # create the task + set action_id [workflow::action::fsm::new \ + -workflow_id $workflow_id \ + -short_name $name \ + -pretty_name $name \ + -assigned_role $assigned_role] + # 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 + set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role] + db_dml set_role_recipient { + insert into sim_tasks + values (:action_id, :recipient_role_id) + } +} -edit_data { + + simulation::action::edit \ + -action_id $action_id \ + -short_name $name \ + -pretty_name $name \ + -assigned_role $assigned_role \ + -recipient_role $recipient_role + +} -after_submit { + ad_returnredirect [export_vars -base "sim-template-edit" { workflow_id }] + ad_script_abort +} + Index: openacs-4/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/simulation/tcl/simulation-procs.tcl 24 Oct 2003 10:28:27 -0000 1.3 +++ openacs-4/packages/simulation/tcl/simulation-procs.tcl 29 Oct 2003 12:57:13 -0000 1.4 @@ -7,13 +7,15 @@ } namespace eval simulation {} +namespace eval simulation::action {} namespace eval simulation::object_type {} +namespace eval simulation::template {} ad_proc -public simulation::object_type::get_options { } { - Generate a list of object types formatted as an option list for form-builder's widgets. + Generate a list of object types formatted as an option list for form-builder's widgets. foo. } { - set sim_types { sim_character sim_prop sim_home sim_stylesheet } + set sim_types { sim_character sim_prop sim_home sim_stylesheet image } return [db_list_of_lists object_types " select ot.pretty_name, @@ -23,4 +25,103 @@ "] } +ad_proc -public simulation::action::edit { + {-action_id:required} + {-sort_order {}} + {-short_name:required} + {-pretty_name:required} + {-pretty_past_tense {}} + {-edit_fields {}} + {-allowed_roles {}} + {-assigned_role {}} + {-privileges {}} + {-enabled_states {}} + {-assigned_states {}} + {-new_state {}} + {-callbacks {}} + {-always_enabled_p f} + {-initial_action_p f} + {-recipient_role:required {}} +} { + Edit an action. Mostly a wrapper for fsm, plus some simulation-specific stuff. +} { + # should call API, but API doesn't exist yet + # deferring at the moment since we're only changing two fields in this + # prototype UI anyway. But it would look like this: + + # workflow::action::fsm::edit \ + # -workflow_id $workflow_id + # -short_name $name \ + # -pretty_name $name \ + # -assigned_role $assigned_role + + set workflow_id [workflow::action::get_workflow_id -action_id $action_id] + + set assigned_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $assigned_role ] + set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role ] + + db_transaction { + db_dml edit_workflow_action { + update workflow_actions + set short_name = :short_name, + pretty_name = :pretty_name, + assigned_role = :assigned_role_id + where action_id = :action_id + } + + db_dml edit_sim_role { + update sim_tasks + set recipient = :recipient_role_id + where task_id = :action_id + } + } + + workflow::action::flush_cache -workflow_id $workflow_id +} + +ad_proc -public simulation::template::associate_object { + -template_id:required + -object_id:required +} { + Associate an object with a simulation template. Succeeds if the record is added or already exists. +} { + + with_catch errmsg { + db_dml add_object_to_workflow_insert { + insert into sim_workflow_object_map + values (:template_id, :object_id) + } + } { + # can only be 0 or 1 due to table constraints + set exists_p [db_string row_exists { + select count(*) + from sim_workflow_object_map + where workflow_id = :template_id + and object_id = :object_id + }] + + if { $exists_p } { + # the record already exists. Return normally + } { + # the record didn't exist, so pass on the error + global errorInfo + error $errmsg $errorInfo + } + } +} + +ad_proc -public simulation::template::dissociate_object { + -template_id:required + -object_id:required +} { + Dissociate an object with a simulation template +} { + db_dml remove_object_from_workflow_delete { + delete from sim_workflow_object_map + where workflow_id = :template_id + and object_id = :object_id + } + # no special error handling because the delete is pretty safe + +} Index: openacs-4/packages/simulation/www/object-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/object-edit.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/simulation/www/object-edit.tcl 27 Oct 2003 12:41:24 -0000 1.10 +++ openacs-4/packages/simulation/www/object-edit.tcl 29 Oct 2003 12:57:13 -0000 1.11 @@ -258,9 +258,10 @@ set attributes [list] foreach attribute_name $attr_names { - lappend attributes $attribute_name [set attr__${content_type}__${attribute_name}] + lappend attributes [list $attribute_name [set attr__${content_type}__${attribute_name}]] } + } -new_data { permission::require_permission -privilege create -object_id [ad_conn package_id] @@ -276,39 +277,42 @@ } } - set item_id [bcms::item::create_item \ - -item_name $name \ - -parent_id $parent_id \ - -content_type $content_type] - - switch $content_method($content_type) { - richtext { - set content_text [template::util::richtext::get_property contents $content_elm] - set mime_type [template::util::richtext::get_property format $content_elm] + db_transaction { + + set item_id [bcms::item::create_item \ + -item_name $name \ + -parent_id $parent_id \ + -content_type $content_type] + + switch $content_method($content_type) { + richtext { + set content_text [template::util::richtext::get_property contents $content_elm] + set mime_type [template::util::richtext::get_property format $content_elm] + } + textarea { + set content_text $content_elm + set mime_type "text/plain" + } } - textarea { - set content_text $content_elm - set mime_type "text/plain" + + if { $content_type == "sim_stylesheet" } { + set mime_type "text/css" } - } + + set revision_id [bcms::revision::add_revision \ + -item_id $item_id \ + -title $title \ + -content_type $content_type \ + -mime_type $mime_type \ + -content $content_text \ + -description $description \ + -additional_properties $attributes] - if { $content_type == "sim_stylesheet" } { - set mime_type "text/css" + bcms::revision::set_revision_status \ + -revision_id $revision_id \ + -status "live" } - - set revision_id [bcms::revision::add_revision \ - -item_id $item_id \ - -title $title \ - -content_type $content_type \ - -mime_type $mime_type \ - -content $content_text \ - -description $description \ - -additional_properties $attributes] - bcms::revision::set_revision_status \ - -revision_id $revision_id \ - -status "live" - } -edit_request { permission::require_write_permission -object_id $item_id @@ -342,22 +346,22 @@ } } + db_transaction { - set revision_id [bcms::revision::add_revision \ - -item_id $item_id \ - -title $title \ - -content_type $content_type \ - -mime_type $mime_type \ - -content $content_text \ - -description $description \ - -additional_properties $attributes] + set revision_id [bcms::revision::add_revision \ + -item_id $item_id \ + -title $title \ + -content_type $content_type \ + -mime_type $mime_type \ + -content $content_text \ + -description $description \ + -additional_properties $attributes] - bcms::revision::set_revision_status \ - -revision_id $revision_id \ - -status "live" - + bcms::revision::set_revision_status \ + -revision_id $revision_id \ + -status "live" + } - } -after_submit { ad_returnredirect object-list ad_script_abort Index: openacs-4/packages/simulation/www/role-delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/role-delete.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/role-delete.adp 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,19 @@ + + @page_title;noquote@ + @context;noquote@ + +

@name@ has dependent tasks. Do you want to delete this role +and all related tasks? + +

Related Tasks

+ + + +

+ » Delete @name@ and tasks +

+ +

+ » Cancel +

+ Index: openacs-4/packages/simulation/www/role-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/role-delete.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/role-delete.tcl 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,37 @@ +ad_page_contract { + Delete a role. + + Determine if a role has tasks. If show, display all those + tasks and ask for confirmation. If not, delete on the first pass. +} { + {confirm_p:boolean "f"} + role_id:integer + {return_url "sim-template-list"} +} + +set package_id [ad_conn package_id] +set num_of_tasks [db_string task_count " +select count(*) + from workflow_actions wa, + sim_tasks st + where st.task_id = wa.action_id + and wa.assigned_role = :role_id + or st.recipient = :role_id + " + ] +if { [template::util::is_true $confirm_p] || $num_of_tasks == 0 } { + + simulation::role::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 + +set page_title "Delete $name" +set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + +set delete_url [export_vars -base [ad_conn url] { role_id return_url { confirm_p 1 } }] +set cancel_url $return_url Index: openacs-4/packages/simulation/www/role-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/role-edit.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simulation/www/role-edit.adp 24 Oct 2003 09:46:13 -0000 1.1 +++ openacs-4/packages/simulation/www/role-edit.adp 29 Oct 2003 12:57:13 -0000 1.2 @@ -4,4 +4,3 @@ object.title - Index: openacs-4/packages/simulation/www/role-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/role-edit.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/www/role-edit.tcl 27 Oct 2003 07:31:55 -0000 1.2 +++ openacs-4/packages/simulation/www/role-edit.tcl 29 Oct 2003 12:57:13 -0000 1.3 @@ -1,11 +1,12 @@ ad_page_contract { - Add/edit template. + Add/edit role. - @creation-date 2003-10-13 + @creation-date 2003-10-27 @cvs-id $Id$ } { workflow_id:optional role_id:optional + {limit_characters_p "0"} } -validate { workflow_id_or_role_id { if { ![exists_and_not_null workflow_id] && @@ -20,30 +21,51 @@ # preparation # ###################################################################### -# TODO: one of workflow_id or role_id is required -# enforce this in page contract validation -# redirect to sim-template-list if both missing set package_key [ad_conn package_key] set package_id [ad_conn package_id] #--------------------------------------------------------------------- # Get a list of relevant characters #--------------------------------------------------------------------- -# TODO: make sure this query (and other queries to cr) get only the live -# record from cr_revisions # deliberately not checking to see if character is already cast in sim # because no reason not to have same character in multiple roles (?) -set char_options [db_list_of_lists character_option_list " +# if we are limiting to only characters already in the sim, +# create the sql filter and generate a link to end the filter +# if not, create the opposite filter and link + +if { $limit_characters_p } { + set char_options [db_list_of_lists character_option_list { select ci.name, - cr.item_id - from cr_revisions cr, - cr_items ci + ci.item_id + from cr_items ci, + sim_workflow_object_map swom where ci.content_type = 'sim_character' - and ci.item_id = cr.item_id -"] + and ci.item_id = swom.object_id + and swom.workflow_id = :workflow_id + order by upper(ci.name) + }] + set toggle_text "show all" +} else { + set char_options [db_list_of_lists character_option_list { + select ci.name, + ci.item_id + from cr_items ci + where ci.content_type = 'sim_character' + order by upper(ci.name) + }] + set toggle_text "(limit to characters
in template
)" +} + +set character_filter_html "$toggle_text" + + ###################################################################### # # role @@ -61,14 +83,14 @@ ad_form -name role -cancel_url sim-template-list -form { {role_id:key} {workflow_id:integer(hidden),optional} + {character_id:text(select) + {label "Character
$character_filter_html"} + {options $char_options} + } {name:text {label "Role Name"} {html {size 20}} } - {character_id:text(select) - {label "Character"} - {options $char_options} - } } -edit_request { workflow::role::get -role_id $role_id -array role_array set workflow_id $role_array(workflow_id) @@ -81,6 +103,13 @@ set page_title "Add Role to $sim_template_array(pretty_name)" set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] } -new_data { + + db_transaction { + + simulation::template::associate_object \ + -template_id $workflow_id \ + -object_id $character_id + # create the role set role_id [workflow::role::new \ -workflow_id $workflow_id \ @@ -91,6 +120,8 @@ insert into sim_roles values (:role_id, :character_id) } + +} } -after_submit { ad_returnredirect [export_vars -base "sim-template-edit" { workflow_id }] ad_script_abort Index: openacs-4/packages/simulation/www/sim-template-add-objects-2.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-add-objects-2.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/simulation/www/sim-template-add-objects-2.tcl 24 Oct 2003 09:46:13 -0000 1.1 +++ openacs-4/packages/simulation/www/sim-template-add-objects-2.tcl 29 Oct 2003 12:57:13 -0000 1.2 @@ -15,9 +15,8 @@ # ###################################################################### -db_dml add_object_to_workflow_insert " -insert into sim_workflow_object_map -values (:workflow_id, :item_id) -" +simulation::template::associate_object \ + -template_id $workflow_id \ + -object_id $item_id ad_returnredirect "sim-template-edit?workflow_id=$workflow_id" \ No newline at end of file Index: openacs-4/packages/simulation/www/sim-template-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-edit.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/www/sim-template-edit.adp 27 Oct 2003 07:31:55 -0000 1.2 +++ openacs-4/packages/simulation/www/sim-template-edit.adp 29 Oct 2003 12:57:13 -0000 1.3 @@ -11,4 +11,5 @@

Roles

Tasks

+ \ No newline at end of file Index: openacs-4/packages/simulation/www/sim-template-tasks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-tasks.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/sim-template-tasks.adp 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,2 @@ +

+

Add a task Index: openacs-4/packages/simulation/www/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-tasks.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/sim-template-tasks.tcl 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,78 @@ +# an includelet + +# the includelet can be a full +if { ![exists_and_not_null usage_mode] } { + set usage_mode normal +} + +############################################################## +# +# tasks +# +# A list of all tasks associated with the Simulation Template +# +############################################################## + +#------------------------------------------------------------- +# tasks list +#------------------------------------------------------------- +# TODO: missing: discription, type +# how is type going to work? open question pending prototyping + +set hide_edit_p 1 + +template::list::create \ + -name tasks \ + -multirow tasks \ + -no_data "No tasks in this Simulation Template" \ + -elements { + edit { + hide_p $hide_edit_p + sub_class narrow + link_url_col edit_url + display_template { + Edit + } + } + name { + label "Name" + } + assigned_name { + label "Assigned to" + } + recipient_name { + label "Recipient" + } + delete { + sub_class narrow + link_url_col delete_url + display_template { + Edit + } + } + } + +#------------------------------------------------------------- +# tasks db_multirow +#------------------------------------------------------------- +# TODO: fix this so it returns rows when it should + +db_multirow -extend { edit_url delete_url } tasks select_tasks " + select wa.action_id, + wa.pretty_name as name, + (select pretty_name + from workflow_roles + where role_id = wa.assigned_role) as assigned_name, + (select pretty_name + from workflow_roles + where role_id = st.recipient) as recipient_name, + wa.sort_order + from workflow_actions wa, + sim_tasks st + where wa.workflow_id = :workflow_id + and st.task_id = wa.action_id + [template::list::orderby_clause -orderby -name "tasks"] +" { + set edit_url [export_vars -base "task-edit" { action_id }] + set delete_url [export_vars -base "task-delete" { action_id }] +} Index: openacs-4/packages/simulation/www/task-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/task-edit.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/task-edit.adp 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,7 @@ + + @page_title;noquote@ + @context;noquote@ + object.title + + + Index: openacs-4/packages/simulation/www/task-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/task-edit.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/task-edit.tcl 29 Oct 2003 12:57:13 -0000 1.1 @@ -0,0 +1,128 @@ +ad_page_contract { + Add/edit task. + + @creation-date 2003-10-27 + @cvs-id $Id: task-edit.tcl,v 1.1 2003/10/29 12:57:13 joela Exp $ +} { + workflow_id:optional + action_id:optional +} -validate { + workflow_id_or_task_id { + if { ![exists_and_not_null workflow_id] && + ![exists_and_not_null action_id]} { + ad_complain "Either task_id or workflow_id is required." + } + } +} + +###################################################################### +# +# preparation +# +###################################################################### + +set package_key [ad_conn package_key] +set package_id [ad_conn package_id] + +# this part may be superfluous since we do the same thing in edit mode +# TODO - if so, cut it +if { ![exists_and_not_null workflow_id] } { + set workflow_id [db_string get_workflow_from_role "select workflow_id + from workflow_actions + where action_id = :action_id" + ] +} + +workflow::get -workflow_id $workflow_id -array workflow + +#--------------------------------------------------------------------- +# Get a list of relevant roles +#--------------------------------------------------------------------- +# TODO: make sure this query (and other queries to cr) get only the live +# record from cr_revisions +# deliberately not checking to see if character is already cast in sim +# because no reason not to have same character in multiple tasks (?) + +set role_options [db_list_of_lists role_option_list " + select wr.pretty_name, + wr.short_name + from workflow_roles wr + where wr.workflow_id = :workflow_id +"] + +###################################################################### +# +# task +# +# a form showing fields for a task in a workflow +# includes add and edit modes and handles form submission +# display mode is only in list form via sim-template-edit +# +###################################################################### + +#--------------------------------------------------------------------- +# task form +#--------------------------------------------------------------------- + +ad_form -name task -cancel_url sim-template-list -form { + {action_id:key} + {workflow_id:integer(hidden),optional} + {name:text + {label "Task"} + {html {size 20}} + } + {assigned_role:text(select) + {label "Assigned To"} + {options $role_options} + } + {recipient_role:text(select) + {label "Recipient"} + {options $role_options} + } +} -edit_request { + + # Retrieve the task and populate the form + workflow::action::fsm::get -action_id $action_id -array task_array + set workflow_id $task_array(workflow_id) + set name $task_array(pretty_name) + workflow::get -workflow_id $workflow_id -array sim_template_array + set page_title "Edit Task $name" + set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + +} -new_request { + + # Set up the page for a new task + workflow::get -workflow_id $workflow_id -array sim_template_array + set page_title "Add Task to $sim_template_array(pretty_name)" + set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + +} -new_data { + + # create the task + set action_id [workflow::action::fsm::new \ + -workflow_id $workflow_id \ + -short_name $name \ + -pretty_name $name \ + -assigned_role $assigned_role] + # 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 + set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role] + db_dml set_role_recipient { + insert into sim_tasks + values (:action_id, :recipient_role_id) + } +} -edit_data { + + simulation::action::edit \ + -action_id $action_id \ + -short_name $name \ + -pretty_name $name \ + -assigned_role $assigned_role \ + -recipient_role $recipient_role + +} -after_submit { + ad_returnredirect [export_vars -base "sim-template-edit" { workflow_id }] + ad_script_abort +} +