[CallLog] updated CallLog sources
[samples/web/CallLog.git] / js / app.ui.js
1 /*jslint devel: true*/
2 /*global tizen, document, $, jQuery, app, UiPanel, UiContact, TemplateManager, window, Helpers */
3
4 /**
5  * @class Ui
6  */
7
8 function Ui(contacts) {
9         'use strict';
10         this.init();
11 }
12
13 (function () { // strict mode wrapper
14         'use strict';
15         Ui.prototype = {
16                 /**
17                  * UI remove mode
18                  * @type {boolean}
19                  */
20                 removeMode: false,
21
22                 addressBook: tizen.contact.getDefaultAddressBook(),
23
24                 photoURIdefault: null,
25
26                 contactsLoaded: null,
27
28                 checkedLogs: [],
29
30                 /**
31                  * @type {TemplateManager}
32                  */
33                 templateManager: null,
34
35                 /**
36                  * UI Initializer
37                  */
38                 init: function Ui_init() {
39                         this.loadContacts();
40                         this.templateManager = new TemplateManager();
41                         this.helpers = new Helpers();
42                         $(document).ready(this.domInit.bind(this));
43                         $.mobile.tizen.disableSelection(document);
44                 },
45
46                 /**
47                  * When DOM is ready, initialise it (bind events)
48                  */
49                 domInit: function Ui_domInit() {
50                         this.templateManager.loadToCache(['callView',
51                                 'callerHistory',
52                                 'callItemRow',
53                                 'callerCallItemRow',
54                                 'messageWindow',
55                                 'errorWindow',
56                                 'dateRow'], this.initPages.bind(this));
57                 },
58
59                 /**
60                  * UI pages initializer
61                  */
62                 initPages: function Ui_initPages() {
63                         var pages = [], body = $('body');
64
65                         body
66                                 .append(this.templateManager.get('messageWindow'))
67                                 .append(this.templateManager.get('errorWindow'))
68                                 .trigger('create');
69                         $('#callView')
70                                 .append($(this.templateManager.get('callView'))
71                                         .children())
72                                         .trigger('pagecreate')
73                                         .trigger('pageshow');
74                         pages.push(this.templateManager.get('callerHistory'));
75                         body.append(pages.join(''));
76                         this.removeSearchBarToHeader();
77
78                         this.addEvents();
79                         app.showCallHistory();
80
81                         this.photoURIdefault = $("#header .photo").css('background-image');
82                 },
83
84                 /**
85                  * Add UI events
86                  */
87                 addEvents: function Ui_addEvents() {
88                         var self = this;
89
90                         $(window).on('resize', function () {
91                                 $.mobile.activePage.page('refresh');
92                         });
93
94                         $('#callView').on('pagebeforeshow', function () {
95                                 app.showCallHistory();
96                         });
97
98                         //original code, do not remove until web-ui release; N_SE-48946
99                         //$(".ui-scrollview-view").listview();
100
101                         $('#historyForCallerView').on('pagebeforeshow', function () {
102                                 self.hideCheckboxes();
103                                 $('#historyForCallerView .ui-content.ui-scrollview-clip .ui-scrollview-view')
104                                         .css('-webkit-transform', 'translate3d(0px, 0px, 0px)');
105                                 $('#selectAllDetails').on('change', function () {
106                                         self.selectAll();
107                                 });
108                         });
109
110                         $('#historyForCallerView').on('pageshow', function () {
111                                 $('#content').css('top', '160px');
112                                 $('#header').css('height', '160px');
113                                 $('#callerListContainer')
114                                         .children('.ui-overflow-indicator-top', '.ui-overflow-indicator-bottom')
115                                         .hide();
116                         });
117
118                         $('#callerListContainer').on('scrollstart', function () {
119                                 $(this)
120                                         .children('.ui-overflow-indicator-top', '.ui-overflow-indicator-bottom')
121                                         .fadeIn(200);
122                         });
123
124                         $('#callerListContainer').on('scrollstop', function () {
125                                 $(this)
126                                         .children('.ui-overflow-indicator-top', '.ui-overflow-indicator-bottom')
127                                         .fadeOut(200);
128                         });
129
130                         $('.selectAllBox').children().on('click', function () {
131                                 $('.selectAllBox input[type=checkbox]').trigger('click');
132                                 self.selectAll();
133                                 self.selectAllDetailsEach();
134                         });
135
136                         $('#calllogList').on('tap', '.date', function (event) {
137                                 event.stopPropagation();
138                         });
139
140                         $('#calllogList').on('click', '.call', function onCalllogEntryClick(event) {
141                                 var remoteParty = $(this)
142                                         .data('entries')[0]
143                                         .remoteParties[0]
144                                         .remoteParty;
145                                 app.showHistoryForCaller(remoteParty);
146                                 $.mobile.changePage('#historyForCallerView');
147                         });
148
149                         $('#smsActionBtn').on('click', function (event) {
150                                 event.stopPropagation();
151                                 event.preventDefault();
152                                 self.lockButtons();
153                                 self.hideCheckboxes();
154                                 app.sendSms($('#forCallerList').data('remoteParty'));
155                         });
156
157                         $('#callActionBtn').on("click", function (event) {
158                                 self.lockButtons();
159                                 self.hideCheckboxes();
160                                 app.makeCall($('#forCallerList').data('remoteParty'));
161                         });
162
163                         $('#deleteActionBtn').on('click', function () {
164                                 self.changeDetailsToRemoveState();
165                         });
166
167                         $('.selectAllBox').on('click', 'li', function () {
168                                 var checkbox = $(this).find(':checkbox');
169                                 if (self.removeMode === true) {
170                                         if (checkbox.attr('checked')) {
171                                                 checkbox.attr('checked', false)
172                                                         .data('checkboxradio')
173                                                         .refresh();
174                                         } else {
175                                                 checkbox.attr('checked', true)
176                                                         .data('checkboxradio')
177                                                         .refresh();
178                                         }
179                                         self.setSelectAllDetails();
180                                 }
181                         });
182
183                         $('#popup')
184                                 .on('click', '#popupCancelActionBtn', this.closePopup.bind(this))
185                                 .on('click', '#popupSubmitActionBtn', this.deleteCheckedLogs.bind(this));
186
187                         $('#errorPopup').on('click', '#errorPopupOkBtn', this.closeErrorPopup);
188
189                         $( "#errorPopup" ).bind({
190                                 popupafterclose: function(){
191                                         self.unlockOptionButtons();
192                                 }
193                         });
194
195                         $(window).keyup(function(e){
196                                 if (e.which === 13) {
197                                         $('input:focus').blur();
198                                 }
199                         });
200
201                         window.addEventListener('tizenhwkey', function(e) {
202                                 if (e.keyName == "back") {
203                                         if ($.mobile.popup.active) {
204                                                 $.mobile.popup.active.close();
205                                         } else if (self.removeMode === true) {
206                                                 app.ui.changeDetailsToRemoveState(undefined, true);
207                                         } else if ($.mobile.activePage.attr('id') === 'callView') {
208                                                         tizen.application.getCurrentApplication().exit();
209                                         } else {
210                                                 history.back();
211                                         }
212                                 }
213                         });
214
215                         self.onVisibilityChange();
216                 },
217
218                 addEventsForCallerListCheckboxes: function Ui_addEventsForCallerListCheckboxes() {
219                         var self = this;
220                         $('#forCallerList :checkbox').on('change', function (event) {
221                                 if ($(this).attr('checked')) {
222                                         $(this).attr('checked', true);
223                                 } else {
224                                         $(this).attr('checked', false);
225                                 }
226                                 self.setSelectAllDetails();
227                         });
228                 },
229
230                 selectAll: function () {
231                         if ($('#selectAllDetails').attr('checked')) {
232                                 this.selectCheckbox($('#selectAllDetails'), true);
233                         } else {
234                                 this.selectCheckbox($('#selectAllDetails'), false);
235                         }
236                         this.selectAllDetailsEach();
237                 },
238
239                 selectCheckbox: function (obj, state) {
240                         var deleteButton = $('#deleteActionBtn'), numChecked;
241                         obj.attr('checked', state)
242                                 .data('checkboxradio')
243                                 .refresh();
244
245                         numChecked = $('#forCallerList input:checked').length;
246                         if (this.removeMode && numChecked === 0 && !deleteButton.hasClass('ui-disabled')) {
247                                 deleteButton.addClass('ui-disabled').attr('tabIndex', '-1').blur();
248                         } else if (deleteButton.hasClass('ui-disabled')) {
249                                 deleteButton.removeClass('ui-disabled').attr('tabIndex', '0');
250                         }
251                 },
252
253                 /**
254                  * Returns number of selected call logs
255                  * @return {number} length
256                  */
257                 getCountSelectedLogEntries: function Ui_getCountSelectedLogEntries() {
258                         return $('#forCallerList li .toRemove label.ui-checkbox-on').length;
259                 },
260
261                 selectAllDetailsEach: function Ui_selectAllDetailsEach() {
262                         var self = this;
263                         $('#forCallerList').find('input').each(function () {
264                                 if ($('#selectAllDetails').attr('checked')) {
265                                         self.selectCheckbox($(this), true);
266                                 } else {
267                                         self.selectCheckbox($(this), false);
268                                 }
269                         });
270                 },
271
272                 /**
273                  * Hides checkboxes
274                  */
275                 hideCheckboxes: function Ui_hideCheckboxes() {
276                         var self = this;
277                         this.selectCheckbox($('#selectAllDetails'), false);
278
279                         $('#forCallerList').find('input').each(function () {
280                                 self.selectCheckbox($(this), false);
281                         });
282                         this.changeDetailsToRemoveState('hide');
283                 },
284
285                 /**
286                  * Returns css classes for specified entry
287                  *
288                  * @param {CallHistoryEntry} entry
289                  * @returns {string}
290                  */
291                 cssClassesForEntry: function Ui_cssClassesForEntry(entry) {
292                         return 'call dir_' + entry.direction.toLowerCase() + ' type_' + entry.type.replace('.', '-').toLowerCase();
293                 },
294
295                 setSelectAllDetails: function Ui_setSelectAllDetails() {
296                         if ($('#forCallerList input[type="checkbox"]').length ===
297                                 $('#forCallerList input[checked="checked"]').length) {
298                                 this.selectCheckbox($('#selectAllDetails'), true);
299                         } else {
300                                 this.selectCheckbox($('#selectAllDetails'), false);
301                         }
302                 },
303
304                 /**
305                  * Shows popup with specified message
306                  * @param {string} message
307                  */
308                 showPopup: function Ui_showPopup(message) {
309                         $('#popupMessage').html(message);
310                         $('#popup').popup('open', {'positionTo': 'window'});
311                 },
312
313                 /**
314                  * Hides popup
315                  */
316                 closePopup: function Ui_closePopup() {
317                         $('#popup').popup('close');
318                 },
319
320                 showErrorPopup: function Ui_showErrorPopup(message) {
321                         $('#errorPopupMessage').html(message);
322                         $('#errorPopup').popup('open', {'positionTo': 'window'});
323                 },
324
325                 closeErrorPopup: function Ui_closeErrorPopup() {
326                         $('#errorPopup').popup('close');
327                 },
328
329                 /**
330                  * Deletes checked log entries
331                  */
332                 deleteCheckedLogs: function Ui_deleteCheckedLogs(e) {
333                         this.closePopup();
334
335                         this.selectCheckbox($('#selectAllDetails'), false);
336
337                         $('#forCallerList li.call').each(function () {
338                                 if ($(this).find('form label').hasClass('ui-checkbox-on')) {
339                                         app.deleteLog($(this).data('entries')[0]);
340                                         $(this).remove();
341                                 }
342                         });
343
344                         if ($('#forCallerList li.call').length > 0) {
345                                 this.updateCallerHeaderNumberOfEntries($('#forCallerList li.call').length);
346                         } else {
347                                 e.preventDefault();
348                                 $('.ui-listview-filter .ui-input-text').val('');
349                                 $('.ui-listview-filter .ui-input-text').trigger('change');
350                                 $.mobile.changePage('#callView');
351                         }
352
353                         this.changeDetailsToRemoveState(true);
354                         this.scrollToBottom();
355                 },
356
357                 changeDetailsToRemoveState: function Ui_changeDetailsToRemoveState(set, clear) {
358                         var counter = this.getCountSelectedLogEntries(),
359                                 numChecked = $('#forCallerList input:checked').length;
360                         if (clear === true) {
361                                 counter = 0;
362                                 $('#forCallerList').find(':checkbox').attr('checked', false)
363                                         .data('checkboxradio').refresh();
364                                 $('.selectAllBox').find(':checkbox').attr('checked', false)
365                                         .data('checkboxradio').refresh();
366                         }
367                         if (set !== undefined) {
368                                 this.removeMode = false;
369                         } else if (counter === 0) {
370                                 this.removeMode = !this.removeMode;
371                         }
372
373                         if (this.removeMode && numChecked === 0) {
374                                 $('#deleteActionBtn').addClass('ui-disabled').attr('tabIndex', '-1').blur();
375                         } else if (!this.removeMode) {
376                                 $('#deleteActionBtn').removeClass('ui-disabled').attr('tabIndex', '0');
377                                 this.selectAllDetailsEach();
378                         }
379
380                         if (counter === 0) {
381                                 if (this.removeMode) {
382                                         $('#historyForCallerView .toRemove').removeClass('hidden');
383                                         $('#historyForCallerView .selectAllBox')
384                                                 .removeClass('hidden');
385                                 } else {
386                                         $('#historyForCallerView .toRemove').addClass('hidden');
387                                         $('#historyForCallerView .selectAllBox').addClass('hidden');
388                                 }
389                         } else if (counter > 1) {
390                                 this.showPopup('Are you sure you want to delete selected logs?');
391                         } else {
392                                 this.showPopup('Are you sure you want to delete selected log?');
393                         }
394                         this.refreshScrollView();
395                 },
396
397                 /**
398                  * Renders call history list
399                  *
400                  * @param {CallHistoryEntry[]} callEntries
401                  */
402                 showCallHistory: function Ui_showCallHistory(callEntries) {
403                         var self = this,
404                                 pdate = null, // previous date
405                                 date = '',
406                                 elements = [], // list elements
407                                 len = callEntries.length, // entries length
408                                 tempLength = 0, // length of temporary table;
409                                 i, // loop counter
410                                 j, // loop counter
411                                 current, // current entry object
412                                 today = this.helpers.getShortDate(new Date()), // today short date
413                                 entryShortDate,
414                                 filterResult,
415                                 groupsOfDays = [],
416                                 dayLog,
417                                 index = 0,
418                                 calllogList = $('#calllogList'),
419                                 calllogListContent = $('#calllogListContent'),
420                                 calllogListContentPos;
421
422                         function filterForSameEntry(element) {
423                                 return self.getNumber(current) === self.getNumber(element)
424                                         && current.direction === element.direction;
425                         }
426
427                         $('.selectedCount').hide();
428
429                         for (i = 0; i < len; i = i + 1) {
430                                 current = callEntries[i];
431                                 date = this.helpers.toNativeDate(current.startTime);
432
433                                 // if date is changed create new deyLog;
434                                 if (date !== pdate) {
435                                         dayLog = {};
436                                         dayLog.date = date;
437                                         dayLog.entries = [];
438                                         dayLog.counters = [];
439                                         groupsOfDays.push(dayLog);
440                                         pdate = date;
441                                 }
442
443                                 // group entries by remote Party;
444                                 filterResult = dayLog.entries.filter(filterForSameEntry);
445                                 if (filterResult.length) {
446                                         index = dayLog.entries.indexOf(filterResult[0]);
447                                         dayLog.counters[index] += 1;
448                                 } else {
449                                         dayLog.entries.push(current);
450                                         dayLog.counters[dayLog.entries.length - 1] = 1;
451                                 }
452                         }
453                         // Create UL list with dividers;
454                         len = groupsOfDays.length;
455                         for (i = 0; i < len; i += 1) {
456                                 dayLog = groupsOfDays[i];
457                                 tempLength = dayLog.entries.length;
458                                 entryShortDate = this.helpers.getShortDate(dayLog.entries[0].startTime);
459                                 // add date header;
460                                 //original code, do not remove until web-ui release; N_SE-48946
461 //                              elements.push($(this.templateManager.get('dateRow', {
462 //                                      'date': today === entryShortDate ? 'Today' : dayLog.date
463 //                              })).get(0));
464
465                                 for (j = 0; j < tempLength; j = j + 1) {
466                                         elements.push(this.getCallItemRow(dayLog.entries[j], dayLog.counters[j]));
467                                 }
468                         }
469                         calllogListContentPos = this.helpers.getScrollPosition(calllogListContent);
470                         calllogList.empty().append(elements);
471
472                         /* workaround solution for not auto refreshing list view*/
473                         setTimeout(function () {
474                                 // original code, do not remove until web-ui release; N_SE-48946
475                                 calllogList.listview({
476                                         autodividers: true,
477                                         //filter: true,
478                                         autodividersSelector: function ( li ) {
479                                                 return $(li).find('.callDate').text() === app.ui.helpers.toNativeDate(new Date())
480                                                 ? "Today" : $(li).find('.callDate').text();
481                                         }
482                                 }).listview('refresh'); 
483                                 $(".ui-li-divider").removeClass().addClass("date");
484                         }, 0);
485
486                         /* workaround for registering call during working app in removeMode */
487                         if (this.removeMode) {
488                                 if ($('#selectAllDetails').attr('checked')){
489                                         this.selectAll();
490                                 }
491                                 $('.toRemove, .selectAllBox', $('#historyForCallerView'))
492                                         .removeClass('hidden');
493                                 $('#forCallerList .toRemove').show()
494                         }
495
496                         setTimeout(this.helpers.scrollTo.bind(this, calllogListContent, calllogListContentPos), 10);
497                 },
498
499                 /**
500                  * @param: {CallHistoryEntry} entry
501                  */
502                 getNumber: function (entry) {
503                         return entry.remoteParties[0].remoteParty;
504                 },
505
506                 /**
507                  * Returns HTML for single log entry
508                  *
509                  * @param {CallHistoryEntry} entry
510                  * @param {number} counter
511                  * @returns {HTMLPartial}
512                  */
513                 getCallItemRow: function Ui_getCallItemRow(entry, counter) {
514                         var party = entry.remoteParties[0],
515                                 name = this.getNameByNumber(party.remoteParty),
516                                 tpl;
517
518                         if (counter > 1) {
519                                 name += ' (' + counter + ')';
520                         }
521
522                         tpl = this.templateManager.get('callItemRow', {
523                                 'name': name,
524                                 'callTime': this.helpers.toNativeTime(entry.startTime),
525                                 'callDate': this.helpers.toNativeDate(entry.startTime),
526                                 'cssClasses': this.cssClassesForEntry(entry),
527                                 'uid': entry.uid
528                         });
529
530                         return $(tpl)
531                                 .data('remoteParty', entry.remoteParties[0].remoteParty)
532                                 .data('entries', [entry])
533                                 .get(0); // return clean DOM element so array of those could be appended at once*/
534                 },
535
536                 getNameByNumber: function (number) {
537                         var i, j, contact, name;
538                         for (i in this.contactsLoaded) {
539                                 if (this.contactsLoaded.hasOwnProperty(i)) {
540                                         contact = this.contactsLoaded[i];
541                                         for (j in contact.phoneNumbers) {
542                                                 if (contact.phoneNumbers.hasOwnProperty(j)) {
543                                                         if (contact.phoneNumbers[j].number.substr(-9)
544                                                                         === number.substr(-9)) {
545                                                                 name = contact.name.displayName;
546                                                                 break;
547                                                         }
548                                                 }
549                                         }
550                                 }
551                         }
552                         return name || number || 'Unknown';
553                 },
554
555                 /**
556                  * Returns HTML for single caller log entry
557                  *
558                  * @param {CallHistoryEntry} entry
559                  * @returns {HTMLElement}
560                  */
561                 getCallerCallLogRow: function Ui_getCallerCallLogRow(entry) {
562                         return $(this.templateManager.get('callerCallItemRow', {
563                                 'cssClass': this.cssClassesForEntry(entry),
564                                 'callTime': this.helpers.toNativeTime(entry.startTime),
565                                 'callDuration': this.helpers.secondsToHours(entry.duration),
566                                 'uid': entry.uid
567                         })).data('entries', [entry]).get(0);
568                 },
569
570                 /**
571                  * Renders call log list for specified caller
572                  *
573                  * @param {string} remoteParty
574                  * @param {CallHistoryEntry[]} entries
575                  */
576                 showHistoryForCaller: function Ui_showHistoryForCaller(remoteParty, entries) {
577                         var pdate = '',
578                                 date = '',
579                                 elements = [],
580                                 len = entries.length,
581                                 i,
582                                 checkbox;
583
584                         if (len) {
585                                 this.updateCallerHeader(entries[0], entries.length);
586                         } else {
587                                 // if last call log has been removed
588                                 this.removedLastLog();
589                                 this.app.lastViewedCaller = 0;
590                         }
591
592                         $('#forCallerList')
593                                 .data('remoteParty', remoteParty)
594                                 .data('modified', false)
595                                 .empty();
596
597                         // group caller log entries by date
598                         for (i = 0; i < len; i = i + 1) {
599                                 date = this.helpers.toNativeDate(entries[i].startTime);
600
601                                 // if date is changed render new header
602                                 if (date !== pdate) {
603                                         elements.push($(this.templateManager.get('dateRow', {'date': date})).get(0));
604                                         pdate = date;
605                                 }
606                                 elements.push(this.getCallerCallLogRow(entries[i]));
607                         }
608
609                         $('#forCallerList')
610                                 .empty()
611                                 .append(elements);
612
613                         if (elements.length > 0) {
614                                 $('li#delete > a').addClass('ui-btn-active');
615                         } else {
616                                 $('li#delete > a').removeClass('ui-btn-active');
617                         }
618
619                         $('#forCallerList').trigger('create');
620
621                         // change to remove mode if it was active before registering call
622                         if (this.removeMode) {
623                                 this.removeMode = !this.removeMode;
624                                 this.changeDetailsToRemoveState();
625                                 // check previous checked entries
626                                 this.checkedLogs.forEach(function(logUid){
627                                         checkbox = $('#forCallerList li.call[data-uid="' + logUid + '"]')
628                                                 .find(':checkbox');
629
630                                         if (checkbox.length > 0) {
631                                                 checkbox.attr('checked', true)
632                                                         .data('checkboxradio')
633                                                         .refresh();
634                                                 $('#deleteActionBtn').removeClass('ui-disabled').attr('tabIndex', '0');
635                                         }
636                                 });
637
638                                 // close popup if there are no checked checkboxes
639                                 if (!$("#forCallerList input:checked").length) {
640                                         if ($.mobile.popup.active) {
641                                                 $.mobile.popup.active.close();
642                                         }
643                                 }
644                         }
645                         this.addEventsForCallerListCheckboxes();
646                         // lock buttons if unknown caller
647                         if(remoteParty) {
648                                 this.unlockOptionButtons();
649                         } else {
650                                 this.lockButtons();
651                         }
652                 },
653
654                 /**
655                  * Update accoundId
656                  * @param {string} accountId
657                  */
658                 updateCallerHeaderAccountId: function Ui_updateCallerHeaderAccountId(accountId) {
659                         $('.infoContainer .accountId').html(accountId);
660                 },
661
662                 /**
663                  * Update number of entries
664                  * @param numberOfEntries
665                  */
666                 updateCallerHeaderNumberOfEntries: function Ui_updateCallerHeaderNumberOfEntries(numberOfEntries) {
667                         $('.infoContainer .numberOfEntries').html(numberOfEntries);
668                 },
669
670                 /**
671                  * Updates caller main info
672                  * @param {CallHistoryEntry} entry
673                  * @param {number} numberOfEntries
674                  */
675                 updateCallerHeader: function Ui_updateCallerHeader(entry, numberOfEntries) {
676                         var name = '', party, imgPath, personId;
677
678                         $('#header .photo').css('background-image', this.photoURIdefault);
679
680                         if (entry.remoteParties !== null) {
681                                 party = entry.remoteParties[0];
682                                 personId = parseInt(party.personId, 10);
683                                 name = this.getNameByNumber(party.remoteParty);
684                                 if (party.displayName) {
685                                         this.updateCallerHeaderAccountId(party.remoteParty);
686                                 }
687                                 this.updateCallerHeaderNumberOfEntries(numberOfEntries);
688                                 if (personId !== 0) {
689                                         imgPath = app.getPhotoURIForContact(personId);
690                                         if (imgPath !== false) {
691                                                 $('#header .photo').css('background-image', 'url(' + imgPath + ')');
692                                         }
693                                 }
694                         } else if (entry.contactId !== null) {
695                                 name = entry.accountId;
696                                 this.updateCallerHeaderAccountId(entry.accountId);
697                                 this.updateCallerHeaderNumberOfEntries(numberOfEntries);
698                         } else {
699                                 name = entry.accountId;
700                                 this.updateCallerHeaderAccountId('');
701                                 this.updateCallerHeaderNumberOfEntries(numberOfEntries);
702                         }
703                         $('.contact > .infoContainer > .name').html(this.templateManager.modifiers.escape(name));
704
705                 },
706
707                 loadContacts: function Model_loadContacts(callback) {
708                         var contactsFoundCB, errorCB;
709
710                         this.contactsLoaded = null;
711
712                         contactsFoundCB = function (contacts) {
713                                 this.contactsLoaded = contacts;
714                                 if (callback instanceof Function) {
715                                         callback();
716                                 }
717                         };
718
719                         errorCB = function (error) {
720                                 console.error('Model_loadContacts, problem with find() method: ' + error.message);
721                         };
722
723                         this.addressBook.find(contactsFoundCB.bind(this), errorCB);
724                 },
725
726                 /**
727                  * Remove search filter from content and appends it to header
728                  */
729                 removeSearchBarToHeader: function () {
730                         $('#page-header').append($('#callView .ui-listview-filter'));
731                         $.mobile.activePage.page('refresh');
732                         $('.ui-input-cancel').remove(); // patch for WebUI bug;
733                 },
734
735                 scrollToBottom: function () {
736                         var scrollView = $(".ui-scrollview-view");
737                         scrollView.css("-webkit-transform", "translate3d(0px, -" +
738                                                 scrollView.height() + "px, 0px)");
739                 },
740
741                 onVisibilityChange: function () {
742                         var self = this;
743                         document.addEventListener('webkitvisibilitychange', function () {
744                                 if (document.webkitVisibilityState === 'hidden') {
745                                         self.checkedLogs = [];
746                                         $('#forCallerList li.call').each(function () {
747                                                 if ($(this).find('form label')
748                                                         .hasClass('ui-checkbox-on')) {
749                                                         var checkedEntry = $(this).data('entries')[0];
750                                                         self.checkedLogs.push(checkedEntry.uid);
751                                                 }
752                                         });
753                                 } else {
754                                         self.loadContacts(app.updateCallLists.bind(app));
755                                         $('#callActionBtn, #smsActionBtn')
756                                                 .removeClass('ui-disabled').attr('tabIndex', '0');
757                                 }
758                         });
759                 },
760
761                 lockButtons: function () {
762                         $('#callActionBtn, #smsActionBtn').addClass('ui-disabled').attr('tabIndex', '-1').blur();
763                 },
764
765                 unlockOptionButtons : function Ui_unlockOptionButtons(){
766                         $('#callActionBtn, #smsActionBtn').removeClass('ui-disabled').attr('tabIndex', '0');
767                 },
768
769                 /**
770                  * WORKAROUND;
771                  * Patch for UI, bad refresh scrollView
772                  */
773                 refreshScrollView: function () {
774                         var scrollView = $('.ui-scrollview-view'),
775                                 show = function () {
776                                         scrollView.show();
777                                 };
778                         scrollView.hide();
779                         setTimeout(show, 0);
780                 },
781
782                 removedLastLog: function () {
783                         this.hideCheckboxes();
784                         $(".ui-popup").popup('close');
785                         $.mobile.changePage('#callView');
786                 }
787         };
788
789 }());