Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- writeContactsIOS: (type, loadContacts)->
- onFindSuccessCallback = (phoneContacts) =>
- _.each(loadContacts, (loadContact)->
- newContact = undefined
- _.each(phoneContacts, (phoneContact)->
- if phoneContact.phoneNumbers && phoneContact.phoneNumbers[0].value.replace(/[(|)|+|-]|[^0-9]/g, '') == loadContact.phone.replace(/[(|)|+|-]|[^0-9]/g, '')
- newContact = phoneContact
- )
- unless newContact
- url = if type == 'event' then 'https://realtycalendar.ru' else 'http://listblacks.com/swindlers'
- newContact = navigator.contacts.create()
- newContact.phoneNumbers = [new ContactField('work', loadContact.phone, false)]
- newContact.urls = [new ContactField('e-mail', url, false)]
- name = new ContactName
- name.givenName = loadContact.given_name
- name.familyName = loadContact.family_name
- name.middleName = loadContact.middle_name
- newContact.name = name
- onCreateSuccessCallback = (_createdContact) =>
- localStorage.setItem("#{ type }_contacts_sync_date", moment().format('YYYY-MM-DD HH:mm'))
- onCreateErrorCallback = (e) =>
- alert("contact create error - #{e.message}")
- newContact.organizations = [new ContactOrganization(false, null, loadContact.contact_text)]
- newContact.save(onCreateSuccessCallback, onCreateErrorCallback)
- )
- onFindErrorCallback = (e) =>
- alert("ContactFindOptions error: #{e.message}")
- options = new ContactFindOptions
- options.filter = ""
- options.multiple = true
- fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name]
- navigator.contacts.find(fields, onFindSuccessCallback, onFindErrorCallback, options)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement