Tizen 2.0 Release
[samples/web/CallLog.git] / 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.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
53                         this.ui = new Ui();
54
55                         return this;
56                 },
57
58                 /**
59                  * Updates call history and caller detailed history lists
60                  */
61                 updateCallLists: function App_updateCallLists() {
62                         // workaround;
63                         setTimeout(this.showHistoryForCaller(this.lastViewedCaller), 500);
64                         this.showCallHistory();
65                 },
66
67                 /**
68                  * Renders call history view
69                  */
70                 showCallHistory: function App_showCallHistory() {
71                         this.model.getCallHistory(this.ui.showCallHistory.bind(this.ui));
72                 },
73
74                 /**
75                  * Renders history for caller view
76                  * @param {string} phoneNumber
77                  */
78                 showHistoryForCaller: function App_showHistoryForCaller(phoneNumber) {
79                         this.lastViewedCaller = phoneNumber;
80                         this.model.getCallHistoryForCaller(phoneNumber, this.ui.showHistoryForCaller.bind(this.ui, phoneNumber));
81                 },
82
83                 /**
84                  * @param {number} addressBookId
85                  * @param {number} contactId
86                  * @returns {string} photoURI Photo URI for specified contact
87                  */
88                 getPhotoURIForContact: function App_getPhotoURIForContact(addressBookId, contactId) {
89                         return this.model.getPhotoURIForContact(addressBookId, contactId);
90                 },
91
92                 /**
93                  * Launch extension call service
94                  * @param {string} phoneNumber
95                  */
96                 makeCall: function App_makeCall(phoneNumber) {
97                         var appControl = new tizen.ApplicationControl(
98                                         'http://tizen.org/appcontrol/operation/dial',
99                                         'tel:' + phoneNumber
100                                 );
101
102                         tizen.application.launchAppControl(
103                                 appControl,
104                                 null,
105                                 function () {
106                                 },
107                                 function (e) {
108                                         console.error('App_makeCall: CALL service failure', e);
109                                         alert('Call service is unavailable');
110                                 },
111                                 {
112                                         onsuccess: function () {
113                                         },
114                                         onfailure: function (er) {
115                                                 console.error('Error during call to ' + phoneNumber, er);
116                                                 alert('Call service is unavailable');
117                                         }
118                                 }
119                         );
120                 },
121
122                 /**
123                  * Launch extension sms service
124                  * @param {string} phoneNumber
125                  */
126                 sendSms: function App_sendSms(phoneNumber) {
127
128                         var appControl = new tizen.ApplicationControl(
129                                         'http://tizen.org/appcontrol/operation/send_text',
130                                         'sms:' + phoneNumber
131                                 );
132
133                         tizen.application.launchAppControl(
134                                 appControl,
135                                 null,
136                                 function () {
137                                 },
138                                 function (e) {
139                                         console.error('Message launch error: ', e);
140                                         alert('Message service is unavailable');
141                                 },
142                                 {
143                                         onsuccess: function () {
144                                         },
145                                         onfailure: function (er) {
146                                                 console.error('Message service launch error: ', er);
147                                                 alert('Message service is unavailable');
148                                         }
149                                 }
150                         );
151                 },
152
153                 /**
154                  * Deletes specified log entry
155                  * @param {CallHistoryEntry} entry
156                  */
157                 deleteLog: function App_deleteLogs(entry) {
158                         this.model.deleteLog(entry);
159                 },
160
161                 /**
162                  * App exit
163                  */
164                 exit: function App_exit() {
165                         tizen.application.getCurrentApplication().exit();
166                 }
167         };
168 }());