Switch pagination on users in ACP

This commit is contained in:
calzoneman 2013-07-31 10:27:01 -04:00
parent 5a91a7ce21
commit 17b9353833
2 changed files with 75 additions and 66 deletions

View File

@ -254,6 +254,7 @@
<!-- Mine -->
<script src="./assets/js/iourl.js"></script>
<script src="./assets/js/data.js"></script>
<script src="./assets/js/paginator.js"></script>
<script src="./assets/js/util.js"></script>
<script src="./assets/js/acp.js"></script>
</body>

View File

@ -47,7 +47,25 @@ function tableResort(tbl, sortby) {
tbl.data("sort_desc", !tbl.data("sort_desc"));
else
tbl.data("sortby", sortby)
loadPage(tbl, 0);
var sort_field = tbl.data("sortby");
var sort_desc = tbl.data("sort_desc");
var p = tbl.data("paginator");
if(sort_field) {
p.items.sort(function(a, b) {
var x = a[sort_field];
if(typeof x == "string")
x = x.toLowerCase();
var y = b[sort_field];
if(typeof y == "string")
y = y.toLowerCase();
var z = x == y ? 0 : (x < y ? -1 : 1);
if(sort_desc)
z = -z;
return z;
});
}
p.loadPage(0);
}
$("#userlookup_uid").click(function() {
tableResort($("#userlookup table"), "id");
@ -372,28 +390,12 @@ function setupCallbacks() {
socket.on("acp-userdata", function(data) {
var tbl = $("#userlookup table");
if(data.length > 20) {
var pag = $("<div/>").addClass("pagination")
.attr("id", "userlookup_pagination")
.insertAfter($("#userlookup table"));
var btns = $("<ul/>").appendTo(pag);
for(var i = 0; i < data.length / 20; i++) {
var li = $("<li/>").appendTo(btns);
(function(i) {
$("<a/>").attr("href", "javascript:void(0)")
.text(i+1)
.click(function() {
loadPage(tbl, i);
})
.appendTo(li);
})(i);
}
tbl.data("pagination", pag);
}
tbl.data("entries", data);
tbl.data("sortby", "uname");
tbl.data("sort_desc", false);
tbl.data("generator", function(u) {
var tr = $("<tr/>").appendTo($("#userlookup table"));
var opts = {
preLoadPage: function () {
tbl.find("tbody").remove();
},
generator: function (u, page, index) {
var tr = $("<tr/>").appendTo(tbl);
$("<td/>").text(u.id).appendTo(tr);
$("<td/>").text(u.uname).appendTo(tr);
var rank = $("<td/>").text(u.global_rank).appendTo(tr);
@ -438,8 +440,14 @@ function setupCallbacks() {
save.bind(edit)();
});
}.bind(rank));
});
loadPage($("#userlookup table"), 0);
}
};
var p = Paginate(data, opts);
p.paginator.insertBefore(tbl);
tbl.data("paginator", p);
}
tbl.data("sortby", "uname");
tbl.data("sort_desc", false);
});
socket.on("acp-set-rank", function(data) {