author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 04 Jan 2011 14:41:10 +0100 | |
branch | stable |
changeset 6764 | b2c1b481f310 |
parent 5774 | 0d792bceb25d |
child 6880 | 4be32427b2b9 |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
1 |
/** |
0 | 2 |
* This file contains Calendar utilities |
3 |
* :organization: Logilab |
|
5767
1d811df051c2
[packaging] MANIFEST.in cleanups, update js/css copyright, remove no more used files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3096
diff
changeset
|
4 |
* :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
* :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
*/ |
|
7 |
||
8 |
// IMPORTANT NOTE: the variables DAYNAMES AND MONTHNAMES will be added |
|
9 |
// by cubicweb automatically |
|
10 |
// dynamically computed (and cached) |
|
11 |
var _CAL_HEADER = null; |
|
12 |
||
13 |
TODAY = new Date(); |
|
14 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
15 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
16 |
* .. class:: Calendar |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
17 |
* |
0 | 18 |
* Calendar (graphical) widget |
19 |
* public methods are : |
|
20 |
* __init__ : |
|
21 |
* @param containerId: the DOM node's ID where the calendar will be displayed |
|
22 |
* @param inputId: which input needs to be updated when a date is selected |
|
23 |
* @param year, @param month: year and month to be displayed |
|
24 |
* @param cssclass: CSS class of the calendar widget (default is commandCal) |
|
25 |
* |
|
26 |
* show() / hide(): |
|
27 |
* show or hide the calendar widget |
|
28 |
* |
|
29 |
* toggle(): |
|
30 |
* show (resp. hide) the calendar if it's hidden (resp. displayed) |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
31 |
* |
0 | 32 |
* displayNextMonth(): (resp. displayPreviousMonth()) |
33 |
* update the calendar to display next (resp. previous) month |
|
34 |
*/ |
|
35 |
Calendar = function(containerId, inputId, year, month, cssclass) { |
|
36 |
this.containerId = containerId; |
|
37 |
this.inputId = inputId; |
|
38 |
this.year = year; |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
39 |
this.month = month - 1; // Javascript's counter starts at 0 for january |
0 | 40 |
this.cssclass = cssclass || "popupCalendar"; |
41 |
this.visible = false; |
|
42 |
this.domtable = null; |
|
43 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
44 |
this.cellprops = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
45 |
'onclick': function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
46 |
dateSelected(this, containerId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
47 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
48 |
'onmouseover': function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
49 |
this.style.fontWeight = 'bold'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
50 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
51 |
'onmouseout': function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
52 |
this.style.fontWeight = 'normal'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
53 |
} |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
54 |
}; |
0 | 55 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
56 |
this.todayprops = jQuery.extend({}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
57 |
this.cellprops, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
58 |
'class': 'today' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
59 |
}); |
0 | 60 |
|
61 |
this._rowdisplay = function(row) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
62 |
var _td = function(elt) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
63 |
return TD(this.cellprops, elt); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
64 |
}; |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
65 |
return TR(null, $.map(row, _td)); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
66 |
}; |
0 | 67 |
|
68 |
this._makecell = function(cellinfo) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
69 |
return TD(cellinfo[0], cellinfo[1]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
70 |
}; |
0 | 71 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
72 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
73 |
* .. function:: Calendar._uppercaseFirst(s) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
74 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
75 |
* utility function (the only use for now is inside the calendar) |
0 | 76 |
*/ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
77 |
this._uppercaseFirst = function(s) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
78 |
return s.charAt(0).toUpperCase(); |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
79 |
}; |
0 | 80 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
81 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
82 |
* .. function:: Calendar._domForRows(rows) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
83 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
84 |
* accepts the cells data and builds the corresponding TR nodes |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
85 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
86 |
* * `rows`, a list of list of couples (daynum, cssprops) |
0 | 87 |
*/ |
88 |
this._domForRows = function(rows) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
89 |
var lines = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
90 |
for (i = 0; i < rows.length; i++) { |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
91 |
lines.push(TR(null, $.map(rows[i], this._makecell))); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
92 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
93 |
return lines; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
94 |
}; |
0 | 95 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
96 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
97 |
* .. function:: Calendar._headdisplay(row) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
98 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
99 |
* builds the calendar headers |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
100 |
*/ |
0 | 101 |
this._headdisplay = function(row) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
102 |
if (_CAL_HEADER) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
103 |
return _CAL_HEADER; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
104 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
105 |
var self = this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
106 |
var _th = function(day) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
107 |
return TH(null, self._uppercaseFirst(day)); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
108 |
}; |
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
109 |
return TR(null, $.map(DAYNAMES, _th)); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
110 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
111 |
|
0 | 112 |
this._getrows = function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
113 |
var rows = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
114 |
var firstday = new Date(this.year, this.month, 1); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
115 |
var stopdate = firstday.nextMonth(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
116 |
var curdate = firstday.sub(firstday.getRealDay()); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
117 |
while (curdate.getTime() < stopdate) { |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
118 |
var row = []; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
119 |
for (var i = 0; i < 7; i++) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
120 |
if (curdate.getMonth() == this.month) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
121 |
props = curdate.equals(TODAY) ? this.todayprops: this.cellprops; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
122 |
row.push([props, curdate.getDate()]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
123 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
124 |
row.push([this.cellprops, ""]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
125 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
126 |
curdate.iadd(1); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
127 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
128 |
rows.push(row); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
129 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
130 |
return rows; |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
131 |
}; |
0 | 132 |
|
133 |
this._makecal = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
134 |
var rows = this._getrows(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
135 |
var monthname = MONTHNAMES[this.month] + " " + this.year; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
136 |
var prevlink = "javascript: togglePreviousMonth('" + this.containerId + "');"; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
137 |
var nextlink = "javascript: toggleNextMonth('" + this.containerId + "');"; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
138 |
this.domtable = TABLE({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
139 |
'class': this.cssclass |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
140 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
141 |
THEAD(null, TR(null, TH(null, A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
142 |
'href': prevlink |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
143 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
144 |
"<<")), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
145 |
// IE 6/7 requires colSpan instead of colspan |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
146 |
TH({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
147 |
'colSpan': 5, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
148 |
'colspan': 5, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
149 |
'style': "text-align: center;" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
150 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
151 |
monthname), TH(null, A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
152 |
'href': nextlink |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
153 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
154 |
">>")))), TBODY(null, this._headdisplay(), this._domForRows(rows))); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
155 |
return this.domtable; |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
156 |
}; |
0 | 157 |
|
158 |
this._updateDiv = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
159 |
if (!this.domtable) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
160 |
this._makecal(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
161 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
162 |
cw.jqNode(this.containerId).empty().append(this.domtable); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
163 |
// replaceChildNodes($(this.containerId), this.domtable); |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
164 |
}; |
0 | 165 |
|
166 |
this.displayNextMonth = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
167 |
this.domtable = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
168 |
if (this.month == 11) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
169 |
this.year++; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
170 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
171 |
this.month = (this.month + 1) % 12; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
172 |
this._updateDiv(); |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
173 |
}; |
0 | 174 |
|
175 |
this.displayPreviousMonth = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
176 |
this.domtable = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
177 |
if (this.month == 0) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
178 |
this.year--; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
179 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
180 |
this.month = (this.month + 11) % 12; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
181 |
this._updateDiv(); |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
182 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
183 |
|
0 | 184 |
this.show = function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
185 |
if (!this.visible) { |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
186 |
var container = cw.jqNode(this.containerId); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
187 |
if (!this.domtable) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
188 |
this._makecal(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
189 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
190 |
container.empty().append(this.domtable); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
191 |
toggleVisibility(container); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
192 |
this.visible = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
193 |
} |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
194 |
}; |
0 | 195 |
|
196 |
this.hide = function(event) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
197 |
var self; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
198 |
if (event) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
199 |
self = event.data.self; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
200 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
201 |
self = this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
202 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
203 |
if (self.visible) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
204 |
toggleVisibility(self.containerId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
205 |
self.visible = false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
206 |
} |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
207 |
}; |
0 | 208 |
|
209 |
this.toggle = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
210 |
if (this.visible) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
211 |
this.hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
212 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
213 |
else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
214 |
this.show(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
215 |
} |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
216 |
}; |
0 | 217 |
|
218 |
// call hide() when the user explicitly sets the focus on the matching input |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
219 |
cw.jqNode(inputId).bind('focus', { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
220 |
'self': this |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
221 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
222 |
this.hide); // connect(inputId, 'onfocus', this, 'hide'); |
0 | 223 |
}; |
224 |
||
225 |
// keep track of each calendar created |
|
226 |
Calendar.REGISTRY = {}; |
|
227 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
228 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
229 |
* .. function:: toggleCalendar(containerId, inputId, year, month) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
230 |
* |
0 | 231 |
* popup / hide calendar associated to `containerId` |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
232 |
*/ |
0 | 233 |
function toggleCalendar(containerId, inputId, year, month) { |
234 |
var cal = Calendar.REGISTRY[containerId]; |
|
235 |
if (!cal) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
236 |
cal = new Calendar(containerId, inputId, year, month); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
237 |
Calendar.REGISTRY[containerId] = cal; |
0 | 238 |
} |
239 |
/* hide other calendars */ |
|
240 |
for (containerId in Calendar.REGISTRY) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
241 |
var othercal = Calendar.REGISTRY[containerId]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
242 |
if (othercal !== cal) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
243 |
othercal.hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
244 |
} |
0 | 245 |
} |
246 |
cal.toggle(); |
|
247 |
} |
|
248 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
249 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
250 |
* .. function:: toggleNextMonth(containerId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
251 |
* |
0 | 252 |
* ask for next month to calendar displayed in `containerId` |
253 |
*/ |
|
254 |
function toggleNextMonth(containerId) { |
|
255 |
var cal = Calendar.REGISTRY[containerId]; |
|
256 |
cal.displayNextMonth(); |
|
257 |
} |
|
258 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
259 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
260 |
* .. function:: togglePreviousMonth(containerId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
261 |
* |
0 | 262 |
* ask for previous month to calendar displayed in `containerId` |
263 |
*/ |
|
264 |
function togglePreviousMonth(containerId) { |
|
265 |
var cal = Calendar.REGISTRY[containerId]; |
|
266 |
cal.displayPreviousMonth(); |
|
267 |
} |
|
268 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
269 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
270 |
* .. function:: dateSelected(cell, containerId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
271 |
* |
0 | 272 |
* Callback called when the user clicked on a cell in the popup calendar |
273 |
*/ |
|
274 |
function dateSelected(cell, containerId) { |
|
275 |
var cal = Calendar.REGISTRY[containerId]; |
|
5727
29afb9e715bb
[3.9] api update (mostly js) + add support for FCKEditor in formContents js function
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5699
diff
changeset
|
276 |
var input = cw.getNode(cal.inputId); |
0 | 277 |
// XXX: the use of innerHTML might cause problems, but it seems to be |
278 |
// the only way understood by both IE and Mozilla. Otherwise, |
|
279 |
// IE accepts innerText and mozilla accepts textContent |
|
280 |
var selectedDate = new Date(cal.year, cal.month, cell.innerHTML, 12); |
|
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
281 |
input.value = remoteExec("format_date", cw.utils.toISOTimestamp(selectedDate)); |
0 | 282 |
cal.hide(); |
283 |
} |
|
284 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
285 |
function whichElement(e) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
286 |
var targ; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
287 |
if (!e) { |
5699
f4f6ee3af50b
[javascript] move CubicWeb object declaration to cubicweb.js, remove CubicWeb.provide/require, use cw instead of CubicWeb
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
5658
diff
changeset
|
288 |
e = window.event; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
289 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
290 |
if (e.target) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
291 |
targ = e.target; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
292 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
293 |
else if (e.srcElement) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
294 |
targ = e.srcElement; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
295 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
296 |
if (targ.nodeType == 3) // defeat Safari bug |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
297 |
{ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
298 |
targ = targ.parentNode; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
299 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
300 |
return targ; |
0 | 301 |
} |
302 |
||
303 |
function getPosition(element) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
304 |
var left; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
305 |
var top; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
306 |
var offset; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
307 |
// TODO: deal scrollbar positions also! |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
308 |
left = element.offsetLeft; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
309 |
top = element.offsetTop; |
0 | 310 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
311 |
if (element.offsetParent != null) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
312 |
offset = getPosition(element.offsetParent); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
313 |
left = left + offset[0]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
314 |
top = top + offset[1]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
315 |
|
0 | 316 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
317 |
return [left, top]; |
0 | 318 |
} |
319 |
||
320 |
function getMouseInBlock(event) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
321 |
var elt = event.target; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
322 |
var x = event.clientX; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
323 |
var y = event.clientY; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
324 |
var w = elt.clientWidth; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
325 |
var h = elt.clientHeight; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
326 |
var offset = getPosition(elt); |
0 | 327 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
328 |
x = 1.0 * (x - offset[0]) / w; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
329 |
y = 1.0 * (y - offset[1]) / h; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
330 |
return [x, y]; |
0 | 331 |
} |
332 |
function getHourFromMouse(event, hmin, hmax) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
333 |
var pos = getMouseInBlock(event); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
334 |
var y = pos[1]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
335 |
return Math.floor((hmax - hmin) * y + hmin); |
0 | 336 |
} |
337 |
||
338 |
function addCalendarItem(event, hmin, hmax, year, month, day, duration, baseurl) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
339 |
var hour = getHourFromMouse(event, hmin, hmax); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
340 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
341 |
if (0 <= hour && hour < 24) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
342 |
baseurl += "&start=" + year + "%2F" + month + "%2F" + day + "%20" + hour + ":00"; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
343 |
baseurl += "&stop=" + year + "%2F" + month + "%2F" + day + "%20" + (hour + duration) + ":00"; |
0 | 344 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
345 |
stopPropagation(event); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
346 |
window.location.assign(baseurl); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
347 |
return false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
348 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
349 |
return true; |
0 | 350 |
} |
351 |
||
352 |
function stopPropagation(event) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
353 |
event.cancelBubble = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
354 |
if (event.stopPropagation) event.stopPropagation(); |
0 | 355 |
} |