Skip to content

Commit

Permalink
Added TypeScript definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Feb 27, 2016
1 parent aa61187 commit 9e4d295
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 41 deletions.
11 changes: 11 additions & 0 deletions calendar-common.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module "nativescript-calendar" {
/**
* The allowed values for RecurrenceFrequency.
*/
enum RecurrenceFrequency {
DAILY,
WEEKLY,
MONTHLY,
YEARLY
}
}
2 changes: 1 addition & 1 deletion calendar-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Calendar.defaults = {
},
recurrence: {
frequency: null,
interval: null, // if frequency is DAILY, then 1 = every day, 2 = every other day
interval: 1, // if frequency is DAILY, then 1 = every day, 2 = every other day
endDate: null
},
calendar: {
Expand Down
16 changes: 8 additions & 8 deletions calendar.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ Calendar._findEvents = function(arg) {
var selection = "";
var selections = [];

if (settings.title != null) {
if (settings.title !== null) {
selection += Calendar._fields.TITLE + " LIKE ?";
selections.push("%" + settings.title + "%");
}
if (settings.location != null) {
if (settings.location !== null) {
if (!"".equals(selection)) {
selection += " AND ";
}
Expand Down Expand Up @@ -247,8 +247,8 @@ Calendar.createEvent = function(arg) {

// there's no separate url field, so adding it to the notes
var description = settings.notes;
if (settings.url != null) {
if (settings.notes == null) {
if (settings.url !== null) {
if (settings.notes === null) {
description = settings.url;
} else {
description += " " + settings.url;
Expand All @@ -258,7 +258,7 @@ Calendar.createEvent = function(arg) {
var ContentResolver = application.android.foregroundActivity.getContentResolver();
ContentValues.put(Calendar._fields.HAS_ALARM, new java.lang.Integer(settings.reminders.first || settings.reminders.second ? 1 : 0));
var calendarId = null;
if (settings.calendar.name != null) {
if (settings.calendar.name !== null) {
var calendars = Calendar._findCalendars(settings.calendar.name);
if (calendars.length > 0) {
calendarId = calendars[0].id;
Expand Down Expand Up @@ -288,14 +288,14 @@ Calendar.createEvent = function(arg) {
}
}
}
if (calendarId == null) {
if (calendarId === null) {
calendarId = settings.calendar.id;
}
ContentValues.put(Calendar._fields.CALENDAR.ID, new java.lang.Integer(calendarId));

// recurrence
if (settings.recurrence.frequency != null) {
if (settings.recurrence.endDate == null) {
if (settings.recurrence.frequency !== null) {
if (settings.recurrence.endDate === null) {
ContentValues.put(Calendar._fields.RRULE, "FREQ=" + settings.recurrence.frequency.toUpperCase() + ";INTERVAL=" + settings.recurrence.interval);
} else {
var endDate = arg.recurrence.endDate;
Expand Down
189 changes: 189 additions & 0 deletions calendar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/// <reference path="calendar-common.d.ts"/>
declare module "nativescript-calendar" {

/**
* The options object passed into the createEvent function.
*/
export interface CreateEventOptions {
/**
* The title of the event.
*/
title: string;

/**
* A valid JS Date representing the start date (and time of the event).
* If you want an 'All day event', make sure you set the dates to midnight like this:
*
* var d = new Date();
* d.setHours(0);
* d.setMinutes(0);
* d.setSeconds(0);
*
* // then this will create an 'all day event' for tomorrow
* startDate = new Date(d.getTime() + (24*60*60*1000));
* endDate = new Date(d.getTime() + (2*24*60*60*1000));
*/
startDate: Date;

/**
* A valid JS Date representing the end date (and time of the event).
*/
endDate: Date;

/**
* Where the event takes place.
*/
location?: string;

/**
* Any remarks you want to store with the event.
*/
notes?: string;

/**
* On iOS there's a seperate field for storing a URL with the event.
* On Android there's not, so we add it to any notes you pass in automatically.
*/
url?: URL;

/**
* Want to use a custom calendar for your app? Pass in the 'name'.
* If the name doesn't yet exist the plugin will create it for you.
*/
calendar: {
name: string;
};

/**
* Override the default reminders if you like.
* If you don't the plugin will set a reminder of 60 minutes before the event automatically.
*/
reminders?: {
/**
* Set to null if you don't want a reminder at all.
* Default 60 (minutes).
*/
first?: number;
/**
* Default null (no second reminder).
*/
second?: number;
};

/**
* Use this if you want this event to repeat with a certain interval.
* For instance, if you want an event to recur every other day for 10 days, use:
* {
* frequency: RecurrenceFrequency.DAILY,
* interval: 2,
* endDate: new Date(new Date().getTime() + (10*24*60*60*1000))
* }
*/
recurrence?: {
frequency: RecurrenceFrequency;
/**
* Default 1 (every <RecurrenceFrequency>).
*/
interval?: number;
endDate?: Date;
};
}

interface FindOrDeleteEventsOptions {
/**
* When searching, dates are mandatory - the event must be within this interval.
*/
startDate: Date;

/**
* When searching, dates are mandatory - the event must be within this interval.
*/
endDate: Date;

/**
* If you know the Event ID, set it here.
*/
id?: string;

/**
* (Part of) the title of the event.
*/
title?: string;

/**
* (Part of) the location of the event.
*/
location?: string;

/**
* (Part of) the notes of the event.
* iOS only.
*/
notes?: string;
}

export interface FindEventsOptions extends FindOrDeleteEventsOptions {
}

export interface DeleteEventsOptions extends FindOrDeleteEventsOptions {
}

export interface Calendar {
id: string;
name: string;
}

export interface Event {
id: string;
title: string;
location: string;
url: string;
startDate: Date;
endDate: Date;
allDay: boolean;
calendar: Calendar;
/**
* iOS only.
*/
attendees: {
name: string;
url?: string;
/**
* One of: "Unknown", "Pending", "Accepted", "Declined", "Tentative", "Delegated", "Completed", "In Process"
*/
status: string;
/**
* One of: "Unknown", "Required", "Optional", "Chair", "Non Participant"
*/
role: string;
/**
* One of: "Unknown", "Person", "Room", "Resource", "Group"
*/
type: string;
};
}

/**
* Returns the ID of the event that was created.
*/
export function createEvent(options: CreateEventOptions): Promise<string>;

/**
* Find events matched on ALL params passed in.
*/
export function findEvents(options: FindEventsOptions): Promise<Event[]>;

/**
* Usage is the same as findEvents, but the result is a bit different ;)
* Returns an array of deleted event ID's.
*/
export function deleteEvents(options: DeleteEventsOptions): Promise<string[]>;

/**
* List all available Calendars on the user's device.
*/
export function listCalendars(): Promise<Calendar[]>;

export function hasPermission(): Promise<boolean>;
export function requestPermission(): Promise<any>;
}
Loading

0 comments on commit 9e4d295

Please sign in to comment.