var AUTH = ""; var NO_WEBSOCKETS = false; /* init socket connection */ $.getScript(IO_URL+"/socket.io/socket.io.js", function() { try { if(NO_WEBSOCKETS) { var i = io.transports.indexOf("websocket"); if(i >= 0) io.transports.splice(i, 1); } socket = io.connect(IO_URL); setupCallbacks(); } catch(e) { Callbacks.disconnect(); } }); $("#login").click(showLoginMenu); $("#logout").click(function() { eraseCookie("cytube_uname"); eraseCookie("cytube_session"); document.location.reload(true); }); $("#panels .span12").each(function() { $(this).hide(); }); function menuHandler(liselect, panelselect) { $(liselect).click(function() { $("#panels .span12").each(function() { $(this).hide(); }); $(panelselect).show(); $("#menudd_title").text($(liselect).text()); }); } menuHandler("#show_logview", "#logview"); menuHandler("#show_announce", "#announcepanel"); menuHandler("#show_gbans", "#gbanpanel"); menuHandler("#show_userlookup", "#userlookup"); function tableResort(tbl, sortby) { if(tbl.data("sortby") == sortby) tbl.data("sort_desc", !tbl.data("sort_desc")); else tbl.data("sortby", sortby) 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"); }); $("#userlookup_uname").click(function() { tableResort($("#userlookup table"), "uname"); }); $("#userlookup_rank").click(function() { tableResort($("#userlookup table"), "global_rank"); }); $("#userlookup_email").click(function() { tableResort($("#userlookup table"), "email"); }); menuHandler("#show_chanlookup", "#chanlookup"); $("#chanlookup_id").click(function() { tableResort($("#chanlookup table"), "id"); }); $("#chanlookup_name").click(function() { tableResort($("#chanlookup table"), "name"); }); $("#chanlookup_owner").click(function() { tableResort($("#chanlookup table"), "owner"); }); menuHandler("#show_chanloaded", "#channellist"); $("#show_chanloaded").click(function() { socket.emit("acp-list-loaded"); }); $("#listloaded_refresh").click(function() { socket.emit("acp-list-loaded"); }); menuHandler("#show_actionlog", "#actionlog"); $("#show_actionlog").click(function () { socket.emit("acp-actionlog-list"); }); $("#actionlog_filter").click(getActionLog); $("#actionlog_searchbtn").click(function() { var tbl = $("#actionlog table"); var sfield = $("#actionlog_sfield").val(); var sval = $("#actionlog_search").val().toLowerCase(); var sort = $("#actionlog_sort").val(); var desc = $("#actionlog_sortorder").val() === "true"; tbl.data("sort_desc", desc); tbl.data("sortby", sort); var entries = tbl.data("allentries"); entries = entries.filter(function (item, i, arr) { var f = item[sfield]; if(sfield === "time") f = new Date(f).toString().toLowerCase(); return f.indexOf(sval) > -1; }); tbl.data("entries", entries); var p = tbl.data("paginator"); p.items = entries; tableResort(tbl); }); $("#actionlog_clear").click(function() { socket.emit("acp-actionlog-clear", $("#actionlog_filter").val()); socket.emit("acp-actionlog-list"); getActionLog(); }); $("#actionlog_refresh").click(function() { getActionLog(); }); $("#actionlog_ip").click(function() { tableResort($("#actionlog table"), "ip"); }); $("#actionlog_name").click(function() { tableResort($("#actionlog table"), "name"); }); $("#actionlog_action").click(function() { tableResort($("#actionlog table"), "action"); }); $("#actionlog_time").click(function() { tableResort($("#actionlog table"), "time"); }); menuHandler("#show_stats", "#stats"); $("#show_stats").click(function () { socket.emit("acp-view-stats"); }); function reverseLog() { $("#log").text($("#log").text().split("\n").reverse().join("\n")); } $("#log_reverse").click(reverseLog); function getSyslog() { $.ajax(WEB_URL+"/api/logging/syslog?"+AUTH).done(function(data) { $("#log").text(data); }); } $("#syslog").click(getSyslog); function getErrlog() { $.ajax(WEB_URL+"/api/logging/errorlog?"+AUTH).done(function(data) { $("#log").text(data); }); } $("#errlog").click(getErrlog); function getActionLog() { var types = "&actions=" + $("#actionlog_filter").val().join(","); $.getJSON(WEB_URL+"/api/logging/actionlog?"+AUTH+types+"&callback=?") .done(function(entries) { var tbl = $("#actionlog table"); entries.forEach(function (e) { e.time = parseInt(e.time); }); var p = tbl.data("paginator"); if(p) { p.items = entries; } else { var opts = { preLoadPage: function () { $("#actionlog tbody").remove(); }, generator: function (e, page, index) { var tr = $("").appendTo($("#actionlog table")); var rem = $("").appendTo(tr); $("