1 /*global Phone, callContactCarousel*/
6 * This class provides methods to operate with call history carousel. It wrapps handling CarouFredSel object and provides
7 * following operations:
9 * * Show placed, received and missed phone calls ordered by date of phone call
10 * * For each call displays phone number, contact name, date and time of phone call
12 * @module PhoneApplication
16 var Carousel = function() {
18 this.initializeSwipe();
21 * This property holds call history data array for show in html.
22 * @property callHistory {Array}
24 Carousel.prototype.callHistory = [];
26 * This property holds swipe object for internal use in carousel.
27 * @property swipe {Object}
30 Carousel.prototype.swipe = null;
32 * This property holds callback function which is called after current element in carousel is changed.
33 * @property indexChangeCallback {Object}
36 Carousel.prototype.indexChangeCallback = null;
38 * This method adds listener for current carousel element change.
40 * @method addIndexChangeListener
41 * @param indexChangeCallback {function()} Callback function called after current carousel element changed.
43 Carousel.prototype.addIndexChangeListener = function(indexChangeCallback) {
46 this.indexChangeCallback = indexChangeCallback;
49 * This method initializes and configures carousel object
51 * @method initializeSwipe
54 Carousel.prototype.initializeSwipe = function() {
59 this.swipe = $('#contactsCarousel').carouFredSel({
76 onAfter : function(data) {
77 if (!!self.indexChangeCallback) {
78 self.indexChangeCallback(self.getCurrentPosition());
83 if (!this.swipe.length) {
89 * This method provides the index of current selected item of the carousel.
91 * @method getCurrentPosition
92 * @return Current {Integer} index position in carousel.
94 Carousel.prototype.getCurrentPosition = function() {
98 var pos = parseInt(self.swipe.triggerHandler("currentPosition"), 10);
104 * This method moves current position of the carousel to the given index.
107 * @param index {Integer} New index position in carousel
109 Carousel.prototype.slideTo = function(index) {
111 if (!!this.swipe && index >= 0 && index < this.callHistory.length) {
112 this.swipe.trigger("slideTo", index);
116 * This method fills carousel with call history data and resets its current position to start.
118 * @method loadCallHistory
119 * @param callHistory {Array} Call history array.
120 * @param index {Integer} New index position in carousel.
122 Carousel.prototype.loadCallHistory = function(callHistory, index) {
124 this.removeAllItems();
125 this.callHistory = callHistory;
126 this.insertPagesToSwipe();
127 if (index >= 0 && index < this.callHistory.length && !!this.swipe) {
128 this.swipe.trigger("slideTo", [ index, 0, {
134 * This method creates one carousel item for swipe.
136 * @method createSwipeItem
137 * @param callHistory {Array} Call history array.
138 * @param index {Integer} Carousel item index it is use as div id in html.
139 * @return {String} New carousel item as html string.
142 Carousel.prototype.createSwipeItem = function(callHistoryEntry, index) {
146 if (!!callHistoryEntry) {
150 if (!!callHistoryEntry.remoteParties && callHistoryEntry.remoteParties.length) {
151 contact = Phone.getContactByPersonId(callHistoryEntry.remoteParties[0].personId);
157 var phoneNumber = "";
158 var startTime = callHistoryEntry.startTime || "";
159 var direction = callHistoryEntry.direction || "";
161 if (!!callHistoryEntry.remoteParties && callHistoryEntry.remoteParties.length) {
162 // personId = phoneNumber
163 phoneNumber = callHistoryEntry.remoteParties[0].personId;
170 if (!!contact.photoURI) {
171 photoURI = contact.photoURI;
173 if (phoneNumber === "" && !!contact.phoneNumbers && contact.phoneNumbers.length) {
174 phoneNumber = contact.phoneNumbers[0].number;
176 name = Phone.getDisplayNameStr(contact);
183 carouselItem = '<li>';
184 carouselItem += '<div id="carouselBox_' + index + '" class="carouselBox borderColorTheme" data-id="' + id + '">';
185 carouselItem += '<div class="carouselPhotoArea borderColorTheme">';
186 carouselItem += '<div class="carouselPhotoBox noContactPhoto">';
187 carouselItem += '<img class="carouselPhoto" src="' + photoURI + '" /></div></div>';
188 carouselItem += '<div class="carouselInfoBox carouselName fontSizeLarger fontWeightBold fontColorNormal">' + name + '</div>';
189 carouselItem += '<div class="carouselInfoBox carouselNumber fontSizeSmall fontWeightBold fontColorTheme">' + phoneNumber + '</div>';
190 carouselItem += '<div class="callHistoryElement borderColorTheme">';
191 carouselItem += '<div class="missedNewCallIcon callHistoryIcon callHistoryIconGen"></div>';
192 carouselItem += '<div class="callHistoryDetails">';
193 carouselItem += '<div class="fontSizeXXSmall fontColorNormal">' + startTime + '</div>';
194 carouselItem += '<div class="fontSizeXXSmall fontWeightBold fontColorTheme">' + direction + '</div></div></div></div>';
195 carouselItem += '</li>';
197 carouselItem = $(carouselItem);
198 carouselItem.data("callhistory", callHistoryEntry);
199 carouselItem.data("contact", contact);
200 carouselItem.click(function() {
201 self.swipe.trigger("slideTo", [ $(this), -1 ]);
202 var hystoryEntry = $(this).data("callhistory");
203 var contactEntry = $(this).data("contact");
206 displayName : contactEntry.name.displayName,
207 firstName : contactEntry.name.firstName,
208 lastName : contactEntry.name.lastName
210 photoURI : contactEntry.photoURI,
212 number : hystoryEntry.remoteParties[0].personId
216 callContactCarousel(contact);
224 * This method inserts pages whit carousel elements to swipe.
226 * @method insertPagesToSwipe
229 Carousel.prototype.insertPagesToSwipe = function() {
233 for ( var index = this.callHistory.length - 1; index >= 0; --index) {
234 carouselItem = this.createSwipeItem(this.callHistory[index], index);
235 if (!!carouselItem && !!this.swipe) {
236 this.swipe.trigger("insertItem", [ carouselItem, 0 ]);
239 this.addCarouselEdges();
242 * This method removes all item from carousel.
244 * @method removeAllItems
246 Carousel.prototype.removeAllItems = function() {
251 for ( var index = this.callHistory.length + 1; index >= 0; --index) {
252 this.swipe.trigger("removeItem", index);
257 * This method adds emty carousel items to the beginning and the end of the carousel
258 * (to make sure first and last visible items appear in the middle of screen instead of at the edges when swiped to edges of carousel).
259 * @method addCarouselEdges
261 Carousel.prototype.addCarouselEdges = function() {
264 var html = "<li><div class='carouselEdgeBox'></div></li>";
265 this.swipe.trigger("insertItem", [ html, 0 ]);
266 this.swipe.trigger("insertItem", [ html, "end", true ]);