--- /dev/null
+Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Flora License, Version 1.
+Please, see the LICENSE.Flora file for Flora License terms and conditions.
+
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://sample-web-application.tizen.org/contacts-exchanger" version="2.1.0" viewmodes="maximized">
- <tizen:application id="FkdFMekdRH" required_version="1.0"/>
+ <tizen:application id="CUflbBqLYv.ContactsExchanger" package="CUflbBqLYv" required_version="2.1"/>
<tizen:app-control>
- <src name="index.html"/>
- <operation name="http://tizen.org/appcontrol/operation/nfc_empty_type"/>
- <mime name="*/*"/>
+ <tizen:src name="index.html"/>
+ <tizen:operation name="http://tizen.org/appcontrol/operation/nfc_empty_type"/>
+ <tizen:uri name=""/>
+ <tizen:mime name="*/*"/>
</tizen:app-control>
<tizen:app-control>
- <src name="index.html"/>
- <operation name="http://tizen.org/appcontrol/operation/nfc_well_known_type"/>
- <mime name="*/*"/>
+ <tizen:src name="index.html"/>
+ <tizen:operation name="http://tizen.org/appcontrol/operation/nfc_well_known_type"/>
+ <tizen:uri name=""/>
+ <tizen:mime name="*/*"/>
</tizen:app-control>
<tizen:app-control>
- <src name="index.html"/>
- <operation name="http://tizen.org/appcontrol/operation/nfc_mime_type"/>
- <mime name="*/*"/>
+ <tizen:src name="index.html"/>
+ <tizen:operation name="http://tizen.org/appcontrol/operation/nfc_mime_type"/>
+ <tizen:uri name=""/>
+ <tizen:mime name="*/*"/>
</tizen:app-control>
<tizen:app-control>
- <src name="index.html"/>
- <operation name="http://tizen.org/appcontrol/operation/nfc_uri_type"/>
- <mime name="*/*"/>
+ <tizen:src name="index.html"/>
+ <tizen:operation name="http://tizen.org/appcontrol/operation/nfc_uri_type"/>
+ <tizen:uri name=""/>
+ <tizen:mime name="*/*"/>
</tizen:app-control>
<content src="index.html"/>
<icon src="icon.png"/>
<tizen:privilege name="http://tizen.org/privilege/nfc.common"/>
<tizen:privilege name="http://tizen.org/privilege/nfc.p2p"/>
<tizen:privilege name="http://tizen.org/privilege/nfc.tag"/>
- <tizen:privilege name="http://tizen.org/privilege/tizen"/>
- <tizen:setting screen-orientation="portrait" context-menu="enable" background-support="enable" encryption="disable" nodisplay="false"/>
- <tizen:setting context-menu="enable"/>
+ <tizen:setting screen-orientation="portrait" context-menu="disable" background-support="enable" encryption="disable" install-location="auto"/>
</widget>
}
#comment {
- position: absolute;
- top: -50px;
left: 0px;
margin: 0 auto;
right: 0px;
+ width: inherit;
}
.box {
margin: 0px;
- padding: 0px;
- margin-top: 50%;
+ padding: 0 32px;
+ display: table-cell;
+ vertical-align: middle;
+ height: inherit;
+ width: 100%;
+ min-width: 296px;
+ text-align: center;
}
.gap {
width: 40%;
}
+#list-choose li.ui-btn-down-s a {
+ color: black;
+}
+
#comment-name {
white-space: nowrap;
overflow: hidden !important;
#accept-choose {
width: auto;
}
+
.defaultVeryBigText {
font-size: 30px;
margin: 0px;
padding: 0px;
text-align: center;
line-height: 100px;
+}
+
+.ui-btn-create span.ui-btn-text {
+ font-size: .8rem;
+}
+
+#header-start .ui-title, #header-choose .ui-title, #header-contact .ui-title {
+ font-size: 1.1rem;
+}
+
+/* overwrite web-ui-fw styles for popupwindow button */
+.ui-popupwindow .center_basic_1btn .popup-button-bg .ui-btn {
+ width: 90%;
+ height: auto;
+}
+#list-choose li.selected {
+ background-color: #ccc;
+}
+
+.ui-content {
+ padding: 0;
+}
}
\ No newline at end of file
<head>
<meta charset="utf-8"/>
<meta name="description" content="Contacts-exchanger"/>
+ <meta name="viewport" content="width=360, user-scalable=no"/>
- <title>Contacts-exchanger</title>
+ <title>ContactsExchanger</title>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/jquery.js"></script>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js"></script>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.js" data-framework-theme="tizen-white" data-framework-viewport-scale="false"></script>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/jquery.min.js"></script>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.min.js"></script>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.min.js" data-framework-theme="tizen-white" data-framework-viewport-scale="false"></script>
<script type="text/javascript" src="./js/app.js"></script>
+ <script type="text/javascript" src="./js/app.config.js"></script>
<script type="text/javascript" src="./js/app.ui.js"></script>
+ <script type="text/javascript" src="./js/app.ui.templateManager.js"></script>
<script type="text/javascript" src="./js/app.nfc.js"></script>
<script type="text/javascript" src="./js/app.nfc.card.js"></script>
<script type="text/javascript" src="./js/app.nfc.peer.js"></script>
<body>
<div id="start" data-role="page" data-add-back-btn="header" data-footer-exist="true">
<div data-role="header" id="header-start" data-position="fixed">
- <h1>Contacts-exchanger</h1>
+ <h1>CONTACTS EXCHANGER</h1>
</div>
- <div data-role="content" id="content-start"></div>
-
- <div data-role="footer" id="footer-start" data-position="fixed">
- <h4></h4>
- </div>
+ <div data-role="content" id="content-start" data-scroll="none"></div>
</div>
<div id="choose" data-role="page" data-add-back-btn="footer" data-footer-exist="true">
<div data-role="header" id="header-choose" data-position="fixed">
<h1>Contacts list</h1>
- <a data-role="button" id="accept-choose">Accept</a>
</div>
<div data-role="content" id="content-choose"></div>
- <div data-role="footer" id="footer-choose" data-position="fixed">
- <h4></h4>
- </div>
+ <div data-role="footer" id="footer-choose" data-position="fixed"></div>
</div>
<div id="transfer" data-role="page">
<h1></h1>
</div>
- <div data-role="content" id="content-transfer"></div>
-
- <div data-role="footer" id="footer-transfer" data-position="fixed">
- <h4></h4>
- </div>
+ <div data-role="content" id="content-transfer" data-scroll="none"></div>
</div>
<div id="contact" data-role="page" data-add-back-btn="footer" data-footer-exist="true">
<div data-role="content" id="content-contact"></div>
- <div data-role="footer" id="footer-contact" data-position="fixed">
- <h4></h4>
- </div>
+ <div data-role="footer" id="footer-contact" data-position="fixed"></div>
</div>
</body>
--- /dev/null
+/**
+ * @class Config
+ */
+function Config() {
+ 'use strict';
+}
+
+(function () { // strict mode wrapper
+ 'use strict';
+ Config.prototype = {
+
+ properties: {
+ 'templateDir': 'templates',
+ 'templateExtension': '.tpl'
+ },
+
+ /**
+ * Returns config value
+ */
+ get: function (value, defaultValue) {
+
+ if (this.properties.hasOwnProperty(value)) {
+ return this.properties[value];
+ }
+ return defaultValue;
+ }
+ };
+}());
*/
/*jslint devel: true*/
-/*global $, tizen */
+/*global $, tizen, Config */
var App = null;
(function () { // strict mode wrapper
'use strict';
- function checkCharsSize(string) {
- var i, result = '', length = string.length;
- for (i = 0; i < length; i += 1) {
- if (string.charCodeAt(i) < 256) {
- result += string[i];
- }
- }
- return result;
- }
-
/**
* Creates a new application object
*
nfc: null,
init: function appInit() {
+ this.config = new Config();
this.ui = new App.Ui(this);
this.nfc = new App.NFCControl(this);
+ this.ui.disableSelections();
this.ui.defineEvents();
this.initAddressBook();
this.nfc.startNFC();
saveDefaultCard: function saveDefaultCard() {
var elementSelected = $('#list-choose li.selected');
- console.log(elementSelected);
localStorage.started = true;
localStorage.id = elementSelected.attr('id');
localStorage.firstName = elementSelected.attr('firstName');
$.mobile.changePage('#start');
},
- initAddressBook: function initAddressBook() {
- var addressBooksCB = function (addressbooks) {
- console.log('addressBooksCB success');
- if (addressbooks.length > 0) {
- this.addressBook = addressbooks[0];
- } else {
- console.log('addressBook: failed');
- }
- },
- errorCB = function (e) {
- console.log('problem with getAddressBooks() method: ' + e.message);
- };
+ /**
+ * @param {Array} addressbooks
+ */
+ getAddressBooksSuccess: function getAddressBooksSuccess(addressbooks) {
+ if (addressbooks.length > 0) {
+ this.addressBook = addressbooks[0];
+ } else {
+ console.error('initAddressBook failed');
+ }
+ },
+ /**
+ *
+ * @param {Error} e
+ */
+ getAddressBooksError: function getAddressBooksError(e) {
+ console.log('getAddressBooks() error: ' + e.message);
+ },
+
+ initAddressBook: function initAddressBook() {
try {
- tizen.contact.getAddressBooks(addressBooksCB.bind(this), errorCB);
+ tizen.contact.getAddressBooks(
+ this.getAddressBooksSuccess.bind(this),
+ this.getAddressBooksError.bind(this)
+ );
} catch (e) {
- console.log('problem with getAddressBooks() method: ' + e.message);
+ console.error('getAddressBooks() error: ' + e.message);
}
},
obj.text(time);
if (time > 0) {
time -= 1;
- this.timeOutHandler = setTimeout(function () { this.countDown(time, obj); }.bind(this), 1000);
+ this.timeOutHandler = setTimeout(function () {
+ this.countDown(time, obj);
+ }.bind(this), 1000);
} else {
this.nfc.timeExpired();
}
},
saveContact: function saveContact() {
- var phone, first, last, contactPage = $('#contact'), contact = null;
- phone = contactPage.data('contactsData').phone;
- first = contactPage.data('contactsData').first;
- last = contactPage.data('contactsData').last;
+ var contact = null,
+ data = $('#contact').data('contactsData');
try {
- contact = new tizen.Contact({name: new tizen.ContactName({firstName: first, lastName: last}), phoneNumbers: [new tizen.ContactPhoneNumber(phone)]});
+ contact = new tizen.Contact({
+ name: new tizen.ContactName({
+ firstName: data.first,
+ lastName: data.last
+ }),
+ phoneNumbers: [new tizen.ContactPhoneNumber(data.phone)]
+ });
this.addressBook.add(contact);
- this.app.ui.moveToStartPage('New contact added');
+ this.ui.moveToStartPage('New contact added');
} catch (err) {
- this.app.ui.moveToStartPage('Problem with new contact adding');
- console.log('The following error occurred while adding: ' + err.name);
+ this.ui.moveToStartPage('Problem with new contact adding');
+ console.error('saveContact error:' + err.name);
}
},
- loadContacts: function loadContacts() {
- var self = this,
- errorCB = function (e) {
- console.log('problem with find() method: ' + e.message);
- };
- this.addressBook.find(function (contacts) {
- self.ui.showContactsList(contacts);
- }, errorCB);
+ /**
+ * Load contacts from the address book and pass the result to a callback
+ *
+ * @param {function} successCallback
+ * @param {function} errorCallback
+ */
+ loadContacts: function loadContacts(successCallback, errorCallback) {
+ this.addressBook.find(successCallback, errorCallback);
}
};
(function () { // strict mode wrapper
'use strict';
- App.NFCCard = function (nfcControl) {
- this.app = nfcControl.app;
- console.log('NFCCard: ', nfcControl);
+ /**
+ * Constructs NFCCard
+ * @constructor
+ * @param {NFCControl} nfc
+ */
+ App.NFCCard = function nfc_NFCCard(nfc) {
+ this.nfc = nfc;
};
App.NFCCard.prototype = {
- prepareForNFC: null,
-
- /* card read */
-
- readMessageErr: function readMessageErr(e) {
- app.nfc.timeExpired('Read error!');
+ readMessageErr: function nfc_card_readMessageErr(e) {
+ console.error('Read error! ' + e.message, e);
+ this.nfc.timeExpired('Read error! ' + e.message);
},
- sucTagReadAttach: function sucTagReadAttach(tag) {
- if (tag.isSupportedNDEF) {
- tag.readNDEF(this.app.nfc.readMessage.bind(this.app.nfc), this.readMessageErr.bind(this));
- } else {
- console.log("This Tag doesn't support NDEF");
+ /**
+ * Read contents from a tag
+ * @param {NFCTag} tag
+ */
+ sucTagReadAttach: function nfc_card_sucTagReadAttach(tag) {
+ try {
+ if (!tag.isSupportedNDEF) {
+ throw {message: "This tag doesn't support NDEF"};
+ }
+ tag.readNDEF(
+ this.nfc.readMessage.bind(this.nfc),
+ this.readMessageErr.bind(this)
+ );
+ } catch (e) {
+ this.readMessageErr(e);
}
},
- setTagDetectRead: function setTagDetectRead() {
- /*
- var err, suc;
- err = function (e) {
- console.log('Tag Listen Error: ' + e.message);
- };
- */
- var suc = { onattach: this.sucTagReadAttach.bind(this), ondetach: this.app.nfc.sucDetach.bind(this.app.nfc) };
+ /**
+ * Set tag listener
+ */
+ setTagDetectRead: function nfc_card_setTagDetectRead() {
try {
- //nfcAdapter.setTagListener(suc, err);
- app.nfc.nfcAdapter.setTagListener(suc);
+ this.nfc.nfcAdapter.setTagListener({
+ onattach: this.sucTagReadAttach.bind(this),
+ ondetach: this.nfc.sucDetach.bind(this.nfc)
+ });
} catch (error) {
- console.log('error: ' + error.message);
+ this.readMessageErr(error);
}
},
-
- /* card write */
-
- sucSend: function sucSend() {
- console.log('sucSend');
- app.nfc.timeExpired('Send success!');
+ sucSend: function nfc_card_sucSend() {
+ this.nfc.timeExpired('Send success!');
},
- errSend: function errSend(e) {
- console.log('errSend');
- app.nfc.timeExpired('Send problem! ' + e.message);
+ errSend: function nfc_card_errSend(e) {
+ console.warn('errSend', e);
+ this.nfc.timeExpired('Write error! ' + e.message);
},
- sucTagWriteAttach: function sucTagWriteAttach(tag) {
+ sucTagWriteAttach: function nfc_card_sucTagWriteAttach(tag) {
var newMessage = null,
- separator = String.fromCharCode(30),
- endOfText = String.fromCharCode(3),
- fullContact = localStorage.phoneNumber + separator + localStorage.firstName + separator + localStorage.lastName,
- prepareForNFC;
-
- prepareForNFC = this.prepareForNFC || function prepareForNFC(contact) {
- if (contact.length > 31) {
- contact = contact.substring(0, 31);
- if (contact[29] !== separator) {
- contact = contact.substring(0, 30) + endOfText;
- }
- }
- return contact;
- };
-
- fullContact = prepareForNFC(fullContact);
+ fullContact = '';
try {
- newMessage = this.app.nfc.phoneNumber2NDEF(fullContact);
- } catch (err) {
- console.log("NDEFMessage problem: " + err.message);
- }
-
- if (tag.isSupportedNDEF) {
- tag.writeNDEF(newMessage, this.sucSend.bind(this), this.errSend.bind(this));
- } else {
- console.log("This Tag doesn't support NDEF");
+ fullContact = this.nfc.prepareForNFC(localStorage);
+ newMessage = this.nfc.phoneNumber2NDEF(fullContact);
+ if (!tag.isSupportedNDEF) {
+ throw {message: "This tag doesn't support NDEF"};
+ }
+ tag.writeNDEF(
+ newMessage,
+ this.sucSend.bind(this),
+ this.errSend.bind(this)
+ );
+ } catch (e) {
+ this.errSend(e);
}
},
- setTagDetectWrite: function setTagDetectWrite() {
- /*
- var err, suc;
- err = function (e) {
- console.log('Tag Listen Error: ' + e.message);
+ setTagDetectWrite: function nfc_card_setTagDetectWrite() {
+ var suc = {
+ onattach: this.sucTagWriteAttach.bind(this),
+ ondetach: this.nfc.sucDetach.bind(this.nfc)
};
- */
- var suc = { onattach: this.sucTagWriteAttach.bind(this), ondetach: this.app.nfc.sucDetach };
+
try {
- //nfcAdapter.setTagListener(suc, err);
- app.nfc.nfcAdapter.setTagListener(suc);
+ this.nfc.nfcAdapter.setTagListener(suc);
} catch (error) {
- console.log('error: ' + error.message);
+ console.error(error);
}
}
(function () { // strict mode wrapper
'use strict';
- App.NFCControl = function (app) {
- console.log('NFCControl: ', app);
+ /**
+ * Constructs NFCControl
+ * @constructor
+ * @param {App} app
+ */
+ App.NFCControl = function NFCControl(app) {
this.app = app;
this.init();
};
nfcTarget: null,
nfcStateMemory: false,
- init: function init() {
+ /**
+ * Initialize NFC application module
+ */
+ init: function nfc_init() {
this.card = new App.NFCCard(this);
this.peer = new App.NFCPeer(this);
+ this.separator = String.fromCharCode(30);
+ this.endOfText = String.fromCharCode(3);
},
-
- timeExpired: function timeExpired(monit) {
- console.log('timeExpired: ', this);
+ /**
+ * Disable tag/target detection and move to start page
+ *
+ * @param {string} monit message text to be displayed
+ */
+ timeExpired: function nfc_timeExpired(monit) {
clearTimeout(this.app.timeOutHandler);
- console.log(this.nfcTarget, 'this.nfcTarget');
this.unsetTargetDetect();
this.unsetTagDetect();
this.app.ui.moveToStartPage(monit);
},
- resolveContact: function resolveContact(contactsString) {
- var separator = String.fromCharCode(30),
- endOfText = String.fromCharCode(3),
- contactsArray,
- phone = '',
- first = '',
- last = '',
- resolveData;
+ /**
+ * Get the field separator
+ *
+ * @returns {string}
+ */
+ getSeparator: function nfc_getSeparator() {
+ return this.separator;
+ },
+
+ /**
+ * Get the end of text marker
+ *
+ * @returns {string}
+ */
+ getEndOfText: function nfc_getEndOfText() {
+ return this.endOfText;
+ },
- contactsArray = contactsString.split(separator);
+ createContactString: function createContactString(contact) {
+ var contactString;
+ contactString = contact.phoneNumber + this.getSeparator();
+ contactString += contact.firstName + this.getSeparator();
+ contactString += contact.lastName;
+ return contactString;
+ },
- resolveData = function (value) {
- if (!value) {
- return '';
+ /**
+ *
+ * @param {string|object} contact
+ * @returns {string}
+ */
+ prepareForNFC: function nfc_prepareForNFC(contact) {
+ if ($.type(contact) !== 'string') {
+ contact = this.createContactString(contact);
+ }
+ if (contact.length > 31) {
+ contact = contact.substring(0, 31);
+ if (contact[29] !== this.getSeparator()) {
+ contact = contact.substring(0, 30) + this.getEndOfText();
}
- return value.replace(endOfText, '…');
- };
+ }
+ return contact;
+ },
+
+ resolveData: function nfc_resolveData(value, endOfText) {
+ if (!value) {
+ return '';
+ }
+
+ endOfText = endOfText || this.getEndOfText();
- phone = resolveData(contactsArray[0]);
- first = resolveData(contactsArray[1]);
- last = resolveData(contactsArray[2]);
- return {phone: phone, first: first, last: last};
+ return value.replace(endOfText, '…');
+ },
+
+ resolveContact: function nfc_resolveContact(contactsString) {
+ var separator = this.getSeparator(),
+ contactsArray = contactsString.split(separator);
+
+ return {
+ phone: this.resolveData(contactsArray[0]),
+ first: this.resolveData(contactsArray[1]),
+ last: this.resolveData(contactsArray[2])
+ };
},
- fillRecordInfo: function fillRecordInfo(record) {
+ /**
+ *
+ * @param {type} record
+ * @returns {undefined}
+ */
+ fillRecordInfo: function nfc_fillRecordInfo(record) {
try {
var contactsData = this.resolveContact(this.convertNDEF2phoneNumber(record.payload));
- this.app.ui.displayContact(contactsData);
+ this.app.nfc.displayContact(contactsData);
} catch (error) {
- console.log(error);
+ console.error(error);
}
},
- readMessage: function readMessage(message) {
- console.log('readMessage', message);
+ /**
+ *
+ * @param {NDEFMessage} message
+ */
+ readMessage: function nfc_readMessage(message) {
try {
this.fillRecordInfo(message.records[0]);
} catch (e) {
- console.log(e.message);
+ console.error(e.message);
}
},
- contact2NDEF: function contact2NDEF(contact) {
- var t, a = [], i, newMessage = new tizen.NDEFMessage();
+ /**
+ *
+ * @param {string|object} contact
+ * @returns {NDEFMessage}
+ */
+ contact2NDEF: function nfc_contact2NDEF(contact) {
+ var t, a = [], len, i, newMessage = new tizen.NDEFMessage();
if (typeof contact === 'string') {
t = contact;
} else {
t = contact.convertToString("VCARD_30");
}
- a.length = t.length;
- for (i = 0; i < a.length; i += 1) {
+ len = t.length;
+ for (i = 0; i < len; i += 1) {
a[i] = t.charCodeAt(i);
}
newMessage.records[0] = new tizen.NDEFRecordMedia('text/x-vcard', a);
return newMessage;
},
- phoneNumber2NDEF: function phoneNumber2NDEF(contact) {
+ /**
+ *
+ * @param {string} contact
+ * @returns {NDEFMessage}
+ */
+ phoneNumber2NDEF: function nfc_phoneNumber2NDEF(contact) {
var phoneNumberArray = [], i, length = contact.length, newMessage = new tizen.NDEFMessage();
for (i = 0; i < length; i += 1) {
phoneNumberArray.push(contact.charCodeAt(i));
return newMessage;
},
- convertNDEF2phoneNumber: function convertNDEF2phoneNumber(contact) {
+ /**
+ *
+ * @param {string} contact
+ * @returns {string}
+ */
+ convertNDEF2phoneNumber: function nfc_convertNDEF2phoneNumber(contact) {
var i, length = contact.length, phoneNumber = '';
for (i = 0; i < length; i += 1) {
phoneNumber += String.fromCharCode(contact[i]);
return phoneNumber;
},
- startNFC: function startNFC() {
- var onPowerOn, onPowerOnFails;
+ /**
+ * NFC setPowered success callback
+ * @returns {undefined}
+ */
+ onPowerOn: function nfc_onPowerOn() {
+ this.app.started = true;
+ this.app.ui.loadStartPage();
+ },
- onPowerOn = function () {
- app.started = true;
- app.ui.loadStartPage();
- };
- onPowerOnFails = function (err) {
- console.log('Power On error: ' + err.message);
- };
+ /**
+ * NFC setPowered error callback
+ * @param {Error} err
+ * @returns {undefined}
+ */
+ onPowerOnFails: function nfc_onPowerOnFails(err) {
+ console.error('Power On error: ' + err.message);
+ },
+
+ /**
+ * NFC setPowered success callback
+ * @returns {undefined}
+ */
+ onPowerOff: function nfc_onPowerOff() {
+ tizen.application.getCurrentApplication().exit();
+ },
+
+ /**
+ * NFC setPowered error callback
+ * @param {Error} err
+ * @returns {undefined}
+ */
+ onPowerOffFails: function nfc_onPowerOffFails(err) {
+ console.error('Power Off error', err);
+ tizen.application.getCurrentApplication().exit();
+ },
+
+ startNFC: function nfc_startNFC() {
try {
this.nfcAdapter = tizen.nfc.getDefaultAdapter();
- try {
- if (this.nfcAdapter.powered) {
- console.log('this.nfcAdapter.powered');
- this.nfcStateMemory = true;
- onPowerOn();
- } else {
- console.log('!this.nfcAdapter.powered');
- this.nfcStateMemory = false;
- this.nfcAdapter.setPowered(true, onPowerOn, onPowerOnFails);
- }
- } catch (err) {
- console.log('setPowered(true) problem: ' + err);
+
+ if (this.nfcAdapter.powered) {
+ this.nfcStateMemory = true;
+ this.onPowerOn();
+ return;
}
+
+ this.nfcStateMemory = false;
+ this.nfcAdapter.setPowered(true, this.onPowerOn.bind(this), this.onPowerOnFails.bind(this));
} catch (e) {
- console.log('getDefaultAdapter() method problem: ' + e);
+ console.error('startNFC problem', e);
}
},
- stopNFC: function stopNFC() {
- var onPowerOff, onPowerOffFails;
-
- onPowerOff = function () {
- tizen.application.getCurrentApplication().exit();
- };
-
- onPowerOffFails = function (err) {
- console.log('Power Off error: ' + err.message);
- tizen.application.getCurrentApplication().exit();
- };
-
+ stopNFC: function nfc_stopNFC() {
try {
if (this.nfcStateMemory) {
- console.log('this.nfcStateMemory');
- onPowerOff();
+ this.onPowerOff();
} else {
- console.log('!this.nfcStateMemory');
- this.nfcAdapter.setPowered(false, onPowerOff, onPowerOffFails);
+ this.nfcAdapter.setPowered(false, this.onPowerOff.bind(this), this.onPowerOffFails.bind(this));
}
} catch (err) {
- console.log('setPowered(false) problem: ' + err);
+ console.error('setPowered(false) problem', err);
}
},
- unsetTargetDetect: function unsetTargetDetect() {
- console.log('unsetTargetDetect: ', this);
+ unsetTargetDetect: function nfc_unsetTargetDetect() {
try {
if (this.nfcTarget) {
this.nfcTarget.unsetReceiveNDEFListener();
console.warn("app.nfc.nfcTarget not set");
}
} catch (error) {
- console.log('error: ' + error.message);
+ console.error('error: ' + error.message);
}
try {
this.nfcAdapter.unsetPeerListener();
} catch (e) {
- console.log('error: ' + e.message);
+ console.error('error: ' + e.message);
}
},
- unsetTagDetect: function unsetTagDetect() {
+ unsetTagDetect: function nfc_unsetTagDetect() {
try {
this.nfcAdapter.unsetTagListener();
} catch (error) {
- console.log('error: ' + error.message);
+ console.error('error: ' + error.message);
}
},
- displayContact: function displayContact(obj) {
+ displayContact: function nfc_displayContact(obj) {
clearTimeout(this.app.timeOutHandler);
this.unsetTargetDetect();
this.unsetTagDetect();
this.app.ui.moveToContactPage(obj);
},
- sucDetach: function sucDetach() {
- console.log('sucDetach');
+ sucDetach: function nfc_sucDetach() {
}
};
(function () { // strict mode wrapper
'use strict';
- App.NFCPeer = function (nfcControl) {
- this.app = nfcControl.app;
+ /**
+ * Constructs NFCPeer
+ * @constructor
+ * @param {NFCControl} nfc
+ */
+ App.NFCPeer = function (nfc) {
+ this.nfc = nfc;
};
App.NFCPeer.prototype = {
- sucSendToTarget: function sucSendToTarget() {
- //timeExpired('Send success!');
+ sucSendToTarget: function nfc_peer_sucSendToTarget() {
},
- errSendToTarget: function errSendToTarget(e) {
- this.app.nfc.timeExpired('Send problem! ' + e.message);
+ errSendToTarget: function nfc_peer_errSendToTarget(e) {
+ this.nfc.timeExpired('Send problem! ' + e.message);
},
- errorMessage: function errorMessage(e) {
- console.log('Target Receiving Error: ' + e.message);
+ errorMessage: function nfc_peer_errorMessage(e) {
+ console.error('Target Receiving Error: ' + e.message);
},
- setReceiveFromTarget: function setReceiveFromTarget() {
+ setReceiveFromTarget: function nfc_peer_setReceiveFromTarget() {
try {
- if (this.app.nfc.nfcTarget) {
- this.app.nfc.nfcTarget.setReceiveNDEFListener(this.app.nfc.readMessage.bind(this.app.nfc), this.errorMessage.bind(this));
- } else {
+ if (!this.nfc.nfcTarget) {
console.warn("app.nfc.nfcTarget not set");
+ return;
}
+ this.nfc.nfcTarget.setReceiveNDEFListener(
+ this.nfc.readMessage.bind(this.nfc),
+ this.errorMessage.bind(this)
+ );
} catch (error) {
- console.log('setReceiveFromTarget error: ' + error.message);
+ console.error('setReceiveFromTarget error: ' + error.message);
}
},
- sucTargetAttach: function sucTargetAttach(target) {
+ sucTargetAttach: function nfc_peer_sucTargetAttach(target) {
var newMessage = null,
- separator = String.fromCharCode(30),
- endOfText = String.fromCharCode(3),
- fullContact = localStorage.phoneNumber + separator + localStorage.firstName + separator + localStorage.lastName;
- console.log('sucTargetAttach: ', target);
- this.app.nfc.nfcTarget = target;
- this.setReceiveFromTarget();
+ fullContact = this.nfc.prepareForNFC(localStorage);
- try {
- newMessage = this.app.nfc.phoneNumber2NDEF(fullContact);
- } catch (err) {
- console.log("NDEFMessage problem: " + err.message);
- }
+ this.nfc.nfcTarget = target;
+ this.setReceiveFromTarget();
try {
- target.sendNDEF(newMessage, this.sucSendToTarget.bind(this), this.errSendToTarget.bind(this));
+ newMessage = this.nfc.phoneNumber2NDEF(fullContact);
+ target.sendNDEF(
+ newMessage,
+ this.sucSendToTarget.bind(this),
+ this.errSendToTarget.bind(this)
+ );
} catch (e) {
- console.log("NDEFMessage problem: " + e.message);
+ console.error("NDEFMessage problem: " + e.message);
}
},
- setTargetDetect: function setTargetDetect() {
- var err = function (e) {
- console.log('Target Listen Error: ' + e.message);
- },
- suc = { onattach: this.sucTargetAttach.bind(this), ondetach: this.app.nfc.sucDetach.bind(this.app.nfc) };
+ setTargetDetectError: function nfc_peer_setTargetDetectError(e) {
+ console.error('Target Listen Error: ' + e.message);
+ },
+
+ setTargetDetect: function nfc_peer_setTargetDetect() {
+ var successCallbacks = {
+ onattach: this.sucTargetAttach.bind(this),
+ ondetach: this.nfc.sucDetach.bind(this.nfc)
+ };
+
try {
- app.nfc.nfcAdapter.setPeerListener(suc, err);
+ this.nfc.nfcAdapter.setPeerListener(
+ successCallbacks,
+ this.setTargetDetectError
+ );
} catch (error) {
- console.log('error: ' + error.message);
+ console.error(error.message);
}
}
};
-
-/*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'));
},
- loadTemporaryContent: function loadTemporaryContent() {
+ /**
+ * @returns {string}
+ */
+ getTemporaryBoxHtml: function ui_getTemporaryBoxHtml() {
+ return '<div class="box" id="temporaryBox"></div>';
+ },
+
+ /**
+ * @returns {string}
+ */
+ 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>';
},
- loadStartContent: function loadStartContent() {
- var startBox, gap, comment, changeContact, readFromCard, writeToCard, communicateWithOtherDevice;
+ /**
+ *
+ * @param {string} firstName
+ * @param {string} lastName
+ * @returns {string}
+ */
+ getCommentHtml: function ui_getCommentHtml(firstName, lastName) {
+ var html = '<div id="comment">'
+ + '<p class="comment">Your default contact</p>'
+ + '<p class="comment" id="comment-name">'
+ + (firstName || '') + ' ' + (lastName || '')
+ + '</p>'
+ + '</div>';
+ return html;
+ },
+
+ /**
+ * 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;
+ },
+
+ /**
+ * Read From Card button action
+ * @event
+ * @param {Event} event
+ */
+ readFromCard: function ui_readFromCard(event) {
+ event.preventDefault();
+ $('#transfer').data('option', 'read');
+ $.mobile.changePage('#transfer');
+ },
+
+ /**
+ * @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();
+ $('#transfer').data('option', 'write');
+ $.mobile.changePage('#transfer');
+ },
+
+ /**
+ * @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();
+ $('#transfer').data('option', 'communicate');
+ $.mobile.changePage('#transfer');
+ },
+
+ /**
+ * @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.firstName, localStorage.lastName));
+
+ 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();
}
},
- prepareContactsTemplate: function prepareContactsTemplate(phone, first, last) {
- var i, ul;
+ /**
+ *
+ * @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;
+ },
- ul = $('<ul data-role="listview" id="contacts-data"></ul>');
- $('#contact > #content-contact > .ui-scrollview-view').empty().append(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.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>'));
+ /**
+ * @param {object} contact
+ * @returns {string}
+ */
+ getContactsListElement: function ui_getContactsListElement(contact) {
+ var html =
+ '<li class="ui-li-multiline" firstName="' + contact.firstName
+ + '" lastName="' + contact.lastName +
+ '" phoneNumber="' + contact.phoneNumber +
+ '" id="' + contact.id +
+ '" vCard="' + contact.vCard + '">'
+ + '<a href="#">' + contact.caller
+ + '<span class="ui-li-text-sub">' +
+ contact.phoneNumber
+ + '</span>'
+ + '</a>'
+ + '</li>';
+ return html;
+ },
- $('#contact > #content-contact').trigger('create');
+ prepareContactsTemplate: function ui_prepareContactsTemplate(phone, first, last) {
+ $('#content-contact > .ui-scrollview-view')
+ .empty()
+ .append(this.getContactsUlHtml(phone, first, last));
+ $('#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;
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>');
+ for (i = 0, len = sortedContactList.length; i < len; i += 1) {
+ listElement = $(this.getContactsListElement(sortedContactList[i]));
if (localStorage.id === listElement.attr('id')) {
- listElement.css('background-color', '#ccc');
+ listElement.addClass('selected');
}
- 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) {
+ moveToContactPage: function ui_moveToContactPage(obj) {
$('#start').data('monit', '');
$('#contact').data('contactsData', obj);
$.mobile.changePage('#contact');
},
+ disableSelections: function ui_disableSelections() {
+ $.mobile.tizen.disableSelection(document);
+ },
- 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();
- });
-
$('#footer-contact').on('tap', '.ui-btn-back', function (event) {
event.preventDefault();
$.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) {
});
$('#start').on('pageshow', function () {
- var monit, obj;
+ var monit, obj, contentStart, contentStartHeight;
obj = $(this);
monit = obj.data('monit');
if (monit !== '' && monit !== undefined) {
self.showPopup(obj.data('monit'), obj);
}
+ contentStart = $('#content-start');
+
+ if (contentStart.height() > $(window).height()) {
+ contentStartHeight = $(window).height() - $('#header-start').height()
+ - parseInt(contentStart.css('padding-top'), 10) - parseInt(contentStart.css('padding-bottom'), 10);
+ } else {
+ contentStartHeight = contentStart.height();
+ }
+ setTimeout(function () { // workaround (setTimeout with 0 delay)
+ contentStart
+ .css('height', contentStartHeight + 'px')
+ .css('min-height', 'auto')
+ obj.css('min-height', 'auto');
+ }, 0);
+ });
+
+ $('#transfer').on('pageshow', function () {
+ var contentTransfer = $('#content-transfer');
+ contentTransfer.css('width', contentTransfer.width() + 'px');
+ setTimeout(function () { // workaround (setTimeout with 0 delay)
+ contentTransfer.css('height', contentTransfer.css('min-height'));
+ }, 0);
});
$('#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 {
+ try {
+ 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();
- } catch (err) {
- console.log(err);
- }
- } else if (option === 'write') {
- self.prepareWaitingPage('Device to Card', 'PUT WIRELESS TAG<br>CLOSE TO<br>YOUR DEVICE');
- try {
+ } else if (option === 'write') {
+ self.prepareWaitingPage('Device to Card', 'PUT WIRELESS TAG<br>CLOSE TO<br>YOUR DEVICE');
self.app.nfc.card.setTagDetectWrite();
- } catch (er) {
- console.log(er);
- }
- } else {
- self.prepareWaitingPage('Device to Device', 'PUT YOUR DEVICE<br>CLOSE TO<br>OTHER DEVICE');
- try {
+ } 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);
}
+ } catch (e) {
+ console.error(e.message);
}
});
}
--- /dev/null
+/*global tizen, $, app */
+/**
+ * @class TemplateManager
+ */
+function TemplateManager() {
+ 'use strict';
+ this.init();
+}
+
+(function () { // strict mode wrapper
+ 'use strict';
+ TemplateManager.prototype = {
+
+ /**
+ * Template cache
+ */
+ cache: {},
+
+ /**
+ * UI module initialisation
+ */
+ init: function init() {
+ },
+
+ /**
+ * Returns template html (from cache)
+ * @param {string} tplName
+ * @param {string} tplParams
+ */
+ get: function TemplateManager_get(tplName, tplParams) {
+ if (this.cache[tplName] !== undefined) {
+ return this.getCompleted(this.cache[tplName], tplParams);
+ }
+ return '';
+ },
+
+ /**
+ * Load templates to cache
+ * @param {string} tplNames
+ * @param {function} onSuccess
+ */
+ loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
+ var self = this,
+ cachedTemplates = 0,
+ tplName,
+ tplPath;
+
+ if ($.isArray(tplNames)) {
+
+ // for each template
+ $.each(tplNames, function (index, fileName) {
+
+ // cache template html
+ if (self.cache[fileName] === undefined) {
+ tplName = [fileName, app.config.get('templateExtension')].join('');
+ tplPath = [app.config.get('templateDir'), tplName].join('/');
+
+ $.ajax({
+ url: tplPath,
+ cache: true,
+ dataType: 'html',
+ async: true,
+ success: function (data) {
+ // increase counter
+ cachedTemplates += 1;
+
+ // save to cache
+ self.cache[fileName] = data;
+
+ // if all templates are cached launch callback
+ if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
+ onSuccess();
+ }
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ console.error('templateManagerError: ' + errorThrown);
+ }
+ });
+ } else {
+ // template is already cached
+ cachedTemplates += 1;
+ // if all templates are cached launch callback
+ if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
+ onSuccess();
+ }
+ }
+ });
+
+ }
+ },
+
+ /**
+ * Returns template completed by specified params
+ * @param {string} tplHtml
+ * @param {string} tplParams
+ */
+ getCompleted: function TemplateManager_getCompleted(tplHtml, tplParams) {
+ var tplParam, replaceRegExp;
+
+ for (tplParam in tplParams) {
+ if (tplParams.hasOwnProperty(tplParam)) {
+ replaceRegExp = new RegExp(['%', tplParam, '%'].join(''), 'g');
+ tplHtml = tplHtml.replace(replaceRegExp, tplParams[tplParam]);
+ }
+ }
+
+ return tplHtml;
+ }
+ };
+
+}());
\ No newline at end of file