X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=project%2Fjs%2Fapp.model.js;h=42c3c64ca9e673090f217c29f9948898bb361ba2;hb=HEAD;hp=0273e5c84c8105f7c5a95741574542311b3a4623;hpb=335f789d65024a4f29b1fc71773bac03430de476;p=apps%2Fweb%2Fsample%2FCallLog.git diff --git a/project/js/app.model.js b/project/js/app.model.js index 0273e5c..42c3c64 100644 --- a/project/js/app.model.js +++ b/project/js/app.model.js @@ -1,142 +1,113 @@ -/* -* Copyright 2013 Samsung Electronics Co., Ltd -* -* Licensed under the Flora License, Version 1.1 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://floralicense.org/license/ -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - /*jslint devel: true*/ /*global tizen, $, app, localStorage */ /** -* @class Model -*/ + * @class Model + */ function Model() { - 'use strict'; + 'use strict'; - this.init(); + this.init(); } (function () { // strict mode wrapper - 'use strict'; + 'use strict'; + Model.prototype = { + + /** + * API module initialisation + */ + init: function Model_init() { + }, - Model.prototype = { + /** + * Registers listener for call history change + * @param {onSuccessCallback} function + */ + registerChangeListener: function Model_registerChangeListener(onSuccessCallback) { - /** - * API module initialisation - */ - init: function Model_init() { - }, + var callHistoryListener = { + onadded: onSuccessCallback, + onchanged: onSuccessCallback, + onremoved: onSuccessCallback + }; - /** - * Registers listener for call history change - * @param {onSuccessCallback} function - */ - registerChangeListener: function Model_registerChangeListener( - onSuccessCallback - ) { - var callHistoryListener = { - onadded: onSuccessCallback, - onchanged: onSuccessCallback, - onremoved: onSuccessCallback - }; - tizen.callhistory.addChangeListener(callHistoryListener); - }, + tizen.callhistory.addChangeListener(callHistoryListener); + }, - /** - * @param {function} onSuccess callback - * @param {function} onError callback - */ - getCallHistory: function Model_getCallHistory(onSuccess, onError) { - if (typeof onError !== 'function') { - onError = function (e) { - console.error('Model_getCallHistory error', e); - }; - } + /** + * @param {function} onSuccess callback + * @param {function} onError callback + */ + getCallHistory: function Model_getCallHistory(onSuccess, onError) { + if (typeof onError !== 'function') { + onError = function (e) { + console.error('Model_getCallHistory error', e); + }; + } - tizen.callhistory.find( - onSuccess, - onError, - null, - new tizen.SortMode('startTime', 'DESC') - ); - }, + tizen.callhistory.find(onSuccess, onError, null, new tizen.SortMode('startTime', 'DESC')); + }, - /** - * @param {number} phoneNumber - * @param {function} onSuccess Callback - */ - getCallHistoryForCaller: function Model_getCallHistoryForCaller( - phoneNumber, - onSuccess - ) { - var filter = null, success; - if (phoneNumber) { - filter = new tizen.AttributeFilter( - 'remoteParties.remoteParty', - 'EXACTLY', - phoneNumber - ); - success = onSuccess; - } else { - success = function (calls) { - onSuccess(calls.filter(function (element) { - if (!element.remoteParties[0].remoteParty) { - return element; - } - })); - }; - } + /** + * @param {number} phoneNumber + * @param {function} onSuccess Callback + */ + getCallHistoryForCaller: function Model_getCallHistoryForCaller(phoneNumber, onSuccess) { + var filter = null, success; + if (phoneNumber) { + filter = new tizen.AttributeFilter('remoteParties.remoteParty', 'EXACTLY', phoneNumber); + success = onSuccess; + } else { + success = function (calls) { + onSuccess(calls.filter(function (element) { + if(!element.remoteParties[0].remoteParty) { + return element; + } + })); + }; + } - tizen.callhistory.find(success, - function (e) { - console.error(e); - }, - filter, - new tizen.SortMode('startTime', 'DESC') - ); - }, + tizen.callhistory.find(success, + function (e) { + console.error(e); + }, + filter, + new tizen.SortMode('startTime', 'DESC') + ); + }, - /** - * Deletes specified log entry - * @param {CallHistoryEntry} entry - */ - deleteLog: function Model_deleteLog(entry) { - try { - tizen.callhistory.remove(entry); - } catch (e) { - console.error('Error on entry delete: ' + e.message); - } - }, + /** + * Deletes specified log entry + * @param {CallHistoryEntry} entry + */ + deleteLog: function Model_deleteLog(entry) { + try { + tizen.callhistory.remove(entry); + } catch (e) { + console.error('Error on entry delete: ' + e.message); + } + }, - /** - * @param {number} addressBookId - * @param {number} contactId - * @returns {string} photoURI - */ - getPhotoURIForContact: function Model_getPhotoURIForContact(personId) { - try { - var addressBook = tizen.contact.getDefaultAddressBook(), - contact; - if (addressBook) { - contact = addressBook.get(personId); - return contact.photoURI || false; - } - } catch (e) { - console.error('updatePhotoByContactId error:' + e.message); - } - return false; - } + /** + * @param {number} addressBookId + * @param {number} contactId + * @returns {string} photoURI + */ + getPhotoURIForContact: function Model_getPhotoURIForContact(personId) { + try { + var addressBook = tizen.contact.getDefaultAddressBook(), + contact; - }; + if (addressBook) { + contact = addressBook.get(personId); + return contact.photoURI || false; + } + } catch (e) { + console.error('updatePhotoByContactId error:' + e.message); + } + return false; + } + }; }());