2011-08-25 09:39:15 +00:00
|
|
|
$('#listLeft ul li a').live("click", function() {
|
|
|
|
// alert("foo");
|
|
|
|
// e.preventDefault();
|
2011-08-26 17:33:31 +00:00
|
|
|
if ($(this).hasClass("listLeftSelected")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$('.listLeftSelected').removeClass("listLeftSelected");
|
|
|
|
$(this).addClass('listLeftSelected');
|
2011-08-25 09:39:15 +00:00
|
|
|
var objId = $(this).attr("data-id");
|
|
|
|
var tabId = $('.innerSelected').attr("data-id");
|
|
|
|
$.getJSON("/m/get_details", {
|
|
|
|
'tab_id': tabId,
|
|
|
|
'object_id': objId
|
|
|
|
}, function(data) {
|
|
|
|
$('#textRight').text(data.title);
|
|
|
|
$('#bottomRight').html(data.html);
|
|
|
|
// console.log(data);
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2011-09-10 01:40:47 +00:00
|
|
|
|
|
|
|
/* Get a jquery <option> row for a sort field, requires s.operator, s.field_name, s.friendly_name */
|
|
|
|
function getOption(s) {
|
|
|
|
return $('<option />').val(s.operator + s.field_name).text(s.friendly_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a Jquery List Row object for an item - requires item.id and item.title*/
|
2011-08-25 09:39:15 +00:00
|
|
|
function getLi(item) {
|
2011-08-26 17:33:31 +00:00
|
|
|
var titleLength = 30;
|
2011-08-25 09:39:15 +00:00
|
|
|
var $li = $('<li />').addClass("tabListItem");
|
|
|
|
var $a = $('<a />').attr("href", '#').attr("data-id", item.id).appendTo($li);
|
2011-08-26 17:33:31 +00:00
|
|
|
// console.log(item.title.length);
|
2011-08-27 10:54:45 +00:00
|
|
|
var $span = $('<span />').text(item.title).appendTo($a);
|
2011-08-25 09:39:15 +00:00
|
|
|
return $li;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function() {
|
2011-09-10 01:40:47 +00:00
|
|
|
/* search button toggle */
|
|
|
|
$('.searchInnerField').hide();
|
|
|
|
$('#searchInner').toggle(function() {
|
|
|
|
$('.searchInnerField').slideDown();
|
|
|
|
}, function() {
|
|
|
|
$('.searchInnerField').slideUp();
|
|
|
|
});
|
|
|
|
/* search button end */
|
|
|
|
|
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
$('#listLeft ul li a').eq(0).click();
|
|
|
|
// alert("hi");
|
2011-09-10 01:40:47 +00:00
|
|
|
|
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
$('.tabCategory').click(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
if ($this.hasClass('.innerSelected')) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-10 01:40:47 +00:00
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
$('.innerSelected').removeClass("innerSelected");
|
|
|
|
$this.addClass("innerSelected");
|
|
|
|
$('.displayedTab').removeClass("displayedTab");
|
|
|
|
var tabId = $this.attr("data-id");
|
|
|
|
$('#tabText_' + tabId).addClass("displayedTab");
|
2011-09-10 01:40:47 +00:00
|
|
|
doListLoading();
|
|
|
|
$.getJSON("/m/get_tab", {
|
2011-08-25 09:39:15 +00:00
|
|
|
'tab_id': tabId,
|
2011-09-10 01:40:47 +00:00
|
|
|
// 'page_no': 1
|
2011-08-25 09:39:15 +00:00
|
|
|
}, function(data) {
|
2011-09-10 01:40:47 +00:00
|
|
|
// $('#loadingList').hide();
|
|
|
|
stopListLoading(data.page);
|
|
|
|
/* begin if for has_list, ideally make into separate render function */
|
|
|
|
if (data.has_list) {
|
|
|
|
/* handle sort options on list */
|
|
|
|
$select = $('#orderBySelect');
|
|
|
|
$select.empty();
|
|
|
|
var sorts = data.sorts;
|
|
|
|
if (sorts.length == 0) { $select.hide(); } else { $select.show(); }
|
|
|
|
for (var j=0; j<sorts.length; j++) {
|
|
|
|
var s = sorts[j];
|
|
|
|
var $opt = getOption(s);
|
|
|
|
$select.append($opt);
|
|
|
|
}
|
|
|
|
/* end handle sort */
|
|
|
|
|
|
|
|
/* handle displaying initial list on page */
|
|
|
|
displayList(data.page.items);
|
|
|
|
/* end display initial list */
|
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
}
|
2011-09-10 01:40:47 +00:00
|
|
|
/* end if has_list */
|
|
|
|
|
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
});
|
|
|
|
});
|
2011-09-10 01:40:47 +00:00
|
|
|
|
|
|
|
$('#orderBySelect').change(function(e) {
|
|
|
|
var sortString = $(this).val();
|
|
|
|
doListLoading();
|
|
|
|
$.getJSON("/m/get_list", {
|
|
|
|
'tab_id': $('.innerSelected').attr("data-id"),
|
|
|
|
'sort': sortString
|
|
|
|
}, function(data) {
|
|
|
|
stopListLoading(data);
|
|
|
|
displayList(data.items);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#triangleUp').click(function() {
|
|
|
|
goPreviousPage();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#triangleDown').click(function() {
|
|
|
|
goNextPage();
|
|
|
|
});
|
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
});
|
2011-09-10 01:40:47 +00:00
|
|
|
|
|
|
|
function displayList(items) {
|
|
|
|
for (var i=0; i<items.length; i++) {
|
|
|
|
var $li = getLi(items[i]);
|
|
|
|
$('#listLeft ul').append($li);
|
|
|
|
}
|
|
|
|
$('#listLeft ul li a').eq(0).click();
|
|
|
|
}
|
|
|
|
|
|
|
|
function doListLoading() {
|
|
|
|
$('#loadingList').show();
|
|
|
|
$('.tabListItem').remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopListLoading(page) {
|
|
|
|
$('#currPageNo').text(page.page_no);
|
|
|
|
$('#totalPages').text(page.num_pages);
|
|
|
|
$('#loadingList').hide();
|
|
|
|
if (page.page_no == 1) {
|
|
|
|
$('#triangleUp').hide();
|
|
|
|
} else {
|
|
|
|
$('#triangleUp').show();
|
|
|
|
}
|
|
|
|
if (page.page_no == page.num_pages) {
|
|
|
|
$('#triangleDown').hide();
|
|
|
|
} else {
|
|
|
|
$('#triangleDown').show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function goNextPage() {
|
|
|
|
var currPage = parseInt($('#currPageNo').text());
|
|
|
|
var totalPages = parseInt($('#totalPages').text());
|
|
|
|
if (currPage < totalPages) {
|
|
|
|
getPage(currPage + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function goPreviousPage() {
|
|
|
|
var currPage = parseInt($('#currPageNo').text());
|
|
|
|
if (currPage > 1) {
|
|
|
|
getPage(currPage - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPage(pageNo) {
|
|
|
|
doListLoading();
|
|
|
|
$.getJSON("/m/get_list", {
|
|
|
|
'tab_id': $('.innerSelected').attr("data-id"),
|
|
|
|
'page': pageNo,
|
|
|
|
'sort': $('#orderBySelect').val()
|
|
|
|
}, function(page) {
|
|
|
|
stopListLoading(page);
|
|
|
|
displayList(page.items);
|
|
|
|
});
|
|
|
|
}
|