contact

Contacts

Returns a new contact object. Various properties like name, phone, address etc. can be set using the helper methods provided on the contact object. Use $m.saveContact() or $m.contact.save() method to save a contact.

var contactObj = $m.contact("Mowbly Support", "0999999999", "support@mowbly.com" );

The contact object does not hold any reference to a contact in the native address book until it is saved.

Syntax

        $m.contact()

$m.contact([name, phoneNumber, email])

Parameters

name

string (optional)

The name of the contact.

phoneNum

string/number (optional)

The phone number of the contact.

email

string (optional)

The email address of the contact.

Returns

Contact {object}. Object that contains the following methods,

save

Saves the specified contact to the native contacts.

contactObj.save(function(response){

    if(response.code){

        $m.toast("contact saved");

    } else {

        $m.toast(r.error.message);

    }

});

Syntax

        save(fp_callback)

Parameters

fp_callback

function  (optional)

The function that gets invoked when the save operation is completed. The function receives a response object as parameter with the following properties,

  1. code - {Number}. The value can be 0 or 1. 1 indicates that the save operation is successful. 0 indicates a failure.
  2. result - {Array}. Contact object passed. If the save operation is successful, then the contact object will have an id property that is the unique identifier of the contact in the native contacts list.
  3. error - {Object}. Available when the code is 0. The error object contains,
  1. message - {String}. A short description of the error.
  2. description - {String}. A detailed description of the error.

        Remarks

This method always creates new contact. Update of existing contact is not supported in the current         version of the framework.

view

Launches the native contact viewer to display the properties of the specified contact.

contactObj.view()

Syntax

        view()

Remarks

        In Windows Phone 7, native contact viewer is not exposed for external applications. So Mowbly framework’s native contact viewer will display.

remove

Deletes the specified contact from the native contacts list.

contactObj.remove(function(){

  if(response.code){

     $m.toast("contact removed");

   } else {

     $m.toast(r.error.message);

   }

})

Syntax

        remove(fp_callback)

Parameters

fp_callback

function (optional)

The function to execute when the remove operation is completed. The function receives a response object as parameter with the following properties,

  1. code - {Number}. The value can be 0 or 1. 1 indicates that the save operation is successful. 0 indicates a failure.
  2. result - {Array}. Contact object passed. If the save operation is successful, then the contact object will have an id property that is the unique identifier of the contact in the native contacts list.
  3. error - {Object}. Available when the code is 0. The error object contains,
  1. message - {String}. A short description of the error.
  2. description - {String}. A detailed description of the error.

Name

getName

Returns the name of the contact.

var name = contactObj.getName();

Syntax

        getName()

Return value

  1. Name - {Object}. The name object with the following properties,
  1. firstName - {String}. First name of the contact.
  2. lastName - {String}. Last name of the contact.
  3. middleName - {String}. Middle name of the contact.
  4. prefix - {String}. Prefix of the contact.
  5. suffix - {String}. Suffix of the contact.

setName

Sets the name of the contact.

contactObj.setName("cloudpact", "Mowbly")

Syntax

setName(firstName, lastName, middleName, prefix, suffix)

Parameters

firstName

string (required)

First name of the contact.

lastName

string (optional)

Last name of the contact.

middleName

string (optional)

Middle name of the contact.

prefix

string (optional)

Prefix of the contact.

suffix

string (optional)

Suffix of the contact.

Return value

  1. contact - {Contact}. Contact object.

phone

getPhone

Returns the phone number of the contact for the specified type.

var workPhone = contactObj.getPhone("work");

Syntax

getPhone(type)

Parameters

type

string (optional)

Type of the phone. Possible values are ‘work’, ‘home’, ‘mobile’, ‘other’ and ‘fax’.

Return value

  1. Phone number - {String}. The specified type of  phone number of the contact, if type is provided;  the available phone number in types ‘work’, ‘home’, ‘mobile’, ‘other’ or ‘fax’ otherwise.

getPhones

Returns the available phone numbers in the contact indexed by type.

var phones = contactObj.getPhones();

Syntax

getPhones()

Return value

  1. Phones - {Object}. Object containing none or many of the following properties,
  1. work - {String}. Work phone number of the contact.
  2. home - {String}. Home phone number of the contact.
  3. other - {String}. Other phone number of the contact.
  4. mobile - {String}. Mobile phone number of the contact.
  5. fax - {String}. Fax number of the contact.
  6. pager - {String}. Pager number of the contact.

setPhone

Sets the specified type of  phone number of the contact, if type is provided otherwise sets the work type phone number .

contactObj.setPhone(9090909090,"home");

Syntax

setPhone(phoneNumber [, type])

Parameters

phoneNumber

string/number (required)

Phone number of the contact.

type

string (optional)

Type of the phone number.  Possible values are ‘work’, ‘home’, ‘’mobile, ‘other’ and ‘fax’. Default value is ‘work’.

Return value

  1. contact - {Contact}. Contact object.

email

getEmail

Returns the specified type email of the contact, if type is provided otherwise returns the work type email.

var workEmail = contactObj.getEmail("work");

Syntax

getEmail(type)

Parameters

type

string (optional)

Type of the email. Possible values are ‘work’, ‘home’, ‘mobile’ and ‘other’.

