daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Oct 18th, 2018 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   writeContactsIOS: (type, loadContacts)->
  2.     onFindSuccessCallback = (phoneContacts) =>
  3.       _.each(loadContacts, (loadContact)->
  4.         newContact = undefined
  5.         _.each(phoneContacts, (phoneContact)->
  6.           if phoneContact.phoneNumbers && phoneContact.phoneNumbers[0].value.replace(/[(|)|+|-]|[^0-9]/g, '') == loadContact.phone.replace(/[(|)|+|-]|[^0-9]/g, '')
  7.             newContact = phoneContact
  8.         )
  9.  
  10.         unless newContact
  11.           url = if type == 'event' then 'https://realtycalendar.ru' else 'http://listblacks.com/swindlers'
  12.  
  13.           newContact = navigator.contacts.create()
  14.           newContact.phoneNumbers = [new ContactField('work', loadContact.phone, false)]
  15.           newContact.urls = [new ContactField('e-mail', url, false)]
  16.  
  17.           name = new ContactName
  18.           name.givenName = loadContact.given_name
  19.           name.familyName = loadContact.family_name
  20.           name.middleName = loadContact.middle_name
  21.           newContact.name = name
  22.  
  23.         onCreateSuccessCallback = (_createdContact) =>
  24.           localStorage.setItem("#{ type }_contacts_sync_date", moment().format('YYYY-MM-DD HH:mm'))
  25.  
  26.         onCreateErrorCallback = (e) =>
  27.           alert("contact create error - #{e.message}")
  28.  
  29.         newContact.organizations = [new ContactOrganization(false, null, loadContact.contact_text)]
  30.  
  31.         newContact.save(onCreateSuccessCallback, onCreateErrorCallback)
  32.       )
  33.  
  34.     onFindErrorCallback = (e) =>
  35.       alert("ContactFindOptions error: #{e.message}")
  36.  
  37.     options = new ContactFindOptions
  38.     options.filter = ""
  39.     options.multiple = true
  40.     fields = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name]
  41.     navigator.contacts.find(fields, onFindSuccessCallback, onFindErrorCallback, options)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top