3
0
mirror of https://github.com/danielsogl/awesome-cordova-plugins.git synced 2025-04-21 17:36:27 +08:00

refactor(contacts):

This commit is contained in:
Guille 2016-07-08 00:49:27 +02:00
parent b995d7bc31
commit e52fb1cacc

@ -1,235 +1,252 @@
import {Plugin, Cordova, InstanceProperty, CordovaInstance} from './plugin'; import { Cordova, CordovaInstance, Plugin, InstanceProperty } from './plugin';
declare var window: any,
navigator: any;
export interface IContactProperties {
/** 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. */
phoneNumbers?: IContactField[];
/** An array of all the contact's email addresses. */
emails?: IContactField[];
/** An array of all the contact's addresses. */
addresses?: ContactAddress[];
/** An array of all the contact's IM addresses. */
ims?: IContactField[];
/** 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. */
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[];
}
declare var window: any,
navigator: any;
export interface IContactProperties {
/** 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. */
phoneNumbers?: IContactField[];
/** An array of all the contact's email addresses. */
emails?: IContactField[];
/** An array of all the contact's addresses. */
addresses?: ContactAddress[];
/** An array of all the contact's IM addresses. */
ims?: IContactField[];
/** 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. */
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[];
}
/** /**
* @private * @private
*/ */
export class Contact { export class Contact {
private _objectInstance: any; private _objectInstance: any;
@InstanceProperty get id(): string {return; } @InstanceProperty get id(): string { return; }
@InstanceProperty get displayName(): string {return; } @InstanceProperty get displayName(): string { return; }
@InstanceProperty get nickname(): ContactName {return; } @InstanceProperty get nickname(): ContactName { return; }
@InstanceProperty get phoneNumbers(): string {return; } @InstanceProperty get phoneNumbers(): string { return; }
@InstanceProperty get emails(): IContactField[] {return; } @InstanceProperty get emails(): IContactField[] { return; }
@InstanceProperty get addresses(): ContactAddress[] {return; } @InstanceProperty get addresses(): ContactAddress[] { return; }
@InstanceProperty get ims(): IContactField[] {return; } @InstanceProperty get ims(): IContactField[] { return; }
@InstanceProperty get organizations(): ContactOrganization[] {return; } @InstanceProperty get organizations(): ContactOrganization[] { return; }
@InstanceProperty get birthday(): Date {return; } @InstanceProperty get birthday(): Date { return; }
@InstanceProperty get note(): string {return; } @InstanceProperty get note(): string { return; }
@InstanceProperty get photos(): IContactField[] {return; } @InstanceProperty get photos(): IContactField[] { return; }
@InstanceProperty get categories(): IContactField[] {return; } @InstanceProperty get categories(): IContactField[] { return; }
@InstanceProperty get urls(): IContactField[] {return; } @InstanceProperty get urls(): IContactField[] { return; }
constructor () {
this._objectInstance = navigator.contacts.create(); 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];
} }
clone(): Contact { return newContact;
let newContact = new Contact(); }
for (let prop in this) {
if (prop === 'id') return; @CordovaInstance()
newContact[prop] = this[prop]; remove(): Promise<any> { return; }
}
return newContact; @CordovaInstance()
} save(): Promise<any> { return; }
@CordovaInstance()
remove(): Promise<any> {return; }
@CordovaInstance()
save(): Promise<any> {return; }
} }
interface IContactError { interface IContactError {
/** Error code */ /** Error code */
code: number; code: number;
/** Error message */ /** Error message */
message: string; message: string;
} }
declare var ContactError: { declare var ContactError: {
new(code: number): IContactError; new (code: number): IContactError;
UNKNOWN_ERROR: number; UNKNOWN_ERROR: number;
INVALID_ARGUMENT_ERROR: number; INVALID_ARGUMENT_ERROR: number;
TIMEOUT_ERROR: number; TIMEOUT_ERROR: number;
PENDING_OPERATION_ERROR: number; PENDING_OPERATION_ERROR: number;
IO_ERROR: number; IO_ERROR: number;
NOT_SUPPORTED_ERROR: number; NOT_SUPPORTED_ERROR: number;
PERMISSION_DENIED_ERROR: number PERMISSION_DENIED_ERROR: number
}; };
export interface IContactName { export interface IContactName {
/** The complete name of the contact. */ /** The complete name of the contact. */
formatted?: string; formatted?: string;
/** The contact's family name. */ /** The contact's family name. */
familyName?: string; familyName?: string;
/** The contact's given name. */ /** The contact's given name. */
givenName?: string; givenName?: string;
/** The contact's middle name. */ /** The contact's middle name. */
middleName?: string; middleName?: string;
/** The contact's prefix (example Mr. or Dr.) */ /** The contact's prefix (example Mr. or Dr.) */
honorificPrefix?: string; honorificPrefix?: string;
/** The contact's suffix (example Esq.). */ /** The contact's suffix (example Esq.). */
honorificSuffix?: string; honorificSuffix?: string;
} }
/** /**
* @private * @private
*/ */
export class ContactName implements IContactName { export class ContactName implements IContactName {
private _objectInstance: any; 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); 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 formatted(): string { return; }
@InstanceProperty get middleName(): string {return; } @InstanceProperty get familyName(): string { return; }
@InstanceProperty get honorificPrefix(): string {return; } @InstanceProperty get givenName(): string { return; }
@InstanceProperty get honorificSuffix(): string {return; } @InstanceProperty get middleName(): string { return; }
@InstanceProperty get honorificPrefix(): string { return; }
@InstanceProperty get honorificSuffix(): string { return; }
} }
export interface IContactField { export interface IContactField {
/** A string that indicates what type of field this is, home for example. */ /** A string that indicates what type of field this is, home for example. */
type: string; type: string;
/** The value of the field, such as a phone number or email address. */ /** The value of the field, such as a phone number or email address. */
value: string; value: string;
/** Set to true if this ContactField contains the user's preferred value. */ /** Set to true if this ContactField contains the user's preferred value. */
pref: boolean; pref: boolean;
} }
/** /**
* @private * @private
*/ */
export class ContactField implements IContactField { export class ContactField implements IContactField {
private _objectInstance: any; private _objectInstance: any;
constructor(type?: string, value?: string, pref?: boolean) {
this._objectInstance = new window.ContactField(type, value, pref); 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; } @InstanceProperty get type(): string { return; }
@InstanceProperty get value(): string { return; }
@InstanceProperty get pref(): boolean { return; }
} }
export interface IContactAddress { export interface IContactAddress {
/** Set to true if this ContactAddress contains the user's preferred value. */ /** Set to true if this ContactAddress contains the user's preferred value. */
pref?: boolean; pref?: boolean;
/** A string indicating what type of field this is, home for example. */ /** A string indicating what type of field this is, home for example. */
type?: string; type?: string;
/** The full address formatted for display. */ /** The full address formatted for display. */
formatted?: string; formatted?: string;
/** The full street address. */ /** The full street address. */
streetAddress?: string; streetAddress?: string;
/** The city or locality. */ /** The city or locality. */
locality?: string; locality?: string;
/** The state or region. */ /** The state or region. */
region?: string; region?: string;
/** The zip code or postal code. */ /** The zip code or postal code. */
postalCode?: string; postalCode?: string;
/** The country name. */ /** The country name. */
country?: string; country?: string;
} }
/** /**
* @private * @private
*/ */
export class ContactAddress implements IContactAddress { export class ContactAddress implements IContactAddress {
private _objectInstance: any; private _objectInstance: any;
constructor (pref?: boolean,
type?: string, constructor(pref?: boolean,
formatted?: string, type?: string,
streetAddress?: string, formatted?: string,
locality?: string, streetAddress?: string,
region?: string, locality?: string,
postalCode?: string, region?: string,
country?: string) { postalCode?: string,
this._objectInstance = new window.ContactAddress(pref, type, formatted, streetAddress, locality, region, postalCode, country); 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 pref(): boolean { return; }
@InstanceProperty get streetAddress(): string {return; } @InstanceProperty get type(): string { return; }
@InstanceProperty get locality(): string {return; } @InstanceProperty get formatted(): string { return; }
@InstanceProperty get region(): string {return; } @InstanceProperty get streetAddress(): string { return; }
@InstanceProperty get postalCode(): string {return; } @InstanceProperty get locality(): string { return; }
@InstanceProperty get country(): string {return; } @InstanceProperty get region(): string { return; }
@InstanceProperty get postalCode(): string { return; }
@InstanceProperty get country(): string { return; }
} }
export interface IContactOrganization { export interface IContactOrganization {
/** Set to true if this ContactOrganization contains the user's preferred value. */ /** Set to true if this ContactOrganization contains the user's preferred value. */
pref?: boolean; pref?: boolean;
/** A string that indicates what type of field this is, home for example. */ /** A string that indicates what type of field this is, home for example. */
type?: string; type?: string;
/** The name of the organization. */ /** The name of the organization. */
name?: string; name?: string;
/** The department the contract works for. */ /** The department the contract works for. */
department?: string; department?: string;
/** The contact's title at the organization. */ /** The contact's title at the organization. */
title?: string; title?: string;
} }
/** /**
* @private * @private
*/ */
export class ContactOrganization implements IContactOrganization { export class ContactOrganization implements IContactOrganization {
private _objectInstance: any; private _objectInstance: any;
constructor () { constructor() {
this._objectInstance = new window.ContactOrganization(); this._objectInstance = new window.ContactOrganization();
} }
@InstanceProperty get pref(): boolean {return; } @InstanceProperty get pref(): boolean { return; }
@InstanceProperty get type(): string {return; } @InstanceProperty get type(): string { return; }
@InstanceProperty get name(): string {return; } @InstanceProperty get name(): string { return; }
@InstanceProperty get department(): string {return; } @InstanceProperty get department(): string { return; }
@InstanceProperty get title(): string {return; } @InstanceProperty get title(): string { return; }
} }
/** Search options to filter navigator.contacts. */ /** Search options to filter navigator.contacts. */
export interface IContactFindOptions { export interface IContactFindOptions {
/** The search string used to find navigator.contacts. */ /** The search string used to find navigator.contacts. */
filter?: string; filter?: string;
/** Determines if the find operation returns multiple navigator.contacts. */ /** Determines if the find operation returns multiple navigator.contacts. */
multiple?: boolean; multiple?: boolean;
/* Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. */ /* Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. */
desiredFields?: string[]; desiredFields?: string[];
} }
/** /**
* @private * @private
*/ */
export class ContactFindOptions implements IContactFindOptions { export class ContactFindOptions implements IContactFindOptions {
private _objectInstance: any; private _objectInstance: any;
constructor () {
this._objectInstance = new window.ContactFindOptions(); constructor() {
} this._objectInstance = new window.ContactFindOptions();
@InstanceProperty get filter(): string {return; } }
@InstanceProperty get multiple(): boolean {return; }
@InstanceProperty get desiredFields(): any {return; } @InstanceProperty get filter(): string { return; }
@InstanceProperty get hasPhoneNumber(): boolean {return; } @InstanceProperty get multiple(): boolean { return; }
@InstanceProperty get desiredFields(): any { return; }
@InstanceProperty get hasPhoneNumber(): boolean { return; }
} }
/** /**
@ -260,9 +277,10 @@ export class ContactFindOptions implements IContactFindOptions {
repo: 'https://github.com/apache/cordova-plugin-contacts' repo: 'https://github.com/apache/cordova-plugin-contacts'
}) })
export class Contacts { export class Contacts {
static create(): Contact { static create(): Contact {
return new Contact(); return new Contact();
} }
/** /**
* Search for contacts in the Contacts list. * Search for contacts in the Contacts list.
* *
@ -285,10 +303,11 @@ export class Contacts {
errorIndex: 2 errorIndex: 2
}) })
static find(fields: string[], options?: any): Promise<any> { return; } static find(fields: string[], options?: any): Promise<any> { return; }
/** /**
* Select a single Contact. * Select a single Contact.
* @return Returns a Promise that resolves with the selected Contact * @return Returns a Promise that resolves with the selected Contact
*/ */
@Cordova() @Cordova()
static pickContact(): Promise<any> {return; } static pickContact(): Promise<any> { return; }
} }