Return value

  1. Email - {String}. The specified type of  emai of the contact, if type is provided; the available email in types ‘work’, ‘home’ or ‘other’ otherwise.

getEmails

Returns the available emails in the contact indexed by type.

var emails = contactObj.getEmails();

Syntax

getEmails()

Return value

  1. emails - {Object}. Object containing none or many of the following properties,
  1. work - {String}. Work email of the contact.
  2. home - {String}. Home email of the contact.
  3. other - {String}. Other email of the contact.

setEmail

Sets the specified type of email of the contact, if type is provided otherwise sets the work email.

contactObj.setEamil("mowbly@support.com","home");

Syntax

setEmail(emailt [,type])

Parameters

email

string (required)

Email of the contact.

type

string (optional)

Type of the email.  Possible values are ‘work’, ‘home’ and ‘other’.

Return value

  1. contact - {Contact}. Contact object.

Address

getAddress

Returns the specified type of address of the contact of type provided.

var workAddress = contactObj.getAddress("work");

Syntax

getAddress(type)

Parameters

type

string (optional)

Type of the address. Possible values are ‘work’, ‘home’ and ‘other’.

Return value

Address - {Object}. The specified type of address of the contact, if type is provided; the available address in types ‘work’, ‘home’ or ‘other’ otherwise. The address object would contain one or more of the following properties,

  1. street - {String}. Street name.
  2. city - {String}. City name.
  3. region - {String}. Region name.
  4. postalCode - {String/Number}. Postal code of the address.

getAddresses

Returns the available addresses in the contact indexed by type.

var addresses = contactObj.getAddresses();

Syntax

getAddresses()

Return value

  1. addresses - {Object}. Object containing none or many of the following properties,
  1. work - {String}. Work address of the contact.
  2. home - {String}. Home address of the contact.
  3. other - {String}. Other address of the contact.

setAddress

Sets the specified type of address of the contact, if type is provided otherwise sets the work address.

contactObj.setAddress({"street":"madhapoor","city":"Hyderabad","region":"asia",         "postalCode":"500001"},"work");

Syntax

setAddress(address, type)

Parameters

address

object (required)

Object containing none or many of the following properties,

  1. street - {Optional. String}. Street name.
  2. city - {Optional. String}. City name.
  3. region - {Optional. String}. Region name.
  4. postalCode - {Optional. String/Number}. Postal code of the address.

type

string (optional)

Type of the address.  Possible values are ‘work’, ‘home’ and ‘other’.

Return value

  1. contact - {Contact}. Contact object.

Url

getUrl

Returns the specified type of url of the contact for the type provided.

var workUrl = contactObj.getUrl("work");

Syntax

getUrl(type)

type

string (optional)

Type of the url. Possible values are ‘work’, ‘home’ and ‘other’.

Return value

  1. Url - {string}. The specified type of url of the contact, if type is provided;  the available url in types ‘work’, ‘home’ or ‘other’ otherwise.

getUrls

Returns the available urls in the contact by type.

var urls = contactObj.getUrls();

Syntax

getUrls()

Return value

  1. urls - {Object}. Object containing none or many of the following properties,

  1. work - {String}. Work url of the contact.
  2. home - {String}. Home url of the contact.
  3. other - {String}. Other url of the contact.

setUrl

Sets the specified type of  url of the contact, if type is provided otherwise sets work url.

 contactObj.setUrls("www.cloudpact.com","work");

Syntax

setUrl(url, type)

Parameters

url

string (required)

Url of the contact.

type

string (optional)

Type of the url. Possible values are ‘work’, ‘home’ and ‘other’.

Return value

  1. contact - {Contact}. Contact object.

Organization

getOrganization

Returns the organization of the contact.

var organization = contactObj.getOrganization();

Syntax

getOrganization()

Return value

  1. Organization - {Object}. The organization object with the following properties,

  1. Organization name - {String}. Name of the organization of the contact.
  2. Job title - {String}. Job title of the contact.
  3. Department -{String}. Department name of the contact.

setOrganization

Sets the organization of the contact.

contactObj.setOrganization("cloudpact","SE", "10");

Syntax

setOrganization(oganizationName, jobTitle, department)

Parameters

organizationName

string (optional)

Name of the organization of the contact.

jobTitle

string (optional)

Job title of the contact.

department

string (optional)

Department name of the contact.

Return value

  1. contact - {Contact}. Contact object.

Note

getNote

Returns any notes (additional information) stored for this contact.

var note = contactObj.getNote();

Syntax

getNote()

Return value

  1. note - {String}. Note stored for this contact.

setNote

Sets the notes (additional information) for this contact.

contactObj.setNote("mowbly webinar on 15/Dec/2012");

Syntax

setNote(note)

Parameters

note

string (optional)

The note content for the contact.

Return value

  1. contact - {Contact}. Contact object.

Birthday

getBirthday

Returns the birthday

var birthday = contactObj.getBirthday();

Syntax

getBirthday()

Return value

  1. Birthday - {String}. Birthday of the contact in format MM/DD/YYYY.

setBirthday

Sets the birthday of the contact.

contactObj.setBirthday("08/28/1989");

Syntax

setBirthday(birthday)

Parameters

birthday

string (optional)

Birthday of the contact. Supported format is MM/DD/YYYY.

Return value

  1. contact - {Contact}. Contact object.