Debian Codegraph @

dojox/calendar/tests/calendarMonthView.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <title>Calendar Sample: Desktop</title>
8 <style type="text/css">
9 @import "../themes/claro/Calendar.css";
10 @import "../themes/claro/MonthColumnView.css";
11 @import "calendar.css";
12 @import "../../../dojo/resources/dojo.css";
13 @import "../../../dijit/themes/dijit.css";
14 @import "../../../dijit/themes/claro/claro.css";
15 </style>
16 </head>
17
18 <body class="claro">
19 <script type="text/javascript"
20 data-dojo-config="async: true, parseOnLoad: true, paths : {'demo' : '../dojox/calendar/tests'}"
21 src="../../../dojo/dojo.js"></script>
22
23 <script type="text/javascript">
24
25 require([
26 "dojo/ready",
27 "dojo/_base/lang",
28 "dojo/_base/array",
29 "dojo/_base/fx",
30 "dojo/on",
31 "dojo/date/locale",
32 "dojo/parser",
33 "dojo/dom",
34 "dojo/dom-construct",
35 "dojo/store/Memory",
36 "dojo/store/Observable",
37 "demo/ExtendedCalendar",
38 "dijit/Calendar",
39 "dijit/TitlePane",
40 "dijit/layout/BorderContainer",
41 "dijit/layout/ContentPane",
42 "dijit/form/CheckBox",
43 "dijit/form/TextBox",
44 "dijit/form/DateTextBox",
45 "dijit/form/TimeTextBox",
46 "dijit/form/Button",
47 "dijit/form/ComboBox",
48 "dijit/Menu",
49 "dijit/MenuItem"
50 ],
51
52 function(
53 ready,
54 lang,
55 arr,
56 fx,
57 on,
58 locale,
59 parser,
60 dom,
61 domConstruct,
62 Memory,
63 Observable,
64 ExtendedCalendar){
65
66 ready(function(){
67
68 var hints = [
69 "Hint: Create an event by clicking and dragging on the grid while maintaining the control key",
70 "Hint: Drill down the view by clicking row or column header cells",
71 "Hint: Drill down the view by double-clicking a grid cell while maintaining the shift and control key",
72 "Hint: Drill up by double-clicking the grid while maintaining the shift key",
73 "Hint: Move an event by clicking on it and dragging it",
74 "Hint: Resize an event by clicking on one of its ends and dragging it"
75 ];
76
77 var hintIdx = 0;
78 dom.byId("hint").innerHTML = hints[0];
79
80 setInterval(function(){
81 fx.fadeOut({node: "hint",
82 onEnd: function(){
83 hintIdx = hintIdx+1>hints.length-1 ? 0 : hintIdx+1;
84 dom.byId("hint").innerHTML = hints[hintIdx];
85 fx.fadeIn({node: "hint"}).play(500);
86 }
87 }).play(500);
88 }, 10000);
89
90 calendar.set("cssClassFunc", function(item){
91 // Use custom css class on renderers depending of a parameter (calendar).
92 return item.calendar == "cal1" ? "Calendar1" : "Calendar2"
93 });
94
95 // Calendar model creation
96
97 var modelBase = [
98 {day: 1, start: [10,0], duration: 1400},
99 {day: 2, start: [10,30], duration: 120},
100 {day: 2, start: [12,0], duration: 240},
101 {day: 3, start: [6,0], duration: 180},
102 {day: 3, start: [0,0], duration: 2880, allDay: true}
103 ];
104
105 var someData = [];
106
107 var startOfWeek = calendar.floorToWeek(new calendar.dateClassObj());
108
109 for (var id=0; id<modelBase.length; id++) {
110 var newObj = {
111 id: id,
112 summary: "New Event " + id,
113 startTime: new calendar.dateClassObj(startOfWeek.getTime()),
114 endTime: new calendar.dateClassObj(startOfWeek.getTime()),
115 calendar: id%2 == 0 ? "cal1" : "cal2",
116 allDay: modelBase[id].allDay
117 };
118
119 newObj.startTime = calendar.dateModule.add(newObj.startTime, "day", modelBase[id].day);
120 newObj.startTime.setHours(modelBase[id].start[0]);
121 newObj.startTime.setMinutes(modelBase[id].start[1]);
122
123 newObj.endTime = calendar.dateModule.add(newObj.startTime, "minute", modelBase[id].duration);
124
125 someData.push(newObj);
126 }
127
128 calendar.set("store", new Observable(new Memory({data: someData})));
129 calendar.set("date", startOfWeek);
130
131 calendar.on("gridDoubleClick", function(e){
132
133 if(e.triggerEvent.ctrlKey && e.triggerEvent.shiftKey){
134 // drill down
135 calendar.set("date", e.date);
136 calendar.set("dateIntervalSteps", 1);
137 calendar.set("dateInterval", "day");
138 return;
139 }
140
141 if(e.triggerEvent.shiftKey){
142 // drill up
143 var dis = calendar.get("dateIntervalSteps");
144 var di = calendar.get("dateInterval");
145 var d = e.date;
146 switch(e.source.viewKind){
147 case "columns":
148 if(dis == 1){
149 di = "day";
150 dis = 7;
151 d = calendar.floorToWeek(e.date);
152 }else{
153 di = "month";
154 dis = 1;
155 }
156 break;
157 case "matrix":
158 di = "month";
159 dis = 6;
160 break;
161 }
162 calendar.set("date", e.date);
163 calendar.set("dateIntervalSteps", dis);
164 calendar.set("dateInterval", di);
165 }
166
167 });
168
169 // Enable creation of event interactively by ctrl clicking grid.
170 var createItem = function(view, d, e){
171
172 var cal1 = calendar1CB.get("checked");
173 var cal2 = calendar2CB.get("checked");
174
175 // create item by maintaining control key
176 if(!e.ctrlKey || e.shiftKey || e.altKey || (!cal1 && !cal2)){
177 return null;
178 }
179
180 // create a new event
181 var start, end;
182 var colView = calendar.columnView;
183 var cal = calendar.dateModule;
184
185 if(view == colView){
186 start = calendar.floorDate(d, "minute", colView.timeSlotDuration);
187 end = cal.add(start, "minute", colView.timeSlotDuration);
188 }else{
189 start = calendar.floorToDay(d);
190 end = cal.add(start, "day", 1);
191 }
192
193 var item = {
194 id: id,
195 summary: "New event " + id,
196 startTime: start,
197 endTime: end,
198 calendar: cal1 ? "cal1" : "cal2",
199 allDay: view.viewKind != "columns" // use viewKind to manage secondary sheet of columns view
200 };
201
202 id++;
203
204 return item;
205 };
206
207 calendar.set("createOnGridClick", true);
208 calendar.set("createItemFunc", createItem);
209
210 // filter out event according to their calendar
211 var calendarVisibility = [true, true];
212
213 var itemToRendererKindFunc = function(item){
214 if(item.cssClass == "Calendar1" && calendarVisibility[0] ||
215 item.cssClass == "Calendar2" && calendarVisibility[1]){
216 return this._defaultItemToRendererKindFunc(item);
217 }
218 return null
219 };
220
221 calendar.columnView.set("itemToRendererKindFunc", itemToRendererKindFunc);
222 calendar.columnView.secondarySheet.set("itemToRendererKindFunc", itemToRendererKindFunc);
223 calendar.matrixView.set("itemToRendererKindFunc", itemToRendererKindFunc);
224 calendar.monthColumnView.set("itemToRendererKindFunc", itemToRendererKindFunc);
225
226 // show context menu on right clicking an event
227 calendar.on("itemContextMenu", function(e){
228 dojo.stopEvent(e.triggerEvent);
229 calendarContextMenu._openMyself({
230 target: e.renderer.domNode,
231 coords: {x: e.triggerEvent.pageX, y: e.triggerEvent.pageY}
232 });
233 });
234
235 contextMenuDelete.on("click", function(){
236 arr.forEach(calendar.selectedItems, function(item){
237 calendar.store.remove(item.id);
238 });
239 });
240
241 // refresh item panel on event selection.
242 var editedItem;
243
244 var selectionChanged = function(item){
245
246 var itemNull = item == null;
247
248 var widgets = [itemSummaryEditor, itemStartDateEditor, itemStartTimeEditor, itemEndDateEditor,
249 itemEndTimeEditor, calendarEditor, allDayCB, deleteItemButton, updateItemButton];
250
251 arr.forEach(widgets, function(w){
252 w.set("disabled", itemNull);
253 w.set("value", null, false);
254 });
255
256 editedItem = itemNull ? null : lang.mixin({}, item);
257
258 if(!itemNull){
259
260 var allDay = item.allDay === true;
261
262 itemStartTimeEditor.set("disabled", allDay);
263 itemEndTimeEditor.set("disabled", allDay);
264
265 itemSummaryEditor.set("value", item.summary);
266 itemStartDateEditor.set("value", item.startTime);
267 itemStartTimeEditor.set("value", item.startTime);
268 itemEndDateEditor.set("value", item.endTime);
269 itemEndTimeEditor.set("value", item.endTime);
270 calendarEditor.set("value", item.calendar == "cal1" ? "Calendar 1" : "Calendar 2");
271 allDayCB.set("checked", allDay, false);
272 }
273 };
274
275 calendar.on("change", function(e){
276 selectionChanged(e.newValue);
277 });
278
279 calendar.on("itemEditEnd", function(e){
280 selectionChanged(e.item);
281 });
282
283 // configure item properties panel
284 calendar.on("timeIntervalChange", function(e){
285 dateChooser.set("value", e.startTime, false);
286 });
287
288 allDayCB.on("change", function(value){
289
290 itemStartTimeEditor.set("disabled", value);
291 itemEndTimeEditor.set("disabled", value);
292
293 var d;
294 if(value){
295 d = itemStartTimeEditor.get("value");
296 calendar.floorToDay(d, true);
297 itemStartTimeEditor.set("value", d);
298 d = itemEndTimeEditor.get("value");
299 calendar.floorToDay(d, true);
300 itemEndTimeEditor.set("value", d);
301
302 if(!calendar.isStartOfDay(editedItem.endTime)){
303 d = itemEndDateEditor.get("value");
304 calendar.floorToDay(d, true);
305 d = calendar.dateModule.add(d, "day", 1);
306 itemEndDateEditor.set("value", d);
307 }
308
309 }else{
310 editedItem.startTime.setHours(8);
311 editedItem.endTime.setHours(9);
312 itemStartTimeEditor.set("value", editedItem.startTime);
313 itemEndTimeEditor.set("value", editedItem.endTime);
314 d = itemEndDateEditor.get("value");
315 calendar.floorToDay(d, true);
316 d = calendar.dateModule.add(d, "day", -1);
317 itemEndDateEditor.set("value", d);
318 }
319
320 });
321
322 var mergeDateTime = function(isStart){
323 var dateEditor = isStart ? itemStartDateEditor : itemEndDateEditor;
324 var timeEditor = isStart ? itemStartTimeEditor : itemEndTimeEditor;
325 var date = dateEditor.get("value");
326 var time = timeEditor.get("value");
327 date.setHours(time.getHours());
328 date.setMinutes(time.getMinutes());
329 return date;
330 };
331
332 updateItemButton.on("click", function(value){
333
334 if (editedItem != null) {
335 editedItem.summary = itemSummaryEditor.get("value");
336 if(allDayCB.get("value")){
337 if(!calendar.isStartOfDay(editedItem.startTime)){
338 editedItem.startTime = calendar.floorToDay(itemStartDateEditor.get("value"), true);
339 }
340 if(!calendar.isStartOfDay(editedItem.endTime)){
341 editedItem.endTime = calendar.floorToDay(itemEndDateEditor.get("value"), true);
342 }
343 editedItem.allDay = true;
344 }else{
345 editedItem.startTime = mergeDateTime(true);
346 editedItem.endTime = mergeDateTime(false);
347 delete editedItem.allDay;
348 }
349
350 var calValue = calendarEditor.get("value");
351 editedItem.calendar = calValue == "Calendar 1" ? "cal1" : "cal2";
352 calendar.store.put(editedItem);
353 }
354
355 });
356
357 deleteItemButton.on("click", function(value){
358 if (editedItem != null) {
359 calendar.store.remove(editedItem.id);
360 }
361 });
362
363 // Synchronize date picker.
364 dateChooser.set("value", startOfWeek);
365 dateChooser.on("change", function(e){
366 var d = dateChooser.get("value");
367 calendar.set("date", d);
368 });
369
370 calendar1CB.on("change", function(v){
371 calendarVisibility[0] = v;
372 calendar.currentView.invalidateLayout();
373 });
374
375 calendar2CB.on("change", function(v){
376 calendarVisibility[1] = v;
377 calendar.currentView.invalidateLayout();
378 });
379
380 // Hide loading panel when application is ready
381 fx.fadeOut({
382 node:"loadingPanel",
383 onEnd: function(node){
384 node.parentNode.removeChild(node)
385 }}).play(500);
386
387 });
388 });
389 </script>
390
391 <div id="loadingPanel" style="position:absolute;z-index:10;width:100%;height:100%;background:#ffffff">
392 <span style="background: #DBEB8F;padding:2px">Loading...</span>
393 </div>
394
395 <div data-dojo-type="dijit.layout.BorderContainer" style="width:100%;height:100%" data-dojo-props="design:'sidebar', gutters:true" >
396 <div data-dojo-type="dijit.layout.ContentPane" style="width:200px" data-dojo-props="splitter:false, region:'leading'">
397 <div data-dojo-id="dateChooser" data-dojo-type="dijit.Calendar" style="width:100%"></div>
398 <div data-dojo-type="dijit.TitlePane" data-dojo-props="title:'Calendars', style:'margin-top:10px;'" >
399 <div>
400 <input type="checkbox" data-dojo-id="calendar1CB" data-dojo-type="dijit.form.CheckBox" checked="true"/>
401 <label for="calendar1CB">Calendar 1</label>
402 </div>
403
404 <div style="margin-top:5px">
405 <input type="checkbox" data-dojo-id="calendar2CB" data-dojo-type="dijit.form.CheckBox" checked="true"/>
406 <label for="calendar2CB">Calendar 2</label>
407 </div>
408 </div>
409 <div data-dojo-type="dijit.TitlePane" data-dojo-props="title:'Event properties', style:'margin-top:10px;'" >
410 <div><span class="propertyTitle">Summary:</span></div>
411 <div data-dojo-id="itemSummaryEditor" data-dojo-type="dijit.form.TextBox" style="width:165px;" data-dojo-props="disabled:true"></div>
412 <div style="margin-top:10px"><span class="propertyTitle">Start:</span></div>
413 <div>
414 <div data-dojo-id="itemStartDateEditor" data-dojo-type="dijit.form.DateTextBox" style="width:90px;" data-dojo-props="disabled:true"></div>
415 <div data-dojo-id="itemStartTimeEditor" data-dojo-type="dijit.form.TimeTextBox" style="width:70px;" data-dojo-props="disabled:true" ></div>
416 </div>
417 <div style="margin-top:10px"><span class="propertyTitle">End:</span></div>
418 <div>
419 <div data-dojo-id="itemEndDateEditor" data-dojo-type="dijit.form.DateTextBox" style="width:90px;" data-dojo-props="disabled:true" ></div>
420 <div data-dojo-id="itemEndTimeEditor" data-dojo-type="dijit.form.TimeTextBox" style="width:70px;" data-dojo-props="disabled:true" ></div>
421 </div>
422 <div style="margin-top:10px"><span class="propertyTitle">Calendar:</span></div>
423 <select data-dojo-id="calendarEditor" data-dojo-type="dijit.form.ComboBox" style="width:165px;" data-dojo-props="disabled:true" >
424 <option>Calendar 1</option>
425 <option>Calendar 2</option>
426 </select>
427 <div style="margin-top:10px">
428 <input type="checkbox" data-dojo-id="allDayCB" data-dojo-type="dijit.form.CheckBox" checked="false" data-dojo-props="disabled:true" />
429 <label for="allDayCB">All day</label>
430 </div>
431 <div style="margin-top:10px; text-align:right">
432 <span style="text-align:left">
433 <button data-dojo-id="deleteItemButton" class="deleteButton" data-dojo-type="dijit.form.Button" data-dojo-props="disabled:true">Delete</button>
434 </span>
435 <span style="text-align:right">
436 <button data-dojo-id="updateItemButton" data-dojo-type="dijit.form.Button" data-dojo-props="disabled:true" >Update</button>
437 </span>
438 </div>
439 </div>
440 </div>
441 <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="splitter:false, region:'center'">
442 <div data-dojo-id="calendar" data-dojo-type="demo.ExtendedCalendar"
443 style="position:absolute;left:10px;top:10px;bottom:30px;right:10px">
444 <div data-dojo-type="dijit.Menu" data-dojo-id="calendarContextMenu" style="display: none;">
445 <div data-dojo-type="dijit.MenuItem" data-dojo-id="contextMenuDelete" data-dojo-props="iconClass:'dijitIcon dijitIconDelete'">Delete</div>
446 </div>
447 </div>
448 <div id="hint" style="position:absolute;left:10px;height:15px;bottom:10px;right:10px;color:#999;overflow:auto"></div>
449
450 </div>
451 </div>
452
453 </body>
454 </html>