diff --git a/js/script.js b/js/script.js index f51a25b..b9f9270 100644 --- a/js/script.js +++ b/js/script.js @@ -8,28 +8,47 @@ * @copyright Loic Blot 2014 */ +function fetchConversation(phoneNumber) { + $.getJSON(OC.generateUrl('/apps/ocsms/get/get_conversation'), + {'phoneNumber': phoneNumber}, + function(jsondata, status) { + var conversationBuf = ""; + + $.each(jsondata["conversation"]), function(id, vals) { + conversationBuf += vals["msg"] + "
"; + }); + + $('#app-content').html(conversationBuf); + } + ); +} (function ($, OC) { $(document).ready(function () { // Now bind the events when we click on the phone number $('#app-navigation').find('a').on('click', function (event) { OC.Util.History.pushState('feed=' + $(this).attr('nav-feed')); - event.preventDefault(); - }); + event.preventDefault(); + }); $.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) { peerListBuf += '
  • ' + val + '
  • '; }); + $('#app-mailbox-peers ul').html(peerListBuf); - + // Now bind the events when we click on the phone number $('#app-mailbox-peers').find('a[mailbox-navigation]').on('click', function (event) { - OC.Util.History.pushState('phonenumber=' + $(this).attr('mailbox-navigation')); - event.preventDefault(); - }); + var phoneNumber = $(this).attr('mailbox-navigation'); + OC.Util.History.pushState('phonenumber=' + phoneNumber); + fetchConversation(phoneNumber); + event.preventDefault(); + }); - }); + }); }); })(jQuery, OC);