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() {
$.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
*/
if (localStorage.id) {
try {
- this.addressBook.get(localStorage.id);
+ this.updateDefaultCard(
+ this.addressBook.get(localStorage.id)
+ );
} catch (err) {
if (err.name === "NotFoundError") {
resetLocalSorage();
// 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 {
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) {
temporaryContent = $(this.getTemporaryBoxContentHtml());
temporaryButton = $(this.getButtonHtml('Create default card'));
- temporaryButton.on('tap', function (event) {
+ temporaryButton.on('click', function (event) {
event.preventDefault();
$.mobile.changePage('#choose');
});
ul.append(listElement);
}
}
- ul.on('tap taphold', 'li', listElementTap);
+ ul.on('tap taphold click', 'li', listElementTap);
return ul;
},
refreshIfActivePage: function ui_refreshIfActivePage(id) {
if (this.isActivePage(id)) {
- $.mobile.activePage.trigger("pageshow");
+ $.mobile.activePage
+ .trigger("pagebeforeshow")
+ .trigger("pageshow");
}
},
self.showPopup(obj.data('monit'), obj);
}
self.verticalCenter($('.box'));
+ setTimeout(function () {
+ self.verticalCenter($('.box'));
+ }, 30);
});
$('#start').one('pageshow', function () {