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