Permalink
Browse files

Date parsing and sorting, Along with loading icons

  • Loading branch information...
1 parent f924b41 commit 56c3a89038fa8e75bb714ca2d9a2d058e8dcc613 @stefancrain stefancrain committed Jan 24, 2013
@@ -144,15 +144,16 @@ public static function unifiedMessageInfo($email) {
'from_email' => $email->sender[0]->mailbox.'@'.$email->sender[0]->host,
'subject' => $email->subject,
'body' => $body,
- 'date_clean' => self::cleanDate($email->date),
+ 'date_clean' => self::cleanDate($email->date,'short'),
+ 'date_long' => self::cleanDate($email->date,'long'),
'status' => $status,
);
// if we have a direct message populate accordingly
$origin = ($status == 'direct') ? $header['from'] : $froms['2'];
$origin_name = ($status == 'direct') ? $header['from_name'] : $fromEmail['name'];
$origin_email = ($status == 'direct') ? $header['from_email'] : $fromEmail['email'];
- $origin_date = (substr(self::cleanDate($tempDetails),0,8) == '12-31-69') ? $header['date_clean'] : self::cleanDate($tempDetails);
+ $origin_date = (substr(self::cleanDate($tempDetails,'short'),0,8) == '12-31-69') ? $header['date_clean'] : self::cleanDate($tempDetails,'short');
$origin_subject = ($status == 'direct') ? preg_replace("/(Fwd:|fwd:|Fw:|fw:|Re:|re:) /i", "", $header['subject']) : preg_replace("/(Fwd:|fwd:|Fw:|fw:|Re:|re:) /i", "", $subjects['2']);
@@ -220,6 +221,7 @@ public static function getUnmatchedMessages() {
'from' => $output['forwarded']['origin_name'].' '.$output['forwarded']['origin_email'],
'uid' => $header->uid,
'date' => $output['header']['date_clean'],
+ 'date_long' => $output['header']['date_long'],
'format' => $output['header']['format'],
'from_email' => $output['forwarded']['origin_email'],
'from_name' => $output['forwarded']['origin_name'],
@@ -232,7 +234,6 @@ public static function getUnmatchedMessages() {
'status' =>$output['header']['status'],
'imap_id' => $imap_id,
// 'origin_lookup' => $output['forwarded']['origin_lookup']
-
);
}else{
@@ -360,7 +361,7 @@ public static function getMessageDetails() {
* Returns: The 'm-d-y h:i A' formatted date date .
* This function will format many types of incoming dates
*/
- public static function cleanDate($date_string){
+ public static function cleanDate($date_string, $type){
$matches = array();
// search for the word date
@@ -371,8 +372,17 @@ public static function cleanDate($date_string){
$date_string_short = preg_replace("/(at)/i", "", $date_string_short);
// reformat the date to something standard here.
- $date_string_short = date("m-d-y H:i", strtotime($date_string_short));
- return $date_string_short;
+ if($type=='long'){
+ return date("YmdHi", strtotime($date_string_short));
+ }else{
+ // check if the message is from last year
+ if ( (date("Y", strtotime($date_string_short)) - date("Y")) < 0 ){
+ return date("M d, Y h:i A", strtotime($date_string_short));
+ }else{
+ return date("M d, h:i A", strtotime($date_string_short));
+ }
+ }
+
}
/* deleteMessage()
@@ -825,7 +835,8 @@ public static function getMatchedMessages() {
$forwarder = civicrm_api('contact', 'get', $params );
$forwarder_node = $forwarder['values'][$activity_node['source_contact_id']];
- $date = date('m-d-y h:i A', strtotime($activity_node['activity_date_time']));
+ $date = self::cleanDate($activity_node['activity_date_time'],'short');
+ $date_long = self::cleanDate($activity_node['activity_date_time'],'long');
// message to return
if ($debug){
var_dump($activity_node);
@@ -844,7 +855,9 @@ public static function getMatchedMessages() {
'details' => $activity_node['details'],
'match_type' => $activity_node['is_auto'],
'original_id' => $activity_node['original_id'],
- 'date' => $date);
+ 'date' => $date,
+ 'date_long' => $date_long
+ );
}
$returnMessage['count'] = count($returnMessage);
echo json_encode($returnMessage);
@@ -884,7 +897,7 @@ public static function getActivityDetails() {
$forwarder = civicrm_api('contact', 'get', $params );
$forwarder_node = $forwarder['values'][$activity_node['source_contact_id']];
- $date = date('m-d-y h:i A', strtotime($activity_node['activity_date_time']));
+ $date = self::cleanDate($activity_node['activity_date_time'],'short');
$returnMessage = array('uid' => $activitId,
'fromName' => $contact_node['display_name'],
@@ -16,7 +16,7 @@
</tr>
</thead>
<tbody id='imapper-messages-list'>
- <tr><td>Loading Message data <img src="/sites/default/themes/Bluebird/images/loading.gif"/></td></tr>
+ <tr><td><span class="loading_row"><span class="loading_message">Loading Message data <img src="/sites/default/themes/Bluebird/images/loading.gif"/></span></span></td></tr>
</tbody>
</table>
<div class='page_actions'>
@@ -15,8 +15,8 @@
<th class='Actions'>Actions</th>
</tr>
</thead>
- <tbody id='imapper-messages-list' >
- <tr><td>Loading Message data <img src="/sites/default/themes/Bluebird/images/loading.gif"/></td></tr>
+ <tbody id='imapper-messages-list'>
+ <tr><td><span class="loading_row"><span class="loading_message">Loading Message data <img src="/sites/default/themes/Bluebird/images/loading.gif"/></span></span></td></tr>
</tbody>
</table>
<div class='page_actions'>
@@ -101,4 +101,6 @@ a.tag-selected:hover { color: #fff!important; background-color: red; }
#message_right label{float: left;display: block;}
.label_def{width: 95px;font-weight: bold;float: left;margin: 0.4em 0 0.02em;}
#message_right label input {width: 150px; }
-#tagging #BBTreeContainer .BBTree, #BBDialog .BBTree{height: 200px;}
+#tagging #BBTreeContainer .BBTree, #BBDialog .BBTree{height: 200px;}
+.loading_message{ margin: 0px auto; background: #fff; padding:5px; width: 200px}
+
@@ -875,13 +875,34 @@ function destroyReSortable(){
makeListSortable();
}
+// needed to format timestamps to allow sorting:
+// make a hidden title with the non-readable date and sort on that
+
+cj.extend( cj.fn.dataTableExt.oSort, {
+ "title-string-pre": function ( a ) {
+ return a.match(/data="(.*?)"/)[1].toLowerCase();
+ },
+
+ "title-string-asc": function ( a, b ) {
+ return ((a < b) ? -1 : ((a > b) ? 1 : 0));
+ },
+
+ "title-string-desc": function ( a, b ) {
+ return ((a < b) ? 1 : ((a > b) ? -1 : 0));
+ }
+} );
+
function makeListSortable(){
cj("#sortable_results").dataTable({
"aaSorting": [[ 3, "desc" ]],
+ "aoColumnDefs": [ { "sType": "title-string", "aTargets": [ 3 ] }],
// "aoColumnDefs": [ { "bSearchable": true, "bVisible": false, "aTargets": [ 3 ] } ],
"iDisplayLength": 50,
- // "bStateSave": true,
- 'aTargets': [ 1 ]
+ "bStateSave": true,
+ 'aTargets': [ 1 ],
+ "bPaginate": false,
+ "bAutoWidth": false,
+ "bInfo": false,
});
// unbind the sort on the checkbox and actions
cj("th.checkbox").removeClass('sorting').unbind('click');
@@ -939,8 +960,7 @@ function buildMessageList() {
// messagesHtml += '<td class="email"></td>';
messagesHtml += '<td class="subject">'+short_subject(value.subject,40) +' '+icon+'</td>';
- messagesHtml += '<td class="date">'+value.date +'</td>';
-
+ messagesHtml += '<td class="date"><span data="'+value.date_long+'">'+value.date +'<span></td>';
// check for direct messages & not empty forwarded messages
if((value.status == 'direct' ) && (value.forwarder_email != '')){
@@ -989,7 +1009,7 @@ function buildActivitiesList() {
messagesHtml += '<span class="emailbubble marginL10">'+short_subject(value.fromEmail,14)+'</span>';
messagesHtml +='</td>';
messagesHtml += '<td class="subject">'+short_subject(value.subject,50) +'</td>';
- messagesHtml += '<td class="date">'+value.date +'</td>';
+ messagesHtml += '<td class="date"><span data="'+value.date_long+'">'+value.date +'<span></td>';
messagesHtml += '<td class="forwarder">'+short_subject(value.forwarder,14)+'</td>';
messagesHtml += '<td class="Actions"> <span class="edit_match"><a href="#">Edit</a></span> | <span class="add_tag"><a href="#">Tag</a></span> | <span class="clear_activity"><a href="#">Clear</a></span> | <span class="delete"><a href="#">Delete</a></span></td> </tr>';
}

0 comments on commit 56c3a89

Please sign in to comment.