Some style fixes to keep things consistent after recent pull request integration.
[timetracker.git] / WEB-INF / templates / expenses.tpl
1 <script>
2 // We need a few arrays to populate project dropdown.
3 // When client selection changes, the project dropdown must be re-populated with only relevant projects.
4 // Format:
5 // project_ids[143] = "325,370,390,400";  // Comma-separated list of project ids for client.
6 // project_names[325] = "Time Tracker";   // Project name.
7
8 // Prepare an array of project ids for clients.
9 var project_ids = new Array();
10 {foreach $client_list as $client}
11   project_ids[{$client.id}] = "{$client.projects}";
12 {/foreach}
13 // Prepare an array of project names.
14 var project_names = new Array();
15 {foreach $project_list as $project}
16   project_names[{$project.id}] = "{$project.name|escape:'javascript'}";
17 {/foreach}
18 // We'll use this array to populate project dropdown when client is not selected.
19 var idx = 0;
20 var projects = new Array();
21 {foreach $project_list as $project}
22   projects[idx] = new Array("{$project.id}", "{$project.name|escape:'javascript'}");
23   idx++;
24 {/foreach}
25
26 // Mandatory top option for project dropdown.
27 var empty_label_project = "{$i18n.dropdown.select|escape:'javascript'}";
28
29 // Prepare an array of predefined expenses.
30 idx = 0;
31 var defined_expenses = new Array();
32 {foreach $predefined_expenses as $predefined_expense}
33   defined_expenses[idx] = new Array("{$predefined_expense.id}", "{$predefined_expense.name|escape:'javascript'}", "{$predefined_expense.cost}");
34   idx++;
35 {/foreach}
36
37 // The fillProjectDropdown function populates the project combo box with
38 // projects associated with a selected client (client id is passed here as id).
39 function fillProjectDropdown(id) {
40   var str_ids = project_ids[id];
41   var dropdown = document.getElementById("project");
42   // Determine previously selected item.
43   var selected_item = dropdown.options[dropdown.selectedIndex].value;
44
45   // Remove existing content.
46   dropdown.length = 0;
47   // Add mandatory top option.
48   dropdown.options[0] = new Option(empty_label_project, '', true);
49
50   // Populate project dropdown.
51   if (!id) {
52     // If we are here, client is not selected.
53     var len = projects.length;
54     for (var i = 0; i < len; i++) {
55       dropdown.options[i+1] = new Option(projects[i][1], projects[i][0]);
56       if (dropdown.options[i+1].value == selected_item)
57         dropdown.options[i+1].selected = true;
58     }
59   } else if (str_ids) {
60     var ids = new Array();
61     ids = str_ids.split(",");
62     var len = ids.length;
63
64     for (var i = 0; i < len; i++) {
65       var p_id = ids[i];
66       dropdown.options[i+1] = new Option(project_names[p_id], p_id);
67       if (dropdown.options[i+1].value == selected_item)
68         dropdown.options[i+1].selected = true;
69     }
70   }
71 }
72
73 function get_date() {
74   var date = new Date();
75   return date.strftime("%Y-%m-%d");
76 }
77
78 // The recalculateCost function recalculates cost based on the current selection
79 // of predefined expense and quantity and also changes the comment accordingly.
80 function recalculateCost() {
81   var quantity_control = document.getElementById("quantity");
82   // Set quantity to 1 if it is not set already.
83   if (!quantity_control.value) {
84      quantity_control.value = "1";
85   }
86
87   var comment_control = document.getElementById("item_name");
88   var cost_control = document.getElementById("cost");
89
90   // Calculate cost.
91   var dropdown = document.getElementById("predefined_expense");
92   if (dropdown.selectedIndex == 0) {
93     quantity_control.value = "";
94     comment_control.value = "";
95     cost_control.value = "";
96   } else {
97     comment_control.value = defined_expenses[dropdown.selectedIndex - 1][1] + " - " + quantity_control.value;
98     var quantity = quantity_control.value;
99     if (isNaN(quantity))
100       cost_control.value = "";
101     else
102       cost_control.value = (quantity_control.value * defined_expenses[dropdown.selectedIndex - 1][2]).toFixed(2);
103   }
104 }
105 </script>
106
107 {$forms.expensesForm.open}
108 <table cellspacing="4" cellpadding="0" border="0">
109   <tr>
110     <td valign="top">
111       <table>
112 {if $on_behalf_control}
113         <tr>
114           <td align="right">{$i18n.label.user}:</td>
115           <td>{$forms.expensesForm.onBehalfUser.control}</td>
116         </tr>
117 {/if}
118 {if $user->isPluginEnabled('cl')}
119         <tr>
120           <td align="right">{$i18n.label.client}{if $user->isPluginEnabled('cm')} (*){/if}:</td>
121           <td>{$forms.expensesForm.client.control}</td>
122         </tr>
123 {/if}
124 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
125         <tr>
126           <td align="right">{$i18n.label.project} (*):</td>
127           <td>{$forms.expensesForm.project.control}</td>
128         </tr>
129 {/if}
130 {if $predefined_expenses}
131
132         <tr>
133           <td align="right">{$i18n.label.expense}:</td>
134           <td>{$forms.expensesForm.predefined_expense.control}</td>
135         </tr>
136         <tr>
137           <td align="right">{$i18n.label.quantity}:</td>
138           <td>{$forms.expensesForm.quantity.control}</td>
139         </tr>
140 {/if}
141         <tr>
142           <td align="right">{$i18n.label.comment} (*):</td>
143           <td>{$forms.expensesForm.item_name.control}</td>
144         </tr>
145         <tr>
146           <td align="right">{$i18n.label.cost} (*):</td>
147           <td>{$forms.expensesForm.cost.control} {$user->currency|escape}</td>
148         </tr>
149       </table>
150     </td>
151     <td valign="top">
152       <table>
153         <tr><td>{$forms.expensesForm.date.control}</td></tr>
154       </table>
155     </td>
156   </tr>
157 </table>
158
159 <table>
160   <tr>
161     <td align="center" colspan="2">{$forms.expensesForm.btn_submit.control}</td>
162   </tr>
163 </table>
164
165 <table width="720">
166 <tr>
167   <td valign="top">
168 {if $expense_items}
169       <table border="0" cellpadding="3" cellspacing="1" width="100%">
170       <tr>
171   {if $user->isPluginEnabled('cl')}
172         <td width="20%" class="tableHeader">{$i18n.label.client}</td>
173   {/if}
174   {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
175         <td class="tableHeader">{$i18n.label.project}</td>
176   {/if}
177         <td class="tableHeader">{$i18n.label.item}</td>
178         <td width="5%" class="tableHeaderCentered">{$i18n.label.cost}</td>
179         <td width="5%" class="tableHeader">{$i18n.label.edit}</td>
180       </tr>
181   {foreach $expense_items as $item}
182       <tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
183     {if $user->isPluginEnabled('cl')}
184         <td valign="top">{$item.client|escape}</td>
185     {/if}
186     {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
187         <td valign="top">{$item.project|escape}</td>
188     {/if}
189         <td valign="top">{$item.item|escape}</td>
190         <td valign="top" align="right">{$item.cost}</td>
191         <td valign="top" align="center">{if $item.invoice_id}&nbsp;{else}<a href='expense_edit.php?id={$item.id}'>{$i18n.label.edit}</a>{/if}</td>
192       </tr>
193   {/foreach}
194     </table>
195     <table border="0" cellpadding="3" cellspacing="1" width="100%">
196       <tr>
197         <td nowrap align="right">{$i18n.label.day_total}: {$user->currency|escape} {$day_total}</td>
198       </tr>
199     </table>
200 {/if}
201   </td>
202 </tr>
203 </table>
204 {$forms.expensesForm.close}