function main(){
// Inbox Constants and Globals
var INBOX_MESSAGE_COUNT = 8; // Number of message per page in inbox
var CURRENT_INBOX_PAGE = 1;
// CommentsConstants and Globals
var COMMENT_MESSAGE_COUNT = 6; // Number of message per page in comments
var CURRENT_COMMENT_PAGE = 1;
var COMMENT_BOX; // {commentCount : int, commentList : array}
var COMMENT_PAGES = {}; // {pgNum : commentList}
var COMMENT_COUNT;
// User-profile dynamic paging
var items = [
$("#profile-general"),
$("#profile-follows"),
$("#profile-comments"),
$("#profile-inbox")];
// Helper functions
function hidePages(){
items.forEach(function(item){
item.hide();
});
}
// Helper functions: Inbox paging
/* Create the Previous and Next Directional controllers for
* First calculate the page count, then set up controllers accordingly.
* Pre-condition: Type takes on values: 'inbox', 'comments'*/
function generatePager(count, type){
var currentPage;
var pageCount;
var $pageNumber;
var $uPager;
var directionType = type;
if(type == 'inbox'){
currentPage = CURRENT_INBOX_PAGE;
pageCount = Math.ceil(count/INBOX_MESSAGE_COUNT);
$pageNumber = $('#u-inbox-page-number');
$uPager = $("#u-inbox-pager");
}else{
currentPage = CURRENT_COMMENT_PAGE;
pageCount = Math.ceil(count/COMMENT_MESSAGE_COUNT);
$pageNumber = $('#u-comment-page-number');
$uPager = $("#u-comment-pager");
}
if(pageCount > 1){
// State current page
$pageNumber.empty().append(currentPage + ' of ' + pageCount)
.addClass('u-pagination');
$uPager.empty();
var $pager = $('
').addClass('u-pagination');
$uPager.append($pager);
var $previous = $("
").append('Next >')
.attr('id', 'u-next-' + directionType)
.addClass('u-change-page');
if(currentPage == 1){
$pager.append($next);
}else if(currentPage == pageCount){
$pager.append($previous);
}else{
$pager.append($previous);
$pager.append(' | ');
$pager.append($next);
}
}
}
/* Request inbox from server, then create inbox in DOM, call generatePager */
function generateInbox(pageNum){
$.ajax({
dataType: "json",
url: '/user/user_profile/inbox/' + 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 = $('