awesome-cordova-plugins/src/plugins/calendar.ts

467 lines
16 KiB
TypeScript
Raw Normal View History

2015-12-01 12:15:21 +08:00
import {Plugin, Cordova} from './plugin';
2016-02-09 06:11:40 +08:00
export interface CalendarOptions {
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;
}
export interface Calendar {
id: number,
name: string
}
/**
* 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).
*
*/
2015-12-01 12:15:21 +08:00
@Plugin({
name: 'Calendar',
plugin: 'cordova-plugin-calendar',
pluginRef: 'plugins.calendar'
})
export class Calendar {
2016-02-09 06:11:40 +08:00
/**
* Create a calendar. (iOS only)
*
* @usage
* ```
* Calendar.createCalendar('MyCalendar').then(
* (msg) => { console.log(msg); },
* (err) => { console.log(err); }
* );
* ```
*
* @param {string | Object} nameOrOptions either a string name or a options object.
* options:
* calendarName: string the name of the calendar
* calendarColor: string the hex color of the calendar
* @return Returns a Promise
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static createCalendar(nameOrOptions: string | { calendarName: string, calendarColor: string }) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08:00
/**
* Delete a calendar. (iOS only)
*
* @usage
* ```
* Calendar.deleteCalendar('MyCalendar').then(
* (msg) => { console.log(msg); },
* (err) => { console.log(err); }
* );
* ```
*
* @param {string} name Name of the calendar to delete.
* @return Returns a Promise
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static deleteCalendar(name: string) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08:00
/**
* 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
* }
* ```
*/
static getCalendarOptions(): CalendarOptions {
return {
firstReminderMinutes: 60,
secondReminderMinutes: null,
recurrence: null,
recurrenceInterval: 1,
recurrenceEndDate: null,
calendarName: null,
calendarId: null,
url: null
}
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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
* @return Returns a Promise
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static createEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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`
* @return Returns a Promise
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static createEventWithOptions(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
options?: CalendarOptions
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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
* @return Returns a Promise
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static createEventInteractively(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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`
* @return Returns a Promise
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static createEventInteractivelyWithOptions(
title?:string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
options?: CalendarOptions
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08:00
// deprecated
// @Cordova()
// static createEventInNamedCalendar(
// title?: string,
// location?: string,
// notes?: string,
// startDate?: Date,
// endDate?: Date,
// calendarName?: string
// ) {}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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
* @return Returns a Promise
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static findEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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`
* @return Returns a Promise that resolves with the event, or rejects with an error.
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static findEventWithOptions(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
options?: CalendarOptions
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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
* @return Returns a Promise that resolves with the list of events, or rejects with an error.
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static listEventsInRange(startDate: Date, endDate: Date) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08:00
/**
* Get a list of all calendars.
* @return A Promise that resolves with the list of calendars, or rejects with an error.
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static listCalendars(){
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08:00
/**
* Get a list of all future events in the specified calendar. (iOS only)
* @return Returns a Promise that resolves with the list of events, or rejects with an error.
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static findAllEventsInNamedCalendar(calendarName: string) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static modifyEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date,
newTitle?: string,
newLocation?: string,
newNotes?: string,
newStartDate?: Date,
newEndDate?: Date
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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} [options] Additional 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,
options?: CalendarOptions
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08: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-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static deleteEvent(
title?: string,
location?: string,
notes?: string,
startDate?: Date,
endDate?: Date
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
/**
* 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
) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
2016-02-09 06:11:40 +08:00
/**
* Open the calendar at the specified date.
* @return {Date} date
*/
2015-12-01 12:15:21 +08:00
@Cordova()
2016-02-09 06:11:40 +08:00
static openCalendar(date: Date) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2015-12-01 12:15:21 +08:00
}