2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
2017-04-27 00:36:12 -04:00
import { Cordova , Plugin , IonicNativePlugin } from '@ionic-native/core' ;
2016-07-08 00:40:35 +02:00
2016-02-08 16:11:40 -06:00
export interface CalendarOptions {
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
* Id
*/
2016-09-28 13:54:19 -04:00
id? : string ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
*
*/
2016-02-08 16:11:40 -06:00
firstReminderMinutes? : number ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
*
*/
2016-02-08 16:11:40 -06:00
secondReminderMinutes? : number ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
* Recurrence. Can be set to `daily`, `weekly`, `monthly` or `yearly`
*/
recurrence? : string ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
* Recurrence interval. Valid only when `recurrence` option is set.
*/
recurrenceInterval? : number ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
* Recurrence end date. Valid only when `recurrence` option is set.
*/
2016-02-08 16:11:40 -06:00
recurrenceEndDate? : Date ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
* Calendar name. Ths is supported by `iOS` only.
*/
2016-02-08 16:11:40 -06:00
calendarName? : string ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
* Calendar id
*/
2016-02-08 16:11:40 -06:00
calendarId? : number ;
2016-12-06 08:02:00 -05:00
2016-12-06 08:57:53 -05:00
/**
* URL
*/
2016-02-08 16:11:40 -06:00
url? : string ;
2016-12-06 08:02:00 -05:00
2016-02-08 16:11:40 -06:00
}
/**
2016-02-22 16:20:00 -05:00
* @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
* ```
2017-04-27 00:36:12 -04:00
* import { Calendar } from '@ionic-native/calendar';
2016-08-01 14:01:54 -04:00
*
2017-03-20 16:38:14 -04:00
* constructor(private calendar: Calendar) { }
2016-08-01 14:01:54 -04:00
*
*
2017-03-20 16:38:14 -04:00
* this.calendar.createCalendar('MyCalendar').then(
2016-08-01 14:01:54 -04:00
* (msg) => { console.log(msg); },
* (err) => { console.log(err); }
* );
* ```
2016-12-06 08:57:53 -05:00
* @interfaces
* CalendarOptions
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'Calendar' ,
2015-11-30 22:15:21 -06:00
plugin : 'cordova-plugin-calendar' ,
2016-02-22 16:20:00 -05:00
pluginRef : 'plugins.calendar' ,
2016-03-14 13:38:35 -04:00
repo : 'https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin' ,
2016-04-29 23:56:49 -04:00
platforms : [ 'Android' , 'iOS' ]
2015-11-30 22:15:21 -06:00
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2017-04-27 00:36:12 -04:00
export class Calendar extends IonicNativePlugin {
2016-05-12 21:54:52 -04:00
/**
* 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
2016-06-11 07:56:18 -04:00
* @returns {Promise<boolean>}
2016-05-12 21:54:52 -04:00
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
hasReadWritePermission ( ) : Promise < boolean > { return ; }
2016-06-11 07:56:18 -04:00
2016-07-08 00:40:35 +02:00
/**
* Check if we have read permission
* @returns {Promise<boolean>}
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
hasReadPermission ( ) : Promise < boolean > { return ; }
2016-06-11 07:56:18 -04:00
2016-07-08 00:40:35 +02:00
/**
* Check if we have write permission
* @returns {Promise<boolean>}
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
hasWritePermission ( ) : Promise < boolean > { return ; }
2016-06-11 07:56:18 -04:00
2016-07-08 00:40:35 +02:00
/**
* Request write permission
* @returns {Promise<any>}
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
requestWritePermission ( ) : Promise < any > { return ; }
2016-06-11 07:56:18 -04:00
2016-07-08 00:40:35 +02:00
/**
* Request read permission
* @returns {Promise<any>}
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
requestReadPermission ( ) : Promise < any > { return ; }
2016-05-12 21:54:52 -04:00
/**
* Requests read/write permissions
2016-06-11 07:56:18 -04:00
* @returns {Promise<any>}
2016-05-12 21:54:52 -04:00
*/
2016-06-11 07:56:18 -04:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
requestReadWritePermission ( ) : Promise < any > { return ; }
2016-05-12 21:54:52 -04:00
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
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
createCalendar ( nameOrOptions : string | any ) : 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.
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
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-12-06 08:57:53 -05:00
* @return {CalendarOptions} Returns an object with the default calendar options
2016-02-08 16:11:40 -06:00
*/
2016-02-09 14:51:32 -06:00
@Cordova ( {
sync : true
} )
2017-03-20 16:38:14 -04:00
getCalendarOptions ( ) : CalendarOptions { return ; }
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
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
createEvent (
2016-02-08 16:11:40 -06:00
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`
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
createEventWithOptions (
2016-02-08 16:11:40 -06:00
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
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>} Returns a Promise
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
createEventInteractively (
2016-02-08 16:11:40 -06:00
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`
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>}
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
createEventInteractivelyWithOptions (
2016-04-29 23:56:49 -04:00
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
/**
* 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
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>}
2016-02-08 16:11:40 -06:00
*/
2015-11-30 22:15:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
findEvent (
2016-02-08 16:11:40 -06:00
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`
2016-11-29 16:40:50 -06:00
* @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 ( )
2017-03-20 16:38:14 -04:00
findEventWithOptions (
2016-02-08 16:11:40 -06:00
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
2016-11-29 16:40:50 -06:00
* @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
*/
2016-12-06 08:57:53 -05:00
@Cordova ( {
platforms : [ 'Android' ]
} )
2017-03-20 16:38:14 -04:00
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.
2016-11-29 16:40:50 -06:00
* @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 ( )
2017-03-20 16:38:14 -04:00
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)
2016-11-29 16:40:50 -06:00
* @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
*/
2016-12-06 08:57:53 -05:00
@Cordova ( {
platforms : [ 'iOS' ]
} )
2017-03-20 16:38:14 -04:00
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
*/
2016-12-06 08:57:53 -05:00
@Cordova ( {
platforms : [ 'iOS' ]
} )
2017-03-20 16:38:14 -04:00
modifyEvent (
2016-02-08 16:11:40 -06:00
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
2016-09-28 13:54:19 -04:00
* @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-12-06 08:57:53 -05:00
@Cordova ( {
platforms : [ 'iOS' ]
} )
2017-03-20 16:38:14 -04:00
modifyEventWithOptions (
2016-07-08 00:40:35 +02:00
title? : string ,
location? : string ,
notes? : string ,
startDate? : Date ,
endDate? : Date ,
newTitle? : string ,
newLocation? : string ,
newNotes? : string ,
newStartDate? : Date ,
newEndDate? : Date ,
2016-09-28 13:54:19 -04:00
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 ( )
2017-03-20 16:38:14 -04:00
deleteEvent (
2016-02-08 16:11:40 -06:00
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-12-06 08:57:53 -05:00
@Cordova ( {
platforms : [ 'iOS' ]
} )
2017-03-20 16:38:14 -04:00
deleteEventFromNamedCalendar (
2016-07-08 00:40:35 +02:00
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 ( )
2017-03-20 16:38:14 -04:00
openCalendar ( date : Date ) : Promise < any > { return ; }
2016-07-20 17:17:09 +02:00
2015-11-30 22:15:21 -06:00
}