123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- "use strict";
- function Calendar() {
- }
- Calendar.prototype.getCreateCalendarOptions = function () {
- return {
- calendarName: null,
- calendarColor: null // optional, the OS will choose one if left empty, example: pass "#FF0000" for red
- };
- };
- Calendar.prototype.hasReadPermission = function (callback) {
- cordova.exec(callback, null, "Calendar", "hasReadPermission", []);
- };
- Calendar.prototype.requestReadPermission = function (callback) {
- cordova.exec(callback, null, "Calendar", "requestReadPermission", []);
- };
- Calendar.prototype.hasWritePermission = function (callback) {
- cordova.exec(callback, null, "Calendar", "hasWritePermission", []);
- };
- Calendar.prototype.requestWritePermission = function (callback) {
- cordova.exec(callback, null, "Calendar", "requestWritePermission", []);
- };
- Calendar.prototype.hasReadWritePermission = function (callback) {
- cordova.exec(callback, null, "Calendar", "hasReadWritePermission", []);
- };
- Calendar.prototype.requestReadWritePermission = function (callback) {
- cordova.exec(callback, null, "Calendar", "requestReadWritePermission", []);
- };
- Calendar.prototype.createCalendar = function (calendarNameOrOptionsObject, successCallback, errorCallback) {
- var options;
- if (typeof calendarNameOrOptionsObject == "string") {
- options = {
- "calendarName": calendarNameOrOptionsObject
- };
- } else {
- options = calendarNameOrOptionsObject;
- }
- // merge passed options with defaults
- var mergedOptions = Calendar.prototype.getCreateCalendarOptions();
- for (var val in options) {
- if (options.hasOwnProperty(val)) {
- mergedOptions[val] = options[val];
- }
- }
- cordova.exec(successCallback, errorCallback, "Calendar", "createCalendar", [mergedOptions]);
- };
- Calendar.prototype.deleteCalendar = function (calendarName, successCallback, errorCallback) {
- cordova.exec(successCallback, errorCallback, "Calendar", "deleteCalendar", [{
- "calendarName": calendarName
- }]);
- };
- Calendar.prototype.openCalendar = function (date, successCallback, errorCallback) {
- // default: today
- if (!(date instanceof Date)) {
- date = new Date();
- }
- cordova.exec(successCallback, errorCallback, "Calendar", "openCalendar", [{
- "date": date.getTime()
- }]);
- };
- Calendar.prototype.getCalendarOptions = function () {
- return {
- firstReminderMinutes: 60,
- secondReminderMinutes: null,
- recurrence: null, // options are: 'daily', 'weekly', 'monthly', 'yearly'
- recurrenceInterval: 1, // only used when recurrence is set
- recurrenceWeekstart: "MO",
- recurrenceByDay: null,
- recurrenceByMonthDay: null,
- recurrenceEndDate: null,
- recurrenceCount: null,
- calendarName: null,
- calendarId: null,
- url: null
- };
- };
- /**
- * This method can be used if you want more control over the event details.
- * Pass in an options object which you can easily override as follow:
- * var options = window.plugins.calendar.getCalendarOptions();
- * options.firstReminderMinutes = 150;
- */
- Calendar.prototype.createEventWithOptions = function (title, location, notes, startDate, endDate, options, successCallback, errorCallback) {
- if (!(startDate instanceof Date && endDate instanceof Date)) {
- errorCallback("startDate and endDate must be JavaScript Date Objects");
- return;
- }
- // merge passed options with defaults
- var mergedOptions = Calendar.prototype.getCalendarOptions();
- for (var val in options) {
- if (options.hasOwnProperty(val)) {
- mergedOptions[val] = options[val];
- }
- }
- if (options.recurrenceEndDate != null) {
- mergedOptions.recurrenceEndTime = options.recurrenceEndDate.getTime();
- }
- cordova.exec(successCallback, errorCallback, "Calendar", "createEventWithOptions", [{
- "title": title,
- "location": location,
- "notes": notes,
- "startTime": startDate instanceof Date ? startDate.getTime() : null,
- "endTime": endDate instanceof Date ? endDate.getTime() : null,
- "options": mergedOptions
- }]);
- };
- /**
- * @deprecated use createEventWithOptions instead
- */
- Calendar.prototype.createEventInNamedCalendar = function (title, location, notes, startDate, endDate, calendarName, successCallback, errorCallback) {
- Calendar.prototype.createEventWithOptions(title, location, notes, startDate, endDate, {calendarName:calendarName}, successCallback, errorCallback);
- };
- Calendar.prototype.createEvent = function (title, location, notes, startDate, endDate, successCallback, errorCallback) {
- Calendar.prototype.createEventWithOptions(title, location, notes, startDate, endDate, {}, successCallback, errorCallback);
- };
- Calendar.prototype.createEventInteractively = function (title, location, notes, startDate, endDate, successCallback, errorCallback) {
- Calendar.prototype.createEventInteractivelyWithOptions(title, location, notes, startDate, endDate, {}, successCallback, errorCallback);
- };
- Calendar.prototype.createEventInteractivelyWithOptions = function (title, location, notes, startDate, endDate, options, successCallback, errorCallback) {
- // merge passed options with defaults
- var mergedOptions = Calendar.prototype.getCalendarOptions();
- for (var val in options) {
- if (options.hasOwnProperty(val)) {
- mergedOptions[val] = options[val];
- }
- }
- if (options.recurrenceEndDate != null) {
- mergedOptions.recurrenceEndTime = options.recurrenceEndDate.getTime();
- }
- cordova.exec(successCallback, errorCallback, "Calendar", "createEventInteractively", [{
- "title": title,
- "location": location,
- "notes": notes,
- "startTime": startDate instanceof Date ? startDate.getTime() : null,
- "endTime": endDate instanceof Date ? endDate.getTime() : null,
- "options": mergedOptions
- }])
- };
- Calendar.prototype.findEventWithOptions = function (title, location, notes, startDate, endDate, options, successCallback, errorCallback) {
- // merge passed options with defaults
- var mergedOptions = Calendar.prototype.getCalendarOptions();
- for (var val in options) {
- if (options.hasOwnProperty(val)) {
- mergedOptions[val] = options[val];
- }
- }
- if (options.recurrenceEndDate != null) {
- mergedOptions.recurrenceEndTime = options.recurrenceEndDate.getTime();
- }
- cordova.exec(successCallback, errorCallback, "Calendar", "findEventWithOptions", [{
- "title": title,
- "location": location,
- "notes": notes,
- "startTime": startDate instanceof Date ? startDate.getTime() : null,
- "endTime": endDate instanceof Date ? endDate.getTime() : null,
- "options": mergedOptions
- }])
- };
- Calendar.prototype.findEvent = function (title, location, notes, startDate, endDate, successCallback, errorCallback) {
- Calendar.prototype.findEventWithOptions(title, location, notes, startDate, endDate, {}, successCallback, errorCallback);
- };
- Calendar.prototype.findAllEventsInNamedCalendar = function (calendarName, successCallback, errorCallback) {
- cordova.exec(successCallback, errorCallback, "Calendar", "findAllEventsInNamedCalendar", [{
- "calendarName": calendarName
- }]);
- };
- Calendar.prototype.deleteEvent = function (title, location, notes, startDate, endDate, successCallback, errorCallback) {
- if (!(startDate instanceof Date && endDate instanceof Date)) {
- errorCallback("startDate and endDate must be JavaScript Date Objects");
- }
- cordova.exec(successCallback, errorCallback, "Calendar", "deleteEvent", [{
- "title": title,
- "location": location,
- "notes": notes,
- "startTime": startDate instanceof Date ? startDate.getTime() : null,
- "endTime": endDate instanceof Date ? endDate.getTime() : null
- }])
- };
- Calendar.prototype.deleteEventFromNamedCalendar = function (title, location, notes, startDate, endDate, calendarName, successCallback, errorCallback) {
- cordova.exec(successCallback, errorCallback, "Calendar", "deleteEventFromNamedCalendar", [{
- "title": title,
- "location": location,
- "notes": notes,
- "startTime": startDate instanceof Date ? startDate.getTime() : null,
- "endTime": endDate instanceof Date ? endDate.getTime() : null,
- "calendarName": calendarName
- }])
- };
- Calendar.prototype.modifyEventWithOptions = function (title, location, notes, startDate, endDate, newTitle, newLocation, newNotes, newStartDate, newEndDate, options, newOptions, successCallback, errorCallback) {
- if (!(newStartDate instanceof Date && newEndDate instanceof Date)) {
- errorCallback("newStartDate and newEndDate must be JavaScript Date Objects");
- return;
- }
- // merge passed options with defaults
- var mergedOptions = Calendar.prototype.getCalendarOptions();
- for (var val in options) {
- if (options.hasOwnProperty(val)) {
- mergedOptions[val] = options[val];
- }
- }
- if (options.recurrenceEndDate != null) {
- mergedOptions.recurrenceEndTime = options.recurrenceEndDate.getTime();
- }
- // and also merge passed newOptions with defaults
- var newMergedOptions = Calendar.prototype.getCalendarOptions();
- for (var val2 in newOptions) {
- if (newOptions.hasOwnProperty(val2)) {
- newMergedOptions[val2] = newOptions[val2];
- }
- }
- if (newOptions.recurrenceEndDate != null) {
- newMergedOptions.recurrenceEndTime = newOptions.recurrenceEndDate.getTime();
- }
- cordova.exec(successCallback, errorCallback, "Calendar", "modifyEventWithOptions", [{
- "title": title,
- "location": location,
- "notes": notes,
- "startTime": startDate instanceof Date ? startDate.getTime() : null,
- "endTime": endDate instanceof Date ? endDate.getTime() : null,
- "newTitle": newTitle,
- "newLocation": newLocation,
- "newNotes": newNotes,
- "newStartTime": newStartDate instanceof Date ? newStartDate.getTime() : null,
- "newEndTime": newEndDate instanceof Date ? newEndDate.getTime() : null,
- "options": mergedOptions,
- "newOptions": newMergedOptions
- }])
- };
- Calendar.prototype.modifyEvent = function (title, location, notes, startDate, endDate, newTitle, newLocation, newNotes, newStartDate, newEndDate, successCallback, errorCallback) {
- Calendar.prototype.modifyEventWithOptions(title, location, notes, startDate, endDate, newTitle, newLocation, newNotes, newStartDate, newEndDate, {}, successCallback, errorCallback);
- };
- Calendar.prototype.modifyEventInNamedCalendar = function (title, location, notes, startDate, endDate, newTitle, newLocation, newNotes, newStartDate, newEndDate, calendarName, successCallback, errorCallback) {
- var options = Calendar.prototype.getCalendarOptions();
- options.calendarName = calendarName;
- Calendar.prototype.modifyEventWithOptions(title, location, notes, startDate, endDate, newTitle, newLocation, newNotes, newStartDate, newEndDate, options, successCallback, errorCallback);
- };
- Calendar.prototype.listEventsInRange = function (startDate, endDate, successCallback, errorCallback) {
- cordova.exec(successCallback, errorCallback, "Calendar", "listEventsInRange", [{
- "startTime": startDate instanceof Date ? startDate.getTime() : null,
- "endTime": endDate instanceof Date ? endDate.getTime() : null
- }])
- };
- Calendar.prototype.listCalendars = function (successCallback, errorCallback) {
- cordova.exec(successCallback, errorCallback, "Calendar", "listCalendars", []);
- };
- Calendar.install = function () {
- if (!window.plugins) {
- window.plugins = {};
- }
- window.plugins.calendar = new Calendar();
- return window.plugins.calendar;
- };
- cordova.addConstructor(Calendar.install);
|