2 // We need a few arrays to populate project and task dropdowns.
3 // When client selection changes, the project dropdown must be re-populated with only relevant projects.
4 // When project selection changes, the task dropdown must be repopulated similarly.
6 // project_ids[143] = "325,370,390,400"; // Comma-separated list of project ids for client.
7 // project_names[325] = "Time Tracker"; // Project name.
8 // task_ids[325] = "100,101,302,303,304"; // Comma-separated list ot task ids for project.
9 // task_names[100] = "Coding"; // Task name.
11 //Prepare an array of projects ids for clients.
12 project_ids = new Array();
13 {foreach $client_list as $client}
14 project_ids[{$client.id}] = "{$client.projects}";
16 // Prepare an array of project names.
17 project_names = new Array();
18 {foreach $project_list as $project}
19 project_names[{$project.id}] = "{$project.name|escape:'javascript'}";
21 // We'll use this array to populate project dropdown when client is not selected.
23 projects = new Array();
24 {foreach $project_list as $project}
25 projects[idx] = new Array("{$project.id}", "{$project.name|escape:'javascript'}");
29 // Prepare an array of task ids for projects.
30 task_ids = new Array();
31 {foreach $project_list as $project}
32 task_ids[{$project.id}] = "{$project.tasks}";
34 // Prepare an array of task names.
35 task_names = new Array();
36 {foreach $task_list as $task}
37 task_names[{$task.id}] = "{$task.name|escape:'javascript'}";
40 // Mandatory top options for project and task dropdowns.
41 empty_label_project = '{$i18n.dropdown.select|escape:'javascript'}';
42 empty_label_task = '{$i18n.dropdown.select|escape:'javascript'}';
44 // The fillDropdowns function populates the "project" and "task" dropdown controls
45 // with relevant values.
46 function fillDropdowns() {
47 if(document.body.contains(document.timerRecordForm.client))
48 fillProjectDropdown(document.timerRecordForm.client.value);
50 fillTaskDropdown(document.timerRecordForm.project.value);
53 // The fillProjectDropdown function populates the project combo box with
54 // projects associated with a selected client (client id is passed here as id).
55 function fillProjectDropdown(id) {
56 var str_ids = project_ids[id];
58 var dropdown = document.getElementById("project");
59 // Determine previously selected item.
60 var selected_item = dropdown.options[dropdown.selectedIndex].value;
62 // Remove existing content.
64 var project_reset = true;
65 // Add mandatory top option.
66 dropdown.options[0] = new Option(empty_label_project, '', true);
68 // Populate project dropdown.
70 // If we are here, client is not selected.
71 var len = projects.length;
72 for (var i = 0; i < len; i++) {
73 dropdown.options[i+1] = new Option(projects[i][1], projects[i][0]);
74 if (dropdown.options[i+1].value == selected_item) {
75 dropdown.options[i+1].selected = true;
76 project_reset = false;
80 var ids = new Array();
81 ids = str_ids.split(",");
84 for (var i = 0; i < len; i++) {
86 dropdown.options[i+1] = new Option(project_names[p_id], p_id);
87 if (dropdown.options[i+1].value == selected_item) {
88 dropdown.options[i+1].selected = true;
89 project_reset = false;
94 // If project selection was reset - clear the tasks dropdown.
96 dropdown = document.getElementById("task");
98 dropdown.options[0] = new Option(empty_label_task, '', true);
102 // The fillTaskDropdown function populates the task combo box with
103 // tasks associated with a selected project (project id is passed here as id).
104 function fillTaskDropdown(id) {
105 var str_ids = task_ids[id];
107 var dropdown = document.getElementById("task");
108 if (dropdown == null) return; // Nothing to do.
110 // Determine previously selected item.
111 var selected_item = dropdown.options[dropdown.selectedIndex].value;
113 // Remove existing content.
115 // Add mandatory top option.
116 dropdown.options[0] = new Option(empty_label_task, '', true);
118 // Populate the dropdown from the task_names array.
120 var ids = new Array();
121 ids = str_ids.split(",");
122 var len = ids.length;
125 for (var i = 0; i < len; i++) {
127 if (task_names[t_id]) {
128 dropdown.options[idx] = new Option(task_names[t_id], t_id);
133 // If a previously selected item is still in dropdown - select it.
134 if (dropdown.options.length > 0) {
135 for (var i = 0; i < dropdown.options.length; i++) {
136 if (dropdown.options[i].value == selected_item) {
137 dropdown.options[i].selected = true;
144 function get_date() {
145 var date = new Date();
146 return date.strftime("%Y-%m-%d");
149 function get_time() {
150 var date = new Date();
151 return date.strftime("%H:%M");
155 <p><span id="hour">00</span><span id="separator">:</span><span id="min">00</span>
160 var startDate = null;
163 var separatorVisible = true;
165 function toggleSeparator() {
166 document.getElementById('separator').style.visibility = separatorVisible ? 'hidden' : 'visible';
167 separatorVisible = !separatorVisible;
170 function updateTimer() {
171 if (startDate == null) startDate = new Date();
172 endDate = new Date();
173 delta = new Date(endDate - startDate);
175 var hours = delta.getUTCHours();
176 if (hours < 10) hours = '0'+hours;
177 document.getElementById('hour').innerHTML = hours;
179 var minutes = delta.getUTCMinutes();
180 if (minutes < 10) minutes = '0'+minutes;
181 document.getElementById('min').innerHTML = minutes;
183 // Toggle visibility of separator for 100 ms.
185 setTimeout('toggleSeparator()', 100);
188 function startTimer() {
192 timerID = setInterval('updateTimer()', 1000);
195 function stopTimer() {
196 clearInterval(timerID);
203 startDate = new Date();
204 startDate.setHours({substr($uncompleted['start'], 0, 2)});
205 startDate.setMinutes({substr($uncompleted['start'], 3, 2)});
206 startDate.setSeconds(0);
212 {$forms.timerRecordForm.open}
213 <table cellspacing="4" cellpadding="7" border="0">
216 <table width = "100%">
220 {if $user->isPluginEnabled('cl')}
221 <tr><td>{$i18n.label.client}:</td></tr>
222 <tr><td>{$forms.timerRecordForm.client.control}</td></tr>
224 {if $user->isPluginEnabled('iv')}
225 <tr><td><label>{$forms.timerRecordForm.billable.control}{$i18n.form.time.billable}</label></td></tr>
227 {if ($custom_fields && $custom_fields->fields[0])}
228 <tr><td>{$custom_fields->fields[0]['label']|escape:'html'}:</td></tr>
229 <tr><td>{$forms.timerRecordForm.cf_1.control}</td></tr>
231 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
232 <tr><td>{$i18n.label.project}:</td></tr>
233 <tr><td>{$forms.timerRecordForm.project.control}</td></tr>
235 {if ($smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
236 <tr><td>{$i18n.label.task}:</td></tr>
237 <tr><td>{$forms.timerRecordForm.task.control}</td></tr>
243 <td colspan="2" height="50" align="center">{$forms.timerRecordForm.btn_start.control} {$forms.timerRecordForm.btn_stop.control}</td>
249 {$forms.timerRecordForm.close}
251 <table cellspacing="3" cellpadding="0" border="0" width="100%">
257 <td align='right'>{$i18n.label.day_total}:</td>
258 <td>{$day_total}</td>
261 <td align='right'>{$i18n.label.week_total}:</td>
262 <td>{$week_total}</td>