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, declare var window: any,
navigator: any; navigator: any;
export interface IContactProperties { export interface IContactProperties {
/** A globally unique identifier. */ /** A globally unique identifier. */
id?: string; id?: string;
@ -32,28 +35,29 @@ export interface IContactProperties {
urls?: IContactField[]; 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 () {
constructor() {
this._objectInstance = navigator.contacts.create(); this._objectInstance = navigator.contacts.create();
} }
clone(): Contact { clone(): Contact {
let newContact = new Contact(); let newContact = new Contact();
for (let prop in this) { for (let prop in this) {
@ -62,19 +66,23 @@ export class Contact {
} }
return newContact; return newContact;
} }
@CordovaInstance() @CordovaInstance()
remove(): Promise<any> {return; } remove(): Promise<any> { return; }
@CordovaInstance() @CordovaInstance()
save(): Promise<any> {return; } 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;
@ -83,6 +91,7 @@ declare var ContactError: {
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;
@ -103,15 +112,17 @@ export interface IContactName {
*/ */
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) { constructor(formatted?: string, familyName?: string, givenName?: string, middleName?: string, honorificPrefix?: string, honorificSuffix?: string) {
this._objectInstance = new window.ContactName(formatted, familyName, givenName, middleName, honorificPrefix, honorificSuffix); this._objectInstance = new window.ContactName(formatted, familyName, givenName, middleName, honorificPrefix, honorificSuffix);
} }
@InstanceProperty get formatted(): string {return; }
@InstanceProperty get familyName(): string {return; } @InstanceProperty get formatted(): string { return; }
@InstanceProperty get givenName(): string {return; } @InstanceProperty get familyName(): string { return; }
@InstanceProperty get middleName(): string {return; } @InstanceProperty get givenName(): string { return; }
@InstanceProperty get honorificPrefix(): string {return; } @InstanceProperty get middleName(): string { return; }
@InstanceProperty get honorificSuffix(): string {return; } @InstanceProperty get honorificPrefix(): string { return; }
@InstanceProperty get honorificSuffix(): string { return; }
} }
export interface IContactField { export interface IContactField {
@ -128,12 +139,14 @@ export interface IContactField {
*/ */
export class ContactField implements IContactField { export class ContactField implements IContactField {
private _objectInstance: any; private _objectInstance: any;
constructor(type?: string, value?: string, pref?: boolean) { constructor(type?: string, value?: string, pref?: boolean) {
this._objectInstance = new window.ContactField(type, value, pref); this._objectInstance = new window.ContactField(type, value, pref);
} }
@InstanceProperty get type(): string {return; }
@InstanceProperty get value(): string {return; } @InstanceProperty get type(): string { return; }
@InstanceProperty get pref(): boolean {return; } @InstanceProperty get value(): string { return; }
@InstanceProperty get pref(): boolean { return; }
} }
export interface IContactAddress { export interface IContactAddress {
@ -160,7 +173,8 @@ export interface IContactAddress {
*/ */
export class ContactAddress implements IContactAddress { export class ContactAddress implements IContactAddress {
private _objectInstance: any; private _objectInstance: any;
constructor (pref?: boolean,
constructor(pref?: boolean,
type?: string, type?: string,
formatted?: string, formatted?: string,
streetAddress?: string, streetAddress?: string,
@ -170,14 +184,15 @@ export class ContactAddress implements IContactAddress {
country?: string) { country?: string) {
this._objectInstance = new window.ContactAddress(pref, type, formatted, streetAddress, locality, region, postalCode, country); 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 pref(): boolean { return; }
@InstanceProperty get formatted(): string {return; } @InstanceProperty get type(): string { return; }
@InstanceProperty get streetAddress(): string {return; } @InstanceProperty get formatted(): string { return; }
@InstanceProperty get locality(): string {return; } @InstanceProperty get streetAddress(): string { return; }
@InstanceProperty get region(): string {return; } @InstanceProperty get locality(): string { return; }
@InstanceProperty get postalCode(): string {return; } @InstanceProperty get region(): string { return; }
@InstanceProperty get country(): string {return; } @InstanceProperty get postalCode(): string { return; }
@InstanceProperty get country(): string { return; }
} }
export interface IContactOrganization { export interface IContactOrganization {
@ -198,14 +213,14 @@ export interface IContactOrganization {
*/ */
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. */
@ -223,13 +238,15 @@ export interface IContactFindOptions {
*/ */
export class ContactFindOptions implements IContactFindOptions { export class ContactFindOptions implements IContactFindOptions {
private _objectInstance: any; private _objectInstance: any;
constructor () {
constructor() {
this._objectInstance = new window.ContactFindOptions(); this._objectInstance = new window.ContactFindOptions();
} }
@InstanceProperty get filter(): string {return; }
@InstanceProperty get multiple(): boolean {return; } @InstanceProperty get filter(): string { return; }
@InstanceProperty get desiredFields(): any {return; } @InstanceProperty get multiple(): boolean { return; }
@InstanceProperty get hasPhoneNumber(): boolean {return; } @InstanceProperty get desiredFields(): any { return; }
@InstanceProperty get hasPhoneNumber(): boolean { return; }
} }
/** /**
@ -263,6 +280,7 @@ 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; }
} }