From 17a14753e0b816c6c082ca42b46ba83a88d1f233 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Tue, 7 Oct 2014 10:33:36 +0200 Subject: [PATCH] PeerList modification Export peerList loading from document.ready. Modify peerlist only if there is peers --- js/script.js | 41 ++++++++++++++++++++++++----------------- templates/main.php | 1 + 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/js/script.js b/js/script.js index 42a2d37..c65d9a9 100644 --- a/js/script.js +++ b/js/script.js @@ -140,27 +140,34 @@ function changeSelectedConversation(item) { selectedConversation.parent().addClass('selected'); } +function fetchInitialPeerList() { + // Use a buffer for better jQuery performance + var peerListBuf = ""; + + $.each(jsondata['phonelist'], function(id, val) { + var fn, peerLabel; + if (typeof jsondata['contacts'][val] == 'undefined') { + fn = ''; + peerLabel = val; + } + else { + fn = jsondata['contacts'][val]; + peerLabel = fn; + } + peerListBuf += '
  • ' + peerLabel + '
  • '; + }); + + // Only modify peerList if there is peers + if (peerListBuf != '') { + $('#app-mailbox-peers ul').html(peerListBuf); + } +} + (function ($, OC) { $(document).ready(function () { // Now bind the events when we click on the phone number $.getJSON(OC.generateUrl('/apps/ocsms/get/peerlist'), function(jsondata, status) { - // Use a buffer for better jQuery performance - var peerListBuf = ""; - - $.each(jsondata['phonelist'], function(id, val) { - var fn, peerLabel; - if (typeof jsondata['contacts'][val] == 'undefined') { - fn = ''; - peerLabel = val; - } - else { - fn = jsondata['contacts'][val]; - peerLabel = fn; - } - peerListBuf += '
  • ' + peerLabel + '
  • '; - }); - - $('#app-mailbox-peers ul').html(peerListBuf); + fetchInitialPeerList(); // Now bind the events when we click on the phone number $('#app-mailbox-peers').find('a[mailbox-navigation]').on('click', function (event) { diff --git a/templates/main.php b/templates/main.php index 9ed64c8..2211ba9 100644 --- a/templates/main.php +++ b/templates/main.php @@ -6,6 +6,7 @@