Index: openacs-4/contrib/packages/project-manager/www/task-add-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/project-manager/www/Attic/task-add-edit.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/contrib/packages/project-manager/www/task-add-edit.tcl 12 Sep 2003 01:20:57 -0000 1.16 +++ openacs-4/contrib/packages/project-manager/www/task-add-edit.tcl 17 Sep 2003 22:20:59 -0000 1.17 @@ -9,6 +9,7 @@ @return context_bar Context bar. @return title Page title. @return num num is used as a multirow datasource to iterate over the ad_form elements + @return edit_p if t then we are editing. Used to show different portions of the form @param project_item_id Specifies which project this task is associated with @param project_id Specifies which project revision this task is associated with @@ -26,13 +27,14 @@ {number:integer "1"} task_revision_id:integer,optional task_id:multiple,integer,optional + task_item_id:array,optional task_title:array,optional use_dependency_p:array,optional description:array,optional name:array,optional - parent_id:array,optional end_date:array,optional percent_complete:array,optional + actual_hours_worked:array,optional estimated_hours_work:array,optional estimated_hours_work_min:array,optional estimated_hours_work_max:array,optional @@ -43,6 +45,7 @@ title:onevalue num:multirow use_uncertain_completion_times_p:onevalue + edit_p:onevalue } -validate { number_is_in_range -requires {number:integer} { @@ -63,14 +66,48 @@ # --------------------------------------------------------------- # -# create a multirow we can use to iterate -template::multirow create num number +if {![exists_and_not_null project_id]} { + set project_id [db_string get_project_id { }] +} -for {set i 1} {$i <= $number} {incr i} { - template::multirow append num $i +ns_log notice it's my page! +set mypage [ns_getform] +if {[string equal "" $mypage]} { + ns_log notice no form was submitted on my page +} else { + ns_log notice the following form was submitted on my page + ns_set print $mypage } +if {[info exists task_id] && ![info exists __new_p]} { + # create a multirow we can use to iterate + # we also set the number variable so we can use that in + # this tcl file + template::multirow create num number + + set i 1 + set number 0 + foreach tid $task_id { + template::multirow append num $i + incr i + incr number + } + set edit_p t + +} else { + # create a multirow we can use to iterate + template::multirow create num number + + for {set i 1} {$i <= $number} {incr i} { + template::multirow append num $i + } + + set edit_p f +} + + + # The evilest hack of all time. # ------------------------------------------------------- # This is a workaround the fact that using multiple dates @@ -120,7 +157,7 @@ set package_id [ad_conn package_id] set user_id [ad_maybe_redirect_for_registration] -# permissions +# permissions and more if {[exists_and_not_null task_id]} { set title "Edit a $task_term_lower" @@ -155,9 +192,11 @@ } -new_data { + # -------------------------------------------------------------- # each task we add in returns a task_revision_id # we set up two lists, one for tasks that will need dependencies # another for tasks that don't + # -------------------------------------------------------------- set revision_has_dependencies [list] set revision_no_dependencies [list] @@ -187,6 +226,43 @@ } -edit_data { + # -------------------------------------------------------------- + # each task we edit returns a task_revision_id + # we set up two lists, one for tasks that will need dependencies + # another for tasks that don't + # -------------------------------------------------------------- + + set revision_has_dependencies [list] + set revision_no_dependencies [list] + + for {set i 1} {$i <= $number} {incr i} { + + if {![exists_and_not_null estimated_hours_work($i)]} { + set estimated_hours_work($i) [expr .5 * ($estimated_hours_work_max($i) - $estimated_hours_work_min($i)) + $estimated_hours_work_min($i)] + } + + if {![exists_and_not_null estimated_hours_work_min($i)]} { + set estimated_hours_work_min($i) $estimated_hours_work($i) + } + + if {![exists_and_not_null estimated_hours_work_max($i)]} { + set estimated_hours_work_max($i) $estimated_hours_work($i) + } + + # do the actual edit + set this_revision_id [db_exec_plsql new_task_revision { }] + # set this_revision_id [db_exec_plsql new_task_item { *SQL* }] + + # BUG: we need to make sure we take care of deleting dependencies + # if unchecked, adding dependencies, etc.. + + if {[info exists use_dependency_p($i)] && [string equal $use_dependency_p($i) "t"]} { + #lappend revision_has_dependencies $this_revision_id + } else { + #lappend revision_no_dependencies $this_revision_id + } + } + } -select_query_name task_query -after_submit { # now go through the use_dependency_p items. For each that is checked, @@ -198,62 +274,173 @@ } +# ---------------------------------- +# we set the values for edited tasks +# ---------------------------------- + +if {[info exists task_id]} { + + set i 1 + + db_foreach get_old_tasks { } { + + set task_title_arr($i) $task_title + set description_arr($i) $description + set estimated_hours_arr($i) $estimated_hours_work + set estimated_hours_min_arr($i) $estimated_hours_work_min + set estimated_hours_max_arr($i) $estimated_hours_work_max + set end_date_arr($i) $end_date + set percent_complete_arr($i) $percent_complete + set actual_hours_worked_arr($i) $actual_hours_worked + set task_item_id_arr($i) [lindex $task_id [expr $i - 1]] + + if {[exists_and_not_null parent_task_id]} { + set use_dependency_arr($i) [list checked ""] + } else { + set use_dependency_arr($i) "" + } + + + # ----------------------------------------------------- + # if we are editing the tasks, then we want to show the + # percent_complete + # ----------------------------------------------------- + + ad_form -extend \ + -name add_edit \ + -select_query_name task_query \ + -form \ + [list [list percent_complete.$i:text \ + {label "Percent complete"} \ + {html {size 4}} \ + {value {$percent_complete_arr($i)}} \ + ] \ + [list actual_hours_worked.$i:text \ + {label "Hours worked"} \ + {html {size 4}} \ + {value {$actual_hours_worked_arr($i)}} \ + ] + ] + + incr i + } +} else { + + for {set i 1} {$i <= $number} {incr i} { + set task_title_arr($i) "" + set description_arr($i) "" + set estimated_hours_arr($i) "" + set estimated_hours_min_arr($i) "" + set estimated_hours_max_arr($i) "" + set use_dependency_arr($i) "" + set parent_arr($i) "" + set end_date_arr($i) "" + set percent_complete_arr($i) 0 + set actual_hours_worked_arr($i) 0 + set task_item_id_arr($i) "" + + # ----------------------------------------------------- + # for new tasks, we hide the percent_complete + # ----------------------------------------------------- + + ad_form -extend \ + -name add_edit \ + -select_query_name task_query \ + -form \ + [list [list percent_complete.$i:text(hidden) \ + {label "Percent complete \#$i"} \ + {html {size 4}} \ + {value {$percent_complete_arr($i)}} \ + ] \ + [list actual_hours_worked.$i:text(hidden) \ + {label "Hours worked"} \ + {html {size 4}} \ + {value {$actual_hours_worked_arr($i)}} \ + ] + ] + + } +} + + +# ---------------------------------------------- +# extend the form with all the items that repeat +# ---------------------------------------------- + for {set i 1} {$i <= $number} {incr i} { # reading this code, you may wonder why we put the .$i at the end. # DaveB showed me this trick. It lets you make a multiple out of # the items by stuffing them in an array. Long live DaveB. - ad_form -extend -name add_edit -form \ + ad_form -extend \ + -name add_edit \ + -select_query_name task_query \ + -form \ [list \ [list \ task_title.$i:text \ {label "Subject \#$i"} \ {html {size 39}} \ + {value {$task_title_arr($i)}} ] \ + [list task_item_id.$i:text(hidden) \ + {label "Task item id"} \ + {html {size 4}} \ + {value {$task_item_id_arr($i)}} \ + ] \ [list \ description.$i:text(textarea),optional \ {label "Description"} \ {html {rows 7 cols 40}} \ + {value {$description_arr($i)}} \ ] \ [list \ use_dependency_p.$i:text(checkbox) \ {label "Use dependency"} \ - {value "t"} \ + {options {{"" "t"}}} \ + {html $use_dependency_arr($i)} \ ] \ [list \ - parent_id.$i:text(hidden) \ - ] \ - [list \ end_date.$i:date,to_sql(linear_date),optional \ {label "Deadline"} \ {format "MONTH DD YYYY"} \ + {value $end_date_arr($i)} \ {help} \ ] \ ] if {$use_uncertain_completion_times_p} { - ad_form -extend -name add_edit -form \ + ad_form -extend \ + -name add_edit \ + -select_query_name task_query \ + -form \ [list \ [list \ estimated_hours_work_min.$i:integer \ {label "Hours estimate - min"} \ {html {size 3}} \ + {value {$estimated_hours_min_arr($i)}} \ ] \ [list \ estimated_hours_work_max.$i:integer \ {label "Hours estimate - max"} \ {html {size 3}} \ + {value {$estimated_hours_max_arr($i)}} \ ] \ ] } else { - ad_form -extend -name add_edit -form \ + ad_form -extend -name add_edit \ + -select_query_name task_query \ + -form \ [list \ [list \ estimated_hours_work.$i:integer \ {label "Hours estimate"} \ {html {size 3}} \ + {value {$estimated_hours_arr($i)}} \ ] \ ] } } +