author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 06 Feb 2014 19:04:03 +0100 | |
changeset 9584 | 8209bede1a4b |
parent 7529 | 2fdc310be7cd |
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 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
18 |
* Calendar (graphical) widget |
6880
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
19 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
20 |
* public methods are : |
6880
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
21 |
* |
0 | 22 |
* __init__ : |
6880
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
23 |
* :attr:`containerId`: the DOM node's ID where the calendar will be displayed |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
24 |
* :attr:`inputId`: which input needs to be updated when a date is selected |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
25 |
* :attr:`year`, :attr:`month`: year and month to be displayed |
4be32427b2b9
[book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5774
diff
changeset
|
26 |
* :attr:`cssclass`: CSS class of the calendar widget (default is 'commandCal') |
0 | 27 |
* |
28 |
* show() / hide(): |
|
29 |
* show or hide the calendar widget |
|
30 |
* |
|
31 |
* toggle(): |
|
32 |
* 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
|
33 |
* |
0 | 34 |
* displayNextMonth(): (resp. displayPreviousMonth()) |
35 |
* update the calendar to display next (resp. previous) month |
|
36 |
*/ |
|
37 |
Calendar = function(containerId, inputId, year, month, cssclass) { |
|
38 |
this.containerId = containerId; |
|
39 |
this.inputId = inputId; |
|
40 |
this.year = year; |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
41 |
this.month = month - 1; // Javascript's counter starts at 0 for january |
0 | 42 |
this.cssclass = cssclass || "popupCalendar"; |
43 |
this.visible = false; |
|
44 |
this.domtable = null; |
|
45 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
46 |
this.cellprops = { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
47 |
'onclick': function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
48 |
dateSelected(this, containerId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
49 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
50 |
'onmouseover': function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
51 |
this.style.fontWeight = 'bold'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
52 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
53 |
'onmouseout': function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
54 |
this.style.fontWeight = 'normal'; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
55 |
} |
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
|
56 |
}; |
0 | 57 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
58 |
this.todayprops = jQuery.extend({}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
59 |
this.cellprops, { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
60 |
'class': 'today' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
61 |
}); |
0 | 62 |
|
63 |
this._rowdisplay = function(row) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
64 |
var _td = function(elt) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
65 |
return TD(this.cellprops, elt); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
66 |
}; |
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
|
67 |
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
|
68 |
}; |
0 | 69 |
|
70 |
this._makecell = function(cellinfo) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
71 |
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
|
72 |
}; |
0 | 73 |
|
5658
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 |
* .. function:: Calendar._uppercaseFirst(s) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
76 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
77 |
* utility function (the only use for now is inside the calendar) |
0 | 78 |
*/ |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
79 |
this._uppercaseFirst = function(s) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
80 |
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
|
81 |
}; |
0 | 82 |
|
5658
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 |
* .. function:: Calendar._domForRows(rows) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
85 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
86 |
* accepts the cells data and builds the corresponding TR nodes |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
87 |
* |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
88 |
* * `rows`, a list of list of couples (daynum, cssprops) |
0 | 89 |
*/ |
90 |
this._domForRows = function(rows) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
91 |
var lines = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
95 |
return lines; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
96 |
}; |
0 | 97 |
|
5658
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 |
* .. function:: Calendar._headdisplay(row) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
100 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
101 |
* builds the calendar headers |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
102 |
*/ |
0 | 103 |
this._headdisplay = function(row) { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
104 |
if (_CAL_HEADER) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
105 |
return _CAL_HEADER; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
106 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
107 |
var self = this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
108 |
var _th = function(day) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
109 |
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
|
110 |
}; |
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
|
111 |
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
|
112 |
}; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
113 |
|
0 | 114 |
this._getrows = function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
115 |
var rows = []; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
116 |
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
|
117 |
var stopdate = firstday.nextMonth(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
var row = []; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
121 |
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
|
122 |
if (curdate.getMonth() == this.month) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
123 |
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
|
124 |
row.push([props, curdate.getDate()]); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
125 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
126 |
row.push([this.cellprops, ""]); |
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 |
curdate.iadd(1); |
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 |
rows.push(row); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
131 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
132 |
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
|
133 |
}; |
0 | 134 |
|
135 |
this._makecal = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
136 |
var rows = this._getrows(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
this.domtable = TABLE({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
141 |
'class': this.cssclass |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
142 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
143 |
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
|
144 |
'href': prevlink |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
145 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
146 |
"<<")), |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
147 |
// 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
|
148 |
TH({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
149 |
'colSpan': 5, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
150 |
'colspan': 5, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
151 |
'style': "text-align: center;" |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
152 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
153 |
monthname), TH(null, A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
154 |
'href': nextlink |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
155 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
156 |
">>")))), 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
|
157 |
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
|
158 |
}; |
0 | 159 |
|
160 |
this._updateDiv = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
161 |
if (!this.domtable) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
162 |
this._makecal(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
163 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
164 |
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
|
165 |
// 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
|
166 |
}; |
0 | 167 |
|
168 |
this.displayNextMonth = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
169 |
this.domtable = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
170 |
if (this.month == 11) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
171 |
this.year++; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
172 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
}; |
0 | 176 |
|
177 |
this.displayPreviousMonth = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
178 |
this.domtable = null; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
179 |
if (this.month == 0) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
180 |
this.year--; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
181 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
182 |
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
|
183 |
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
|
184 |
}; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
185 |
|
0 | 186 |
this.show = function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
if (!this.domtable) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
190 |
this._makecal(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
191 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
192 |
container.empty().append(this.domtable); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
193 |
toggleVisibility(container); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
194 |
this.visible = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
195 |
} |
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
|
196 |
}; |
0 | 197 |
|
198 |
this.hide = function(event) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
199 |
var self; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
200 |
if (event) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
201 |
self = event.data.self; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
202 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
203 |
self = this; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
204 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
205 |
if (self.visible) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
206 |
toggleVisibility(self.containerId); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
207 |
self.visible = false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
208 |
} |
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
|
209 |
}; |
0 | 210 |
|
211 |
this.toggle = function() { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
212 |
if (this.visible) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
213 |
this.hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
214 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
215 |
else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
216 |
this.show(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
217 |
} |
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
|
218 |
}; |
0 | 219 |
|
220 |
// 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
|
221 |
cw.jqNode(inputId).bind('focus', { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
222 |
'self': this |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
223 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
224 |
this.hide); // connect(inputId, 'onfocus', this, 'hide'); |
0 | 225 |
}; |
226 |
||
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
227 |
/** |
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
228 |
* .. data:: Calendar.REGISTRY |
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
229 |
* |
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
230 |
* keep track of each calendar created |
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
231 |
*/ |
0 | 232 |
Calendar.REGISTRY = {}; |
233 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
234 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
235 |
* .. 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
|
236 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
237 |
* 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
|
238 |
*/ |
0 | 239 |
function toggleCalendar(containerId, inputId, year, month) { |
240 |
var cal = Calendar.REGISTRY[containerId]; |
|
241 |
if (!cal) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
242 |
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
|
243 |
Calendar.REGISTRY[containerId] = cal; |
0 | 244 |
} |
245 |
/* hide other calendars */ |
|
246 |
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
|
247 |
var othercal = Calendar.REGISTRY[containerId]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
248 |
if (othercal !== cal) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
249 |
othercal.hide(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
250 |
} |
0 | 251 |
} |
252 |
cal.toggle(); |
|
253 |
} |
|
254 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
255 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
256 |
* .. function:: toggleNextMonth(containerId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
257 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
258 |
* ask for next month to calendar displayed in `containerId` |
0 | 259 |
*/ |
260 |
function toggleNextMonth(containerId) { |
|
261 |
var cal = Calendar.REGISTRY[containerId]; |
|
262 |
cal.displayNextMonth(); |
|
263 |
} |
|
264 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
265 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
266 |
* .. function:: togglePreviousMonth(containerId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
267 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
268 |
* ask for previous month to calendar displayed in `containerId` |
0 | 269 |
*/ |
270 |
function togglePreviousMonth(containerId) { |
|
271 |
var cal = Calendar.REGISTRY[containerId]; |
|
272 |
cal.displayPreviousMonth(); |
|
273 |
} |
|
274 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
275 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
276 |
* .. function:: dateSelected(cell, containerId) |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
277 |
* |
7529
2fdc310be7cd
[book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6880
diff
changeset
|
278 |
* callback called when the user clicked on a cell in the popup calendar |
0 | 279 |
*/ |
280 |
function dateSelected(cell, containerId) { |
|
281 |
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
|
282 |
var input = cw.getNode(cal.inputId); |
0 | 283 |
// XXX: the use of innerHTML might cause problems, but it seems to be |
284 |
// the only way understood by both IE and Mozilla. Otherwise, |
|
285 |
// IE accepts innerText and mozilla accepts textContent |
|
286 |
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
|
287 |
input.value = remoteExec("format_date", cw.utils.toISOTimestamp(selectedDate)); |
0 | 288 |
cal.hide(); |
289 |
} |
|
290 |
||
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
291 |
function whichElement(e) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
292 |
var targ; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
293 |
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
|
294 |
e = window.event; |
5658
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 (e.target) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
297 |
targ = e.target; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
298 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
299 |
else if (e.srcElement) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
300 |
targ = e.srcElement; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
301 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
302 |
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
|
303 |
{ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
304 |
targ = targ.parentNode; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
305 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
306 |
return targ; |
0 | 307 |
} |
308 |
||
309 |
function getPosition(element) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
310 |
var left; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
311 |
var top; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
312 |
var offset; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
313 |
// TODO: deal scrollbar positions also! |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
314 |
left = element.offsetLeft; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
315 |
top = element.offsetTop; |
0 | 316 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
317 |
if (element.offsetParent != null) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
318 |
offset = getPosition(element.offsetParent); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
319 |
left = left + offset[0]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
320 |
top = top + offset[1]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
321 |
|
0 | 322 |
} |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
323 |
return [left, top]; |
0 | 324 |
} |
325 |
||
326 |
function getMouseInBlock(event) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
327 |
var elt = event.target; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
328 |
var x = event.clientX; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
329 |
var y = event.clientY; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
330 |
var w = elt.clientWidth; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
331 |
var h = elt.clientHeight; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
332 |
var offset = getPosition(elt); |
0 | 333 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
return [x, y]; |
0 | 337 |
} |
338 |
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
|
339 |
var pos = getMouseInBlock(event); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
340 |
var y = pos[1]; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
341 |
return Math.floor((hmax - hmin) * y + hmin); |
0 | 342 |
} |
343 |
||
344 |
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
|
345 |
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
|
346 |
|
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
347 |
if (0 <= hour && hour < 24) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
348 |
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
|
349 |
baseurl += "&stop=" + year + "%2F" + month + "%2F" + day + "%20" + (hour + duration) + ":00"; |
0 | 350 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
351 |
stopPropagation(event); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
352 |
window.location.assign(baseurl); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
353 |
return false; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
354 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
355 |
return true; |
0 | 356 |
} |
357 |
||
358 |
function stopPropagation(event) { |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
359 |
event.cancelBubble = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3096
diff
changeset
|
360 |
if (event.stopPropagation) event.stopPropagation(); |
0 | 361 |
} |