import { Cordova, Plugin } from './plugin'; /** * @private */ export interface CalendarOptions { id?: string; firstReminderMinutes?: number; secondReminderMinutes?: number; recurrence?: string; // options are: 'daily', 'weekly', 'monthly', 'yearly' recurrenceInterval?: number; // only used when recurrence is set recurrenceEndDate?: Date; calendarName?: string; calendarId?: number; url?: string; } /** * @name Calendar * @description * 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). * * * @usage * ``` * import {Calendar} from 'ionic-native'; * * * * Calendar.createCalendar('MyCalendar').then( * (msg) => { console.log(msg); }, * (err) => { console.log(err); } * ); * ``` * */ @Plugin({ pluginName: 'Calendar', plugin: 'cordova-plugin-calendar', pluginRef: 'plugins.calendar', repo: 'https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin', platforms: ['Android', 'iOS'] }) 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 * * If this returns false, you should call the `requestReadWritePermission` function * @returns {Promise} */ @Cordova() static hasReadWritePermission(): Promise { return; } /** * Check if we have read permission * @returns {Promise} */ @Cordova() static hasReadPermission(): Promise { return; } /** * Check if we have write permission * @returns {Promise} */ @Cordova() static hasWritePermission(): Promise { return; } /** * Request write permission * @returns {Promise} */ @Cordova() static requestWritePermission(): Promise { return; } /** * Request read permission * @returns {Promise} */ @Cordova() static requestReadPermission(): Promise { return; } /** * Requests read/write permissions * @returns {Promise} */ @Cordova() static requestReadWritePermission(): Promise { return; } /** * Create a calendar. (iOS only) * * @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} Returns a Promise */ @Cordova() static createCalendar( nameOrOptions: string | { calendarName: string, calendarColor: string } ): Promise { return; } /** * Delete a calendar. (iOS only) * @param {string} name Name of the calendar to delete. * @returns {Promise} Returns a Promise */ @Cordova() static deleteCalendar(name: string): Promise { return; } /** * Returns the default calendar options. * * @return Returns an object with the default calendar options: * 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 }) static getCalendarOptions(): CalendarOptions { return { firstReminderMinutes: 60, secondReminderMinutes: null, recurrence: null, recurrenceInterval: 1, recurrenceEndDate: null, calendarName: null, calendarId: null, url: null }; } /** * 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} Returns a Promise */ @Cordova() static createEvent( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date ): Promise { return; } /** * 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} Returns a Promise */ @Cordova() static createEventWithOptions( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date, options?: CalendarOptions ): Promise { return; } /** * 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} Returns a Promise */ @Cordova() static createEventInteractively( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date ): Promise { return; } /** * 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} */ @Cordova() static createEventInteractivelyWithOptions( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date, options?: CalendarOptions ): Promise { return; } // deprecated // @Cordova() // static createEventInNamedCalendar( // title?: string, // location?: string, // notes?: string, // startDate?: Date, // endDate?: Date, // calendarName?: string // ) {} /** * 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} */ @Cordova() static findEvent( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date ): Promise { return; } /** * 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} Returns a Promise that resolves with the event, or rejects with an error. */ @Cordova() static findEventWithOptions( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date, options?: CalendarOptions ): Promise { return; } /** * 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} Returns a Promise that resolves with the list of events, or rejects with an error. */ @Cordova() static listEventsInRange(startDate: Date, endDate: Date): Promise { return; } /** * Get a list of all calendars. * @returns {Promise} A Promise that resolves with the list of calendars, or rejects with an error. */ @Cordova() static listCalendars(): Promise { return; } /** * Get a list of all future events in the specified calendar. (iOS only) * @returns {Promise} Returns a Promise that resolves with the list of events, or rejects with an error. */ @Cordova() static findAllEventsInNamedCalendar(calendarName: string): Promise { return; } /** * 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 */ @Cordova() static modifyEvent( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date, newTitle?: string, newLocation?: string, newNotes?: string, newStartDate?: Date, newEndDate?: Date ): Promise { return; } /** * 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` * @return Returns a Promise */ @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 { return; } /** * 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 */ @Cordova() static deleteEvent( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date ): Promise { return; } /** * 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 */ @Cordova() static deleteEventFromNamedCalendar( title?: string, location?: string, notes?: string, startDate?: Date, endDate?: Date, calendarName?: string ): Promise { return; } /** * Open the calendar at the specified date. * @param {Date} date The date you want to open the calendar on * @return {Promise} Promise returns a promise */ @Cordova() static openCalendar(date: Date): Promise { return; } }