~replaceafill/ubuntu/trusty/schooltool/2.8_custom-css

« back to all changes in this revision

Viewing changes to src/schooltool/app/browser/resources/calwidget/calendar.js

  • Committer: Gediminas Paulauskas
  • Date: 2014-04-11 22:10:31 UTC
  • mfrom: (1.1.32)
  • Revision ID: menesis@pov.lt-20140411221031-8nkk5s1ey58z7cor
Tags: 1:2.6.3-0ubuntu1
* New upstream release.
  - Celery 3 support (LP: #1276384)
  - Switch to CKEditor (LP: #485898)
  - Fixed exception dates format in calendar widget of recurring events (LP: #372889)
  - Fixed export of deleted timetables (LP: #1281335)
  - Fixed term/section navigation in a different school year (LP: #1281050)
* debian/copyright: update, remove calwidget

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
* Calendar Widget Version 1.0
3
 
* Copyright (c) 2004, Tribador Mediaworks,
4
 
*
5
 
* Brian Munroe <bmunroe@tribador.net>
6
 
*
7
 
* calendar.js - Calendar Widget JavaScript Library
8
 
*
9
 
* Permission to use, copy, modify, distribute, and sell this software and its
10
 
* documentation for any purpose is hereby granted without fee, provided that
11
 
* the above copyright notice appear in all copies and that both that
12
 
* copyright notice and this permission notice appear in supporting
13
 
* documentation.  No representations are made about the suitability of this
14
 
* software for any purpose.  It is provided "as is" without express or
15
 
* implied warranty.
16
 
*/
17
 
 
18
 
function pageOffsetLeft(elem) {
19
 
 
20
 
    if (elem.offsetParent) {
21
 
        for(var offX = 0; elem.offsetParent; elem = elem.offsetParent){
22
 
            offX += elem.offsetLeft;
23
 
        }
24
 
 
25
 
        return offX;
26
 
    } else {
27
 
        return elem.x;
28
 
    }
29
 
}
30
 
 
31
 
function pageOffsetTop(elem) {
32
 
 
33
 
    if (elem.offsetParent) {
34
 
        for(var offY = 0; elem.offsetParent; elem = elem.offsetParent){
35
 
            offY += elem.offsetTop;
36
 
        }
37
 
        return offY;
38
 
    } else {
39
 
        return elem.y;
40
 
    }
41
 
}
42
 
 
43
 
function _isLeapYear(year) {
44
 
    return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
45
 
}
46
 
 
47
 
function setCalendar(idtag,yyyy,mm,dd) {
48
 
    y = document.getElementById(idtag);
49
 
    // Zero pad months and days
50
 
    if (mm < 10) {
51
 
        mm = "0" + mm;
52
 
    }
53
 
    if (dd < 10) {
54
 
        dd = "0" + dd;
55
 
    }
56
 
 
57
 
    // replace values in text fields, append them in textarea fields.
58
 
    if (y.type == 'text' || y.value == ""){
59
 
      y.value = yyyy + "-" + mm + "-" + dd;
60
 
    } else if (y.type == 'textarea'){
61
 
      y.value += "\n" + yyyy + "-" + mm + "-" + dd;
62
 
    }
63
 
    y = document.getElementById(idtag + "Div");
64
 
    y.style.display = "none";
65
 
}
66
 
 
67
 
function closeCal(idtag) {
68
 
    t = document.getElementById(idtag + "Div");
69
 
    t.style.display = "none";
70
 
}
71
 
 
72
 
function closeCalNoDate(idtag) {
73
 
    y = document.getElementById(idtag);
74
 
    y.value = "";
75
 
    t = document.getElementById(idtag + "Div");
76
 
    t.style.display = "none";
77
 
}
78
 
 
79
 
function closeCalSetToday(idtag) {
80
 
    var doDate = new Date();
81
 
    var mm = doDate.getMonth()+1;
82
 
    var dd = doDate.getDate();
83
 
    var yyyy = doDate.getYear();
84
 
 
85
 
    if (yyyy < 1000) {
86
 
        yyyy = yyyy + 1900;
87
 
    }
88
 
 
89
 
    setCalendar(idtag,yyyy,mm,dd);
90
 
}
91
 
 
92
 
function redrawCalendar(idtag) {
93
 
 
94
 
    var x = document.getElementById(idtag + "SelectMonth");
95
 
    for (i = 0; i < x.options.length;i++){
96
 
        if (x.options[i].selected) {
97
 
            var mm = x.options[i].value;
98
 
        }
99
 
    }
100
 
 
101
 
    var y = document.getElementById(idtag + "SelectYear");
102
 
    for (i = 0; i < y.options.length; i++) {
103
 
        if (y.options[i].selected) {
104
 
            var yyyy = y.options[i].value;
105
 
        }
106
 
    }
107
 
 
108
 
    // Who f-ing knows why you need this?
109
 
    // If you don't cast it to an int,
110
 
    // the browser goes into some kind of
111
 
    // infinite loop, atleast in IE6.0/Win32
112
 
    //
113
 
    mm = mm*1;
114
 
    yyyy = yyyy*1;
115
 
 
116
 
    drawCalendar(idtag,yyyy,mm);
117
 
}
118
 
 
119
 
function _buildCalendarControls() {
120
 
 
121
 
    var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
122
 
    var nw = new Date();
123
 
 
124
 
    (arguments[0] ? idtag = arguments[0] : idtag = "");
125
 
    (arguments[1] ? yyyy = arguments[1] : yyyy = nw.getYear());
126
 
    (arguments[2] ? mm = arguments[2] : mm = nw.getMonth());
127
 
    (arguments[3] ? dd = arguments[3] : dd = nw.getDay());
128
 
 
129
 
    // Mozilla hack,  I am sure there is a more elegent way, but I did it
130
 
    // on a Friday to get a release out the door...
131
 
    //
132
 
    if (yyyy < 1000) {
133
 
        yyyy = yyyy + 1900;
134
 
    }
135
 
 
136
 
    var monthArray = '<select class ="DateControls" id="' + idtag + 'SelectMonth" onChange="redrawCalendar(\'' + idtag + '\');">';
137
 
    // First build the month selection box
138
 
    for (i = 0; i < months.length; i++){
139
 
        if (i == mm-1) {
140
 
            monthArray = monthArray + '<option value="' + eval(i + 1) + '" selected="selected">' + months[i] + '</option>';
141
 
        } else {
142
 
            monthArray = monthArray + '<option value="' + eval(i + 1) + '">' + months[i] + '</option>';
143
 
        }
144
 
    }
145
 
    monthArray = monthArray + "</select>";
146
 
 
147
 
    var yearArray = '<select class ="DateControls" id="' + idtag + 'SelectYear" onChange="redrawCalendar(\'' + idtag + '\');">';
148
 
    for (i=yyyy-4;i<= yyyy+4;i++){
149
 
        if (i == yyyy) {
150
 
            yearArray = yearArray + '<option value="' + i + '" selected="selected">' + i + '</option>';
151
 
        } else {
152
 
            yearArray = yearArray + '<option value="' + i + '">' + i + '</option>';
153
 
        }
154
 
    }
155
 
    yearArray = yearArray + "</select>";
156
 
    return(monthArray + " " + yearArray);
157
 
}
158
 
 
159
 
function clickWidgetIcon(idtag) {
160
 
    (arguments[0] ? idtag = arguments[0] : idtag = "");
161
 
 
162
 
    t = document.getElementById(idtag + "Div");
163
 
    if (t.style.display == "none") {
164
 
        drawCalendar(idtag);
165
 
    } else {
166
 
        closeCal(idtag);
167
 
    }
168
 
}
169
 
 
170
 
function drawCalendar() {
171
 
 
172
 
    (arguments[0] ? idtag = arguments[0] : idtag = "");
173
 
    (arguments[1] ? yyyy = arguments[1] : yyyy = void(0));
174
 
    (arguments[2] ? mm = arguments[2] : mm = void(0));
175
 
    (arguments[3] ? dd = arguments[3] : dd = void(0));
176
 
 
177
 
    if (!yyyy && !mm) {
178
 
        x = document.getElementById(idtag);
179
 
        if (x.value != "") {
180
 
            var wholeValue = x.value;
181
 
            var dateparts = wholeValue.split("-");
182
 
            var yyyy = dateparts[0]*1;
183
 
            var mm = dateparts[1]*1;
184
 
            var dd = dateparts[2]*1;
185
 
        } else {
186
 
            var doDate = new Date();
187
 
            var mm = doDate.getMonth()+1;
188
 
            var dd = doDate.getDate();
189
 
            var yyyy = doDate.getYear();
190
 
        }
191
 
    }
192
 
 
193
 
    // Mozilla hack,  I am sure there is a more elegent way, but I did it
194
 
    // on a Friday to get a release out the door...
195
 
    if (yyyy < 1000) {
196
 
        yyyy = yyyy + 1900;
197
 
    }
198
 
 
199
 
    var newDate = new Date(yyyy,mm-1,1);
200
 
    var startDay = newDate.getDay();
201
 
    var dom = [31,28,31,30,31,30,31,31,30,31,30,31];
202
 
    var dateControls = '<tr><td class="DateControlFrame" colspan="7">' + _buildCalendarControls(idtag,yyyy,mm,dd) + '</td></tr>';
203
 
    var beginTable = '<table class="CalendarFrame">';
204
 
    var calHeader = '<tr><td class="CalHeader">Su</td><td class="CalHeader">Mo</td><td class="CalHeader">Tu</td><td class="CalHeader">We</td><td class="CalHeader">Th</td><td class="CalHeader">Fr</td><td class="CalHeader">Sa</td></tr>';
205
 
    var closeControls = '<tr><td class="CloseControls" colspan="7"> <a class="close" onclick="closeCal(\'' + idtag + '\');">Close</a>  &nbsp;&nbsp;&nbsp; <a class="cancel" onclick="closeCalNoDate(\'' + idtag + '\');">No Date</a> &nbsp;&nbsp;&nbsp; <a class="today" onclick="closeCalSetToday(\'' + idtag + '\');">Today</a></td></tr></table>';
206
 
    var curHTML = "";
207
 
    var curDay = 1;
208
 
    var endDay = 0;
209
 
    var rowElement = 0;
210
 
    var startFlag = 1;
211
 
    var endFlag = 0;
212
 
    var elementClick = "";
213
 
    var celldata = "";
214
 
 
215
 
    ((_isLeapYear(yyyy) && mm == 2) ? endDay = 29 : endDay = dom[mm-1]);
216
 
 
217
 
    // calculate the lead gap
218
 
    if (startDay != 0) {
219
 
        curHTML = "<tr>";
220
 
        for (i = 0; i < startDay; i++) {
221
 
            curHTML = curHTML + '<td class="EmptyCell">&nbsp;</td>';
222
 
            rowElement++;
223
 
        }
224
 
    }
225
 
 
226
 
    for (i=1;i<=endDay;i++){
227
 
        (dd == i ? celldata = "CurrentCellElement" : celldata = "CellElement");
228
 
 
229
 
        if (rowElement == 0) {
230
 
            curHTML = curHTML + '<tr>' + '<td class="' + celldata + '" onclick="setCalendar(\'' + idtag + '\','+ yyyy +',' + mm + ',' + i +');">' + i + '</td>';
231
 
            rowElement++;
232
 
            continue;
233
 
        }
234
 
 
235
 
        if (rowElement > 0 && rowElement < 6) {
236
 
            curHTML = curHTML + '<td class="' + celldata + '" onclick="setCalendar(\'' + idtag + '\','+ yyyy +',' + mm + ',' + i +');">' + i + '</td>';
237
 
            rowElement++;
238
 
            continue;
239
 
        }
240
 
 
241
 
        if (rowElement == 6) {
242
 
            curHTML = curHTML + '<td class="' + celldata + '" onclick="setCalendar(\'' + idtag + '\','+ yyyy +',' + mm + ',' + i +');">' + i + '</td></tr>';
243
 
            rowElement = 0;
244
 
            continue;
245
 
        }
246
 
    }
247
 
 
248
 
    // calculate the end gap
249
 
    if (rowElement != 0) {
250
 
        for (i = rowElement; i <= 6; i++){
251
 
            curHTML = curHTML + '<td class="EmptyCell">&nbsp;</td>';
252
 
        }
253
 
    }
254
 
 
255
 
    curHTML = curHTML + "</tr>";
256
 
    t = document.getElementById(idtag + "Div");
257
 
    dateField = document.getElementById(idtag);
258
 
    t.innerHTML = beginTable + dateControls + calHeader + curHTML + closeControls;
259
 
 
260
 
    // need to write some better browser detection/positioning code here Also,
261
 
    // there is a perceived stability issue where the calendar goes offscreen
262
 
    // when the widget is right justified..Need some edge detection
263
 
 
264
 
    var kitName = "applewebkit/";
265
 
    var tempStr = navigator.userAgent.toLowerCase();
266
 
    var pos = tempStr.indexOf(kitName);
267
 
    var isAppleWebkit = (pos != -1);
268
 
 
269
 
    t.style.left = pageOffsetLeft(dateField);
270
 
    t.style.top = pageOffsetTop(dateField);
271
 
    t.style.display = "";
272
 
}
273
 
 
274
 
function createCalendarWidget() {
275
 
    (arguments[0] ? idtag = arguments[0] : idtag = "");
276
 
    (arguments[1] ? isEditable = arguments[1] : isEditable = "EDIT");
277
 
    (arguments[2] ? hasIcon = arguments[2] : hasIcon = "NO_ICON");
278
 
    (arguments[3] ? iconPath = arguments[3] : hasIcon = "./OU812.gif");
279
 
 
280
 
    (isEditable == "NO_EDIT" ? readOnly = 'readonly="readonly"' : readOnly = '');
281
 
 
282
 
    if (hasIcon == "ICON") {
283
 
        clicking = '';
284
 
        icon = ' <img src="' + iconPath + '" class="CalIcon" id="' + idtag + 'Icon" onmousedown="clickWidgetIcon(\'' + idtag + '\');" />';
285
 
    } else {
286
 
        clicking = 'onclick="drawCalendar(\'' + idtag + '\')"';
287
 
        icon = '';
288
 
    }
289
 
 
290
 
    // Edited to match SchoolTool styling
291
 
    document.write('<input name="' + idtag + '" id="' + idtag + '" type="text" class="textType" size="20" value="" ' + readOnly + ' ' + clicking + ' />' +  icon + '<br /><div id="' + idtag + 'Div" style="background: #ffffff; position: absolute; display:none;"></div>');
292
 
}