| 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 "../../../dojo/resources/dojo.css"; |
| 12 | @import "../../../dijit/themes/dijit.css"; |
| 13 | @import "../../../dijit/themes/claro/claro.css"; |
| 14 | </style> |
| 15 | </head> |
| 16 | |
| 17 | <body class="claro"> |
| 18 | <script type="text/javascript" |
| 19 | data-dojo-config="async: true, parseOnLoad: true" |
| 20 | src="../../../dojo/dojo.js"></script> |
| 21 | |
| 22 | <script type="text/javascript"> |
| 23 | |
| 24 | require(["dojo/_base/declare", "dojo/ready", "dojo/_base/fx", "dojo/on", "dojo/Deferred", "dojo/when", |
| 25 | "dojo/date/locale", "dojo/parser", "dojo/store/JsonRest", |
| 26 | "dojo/store/Memory", "dojo/store/Observable", "dojo/store/Cache", |
| 27 | "dojox/calendar/Calendar", "dojo/date/stamp", |
| 28 | "dijit/layout/BorderContainer", "dijit/layout/ContentPane" ], |
| 29 | |
| 30 | function(declare, ready, fx, on, Deferred, when, locale, parser, JsonRest, Memory, Observable, Cache, Calendar, stamp){ |
| 31 | |
| 32 | ready(function(){ |
| 33 | |
| 34 | var startOfWeek = calendar.floorToWeek(new calendar.dateClassObj()); |
| 35 | |
| 36 | // Subclass to handle the ID problem |
| 37 | // If the server is generating an ID, the calendar needs the temporary ID |
| 38 | // to synchronize its internal state. |
| 39 | var ExtJsonRest = declare(JsonRest, { |
| 40 | add: function(object, options){ |
| 41 | var tempId = options && options.temporaryId; |
| 42 | var def = new Deferred(); |
| 43 | when(this.inherited(arguments), function(item){ |
| 44 | item.temporaryId = tempId; |
| 45 | def.resolve(item); |
| 46 | }); |
| 47 | return def; |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | // WARNING |
| 52 | // This sample needs a service that hosts REST service that can answer to the Jsonrest store !! |
| 53 | // WARNING |
| 54 | |
| 55 | calendar.on("timeIntervalChange", function(e){ |
| 56 | var startTimeStr = stamp.toISOString(e.startTime, {zulu: true, milliseconds: true}); |
| 57 | var endTimeStr = stamp.toISOString(e.endTime, {zulu: true, milliseconds: true}); |
| 58 | calendar.query = { |
| 59 | startTime: startTimeStr, |
| 60 | endTime:endTimeStr |
| 61 | }; |
| 62 | calendar.set("store", new Observable(new ExtJsonRest({target: "/cal/calendar/"}))); |
| 63 | }); |
| 64 | |
| 65 | calendar.set("date", startOfWeek); |
| 66 | |
| 67 | // Enable creation of event interactively by ctrl clicking grid. |
| 68 | var createItem = function(view, d, e){ |
| 69 | |
| 70 | // create item by maintaining control key |
| 71 | if(!e.ctrlKey || e.shiftKey || e.altKey){ |
| 72 | return null; |
| 73 | } |
| 74 | |
| 75 | // create a new event |
| 76 | var start, end; |
| 77 | var colView = calendar.columnView; |
| 78 | var cal = calendar.dateModule; |
| 79 | |
| 80 | if(view == colView){ |
| 81 | start = calendar.floorDate(d, "minute", colView.timeSlotDuration); |
| 82 | end = cal.add(start, "minute", colView.timeSlotDuration); |
| 83 | }else{ |
| 84 | start = calendar.floorToDay(d); |
| 85 | end = cal.add(start, "day", 1); |
| 86 | } |
| 87 | |
| 88 | var item = { |
| 89 | summary: "New event ", |
| 90 | startTime: start, |
| 91 | endTime: end, |
| 92 | allDay: view.viewKind == "matrix" |
| 93 | }; |
| 94 | |
| 95 | return item; |
| 96 | }; |
| 97 | |
| 98 | var interactive = true; |
| 99 | |
| 100 | if(interactive){ |
| 101 | calendar.set("createOnGridClick", true); |
| 102 | calendar.set("createItemFunc", createItem); |
| 103 | }else{ |
| 104 | |
| 105 | var count = 0; |
| 106 | calendar.on("gridDoubleClick", function(e){ |
| 107 | var item = createItem(calendar.columnView, e.date, e.triggerEvent); |
| 108 | if(item){ |
| 109 | // no id set here and not temporary id in options. |
| 110 | calendar.get("store").add(item, {temporaryId:"toto"}); |
| 111 | } |
| 112 | |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | // Hide loading panel when application is ready |
| 117 | fx.fadeOut({ |
| 118 | node:"loadingPanel", |
| 119 | onEnd: function(node){ |
| 120 | node.parentNode.removeChild(node) |
| 121 | }}).play(500); |
| 122 | |
| 123 | |
| 124 | }); |
| 125 | }); |
| 126 | </script> |
| 127 | |
| 128 | <div id="loadingPanel" style="position:absolute;z-index:10;width:100%;height:100%;background:#ffffff"> |
| 129 | <span style="background: #DBEB8F;padding:2px">Loading...</span> |
| 130 | </div> |
| 131 | |
| 132 | <div data-dojo-type="dijit.layout.BorderContainer" style="width:100%;height:100%" data-dojo-props="design:'sidebar', gutters:true" > |
| 133 | <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="splitter:false, region:'center'"> |
| 134 | <div data-dojo-id="calendar" data-dojo-type="dojox.calendar.Calendar" style="position:absolute;left:10px;top:10px;bottom:10px;right:10px"> |
| 135 | </div> |
| 136 | </div> |
| 137 | |
| 138 | </div> |
| 139 | |
| 140 | </body> |
| 141 | </html> |