*/
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) {
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