1 --- eventum-1.7.1/js/global.js 2006-05-09 00:45:20.430458749 +0300
2 +++ /home/glen/global.js 2006-05-09 00:46:12.751624134 +0300
7 -function updateTimeFields(form_name, year_field, month_field, day_field, hour_field, minute_field)
8 +function updateTimeFields(form_name, year_field, month_field, day_field, hour_field, minute_field, date)
10 var f = getForm(form_name);
11 - var current_date = new Date();
12 - selectOption(f, month_field, padDateValue(current_date.getMonth()+1));
13 - selectOption(f, day_field, padDateValue(current_date.getDate()));
14 - selectOption(f, year_field, current_date.getFullYear());
15 - selectOption(f, hour_field, padDateValue(current_date.getHours()));
16 - selectOption(f, minute_field, padDateValue(current_date.getMinutes()));
17 + if (typeof date == 'undefined') {
20 + selectOption(f, month_field, padDateValue(date.getMonth()+1));
21 + selectOption(f, day_field, padDateValue(date.getDate()));
22 + selectOption(f, year_field, date.getFullYear());
23 + selectOption(f, hour_field, padDateValue(date.getHours()));
24 + // minutes need special case due the 5 minute granularity
25 + var minutes = Math.floor(date.getMinutes() / 5) * 5;
26 + selectOption(f, minute_field, padDateValue(minutes));
29 function padDateValue(str)
30 --- eventum-20060717/templates/add_time_tracking.tpl.html 2006-07-18 01:37:24.232815764 +0300
31 +++ eventum-20060725/templates/add_time_tracking.tpl.html 2006-08-02 10:54:00.044804730 +0300
34 <script language="JavaScript">
38 + * Make javascript Date() object from datetime form selection.
40 + * @param Object f Form object.
41 + * @param String name Form element prefix for date.
43 +function makeDate(f, name) {
45 + d.setFullYear(f.elements[name + '[Year]'].value);
46 + d.setMonth(f.elements[name + '[Month]'].value - 1);
47 + d.setDate(f.elements[name + '[Day]'].value);
48 + d.setHours(f.elements[name + '[Hour]'].value);
49 + d.setMinutes(f.elements[name + '[Minute]'].value);
54 function validateTimeForm(f)
56 if (isWhitespace(f.summary.value)) {
58 alert('{/literal}{t}Please select a valid date of work.{/t}{literal}');
63 + var now = new Date();
64 + var d1 = makeDate(f, 'date');
66 + alert('{/literal}{t}Start time in the future.{/t}{literal}');
69 + var d2 = makeDate(f, 'date2');
71 + alert('{/literal}{t}End time in the future.{/t}{literal}');
78 + * @param Object f Form object
79 + * @param Integer type The type of update occouring.
80 + * 0 = Duration was updated.
81 + * 1 = Start time was updated.
82 + * 2 = End time was updated.
83 + * 11 = Start time refresh icon was clicked.
84 + * 12 = End time refresh icon was clicked.
86 +function calcDateDiff(f, type)
88 + var duration = f.elements['time_spent'].value;
89 + // enforce 5 minute granuality.
90 + duration = Math.floor(duration / 5) * 5;
92 + var d1 = makeDate(f, 'date');
93 + var d2 = makeDate(f, 'date2');
95 + var minute = 1000 * 60;
97 + - if time is adjusted, duration is calculated,
98 + - if duration is adjusted, the end time is adjusted,
99 + - clicking refresh icon on either icons will make that time current date
100 + and recalculate duration.
103 + if (type == 0) { // duration
104 + d1.setTime(d2.getTime() - duration * minute);
105 + } else if (type == 1) { // start time
106 + duration = (d2.getTime() - d1.getTime()) / minute;
107 + } else if (type == 2) { // end time
108 + duration = (d2.getTime() - d1.getTime()) / minute;
109 + } else if (type == 11) { // refresh start time
110 + d2.setTime(d1.getTime() + duration * minute);
111 + } else if (type == 12) { // refresh end time
112 + d1.setTime(d2.getTime() - duration * minute);
115 + /* refill form after calculation */
116 + updateTimeFields(f.name, 'date[Year]', 'date[Month]', 'date[Day]', 'date[Hour]', 'date[Minute]', d1)
117 + updateTimeFields(f.name, 'date2[Year]', 'date2[Month]', 'date2[Day]', 'date2[Hour]', 'date2[Minute]', d2)
119 + duration = parseInt(duration);
120 + if (duration > 0) {
121 + f.elements['time_spent'].value = duration;
128 {include file="error_icon.tpl.html" field="category"}
133 <td bgcolor="{$internal_color}" class="default_white" width="190" nowrap><b>{t}Time Spent{/t}:</b></td>
134 - <td bgcolor="{$light_color}" width="100%"><input class="default" type="text" size="5" name="time_spent" class="default"> <span class="default">({t}in minutes{/t})</span>{include file="error_icon.tpl.html" field="time_spent"}</td>
135 + <td bgcolor="{$light_color}" width="100%"><input class="default" type="text" size="5" name="time_spent" class="default" onChange="calcDateDiff(this.form, 0)"> <span class="default">({t}in minutes{/t})</span>{include file="error_icon.tpl.html" field="time_spent"}</td>
139 + <td bgcolor="{$internal_color}" class="default_white" width="190" nowrap><b>{t}Work started{/t}:</b></td>
140 + <td bgcolor="{$light_color}" width="100%">
141 + {html_select_date start_year='-1' day_value_format='%02d' field_array='date' prefix='' all_extra=' class="default" onChange="calcDateDiff(this.form, 1)"'}
142 + {html_select_time minute_interval=5 field_array='date' prefix='' all_extra=' class="default" onChange="calcDateDiff(this.form, 1)"' display_seconds=false}
143 + <a href="javascript:void(null);" onClick="javascript:updateTimeFields('add_time_form', 'date[Year]', 'date[Month]', 'date[Day]', 'date[Hour]', 'date[Minute]');calcDateDiff(getForm('add_time_form'), 11)"><img src="images/icons/refresh.gif" border="0"></a>
148 - <td bgcolor="{$internal_color}" class="default_white" width="190" nowrap><b>{t}Date of Work{/t}:</b></td>
149 + <td bgcolor="{$internal_color}" class="default_white" width="190" nowrap><b>Work ended:</b></td>
150 <td bgcolor="{$light_color}" width="100%">
151 - {html_select_date start_year='-1' day_value_format='%02d' field_array='date' prefix='' all_extra=' class="default"'}
152 - {html_select_time minute_interval=5 field_array='date' prefix='' all_extra=' class="default"' display_seconds=false}
153 - <a href="javascript:void(null);" onClick="javascript:updateTimeFields('add_time_form', 'date[Year]', 'date[Month]', 'date[Day]', 'date[Hour]', 'date[Minute]');"><img src="images/icons/refresh.gif" border="0"></a>
154 + {html_select_date start_year='-1' day_value_format='%02d' field_array='date2' prefix='' all_extra=' class="default" onChange="calcDateDiff(this.form, 2)"'}
155 + {html_select_time minute_interval=5 field_array='date2' prefix='' all_extra=' class="default" onChange="calcDateDiff(this.form, 2)"' display_seconds=false}
156 + <a href="javascript:void(null);" onClick="javascript:updateTimeFields('add_time_form', 'date2[Year]', 'date2[Month]', 'date2[Day]', 'date2[Hour]', 'date2[Minute]'); calcDateDiff(getForm('add_time_form'), 12)"><img src="images/icons/refresh.gif" border="0"></a>
161 <td colspan="2" bgcolor="{$internal_color}" align="center" width="100%" nowrap>
162 <input type="submit" value="Add Time Entry" class="button">
164 <script language="JavaScript">
166 updateTimeFields('add_time_form', 'date[Year]', 'date[Month]', 'date[Day]', 'date[Hour]', 'date[Minute]');
167 +updateTimeFields('add_time_form', 'date2[Year]', 'date2[Month]', 'date2[Day]', 'date2[Hour]', 'date2[Minute]');
170 {include file="app_info.tpl.html"}