13 TODAY = new Date(); |
13 TODAY = new Date(); |
14 |
14 |
15 /** |
15 /** |
16 * .. class:: Calendar |
16 * .. class:: Calendar |
17 * |
17 * |
18 * Calendar (graphical) widget |
18 * Calendar (graphical) widget |
19 * |
19 * |
20 * public methods are : |
20 * public methods are : |
21 * |
21 * |
22 * __init__ : |
22 * __init__ : |
23 * :attr:`containerId`: the DOM node's ID where the calendar will be displayed |
23 * :attr:`containerId`: the DOM node's ID where the calendar will be displayed |
24 * :attr:`inputId`: which input needs to be updated when a date is selected |
24 * :attr:`inputId`: which input needs to be updated when a date is selected |
25 * :attr:`year`, :attr:`month`: year and month to be displayed |
25 * :attr:`year`, :attr:`month`: year and month to be displayed |
72 }; |
72 }; |
73 |
73 |
74 /** |
74 /** |
75 * .. function:: Calendar._uppercaseFirst(s) |
75 * .. function:: Calendar._uppercaseFirst(s) |
76 * |
76 * |
77 * utility function (the only use for now is inside the calendar) |
77 * utility function (the only use for now is inside the calendar) |
78 */ |
78 */ |
79 this._uppercaseFirst = function(s) { |
79 this._uppercaseFirst = function(s) { |
80 return s.charAt(0).toUpperCase(); |
80 return s.charAt(0).toUpperCase(); |
81 }; |
81 }; |
82 |
82 |
83 /** |
83 /** |
84 * .. function:: Calendar._domForRows(rows) |
84 * .. function:: Calendar._domForRows(rows) |
85 * |
85 * |
86 * accepts the cells data and builds the corresponding TR nodes |
86 * accepts the cells data and builds the corresponding TR nodes |
87 * |
87 * |
88 * * `rows`, a list of list of couples (daynum, cssprops) |
88 * * `rows`, a list of list of couples (daynum, cssprops) |
89 */ |
89 */ |
90 this._domForRows = function(rows) { |
90 this._domForRows = function(rows) { |
91 var lines = []; |
91 var lines = []; |
222 'self': this |
222 'self': this |
223 }, |
223 }, |
224 this.hide); // connect(inputId, 'onfocus', this, 'hide'); |
224 this.hide); // connect(inputId, 'onfocus', this, 'hide'); |
225 }; |
225 }; |
226 |
226 |
227 // keep track of each calendar created |
227 /** |
|
228 * .. data:: Calendar.REGISTRY |
|
229 * |
|
230 * keep track of each calendar created |
|
231 */ |
228 Calendar.REGISTRY = {}; |
232 Calendar.REGISTRY = {}; |
229 |
233 |
230 /** |
234 /** |
231 * .. function:: toggleCalendar(containerId, inputId, year, month) |
235 * .. function:: toggleCalendar(containerId, inputId, year, month) |
232 * |
236 * |
233 * popup / hide calendar associated to `containerId` |
237 * popup / hide calendar associated to `containerId` |
234 */ |
238 */ |
235 function toggleCalendar(containerId, inputId, year, month) { |
239 function toggleCalendar(containerId, inputId, year, month) { |
236 var cal = Calendar.REGISTRY[containerId]; |
240 var cal = Calendar.REGISTRY[containerId]; |
237 if (!cal) { |
241 if (!cal) { |
238 cal = new Calendar(containerId, inputId, year, month); |
242 cal = new Calendar(containerId, inputId, year, month); |
249 } |
253 } |
250 |
254 |
251 /** |
255 /** |
252 * .. function:: toggleNextMonth(containerId) |
256 * .. function:: toggleNextMonth(containerId) |
253 * |
257 * |
254 * ask for next month to calendar displayed in `containerId` |
258 * ask for next month to calendar displayed in `containerId` |
255 */ |
259 */ |
256 function toggleNextMonth(containerId) { |
260 function toggleNextMonth(containerId) { |
257 var cal = Calendar.REGISTRY[containerId]; |
261 var cal = Calendar.REGISTRY[containerId]; |
258 cal.displayNextMonth(); |
262 cal.displayNextMonth(); |
259 } |
263 } |
260 |
264 |
261 /** |
265 /** |
262 * .. function:: togglePreviousMonth(containerId) |
266 * .. function:: togglePreviousMonth(containerId) |
263 * |
267 * |
264 * ask for previous month to calendar displayed in `containerId` |
268 * ask for previous month to calendar displayed in `containerId` |
265 */ |
269 */ |
266 function togglePreviousMonth(containerId) { |
270 function togglePreviousMonth(containerId) { |
267 var cal = Calendar.REGISTRY[containerId]; |
271 var cal = Calendar.REGISTRY[containerId]; |
268 cal.displayPreviousMonth(); |
272 cal.displayPreviousMonth(); |
269 } |
273 } |
270 |
274 |
271 /** |
275 /** |
272 * .. function:: dateSelected(cell, containerId) |
276 * .. function:: dateSelected(cell, containerId) |
273 * |
277 * |
274 * Callback called when the user clicked on a cell in the popup calendar |
278 * callback called when the user clicked on a cell in the popup calendar |
275 */ |
279 */ |
276 function dateSelected(cell, containerId) { |
280 function dateSelected(cell, containerId) { |
277 var cal = Calendar.REGISTRY[containerId]; |
281 var cal = Calendar.REGISTRY[containerId]; |
278 var input = cw.getNode(cal.inputId); |
282 var input = cw.getNode(cal.inputId); |
279 // XXX: the use of innerHTML might cause problems, but it seems to be |
283 // XXX: the use of innerHTML might cause problems, but it seems to be |