2 /*global tizen, $, app, localStorage */
13 (function () { // strict mode wrapper
18 * API module initialisation
20 init: function Model_init() {
24 * Registers listener for call history change
25 * @param {onSuccessCallback} function
27 registerChangeListener: function Model_registerChangeListener(onSuccessCallback) {
29 var callHistoryListener = {
30 onadded: onSuccessCallback,
31 onchanged: onSuccessCallback,
32 onremoved: onSuccessCallback
35 tizen.callhistory.addChangeListener(callHistoryListener);
39 * @param {function} onSuccess callback
40 * @param {function} onError callback
42 getCallHistory: function Model_getCallHistory(onSuccess, onError) {
43 if (typeof onError !== 'function') {
44 onError = function (e) {
45 console.error('Model_getCallHistory error', e);
49 tizen.callhistory.find(onSuccess, onError, null, new tizen.SortMode('startTime', 'DESC'));
53 * @param {number} phoneNumber
54 * @param {function} onSuccess Callback
56 getCallHistoryForCaller: function Model_getCallHistoryForCaller(phoneNumber, onSuccess) {
57 var filter = null, success;
59 filter = new tizen.AttributeFilter('remoteParties.remoteParty', 'EXACTLY', phoneNumber);
62 success = function (calls) {
63 onSuccess(calls.filter(function (element) {
64 if(!element.remoteParties[0].remoteParty) {
71 tizen.callhistory.find(success,
76 new tizen.SortMode('startTime', 'DESC')
81 * Deletes specified log entry
82 * @param {CallHistoryEntry} entry
84 deleteLog: function Model_deleteLog(entry) {
86 tizen.callhistory.remove(entry);
88 console.error('Error on entry delete: ' + e.message);
93 * @param {number} addressBookId
94 * @param {number} contactId
95 * @returns {string} photoURI
97 getPhotoURIForContact: function Model_getPhotoURIForContact(personId) {
99 var addressBook = tizen.contact.getDefaultAddressBook(),
103 contact = addressBook.get(personId);
104 return contact.photoURI || false;
107 console.error('updatePhotoByContactId error:' + e.message);