CyTube/www/assets/js/callbacks.js

856 lines
29 KiB
JavaScript
Raw Normal View History

2013-05-09 16:05:39 +00:00
Callbacks = {
connect: function() {
socket.emit("joinChannel", {
name: CHANNEL
});
if(uname && session) {
socket.emit("login", {
name: uname,
session: session
});
}
$("<div/>").addClass("server-msg-reconnect")
.text("Connected")
.appendTo($("#messagebuffer"));
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
},
2013-03-20 18:35:06 +00:00
2013-05-09 16:05:39 +00:00
disconnect: function() {
if(KICKED)
return;
2013-04-14 17:38:00 +00:00
$("<div/>")
.addClass("server-msg-disconnect")
2013-05-09 16:05:39 +00:00
.text("Disconnected from server. Attempting reconnection...")
2013-04-14 17:38:00 +00:00
.appendTo($("#messagebuffer"));
2013-04-23 19:17:42 +00:00
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
2013-05-09 16:05:39 +00:00
},
2013-05-21 16:17:01 +00:00
errorMsg: function(data) {
alert(data.msg);
},
2013-05-09 16:05:39 +00:00
announcement: function(data) {
$("#announcerow").html("");
$("#announcerow").css("display", "");
2013-05-09 16:05:39 +00:00
var div = $("<div/>").addClass("alert")
.appendTo($("#announcerow"));
2013-05-13 01:37:03 +00:00
$("<button/>").addClass("close pull-right").text("×")
2013-05-09 16:05:39 +00:00
.appendTo(div)
.click(function() { div.remove(); });
$("<h3/>").text(data.title).appendTo(div);
2013-05-09 16:05:39 +00:00
$("<p/>").html(data.text).appendTo(div);
},
kick: function(data) {
KICKED = true;
$("<div/>").addClass("server-msg-disconnect")
2013-05-19 21:23:35 +00:00
.text("Kicked: " + data.reason)
2013-05-09 16:05:39 +00:00
.appendTo($("#messagebuffer"));
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollheight"));
},
2013-04-23 19:17:42 +00:00
2013-05-09 16:05:39 +00:00
noflood: function(data) {
2013-04-23 19:17:42 +00:00
$("<div/>")
.addClass("server-msg-disconnect")
.text(data.action + ": " + data.msg)
.appendTo($("#messagebuffer"));
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
2013-05-09 16:05:39 +00:00
},
channelNotRegistered: function() {
var div = $("<div/>").addClass("alert alert-info").attr("id", "chregnotice")
2013-05-26 15:38:38 +00:00
.insertBefore($("#main"));
2013-05-09 16:05:39 +00:00
$("<button/>").addClass("close pull-right").text("×")
.appendTo(div)
.click(function() { div.remove(); });
$("<h3/>").text("This channel isn't registered").appendTo(div);
$("<button/>").addClass("btn btn-primary").text("Register it")
.appendTo(div)
.click(function() {
socket.emit("registerChannel");
});
},
registerChannel: function(data) {
2013-03-17 17:14:34 +00:00
if(data.success) {
$("#chregnotice").remove();
2013-03-17 17:14:34 +00:00
}
else {
alert(data.error);
}
2013-05-09 16:05:39 +00:00
},
2013-03-17 17:14:34 +00:00
2013-05-13 19:41:29 +00:00
unregisterChannel: function(data) {
if(data.success) {
alert("Channel unregistered");
}
else {
alert(data.error);
}
},
2013-05-09 16:05:39 +00:00
updateMotd: function(data) {
$("#motdtext").val(data.motd);
if(data.motd != "")
$("#motd").parent().css("display", "");
else
$("#motd").parent().css("display", "none");
$("#motd")[0].innerHTML = data.html;
2013-05-09 16:05:39 +00:00
},
chatFilters: function(data) {
var entries = data.filters;
var tbl = $("#filtereditor table");
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = 0; i < entries.length; i++) {
var f = entries[i];
var tr = $("<tr/>").appendTo(tbl);
var remove = $("<button/>").addClass("btn btn-mini btn-danger")
.appendTo($("<td/>").appendTo(tr));
$("<i/>").addClass("icon-remove-circle").appendTo(remove);
var name = $("<code/>").text(f.name)
.appendTo($("<td/>").appendTo(tr));
var regex = $("<code/>").text(f.source)
.appendTo($("<td/>").appendTo(tr));
var flags = $("<code/>").text(f.flags)
.appendTo($("<td/>").appendTo(tr));
var replace = $("<code/>").text(f.replace)
.appendTo($("<td/>").appendTo(tr));
var activetd = $("<td/>").appendTo(tr);
var active = $("<input/>").attr("type", "checkbox")
.prop("checked", f.active).appendTo(activetd);
var remcallback = (function(filter) { return function() {
socket.emit("chatFilter", {
cmd: "remove",
filter: filter
});
} })(f);
remove.click(remcallback);
var actcallback = (function(filter) { return function() {
// Apparently when you check a checkbox, its value is changed
// before this callback. When you uncheck it, its value is not
// changed before this callback
// [](/amgic)
var enabled = active.prop("checked");
filter.active = (filter.active == enabled) ? !enabled : enabled;
socket.emit("chatFilter", {
cmd: "update",
filter: filter
});
} })(f);
active.click(actcallback);
}
var newfilt = $("<tr/>").appendTo(tbl);
$("<td/>").appendTo(newfilt);
var name = $("<input/>").attr("type", "text")
.appendTo($("<td/>").appendTo(newfilt));
var regex = $("<input/>").attr("type", "text")
.appendTo($("<td/>").appendTo(newfilt));
var flags = $("<input/>").attr("type", "text")
.val("g")
.appendTo($("<td/>").appendTo(newfilt));
var replace = $("<input/>").attr("type", "text")
.appendTo($("<td/>").appendTo(newfilt));
var add = $("<button/>").addClass("btn btn-primary")
.text("Add Filter")
.appendTo($("<td/>").appendTo(newfilt));
var cback = (function(name, regex, fg, replace) { return function() {
if(regex.val() && replace.val()) {
var re = regex.val();
var flags = fg.val();
try {
var dummy = new RegExp(re, flags);
}
catch(e) {
alert("Invalid regex: " + e);
}
socket.emit("chatFilter", {
cmd: "update",
filter: {
name: name.val(),
source: re,
flags: flags,
replace: replace.val(),
active: true
}
});
}
} })(name, regex, flags, replace);
add.click(cback);
},
2013-02-16 05:02:42 +00:00
2013-05-09 16:05:39 +00:00
channelOpts: function(opts) {
$("#opt_pagetitle").attr("placeholder", opts.pagetitle);
document.title = opts.pagetitle;
PAGETITLE = opts.pagetitle;
2013-04-06 21:08:26 +00:00
$("#opt_customcss").val(opts.customcss);
$("#opt_customjs").val(opts.customjs);
2013-04-23 19:17:42 +00:00
$("#opt_chat_antiflood").prop("checked", opts.chat_antiflood);
2013-05-01 22:49:34 +00:00
$("#opt_show_public").prop("checked", opts.show_public);
$("#customCss").remove();
2013-04-06 21:08:26 +00:00
if(opts.customcss.trim() != "") {
2013-05-03 02:56:31 +00:00
$("#usertheme").remove();
$("<link/>")
.attr("rel", "stylesheet")
.attr("href", opts.customcss)
.attr("id", "customCss")
.appendTo($("head"));
2013-03-23 22:15:19 +00:00
}
2013-04-02 19:07:22 +00:00
$("#opt_allow_voteskip").prop("checked", opts.allow_voteskip);
$("#opt_voteskip_ratio").val(opts.voteskip_ratio);
if(opts.customjs.trim() != "") {
2013-05-06 16:24:55 +00:00
if(opts.customjs != CUSTOMJS) {
$.getScript(opts.customjs);
CUSTOMJS = opts.customjs;
}
}
2013-03-23 22:15:19 +00:00
CHANNELOPTS = opts;
if(opts.qopen_allow_qnext)
$("#queue_next").attr("disabled", false);
else if(RANK < Rank.Moderator && !LEADER)
$("#queue_next").attr("disabled", true);
if(opts.qopen_allow_playnext)
$("#play_next").attr("disabled", false);
else if(RANK < Rank.Moderator && !LEADER)
$("#play_next").attr("disabled", true);
2013-04-02 19:07:22 +00:00
if(opts.allow_voteskip)
$("#voteskip").attr("disabled", false);
else
$("#voteskip").attr("disabled", true);
2013-05-22 19:38:16 +00:00
handlePermissionChange();
},
setPermissions: function(perms) {
CHANPERMS = perms;
genPermissionsEditor();
handlePermissionChange();
2013-05-09 16:05:39 +00:00
},
2013-05-15 15:34:27 +00:00
channelCSSJS: function(data) {
$("#chancss").remove();
$("#chanjs").remove();
$("#csstext").val(data.css);
$("#jstext").val(data.js);
if(data.css) {
2013-05-17 02:39:33 +00:00
$("#usertheme").remove();
2013-05-15 15:34:27 +00:00
$("<style/>").attr("type", "text/css")
.attr("id", "chancss")
.text(data.css)
.appendTo($("head"));
}
if(data.js) {
$("<script/>").attr("type", "text/javascript")
.attr("id", "chanjs")
.text(data.js)
.appendTo($("body"));
}
},
2013-05-09 16:05:39 +00:00
banlist: function(data) {
var entries = data.entries;
var tbl = $("#banlist table");
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
for(var i = 0; i < entries.length; i++) {
var tr = $("<tr/>").appendTo(tbl);
var remove = $("<button/>").addClass("btn btn-mini btn-danger")
.appendTo($("<td/>").appendTo(tr));
$("<i/>").addClass("icon-remove-circle").appendTo(remove);
var ip = $("<td/>").text(entries[i].ip).appendTo(tr);
var name = $("<td/>").text(entries[i].name).appendTo(tr);
var banner = $("<td/>").text(entries[i].banner).appendTo(tr);
2013-05-21 16:17:01 +00:00
var callback = (function(id, name) { return function() {
socket.emit("unban", {
id: id,
name: name
2013-05-09 16:05:39 +00:00
});
2013-05-21 16:17:01 +00:00
} })(entries[i].id, entries[i].name);
2013-05-09 16:05:39 +00:00
remove.click(callback);
}
},
seenlogins: function(data) {
var entries = data.entries;
var tbl = $("#loginlog table");
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
2013-05-27 03:10:16 +00:00
$("#loginlog_pagination").remove();
2013-05-09 16:05:39 +00:00
entries.sort(function(a, b) {
2013-05-22 14:56:27 +00:00
var x = a.names.join(",").toLowerCase();
var y = b.names.join(",").toLowerCase();
2013-05-09 16:05:39 +00:00
// Force blanknames to the bottom
if(x == "") {
return 1;
}
if(y == "") {
return -1;
}
return x == y ? 0 : (x < y ? -1 : 1);
});
2013-05-27 03:10:16 +00:00
$("#loginlog").data("entries", entries);
if(entries.length > 20) {
var pag = $("<div/>").addClass("pagination span12")
.attr("id", "loginlog_pagination")
.prependTo($("#loginlog"));
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() {
loadLoginlogPage(i);
})
.appendTo(li);
})(i);
2013-05-21 16:17:01 +00:00
}
2013-05-09 16:05:39 +00:00
}
2013-05-27 03:10:16 +00:00
loadLoginlogPage(0);
2013-05-09 16:05:39 +00:00
},
acl: function(entries) {
entries.sort(function(a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return y == x ? 0 : (x < y ? -1 : 1);
});
2013-05-27 03:10:16 +00:00
$("#channelranks").data("entries", entries);
2013-05-09 16:05:39 +00:00
var tbl = $("#channelranks table");
if(tbl.children().length > 1) {
$(tbl.children()[1]).remove();
}
2013-05-27 03:10:16 +00:00
$("#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;
2013-05-09 16:05:39 +00:00
for(var i = 0; 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));
}
}
},
2013-05-09 16:05:39 +00:00
voteskip: function(data) {
if(data.count > 0) {
$("#voteskip").text("Voteskip ("+data.count+"/"+data.need+")");
}
else {
$("#voteskip").text("Voteskip");
}
2013-05-09 16:05:39 +00:00
},
/* REGION Rank Stuff */
2013-05-09 16:05:39 +00:00
rank: function(data) {
RANK = data.rank;
2013-05-22 19:38:16 +00:00
handlePermissionChange();
2013-05-09 16:05:39 +00:00
},
2013-05-09 16:05:39 +00:00
register: function(data) {
if(data.error) {
alert(data.error);
}
2013-05-09 16:05:39 +00:00
},
2013-05-09 16:05:39 +00:00
login: function(data) {
if(!data.success) {
if(data.error != "Invalid session") {
alert(data.error);
}
}
else {
2013-05-04 16:53:07 +00:00
$("#welcome").text("Logged in as " + uname);
$("#loginform").css("display", "none");
$("#logoutform").css("display", "");
$("#loggedin").css("display", "");
session = data.session || "";
createCookie("sync_uname", uname, 7);
createCookie("sync_session", session, 7);
}
2013-05-09 16:05:39 +00:00
},
/* REGION Chat */
2013-05-09 16:05:39 +00:00
usercount: function(data) {
2013-04-22 17:38:42 +00:00
var text = data.count + " connected user";
if(data.count != 1) {
text += "s";
}
$("#usercount").text(text);
2013-05-09 16:05:39 +00:00
},
2013-03-07 01:38:16 +00:00
2013-05-09 16:05:39 +00:00
chatMsg: function(data) {
2013-04-16 01:28:01 +00:00
addChatMessage(data);
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-23 04:03:37 +00:00
clearchat: function() {
$("#messagebuffer").html("");
},
2013-05-09 16:05:39 +00:00
userlist: function(data) {
$(".userlist_item").each(function() { $(this).remove(); });
for(var i = 0; i < data.length; i++) {
2013-05-09 16:05:39 +00:00
Callbacks.addUser(data[i]);
}
2013-05-09 16:05:39 +00:00
},
2013-05-09 16:05:39 +00:00
addUser: function(data) {
var div = $("<div/>").attr("class", "userlist_item");
var flair = $("<span/>").appendTo(div);
var nametag = $("<span/>").text(data.name).appendTo(div);
formatUserlistItem(div[0], data);
addUserDropdown(div, data.name);
2013-05-26 16:53:35 +00:00
if(data.name == uname) {
PROFILE.image = data.profile.image;
PROFILE.text = data.profile.text;
}
2013-05-09 16:05:39 +00:00
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
var othername = users[i].children[1].innerHTML;
if(othername.toLowerCase() > data.name.toLowerCase()) {
div.insertBefore(users[i]);
return;
}
}
div.appendTo($("#userlist"));
},
2013-05-09 16:05:39 +00:00
updateUser: function(data) {
if(data.name == uname) {
2013-05-13 01:15:05 +00:00
PROFILE.text = data.profile.text;
PROFILE.image = data.profile.image;
LEADER = data.leader;
RANK = data.rank;
2013-05-22 19:38:16 +00:00
handlePermissionChange();
if(LEADER) {
// I'm a leader! Set up sync function
sendVideoUpdate = function() {
PLAYER.getTime(function(seconds) {
socket.emit("mediaUpdate", {
id: PLAYER.id,
currentTime: seconds,
2013-05-13 22:05:01 +00:00
paused: PLAYER.paused,
type: PLAYER.type
});
});
};
}
// I'm not a leader. Don't send syncs to the server
else {
sendVideoUpdate = function() { }
}
}
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML;
// Reformat user
if(name == data.name) {
formatUserlistItem(users[i], data);
}
}
2013-05-09 16:05:39 +00:00
},
2013-05-09 16:05:39 +00:00
userLeave: function(data) {
var users = $("#userlist").children();
for(var i = 0; i < users.length; i++) {
var name = users[i].children[1].innerHTML;
if(name == data.name) {
$("#userlist")[0].removeChild(users[i]);
}
}
2013-05-09 16:05:39 +00:00
},
2013-05-09 16:05:39 +00:00
drinkCount: function(data) {
2013-04-22 17:38:42 +00:00
if(data.count != 0) {
var text = data.count + " drink";
if(data.count != 1) {
text += "s";
}
$("#drinkcount").text(text);
2013-05-13 19:06:09 +00:00
$("#drinkbar").show();
2013-04-04 19:56:43 +00:00
}
else {
2013-05-13 19:06:09 +00:00
$("#drinkbar").hide();
2013-04-04 19:56:43 +00:00
}
2013-05-09 16:05:39 +00:00
},
2013-04-04 19:56:43 +00:00
/* REGION Playlist Stuff */
2013-05-09 16:05:39 +00:00
playlist: function(data) {
// Clear the playlist first
var ul = $("#queue")[0];
2013-02-16 05:02:42 +00:00
var n = ul.children.length;
for(var i = 0; i < n; i++) {
ul.removeChild(ul.children[0]);
}
for(var i = 0; i < data.pl.length; i++) {
var li = makeQueueEntry(data.pl[i]);
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER)
2013-02-16 05:02:42 +00:00
addQueueButtons(li);
$(li).attr("title", data.pl[i].queueby
? ("Added by: " + data.pl[i].queueby)
: "Added by: Unknown");
2013-02-16 05:02:42 +00:00
$(li).appendTo(ul);
}
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-09 16:05:39 +00:00
updatePlaylistMeta: function(data) {
$("#plcount").text(data.count + " items");
$("#pllength").text(data.time);
2013-05-09 16:05:39 +00:00
},
2013-05-09 16:05:39 +00:00
queue: function(data) {
2013-02-16 05:02:42 +00:00
var li = makeQueueEntry(data.media);
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER)
2013-02-16 05:02:42 +00:00
addQueueButtons(li);
$(li).css("display", "none");
2013-02-16 05:02:42 +00:00
var idx = data.pos;
var ul = $("#queue")[0];
$(li).attr("title", data.media.queueby
? ("Added by: " + data.media.queueby)
: "Added by: Unknown");
2013-02-16 05:02:42 +00:00
$(li).appendTo(ul);
if(idx < ul.children.length - 1)
moveVideo(ul.children.length - 1, idx);
$(li).show("blind");
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-19 17:06:39 +00:00
queueFail: function() {
2013-06-01 15:59:04 +00:00
makeAlert("Error", "Queue failed. Check your link to make sure it is valid.", "alert-error")
.insertAfter($("#playlist_controls"));
2013-05-19 17:06:39 +00:00
},
2013-05-09 16:05:39 +00:00
setTemp: function(data) {
2013-05-04 22:54:28 +00:00
var li = $("#queue").children()[data.idx];
var buttons = $(li).find(".qe_btn");
if(buttons.length == 5) {
$(buttons[4]).removeClass("btn-danger btn-success");
$(buttons[4]).addClass(data.temp ? "btn-success" : "btn-danger");
2013-05-04 22:54:28 +00:00
}
if(data.temp) {
$(li).addClass("alert alert-error");
}
else {
$(li).removeClass("alert alert-error");
}
2013-05-09 16:05:39 +00:00
},
2013-05-04 22:54:28 +00:00
2013-05-09 16:05:39 +00:00
unqueue: function(data) {
var li = $("#queue").children()[data.pos];
$(li).remove();
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-09 16:05:39 +00:00
moveVideo: function(data) {
// Not recursive
2013-02-16 05:02:42 +00:00
moveVideo(data.src, data.dest);
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-09 16:05:39 +00:00
updatePlaylistIdx: function(data) {
2013-03-29 20:05:08 +00:00
if(data.old != undefined) {
var liold = $("#queue").children()[data.old];
$(liold).removeClass("alert alert-info");
}
var linew = $("#queue").children()[data.idx];
2013-02-16 05:02:42 +00:00
$(linew).addClass("alert alert-info");
2013-04-13 17:14:44 +00:00
$("#queue").scrollTop(0);
var scroll = $(linew).position().top - $("#queue").position().top;
$("#queue").scrollTop(scroll);
2013-03-29 20:05:08 +00:00
POSITION = data.idx;
2013-04-04 16:05:01 +00:00
if(CHANNELOPTS.allow_voteskip)
$("#voteskip").attr("disabled", false);
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-09 16:05:39 +00:00
changeMedia: function(data) {
$("#currenttitle").text("Currently Playing: " + data.title);
if(data.type != "sc" && PLAYER.type == "sc")
// [](/goddamnitmango)
fixSoundcloudShit();
if(data.type != "jw" && PLAYER.type == "jw") {
// Is it so hard to not mess up my DOM?
var wtf = $("<div/>").attr("id", "ytapiplayer")
.insertBefore($("#ytapiplayer_wrapper"));
$("#ytapiplayer_wrapper").remove();
}
if(data.type != PLAYER.type) {
2013-04-03 20:18:35 +00:00
PLAYER = new Media(data);
}
2013-05-04 22:54:28 +00:00
if(PLAYER.update) {
PLAYER.update(data);
}
2013-05-09 16:05:39 +00:00
},
2013-05-04 22:54:28 +00:00
2013-05-09 16:05:39 +00:00
mediaUpdate: function(data) {
2013-05-04 22:54:28 +00:00
if(PLAYER.update) {
2013-04-03 20:18:35 +00:00
PLAYER.update(data);
}
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-09 16:05:39 +00:00
queueLock: function(data) {
OPENQUEUE = !data.locked;
if(OPENQUEUE) {
$("#playlist_controls").css("display", "");
if(RANK < Rank.Moderator) {
$("#qlockbtn").css("display", "none");
rebuildPlaylist();
if(!CHANNELOPTS.qopen_allow_qnext)
$("#queue_next").attr("disabled", true);
if(!CHANNELOPTS.qopen_allow_playnext)
$("#play_next").attr("disabled", true);
2013-02-16 05:02:42 +00:00
}
}
else if(RANK < Rank.Moderator && !LEADER) {
$("#playlist_controls").css("display", "none");
rebuildPlaylist();
2013-02-16 05:02:42 +00:00
}
if(OPENQUEUE) {
$("#qlockbtn").removeClass("btn-danger")
.addClass("btn-success")
.text("Lock Queue");
}
else {
$("#qlockbtn").removeClass("btn-success")
.addClass("btn-danger")
.text("Unlock Queue");
2013-02-16 05:02:42 +00:00
}
2013-05-09 16:05:39 +00:00
},
2013-02-16 05:02:42 +00:00
2013-05-09 16:05:39 +00:00
librarySearchResults: function(data) {
2013-05-27 02:45:50 +00:00
clearSearchResults();
$("#library").data("entries", data.results);
if(data.results.length > 100) {
var pag = $("<div/>").addClass("pagination")
.attr("id", "search_pagination")
.insertAfter($("#library"));
var btns = $("<ul/>").appendTo(pag);
for(var i = 0; i < data.results.length / 100; i++) {
var li = $("<li/>").appendTo(btns);
(function(i) {
$("<a/>").attr("href", "javascript:void(0)")
.text(i+1)
.click(function() {
loadSearchPage(i);
})
.appendTo(li);
})(i);
2013-04-04 20:55:43 +00:00
}
2013-02-16 05:02:42 +00:00
}
2013-05-27 02:45:50 +00:00
loadSearchPage(0);
2013-05-09 16:05:39 +00:00
},
2013-03-16 21:49:58 +00:00
2013-05-09 16:05:39 +00:00
/* REGION Polls */
newPoll: function(data) {
closePoll();
var pollMsg = $("<div/>").addClass("poll-notify")
.text(data.initiator + " opened a poll: \"" + data.title + "\"")
.appendTo($("#messagebuffer"));
2013-05-14 17:15:58 +00:00
$("#messagebuffer").scrollTop($("#messagebuffer").prop("scrollHeight"));
2013-05-09 16:05:39 +00:00
var poll = $("<div/>").addClass("well active").prependTo($("#pollcontainer"));
$("<button/>").addClass("close pull-right").text("×")
.appendTo(poll)
.click(function() { poll.remove(); });
2013-05-27 18:35:24 +00:00
if(hasPermission("pollctl")) {
2013-05-09 16:05:39 +00:00
$("<button/>").addClass("btn btn-danger pull-right").text("End Poll")
.appendTo(poll)
.click(function() {
socket.emit("closePoll")
});
}
$("<h3/>").text(data.title).appendTo(poll);
for(var i = 0; i < data.options.length; i++) {
var callback = (function(i) { return function() {
socket.emit("vote", {
option: i
});
poll.find(".option button").each(function() {
$(this).attr("disabled", "disabled");
});
} })(i);
$("<button/>").addClass("btn").text(data.counts[i])
.prependTo($("<div/>").addClass("option").text(data.options[i])
.appendTo(poll))
.click(callback);
}
2013-05-27 18:35:24 +00:00
poll.find(".btn").attr("disabled", !hasPermission("pollvote"));
2013-05-09 16:05:39 +00:00
},
updatePoll: function(data) {
var poll = $("#pollcontainer .active");
var i = 0;
poll.find(".option button").each(function() {
$(this).text(data.counts[i]);
i++;
});
},
closePoll: function() {
// Not recursive
2013-03-16 21:49:58 +00:00
closePoll();
2013-06-01 15:59:04 +00:00
},
savePlaylist: function(data) {
if(data.success) {
makeAlert("Success", "Playlist saved.", "alert-success");
}
else {
alert("DBG error " + data.error);
makeAlert("Error", data.error, "alert-error");
}
},
2013-06-01 19:42:08 +00:00
listPlaylists: function(data) {
if(data.error) {
makeAlert("Error", data.error, "alert-error")
.addClass("span12")
.css("margin-left", "0")
.insertBefore($("#userpl_name").parent());
}
else {
var pls = data.pllist;
2013-06-01 20:56:23 +00:00
pls.sort(function(a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
if(x < y) return -1;
if(x > y) return 1;
return 0;
});
$("#userpl_list").html("");
2013-06-01 19:42:08 +00:00
for(var i = 0; i < pls.length; i++) {
2013-06-01 20:56:23 +00:00
var li = $("<li/>").appendTo($("#userpl_list"))
.addClass("well");
li.data("pl-name", pls[i].name);
$("<div/>").text(pls[i].name).appendTo(li)
.css("float", "left")
.css("margin-left", "1em");
2013-06-02 17:54:58 +00:00
var metastr = pls[i].count + " item";
if(pls[i].count != 1) {
metastr += "s";
}
metastr +=", playtime " + pls[i].time;
$("<div/>").text(metastr)
.css("float", "right")
.appendTo(li);
2013-06-01 20:56:23 +00:00
var bg = $("<div/>").addClass("btn-group")
.css("float", "left")
.prependTo(li);
var del = $("<button/>")
.addClass("btn btn-mini btn-danger")
.prependTo(bg);
$("<i/>").addClass("icon-trash").appendTo(del);
(function(li) {
del.click(function() {
socket.emit("deletePlaylist", {
name: li.data("pl-name")
});
});
})(li);
if(hasPermission("playlistaddlist")) {
(function(li) {
$("<button/>").addClass("btn btn-mini")
.text("End")
.prependTo(bg)
.click(function() {
socket.emit("queuePlaylist", {
name: li.data("pl-name"),
pos: "end"
});
});
})(li);
if(hasPermission("playlistnext")) {
(function(li) {
$("<button/>").addClass("btn btn-mini")
.text("Next")
.prependTo(bg)
.click(function() {
socket.emit("queuePlaylist", {
name: li.data("pl-name"),
pos: "next"
});
});
})(li);
}
}
2013-06-01 19:42:08 +00:00
}
}
}
2013-02-16 05:02:42 +00:00
}
/*
$.getScript(IO_URL+"/socket.io/socket.io.js", function() {
try {
socket = io.connect(IO_URL);
for(var key in Callbacks) {
socket.on(key, Callbacks[key]);
}
}
catch(e) {
Callbacks.disconnect();
}
});
*/
socket = new NotWebsocket();
for(var key in Callbacks) {
socket.on(key, Callbacks[key]);
}