From 83f233a7fe270dc77893c2df590b2e28ba30fc41 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Sat, 27 Aug 2016 15:43:07 -0400 Subject: Added more inbox functionality for paging --- assets/css/user_profile.css | 18 +++-- assets/js/script.js | 1 - assets/js/user_profile.js | 166 +++++++++++++++++++++++++++++++++++++++++++- node_simple.js | 26 ------- routes/user.js | 22 +++--- views/user_profile_alt.hbs | 42 ++--------- 6 files changed, 194 insertions(+), 81 deletions(-) diff --git a/assets/css/user_profile.css b/assets/css/user_profile.css index 042d842..fb35bb0 100644 --- a/assets/css/user_profile.css +++ b/assets/css/user_profile.css @@ -11,7 +11,6 @@ box-shadow: 2px 4px 5px 0 rgba(0,0,0,0.1); text-align: left; font-family: 'Roboto', sans-serif; - } .u-title h1{ @@ -134,10 +133,7 @@ nav .nav-o:hover .nav-o-container{ color: #737373; } - /* Inbox */ - - .u-table-row { display:table-row; cursor: pointer; @@ -146,5 +142,19 @@ nav .nav-o:hover .nav-o-container{ background-color: #ededed; } +/* Inbox Popups */ +.u-main .modal-content{ + padding: 0 20px 0 20px; +} + +/* Inbox paging */ +.u-pagination{ + text-align: center; +} + +.u-change-page{ + display: inline; + cursor: pointer; +} /*** USER PROFILE PAGE END ***/ \ No newline at end of file diff --git a/assets/js/script.js b/assets/js/script.js index 7a4c21f..0881ac6 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -25,6 +25,5 @@ function main(){ $('.table-row').trigger('create'); - } $(document).ready(main); \ No newline at end of file diff --git a/assets/js/user_profile.js b/assets/js/user_profile.js index c26299b..c28cb8d 100644 --- a/assets/js/user_profile.js +++ b/assets/js/user_profile.js @@ -1,4 +1,8 @@ function main(){ + //Constants and Globals + var MESSAGE_COUNT = 8; // Number of message per page in inbox + var CURRENT_INBOX_PAGE = 1; + // User-profile dynamic paging var items = [ $("#profile-general"), @@ -6,12 +10,153 @@ function main(){ $("#profile-comments"), $("#profile-inbox")]; + // Helper functions function hidePages(){ items.forEach(function(item){ item.hide(); }); } + function generatePager(mailCount){ + var pageCount = Math.ceil(mailCount/MESSAGE_COUNT); + if(pageCount > 1){ + + // State current page + $('#u-pageNumber').empty().append(CURRENT_INBOX_PAGE + ' of ' + pageCount) + .addClass('u-pagination'); + + + var $uPager = $("#u-pager"); + $uPager.empty(); + + var $pager = $('
').addClass('u-pagination'); + $uPager.append($pager); + + var $previous = $("
").append('< Previous') + .attr('id', 'u-previous') + .addClass('u-change-page'); + var $next = $("
").append('Next >') + .attr('id', 'u-next') + .addClass('u-change-page'); + + if(CURRENT_INBOX_PAGE == 1){ + $pager.append($next); + }else if(CURRENT_INBOX_PAGE == pageCount){ + $pager.append($previous); + }else{ + $pager.append($previous); + $pager.append(' | '); + $pager.append($next); + + } + } + } + + function generateInbox(pageNum){ + $.ajax({ + dataType: "json", + url: '/user/user_profile/inbox/' + MESSAGE_COUNT + '/' + pageNum, + success: function(mailbox){ + + + var inbox = mailbox.mail; + var mailCount = mailbox.mailCount; + var uInboxCount = $('#u-inbox-count'); + + uInboxCount.empty().append('You have ' + mailCount + + ' messages in your inbox.'); + + // For inbox table body + var $InboxBody = $('#u-inbox-body'); + + // For table modal op up windows + var $InboxContainer = $('#u-inbox-container'); + + $InboxBody.empty(); + + var windowCounter = 0; + inbox.forEach(function(message){ + + //create row + var $row = $(''); + $row.addClass('u-table-row'); + $row.attr('data-toggle', 'modal'); + $row.attr('data-target', '#popup' + windowCounter); + $row.attr('type', 'button'); + + //create cells in row + var $date = $('').text(message.date); + var $subject = $('').text(message.subject); + var $sender = $('').text(message.sender); + + //append cells to row + $row.append($date); + $row.append($subject); + $row.append($sender); + + + //append row to body + $InboxBody.append($row); + + //Create modal pop up + var $modalFade = $('
') + .addClass('modal') + .addClass('fade') + .attr('id', 'popup' + String(windowCounter)); + var $modalDialog = $('
').addClass('modal-dialog'); + var $modalContent = $('
').addClass('modal-content'); + var $modalHeader = $('
').addClass('modal-header'); + var $modalButton = $(' - -
From: {{ this.sender }}
- Date: {{this.date}} -
- - - - - -
-
-
- {{/each}}
{{ else }}

No Messages.

{{/if}} +
+
-- cgit v1.2.3