Revert "Updated application sources"
[apps/web/sample/CallLog.git] / project / js / app.js
1 /*jslint devel: true*/
2 /*global Config, Model, Ui, tizen, setTimeout, navigator */
3
4 var App = null;
5
6 (function () { // strict mode wrapper
7         'use strict';
8
9         /**
10          * Creates a new application object
11          *
12          * @class Application
13          */
14         App = function App() {
15                 this.configData = {};
16         };
17
18         App.prototype = {
19                 /**
20                  * @type Array
21                  */
22                 requires: ['js/app.config.js', 'js/app.model.js', 'js/app.ui.js', 'js/app.ui.templateManager.js', 'js/app.ui.templateManager.modifiers.js', 'js/app.helpers.js'],
23
24                 /**
25                  * @type Model
26                  */
27                 model: null,
28
29                 /**
30                  * @type Ui
31                  */
32                 ui: null,
33
34                 /**
35                  * @type Config
36                  */
37                 config: null,
38
39                 /**
40                  * @type {number}
41                  */
42                 lastViewedCaller: 0,
43
44                 /**
45                  * Initialisation function
46                  */
47                 init: function App_init() {
48                         // instantiate the libs
49                         this.config = new Config();
50                         this.model = new Model();
51                         this.model.registerChangeListener(this.updateCallLists.bind(this));
52                         this.ui = new Ui();
53                         this.updateCallLists();
54
55                         return this;
56                 },
57
58                 /**
59                  * Updates call history and caller detailed history lists
60                  */
61                 updateCallLists: function App_updateCallLists() {
62                         // workaround - time zone update
63                         tizen.time.getCurrentDateTime().toLocalTimezone();
64                         // workaround;
65                         setTimeout(this.showHistoryForCaller(this.lastViewedCaller), 500);
66                         this.showCallHistory();
67                 },
68
69                 /**
70                  * Renders call history view
71                  */
72                 showCallHistory: function App_showCallHistory() {
73                         this.model.getCallHistory(this.ui.showCallHistory.bind(this.ui));
74                 },
75
76                 /**
77                  * Renders history for caller view
78                  * @param {string} phoneNumber
79                  */
80                 showHistoryForCaller: function App_showHistoryForCaller(phoneNumber) {
81                         this.lastViewedCaller = phoneNumber;
82                         this.model.getCallHistoryForCaller(phoneNumber, this.ui.showHistoryForCaller.bind(this.ui, phoneNumber));
83                 },
84
85                 /**
86                  * @param {number} addressBookId
87                  * @param {number} contactId
88                  * @returns {string} photoURI Photo URI for specified contact
89                  */
90                 getPhotoURIForContact: function App_getPhotoURIForContact(personId) {
91                         return this.model.getPhotoURIForContact(personId);
92                 },
93
94                 /**
95                  * Launch extension call service
96                  * @param {string} phoneNumber
97                  */
98                 makeCall: function App_makeCall(phoneNumber) {
99                         var self = this,
100                                 appControl = new tizen.ApplicationControl(
101                                         'http://tizen.org/appcontrol/operation/call',
102                                         'tel:' + phoneNumber
103                                 );
104                         tizen.application.launchAppControl(
105                                 appControl,
106                                 null,
107                                 function () {
108                                 },
109                                 function (e) {
110                                         console.error('Call to ' + phoneNumber
111                                                 + ' failed. Call service is unavailable.', e);
112                                         self.ui.showErrorPopup('Call failed. '
113                                                 + 'Call service is unavailable.');
114                                 },
115                                 {
116                                         onsuccess: function () {
117                                         },
118                                         onfailure: function (e) {
119                                                 console.log('App_makeCall: Call to ' + phoneNumber
120                                                         + ' failed. Call service was busy.', e);
121                                                 //self.ui.showErrorPopup('Call failed.'
122                                                 //      + 'Call service was busy.');
123                                         }
124                                 }
125                         );
126                 },
127
128                 /**
129                  * Launch extension sms service
130                  * @param {string} phoneNumber
131                  */
132                 sendSms: function App_sendSms(phoneNumber) {
133
134                         var self = this,
135                                 appControl = new tizen.ApplicationControl(
136                                         'http://tizen.org/appcontrol/operation/compose',
137                                         'sms:' + phoneNumber
138                                 );
139
140                         tizen.application.launchAppControl(
141                                 appControl,
142                                 null,
143                                 null,
144                                 function (e) {
145                                         console.error('Message launch error: ', e);
146                                         self.ui.showErrorPopup('Message service is unavailable');
147                                         app.ui.unlockOptionButtons();
148                                 },
149                                 {
150                                         onfailure: function (er) {
151                                                 console.error('Message service launch error: ', er);
152                                                 self.ui.showErrorPopup('Message service is unavailable');
153                                                 app.ui.unlockOptionButtons();
154                                         }
155                                 }
156                         );
157                 },
158
159                 /**
160                  * Deletes specified log entry
161                  * @param {CallHistoryEntry} entry
162                  */
163                 deleteLog: function App_deleteLogs(entry) {
164                         this.model.deleteLog(entry);
165                 },
166
167                 /**
168                  * App exit
169                  */
170                 exit: function App_exit(event) {
171                         event.preventDefault();
172                         event.stopPropagation();
173                         tizen.application.getCurrentApplication().exit();
174                 }
175         };
176 }());