Created
January 9, 2012 20:19
-
-
Save mgcrea/1584728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var options = new ContactFindOptions(); | |
options.filter = operation.filter || ''; | |
options.multiple = true; | |
//d&&console.log('navigator.contacts.find', [self.deviceFields, options]); | |
navigator.contacts.find(self.deviceFields, | |
function(deviceContacts) { | |
// Loop over deviceContacts and create Contact model instances | |
var contacts = []; | |
for (var i = 0; i < deviceContacts.length; i++) { | |
var deviceContact = deviceContacts[i]; | |
// Force strings | |
if(!deviceContact.name.familyName) deviceContact.name.familyName = ''; | |
if(!deviceContact.name.givenName) deviceContact.name.givenName = ''; | |
// Require one name | |
if(!deviceContact.name.familyName && !deviceContact.name.givenName) continue; | |
// givenName -> familyName | |
/*if(!deviceContact.name.familyName) { | |
deviceContact.name.familyName = deviceContact.name.givenName; | |
deviceContact.name.givenName = ''; | |
}*/ | |
//console.warn(i, deviceContact); | |
var contact = new self.model(deviceContact); | |
//d&&console.log(displayName + ' ~ Importing new contact from deviceContact.', [contact, deviceContact]); | |
contact.deviceContact = deviceContact; | |
contacts.push(contact); | |
} | |
//return model instances in a result set | |
operation.resultSet = new Ext.data.ResultSet({ | |
records: contacts, | |
total : contacts.length, | |
loaded : true | |
}); | |
// Announce success | |
operation.setSuccessful(); | |
operation.setCompleted(); | |
// Finish with callback | |
if (typeof callback == 'function') { | |
callback.call(scope, operation); | |
} | |
}, | |
function (error) { | |
throw new Error('Something went wrong during Phonegap.contacts.find() operation.'); | |
}, | |
options | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment