Added controls for report approval options on reports.php.
[timetracker.git] / WEB-INF / templates / reports.tpl
1 <script>
2 // We need a couple of array-like objects, one for associated task ids, another for task names.
3 // For performance, and because associated arrays are frowned upon in JavaScript, we'll use a simple object
4 // with properties for project tasks. Format:
5
6 // obj_tasks.p325 = "100,101,302,303,304"; // Tasks ids for project 325 are "100,101,302,303,304".
7 // obj_tasks.p408 = "100,302";  // Tasks ids for project 408 are "100,302".
8
9 // Create an object for task ids.
10 obj_tasks = {};
11 var project_prefix = "p"; // Prefix for project property.
12 var project_property;
13
14 // Populate obj_tasks with task ids for each relevant project.
15 {foreach $project_list as $project}
16   project_property = project_prefix + {$project.id};
17   obj_tasks[project_property] = "{$project.tasks}";
18 {/foreach}
19
20 // Prepare an array of task names.
21 // Format: task_names[0] = Array(100, 'Coding'), task_names[1] = Array(302, 'Debugging'), etc...
22 // First element = task_id, second element = task name.
23 task_names = new Array();
24 var idx = 0;
25 {foreach $task_list as $task}
26   task_names[idx] = new Array({$task.id}, "{$task.name|escape:'javascript'}");
27   idx++;
28 {/foreach}
29
30
31 // empty_label is the mandatory top option in the tasks dropdown.
32 empty_label = '{$i18n.dropdown.all|escape:'javascript'}';
33
34 // inArray - determines whether needle is in haystack array.
35 function inArray(needle, haystack) {
36   var length = haystack.length;
37   for(var i = 0; i < length; i++) {
38     if(haystack[i] == needle) return true;
39   }
40   return false;
41 }
42
43 // The fillTaskDropdown function populates the task combo box with
44 // tasks associated with a selected project_id.
45 function fillTaskDropdown(project_id) {
46   var str_task_ids;
47   // Get a string of comma-separated task ids.
48   if (project_id) {  
49     var property = "p" + project_id;
50     str_task_ids = obj_tasks[property];
51   }
52   if (str_task_ids) {
53     var task_ids = new Array(); // Array of task ids.
54     task_ids = str_task_ids.split(",");
55   }
56
57   var dropdown = document.getElementById("task");
58   // Determine previously selected item.
59   var selected_item = dropdown.options[dropdown.selectedIndex].value;
60
61   // Remove existing content.
62   dropdown.length = 0;
63   // Add mandatory top option.
64   dropdown.options[0] = new Option(empty_label, '', true);
65
66   // Populate the dropdown with associated tasks.
67   len = task_names.length;
68   var dropdown_idx = 0;
69   for (var i = 0; i < len; i++) {
70     if (!project_id) {
71       // No project is selected. Fill in all tasks.
72       dropdown.options[dropdown_idx+1] = new Option(task_names[i][1], task_names[i][0]);
73       dropdown_idx++;
74     } else if (str_task_ids) {
75       // Project is selected and has associated tasks. Fill them in.
76       if (inArray(task_names[i][0], task_ids)) {
77         dropdown.options[dropdown_idx+1] = new Option(task_names[i][1], task_names[i][0]);
78         dropdown_idx++;
79       }
80     }
81   }
82
83   // If a previously selected item is still in dropdown - select it.
84   if (dropdown.options.length > 0) {
85     for (var i = 0; i < dropdown.options.length; i++) {
86       if (dropdown.options[i].value == selected_item)  {
87         dropdown.options[i].selected = true;
88       }
89     }
90   }
91 }
92
93 // Build JavaScript array for assigned projects out of passed in PHP array.
94 var assigned_projects = new Array();
95 {if $assigned_projects}
96   {foreach $assigned_projects as $user_id => $projects}
97     assigned_projects[{$user_id}] = new Array();
98     {if $projects}
99       {foreach $projects as $idx => $project_id}
100         assigned_projects[{$user_id}][{$idx}] = {$project_id};
101       {/foreach}
102     {/if}
103   {/foreach}
104 {/if}
105
106 // selectAssignedUsers is called when a project is changed in project dropdown.
107 // It selects users on the form who are assigned to this project.
108 function selectAssignedUsers(project_id) {
109   var user_id;
110   var len;
111
112   for (var i = 0; i < document.reportForm.elements.length; i++) {
113     if ((document.reportForm.elements[i].type == 'checkbox') && (document.reportForm.elements[i].name == 'users[]')) {
114       user_id = document.reportForm.elements[i].value;
115       if (project_id)
116         document.reportForm.elements[i].checked = false;
117       else
118         document.reportForm.elements[i].checked = true;
119
120       if(assigned_projects[user_id] != undefined)
121         len = assigned_projects[user_id].length;
122       else
123         len = 0;
124
125       if (project_id != '')
126         for (var j = 0; j < len; j++) {
127           if (project_id == assigned_projects[user_id][j]) {
128             document.reportForm.elements[i].checked = true;
129             break;
130           }
131         }
132     }
133   }
134 }
135
136 // handleCheckboxes - unmarks and hides the "Totals only" checkbox when
137 // "no grouping" is selected in the associated group by dropdowns.
138 function handleCheckboxes() {
139   var totalsOnlyCheckbox = document.getElementById("chtotalsonly");
140   var totalsOnlyLabel = document.getElementById("totals_only_label");
141   var groupBy1 = document.getElementById("group_by1");
142   var groupBy2 = document.getElementById("group_by2");
143   var groupBy3 = document.getElementById("group_by3");
144   var grouping = false;
145   if ((groupBy1 != null && "no_grouping" != groupBy1.value) ||
146       (groupBy2 != null && "no_grouping" != groupBy2.value) ||
147       (groupBy3 != null && "no_grouping" != groupBy3.value)) {
148     grouping = true;
149   }
150   if (grouping) {
151     // Show the "Totals only" checkbox.
152     totalsOnlyCheckbox.style.visibility = "visible";
153     totalsOnlyLabel.style.visibility = "visible";
154   } else {
155     // Unmark and hide the "Totals only" checkbox.
156     totalsOnlyCheckbox.checked = false;
157     totalsOnlyCheckbox.style.visibility = "hidden";
158     totalsOnlyLabel.style.visibility = "hidden";
159   }
160 }
161 </script>
162
163 {$forms.reportForm.open}
164 <div style="padding: 0 0 10 0;">
165   <table border="0" class="divider">
166     <tr>
167       <td>
168         <table cellspacing="1" cellpadding="3" border="0">
169           <tr>
170             <td>{$i18n.label.fav_report}:</td><td>{$forms.reportForm.favorite_report.control}</td>
171             <td>{$forms.reportForm.btn_generate.control}&nbsp;{$forms.reportForm.btn_delete.control}</td>
172           </tr>
173         </table>
174       </td>
175     </tr>
176   </table>
177 </div>
178
179 <table cellspacing="4" cellpadding="7" border="0">
180   <tr>
181     <td valign="top" colspan="2" align="center">
182       <table border="0" cellpadding="3">
183         <tr>
184           <td valign="top">
185             <table border="0" cellpadding="3">
186 {if $show_client}
187               <tr><td><b>{$i18n.label.client}</b></td></tr>
188               <tr><td>{$forms.reportForm.client.control}</td></tr>
189 {/if}
190 {if $show_project}
191               <tr><td><b>{$i18n.label.project}</b></td></tr>
192               <tr><td>{$forms.reportForm.project.control}</td></tr>
193 {/if}
194 {if $show_billable}
195               <tr><td><b>{$i18n.form.time.billable}</b></td></tr>
196               <tr><td>{$forms.reportForm.include_records.control}</td></tr>
197 {/if}
198 {if $show_paid_status}
199               <tr><td><b>{$i18n.label.paid_status}</b></td></tr>
200               <tr><td>{$forms.reportForm.paid_status.control}</td></tr>
201 {/if}
202             </table>
203           </td>
204           <td></td>
205           <td valign="top">
206             <table border="0" cellpadding="3">
207 {if $show_cf_1_dropdown}
208               <tr><td><b>{$i18n.label.option}</b></td></tr>
209               <tr><td>{$forms.reportForm.option.control}</td></tr>
210 {/if}
211 {if $show_task}
212               <tr><td><b>{$i18n.label.task}</b></td></tr>
213               <tr><td>{$forms.reportForm.task.control}</td></tr>
214 {/if}
215 {if $show_approved}
216               <tr><td><b>{$i18n.label.approved}</b></td></tr>
217               <tr><td>{$forms.reportForm.approved.control}</td></tr>
218 {/if}
219 {if $show_invoice_dropdown}
220               <tr><td><b>{$i18n.label.invoice}</b></td></tr>
221               <tr><td>{$forms.reportForm.invoice.control}</td></tr>
222 {/if}
223 {if $show_timesheet_dropdown}
224               <tr><td><b>{$i18n.label.timesheet}</b></td></tr>
225               <tr><td>{$forms.reportForm.timesheet.control}</td></tr>
226 {/if}
227             </table>
228           </td>
229         </tr>
230 {if $show_users}
231         <tr>
232           <td colspan="3"><b>{$i18n.label.users}</b></td>
233         </tr>
234         <tr>
235           <td colspan="3">{$forms.reportForm.users.control}</td>
236         </tr>
237 {/if}
238         <tr>
239           <td><b>{$i18n.form.reports.select_period}</b></td>
240           <td>&nbsp;</td>
241           <td><b>{$i18n.form.reports.set_period}</b></td>
242         </tr>
243         <tr valign="top">
244           <td>{$forms.reportForm.period.control}</td>
245           <td align="right">{$i18n.label.start_date}:</td>
246           <td>{$forms.reportForm.start_date.control}</td>
247         </tr>
248         <tr>
249           <td></td>
250           <td align="right">{$i18n.label.end_date}:</td>
251           <td>{$forms.reportForm.end_date.control}</td>
252         </tr>
253         <tr><td colspan="3"><b>{$i18n.form.reports.show_fields}</b></td></tr>
254         <tr>
255           <td colspan="3">
256             <table border="0" width="100%">
257               <tr>
258                 <td width="25%" valign="top">
259                   <table border="0" cellpadding="3">
260 {if $show_client}
261                     <tr><td><label>{$forms.reportForm.chclient.control}&nbsp;{$i18n.label.client}</label></td></tr>
262 {/if}
263 {if $show_project}
264                     <tr><td><label>{$forms.reportForm.chproject.control}&nbsp;{$i18n.label.project}</label></td></tr>
265 {/if}
266 {if $show_timesheet_checkbox}
267                     <tr><td><label>{$forms.reportForm.chtimesheet.control}&nbsp;{$i18n.label.timesheet}</label></td></tr>
268 {/if}
269 {if $show_cf_1_checkbox}
270                     <tr><td><label>{$forms.reportForm.chcf_1.control}&nbsp;{$custom_fields->fields[0]['label']|escape}</label></td></tr>
271 {/if}
272                   </table>
273                 </td>
274                 <td width="25%" valign="top">
275                   <table border="0" cellpadding="3">
276 {if $show_start}
277                     <tr><td><label>{$forms.reportForm.chstart.control}&nbsp;{$i18n.label.start}</label></td></tr>
278 {/if}
279 {if $show_task}
280                     <tr><td><label>{$forms.reportForm.chtask.control}&nbsp;{$i18n.label.task}</label></td></tr>
281 {/if}
282 {if $show_ip}
283                     <tr><td><label>{$forms.reportForm.chip.control}&nbsp;{$i18n.label.ip}</label></td></tr>
284 {/if}
285 {if $show_work_units}
286                     <tr><td><label>{$forms.reportForm.chunits.control}&nbsp;{$i18n.label.work_units}</label></td></tr>
287 {/if}
288                   </table>
289                 </td>
290                 <td width="25%" valign="top">
291                   <table border="0" cellpadding="3">
292 {if $show_finish}
293                     <tr><td><label>{$forms.reportForm.chfinish.control}&nbsp;{$i18n.label.finish}</label></td></tr>
294 {/if}
295                     <tr><td><label>{$forms.reportForm.chnote.control}&nbsp;{$i18n.label.note}</label></td></tr>
296 {if $show_approved}
297                     <tr><td><label>{$forms.reportForm.chapproved.control}&nbsp;{$i18n.label.approved}</label></td></tr>
298 {/if}
299 {if $show_invoice_checkbox}
300                     <tr><td><label>{$forms.reportForm.chinvoice.control}&nbsp;{$i18n.label.invoice}</label></td></tr>
301 {/if}
302                   </table>
303                 </td>
304                 <td width="25%" valign="top">
305                   <table border="0" cellpadding="3">
306                     <tr><td><label>{$forms.reportForm.chduration.control}&nbsp;{$i18n.label.duration}</label></td></tr>
307                     <tr><td><label>{$forms.reportForm.chcost.control}&nbsp;{$i18n.label.cost}</label></td></tr>
308 {if $show_paid_status}
309                     <tr><td><label>{$forms.reportForm.chpaid.control}&nbsp;{$i18n.label.paid}</label></td></tr>
310 {/if}
311                   </table>
312                 </td>
313               </tr>
314             </table>
315           </td>
316         </tr>
317
318         <tr><td><b>{$i18n.form.reports.group_by}</b></td></tr>
319         <tr valign="top">
320           <td>{$forms.reportForm.group_by1.control}</td>
321           <td>{$forms.reportForm.group_by2.control}</td>
322           <td>{$forms.reportForm.group_by3.control}</td>
323         </tr>
324         <tr>
325             <td><span id="totals_only_label"><label>{$forms.reportForm.chtotalsonly.control} {$i18n.label.totals_only}</label></span></td>
326         </tr>
327       </table>
328
329 <div style="padding: 10 0 10 0;">
330   <table border="0" class="divider">
331     <tr>
332       <td align="center">
333         <table cellspacing="1" cellpadding="3" border="0">
334           <tr>
335             <td>{$i18n.form.reports.save_as_favorite}:</td><td>{$forms.reportForm.new_fav_report.control}</td>
336             <td>{$forms.reportForm.btn_save.control}</td>
337           </tr>
338         </table>
339       </td>
340     </tr>
341   </table>
342 </div>
343
344       <table border="0" cellpadding="3" width="100%">
345         <tr><td colspan="3" height="50" align="center">{$forms.reportForm.btn_generate.control}</td></tr>
346       </table>
347     </td>
348   </tr>
349 </table>
350 {$forms.reportForm.close}