More pagination

This commit is contained in:
Calvin Montgomery 2013-05-26 23:10:16 -04:00
parent ee10a080cc
commit 81d6b4873d
2 changed files with 175 additions and 65 deletions

View File

@ -288,6 +288,7 @@ Callbacks = {
if(tbl.children().length > 1) { if(tbl.children().length > 1) {
$(tbl.children()[1]).remove(); $(tbl.children()[1]).remove();
} }
$("#loginlog_pagination").remove();
entries.sort(function(a, b) { entries.sort(function(a, b) {
var x = a.names.join(",").toLowerCase(); var x = a.names.join(",").toLowerCase();
var y = b.names.join(",").toLowerCase(); var y = b.names.join(",").toLowerCase();
@ -300,73 +301,25 @@ Callbacks = {
} }
return x == y ? 0 : (x < y ? -1 : 1); return x == y ? 0 : (x < y ? -1 : 1);
}); });
for(var i = 0; i < entries.length; i++) { $("#loginlog").data("entries", entries);
var tr = $("<tr/>").appendTo(tbl); if(entries.length > 20) {
var bantd = $("<td/>").appendTo(tr); var pag = $("<div/>").addClass("pagination span12")
if(entries[i].banned) { .attr("id", "loginlog_pagination")
bantd.text("Banned"); .prependTo($("#loginlog"));
tr.addClass("alert alert-error"); var btns = $("<ul/>").appendTo(pag);
} for(var i = 0; i < entries.length / 20; i++) {
else { var li = $("<li/>").appendTo(btns);
var ban = $("<button/>").addClass("btn btn-mini btn-danger") (function(i) {
.text("Ban IP") $("<a/>").attr("href", "javascript:void(0)")
.appendTo(bantd); .text(i+1)
var banrange = $("<button/>").addClass("btn btn-mini btn-danger")
.text("Ban IP Range")
.appendTo(bantd);
var callback = (function(id, name) { return function() {
console.log(id, name);
socket.emit("banIP", {
id: id,
name: name,
range: false
});
return false;
} })(entries[i].id, entries[i].names[0]);
ban.click(callback);
var callback2 = (function(id, name) { return function() {
console.log(id, name);
socket.emit("banIP", {
id: id,
name: name,
range: true
});
return false;
} })(entries[i].id, entries[i].names[0]);
banrange.click(callback2);
}
var ip = $("<td/>").text(entries[i].ip).appendTo(tr);
var name = $("<td/>").text(entries[i].names).appendTo(tr);
tr.data("names", entries[i].names);
tr.data("banned", entries[i].banned);
tr.click(function(ev) {
tbl.find(".name-detail").remove();
if(this.data("namesopen")) {
this.data("namesopen", false);
return;
}
var names = this.data("names") || [];
for(var i = names.length-1; i >= 0; i--) {
var detail = $("<tr/>").insertAfter(this);
detail.addClass("name-detail");
if(this.data("banned")) {
detail.addClass("alert alert-error");
}
var buttontd = $("<td/>").appendTo(detail);
$("<button/>").addClass("btn btn-mini btn-danger")
.text("Ban Name")
.appendTo(buttontd)
.click(function() { .click(function() {
socket.emit("banName", { loadLoginlogPage(i);
name: this })
}); .appendTo(li);
}.bind(names[i])); })(i);
$("<td/>").text("\"").appendTo(detail);
$("<td/>").text(names[i]).appendTo(detail);
} }
this.data("namesopen", true);
}.bind(tr));
} }
loadLoginlogPage(0);
}, },
acl: function(entries) { acl: function(entries) {
@ -375,10 +328,31 @@ Callbacks = {
var y = b.name.toLowerCase(); var y = b.name.toLowerCase();
return y == x ? 0 : (x < y ? -1 : 1); return y == x ? 0 : (x < y ? -1 : 1);
}); });
$("#channelranks").data("entries", entries);
var tbl = $("#channelranks table"); var tbl = $("#channelranks table");
if(tbl.children().length > 1) { if(tbl.children().length > 1) {
$(tbl.children()[1]).remove(); $(tbl.children()[1]).remove();
} }
$("#acl_pagination").remove();
if(entries.length > 20) {
var pag = $("<div/>").addClass("pagination span12")
.attr("id", "acl_pagination")
.prependTo($("#channelranks"));
var btns = $("<ul/>").appendTo(pag);
for(var i = 0; i < entries.length / 20; i++) {
var li = $("<li/>").appendTo(btns);
(function(i) {
$("<a/>").attr("href", "javascript:void(0)")
.text(i+1)
.click(function() {
loadACLPage(i);
})
.appendTo(li);
})(i);
}
}
loadACLPage(0);
return;
for(var i = 0; i < entries.length; i++) { for(var i = 0; i < entries.length; i++) {
var tr = $("<tr/>").appendTo(tbl); var tr = $("<tr/>").appendTo(tbl);
var name = $("<td/>").text(entries[i].name).appendTo(tr); var name = $("<td/>").text(entries[i].name).appendTo(tr);

View File

@ -464,6 +464,12 @@ function loadSearchPage(page) {
} }
$(li).appendTo($("#library")); $(li).appendTo($("#library"));
} }
if($("#search_pagination").length > 0) {
$("#search_pagination").find("li").each(function() {
$(this).removeClass("active");
});
$($("#search_pagination").find("li")[page]).addClass("active");
}
} }
function clearSearchResults() { function clearSearchResults() {
@ -471,6 +477,136 @@ function clearSearchResults() {
$("#search_pagination").remove(); $("#search_pagination").remove();
} }
function loadLoginlogPage(page) {
var entries = $("#loginlog").data("entries");
var start = page * 20;
var tbl = $("#loginlog table");
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = start; i < start + 20 && i < entries.length; i++) {
var tr = $("<tr/>").appendTo(tbl);
var bantd = $("<td/>").appendTo(tr);
if(entries[i].banned) {
bantd.text("Banned");
tr.addClass("alert alert-error");
}
else {
var ban = $("<button/>").addClass("btn btn-mini btn-danger")
.text("Ban IP")
.appendTo(bantd);
var banrange = $("<button/>").addClass("btn btn-mini btn-danger")
.text("Ban IP Range")
.appendTo(bantd);
var callback = (function(id, name) { return function() {
console.log(id, name);
socket.emit("banIP", {
id: id,
name: name,
range: false
});
return false;
} })(entries[i].id, entries[i].names[0]);
ban.click(callback);
var callback2 = (function(id, name) { return function() {
console.log(id, name);
socket.emit("banIP", {
id: id,
name: name,
range: true
});
return false;
} })(entries[i].id, entries[i].names[0]);
banrange.click(callback2);
}
var ip = $("<td/>").text(entries[i].ip).appendTo(tr);
var name = $("<td/>").text(entries[i].names).appendTo(tr);
tr.data("names", entries[i].names);
tr.data("banned", entries[i].banned);
tr.click(function(ev) {
tbl.find(".name-detail").remove();
if(this.data("namesopen")) {
this.data("namesopen", false);
return;
}
var names = this.data("names") || [];
for(var i = names.length-1; i >= 0; i--) {
var detail = $("<tr/>").insertAfter(this);
detail.addClass("name-detail");
if(this.data("banned")) {
detail.addClass("alert alert-error");
}
var buttontd = $("<td/>").appendTo(detail);
$("<button/>").addClass("btn btn-mini btn-danger")
.text("Ban Name")
.appendTo(buttontd)
.click(function() {
socket.emit("banName", {
name: this
});
}.bind(names[i]));
$("<td/>").text("\"").appendTo(detail);
$("<td/>").text(names[i]).appendTo(detail);
}
this.data("namesopen", true);
}.bind(tr));
}
if($("#loginlog_pagination").length > 0) {
$("#loginlog_pagination").find("li").each(function() {
$(this).removeClass("active");
});
$($("#loginlog_pagination").find("li")[page]).addClass("active");
}
}
function loadACLPage(page) {
var entries = $("#channelranks").data("entries");
var start = page * 20;
var tbl = $("#channelranks table");
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = start; i < start + 20 && i < entries.length; i++) {
var tr = $("<tr/>").appendTo(tbl);
var name = $("<td/>").text(entries[i].name).appendTo(tr);
name.addClass(getNameColor(entries[i].rank));
var rank = $("<td/>").text(entries[i].rank).appendTo(tr);
var control = $("<td/>").appendTo(tr);
var up = $("<button/>").addClass("btn btn-mini btn-success")
.appendTo(control);
$("<i/>").addClass("icon-plus").appendTo(up);
var down = $("<button/>").addClass("btn btn-mini btn-danger")
.appendTo(control);
$("<i/>").addClass("icon-minus").appendTo(down);
if(entries[i].rank + 1 >= RANK) {
up.attr("disabled", true);
}
else {
up.click(function(name) { return function() {
socket.emit("promote", {
name: name
});
}}(entries[i].name));
}
if(entries[i].rank >= RANK) {
down.attr("disabled", true);
}
else {
down.click(function(name) { return function() {
socket.emit("demote", {
name: name
});
}}(entries[i].name));
}
}
if($("#acl_pagination").length > 0) {
$("#acl_pagination").find("li").each(function() {
$(this).removeClass("active");
});
$($("#acl_pagination").find("li")[page]).addClass("active");
}
}
// Rearranges the queue // Rearranges the queue
function moveVideo(src, dest, noanim) { function moveVideo(src, dest, noanim) {
var li = $($("#queue").children()[src]); var li = $($("#queue").children()[src]);