2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /*jslint devel: true*/
25 (function () { // strict mode wrapper
28 function checkCharsSize(string) {
29 var i, result = '', length = string.length;
30 for (i = 0; i < length; i += 1) {
31 if (string.charCodeAt(i) < 256) {
39 * Creates a new application object
43 App = function App() {};
52 init: function appInit() {
53 this.ui = new App.Ui(this);
54 this.nfc = new App.NFCControl(this);
56 this.ui.defineEvents();
57 this.initAddressBook();
61 saveDefaultCard: function saveDefaultCard() {
62 var elementSelected = $('#list-choose li.selected');
63 console.log(elementSelected);
64 localStorage.started = true;
65 localStorage.id = elementSelected.attr('id');
66 localStorage.firstName = elementSelected.attr('firstName');
67 localStorage.lastName = elementSelected.attr('lastName');
68 localStorage.phoneNumber = elementSelected.attr('phoneNumber');
69 localStorage.vCard = elementSelected.attr('vCard');
70 $.mobile.changePage('#start');
73 initAddressBook: function initAddressBook() {
74 var addressBooksCB = function (addressbooks) {
75 console.log('addressBooksCB success');
76 if (addressbooks.length > 0) {
77 this.addressBook = addressbooks[0];
79 console.log('addressBook: failed');
82 errorCB = function (e) {
83 console.log('problem with getAddressBooks() method: ' + e.message);
87 tizen.contact.getAddressBooks(addressBooksCB.bind(this), errorCB);
89 console.log('problem with getAddressBooks() method: ' + e.message);
93 countDown: function countDown(time, obj) {
97 this.timeOutHandler = setTimeout(function () { this.countDown(time, obj); }.bind(this), 1000);
99 this.nfc.timeExpired();
103 saveContact: function saveContact() {
104 var phone, first, last, contactPage = $('#contact'), contact = null;
105 phone = contactPage.data('contactsData').phone;
106 first = contactPage.data('contactsData').first;
107 last = contactPage.data('contactsData').last;
110 contact = new tizen.Contact({name: new tizen.ContactName({firstName: first, lastName: last}), phoneNumbers: [new tizen.ContactPhoneNumber(phone)]});
111 this.addressBook.add(contact);
112 this.app.ui.moveToStartPage('New contact added');
114 this.app.ui.moveToStartPage('Problem with new contact adding');
115 console.log('The following error occurred while adding: ' + err.name);
119 loadContacts: function loadContacts() {
121 errorCB = function (e) {
122 console.log('problem with find() method: ' + e.message);
124 this.addressBook.find(function (contacts) {
125 self.ui.showContactsList(contacts);
135 $(document).ready(app.init.bind(app));