From e0bc5e67f0be025aa54fbac3d25065b4b8c00f40 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 26 Nov 2012 12:06:35 -0500 Subject: www/ folder --- www/static/js/admin.js | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 www/static/js/admin.js (limited to 'www/static/js/admin.js') diff --git a/www/static/js/admin.js b/www/static/js/admin.js new file mode 100755 index 0000000..92a0421 --- /dev/null +++ b/www/static/js/admin.js @@ -0,0 +1,119 @@ +var Admin = + { + videos: {}, + viewRoom: function () + { + var videoKey = '' + var hash = document.location.hash + if (hash.indexOf("#") !== -1) + hash = hash.substr(1) + var partz = hash.split("&") + for (i in partz) + { + var pair = partz[i].split("=") + if (pair[0] === "v") + videoKey = pair[1] + } + d.warn("VIEWING ROOM "+Room.name) + $.post(API.URL.room.view, {'room':Room.name,'session':Auth.session,}).success(Admin.viewCallback).error(Admin.viewError) + }, + viewError: function (raw) + { + d.warn(raw) + }, + viewCallback: function (raw) + { + var lines = API.parse("/room/view", raw) + if (! lines) + return d.error("UNABLE TO LOAD ROOM") + var ll = lines.shift().split("\t") + if (ll[0] === '0') + return d.error(ll[1]) + + Lastlog.update(lines.shift()) + Admin.storeVideos(lines) + }, + storeVideos: function (lines) + { + var rows = [] + var lastDate = "" + for (i in lines.reverse()) + { + var row = lines[i].split("\t") + if (row[0].indexOf("ROOM") === 0) + { + Room.updateSetting(row[1],row[2]) + continue + } + if (row[0].indexOf("VIDEO") === 0) + { + var type = "??" + if (row[5].indexOf("youtube") !== -1) + type = "yt" + else if (row[5].indexOf("vimeo") !== -1) + type = "vm" + else if (row[5].indexOf("soundcloud") !== -1) + type = "sc" + else if (row[5].indexOf("mp3") !== -1) + type = "au" + // 0 VIDEO 1 id 2 date 3 userid 4 username 5 url 6 title + var d = new Date(parseInt(row[2])*1000) + var thisDate = makeClockDate(d) + if (thisDate === lastDate) + thisDate = "" + else + lastDate = thisDate + var li = "
  • " + li += ""+thisDate+"" + li += ""+makeClockTime(d)+"" + li += ""+row[4]+"" + li += ""+type+"" + li += ""+row[6]+"" + li += "remove" + li += "
  • " + rows.push(li) + Admin.videos[row[1]] = { id: row[1], title: row[6], username: row[4] } + } + } + $("#videos").css({"display": "inline-block", "vertical-align": "top"}) + $("#videos").html(rows.join("")) + }, + removeVideoClick: function () + { + var id = $(this).attr("id") + var idx = id.substr(id.indexOf("_")+1) + var video = Admin.videos[idx] + d.act("+ remove video "+idx) + if (confirm(video.title+"\nposted by "+video.username+"\n\nThis video will be removed from the queue.")) + $.post(API.URL.video.remove, {session:Auth.session, video:idx, room:Room.name}).success(Admin.removeVideoSuccess) + }, + removeVideoSuccess: function (raw) + { + var lines = API.parse("/video/remove", raw) + if (! lines) + return d.error("UNABLE TO REMOVE VIDEO") + var l = lines.shift().split("\t") + if (l[0] === '0') + { + d.error(l[1]) + return + } + d.warn(l[1]) + $("#video_"+l[0]).fadeOut(500) + } + } +var months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ") +function makeClockDate(d) + { + var date = d.getDate() + var month = months[d.getMonth()] + return date+"-"+month + } +function makeClockTime(d) + { + var h = d.getHours() + var m = d.getMinutes() + if (m < 10) + m = "0" + m + return h+":"+m + } -- cgit v1.2.3-70-g09d2