Debian Codegraph @

dojox/calendar/tests/asyncStore.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 "calendar.css";
11 @import "asyncStore.css";
12 @import "../../../dojo/resources/dojo.css";
13 @import "../../../dijit/themes/dijit.css";
14 @import "../../../dijit/themes/claro/claro.css";
15 </style>
16
17 </head>
18
19 <body class="claro">
20 <script type="text/javascript"
21 data-dojo-config="async: true, parseOnLoad: true"
22 src="../../../dojo/dojo.js"></script>
23
24 <script type="text/javascript">
25
26 require(["dojo/ready", "dojo/_base/declare", "dojo/_base/lang", "dojo/_base/sniff", "dojo/_base/array", "dojo/_base/fx", "dojo/on",
27 "dojo/date/locale", "dojo/parser", "dojo/Deferred", "dojo/dom", "dojo/dom-construct", "dojo/store/Memory",
28 "dojo/store/Observable", "dojox/calendar/Calendar", "dijit/Calendar", "dijit/Menu", "dijit/MenuItem" ],
29
30 function(ready, declare, lang, has, arr, fx, on, locale, parser, Deferred, dom, domConstruct,
31 Memory, Observable, Calendar){
32
33 ready(function(){
34
35 // Display different hint every 10 seconds
36 var hints = [
37 "Hint: Create an event by clicking and dragging on the grid while maintaining the control key",
38 "Hint: Move an event by clicking on it and dragging it",
39 "Hint: Resize an event by clicking on one of its ends and dragging it"
40 ];
41
42 var hintIdx = 0;
43 dom.byId("hint").innerHTML = hints[0];
44
45 setInterval(function(){
46 fx.fadeOut({node: "hint",
47 onEnd: function(){
48 hintIdx = hintIdx+1>hints.length-1 ? 0 : hintIdx+1;
49 dom.byId("hint").innerHTML = hints[hintIdx];
50 fx.fadeIn({node: "hint"}).play(500);
51 }
52 }).play(500);
53 }, 10000);
54
55 // Calendar model creation
56 var modelBase = [
57 {day: 1, start: [10,0], duration: 1400},
58 {day: 2, start: [10,30], duration: 120},
59 {day: 2, start: [12,0], duration: 240},
60 {day: 3, start: [6,0], duration: 180},
61 {day: 3, start: [0,0], duration: 2880, allDay: true}
62 ];
63
64 var someData = [];
65
66 var startOfWeek = calendar.floorToWeek(new calendar.dateClassObj());
67
68 for (var id=0; id<modelBase.length; id++) {
69 var newObj = {
70 id: id,
71 summary: "New Event " + id,
72 startTime: new calendar.dateClassObj(startOfWeek.getTime()),
73 endTime: new calendar.dateClassObj(startOfWeek.getTime()),
74 allDay: modelBase[id].allDay
75 };
76
77 newObj.startTime = calendar.dateModule.add(newObj.startTime, "day", modelBase[id].day);
78 newObj.startTime.setHours(modelBase[id].start[0]);
79 newObj.startTime.setMinutes(modelBase[id].start[1]);
80
81 newObj.endTime = calendar.dateModule.add(newObj.startTime, "minute", modelBase[id].duration);
82
83 someData.push(newObj);
84 }
85
86
87 // BEGIN HACK
88 // Hack to simulate some latency when adding / updating an event.
89 // Observable is breaking completely the inheritance chain
90
91 var DelayedMemory = declare(Memory, {
92 put: function(value, options){
93 var def = new Deferred();
94 var res = this.inherited(arguments);
95 setTimeout(lang.hitch(this, function(){
96 def.resolve(res);
97 }), 1000);
98 return def;
99 },
100
101 newIdCount: 100,
102
103 add: function(value, options){
104 value.id = this.newIdCount++;
105 return this.inherited(arguments, [value, options]);
106 }
107 });
108
109 var store = new Observable(DelayedMemory({data: []}));
110
111 calendar.set("store", store);
112 calendar.set("date", startOfWeek);
113
114 // Enable creation of event interactively by ctrl clicking grid.
115 var createItem = function(view, d, e){
116
117 // create item by maintaining control key
118 if(!e.ctrlKey || e.shiftKey || e.altKey){
119 return null;
120 }
121
122 // create a new event
123 var start, end;
124 var colView = calendar.columnView;
125 var cal = calendar.dateModule;
126
127 if(view == colView){
128 start = calendar.floorDate(d, "minute", colView.timeSlotDuration);
129 end = cal.add(start, "minute", colView.timeSlotDuration);
130 }else{
131 start = calendar.floorToDay(d);
132 end = cal.add(start, "day", 1);
133 }
134
135 var item = {
136 created: true,
137 summary: "New event",
138 startTime: start,
139 endTime: end,
140 allDay: view.viewKind == "matrix"
141 };
142
143 id++;
144
145 return item;
146 };
147
148 calendar.set("createOnGridClick", true);
149 calendar.set("createItemFunc", createItem);
150
151 // show context menu on right clicking an event
152 calendar.on("itemContextMenu", function(e){
153 dojo.stopEvent(e.triggerEvent);
154 calendarContextMenu._openMyself({
155 target: e.renderer.domNode,
156 coords: {x: e.triggerEvent.pageX, y: e.triggerEvent.pageY}
157 });
158 });
159
160 contextMenuDelete.on("click", function(){
161 arr.forEach(calendar.selectedItems, function(item){
162 calendar.store.remove(item.id);
163 });
164 });
165
166 // Hide loading panel when application is ready
167 fx.fadeOut({
168 node:"loadingPanel",
169 onEnd: function(node){
170 node.parentNode.removeChild(node)
171 }}).play(500);
172
173
174 });
175 });
176 </script>
177
178 <div id="loadingPanel" style="position:absolute;z-index:10;width:100%;height:100%;background:#ffffff">
179 <span style="background: #DBEB8F;padding:2px">Loading...</span>
180 </div>
181
182 <div data-dojo-id="calendar" data-dojo-type="dojox.calendar.Calendar"
183 style="position:absolute;left:10px;top:10px;bottom:30px;right:10px">
184 <div data-dojo-type="dijit.Menu" data-dojo-id="calendarContextMenu" style="display: none;">
185 <div data-dojo-type="dijit.MenuItem" data-dojo-id="contextMenuDelete" data-dojo-props="iconClass:'dijitIcon dijitIconDelete'">Delete</div>
186 </div>
187 </div>
188 <div id="hint" style="position:absolute;left:10px;height:15px;bottom:10px;right:10px;color:#999;overflow:auto"></div>
189
190 </div>
191
192 </body>
193 </html>