refactor(contacts):

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

View File

@ -1,6 +1,9 @@
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;
@ -32,28 +35,29 @@ export interface IContactProperties {
urls?: IContactField[];
}
/**
* @private
*/
export class Contact {
private _objectInstance: any;
@InstanceProperty get id(): string {return; }
@InstanceProperty get displayName(): string {return; }
@InstanceProperty get nickname(): ContactName {return; }
@InstanceProperty get phoneNumbers(): string {return; }
@InstanceProperty get emails(): IContactField[] {return; }
@InstanceProperty get addresses(): ContactAddress[] {return; }
@InstanceProperty get ims(): IContactField[] {return; }
@InstanceProperty get organizations(): ContactOrganization[] {return; }
@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 () {
@InstanceProperty get id(): string { return; }
@InstanceProperty get displayName(): string { return; }
@InstanceProperty get nickname(): ContactName { return; }
@InstanceProperty get phoneNumbers(): string { return; }
@InstanceProperty get emails(): IContactField[] { return; }
@InstanceProperty get addresses(): ContactAddress[] { return; }
@InstanceProperty get ims(): IContactField[] { return; }
@InstanceProperty get organizations(): ContactOrganization[] { return; }
@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) {
@ -62,19 +66,23 @@ export class Contact {
}
return newContact;
}
@CordovaInstance()
remove(): Promise<any> {return; }
remove(): Promise<any> { return; }
@CordovaInstance()
save(): Promise<any> {return; }
save(): Promise<any> { return; }
}
interface IContactError {
/** Error code */
code: number;
/** Error message */
message: string;
}
declare var ContactError: {
new(code: number): IContactError;
new (code: number): IContactError;
UNKNOWN_ERROR: number;
INVALID_ARGUMENT_ERROR: number;
TIMEOUT_ERROR: number;
@ -83,6 +91,7 @@ declare var ContactError: {
NOT_SUPPORTED_ERROR: number;
PERMISSION_DENIED_ERROR: number
};
export interface IContactName {
/** The complete name of the contact. */
formatted?: string;
@ -103,15 +112,17 @@ export interface IContactName {
*/
export class ContactName implements IContactName {
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; }
@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; }
}
export interface IContactField {
@ -128,12 +139,14 @@ export interface IContactField {
*/
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; }
@InstanceProperty get type(): string { return; }
@InstanceProperty get value(): string { return; }
@InstanceProperty get pref(): boolean { return; }
}
export interface IContactAddress {
@ -160,7 +173,8 @@ export interface IContactAddress {
*/
export class ContactAddress implements IContactAddress {
private _objectInstance: any;
constructor (pref?: boolean,
constructor(pref?: boolean,
type?: string,
formatted?: string,
streetAddress?: string,
@ -170,14 +184,15 @@ export class ContactAddress implements IContactAddress {
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; }
@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; }
}
export interface IContactOrganization {
@ -198,14 +213,14 @@ export interface IContactOrganization {
*/
export class ContactOrganization implements IContactOrganization {
private _objectInstance: any;
constructor () {
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; }
@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; }
}
/** Search options to filter navigator.contacts. */
@ -223,13 +238,15 @@ export interface IContactFindOptions {
*/
export class ContactFindOptions implements IContactFindOptions {
private _objectInstance: any;
constructor () {
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; }
@InstanceProperty get filter(): string { return; }
@InstanceProperty get multiple(): boolean { return; }
@InstanceProperty get desiredFields(): any { return; }
@InstanceProperty get hasPhoneNumber(): boolean { return; }
}
/**
@ -263,6 +280,7 @@ export class Contacts {
static create(): Contact {
return new Contact();
}
/**
* Search for contacts in the Contacts list.
*
@ -285,10 +303,11 @@ export class Contacts {
errorIndex: 2
})
static find(fields: string[], options?: any): Promise<any> { return; }
/**
* Select a single Contact.
* @return Returns a Promise that resolves with the selected Contact
*/
@Cordova()
static pickContact(): Promise<any> {return; }
static pickContact(): Promise<any> { return; }
}