[ContactsExchanger] updated ContactsExchanger sources
authorPiotr Dabrowski <p.dabrowski2@samsung.com>
Fri, 2 Aug 2013 11:09:45 +0000 (13:09 +0200)
committerPiotr Dabrowski <p.dabrowski2@samsung.com>
Fri, 2 Aug 2013 11:09:45 +0000 (13:09 +0200)
Change-Id: Ib7398908174dc3b6338c68a957b5f4551fd30ace

js/app.js

index b5965cd..0d399b6 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -68,9 +68,28 @@ var app = null;
                 */
                getAddressBooksSuccess: function getAddressBooksSuccess(addressbooks) {
                        if (addressbooks.length > 0) {
-                               var self = this;
+                               var self = this,
+                               resetLocalSorage = function () {
+                                       // Reset localStorage
+                                       localStorage.clear();
+                                       self.started = false;
+
+                                       // Load start page with temporary content
+                                       self.ui.moveToStartPage();
+                                       self.ui.loadTemporaryContent();
+                               };
                                this.addressBook =  addressbooks[0];
 
+                               if (localStorage.id) {
+                                       try {
+                                               this.addressBook.get(localStorage.id);
+                                       } catch (err) {
+                                               if (err.name === "NotFoundError") {
+                                                       resetLocalSorage();
+                                               }
+                                       }
+                               }
+
                                // Registers to be notified when the address book changes
                                this.addressBook.addChangeListener({
                                                oncontactsadded: function(contacts) {
@@ -80,15 +99,7 @@ var app = null;
                                                oncontactsremoved: function(ids) {
                                                        // Refresh localStorage if default contact was deleted
                                                        if (ids.indexOf(localStorage.id) >= 0) {
-
-                                                               // Reset localStorage
-                                                               localStorage.clear();
-                                                               self.started = false;
-
-                                                               // Load start page with temporary content
-                                                               self.ui.moveToStartPage();
-                                                               self.ui.loadTemporaryContent();
-
+                                                               resetLocalSorage();
                                                                alert("Your default contact has been removed. Please choose another one.");
                                                        } else {
                                                                // Refresh if choose page active