[CallLog] updated CallLog sources
authorPiotr Dabrowski <p.dabrowski2@samsung.com>
Fri, 13 Sep 2013 06:53:41 +0000 (08:53 +0200)
committerPiotr Dabrowski <p.dabrowski2@samsung.com>
Fri, 13 Sep 2013 06:53:41 +0000 (08:53 +0200)
Change-Id: I08cee4030f1384554006bc1f5e6d69be1528a5dc

js/app.helpers.js
js/app.ui.js
js/app.ui.templateManager.js
templates/callItemRow.tpl

index 08f8c4c..7bb1869 100644 (file)
@@ -30,7 +30,34 @@ function Helpers() {
 
                        return yyyy + '/' + (mm[1] ? mm : '0' + mm[0]) + '/' + (dd[1] ? dd : '0' + dd[0]);
                },
+               /**
+                * Returns date in format DD short_month YYYY
+                * @param dateObj
+                * @returns {String} formatted
+                */
+               toNativeDate: function Helpers_toNativeDate(dateObj) {
+                       var date = dateObj.toDateString().split(" ");
+
+                       return  date[2] + ' ' + date[1] + ' ' + date[3];
+               },
+               /**
+                * Returns time in format HH:mm or hh:mm ap
+                * @param dateObj
+                * @returns {String} formatted
+                */
+               toNativeTime: function Helpers_toNativeDate(dateObj) {
+                       var hours, apHours;
+
+                       if (tizen.time.getTimeFormat().indexOf('ap') != -1) {
+                               hours = dateObj.getHours();
+                               apHours = hours % 12 < 10 ? '0' + hours % 12 : hours % 12;
 
+                               return apHours.toString().replace("00", "12") + ':' +
+                                       dateObj.getMinutes() + (hours > 11 ? ' PM' : ' AM');
+                       }
+
+                       return dateObj.toTimeString().substring(0, 5);
+               },
                /**
                 * Seconds to hours converter
                 *
index 74387a6..8befbe9 100644 (file)
@@ -436,7 +436,7 @@ function Ui(contacts) {
 
                        for (i = 0; i < len; i = i + 1) {
                                current = callEntries[i];
-                               date = current.startTime.toLocaleDateString();
+                               date = this.helpers.toNativeDate(current.startTime);
 
                                // if date is changed create new deyLog;
                                if (date !== pdate) {
@@ -484,7 +484,7 @@ function Ui(contacts) {
                                        autodividers: true,
                                        //filter: true,
                                        autodividersSelector: function ( li ) {
-                                               return $(li).find('.callDate').text() === new Date().toLocaleDateString() 
+                                               return $(li).find('.callDate').text() === app.ui.helpers.toNativeDate(new Date())
                                                ? "Today" : $(li).find('.callDate').text();
                                        }
                                }).listview('refresh'); 
@@ -529,8 +529,8 @@ function Ui(contacts) {
 
                        tpl = this.templateManager.get('callItemRow', {
                                'name': name,
-                               'callTime': entry.startTime.toLocaleTimeString(),
-                               'callDate': entry.startTime.toLocaleDateString(),
+                               'callTime': this.helpers.toNativeTime(entry.startTime),
+                               'callDate': this.helpers.toNativeDate(entry.startTime),
                                'cssClasses': this.cssClassesForEntry(entry),
                                'uid': entry.uid
                        });
@@ -569,7 +569,7 @@ function Ui(contacts) {
                getCallerCallLogRow: function Ui_getCallerCallLogRow(entry) {
                        return $(this.templateManager.get('callerCallItemRow', {
                                'cssClass': this.cssClassesForEntry(entry),
-                               'callTime': entry.startTime.toLocaleTimeString(),
+                               'callTime': this.helpers.toNativeTime(entry.startTime),
                                'callDuration': this.helpers.secondsToHours(entry.duration),
                                'uid': entry.uid
                        })).data('entries', [entry]).get(0);
@@ -604,7 +604,7 @@ function Ui(contacts) {
 
                        // group caller log entries by date
                        for (i = 0; i < len; i = i + 1) {
-                               date = entries[i].startTime.toLocaleDateString();
+                               date = this.helpers.toNativeDate(entries[i].startTime);
 
                                // if date is changed render new header
                                if (date !== pdate) {
@@ -708,7 +708,7 @@ function Ui(contacts) {
                                this.updateCallerHeaderAccountId('');
                                this.updateCallerHeaderNumberOfEntries(numberOfEntries);
                        }
-                       $('.contact > .infoContainer > .name').html(name);
+                       $('.contact > .infoContainer > .name').html(this.templateManager.modifiers.escape(name));
 
                },
 
index e2a440a..463c032 100644 (file)
@@ -108,27 +108,30 @@ function TemplateManager() {
                },
 
                passThruModifiers: function (tplHtml, tplParam, content) {
-                       var regModOn = new RegExp('%' + tplParam + '\\|([a-zA-Z]){1,}%', 'g'),
+                       var regModOn = new RegExp('%' + tplParam + '(\\|(.+?)){1,}%', 'g'),
                                regModOff = new RegExp(['%', tplParam, '%'].join(''), 'g'),
                                regModGet = new RegExp('%' + tplParam + '\\|(.+?)%'),
+                               regModPut = new RegExp('%' + tplParam + '\\|(.+?)%', 'g'),
                                specRegExp = new RegExp('\\$','g'),
-                               modifier;
+                               modifiers, i;
 
                        if (content && (typeof content === 'string')) {
                                content = content.replace(specRegExp, '$$$$');
                        }
 
                        if (regModOn.test(tplHtml)) {
-                               modifier = tplHtml.match(regModGet)[1];
-                               try {
-                                       content = this.modifiers[modifier](content);
-                               } catch (error) {
-                                       console.error('unknown modifier: ' + modifier);
+                               modifiers = tplHtml.match(regModGet)[1].split('|');
+                               for (i in modifiers) {
+                                       if (this.modifiers[modifiers[i]] instanceof Function){
+                                               content = this.modifiers[modifiers[i]](content);
+                                       } else {
+                                               console.error('unknown modifier: ' + modifiers[i]);
+                                       }
                                }
-                               tplHtml = tplHtml.replace(regModOn, content);
-                       } else {
-                               tplHtml = tplHtml.replace(regModOff, content);
+                               tplHtml = tplHtml.replace(regModPut, content);
                        }
+                       tplHtml = tplHtml.replace(regModOff, content);
+
                        return tplHtml;
                }
        };
index 690d5e5..7cdb23a 100644 (file)
@@ -1,6 +1,6 @@
-<li data-filtertext="%name%" class="%cssClasses%">
+<li data-filtertext="%name|escape%" class="%cssClasses%">
        <div class="toRemove hidden"><input type="checkbox" /></div>
-       <div class="numberOrName">%name%</div>
+       <div class="numberOrName">%name|escape%</div>
        <div class="iconStatus"></div>
        <div class="callTime">%callTime%</div>
        <div class="callDate hidden">%callDate%</div>