[CallLog]update CallLog(tizen_2.1)
[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/call',
99                                         'tel:' + phoneNumber
100                                 );
101                         tizen.application.launchAppControl(
102                                 appControl,
103                                 null,
104                                 function () {
105                                 },
106                                 function (e) {
107                                         console.error('App_makeCall: CALL service failure', e);
108                                         alert('Call service is unavailable');
109                                 },
110                                 {
111                                         onsuccess: function () {
112                                         },
113                                         onfailure: function (er) {
114                                                 console.error('Error during call to ' + phoneNumber, er);
115                                                 alert('Call service is unavailable');
116                                         }
117                                 }
118                         );
119                 },
120
121                 /**
122                  * Launch extension sms service
123                  * @param {string} phoneNumber
124                  */
125                 sendSms: function App_sendSms(phoneNumber) {
126
127                         var appControl = new tizen.ApplicationControl(
128                                         'http://tizen.org/appcontrol/operation/send_text',
129                                         'sms:' + phoneNumber
130                                 );
131
132                         tizen.application.launchAppControl(
133                                 appControl,
134                                 null,
135                                 function () {
136                                 },
137                                 function (e) {
138                                         console.error('Message launch error: ', e);
139                                         alert('Message service is unavailable');
140                                 },
141                                 {
142                                         onsuccess: function () {
143                                         },
144                                         onfailure: function (er) {
145                                                 console.error('Message service launch error: ', er);
146                                                 alert('Message service is unavailable');
147                                         }
148                                 }
149                         );
150                 },
151
152                 /**
153                  * Deletes specified log entry
154                  * @param {CallHistoryEntry} entry
155                  */
156                 deleteLog: function App_deleteLogs(entry) {
157                         this.model.deleteLog(entry);
158                 },
159
160                 /**
161                  * App exit
162                  */
163                 exit: function App_exit(event) {
164                         event.preventDefault();
165                         event.stopPropagation();
166                         tizen.application.getCurrentApplication().exit();
167                 }
168         };
169 }());