]> git.pld-linux.org Git - packages/eventum.git/blob - eventum-timetracking-advanced-logic.patch
- outdated with 20070116.3201
[packages/eventum.git] / eventum-timetracking-advanced-logic.patch
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
3 @@ -143,15 +143,19 @@
4      popupWin.focus();
5  }
6  
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)
9  {
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') {
18 +               date = new Date();
19 +       }
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));
27  }
28  
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
32 @@ -28,6 +28,24 @@
33  {literal}
34  <script language="JavaScript">
35  <!--
36 +
37 +/**
38 + * Make javascript Date() object from datetime form selection.
39 + *
40 + * @param      Object  f               Form object.
41 + * @param      String  name    Form element prefix for date.
42 + */
43 +function makeDate(f, name) {
44 +       var d = new Date();
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);
50 +       d.setSeconds(0);
51 +       return d;
52 +}
53 +
54  function validateTimeForm(f)
55  {
56      if (isWhitespace(f.summary.value)) {
57 @@ -49,7 +67,68 @@
58          alert('{/literal}{t}Please select a valid date of work.{/t}{literal}');
59          return false;
60      }
61 -    return true;
62 +
63 +       var now = new Date();
64 +       var d1 = makeDate(f, 'date');
65 +       if (d1 > now) {
66 +               alert('{/literal}{t}Start time in the future.{/t}{literal}');
67 +               return false;
68 +       }
69 +       var d2 = makeDate(f, 'date2');
70 +       if (d2 > now) {
71 +               alert('{/literal}{t}End time in the future.{/t}{literal}');
72 +               return false;
73 +       }
74 +       return true;
75 +}
76 +
77 +/**
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.
85 + */
86 +function calcDateDiff(f, type)
87 +{
88 +       var duration = f.elements['time_spent'].value;
89 +       // enforce 5 minute granuality.
90 +       duration = Math.floor(duration / 5) * 5;
91 +
92 +       var d1 = makeDate(f, 'date');
93 +       var d2 = makeDate(f, 'date2');
94 +
95 +       var minute = 1000 * 60;
96 +       /*
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.
101 +       */
102 +
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);
113 +       }
114 +
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)
118 +
119 +       duration = parseInt(duration);
120 +       if (duration > 0) {
121 +               f.elements['time_spent'].value = duration;
122 +       }
123 +
124  }
125  //-->
126  </script>
127 @@ -82,18 +161,30 @@
128                    {include file="error_icon.tpl.html" field="category"}
129                  </td>
130                </tr>
131 +
132                <tr>
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>
136 +              </tr>
137 +
138 +              <tr>
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)"'}&nbsp;
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>
144 +                </td>
145                </tr>
146 +
147                <tr>
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"'}&nbsp;
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)"'}&nbsp;
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>
157                  </td>
158                </tr>
159 +
160                <tr>
161                  <td colspan="2" bgcolor="{$internal_color}" align="center" width="100%" nowrap>
162                    <input type="submit" value="Add Time Entry" class="button">
163 @@ -111,6 +202,7 @@
164  <script language="JavaScript">
165  <!--
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]');
168  //-->
169  </script>
170  {include file="app_info.tpl.html"}
This page took 0.086071 seconds and 3 git commands to generate.