410 lines
12 KiB
TypeScript
Raw Normal View History

2016-07-08 00:40:35 +02:00
import { Cordova, Plugin } from './plugin';
2015-11-30 22:15:21 -06:00
2016-08-01 14:01:54 -04:00
/**
* @private
*/
2016-02-08 16:11:40 -06:00
export interface CalendarOptions {
id?: string;
2016-02-08 16:11:40 -06:00
firstReminderMinutes?: number;
secondReminderMinutes?: number;
recurrence?: string; // options are: 'daily', 'weekly', 'monthly', 'yearly'
recurrenceInterval?: number; // only used when recurrence is set
2016-02-08 16:11:40 -06:00
recurrenceEndDate?: Date;
calendarName?: string;
calendarId?: number;
url?: string;
}
/**
* @name Calendar
* @description
2016-02-08 16:11:40 -06:00
* This plugin allows you to add events to the Calendar of the mobile device.
*
* Requires Cordova plugin: `cordova-plugin-calendar`. For more info, please see the [Calendar plugin docs](https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin).
*
2016-08-01 14:01:54 -04:00
*
2016-03-12 18:56:01 -05:00
* @usage
2016-08-01 14:01:54 -04:00
* ```
* import {Calendar} from 'ionic-native';
*
*
*
* Calendar.createCalendar('MyCalendar').then(
* (msg) => { console.log(msg); },
* (err) => { console.log(err); }
* );
* ```
2016-07-08 00:40:35 +02:00
*
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Plugin({
pluginName: 'Calendar',
2015-11-30 22:15:21 -06:00
plugin: 'cordova-plugin-calendar',
pluginRef: 'plugins.calendar',
2016-03-14 13:38:35 -04:00
repo: 'https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin',
platforms: ['Android', 'iOS']
2015-11-30 22:15:21 -06:00
})
export class Calendar {
/**
* This function checks if we have permission to read/write from/to the calendar.
* The promise will resolve with `true` when:
* - You're running on iOS, or
* - You're targetting API level lower than 23, or
* - You're using Android < 6, or
* - You've already granted permission
*
2016-10-08 14:54:02 -04:00
* If this returns false, you should call the `requestReadWritePermission` function
* @returns {Promise<boolean>}
*/
@Cordova()
static hasReadWritePermission(): Promise<boolean> { return; }
2016-07-08 00:40:35 +02:00
/**
* Check if we have read permission
* @returns {Promise<boolean>}
*/
@Cordova()
static hasReadPermission(): Promise<boolean> { return; }
2016-07-08 00:40:35 +02:00
/**
* Check if we have write permission
* @returns {Promise<boolean>}
*/
@Cordova()
static hasWritePermission(): Promise<boolean> { return; }
2016-07-08 00:40:35 +02:00
/**
* Request write permission
* @returns {Promise<any>}
*/
@Cordova()
static requestWritePermission(): Promise<any> { return; }
2016-07-08 00:40:35 +02:00
/**
* Request read permission
* @returns {Promise<any>}
*/
@Cordova()
static requestReadPermission(): Promise<any> { return; }
/**
* Requests read/write permissions
* @returns {Promise<any>}
*/
@Cordova()
2016-07-08 00:40:35 +02:00
static requestReadWritePermission(): Promise<any> { return; }
2016-02-08 16:11:40 -06:00
/**
* Create a calendar. (iOS only)
*
2016-08-01 14:01:54 -04:00
* @param {string | Object} nameOrOptions either a string name or a options object. If string, provide the calendar name. IF an object, provide a calendar name as a string and a calendar color in hex format as a string
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
static createCalendar(
nameOrOptions: string | { calendarName: string, calendarColor: string }
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Delete a calendar. (iOS only)
* @param {string} name Name of the calendar to delete.
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
static deleteCalendar(name: string): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Returns the default calendar options.
*
2016-02-12 13:12:14 -06:00
* @return Returns an object with the default calendar options:
2016-02-08 16:11:40 -06:00
* firstReminderMinutes: 60,
* secondReminderMinutes: null,
* recurrence: null, // options are: 'daily', 'weekly', 'monthly', 'yearly'
* recurrenceInterval: 1, // only used when recurrence is set
* recurrenceEndDate: null,
* calendarName: null,
* calendarId: null,
* url: null
*/
@Cordova({
sync: true
})
2016-02-08 16:11:40 -06:00
static getCalendarOptions(): CalendarOptions {
return {
firstReminderMinutes: 60,
secondReminderMinutes: null,
recurrence: null,
recurrenceInterval: 1,
recurrenceEndDate: null,
calendarName: null,
calendarId: null,
url: null
};
2016-02-08 16:11:40 -06:00
}
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Silently create an event.
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static createEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Silently create an event with additional options.
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @param {CalendarOptions} [options] Additional options, see `getCalendarOptions`
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static createEventWithOptions(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
options?: CalendarOptions
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Interactively create an event.
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static createEventInteractively(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Interactively create an event with additional options.
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @param {CalendarOptions} [options] Additional options, see `getCalendarOptions`
* @returns {Promise<any>}
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static createEventInteractivelyWithOptions(
title?: string,
2016-02-08 16:11:40 -06:00
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
options?: CalendarOptions
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
// deprecated
// @Cordova()
// static createEventInNamedCalendar(
// title?: string,
// location?: string,
// notes?: string,
// startDate?: Date,
// endDate?: Date,
// calendarName?: string
// ) {}
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Find an event.
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @returns {Promise<any>}
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static findEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Find an event with additional options.
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @param {CalendarOptions} [options] Additional options, see `getCalendarOptions`
* @returns {Promise<any>} Returns a Promise that resolves with the event, or rejects with an error.
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static findEventWithOptions(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
options?: CalendarOptions
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Find a list of events within the specified date range. (Android only)
*
* @param {Date} [startDate] The start date
* @param {Date} [endDate] The end date
* @returns {Promise<any>} Returns a Promise that resolves with the list of events, or rejects with an error.
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
static listEventsInRange(startDate: Date, endDate: Date): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Get a list of all calendars.
* @returns {Promise<any>} A Promise that resolves with the list of calendars, or rejects with an error.
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-05-25 00:28:19 -04:00
static listCalendars(): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Get a list of all future events in the specified calendar. (iOS only)
* @returns {Promise<any>} Returns a Promise that resolves with the list of events, or rejects with an error.
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
static findAllEventsInNamedCalendar(calendarName: string): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Modify an event. (iOS only)
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @param {string} [newTitle] The new event title
* @param {string} [newLocation] The new event location
* @param {string} [newNotes] The new event notes
* @param {Date} [newStartDate] The new event start date
* @param {Date} [newEndDate] The new event end date
* @return Returns a Promise
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static modifyEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
newTitle?: string,
newLocation?: string,
newNotes?: string,
newStartDate?: Date,
newEndDate?: Date
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Modify an event with additional options. (iOS only)
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @param {string} [newTitle] The new event title
* @param {string} [newLocation] The new event location
* @param {string} [newNotes] The new event notes
* @param {Date} [newStartDate] The new event start date
* @param {Date} [newEndDate] The new event end date
* @param {CalendarOptions} [filterOptions] Event Options, see `getCalendarOptions`
* @param {CalendarOptions} [newOptions] New event options, see `getCalendarOptions`
2016-02-08 16:11:40 -06:00
* @return Returns a Promise
*/
2016-07-08 00:40:35 +02:00
@Cordova()
static modifyEventWithOptions(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
newTitle?: string,
newLocation?: string,
newNotes?: string,
newStartDate?: Date,
newEndDate?: Date,
filterOptions?: CalendarOptions,
newOptions?: CalendarOptions
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-07-08 00:40:35 +02:00
/**
* Delete an event.
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @return Returns a Promise
*/
2015-11-30 22:15:21 -06:00
@Cordova()
2016-02-08 16:11:40 -06:00
static deleteEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
2016-07-08 00:40:35 +02:00
): Promise<any> { return; }
2016-02-08 16:11:40 -06:00
/**
* Delete an event from the specified Calendar. (iOS only)
*
* @param {string} [title] The event title
* @param {string} [location] The event location
* @param {string} [notes] The event notes
* @param {Date} [startDate] The event start date
* @param {Date} [endDate] The event end date
* @param {string} calendarName
* @return Returns a Promise
*/
2016-07-08 00:40:35 +02:00
@Cordova()
static deleteEventFromNamedCalendar(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
calendarName?: string
): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
2016-02-08 16:11:40 -06:00
/**
* Open the calendar at the specified date.
2016-08-01 14:01:54 -04:00
* @param {Date} date The date you want to open the calendar on
* @return {Promise<any>} Promise returns a promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova()
static openCalendar(date: Date): Promise<any> { return; }
2015-11-30 22:15:21 -06:00
}