2016-07-08 06:49:27 +08:00
|
|
|
import { Cordova, CordovaInstance, Plugin, InstanceProperty } from './plugin';
|
|
|
|
|
|
|
|
|
2016-06-10 13:10:50 +08:00
|
|
|
declare var window: any,
|
2016-07-08 06:49:27 +08:00
|
|
|
navigator: any;
|
|
|
|
|
2016-05-01 05:50:08 +08:00
|
|
|
export interface IContactProperties {
|
2016-07-08 06:49:27 +08:00
|
|
|
/** A globally unique identifier. */
|
|
|
|
id?: string;
|
|
|
|
/** The name of this Contact, suitable for display to end users. */
|
|
|
|
displayName?: string;
|
|
|
|
/** An object containing all components of a persons name. */
|
2016-07-18 12:06:07 +08:00
|
|
|
name?: IContactName;
|
2016-07-08 06:49:27 +08:00
|
|
|
/** A casual name by which to address the contact. */
|
|
|
|
nickname?: string;
|
|
|
|
/** An array of all the contact's phone numbers. */
|
|
|
|
phoneNumbers?: IContactField[];
|
|
|
|
/** An array of all the contact's email addresses. */
|
|
|
|
emails?: IContactField[];
|
|
|
|
/** An array of all the contact's addresses. */
|
2016-07-18 12:06:07 +08:00
|
|
|
addresses?: IContactAddress[];
|
2016-07-08 06:49:27 +08:00
|
|
|
/** An array of all the contact's IM addresses. */
|
|
|
|
ims?: IContactField[];
|
|
|
|
/** An array of all the contact's organizations. */
|
2016-07-18 12:06:07 +08:00
|
|
|
organizations?: IContactOrganization[];
|
2016-07-08 06:49:27 +08:00
|
|
|
/** The birthday of the contact. */
|
|
|
|
birthday?: Date;
|
|
|
|
/** A note about the contact. */
|
|
|
|
note?: string;
|
|
|
|
/** An array of the contact's photos. */
|
|
|
|
photos?: IContactField[];
|
|
|
|
/** An array of all the user-defined categories associated with the contact. */
|
|
|
|
categories?: IContactField[];
|
|
|
|
/** An array of web pages associated with the contact. */
|
|
|
|
urls?: IContactField[];
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
2016-07-07 02:24:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2016-07-18 10:35:38 +08:00
|
|
|
export class Contact implements IContactProperties {
|
2016-07-08 06:49:27 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
@InstanceProperty get id(): string { return; }
|
|
|
|
@InstanceProperty get displayName(): string { return; }
|
2016-07-18 12:06:07 +08:00
|
|
|
@InstanceProperty get name(): IContactName {return; }
|
|
|
|
@InstanceProperty get nickname(): string { return; }
|
|
|
|
@InstanceProperty get phoneNumbers(): IContactField[] { return; }
|
2016-07-08 06:49:27 +08:00
|
|
|
@InstanceProperty get emails(): IContactField[] { return; }
|
2016-07-18 12:06:07 +08:00
|
|
|
@InstanceProperty get addresses(): IContactAddress[] { return; }
|
2016-07-08 06:49:27 +08:00
|
|
|
@InstanceProperty get ims(): IContactField[] { return; }
|
2016-07-18 12:06:07 +08:00
|
|
|
@InstanceProperty get organizations(): IContactOrganization[] { return; }
|
2016-07-08 06:49:27 +08:00
|
|
|
@InstanceProperty get birthday(): Date { return; }
|
|
|
|
@InstanceProperty get note(): string { return; }
|
|
|
|
@InstanceProperty get photos(): IContactField[] { return; }
|
|
|
|
@InstanceProperty get categories(): IContactField[] { return; }
|
|
|
|
@InstanceProperty get urls(): IContactField[] { return; }
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this._objectInstance = navigator.contacts.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
clone(): Contact {
|
|
|
|
let newContact = new Contact();
|
|
|
|
for (let prop in this) {
|
|
|
|
if (prop === 'id') return;
|
|
|
|
newContact[prop] = this[prop];
|
2016-05-01 01:43:47 +08:00
|
|
|
}
|
2016-07-08 06:49:27 +08:00
|
|
|
return newContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
@CordovaInstance()
|
|
|
|
remove(): Promise<any> { return; }
|
|
|
|
|
|
|
|
@CordovaInstance()
|
|
|
|
save(): Promise<any> { return; }
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
2016-07-08 06:49:27 +08:00
|
|
|
|
2016-05-01 05:50:08 +08:00
|
|
|
interface IContactError {
|
2016-07-08 06:49:27 +08:00
|
|
|
/** Error code */
|
|
|
|
code: number;
|
|
|
|
/** Error message */
|
|
|
|
message: string;
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
2016-07-08 06:49:27 +08:00
|
|
|
|
2016-02-10 04:46:21 +08:00
|
|
|
declare var ContactError: {
|
2016-07-08 06:49:27 +08:00
|
|
|
new (code: number): IContactError;
|
|
|
|
UNKNOWN_ERROR: number;
|
|
|
|
INVALID_ARGUMENT_ERROR: number;
|
|
|
|
TIMEOUT_ERROR: number;
|
|
|
|
PENDING_OPERATION_ERROR: number;
|
|
|
|
IO_ERROR: number;
|
|
|
|
NOT_SUPPORTED_ERROR: number;
|
|
|
|
PERMISSION_DENIED_ERROR: number
|
2016-02-10 04:46:21 +08:00
|
|
|
};
|
2016-07-08 06:49:27 +08:00
|
|
|
|
2016-05-01 05:50:08 +08:00
|
|
|
export interface IContactName {
|
2016-07-08 06:49:27 +08:00
|
|
|
/** The complete name of the contact. */
|
|
|
|
formatted?: string;
|
|
|
|
/** The contact's family name. */
|
|
|
|
familyName?: string;
|
|
|
|
/** The contact's given name. */
|
|
|
|
givenName?: string;
|
|
|
|
/** The contact's middle name. */
|
|
|
|
middleName?: string;
|
|
|
|
/** The contact's prefix (example Mr. or Dr.) */
|
|
|
|
honorificPrefix?: string;
|
|
|
|
/** The contact's suffix (example Esq.). */
|
|
|
|
honorificSuffix?: string;
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
2016-07-07 02:24:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2016-05-01 05:50:08 +08:00
|
|
|
export class ContactName implements IContactName {
|
2016-07-08 06:49:27 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
|
|
|
|
constructor(formatted?: string, familyName?: string, givenName?: string, middleName?: string, honorificPrefix?: string, honorificSuffix?: string) {
|
|
|
|
this._objectInstance = new window.ContactName(formatted, familyName, givenName, middleName, honorificPrefix, honorificSuffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
@InstanceProperty get formatted(): string { return; }
|
|
|
|
@InstanceProperty get familyName(): string { return; }
|
|
|
|
@InstanceProperty get givenName(): string { return; }
|
|
|
|
@InstanceProperty get middleName(): string { return; }
|
|
|
|
@InstanceProperty get honorificPrefix(): string { return; }
|
|
|
|
@InstanceProperty get honorificSuffix(): string { return; }
|
2016-05-01 00:56:30 +08:00
|
|
|
}
|
2016-02-10 04:46:21 +08:00
|
|
|
|
2016-05-01 05:50:08 +08:00
|
|
|
export interface IContactField {
|
2016-07-08 06:49:27 +08:00
|
|
|
/** A string that indicates what type of field this is, home for example. */
|
|
|
|
type: string;
|
|
|
|
/** The value of the field, such as a phone number or email address. */
|
|
|
|
value: string;
|
|
|
|
/** Set to true if this ContactField contains the user's preferred value. */
|
|
|
|
pref: boolean;
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 02:24:58 +08:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2016-05-01 05:50:08 +08:00
|
|
|
export class ContactField implements IContactField {
|
2016-07-08 06:49:27 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
|
|
|
|
constructor(type?: string, value?: string, pref?: boolean) {
|
|
|
|
this._objectInstance = new window.ContactField(type, value, pref);
|
|
|
|
}
|
|
|
|
|
|
|
|
@InstanceProperty get type(): string { return; }
|
|
|
|
@InstanceProperty get value(): string { return; }
|
|
|
|
@InstanceProperty get pref(): boolean { return; }
|
2016-05-01 05:50:08 +08:00
|
|
|
}
|
2016-02-10 04:46:21 +08:00
|
|
|
|
2016-05-01 05:50:08 +08:00
|
|
|
export interface IContactAddress {
|
2016-07-08 06:49:27 +08:00
|
|
|
/** Set to true if this ContactAddress contains the user's preferred value. */
|
|
|
|
pref?: boolean;
|
|
|
|
/** A string indicating what type of field this is, home for example. */
|
|
|
|
type?: string;
|
|
|
|
/** The full address formatted for display. */
|
|
|
|
formatted?: string;
|
|
|
|
/** The full street address. */
|
|
|
|
streetAddress?: string;
|
|
|
|
/** The city or locality. */
|
|
|
|
locality?: string;
|
|
|
|
/** The state or region. */
|
|
|
|
region?: string;
|
|
|
|
/** The zip code or postal code. */
|
|
|
|
postalCode?: string;
|
|
|
|
/** The country name. */
|
|
|
|
country?: string;
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 02:24:58 +08:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2016-05-01 05:50:08 +08:00
|
|
|
export class ContactAddress implements IContactAddress {
|
2016-07-08 06:49:27 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
|
|
|
|
constructor(pref?: boolean,
|
|
|
|
type?: string,
|
|
|
|
formatted?: string,
|
|
|
|
streetAddress?: string,
|
|
|
|
locality?: string,
|
|
|
|
region?: string,
|
|
|
|
postalCode?: string,
|
|
|
|
country?: string) {
|
|
|
|
this._objectInstance = new window.ContactAddress(pref, type, formatted, streetAddress, locality, region, postalCode, country);
|
|
|
|
}
|
|
|
|
|
|
|
|
@InstanceProperty get pref(): boolean { return; }
|
|
|
|
@InstanceProperty get type(): string { return; }
|
|
|
|
@InstanceProperty get formatted(): string { return; }
|
|
|
|
@InstanceProperty get streetAddress(): string { return; }
|
|
|
|
@InstanceProperty get locality(): string { return; }
|
|
|
|
@InstanceProperty get region(): string { return; }
|
|
|
|
@InstanceProperty get postalCode(): string { return; }
|
|
|
|
@InstanceProperty get country(): string { return; }
|
2016-05-01 05:50:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface IContactOrganization {
|
2016-07-08 06:49:27 +08:00
|
|
|
/** Set to true if this ContactOrganization contains the user's preferred value. */
|
|
|
|
pref?: boolean;
|
|
|
|
/** A string that indicates what type of field this is, home for example. */
|
|
|
|
type?: string;
|
|
|
|
/** The name of the organization. */
|
|
|
|
name?: string;
|
|
|
|
/** The department the contract works for. */
|
|
|
|
department?: string;
|
|
|
|
/** The contact's title at the organization. */
|
|
|
|
title?: string;
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 02:24:58 +08:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2016-05-01 05:50:08 +08:00
|
|
|
export class ContactOrganization implements IContactOrganization {
|
2016-07-08 06:49:27 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
constructor() {
|
|
|
|
this._objectInstance = new window.ContactOrganization();
|
|
|
|
}
|
|
|
|
@InstanceProperty get pref(): boolean { return; }
|
|
|
|
@InstanceProperty get type(): string { return; }
|
|
|
|
@InstanceProperty get name(): string { return; }
|
|
|
|
@InstanceProperty get department(): string { return; }
|
|
|
|
@InstanceProperty get title(): string { return; }
|
2016-05-01 05:50:08 +08:00
|
|
|
}
|
2016-02-10 04:46:21 +08:00
|
|
|
|
|
|
|
/** Search options to filter navigator.contacts. */
|
2016-06-10 13:10:50 +08:00
|
|
|
export interface IContactFindOptions {
|
2016-07-08 06:49:27 +08:00
|
|
|
/** The search string used to find navigator.contacts. */
|
|
|
|
filter?: string;
|
|
|
|
/** Determines if the find operation returns multiple navigator.contacts. */
|
|
|
|
multiple?: boolean;
|
|
|
|
/* Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. */
|
|
|
|
desiredFields?: string[];
|
2016-02-10 04:46:21 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 02:24:58 +08:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2016-05-01 05:50:08 +08:00
|
|
|
export class ContactFindOptions implements IContactFindOptions {
|
2016-07-08 06:49:27 +08:00
|
|
|
private _objectInstance: any;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this._objectInstance = new window.ContactFindOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
@InstanceProperty get filter(): string { return; }
|
|
|
|
@InstanceProperty get multiple(): boolean { return; }
|
|
|
|
@InstanceProperty get desiredFields(): any { return; }
|
|
|
|
@InstanceProperty get hasPhoneNumber(): boolean { return; }
|
2016-05-01 00:56:30 +08:00
|
|
|
}
|
2016-07-07 02:24:58 +08:00
|
|
|
|
2016-01-26 06:20:36 +08:00
|
|
|
/**
|
2016-02-23 05:20:00 +08:00
|
|
|
* @name Contacts
|
|
|
|
* @description
|
2016-01-26 06:20:36 +08:00
|
|
|
* Access and manage Contacts on the device.
|
|
|
|
*
|
|
|
|
* @usage
|
|
|
|
*
|
|
|
|
* ```js
|
2016-06-10 13:10:50 +08:00
|
|
|
* import {Contact} from 'ionic-native';
|
2016-03-25 01:00:18 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
2016-06-10 13:10:50 +08:00
|
|
|
* let contact = new Contact();
|
|
|
|
* contact.displayName = "Mr. Ionitron";
|
|
|
|
* contact.save().then(
|
|
|
|
* () => console.log("Contact saved!", contact),
|
|
|
|
* (error: any) => console.error("Error saving contact.", error)
|
|
|
|
* );
|
2016-01-26 06:20:36 +08:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2015-12-01 01:09:50 +08:00
|
|
|
@Plugin({
|
|
|
|
plugin: 'cordova-plugin-contacts',
|
|
|
|
pluginRef: 'navigator.contacts',
|
|
|
|
repo: 'https://github.com/apache/cordova-plugin-contacts'
|
|
|
|
})
|
|
|
|
export class Contacts {
|
2016-07-08 06:49:27 +08:00
|
|
|
static create(): Contact {
|
|
|
|
return new Contact();
|
|
|
|
}
|
|
|
|
|
2016-02-10 04:46:21 +08:00
|
|
|
/**
|
|
|
|
* Search for contacts in the Contacts list.
|
|
|
|
* @param fields {string[]} Contact fields to be used as a search qualifier.
|
|
|
|
* A zero-length contactFields parameter is invalid and results in ContactError.INVALID_ARGUMENT_ERROR.
|
|
|
|
* A contactFields value of "*" searches all contact fields.
|
|
|
|
*
|
|
|
|
* @param options {Object} the options to query with:
|
|
|
|
* filter: The search string used to find navigator.contacts. (string) (Default: "")
|
|
|
|
* multiple: Determines if the find operation returns multiple navigator.contacts. (Boolean) (Default: false)
|
|
|
|
* desiredFields: Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. (DOMString[]) [Optional]
|
|
|
|
* hasPhoneNumber(Android only): Filters the search to only return contacts with a phone number informed. (Boolean) (Default: false)
|
|
|
|
*
|
|
|
|
* @return Returns a Promise that resolves with the search results (an array of Contact objects)
|
|
|
|
*/
|
2015-12-01 01:09:50 +08:00
|
|
|
@Cordova({
|
|
|
|
successIndex: 1,
|
|
|
|
errorIndex: 2
|
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static find(fields: string[], options?: any): Promise<any> { return; }
|
2016-07-08 06:49:27 +08:00
|
|
|
|
2016-02-10 04:46:21 +08:00
|
|
|
/**
|
|
|
|
* Select a single Contact.
|
|
|
|
* @return Returns a Promise that resolves with the selected Contact
|
|
|
|
*/
|
2015-12-01 01:09:50 +08:00
|
|
|
@Cordova()
|
2016-07-08 06:49:27 +08:00
|
|
|
static pickContact(): Promise<any> { return; }
|
2016-07-07 02:24:58 +08:00
|
|
|
}
|