-
-/*global $, tizen, App, app */
+/*jslint devel: true*/
+/*global $, tizen, App, app, localStorage: true, TemplateManager, document, window, setTimeout */
App.Ui = null;
(function () { // strict mode wrapper
'use strict';
- var prepareCallerName = function prepareCallerName(contact) {
- var callerName, firstName, lastName;
- callerName = '';
- firstName = contact.name.firstName;
- lastName = contact.name.lastName;
- if (firstName !== '' && firstName !== null) {
- callerName = firstName;
- }
- if (lastName !== '' && lastName !== null) {
- if (callerName === '') {
- callerName += lastName;
- } else {
- callerName += ' ';
- callerName += lastName;
- }
- }
- if (callerName === '') {
- callerName = 'no name';
- }
- return callerName;
- };
-
App.Ui = function App_Ui(app) {
this.app = app;
+ this.templateManager = new TemplateManager(app.config);
};
App.Ui.prototype = {
popup: null,
- showPopup: function showPopup(message, page) {
- this.popup = $('<div id="popup" data-role="popupwindow" data-style="center_basic_1btn"><p data-role="text">' + message + '</p><div data-role="button-bg"><a href="#" data-role="button" data-inline="true" onclick="closePopup();">OK</a></div></div>');
- this.page.append(this.popup);
- this.page.trigger('create');
+ prepareCallerName: function ui_prepareCallerName(contact) {
+ var callerName, firstName, lastName;
+
+ callerName = '';
+ firstName = contact.name.firstName;
+ lastName = contact.name.lastName;
+
+ if (firstName !== '' && firstName !== null) {
+ callerName = firstName;
+ }
+ if (lastName !== '' && lastName !== null) {
+ if (callerName !== '') {
+ callerName += ' ';
+ }
+ callerName += lastName;
+ }
+ if (callerName === '') {
+ callerName = 'No Name';
+ }
+ return callerName;
+ },
+
+ /**
+ *
+ * @param {string} message
+ * @param {string} onclick
+ * @returns {string}
+ */
+ getPopupHtml: function ui_getPopupHtml(message, onclick) {
+ var html = '<div id="popup" data-role="popupwindow"'
+ + ' data-style="center_basic_1btn">'
+ + '<p data-role="text">' + message + '</p>'
+ + '<div data-role="button-bg">'
+ + '<a href="#" data-role="button" data-inline="true"'
+ + ' onclick="' + onclick + '">OK</a>'
+ + '</div>'
+ + '</div>';
+ return html;
+ },
+
+ /**
+ * Show a popup
+ * @param {string} message
+ * @param {jQuery} page
+ */
+ showPopup: function ui_showPopup(message, page) {
+ this.popup = $(this.getPopupHtml(message, "app.ui.closePopup();"));
+ page.append(this.popup);
+ page.trigger('create');
this.popup.data('page', page);
this.popup.popupwindow('open');
},
- closePopup: function closePopup() {
+ closePopup: function ui_closePopup() {
var page = this.popup.data('page');
page.data('monit', '');
this.popup.popupwindow('close');
this.popup = null;
},
- disableAccept: function disableAccept() {
- $('#accept-choose').css('pointer-events', 'none').addClass('ui-disabled');
+ createListRecord: function ui_createListRecord() {
+ $.mobile.changePage('#choose');
},
- enableAccept: function enableAccept() {
- $('#accept-choose').css('pointer-events', 'auto').removeClass('ui-disabled');
- },
+ /**
+ *
+ * @param {string} text
+ * @returns {string}
+ */
+ getWaitingContentHtml: function getWaitingContentHtml(text) {
+ var html;
+ html += '<p class="defaultVeryBigText">';
+ html += text;
+ html += '</p>';
- createListRecord: function createListRecord(contacts) {
- $.mobile.changePage('#choose');
+ html += '<p class="defaultCounterText" id="counter"></p>';
+
+ return html;
},
- prepareWaitingPage: function prepareWaitingPage(title, text) {
- var waitingBox, waitingContent;
+ /**
+ *
+ * @param {string} title
+ * @param {string} text
+ */
+ prepareWaitingPage: function ui_prepareWaitingPage(title, text) {
+ var waitingBox, waitingContent,
+ contentTransfer = $('#content-transfer');
waitingBox = $('<div class="box" id="waitingBox"></div>');
- waitingContent = $('<p class="defaultVeryBigText">' + text + '</p><p class="defaultCounterText" id="counter"></p>');
+ waitingContent = $(this.getWaitingContentHtml(text));
$('#header-transfer H1').text(title);
- $('#content-transfer .ui-scrollview-view').empty();
+ contentTransfer.empty();
waitingBox.append(waitingContent);
- $('#content-transfer .ui-scrollview-view').append(waitingBox);
+ contentTransfer.append(waitingBox);
$('#content-start').trigger('create');
this.app.countDown(10, $('#counter'));
+ this.verticalCenter($('#waitingBox'));
},
- loadTemporaryContent: function loadTemporaryContent() {
+ /**
+ * @returns {string}
+ */
+ getTemporaryBoxHtml: function ui_getTemporaryBoxHtml() {
+ return '<div class="box" id="temporaryBox"></div>';
+ },
+
+ /**
+ * @returns {string}
+ */
+ showPopupWarning: function ui_showPopupWarning(){
+ setTimeout(function(){
+ $("#contact-nfc-error").popup("open",{"positionTo":"window"});
+ },500);
+ },
+
+ getTemporaryBoxContentHtml: function ui_getTemporaryBoxContentHtml() {
+ return '<p class="defaultText">'
+ + 'Default card is not defined yet!<br/>'
+ + 'Do you want to define it now?'
+ + '</p>';
+ },
+
+ loadTemporaryContent: function ui_loadTemporaryContent() {
var temporaryBox, temporaryContent, temporaryButton;
- temporaryBox = $('<div class="box" id="temporaryBox"></div>');
- temporaryContent = $('<p class="defaultText">Default card hasn\'t defined yet!<br>Do you want to define it now?</p>');
- temporaryButton = $('<div data-role="button" class="ui-btn-create">Create default card</div>');
+
+ temporaryBox = $(this.getTemporaryBoxHtml());
+ temporaryContent = $(this.getTemporaryBoxContentHtml());
+ temporaryButton = $(this.getButtonHtml('Create default card'));
temporaryButton.on('tap', function (event) {
event.preventDefault();
$.mobile.changePage('#choose');
});
- $('#content-start .ui-scrollview-view').empty();
temporaryBox.append(temporaryContent).append(temporaryButton);
- $('#content-start .ui-scrollview-view').append(temporaryBox);
- $('#content-start').trigger('create');
+
+ $('#content-start').empty().append(temporaryBox).trigger('create');
+ },
+ /**
+ *
+ * @param {string} text button text
+ * @returns {string}
+ */
+ getButtonHtml: function ui_getButtonHtml(text) {
+ return '<div data-role="button" class="ui-btn-create">'
+ + text
+ + '</div>';
+ },
+
+ /**
+ *
+ * @param {string} firstName
+ * @param {string} lastName
+ * @returns {string}
+ */
+ getCommentHtml: function ui_getCommentHtml(data) {
+ return '<div id="comment">'
+ + '<p class="comment">Your default contact</p>'
+ + '<p class="comment" id="comment-name">'
+ + data.caller + '</p>'
+ + '<p class="comment" id="comment-phone">'
+ + data.phoneNumber + '</p>'
+ + '</div>';
+ },
+
+ /**
+ * Change Contact button action
+ * @event
+ * @param {Event} event
+ */
+ changeContact: function ui_changeContact(event) {
+ event.preventDefault();
+ $.mobile.changePage('#choose');
+ },
+
+ /**
+ * @returns {jQuery}
+ */
+ getChangeContactButton: function ui_getChangeContactButton() {
+ var changeContactButton;
+ changeContactButton = $(this.getButtonHtml('Change your default contact'));
+ changeContactButton.on('tap', this.changeContact);
+ return changeContactButton;
},
- loadStartContent: function loadStartContent() {
- var startBox, gap, comment, changeContact, readFromCard, writeToCard, communicateWithOtherDevice;
+ /**
+ * Read From Card button action
+ * @event
+ * @param {Event} event
+ */
+ readFromCard: function ui_readFromCard(event) {
+ event.preventDefault();
+ if (tizen.nfc.getDefaultAdapter().powered) {
+ try {
+ $('#transfer').data('option', 'read');
+ $.mobile.changePage('#transfer');
+ } catch (e) {
+ console.error(e.message);
+ }
+ } else {
+ $.mobile.changePage('#start');
+ alert('Please turn on NFC adapter');
+ }
+ },
+
+ /**
+ * @returns {jQuery}
+ */
+ getReadFromCardButton: function ui_getReadFromCardButton() {
+ var readFromCardButton;
+ readFromCardButton = $(this.getButtonHtml('Read from card'));
+ readFromCardButton.on('tap', this.readFromCard);
+ return readFromCardButton;
+ },
+
+ /**
+ * Write To Card button action
+ * @param {Event} event
+ */
+ writeToCard: function ui_writeToCard(event) {
+ event.preventDefault();
+ if (tizen.nfc.getDefaultAdapter().powered) {
+ try {
+ $('#transfer').data('option', 'write');
+ $.mobile.changePage('#transfer');
+ } catch (e) {
+ console.error(e.message);
+ }
+ } else {
+ alert('Please turn on NFC adapter');
+ }
+ },
+
+ /**
+ * @returns {jQuery}
+ */
+ getWriteToCardButton: function ui_getWriteToCardButton() {
+ var writeToCardButton;
+ writeToCardButton = $(this.getButtonHtml('Write to card'));
+ writeToCardButton.on('tap', this.writeToCard);
+ return writeToCardButton;
+ },
+
+ /**
+ * Communicate With Other Device button action
+ * @param {type} event
+ */
+ communicateWithOtherDevice: function ui_communicateWithOtherDevice(event) {
+ event.preventDefault();
+ if (tizen.nfc.getDefaultAdapter().powered) {
+ try {
+ $('#transfer').data('option', 'communicate');
+ $.mobile.changePage('#transfer');
+ } catch (e) {
+ console.error(e.message);
+ }
+ } else {
+ alert('Please turn on NFC adapter');
+ }
+ },
+
+ /**
+ * @returns {jQuery}
+ */
+ getCommunicateWithOtherDeviceButton: function ui_getCommunicateWithOtherDeviceButton() {
+ var communicateWithOtherDeviceButton;
+ communicateWithOtherDeviceButton = $(this.getButtonHtml('Communicate with another device'));
+ communicateWithOtherDeviceButton.on('tap', this.communicateWithOtherDevice);
+ return communicateWithOtherDeviceButton;
+ },
+
+ loadStartContent: function ui_loadStartContent() {
+ var startBox, contentStart, gap, comment;
+ contentStart = $('#content-start');
startBox = $('<div class="box" id="startBox"></div>');
gap = $('<div class="gap"></div>');
- comment = $('<div id="comment"><p class="comment">Your default contact</p><p class="comment" id="comment-name">' + (localStorage.firstName || '') + ' ' + (localStorage.lastName || '') + '</p></div>');
- changeContact = $('<div data-role="button" class="ui-btn-create">Change your default contact</div>');
- changeContact.on('tap', function (event) {
- event.preventDefault();
- $.mobile.changePage('#choose');
- });
- readFromCard = $('<div data-role="button" class="ui-btn-create">Read from card</div>');
- readFromCard.on('tap', function (event) {
- event.preventDefault();
- $('#transfer').data('option', 'read');
- $.mobile.changePage('#transfer');
- });
- writeToCard = $('<div data-role="button" class="ui-btn-create">Write to card</div>');
- writeToCard.on('tap', function (event) {
- event.preventDefault();
- $('#transfer').data('option', 'write');
- $.mobile.changePage('#transfer');
- });
- communicateWithOtherDevice = $('<div data-role="button" class="ui-btn-create">Communicate with other device</div>');
- communicateWithOtherDevice.on('tap', function (event) {
- event.preventDefault();
- $('#transfer').data('option', 'communicate');
- $.mobile.changePage('#transfer');
- });
-
- $('#content-start .ui-scrollview-view').empty();
- startBox.append(changeContact).append(gap.clone()).append(readFromCard).append(gap.clone()).append(writeToCard).append(gap.clone()).append(communicateWithOtherDevice).prepend(comment);
- //$('#content-start .ui-scrollview-view').append(comment);
- $('#content-start .ui-scrollview-view').append(startBox);
- $('#content-start').trigger('create');
+ comment = $(this.getCommentHtml(localStorage));
+
+ contentStart.empty();
+ startBox
+ .append(this.getChangeContactButton())
+ .append(gap.clone())
+ .append(this.getReadFromCardButton())
+ .append(gap.clone())
+ .append(this.getWriteToCardButton())
+ .append(gap.clone())
+ .append(this.getCommunicateWithOtherDeviceButton())
+ .prepend(comment);
+
+ contentStart.append(startBox);
+ contentStart.trigger('create');
},
- loadStartPage: function loadStartPage() {
+ loadStartPage: function ui_loadStartPage() {
if (localStorage.started === undefined) {
- console.log('localStorage.started === undefined');
this.loadTemporaryContent();
} else {
- console.log('localStorage.started !== undefined');
this.loadStartContent();
}
+ $.mobile.activePage.page('refresh');
+ $('#start, #content-start').css("min-height", 0);
+ },
+
+ /**
+ *
+ * @param {string} value
+ * @param {string} label
+ * @returns {string}
+ */
+ getLiHtml: function ui_getLiHtml(value, label) {
+ var html;
+ html = '<li class="ui-li-multiline">'
+ + '<a href="#">'
+ + ((value === '' || value === 'null') ? '...' : value)
+ + '<span class="ui-li-text-sub">' + label + '</span>'
+ + '</a>'
+ + '</li>';
+ return html;
},
- prepareContactsTemplate: function prepareContactsTemplate(phone, first, last) {
- var i, ul;
+ /**
+ *
+ * @param {string} phone
+ * @param {string} first
+ * @param {string} last
+ * @returns {string}
+ */
+ getContactsUlHtml: function ui_getContactsUlHtml(phone, first, last) {
+ var html;
+ html = '<ul data-role="listview" id="contacts-data">';
+ html += this.getLiHtml(first, 'First Name');
+ html += this.getLiHtml(last, 'Last Name');
+ html += this.getLiHtml(phone, 'Phone');
+ html += '</ul>';
+ return html;
+ },
- ul = $('<ul data-role="listview" id="contacts-data"></ul>');
- $('#contact > #content-contact > .ui-scrollview-view').empty().append(ul);
+ /**
+ * @param {object} contact
+ * @returns {string}
+ */
+ getContactsListElement: function ui_getContactsListElement(contact) {
+ var html =
+ '<li class="ui-li-multiline">'
+ + '<a href="#">' + contact.caller
+ + '<span class="ui-li-text-sub">' +
+ contact.phoneNumber
+ + '</span>'
+ + '</a>'
+ + '</li>';
+ return html;
+ },
- ul.append($('<li class="ui-li-multiline"><a href="#">' + ((first === '' || first === 'null') ? '...' : first) + '<span class="ui-li-text-sub">First Name</span></a></li>'));
- ul.append($('<li class="ui-li-multiline"><a href="#">' + ((last === '' || last === 'null') ? '...' : last) + '<span class="ui-li-text-sub">Last Name</span></a></li>'));
- ul.append($('<li class="ui-li-multiline"><a href="#">' + ((phone === '' || phone === 'null') ? '...' : phone) + '<span class="ui-li-text-sub">Phone Number</span></a></li>'));
+ prepareContactsTemplate: function ui_prepareContactsTemplate(phone, first, last) {
+ $('#content-contact > .ui-scrollview-view')
+ .empty()
+ .append(this.getContactsUlHtml(phone, first, last));
+ $('#content-contact').trigger('create');
+ },
- $('#contact > #content-contact').trigger('create');
+ contactsCompare: function ui_contactsCompare(a, b) {
+ if (a.caller < b.caller) {
+ return -1;
+ }
+ if (a.caller > b.caller) {
+ return 1;
+ }
+ return 0;
},
- showContactsList: function showContactsList(contacts) {
- console.log(this, 'showContactsList');
- var self = this,
+ createSortedContactArray: function ui_createSortedContactArray(contacts) {
+ var i, len, sortedContactList = [], contact, phoneNumber;
+
+ for (i = 0, len = contacts.length; i < len; i += 1) {
+ contact = contacts[i];
+ if (contact.phoneNumbers.length === 0) {
+ phoneNumber = '';
+ } else {
+ phoneNumber = contact.phoneNumbers[0].number;
+ }
+ sortedContactList.push({
+ caller: this.prepareCallerName(contact),
+ firstName: contact.name.firstName || '',
+ lastName: contact.name.lastName || '',
+ phoneNumber: phoneNumber,
+ id: contact.id,
+ vCard: contact.convertToString('VCARD_30'),
+ contact: contact
+ });
+ }
+ sortedContactList.sort(this.contactsSort);
+
+ return sortedContactList;
+ },
+
+ createSortedContactList: function ui_createSortedContactList(contacts) {
+ var sortedContactList = this.createSortedContactArray(contacts),
ul = $('<ul data-role="listview" id="list-choose"></ul>'),
- listElementTap,
- sortedContactList = [],
i,
- j,
len,
- length,
- firstName = '',
- lastName = '',
- phoneNumber = '',
- id,
- vCard,
- listElement;
-
- $('#choose > #content-choose > .ui-scrollview-view').empty().append(ul);
+ listElement,
+ listElementTap,
+ self = this,
+ contact;
listElementTap = function (event) {
event.preventDefault();
- console.log(self, 'listElementTap');
- self.enableAccept();
- console.log($(this), 'jQuery $(this)');
- $(this).parent().find('li').css('background-color', 'inherit').removeClass('selected');
- $(this).css('background-color', '#ccc').addClass('selected');
+ $(this).addClass('selected').siblings().removeClass('selected');
+ self.app.saveDefaultCard();
};
- for (i = 0, len = contacts.length; i < len; i += 1) {
- firstName = '';
- lastName = '';
- phoneNumber = '';
- id = contacts[i].id;
- vCard = contacts[i].convertToString('VCARD_30');
- if (contacts[i].name.firstName !== null) {
- firstName = contacts[i].name.firstName;
- }
- if (contacts[i].name.lastName !== null) {
- lastName = contacts[i].name.lastName;
- }
- if (contacts[i].phoneNumbers[0] !== undefined) {
- phoneNumber = contacts[i].phoneNumbers[0].number;
- }
- sortedContactList.push({caller: prepareCallerName(contacts[i]), firstName: firstName, lastName: lastName, phoneNumber: phoneNumber, id: id, vCard: vCard, contact: contacts[i]});
- }
-
- sortedContactList.sort(function (a, b) {
- if (a.caller < b.caller) {
- return -1;
- }
- if (a.caller > b.caller) {
- return 1;
- }
- return 0;
- });
-
- for (j = 0, length = sortedContactList.length; j < length; j += 1) {
- listElement = $('<li class="ui-li-multiline" firstName="' + sortedContactList[j].firstName + '" lastName="' + sortedContactList[j].lastName + '" phoneNumber="' + sortedContactList[j].phoneNumber + '" id="' + sortedContactList[j].id + '" vCard="' + sortedContactList[j].vCard + '"><a href="#">' + sortedContactList[j].caller + '<span class="ui-li-text-sub">' + sortedContactList[j].phoneNumber + '</span></a></li>');
- if (localStorage.id === listElement.attr('id')) {
- listElement.css('background-color', '#ccc');
+ for (i = 0, len = sortedContactList.length; i < len; i += 1) {
+ contact = sortedContactList[i];
+ if (contact.phoneNumber !== '') {
+ listElement = $(this.getContactsListElement(contact));
+ listElement
+ .data('caller', contact.caller)
+ .data('firstName', contact.firstName)
+ .data('lastName', contact.lastName)
+ .data('phoneNumber', contact.phoneNumber)
+ .data('id', contact.id)
+ .data('vCard', contact.vCard);
+ if (localStorage.id === listElement.data('id')) {
+ listElement.addClass('selected');
+ }
+ ul.append(listElement);
}
- listElement.on('tap', listElementTap);
- ul.append(listElement);
}
+ ul.on('tap taphold', 'li', listElementTap);
+ return ul;
+ },
- $('#choose > #content-choose').trigger('create');
+ showContactsList: function ui_showContactsList(contacts) {
+ var ul = this.createSortedContactList(contacts);
+ $('#content-choose > .ui-scrollview-view').empty().append(ul);
+ $('#content-choose').trigger('create');
},
- moveToStartPage: function moveToStartPage(monit) {
+ moveToStartPage: function ui_moveToStartPage(monit) {
$('#start').data('monit', monit || '');
$.mobile.changePage('#start');
},
- moveToContactPage: function moveToContactPage(obj) {
+ isActivePage: function ui_isActivePage(id) {
+ return (id === $.mobile.activePage.attr("id"));
+ },
+
+ refreshIfActivePage: function ui_refreshIfActivePage(id) {
+ if (this.isActivePage(id)) {
+ $.mobile.activePage.trigger("pageshow");
+ }
+ },
+
+ moveToContactPage: function ui_moveToContactPage(obj) {
$('#start').data('monit', '');
$('#contact').data('contactsData', obj);
$.mobile.changePage('#contact');
},
+ disableSelections: function ui_disableSelections() {
+ $.mobile.tizen.disableSelection(document);
+ },
+
+ verticalCenter: function (obj) {
+ var marginTop = ($(window).height()
+ - $('[data-role=header]:visible').height()
+ - $('[data-role=footer]:visible').height()
+ - obj.outerHeight())/2;
+ if (parseInt(obj.css('margin-top'), 10) !== marginTop) {
+ obj.hide().css('margin-top', marginTop).show();
+ }
+ },
- defineEvents: function defineEvents() {
+ defineEvents: function ui_defineEvents() {
var self = this;
$('#header-start .ui-btn-back').on('tap', function (event) {
self.app.nfc.stopNFC();
});
- $('#footer-transfer').on('tap', '.ui-btn-back', function (event) {
- event.preventDefault();
- self.app.nfc.timeExpired();
+ $('#header-start').on('click', '.ui-btn-back.ui-focus', function () {
+ return false;
});
$('#footer-contact').on('tap', '.ui-btn-back', function (event) {
$.mobile.changePage('#start');
});
- $('#choose').on('pagebeforeshow', function () {
- self.disableAccept();
+ $('#footer-choose').on('tap', '.ui-btn-back', function (event) {
+ event.preventDefault();
+ $.mobile.changePage('#start');
});
$('#choose').on('pageshow', function (event) {
- console.log('#choose pageshow');
- self.app.loadContacts();
+ self.app.loadContacts(self.showContactsList.bind(self), function (e) {
+ alert('Cannot load the contacts list: ' + e.message);
+ console.error(e.message, e);
+ });
});
$('#contact').on('pageshow', function (event) {
- var phone, first, last;
- phone = $(this).data('contactsData').phone;
- first = $(this).data('contactsData').first;
- last = $(this).data('contactsData').last;
- self.prepareContactsTemplate(phone, first, last);
- });
-
- $('#accept-choose').on('tap', function (event) {
- event.preventDefault();
- self.app.saveDefaultCard();
+ var data = $(this).data('contactsData');
+ self.prepareContactsTemplate(data.phone, data.first, data.last);
});
$('#save-contact').on('tap', function (event) {
if (self.app.started) {
self.loadStartPage();
}
+ self.verticalCenter($('#startBox'));
});
$('#start').on('pageshow', function () {
- var monit, obj;
- obj = $(this);
- monit = obj.data('monit');
+ var obj = $(this), monit = obj.data('monit');
if (monit !== '' && monit !== undefined) {
self.showPopup(obj.data('monit'), obj);
}
});
- $('#transfer').on('pageshow', function () {
- console.log($('#transfer').data('option'), 'XXXXXXXXx');
- console.log($(this).data('option'), 'ZZZZZZ');
- var option = $(this).data('option');
- if (option === 'read') {
- self.prepareWaitingPage('Card to Device', 'PUT WIRELESS TAG<br>CLOSE TO<br>YOUR DEVICE');
- try {
- self.app.nfc.card.setTagDetectRead();
- } catch (err) {
- console.log(err);
+ $('#start').one('pageshow', function () {
+ setTimeout(function () {
+ self.verticalCenter($('#startBox'));
+ }, 20);
+ });
+ $( "#contact-nfc-error" ).bind({
+ popupafterclose: function(){
+ tizen.application.getCurrentApplication().exit();
+ }
+ });
+
+ document.addEventListener('tizenhwkey', function(e) {
+ if (e.keyName == "back") {
+ if ($.mobile.activePage.attr('id') === 'start') {
+ tizen.application.getCurrentApplication().exit();
+ } else {
+ self.app.nfc.timeExpired();
}
- } else if (option === 'write') {
- self.prepareWaitingPage('Device to Card', 'PUT WIRELESS TAG<br>CLOSE TO<br>YOUR DEVICE');
- try {
- self.app.nfc.card.setTagDetectWrite();
- } catch (er) {
- console.log(er);
+ }
+ });
+
+ document.addEventListener('webkitvisibilitychange', function () {
+ if(document.webkitVisibilityState === "visible") {
+ if ($.mobile.activePage.attr('id') === "choose") {
+ $.mobile.activePage.trigger('pageshow');
}
- } else {
- self.prepareWaitingPage('Device to Device', 'PUT YOUR DEVICE<br>CLOSE TO<br>OTHER DEVICE');
+ }
+ });
+
+ $('#transfer').on('pageshow', function () {
+ if (tizen.nfc.getDefaultAdapter().powered) {
try {
- self.app.nfc.peer.setTargetDetect();
+ var option = $(this).data('option');
+ if (option === 'read') {
+ self.prepareWaitingPage('Card to device', 'PUT WIRELESS TAG<br>CLOSE TO<br>YOUR DEVICE');
+ self.app.nfc.card.setTagDetectRead();
+ } else if (option === 'write') {
+ self.prepareWaitingPage('Device to card', 'PUT WIRELESS TAG<br>CLOSE TO<br>YOUR DEVICE');
+ self.app.nfc.card.setTagDetectWrite();
+ } else {
+ self.prepareWaitingPage('Device to device', 'PUT YOUR DEVICE<br>CLOSE TO<br>OTHER DEVICE');
+ self.app.nfc.peer.setTargetDetect();
+ }
} catch (e) {
- console.log(e);
+ console.error(e.message);
}
+ } else {
+ $.mobile.changePage('#start');
+ alert('Please turn on NFC adapter');
}
});
}