From b8d0e66a9dbe44191a865a20c1c20a3186b995b7 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 9 Oct 2014 18:57:47 +0000 Subject: [PATCH] Show the multiple phone numbers into the header --- controller/smscontroller.php | 6 +++++- js/script.js | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/controller/smscontroller.php b/controller/smscontroller.php index 16b0379..db9e66b 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -114,6 +114,7 @@ class SmsController extends Controller { } $messages = array(); + $phoneNumbers = array(); // Contact resolved if ($contactName != "") { @@ -128,22 +129,25 @@ class SmsController extends Controller { for ($i=0; $i < $ctPn; $i++) { $messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $iContacts[$contactName][$i], $lastDate); + $phoneNumbers[] = $iContacts[$contactName][$i]; } } // This case mustn't be reached, but add it. else { $messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $phoneNumber, $lastDate); + $phoneNumbers[] = $phoneNumber; } } else { $messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $phoneNumber, $lastDate); + $phoneNumbers[] = $phoneNumber; } // Order by id (date) ksort($messages); // @ TODO: filter correctly - return new JSONResponse(array("conversation" => $messages, "contactName" => $contactName)); + return new JSONResponse(array("conversation" => $messages, "contactName" => $contactName, "phoneNumbers" => $phoneNumbers)); } /** diff --git a/js/script.js b/js/script.js index f772b01..e39edf8 100644 --- a/js/script.js +++ b/js/script.js @@ -58,15 +58,32 @@ function fetchConversation(phoneNumber) { 'phoneNumber': phoneNumber }, function(jsondata, status) { + var phoneNumberLabel = phoneNumber; + + if (typeof jsondata['phoneNumbers'] != 'undefined') { + len = jsondata["phoneNumbers"].length; + ctLen = 0; + phoneNumberLabel = ''; + + $.each(jsondata["phoneNumbers"], function(id, val) { + phoneNumberLabel += val; + ctLen++; + if (ctLen != len) { + phoneNumberLabel += ","; + } + phoneNumberLabel += " "; + }); + } + conversationBuf = formatConversation(jsondata); conversationBuf += '
'; if (typeof jsondata['contactName'] == 'undefined') { - $('#ocsms-phone-label').html(phoneNumber); + $('#ocsms-phone-label').html(phoneNumberLabel); $('#ocsms-phone-opt-number').html(''); } else { $('#ocsms-phone-label').html(jsondata['contactName']); - $('#ocsms-phone-opt-number').html(phoneNumber); + $('#ocsms-phone-opt-number').html(phoneNumberLabel); } if ($('#app-content-header').is(':hidden')) {