The following JavaScript code makes use of the Calendar Manager API to add a new calendar, then a new event within this calendar, as well as a reminder and an attendee.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | var myCalendar = new window.launchbox.CalendarManager.Calendar(); myCalendar.name = "myCalendar" ; myCalendar.color = "#F03CDA" ; var myEvent = new window.launchbox.CalendarManager.CalendarEvent(); myEvent.title = "myEvent" ; myEvent.location = "Galapagos" ; myEvent.dateStart = new Date( "2015-10-14T14:00" ); myEvent.dateEnd = new Date( "2015-10-14T16:00" ); var eventAttendee = new window.launchbox.CalendarManager.Attendee(); eventAttendee.name = "John" ; eventAttendee.attendeeStatus = window.launchbox.CalendarManager.ACCEPTED; eventAttendee.attendeeType = window.launchbox.CalendarManager.OPTIONAL; myEvent.attendees.push(eventAttendee); var eventReminder = new window.launchbox.CalendarManager.Reminder(); eventReminder.minutes = 45; myEvent.reminders.push(eventReminder); myCalendar.save() .then( function (){ myEvent.calendar = myCalendar; return myEvent.save(); }) .then( function (){ console.log( "All is done !" ); }) . catch ( function (error){ console.log( "Error! " + error.message); }); |
The following JavaScript code makes use of the Calendar Manager API to edit reminders and attendees of an event.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | window.launchbox.CalendarManager.getCalendars() .then( function (calendars){ return calendars[0].getCalendarEvents(); }) .then( function (events)){ var event = events[0]; var existingReminder = event.reminders[0]; existingReminder.minutes = 50; var myAttendee = new window.launchbox.CalendarManager.Attendee(); myAttendee.name = "John" ; myAttendee.attendeeStatus = window.launchbox.CalendarManager.AttendeeStatus.INVITED; myAttendee.attendeeType = window.launchbox.CalendarManage.AttendeeType.REQUIRED; event.reminders.push(myAttendee); return event.save() }) .then( function (){ console.log( "Changes saved" ); }) . catch ( function (error){ console.log( "Error! " + error.message); }); |
The index.html
file containing JavaScript that makes use of the
Calendar Manager API functionality is listed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | <!DOCTYPE html> <html manifest= "manifest.appcache" > <head> <title>CalendarManager API sample</title> <link rel= "stylesheet" href= "assets/style.css" type= "text/css" media= "all" /> <link rel= "stylesheet" href= "assets/menu_style.css" type= "text/css" media= "all" /> <link rel= "stylesheet" href= "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" > <script type= "text/javascript" src= "jscolor/jscolor.js" ></script> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script> <script src= "https://code.jquery.com/jquery-1.10.2.js" ></script> <script src= "https://code.jquery.com/ui/1.11.4/jquery-ui.js" ></script> <script type= "text/javascript" src= "jscolor/jscolor.js" ></script> <script> var calendarsList = []; var currentCalendar = null ; var eventsList = []; var currentEvent = null ; function onCalendarListClick() { var d = $( '#calendarsSection' ); window.launchbox.CalendarManager.getCalendars() .then( function (calendars) { var html = "" ; calendarsList = calendars; for ( var i = 0; i < calendarsList.length; i++) { html += "<li onclick='setCurrentCalendar(calendarsList[" + i + "]);'><a>" + calendarsList[i].name + "</a></li>" ; } d.html(html); }) . catch ( function (error) { alert(error); }); } function onAddCalendarClick() { var newCalendar = new window.launchbox.CalendarManager.Calendar(); newCalendar.name=document.getElementById( 'newCalendarName' ).value; newCalendar.color= "#" + document.getElementById( 'newCalendarColor' ).value; newCalendar.save() .then( function () { alert( "Calendar added successfully" ); $( '.menu > li > ul' ).hide(); }) . catch ( function (error) { alert(error); }); } function onRemoveCalendarClick() { var ask = confirm( "Do you want to remove calendar: " + currentCalendar.name + "?" ); if (ask) { window.launchbox.CalendarManager.removeCalendar(currentCalendar) .then( function () { alert( "Calendar: " + currentCalendar.name + " removed successfully" ); document.getElementById( "eventWrapper" ).style.display = 'none' ; document.getElementById( "calendarWrapper" ).style.display = 'none' ; }) . catch ( function (error) { alert(error); }); } } function onShowCalendarEventsClick() { var d = $( '#eventsSection' ); currentCalendar.getCalendarEvents() .then( function (events) { var html = "" ; eventsList = events; for ( var i = 0; i < eventsList.length; i++) { html += "<li onclick='setCurrentEvent(eventsList[" + i + "])'><a>" + eventsList[i].title + "</a></li>" ; } d.html(html); }) . catch ( function (error) { alert(error); }); } function onAddNewEventClick() { var dts= new Date(document.getElementById( "datepickerS" ).value); dts.setHours(Number(document.getElementById( "hourS" ).value)); dts.setMinutes(Number(document.getElementById( "minutesS" ).value)); var dte = new Date(document.getElementById( "datepickerE" ).value); dte.setHours(Number(document.getElementById( "hourE" ).value)); dte.setMinutes(Number(document.getElementById( "minutesE" ).value)); var newEvent = new window.launchbox.CalendarManager.CalendarEvent(); newEvent.title=document.getElementById( "newEventTitle" ).value; newEvent.location=document.getElementById( "newEventLocation" ).value; newEvent.dateStart = dts; newEvent.dateEnd = dte; newEvent.calendar = currentCalendar; newEvent.save() .then( function () { alert( "Event added successfully" ); $( '.menu > li > ul' ).hide(); onShowCalendarEventsClick(); }) . catch ( function (error) { alert(error); }); } function onRemoveEventClick() { var ask = confirm( "Do you want to remove event: " + currentEvent.title + " from calendar: " + currentCalendar.name + " ?" ); if (ask) { currentCalendar.removeCalendarEvent(currentEvent) .then( function () { alert( "Event removed successfully." ); document.getElementById( "eventWrapper" ).style.display = 'none' ; onShowCalendarEventsClick(); }) . catch ( function (error) { printText(error); }); } } function onAddAttendeeClick() { var attendee= new window.launchbox.CalendarManager.Attendee(); attendee.name = document.getElementById( "attName" ).value; attendee.attendeeStatus = Number(document.getElementById( "attStatus" ).value); attendee.attendeeType = Number(document.getElementById( "attType" ).value); currentEvent.attendees.push(attendee); setCurrentEvent(currentEvent); } function onAddReminderClick() { var reminder = new window.launchbox.CalendarManager.Reminder(); reminder.minutes = Number(document.getElementById( "remMin" ).value); currentEvent.reminders.push(reminder); setCurrentEvent(currentEvent); } function createButtonNewAttendee() { var d = $( '#editAttendees' ); d.append( "<li><a>Name: <input type='text' id='attName'/> Status: <select id='attStatus'><option value='0'>Unknown</option><option value='1'>Invited</option><option value='2'>Accepted</option><option value='3'>Declined</option><option value='4'>Tentative</option></select> Type:<select id='attType'><option value='0'>Unknown</option><option value='1'>Required</option><option value='2'>Optional</option></select></a></li>" ); d.append( "<li><a><input type='choice' onclick='onAddAttendeeClick();' value='Add new Attendee'/> </a></li>" ); } function createButtonNewReminder() { var d = $( '#editReminders' ); d.append( "<li><a>Minutes: <input type='number' id='remMin'/> <input type='choice' onclick='onAddReminderClick();' value='Add new Reminder'/> </a></li>" ); } function updateDate(object, property ,value) { var d = new Date(value); d.setHours(object[property].getHours()); d.setMinutes(object[property].getMinutes()); object[property] = d; } function updateValue(object, property, value){ object[property]=value; } function saveEvent(){ currentEvent.save() .then( function (){ alert( 'Changes saved succesfully.' ); setCurrentEvent(currentEvent); }) . catch ( function (error) { alert(error); }); } function setCurrentCalendar(calendar) { currentCalendar = calendar; currentEvent = null ; $( '#currentCalendarSection' ).html( "Calendar: " + currentCalendar.name); eventsList = []; var html = "" ; html += "<li><a>ID: " + currentCalendar.id + "</a></li><li><a>Name: " + currentCalendar.name + "</a></li><li><a>Color: " + currentCalendar.color + "</a></li>" ; $( '#calendarDetails' ).html(html); document.getElementById( "eventWrapper" ).style.display = 'none' ; document.getElementById( "calendarWrapper" ).style.display = 'block' ; } function setCurrentEvent(event) { currentEvent = event; var d = $( '#editDetails' ); var html = "<li><a>Title: <input type='text' id='editedTitle' value='" + currentEvent.title + "'/></a></li>" ; html += "<li><a>Location: <input type='text' id='editedLocation' value='" + currentEvent.location + "'/></a></a></li>" ; html += "<li><a>Date Start: <input type='text' id='editedDateStart' value='" + currentEvent.dateStart.getFullYear() + "-" + (currentEvent.dateStart.getMonth() + 1) + "-" + currentEvent.dateStart.getDate() + "'/></a></li>" ; html += "<li><a>Date End: <input type='text' id='editedDateEnd' value='" + currentEvent.dateEnd.getFullYear() + "-" + (currentEvent.dateEnd.getMonth() + 1) + "-" + currentEvent.dateEnd.getDate() + "'/></a></li>" ; d.html(html); $( "#editedDateStart" ).datepicker({ dateFormat: 'yy-mm-dd' }); $( "#editedDateEnd" ).datepicker({ dateFormat: 'yy-mm-dd' }); $( "#editedTitle" ).change( function (){updateValue(currentEvent, "title" , $( '#editedTitle' ).val());}); $( "#editedLocation" ).change( function (){updateValue(currentEvent, "location" , $( '#editedLocation' + i).val());}); $( "#editedDateStart" ).change( function (){updateDate(currentEvent, "dateStart" ,$( '#editedDateStart' ).val());}); $( "#editedDateEnd" ).change( function (){updateDate(currentEvent, "dateEnd" , $( '#editedDateEnd' ).val());}); $( '#editAttendees' ).html( "" ); for ( var i = 0; i < currentEvent.attendees.length; i++) { ( function (i) { $( '#editAttendees' ).append( " <li><a>ID:" + currentEvent.attendees[i].id + " Name: <input type='text' id='att" + i + "' value='" + currentEvent.attendees[i].name + "'/> Status: <select id='attStatus" + i + "'><option value='0'>Unknown</option><option value='1'>Invited</option><option value='2'>Accepted</option><option value='3'>Declined</option><option value='4'>Tentative</option></select> Type:<select id='attType" + i + "'><option value='0'>Unknown</option><option value='1'>Required</option><option value='2'>Optional</option></select></a></li>" ); $( "#attStatus" + i).val(currentEvent.attendees[i].attendeeStatus); $( "#attType" + i).val(currentEvent.attendees[i].attendeeType); $( "#att" + i).change( function () { updateValue(currentEvent.attendees[i], "name" , $( '#att' + i).val()); }); $( "#attStatus" + i).change( function () { updateValue(currentEvent.attendees[i], "attendeeStatus" , Number($( '#attStatus' + i).val())); }); $( "#attType" + i).change( function () { updateValue(currentEvent.attendees[i], "attendeeType" , Number($( '#attType' + i).val())); }); })(i); } createButtonNewAttendee(); $( '#editReminders' ).html( "" ); for ( var j = 0; j < currentEvent.reminders.length; j++) { ( function (j) { $( '#editReminders' ).append( "<li><a>ID: " + currentEvent.reminders[j].id + " Minutes: <input type='number' id='rem" + j + "' value='" + currentEvent.reminders[j].minutes + "'/></a></li>" ); $( "#rem" + j).change( function () { updateValue(currentEvent.reminders[j], "minutes" , Number($( '#rem' + j).val())); }); })(j); } createButtonNewReminder(); var status = document.getElementById( "eventWrapper" ).style.display; if (status === 'none' ) { document.getElementById( "eventWrapper" ).style.display = 'block' ; } } </script> </head> <body> <header> <h3><span>Calendar API usage example</span></h3> </header> <div class= "title" >Calendar Manager API <a href= "http://10.20.92.42" > appLinkTest </a> </div> <div id= "mainWrapper" > <ul class= "menu" > <li><a onclick= "onCalendarListClick();" >Select calendar</a> <ul id= "calendarsSection" ></ul> </li> <li><a>Add calendar</a> <ul> <li> <a>Name: <input id= "newCalendarName" type= "text" name= "name" value= "" /> Color: <input id= "newCalendarColor" class= "color" value= "66ff00" /> </a> </li> <li> <a> <input type= "choice" onclick= "onAddCalendarClick()" value= "Create new calendar" /></a> </li> </ul> </li> <li onclick= "onRemoveCalendarClick();" ><a>Remove current calendar</a></li> </ul> </div> <div id= "calendarWrapper" style= "display: none" > <br/> <div class= "title" id= "currentCalendarSection" >Calendar:</div> <ul class= "menu" > <li><a>Details</a> <ul id= "calendarDetails" ></ul> </li> <li onclick= "onShowCalendarEventsClick();" ><a>Get events</a> <ul id= "eventsSection" ></ul> </li> <li><a>Add event </a> <ul> <li style= "text-align: left" ><a>Title: <input type= "text" id= "newEventTitle" /> Location: <input type= "text" id= "newEventLocation" /></a></li> <li><a>Start Date: <input type= "text" id= "datepickerS" /> H: <input type= "number" id= "hourS" size= "2" min= "0" max= "23" /> M: <input type= "number" id= "minutesS" size= "2" min= "0" max= "59" /></a></li> <li><a>End Date: <input type= "text" id= "datepickerE" /> H: <input type= "number" id= "hourE" size= "2" min= "0" max= "23" /> M: <input type= "number" id= "minutesE" size= "2" min= "0" max= "59" /></a></li> <li><a><input type= "choice" onclick= "onAddNewEventClick()" value= "Add new Event" /> </a></li> </ul> </li> <li onclick= "onRemoveEventClick();" ><a>Remove currently selected event</a></li> </ul> </div> <div id= "eventWrapper" style= "display: none" > <br/> <div class= "title" id= "currentEventSection" >Event:</div> <ul class= "menu" > <li><a>Details of event</a> <ul id= "editDetails" ></ul> </li> <li><a>Attendees</a> <ul id= "editAttendees" ></ul> </li> <li><a>Reminders</a> <ul id= "editReminders" ></ul> </li> <li onclick= "saveEvent();" ><a>Save</a></li> </ul> </div> <script type= "text/javascript" > $( function () { var menu_ul = $( '.menu > li > ul' ), menu_a = $( '.menu > li > a' ); menu_ul.hide(); menu_a.click( function (e) { e.preventDefault(); if (!$( this ).hasClass( 'active' )) { menu_a.removeClass( 'active' ); menu_ul.filter( ':visible' ).slideUp( 'normal' ); $( this ).addClass( 'active' ).next().stop( true , true ).slideDown( 'normal' ); } else { $( this ).removeClass( 'active' ); $( this ).next().stop( true , true ).slideUp( 'normal' ); } }); $( "#datepickerS" ).datepicker({ dateFormat: 'yy-mm-dd' }); $( "#datepickerE" ).datepicker({ dateFormat: 'yy-mm-dd' }); $( "#editedDateStart" ).datepicker({ dateFormat: 'yy-mm-dd' }); $( "#editedDateEnd" ).datepicker({ dateFormat: 'yy-mm-dd' }); }); </script> </body> </html> |
The contents of the cache manifest file called manifest.appcache
for
this application are listed below:
1 2 3 4 5 6 7 | CACHE MANIFEST CACHE: index.html NETWORK: * |