You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/12/05 01:56:50 UTC
[14/28] git commit: save is linked with the proxy contact.name
doesn't exist www/Contact.js#Contact.prototype.save check on which side is
the error
save is linked with the proxy
contact.name doesn't exist www/Contact.js#Contact.prototype.save
check on which side is the error
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/5833bc0a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/5833bc0a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/5833bc0a
Branch: refs/heads/master
Commit: 5833bc0ae8ebc88f544e7e2783e49a6ee40ecdfc
Parents: c070a4f
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Thu Nov 7 15:04:11 2013 +0100
Committer: hermwong <he...@gmail.com>
Committed: Tue Dec 3 13:28:35 2013 -0800
----------------------------------------------------------------------
src/firefoxos/ContactsProxy.js | 136 +++++++++++++++++++-----------------
1 file changed, 70 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/5833bc0a/src/firefoxos/ContactsProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/ContactsProxy.js b/src/firefoxos/ContactsProxy.js
index 6c074ce..550ddf7 100644
--- a/src/firefoxos/ContactsProxy.js
+++ b/src/firefoxos/ContactsProxy.js
@@ -25,83 +25,87 @@
// http://cordova.apache.org/docs/en/2.5.0/cordova_contacts_contacts.md.html#Contact
// FxOS contact definition:
// https://developer.mozilla.org/en-US/docs/Web/API/mozContact
-function saveContact(contacts, success, fail) {
+function saveContacts(successCB, errorCB, contacts) {
// success and fail will be called every time a contact is saved
for (var contact in contacts) {
- var moz = new mozContact(),
- request;
+ var request;
+
+ function success(result) {
+ // TODO: this will need to amend the result
+ successCB(result);
+ }
- function exportContactFieldArray(contactFieldArray, key) {
- if (!key) {
- key = 'value';
- }
-
- var arr = [];
-
- for (var i in contactFieldArray) {
- arr.push(contactFieldArray[i][key]);
- };
-
- return arr;
- }
+ function exportContactFieldArray(contactFieldArray, key) {
+ if (!key) {
+ key = 'value';
+ }
- function exportAddress (addresses) {
- // TODO: check moz address format
- var arr = [];
-
- for (var i in addresses) {
- var addr = {};
+ var arr = [];
+
+ for (var i in contactFieldArray) {
+ arr.push(contactFieldArray[i][key]);
+ };
+
+ return arr;
+ }
+
+ function exportAddress (addresses) {
+ // TODO: check moz address format
+ var arr = [];
+
+ for (var i in addresses) {
+ var addr = {};
+
+ for (var key in addresses[i]) {
+ addr[key] = addresses[i][key];
+ }
- for (var key in addresses[i]) {
- addr[key] = addresses[i][key];
- }
-
- arr.push(addr);
-
- }
+ arr.push(addr);
- return arr;
- }
+ }
- // prepare mozContact object
- // TODO: find a way to link existing mozContact and Contact
- // (by ID?)
- moz.init({
- name: [contact.name.familyName,
- contact.name.givenName,
- contact.name.middleName,
- contact.name.nickname],
- honorificPrefix: [contact.name.honorificPrefix],
- givenName: [contact.name.givenName],
- familyName: [contact.name.familyName],
- honorificSuffix: [contact.name.honorificSuffix],
- nickname: [contact.nickname],
- email: exportContactFieldArray(contact.emails),
- // photo: Blob
- // url: Array with metadata (?)
- category: exportContactFieldArray(contact.categories),
- adr: exportAddress(contact.addresses),
- tel: exportContactFieldArray(contact.phoneNumbers),
- org: exportContactFieldArray(contact.organizations, 'name'),
- jobTitle: exportContactFieldArray(contact.organizations, 'title'),
- bday: contact.birthday,
- note: contact.note,
- // impp: exportIM(contact.ims), TODO: find the moz impp definition
- // anniversary
- // sex
- // genderIdentity
- // key
- });
-
- request = navigator.mozContacts.save(moz);
- request.onsuccess = success;
- request.onerror = fail;
+ return arr;
+ }
+
+ // prepare mozContact object
+ // TODO: find a way to link existing mozContact and Contact by ID
+ var moz = new mozContact({
+ name: [contact.name.familyName,
+ contact.name.givenName,
+ contact.name.middleName,
+ contact.name.nickname],
+ honorificPrefix: [contact.name.honorificPrefix],
+ givenName: [contact.name.givenName],
+ familyName: [contact.name.familyName],
+ honorificSuffix: [contact.name.honorificSuffix],
+ nickname: [contact.nickname],
+ email: exportContactFieldArray(contact.emails),
+ // photo: Blob
+ // url: Array with metadata (?)
+ category: exportContactFieldArray(contact.categories),
+ adr: exportAddress(contact.addresses),
+ tel: exportContactFieldArray(contact.phoneNumbers),
+ org: exportContactFieldArray(contact.organizations, 'name'),
+ jobTitle: exportContactFieldArray(contact.organizations, 'title'),
+ bday: contact.birthday,
+ note: contact.note,
+ // impp: exportIM(contact.ims), TODO: find the moz impp definition
+ // anniversary
+ // sex
+ // genderIdentity
+ // key
+ });
+
+ request = navigator.mozContacts.save(moz);
+ request.onsuccess = success;
+ request.onerror = errorCB;
}
}
module.exports = {
- saveContact: saveContact,
- cleanup: function(){}
+ save: saveContacts,
+ remove: function(){},
+ search: function(){},
};
require("cordova/firefoxos/commandProxy").add("Contacts", module.exports);