demo.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict';
  2. var title = 'My Event Title';
  3. var loc = 'My Event Location';
  4. var notes = 'My interesting Event notes.';
  5. var startDate = new Date();
  6. var endDate = new Date();
  7. var calendarName = 'MyCal';
  8. var options = {
  9. url: 'https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin',
  10. calendarName: calendarName, // iOS specific
  11. calendarId: 1 // Android specific
  12. };
  13. // clean up the dates a bit
  14. startDate.setMinutes(0);
  15. endDate.setMinutes(0);
  16. startDate.setSeconds(0);
  17. endDate.setSeconds(0);
  18. // add a few hours to the dates, JS will automatically update the date (+1 day) if necessary
  19. startDate.setHours(startDate.getHours() + 2);
  20. endDate.setHours(endDate.getHours() + 3);
  21. function onSuccess(msg) {
  22. alert('Calendar success: ' + JSON.stringify(msg));
  23. }
  24. function onError(msg) {
  25. alert('Calendar error: ' + JSON.stringify(msg));
  26. }
  27. function hasReadPermission() {
  28. window.plugins.calendar.hasReadPermission(onSuccess);
  29. }
  30. function requestReadPermission() {
  31. window.plugins.calendar.requestReadPermission(onSuccess);
  32. }
  33. function hasWritePermission() {
  34. window.plugins.calendar.hasWritePermission(onSuccess);
  35. }
  36. function requestWritePermission() {
  37. window.plugins.calendar.requestWritePermission(onSuccess);
  38. }
  39. function hasReadWritePermission() {
  40. window.plugins.calendar.hasReadWritePermission(onSuccess);
  41. }
  42. function requestReadWritePermission() {
  43. window.plugins.calendar.requestReadWritePermission(onSuccess);
  44. }
  45. function openCalendar() {
  46. // today + 3 days
  47. var d = new Date(new Date().getTime() + 3 * 24 * 60 * 60 * 1000);
  48. window.plugins.calendar.openCalendar(d, onSuccess, onError);
  49. }
  50. function listCalendars() {
  51. window.plugins.calendar.listCalendars(onSuccess, onError);
  52. }
  53. function createCalendar() {
  54. var options = window.plugins.calendar.getCreateCalendarOptions();
  55. options.calendarName = "MyCordovaCalendar";
  56. options.calendarColor = "#FF0000"; // red
  57. window.plugins.calendar.createCalendar(options, onSuccess, onError);
  58. }
  59. function deleteCalendar() {
  60. window.plugins.calendar.deleteCalendar("MyCordovaCalendar", onSuccess, onError);
  61. }
  62. function deleteEvent() {
  63. window.plugins.calendar.deleteEvent(title, loc, notes, startDate, endDate, onSuccess, onError);
  64. }
  65. function createCalendarEvent() {
  66. window.plugins.calendar.createEvent(title, loc, notes, startDate, endDate, onSuccess, onError);
  67. }
  68. function createCalendarEventInteractively() {
  69. window.plugins.calendar.createEventInteractively(title, loc, notes, startDate, endDate, onSuccess, onError);
  70. }
  71. function createCalendarEventInteractivelyWithOptions() {
  72. window.plugins.calendar.createEventInteractivelyWithOptions(title, loc, notes, startDate, endDate, options, onSuccess, onError);
  73. }
  74. function createCalendarEventWithOptions() {
  75. window.plugins.calendar.createEventWithOptions(title, loc, notes, startDate, endDate, options, onSuccess, onError);
  76. }
  77. function findEventWithFilter() {
  78. window.plugins.calendar.findEvent(title, loc, notes, startDate, endDate, onSuccess, onError);
  79. }
  80. function findEventNoFilter() {
  81. window.plugins.calendar.findEvent(null, null, null, startDate, endDate, onSuccess, onError);
  82. }
  83. function listEventsInRange() {
  84. startDate.setHours(startDate.getHours() - 12);
  85. window.plugins.calendar.listEventsInRange(startDate, endDate, onSuccess, onError);
  86. }
  87. window.onerror = function(msg, file, line) {
  88. alert(msg + '; ' + file + '; ' + line);
  89. };