gustafn
committed
on 25 Jul 18
normalize boolean expressions in .adp files
openacs-4/.../tasks/lib/task-form.tcl (+289)
  1 # /packages/tasks/task-form
  2 #
  3 # @author Matthew Geddert
  4
  5 set required_params [list object_id return_url standard_tasks_list]
  6 foreach required_param $required_params {
  7     if { [info exists $required_param] } {
  8         set $required_param [set $required_param]
  9     } else {
  10         set $required_param [ns_queryget $required_param]
  11     }
  12     if { $required_param eq "" } {
  13         ad_return_error "Required Parameter" "A required parameter '$required_params' was not supplied"
  14     }
  15 }
  16
  17
  18 # export_vars_list is a tcl list of key value that need
  19 # to be submitted with the form so that the page that
  20 # includes the tasks is displayed correctly when we
  21 # submit infromation
  22
  23 if { ![info exists export_vars_list] } {
  24     set export_vars_list {}
  25 }
  26
  27 set task_form_vars [list task_id names assignee_id task_prescribed task due_date status priority description comment creator]
  28 set export_vars [list]
  29 foreach {key value} $export_vars_list {
  30     if { [lsearch $task_form_vars $key] < 0 } {
  31         set $key $value
  32         lappend export_vars $key
  33     }
  34 }
  35 #ad_return_error "ASD" "$mode $object_id"
  36
  37 # after being submitted via the form object_id is a single list item string,
  38 # this removes that limitation, and simplifies passing object_id to the form
  39 # by not requiring an ugly hack to maintain two lists
  40 if { [llength $object_id] == 1 } {
  41     set object_id [lindex $object_id 0]
  42 }
  43
  44 set object_id [lsort -unique $object_id]
  45
  46 set object_count [llength $object_id]
  47
  48
  49
  50 # ad_form_new_p is broken by this tasks include
  51 # due to its use of all form vars, thus we need
  52 # to find out if this is an edit request or not
  53 # by checking if the task_id object exists
  54
  55 if { ![info exists task_id] } {
  56     set task_action "add"
  57 } else {
  58     if { [db_0or1row get_it { select 1 from acs_objects where object_id = :task_id }] } {
  59         set task_action "edit"
  60         set task_action_id $task_id
  61     } else {
  62         set task_action "add"
  63     }
  64 }
  65
  66 if { $task_action eq "add" } {
  67     set edit_buttons [list \
  68                           [list "[_ tasks.Add_Task]" save] \
  69                           [list "[_ tasks.lt_Add_Task_and_Add_Anot]" save_add_another] \
  70                          ]
  71 } else {
  72     if { $object_count > 1 } {
  73         ad_return_error "[_ tasks.Not_Allowed]" "[_ tasks.lt_You_are_not_allowed_t]"
  74     }
  75     set edit_buttons [list \
  76                           [list "[_ tasks.Update]" save] \
  77                           [list "[_ tasks.lt_Update_and_Add_New_Ta]" save_add_another] \
  78                           [list "[_ tasks.Delete]" delete]
  79                      ]
  80 }
  81
  82
  83 set user_id [ad_maybe_redirect_for_registration]
  84
  85
  86 # We select the users to use in the assign_object_id element
  87 # on the form to let the user choose who will be assigned to
  88 # the task, plus one blank space that willl be the current object_id
  89 set assign_parties_options [list [list "       " $object_id]]
  90 append assign_parties_options " [db_list_of_lists get_all_users { }]"
  91
  92
  93 set names [list]
  94 foreach object $object_id {
  95     lappend names "<a href=\"/o/$object\">[db_string get_acs_object_name { select acs_object__name(:object) }]</a>"
  96 }
  97 set names [join $names ", "]
  98
  99 set package_id [ad_conn package_id]
  100
  101
  102 if { [ns_queryget "formbutton:delete"] ne "" } {
  103
  104     set task_title [tasks::task::title -task_id $task_id]
  105     tasks::task::delete -task_id $task_id
  106     ad_returnredirect -message "[_ tasks.lt_The_task_lindex_task_]" -html $return_url
  107     ad_script_abort
  108 }
  109
  110 set status_options [db_list_of_lists status_options { }]
  111 set status_options [lang::util::localize $status_options]
  112
  113
  114 set form_elements {
  115         task_id:key
  116         {names:text(hidden),optional {label "[_ tasks.Add_task_to]"}}
  117         {assignee_id:text(select),optional
  118             {label "[_ tasks.Assign_to]"}
  119             {options { $assign_parties_options}}
  120             {help_text "[_ tasks.Select_the_user_to]"}
  121         }
  122     }
  123
  124
  125
  126
  127 if { [exists_and_not_null standard_tasks_list] } {
  128
  129     # the calling package has provided a list of default tasks
  130     # to use for this package. Thus we set up a standard task list
  131     set params [split [parameter::get -parameter DefaultTasks -default ""] ";"]
  132     set opts [list [list "" ""]]
  133     foreach param $params {
  134         lappend opts [list [_ $param] [_ $param]]
  135     }
  136
  137     append form_elements {
  138         {task_prescribed:text(select),optional
  139             {label "[_ tasks.Standard_Task]"}
  140             {options $opts}
  141         }
  142         {task:text(text),optional
  143             {label "[_ tasks.Custom_Task]"}
  144             {html { maxlength 1000 size 80 }}
  145             {help_text "[_ tasks.You_can_either_use]"}
  146         }
  147     }
  148
  149 } else {
  150     append form_elements {
  151         {task_prescribed:text(hidden),optional}
  152         {task:text(text)
  153             {label "[_ tasks.Task]"}
  154             {html { maxlength 1000 size 80 }}
  155         }
  156     }
  157
  158 }
  159
  160 append form_elements {
  161     {due_date:text
  162         {label "[_ tasks.Due]"}
  163         {html {id date1 size 10 maxlength 10}}
  164         {help_text "[_ tasks.if_blank_there_is_no]"}
  165         {after_html {<input type='reset' value=' ... ' onclick=\"return showCalendar('date1', 'y-m-d');\"> \[<b>y-m-d </b>\]}}
  166     }
  167     {status:text(select)
  168         {label "[_ tasks.Status]"}
  169         {options $status_options}
  170     }
  171     {priority:integer(select),optional
  172         {label "[_ tasks.Priority]"}
  173         {options {{{3 - [_ tasks.Very_Important]} 3} {{2 - [_ tasks.Important]} 2} {{1 - [_ tasks.Normal]} 1} {{0 - [_ tasks.Not_Important]} 0}}}
  174     }
  175     {description:text(textarea),optional,nospell
  176         {label "[_ tasks.Notes]"}
  177         {html { rows 6 cols 60 wrap soft}}
  178     }
  179     {comment:text(textarea),optional,nospell
  180         {label "[_ tasks.Comment]"}
  181         {html { rows 6 cols 60 wrap soft}}
  182     }
  183 }
  184
  185 #ad_return_error "ASD" [lsort -unique [concat [list return_url object_id task_action task_action_id task_form_vars] $export_vars_list]]
  186
  187 ad_form \
  188     -name add_edit \
  189     -cancel_url $return_url \
  190     -cancel_label "[_ tasks.Cancel]" \
  191     -edit_buttons $edit_buttons \
  192     -export [lsort -unique [concat [list return_url object_id task_action task_action_id task_form_vars] $export_vars]] \
  193     -form $form_elements \
  194     -new_request {
  195
  196         set title "[_ tasks.Add_Task]"
  197         set context [list $title]
  198         set status "1"
  199         set priority "1"
  200
  201     } -edit_request {
  202
  203         db_1row get_task_info { }
  204         set title $task
  205         set context [list $title]
  206         set task_prescribed_p 0
  207         foreach task_prescribed_option [template::element::get_property add_edit task_prescribed options] {
  208             if { [lindex $task_prescribed_option 0] == $task } {
  209                 set task_prescribed_p 1
  210             }
  211         }
  212         if { $task_prescribed_p } {
  213             set task_prescribed $task
  214             set task ""
  215         } else {
  216             set task_prescribed ""
  217         }
  218
  219     } -validate {
  220 #       {end_date {[calendar::date_valid_p -date $end_date]} {This is not a valid date. Either the date doesn't exist or it is not formatted correctly. Correct formatting is: YYYY-MM-DD or YYYYMMDD}}
  221         {task { [string equal [string trim $task] {}] != [string equal [string trim $task_prescribed] {}] } {[_ tasks.lt_Either_a_custom_task_]}}
  222     } -new_data {
  223         foreach object $object_id {
  224             set task_id [tasks::task::new \
  225                              -title ${task} \
  226                              -description ${description} \
  227                              -mime_type "text/plain" \
  228                              -comment ${comment} \
  229                              -object_id ${object} \
  230                              -due_date ${due_date} \
  231                              -status_id ${status} \
  232                              -package_id ${package_id} \
  233                              -priority ${priority}]
  234         }
  235
  236         if { [llength $object_id] == 1 } {
  237             set task_url [export_vars -base [ad_conn url] -url {task_id return_url}]
  238             util_user_message -html -message "[_ tasks.lt_The_task_a_hreftaskst]"
  239         } else {
  240             util_user_message -html -message "[_ tasks.lt_The_task_task_was_add]"          
  241         }
  242
  243     } -edit_data {
  244
  245         set task_id [tasks::task::edit \
  246                          -task_id ${task_id} \
  247                          -title ${task} \
  248                          -description ${description} \
  249                          -mime_type "text/plain" \
  250                          -comment ${comment} \
  251                          -due_date ${due_date} \
  252                          -status_id ${status} \
  253                          -priority ${priority} \
  254                          -assignee_id ${assignee_id}]
  255
  256         set task_url [export_vars -base task -url {task_id return_url}]
  257         set title $task
  258         util_user_message -html -message "[_ tasks.lt_The_task_a_hreftaskst_1]"
  259
  260
  261     } -after_submit {
  262 #       if { ![exists_and_not_null return_url] } {
  263 #           set return_url [export_vars -url -base "contact" {object_id}]
  264 #       }
  265 #       if { [ns_queryget "formbutton:save_add_another"] != "" } {
  266 #           set return_url [export_vars -url -base [ad_conn url] {return_url}]
  267 #       }
  268         ad_returnredirect $return_url
  269         ad_script_abort
  270
  271     }
  272
  273 if { $task_action eq "edit" } {
  274     set creation_id [db_string get_it { }]
  275     set creator_url [contact::url -party_id $creation_id]
  276     set creator_name [contact::name -party_id $creation_id]
  277     template::element::create add_edit creator \
  278         -datatype "text" \
  279         -widget "inform" \
  280         -label "" \
  281         -value "[_ tasks.lt_Originally_created_by]" \
  282         -optional
  283 } else {
  284     if { $object_count > 1 } {
  285         template::element::set_properties add_edit names widget inform
  286     }
  287 }
  288
  289 ad_return_template