[ContactsExchanger] updated ContactsExchanger sources
authorPiotr Dabrowski <p.dabrowski2@samsung.com>
Thu, 29 Aug 2013 09:44:25 +0000 (11:44 +0200)
committerPiotr Dabrowski <p.dabrowski2@samsung.com>
Thu, 29 Aug 2013 09:44:25 +0000 (11:44 +0200)
Change-Id: If8955dc357ee0a15e38e9425057a769c23e6c328

js/app.js
js/app.ui.js

index 372bb2c..c38e777 100644 (file)
--- 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) {
index 013c7e0..3b46782 100644 (file)
@@ -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 () {