From 0edf1394c6ee7005ecea643034cc795a4027d812 Mon Sep 17 00:00:00 2001
From: Piotr Dabrowski
Date: Thu, 29 Aug 2013 11:44:25 +0200
Subject: [PATCH] [ContactsExchanger] updated ContactsExchanger sources
Change-Id: If8955dc357ee0a15e38e9425057a769c23e6c328
---
js/app.js | 37 +++++++++++++++++++++++++++++++------
js/app.ui.js | 11 ++++++++---
2 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/js/app.js b/js/app.js
index 372bb2c..c38e777 100644
--- a/js/app.js
+++ b/js/app.js
@@ -44,10 +44,8 @@ var app = null;
this.config = new Config();
this.ui = new App.Ui(this);
this.nfc = new App.NFCControl(this);
-
this.ui.defineEvents();
- this.initAddressBook();
- this.nfc.startNFC();
+ this.initAddressBook(this.nfc.startNFC.bind(this.nfc));
},
saveDefaultCard: function saveDefaultCard() {
@@ -63,6 +61,15 @@ var app = null;
$.mobile.changePage('#start');
},
+ updateDefaultCard: function updateDefaultCard (contact) {
+ localStorage.caller = this.ui.prepareCallerName(contact);
+ localStorage.firstName = contact.name.firstName || '';
+ localStorage.lastName = contact.name.lastName || '';
+ localStorage.phoneNumber = contact.phoneNumbers[0].number;
+ localStorage.id = contact.id;
+ localStorage.vCard = contact.convertToString('VCARD_30');
+ },
+
/**
* @param {Array} addressbooks
*/
@@ -82,7 +89,9 @@ var app = null;
if (localStorage.id) {
try {
- this.addressBook.get(localStorage.id);
+ this.updateDefaultCard(
+ this.addressBook.get(localStorage.id)
+ );
} catch (err) {
if (err.name === "NotFoundError") {
resetLocalSorage();
@@ -105,6 +114,19 @@ var app = null;
// Refresh if choose page active
self.ui.refreshIfActivePage("choose");
}
+ },
+ oncontactsupdated: function (contacts) {
+ var index = contacts.length;
+
+ // check if default contact was updated
+ while (index--) {
+ if (contacts[index].id === localStorage.id) {
+ self.updateDefaultCard(contacts[index]);
+ break;
+ }
+ }
+
+ self.ui.refreshIfActivePage("start");
}
});
} else {
@@ -120,10 +142,13 @@ var app = null;
console.error('getAddressBooks() error: ' + e.message);
},
- initAddressBook: function initAddressBook() {
+ initAddressBook: function initAddressBook(callback) {
try {
tizen.contact.getAddressBooks(
- this.getAddressBooksSuccess.bind(this),
+ function (addressbook) {
+ this.getAddressBooksSuccess(addressbook)
+ callback();
+ }.bind(this),
this.getAddressBooksError.bind(this)
);
} catch (e) {
diff --git a/js/app.ui.js b/js/app.ui.js
index 013c7e0..3b46782 100644
--- a/js/app.ui.js
+++ b/js/app.ui.js
@@ -144,7 +144,7 @@ App.Ui = null;
temporaryContent = $(this.getTemporaryBoxContentHtml());
temporaryButton = $(this.getButtonHtml('Create default card'));
- temporaryButton.on('tap', function (event) {
+ temporaryButton.on('click', function (event) {
event.preventDefault();
$.mobile.changePage('#choose');
});
@@ -447,7 +447,7 @@ App.Ui = null;
ul.append(listElement);
}
}
- ul.on('tap taphold', 'li', listElementTap);
+ ul.on('tap taphold click', 'li', listElementTap);
return ul;
},
@@ -468,7 +468,9 @@ App.Ui = null;
refreshIfActivePage: function ui_refreshIfActivePage(id) {
if (this.isActivePage(id)) {
- $.mobile.activePage.trigger("pageshow");
+ $.mobile.activePage
+ .trigger("pagebeforeshow")
+ .trigger("pageshow");
}
},
@@ -540,6 +542,9 @@ App.Ui = null;
self.showPopup(obj.data('monit'), obj);
}
self.verticalCenter($('.box'));
+ setTimeout(function () {
+ self.verticalCenter($('.box'));
+ }, 30);
});
$('#start').one('pageshow', function () {
--
2.7.4