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

364 lines
10 KiB
TypeScript
Raw Normal View History

2016-05-01 01:43:47 +08:00
import {Plugin, Cordova, InstanceProperty, CordovaInstance} from './plugin';
2016-05-01 05:50:08 +08:00
declare var window: any = {
ContactAddress: (...args) => {},
ContactProperties: (...args) => {},
ContactOrganization: (...args) => {},
ContactName: (...args) => {},
ContactField: (...args) => {},
ContactFindOptions: (...args) => {}
};
export interface IContactProperties {
2016-02-10 04:46:21 +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. */
name?: ContactName;
/** A casual name by which to address the contact. */
nickname?: string;
/** An array of all the contact's phone numbers. */
2016-05-01 05:50:08 +08:00
phoneNumbers?: IContactField[];
2016-02-10 04:46:21 +08:00
/** An array of all the contact's email addresses. */
2016-05-01 05:50:08 +08:00
emails?: IContactField[];
2016-02-10 04:46:21 +08:00
/** An array of all the contact's addresses. */
addresses?: ContactAddress[];
/** An array of all the contact's IM addresses. */
2016-05-01 05:50:08 +08:00
ims?: IContactField[];
2016-02-10 04:46:21 +08:00
/** An array of all the contact's organizations. */
organizations?: ContactOrganization[];
/** The birthday of the contact. */
birthday?: Date;
/** A note about the contact. */
note?: string;
/** An array of the contact's photos. */
2016-05-01 05:50:08 +08:00
photos?: IContactField[];
2016-02-10 04:46:21 +08:00
/** An array of all the user-defined categories associated with the contact. */
2016-05-01 05:50:08 +08:00
categories?: IContactField[];
2016-02-10 04:46:21 +08:00
/** An array of web pages associated with the contact. */
2016-05-01 05:50:08 +08:00
urls?: IContactField[];
2016-02-10 04:46:21 +08:00
}
2016-05-01 00:56:30 +08:00
export class Contact {
private _objectInstance: any;
2016-05-01 01:43:47 +08:00
@InstanceProperty
get id() {return; }
@InstanceProperty
get displayName() {return; }
@InstanceProperty
get nickname() {return; }
@InstanceProperty
get phoneNumbers() {return; }
@InstanceProperty
get emails() {return; }
@InstanceProperty
get addresses() {return; }
@InstanceProperty
get ims() {return; }
@InstanceProperty
get organizations() {return; }
@InstanceProperty
get birthday() {return; }
@InstanceProperty
get note() {return; }
@InstanceProperty
get photos() {return; }
@InstanceProperty
get categories() {return; }
@InstanceProperty
get urls() {return; }
2016-05-01 00:56:30 +08:00
constructor () {
2016-05-01 01:43:47 +08:00
this._objectInstance = navigator.contacts.create();
2016-05-01 00:56:30 +08:00
}
2016-05-01 01:43:47 +08:00
clone(): Contact {
// TODO manually clone the object
return;
}
@CordovaInstance()
remove(): Promise<any> {return; }
@CordovaInstance()
save(): Promise<any> {return; }
2016-02-10 04:46:21 +08:00
}
2016-05-01 05:50:08 +08:00
interface IContactError {
2016-02-10 04:46:21 +08:00
/** Error code */
code: number;
/** Error message */
message: string;
}
declare var ContactError: {
2016-05-01 05:50:08 +08:00
new(code: number): IContactError;
2016-02-10 04:46:21 +08:00
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-05-01 05:50:08 +08:00
export interface IContactName {
2016-02-10 04:46:21 +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-05-01 05:50:08 +08:00
export class ContactName implements IContactName {
2016-05-01 00:56:30 +08:00
private _objectInstance: any;
2016-05-01 05:50:08 +08:00
constructor(formatted?: string, familyName?: string, givenName?: string, middleName?: string, honorificPrefix?: string, honorificSuffix?: string) {
this._objectInstance = new window.ContactName(formatted, familyName, givenName, middleName, honorificPrefix, honorificSuffix);
2016-05-01 00:56:30 +08:00
}
2016-05-01 05:50:08 +08:00
@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-02-10 04:46:21 +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-05-01 05:50:08 +08:00
export class ContactField implements IContactField {
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-02-10 04:46:21 +08:00
2016-05-01 05:50:08 +08:00
export interface IContactAddress {
2016-02-10 04:46:21 +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-05-01 05:50:08 +08:00
export class ContactAddress implements IContactAddress {
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; }
2016-02-10 04:46:21 +08:00
2016-05-01 05:50:08 +08:00
@InstanceProperty
get country(): string {return; }
}
export interface IContactOrganization {
2016-02-10 04:46:21 +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-05-01 05:50:08 +08:00
export class ContactOrganization implements IContactOrganization {
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-02-10 04:46:21 +08:00
/** Search options to filter navigator.contacts. */
2016-05-01 05:50:08 +08:00
interface IContactFindOptions {
2016-02-10 04:46:21 +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-05-01 05:50:08 +08:00
export class ContactFindOptions implements IContactFindOptions {
2016-05-01 00:56:30 +08:00
private _objectInstance: any;
2016-05-01 05:50:08 +08:00
constructor () {
this._objectInstance = new window.ContactFindOptions();
2016-05-01 00:56:30 +08:00
}
2016-05-01 05:50:08 +08:00
@InstanceProperty
public get filter(): string {return; }
2016-05-01 00:56:30 +08:00
2016-05-01 05:50:08 +08:00
@InstanceProperty
public get multiple(): boolean {return; }
2016-05-01 00:56:30 +08:00
2016-05-01 05:50:08 +08:00
@InstanceProperty
public get desiredFields(): any {return; }
2016-05-01 00:56:30 +08:00
2016-05-01 05:50:08 +08:00
@InstanceProperty
public get hasPhoneNumber(): boolean {return; }
2016-05-01 00:56:30 +08:00
}
/**
* @name Contacts
* @description
* Access and manage Contacts on the device.
*
* Requires plugin: `cordova-plugin-contacts`
2016-02-10 04:46:21 +08:00
* For full info, please see the [Cordova Contacts plugin docs](https://github.com/apache/cordova-plugin-contacts)
*
* @usage
*
* ```js
* import {Contacts} from 'ionic-native';
*
*
*
* Contacts.create({
* displayName: "Mr. Ionitron"
* }).then((contact) => {}, (err) => {})
* ```
*
*
*/
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-05-01 00:56:30 +08:00
2016-05-01 05:50:08 +08:00
static create(): Contact {
return new Contact();
2016-05-01 00:56:30 +08:00
}
2016-05-01 05:50:08 +08:00
// TODO add fieldType options
2016-02-10 04:46:21 +08:00
/**
* Search for contacts in the Contacts list.
*
* Example: Contacts.find(['*'], { filter: 'Max' }) // will search for a displayName of 'Max'
*
* @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
})
static find(fields: string[], options?: any): Promise<any> { return; }
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()
static pickContact(): Promise<any> { return; }
2015-12-01 01:09:50 +08:00
}