events.js 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841
  1. var feedbackData;
  2. function gup( name, url ) {
  3. if (!url) url = location.href;
  4. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  5. var regexS = "[\\?&]"+name+"=([^&#]*)";
  6. var regex = new RegExp( regexS );
  7. var results = regex.exec( url );
  8. return results == null ? null : results[1];
  9. }
  10. function getSpotifyInfo(title, cb, artist) {
  11. var q = "";
  12. q = title;
  13. if (artist !== undefined) {
  14. q += " artist:" + artist;
  15. }
  16. $.ajax({
  17. type: "GET",
  18. url: 'https://api.spotify.com/v1/search?q=' + encodeURIComponent(q) + '&type=track',
  19. applicationType: "application/json",
  20. contentType: "json",
  21. success: function (data) {
  22. cb(data);
  23. }
  24. });
  25. }
  26. function executeCommand(command, params){
  27. if (command === "help" || command === "commands") {
  28. $('#helpModal').modal('show');
  29. return true;
  30. } else if (command === "volume") {
  31. if (params.length === 1) {
  32. var volume = Number(params[0]);
  33. if (volume >= 0 || volume <= 100) {
  34. if (volume === 0) {
  35. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
  36. } else {
  37. $("#volume-icon").removeClass("fa-volume-off").addClass("fa-volume-down")
  38. }
  39. $("#volume-slider").slider("setValue", volume);
  40. if (YTPlayer !== undefined) {
  41. YTPlayer.setVolume(volume);
  42. localStorage.setItem("volume", volume);
  43. }
  44. return true;
  45. }
  46. }
  47. } else if(command === "mute"){
  48. $("#volume-slider").slider("setValue", 0);
  49. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off");
  50. if (YTPlayer !== undefined) {
  51. YTPlayer.setVolume(0);
  52. localStorage.setItem("volume", 0);
  53. }
  54. } else if(command === "ban"){
  55. var user = params[0];
  56. var time = params[1];
  57. var reason = params[2];
  58. Meteor.call("banUser", user, time, reason, function(err, res){
  59. if(err){
  60. console.log(err);
  61. }
  62. });
  63. } else if(command === "silence"){
  64. var user = params[0];
  65. var time = params[1];
  66. Meteor.call("muteUser", user, time, function(err, res){
  67. if(err){
  68. console.log(err);
  69. }
  70. });
  71. } else if(command === "unban"){
  72. var user = params[0];
  73. Meteor.call("unbanUser", user, function(err, res){
  74. if(err){
  75. console.log(err);
  76. }
  77. });
  78. } else if(command === "unsilence"){
  79. var user = params[0];
  80. Meteor.call("unsilenceUser", user, function(err, res){
  81. if(err){
  82. console.log(err);
  83. }
  84. });
  85. } else if(command === "pause"){
  86. Meteor.call("pauseRoom", Session.get("type"), function(err, res){
  87. if(err){
  88. console.log(err);
  89. }
  90. });
  91. } else if(command === "resume"){
  92. Meteor.call("resumeRoom", Session.get("type"), function(err, res){
  93. if(err){
  94. console.log(err);
  95. }
  96. });
  97. } else if(command === "shuffle"){
  98. Meteor.call("shufflePlaylist", Session.get("type"), function(err, res){
  99. if(err){
  100. console.log(err);
  101. }
  102. });
  103. } else if(command === "skip"){
  104. Meteor.call("skipSong", Session.get("type"), function(err, res){
  105. if(err){
  106. console.log(err);
  107. }
  108. });
  109. }
  110. }
  111. function sendMessage() {
  112. var message = $("#chat-input").val();
  113. if (!$("#chat-input").hasClass("disabled")) {
  114. if (message.length > 0 && message[0] !== " ") {
  115. if (message[0] === "/") {
  116. message = message.split("");
  117. message.shift();
  118. message = message.join("");
  119. var params = message.split(" ");
  120. params = params.map(function(param) {
  121. return param.replace(/\r?\n|\r/g, "");
  122. });
  123. var command = params.shift();
  124. command = command.replace(/\r?\n|\r/g, "");
  125. if (executeCommand(command, params)) {
  126. $("#chat-input").val("");
  127. } else {
  128. $("#chat-input").val("");
  129. }
  130. } else {
  131. $("#chat-input").addClass("disabled");
  132. $("#chat-input").attr("disabled", "");
  133. Meteor.call("sendMessage", Session.get("type"), message, function (err, res) {
  134. if(err){
  135. $("#chat-input").val("");
  136. $("#chat-input").removeAttr("disabled");
  137. $("#chat-input").removeClass("disabled");
  138. }
  139. if (res) {
  140. $("#chat-input").val("");
  141. $("#chat-input").removeAttr("disabled");
  142. $("#chat-input").removeClass("disabled");
  143. }
  144. });
  145. }
  146. }
  147. }
  148. }
  149. function sendMessageGlobal() {
  150. var message = $("#chat-message").val();
  151. if (!$("#chat-message").hasClass("disabled")) {
  152. if (message.length > 0 && message[0] !== " ") {
  153. if (message[0] === "/") {
  154. message = message.split("");
  155. message.shift();
  156. message = message.join("");
  157. var params = message.split(" ");
  158. var command = params.shift();
  159. command = command.replace(/\r?\n|\r/g, "");
  160. if (executeCommand(command, params)) {
  161. $("#chat-message").val("");
  162. } else {
  163. $("#chat-message").val("");
  164. }
  165. } else {
  166. Meteor.call("sendMessage", "global", message, function (err, res) {
  167. if (res) {
  168. $("#chat-message").val("");
  169. }
  170. });
  171. }
  172. }
  173. }
  174. }
  175. Template.admin.events({
  176. "click a": function(e) {
  177. var target = $(e.target);
  178. if (target.hasClass("activate-alert-button") || target.parent().hasClass("activate-alert-button")) {
  179. var id = target.data("id") || target.parent().data("id");
  180. Meteor.call("activateAlert", id);
  181. } else if (target.hasClass("deactivate-alert-button") || target.parent().hasClass("deactivate-alert-button")) {
  182. var id = target.data("id") || target.parent().data("id");
  183. Meteor.call("deactivateAlert", id);
  184. }
  185. },
  186. "click #croom_create": function() {
  187. Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), $("#croom_private").prop("checked"), $("#croom_desc").val(), function (err, res) {
  188. if (err) {
  189. var $toastContent = $('<span><strong>Room not added.</strong> ' + err.reason + '</span>');
  190. Materialize.toast($toastContent, 8000);
  191. } else {
  192. window.location = "/" + $("#croom_tag").val();
  193. }
  194. });
  195. },
  196. "click #submit-alert": function(){
  197. var alertDesc = $("#alert-desc").val()
  198. if(alertDesc !== ""){
  199. Meteor.call("addAlert", alertDesc);
  200. }
  201. },
  202. "click .delete-alert-button": function(e) {
  203. var target = $(e.target);
  204. var id = $(e.target).data("id") || target.parent().data("id");
  205. Meteor.call("deleteAlert", id);
  206. }
  207. });
  208. Template.feedback.events({
  209. "click #feedback_submit": function(){
  210. if(Meteor.userId()){
  211. if($("#feedback_message").val().length !== 0 && $("#feedback_message").hasClass("invalid") === false){
  212. Meteor.call("sendFeedback", $("#feedback_message").val());
  213. $("#feedback_message").val("");
  214. $("#createFeedback").closeModal()
  215. } else{
  216. var $toastContent = $('<span><strong>Feedback not sent.</strong> Possible reasons include:<ul><li>- Empty Feedback Message</li><li>- Feedback is more than 500 words</li></ul></span>');
  217. Materialize.toast($toastContent, 8000);
  218. }
  219. } else {
  220. var $toastContent = $('<span><strong>Feedback not sent.</strong> You must be logged in.</span>');
  221. Materialize.toast($toastContent, 4000);
  222. }
  223. },
  224. "click .upvote": function(){
  225. var message = $(this).parent("card").prevObject[0].message;
  226. Meteor.call("upvoteFeedback", message);
  227. },
  228. "click #delete": function(){
  229. var message = $(this).parent("card").prevObject[0].message;
  230. Meteor.call("deleteFeedback", message);
  231. },
  232. "click #edit": function(){
  233. $("#editModal").click()
  234. var data = Feedback.findOne({"message": $(this).parent("card").prevObject[0].message});
  235. feedbackData = data.message;
  236. $("#edit_feedback_message").val(data.message);
  237. },
  238. "click #edit_feedback_submit": function(){
  239. var oldMessage = feedbackData;
  240. var newMessage = $("#edit_feedback_message").val()
  241. $("#edit_feedback_message").val("")
  242. Meteor.call("updateFeedback", oldMessage, newMessage);
  243. $("#editFeedback").closeModal();
  244. }
  245. });
  246. Template.header.events({
  247. "click .logout": function(e){
  248. e.preventDefault();
  249. Meteor.logout();
  250. if (hpSound !== undefined) {
  251. hpSound.stop();
  252. }
  253. },
  254. "click #profile": function(){
  255. window.location = "/u/" + Meteor.user().profile.username;
  256. }
  257. });
  258. Template.login.events({
  259. "submit form": function(e){
  260. e.preventDefault();
  261. Session.set("github", false);
  262. var username = $("#username").val()
  263. var password = $("#password").val();
  264. Meteor.loginWithPassword(username, password, function(err) {
  265. if (err) {
  266. var $toastContent = $('<span><strong>Oh snap!</strong> ' + err.reason + '</span>');
  267. Materialize.toast($toastContent, 8000);
  268. } else {
  269. window.location.href = "/";
  270. }
  271. });
  272. },
  273. "click #github-login": function(){
  274. Meteor.loginWithGithub({loginStyle: "redirect"}, function(err, res) {
  275. console.log(err, res);
  276. });
  277. }
  278. });
  279. Template.playlist.events({
  280. "keyup #search-playlist": function(){
  281. if($("#search-playlist").val().length === 0){
  282. $(".pl-item").show();
  283. $("#up-next").show();
  284. } else {
  285. $("#up-next").hide();
  286. $(".pl-item").hide();
  287. var input = $("#search-playlist").val().toLowerCase();
  288. $(".pl-item .pl-title").each(function(i, el){
  289. if($(el).text().toLowerCase().indexOf(input) !== -1){
  290. $(el).parent(".pl-item").show();
  291. }
  292. })
  293. $(".pl-item #pl-artist").each(function(i, el){
  294. if($(el).text().toLowerCase().indexOf(input) !== -1){
  295. $(el).parent(".pl-item").show();
  296. }
  297. })
  298. }
  299. }
  300. });
  301. Template.profile.events({
  302. //Edit real name
  303. "click #edit-name": function(){
  304. $("#name").hide();
  305. $("#name-div").show();
  306. $("#edit-name").hide();
  307. $("#cancel-edit").show();
  308. },
  309. "click #submit-name": function(){
  310. var user = Meteor.user();
  311. $("#name").show();
  312. $("#name-div").hide();
  313. $("#edit-name").show();
  314. $("#cancel-edit").hide();
  315. var realname = $("#input-name").val();
  316. var username = user.profile.username;
  317. $("#name").text("Name: " + realname);
  318. $("#input-name").val("")
  319. Meteor.call("updateRealName", realname);
  320. },
  321. "click #cancel-edit": function(){
  322. $("#name").show();
  323. $("#name-div").hide();
  324. $("#edit-name").show();
  325. $("#cancel-edit").hide();
  326. $("#input-name").val("");
  327. },
  328. //Edit username
  329. "click #edit-username": function(){
  330. $("#username").hide();
  331. $("#username-div").show();
  332. $("#edit-username").hide();
  333. $("#cancel-username").show();
  334. },
  335. "click #submit-username": function(){
  336. var user = Meteor.user()
  337. $("#username").show();
  338. $("#username-div").hide();
  339. $("#edit-username").show();
  340. $("#cancel-username").hide();
  341. var username = user.username;
  342. var newUserName = $("#input-username").val();
  343. $("#profile-name").text(newUserName)
  344. $("#username").text("Username: " + newUserName);
  345. $("#input-username").val("")
  346. Meteor.call("updateUserName", newUserName);
  347. window.location = "/u/" + newUserName;
  348. },
  349. "click #cancel-username": function(){
  350. $("#username").show();
  351. $("#username-div").hide();
  352. $("#edit-username").show();
  353. $("#cancel-username").hide();
  354. $("#input-username").val("");
  355. },
  356. // Admins only Edit Rank
  357. "click #edit-rank": function() {
  358. $("#rank").hide();
  359. $("#rank-div").show();
  360. $("#edit-rank").hide();
  361. $("#cancel-rank").show();
  362. },
  363. "click #submit-rank": function() {
  364. $("#rank").show();
  365. $("#rank-div").hide();
  366. $("#edit-rank").show();
  367. $("#cancel-rank").hide();
  368. var newRank = $("#select-rank option:selected").val();
  369. var username = Session.get("username");
  370. },
  371. "click #cancel-rank": function() {
  372. $("#rank").show();
  373. $("#rank-div").hide();
  374. $("#edit-rank").show();
  375. $("#cancel-rank").hide();
  376. }
  377. });
  378. var seekerBarInterval = undefined;
  379. Template.queues.events({
  380. /* TODO Add undo delete button */
  381. "input #id": function() {
  382. $("#previewPlayerContainer").addClass("hide-preview");
  383. },
  384. "input #img": function() {
  385. var url = $("#img").val();
  386. Session.set("image_url", url);
  387. },
  388. "click .preview-button": function(e){
  389. Session.set("song", this);
  390. $("#previewModal").openModal();
  391. },
  392. "click #previewImageButton": function() {
  393. $("#preview-image").attr("src", Session.get("song").img);
  394. },
  395. "click .edit-queue-button": function(e){
  396. Session.set("song", this);
  397. Session.set("genre", $(e.target).data("genre"));
  398. Session.set("type", "queue");
  399. $("#mid").val(this.mid).change();
  400. $("#artist").val(this.artist).change();
  401. $("#title").val(this.title).change();
  402. $("#img").val(this.img).change();
  403. $("#id").val(this.id).change();
  404. $("#likes").val(this.likes).change();
  405. $("#dislikes").val(this.dislikes).change();
  406. $("#duration").val(this.duration).change();
  407. $("#skip-duration").val(this.skipDuration).change();
  408. $("#genres").val(this.genres).change();
  409. $("#genres").material_select();
  410. $("#previewPlayerContainer").addClass("hide-preview");
  411. Session.set("image_url", this.img);
  412. Session.set("editing", true);
  413. $("#editModal").openModal({
  414. complete : function() {
  415. Session.set("editing", false);
  416. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
  417. YTPlayer.stopVideo();
  418. }
  419. }
  420. });
  421. },
  422. "click .add-song-button": function(e){
  423. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  424. Meteor.call("addSongToPlaylist", this, function(err) {
  425. console.log(err);
  426. if (err) {
  427. var $toastContent = $('<span><strong>Song not added.</strong> ' + err.reason + '</span>');
  428. Materialize.toast($toastContent, 8000);
  429. }
  430. });
  431. },
  432. "click .deny-song-button": function(e){
  433. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  434. Meteor.call("removeSongFromQueue", this.mid);
  435. },
  436. "click #play": function() {
  437. var duration = Session.get("song").duration;
  438. var d = moment.duration(parseInt(duration), 'seconds');
  439. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  440. $("#previewPlayerContainer").removeClass("hide-preview");
  441. var song = Session.get("song");
  442. var id = song.id;
  443. var volume = localStorage.getItem("volume") || 20;
  444. if (song.duration !== 0) {
  445. $("#play").attr("disabled", true);
  446. $("#stop").attr("disabled", false);
  447. $("#pause").attr("disabled", false);
  448. $("#forward").attr("disabled", false);
  449. if (YTPlayer === undefined) {
  450. YTPlayer = new YT.Player("previewPlayer", {
  451. height: 540,
  452. width: 568,
  453. videoId: id,
  454. playerVars: {autoplay: 1, controls: 0, iv_load_policy: 3, showinfo: 0, fs: 0},
  455. events: {
  456. 'onReady': function(event) {
  457. event.target.seekTo(Number(song.skipDuration));
  458. event.target.playVideo();
  459. event.target.setVolume(volume);
  460. },
  461. 'onStateChange': function(event){
  462. if (event.data == YT.PlayerState.PAUSED) {
  463. if (seekerBarInterval !== undefined) {
  464. Meteor.clearInterval(seekerBarInterval);
  465. seekerBarInterval = undefined;
  466. }
  467. }
  468. // if (event.data == YT.PlayerState.UNSTARTED) {
  469. // if (seekerBarInterval !== undefined) {
  470. // Meteor.clearInterval(seekerBarInterval);
  471. // seekerBarInterval = undefined;
  472. // }
  473. // $(".seeker-bar").css({width: "0"});
  474. // $("#time-elapsed").text("0:00");
  475. // $("#previewPlayerContainer").addClass("hide-preview");
  476. // console.log("HIDE MEY STACY!!!!")
  477. // }
  478. if (event.data == YT.PlayerState.PLAYING) {
  479. seekerBarInterval = Meteor.setInterval(function() {
  480. var duration = Session.get("song").duration;
  481. var timeElapsed = YTPlayer.getCurrentTime();
  482. var skipDuration = Session.get("song").skipDuration;
  483. if (duration <= (timeElapsed - skipDuration)) {
  484. YTPlayer.stopVideo();
  485. $("#play").attr("disabled", false);
  486. $("#stop").attr("disabled", true);
  487. $("#pause").attr("disabled", true);
  488. $("#forward").attr("disabled", true);
  489. $("#previewPlayerContainer").addClass("hide-preview");
  490. $(".seeker-bar").css({width: "0"});
  491. $("#time-elapsed").text("0:00");
  492. Meteor.clearInterval(seekerBarInterval);
  493. } else {
  494. var percentComplete = (timeElapsed - skipDuration) / duration * 100;
  495. $(".seeker-bar").css({width: percentComplete + "%"});
  496. var d = moment.duration(timeElapsed - skipDuration, 'seconds');
  497. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  498. }
  499. }, 100);
  500. $("#play").attr("disabled", true);
  501. $("#stop").attr("disabled", false);
  502. $("#pause").attr("disabled", false);
  503. $("#forward").attr("disabled", false);
  504. } else {
  505. $("#play").attr("disabled", false);
  506. $("#stop").attr("disabled", true);
  507. $("#pause").attr("disabled", true);
  508. $("#forward").attr("disabled", true);
  509. }
  510. }
  511. }
  512. });
  513. } else {
  514. if (YTPlayer.getPlayerState() === 2) {
  515. YTPlayer.playVideo();
  516. } else {
  517. YTPlayer.loadVideoById(id);
  518. YTPlayer.seekTo(Number(song.skipDuration));
  519. }
  520. }
  521. $("#previewPlayerContainer").removeClass("hide-preview");
  522. }
  523. },
  524. "click #stop": function() {
  525. $("#play").attr("disabled", false);
  526. $("#stop").attr("disabled", true);
  527. $("#pause").attr("disabled", true);
  528. $("#forward").attr("disabled", true);
  529. if (previewEndSongTimeout !== undefined) {
  530. Meteor.clearTimeout(previewEndSongTimeout);
  531. }
  532. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
  533. YTPlayer.stopVideo();
  534. }
  535. },
  536. "click #pause": function() {
  537. $("#play").attr("disabled", false);
  538. $("#stop").attr("disabled", false);
  539. $("#pause").attr("disabled", true);
  540. $("#forward").attr("disabled", true);
  541. if (previewEndSongTimeout !== undefined) {
  542. Meteor.clearTimeout(previewEndSongTimeout);
  543. }
  544. if (YTPlayer !== undefined && YTPlayer.pauseVideo !== undefined) {
  545. YTPlayer.pauseVideo();
  546. }
  547. },
  548. "click #forward": function() {
  549. var error = false;
  550. if (YTPlayer !== undefined) {
  551. var duration = Number(Session.get("song").duration) | 0;
  552. var skipDuration = Number(Session.get("song").skipDuration) | 0;
  553. if (YTPlayer.getDuration() < duration + skipDuration) {
  554. var $toastContent = $('<span><strong>Error.</strong> The song duration is longer than the length of the video.</span>');
  555. Materialize.toast($toastContent, 8000);
  556. error = true;
  557. } else {
  558. YTPlayer.seekTo(skipDuration + duration - 10);
  559. }
  560. }
  561. if (!error) {
  562. if (previewEndSongTimeout !== undefined) {
  563. Meteor.clearTimeout(previewEndSongTimeout);
  564. }
  565. previewEndSongTimeout = Meteor.setTimeout(function() {
  566. if (YTPlayer !== undefined) {
  567. YTPlayer.stopVideo();
  568. }
  569. $("#play").attr("disabled", false);
  570. $("#stop").attr("disabled", true);
  571. $("#pause").attr("disabled", true);
  572. $("#forward").attr("disabled", true);
  573. $("#previewPlayerContainer").addClass("hide-preview");
  574. }, 10000);
  575. }
  576. },
  577. "click #get-spotify-info": function() {
  578. var search = $("#title").val();
  579. var artistName = $("#artist").val();
  580. getSpotifyInfo(search, function(data) {
  581. for(var i in data){
  582. for(var j in data[i].items){
  583. if(search.indexOf(data[i].items[j].name) !== -1 && artistName.indexOf(data[i].items[j].artists[0].name) !== -1){
  584. $("#img").val(data[i].items[j].album.images[0].url).change();
  585. $("#duration").val(data[i].items[j].duration_ms / 1000).change();
  586. return;
  587. }
  588. }
  589. }
  590. }, artistName);
  591. },
  592. "click #save-song-button": function() {
  593. var newSong = {};
  594. newSong.mid = $("#mid").val();
  595. newSong.id = $("#id").val();
  596. newSong.likes = Number($("#likes").val());
  597. newSong.dislikes = Number($("#dislikes").val());
  598. newSong.title = $("#title").val();
  599. newSong.artist = $("#artist").val();
  600. newSong.img = $("#img").val();
  601. newSong.duration = Number($("#duration").val());
  602. newSong.skipDuration = $("#skip-duration").val();
  603. newSong.requestedBy = Session.get("song").requestedBy;
  604. newSong.genres = $("#genres").val() || [];
  605. if(newSong.skipDuration === undefined){
  606. newSong.skipDuration = 0;
  607. }
  608. Meteor.call("updateQueueSong", newSong.mid, newSong, function(err, res) {
  609. if (err) {
  610. var $toastContent = $('<span><strong>Song not saved.</strong> ' + err.reason + '</span>');
  611. Materialize.toast($toastContent, 8000);
  612. } else {
  613. $("#editModal").closeModal();
  614. var $toastContent = $('<span><strong>Song saved!</strong> No errors were found.</span>');
  615. Materialize.toast($toastContent, 4000);
  616. Session.set("song", newSong);
  617. }
  618. });
  619. }
  620. });
  621. Template.manageStation.events({
  622. /* TODO Add undo delete button */
  623. "click #editDescButton": function() {
  624. var parts = location.href.split('/');
  625. parts.pop();
  626. var id = parts.pop();
  627. var type = id.toLowerCase();
  628. var editingDesc = Session.get("editingDesc");
  629. if (!editingDesc) {
  630. Session.set("editingDesc", !editingDesc);
  631. } else {
  632. var newDesc = $("#editDesc").val();
  633. Meteor.call("editRoomDesc", type, newDesc);
  634. Session.set("editingDesc", !editingDesc);
  635. }
  636. },
  637. "input #id": function() {
  638. $("#previewPlayerContainer").addClass("hide-preview");
  639. },
  640. "input #img": function() {
  641. var url = $("#img").val();
  642. Session.set("image_url", url);
  643. },
  644. "click .preview-button": function(e){
  645. Session.set("song", this);
  646. $("#previewModal").openModal();
  647. },
  648. "click #previewImageButton": function() {
  649. $("#preview-image").attr("src", Session.get("song").img);
  650. },
  651. "click .edit-song-button": function(e){
  652. Session.set("song", this);
  653. Session.set("genre", $(e.target).data("genre"));
  654. $("#mid").val(this.mid).change();
  655. $("#artist").val(this.artist).change();
  656. $("#title").val(this.title).change();
  657. $("#img").val(this.img).change();
  658. $("#id").val(this.id).change();
  659. $("#likes").val(this.likes).change();
  660. $("#dislikes").val(this.dislikes).change();
  661. $("#duration").val(this.duration).change();
  662. $("#skip-duration").val(this.skipDuration).change();
  663. $("#previewPlayerContainer").addClass("hide-preview");
  664. Session.set("image_url", this.img);
  665. Session.set("editing", true);
  666. $("#editModal").openModal({
  667. complete : function() {
  668. Session.set("editing", false);
  669. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
  670. YTPlayer.stopVideo();
  671. }
  672. }
  673. });
  674. },
  675. "click .remove-song-button": function(e){
  676. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  677. Meteor.call("removeSongFromPlaylist", genre, this.mid);
  678. },
  679. "click #play": function() {
  680. var duration = Session.get("song").duration;
  681. var d = moment.duration(parseInt(duration), 'seconds');
  682. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  683. $("#previewPlayerContainer").removeClass("hide-preview");
  684. var song = Session.get("song");
  685. var id = song.id;
  686. var volume = localStorage.getItem("volume") || 20;
  687. if (song.duration !== 0) {
  688. $("#play").attr("disabled", true);
  689. $("#stop").attr("disabled", false);
  690. $("#pause").attr("disabled", false);
  691. $("#forward").attr("disabled", false);
  692. if (YTPlayer === undefined) {
  693. YTPlayer = new YT.Player("previewPlayer", {
  694. height: 540,
  695. width: 568,
  696. videoId: id,
  697. playerVars: {autoplay: 1, controls: 0, iv_load_policy: 3, showinfo: 0, fs: 0},
  698. events: {
  699. 'onReady': function(event) {
  700. event.target.seekTo(Number(song.skipDuration));
  701. event.target.playVideo();
  702. event.target.setVolume(volume);
  703. },
  704. 'onStateChange': function(event){
  705. if (event.data == YT.PlayerState.PAUSED) {
  706. if (seekerBarInterval !== undefined) {
  707. Meteor.clearInterval(seekerBarInterval);
  708. seekerBarInterval = undefined;
  709. }
  710. }
  711. // if (event.data == YT.PlayerState.UNSTARTED) {
  712. // if (seekerBarInterval !== undefined) {
  713. // Meteor.clearInterval(seekerBarInterval);
  714. // seekerBarInterval = undefined;
  715. // }
  716. // $(".seeker-bar").css({width: "0"});
  717. // $("#time-elapsed").text("0:00");
  718. // $("#previewPlayerContainer").addClass("hide-preview");
  719. // }
  720. if (event.data == YT.PlayerState.PLAYING) {
  721. seekerBarInterval = Meteor.setInterval(function() {
  722. var duration = Session.get("song").duration;
  723. var timeElapsed = YTPlayer.getCurrentTime();
  724. var skipDuration = Session.get("song").skipDuration;
  725. if (duration <= (timeElapsed - skipDuration)) {
  726. YTPlayer.stopVideo();
  727. $("#play").attr("disabled", false);
  728. $("#stop").attr("disabled", true);
  729. $("#pause").attr("disabled", true);
  730. $("#forward").attr("disabled", true);
  731. $("#previewPlayerContainer").addClass("hide-preview");
  732. $(".seeker-bar").css({width: "0"});
  733. $("#time-elapsed").text("0:00");
  734. Meteor.clearInterval(seekerBarInterval);
  735. } else {
  736. var percentComplete = (timeElapsed - skipDuration) / duration * 100;
  737. $(".seeker-bar").css({width: percentComplete + "%"});
  738. var d = moment.duration(timeElapsed - skipDuration, 'seconds');
  739. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  740. }
  741. }, 100);
  742. $("#play").attr("disabled", true);
  743. $("#stop").attr("disabled", false);
  744. $("#pause").attr("disabled", false);
  745. $("#forward").attr("disabled", false);
  746. } else {
  747. $("#play").attr("disabled", false);
  748. $("#stop").attr("disabled", true);
  749. $("#pause").attr("disabled", true);
  750. $("#forward").attr("disabled", true);
  751. }
  752. }
  753. }
  754. });
  755. } else {
  756. if (YTPlayer.getPlayerState() === 2) {
  757. YTPlayer.playVideo();
  758. } else {
  759. YTPlayer.loadVideoById(id);
  760. YTPlayer.seekTo(Number(song.skipDuration));
  761. }
  762. }
  763. $("#previewPlayerContainer").removeClass("hide-preview");
  764. }
  765. },
  766. "click #stop": function() {
  767. $("#play").attr("disabled", false);
  768. $("#stop").attr("disabled", true);
  769. $("#pause").attr("disabled", true);
  770. $("#forward").attr("disabled", true);
  771. if (previewEndSongTimeout !== undefined) {
  772. Meteor.clearTimeout(previewEndSongTimeout);
  773. }
  774. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
  775. YTPlayer.stopVideo();
  776. }
  777. },
  778. "click #pause": function() {
  779. $("#play").attr("disabled", false);
  780. $("#stop").attr("disabled", false);
  781. $("#pause").attr("disabled", true);
  782. $("#forward").attr("disabled", true);
  783. if (previewEndSongTimeout !== undefined) {
  784. Meteor.clearTimeout(previewEndSongTimeout);
  785. }
  786. if (YTPlayer !== undefined && YTPlayer.pauseVideo !== undefined) {
  787. YTPlayer.pauseVideo();
  788. }
  789. },
  790. "click #forward": function() {
  791. var error = false;
  792. if (YTPlayer !== undefined) {
  793. var duration = Number(Session.get("song").duration) | 0;
  794. var skipDuration = Number(Session.get("song").skipDuration) | 0;
  795. if (YTPlayer.getDuration() < duration + skipDuration) {
  796. var $toastContent = $('<span><strong>Error.</strong> The song duration is longer than the length of the video.</span>');
  797. Materialize.toast($toastContent, 8000);
  798. error = true;
  799. } else {
  800. YTPlayer.seekTo(skipDuration + duration - 10);
  801. }
  802. }
  803. if (!error) {
  804. if (previewEndSongTimeout !== undefined) {
  805. Meteor.clearTimeout(previewEndSongTimeout);
  806. }
  807. previewEndSongTimeout = Meteor.setTimeout(function() {
  808. if (YTPlayer !== undefined) {
  809. YTPlayer.stopVideo();
  810. }
  811. $("#play").attr("disabled", false);
  812. $("#stop").attr("disabled", true);
  813. $("#pause").attr("disabled", true);
  814. $("#forward").attr("disabled", true);
  815. $("#previewPlayerContainer").addClass("hide-preview");
  816. }, 10000);
  817. }
  818. },
  819. "click #get-spotify-info": function() {
  820. var search = $("#title").val();
  821. var artistName = $("#artist").val();
  822. getSpotifyInfo(search, function(data) {
  823. for(var i in data){
  824. for(var j in data[i].items){
  825. if(search.indexOf(data[i].items[j].name) !== -1 && artistName.indexOf(data[i].items[j].artists[0].name) !== -1){
  826. $("#img").val(data[i].items[j].album.images[0].url).change();
  827. $("#duration").val(data[i].items[j].duration_ms / 1000).change();
  828. return;
  829. }
  830. }
  831. }
  832. }, artistName);
  833. },
  834. "click #save-song-button": function() {
  835. var newSong = {};
  836. newSong.mid = $("#mid").val();
  837. newSong.id = $("#id").val();
  838. newSong.likes = Number($("#likes").val());
  839. newSong.dislikes = Number($("#dislikes").val());
  840. newSong.title = $("#title").val();
  841. newSong.artist = $("#artist").val();
  842. newSong.img = $("#img").val();
  843. newSong.duration = Number($("#duration").val());
  844. newSong.skipDuration = $("#skip-duration").val();
  845. newSong.requestedBy = Session.get("song").requestedBy;
  846. newSong.genres = $("#genres").val();
  847. Meteor.call("updatePlaylistSong", newSong.mid, newSong, function(err, res) {
  848. console.log(err, res);
  849. if (err) {
  850. var $toastContent = $('<span><strong>Song not saved.</strong> ' + err.reason + '</span>');
  851. Materialize.toast($toastContent, 8000);
  852. } else {
  853. var $toastContent = $('<span><strong>Song saved!</strong> No errors were found.</span>');
  854. Materialize.toast($toastContent, 4000);
  855. Session.set("song", newSong);
  856. }
  857. });
  858. },
  859. "click .remove-report-button": function(){
  860. var parts = location.href.split('/');
  861. parts.pop();
  862. var id = parts.pop();
  863. var query = {room: id.toLowerCase()};
  864. var obj = $(this)[0];
  865. Meteor.call("removeReport", query, obj);
  866. },
  867. "click #deleteRoom": function(){
  868. var type = location.href.split("/")[3];
  869. Meteor.call("deleteRoom", type, function(err,res){
  870. window.location.href = "/";
  871. })
  872. }
  873. });
  874. Template.manageSongs.events({
  875. /* TODO Add undo delete button */
  876. "change #show_genres_cb": function() {
  877. var selected = $("#show_genres_cb").is(":checked");
  878. Session.set("showGenres", selected);
  879. },
  880. "change #show_no_genres_cb": function() {
  881. var selected = $("#show_no_genres_cb").is(":checked");
  882. Session.set("showNoGenres", selected);
  883. },
  884. "input #id": function() {
  885. $("#previewPlayerContainer").addClass("hide-preview");
  886. },
  887. "input #img": function() {
  888. var url = $("#img").val();
  889. Session.set("image_url", url);
  890. },
  891. "click .preview-button": function(e){
  892. Session.set("song", this);
  893. $("#previewModal").openModal();
  894. },
  895. "click #previewImageButton": function() {
  896. $("#preview-image").attr("src", Session.get("song").img);
  897. },
  898. "click .edit-song-button": function(e){
  899. Session.set("song", this);
  900. Session.set("genre", $(e.target).data("genre"));
  901. $("#mid").val(this.mid).change();
  902. $("#artist").val(this.artist).change();
  903. $("#title").val(this.title).change();
  904. $("#img").val(this.img).change();
  905. $("#id").val(this.id).change();
  906. $("#likes").val(this.likes).change();
  907. $("#dislikes").val(this.dislikes).change();
  908. $("#duration").val(this.duration).change();
  909. $("#skip-duration").val(this.skipDuration).change();
  910. $("#genres").val(this.genres).change();
  911. $("#genres").material_select();
  912. $("#previewPlayerContainer").addClass("hide-preview");
  913. Session.set("image_url", this.img);
  914. Session.set("editing", true);
  915. $("#editModal").openModal({
  916. complete : function() {
  917. Session.set("editing", false);
  918. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
  919. YTPlayer.stopVideo();
  920. }
  921. }
  922. });
  923. },
  924. "click .remove-song-button": function(){
  925. Meteor.call("deleteSong", this.mid);
  926. },
  927. "click #play": function() {
  928. var duration = Session.get("song").duration;
  929. var d = moment.duration(parseInt(duration), 'seconds');
  930. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  931. $("#previewPlayerContainer").removeClass("hide-preview");
  932. var song = Session.get("song");
  933. var id = song.id;
  934. var volume = localStorage.getItem("volume") || 20;
  935. if (song.duration !== 0) {
  936. $("#play").attr("disabled", true);
  937. $("#stop").attr("disabled", false);
  938. $("#pause").attr("disabled", false);
  939. $("#forward").attr("disabled", false);
  940. if (YTPlayer === undefined) {
  941. YTPlayer = new YT.Player("previewPlayer", {
  942. height: 540,
  943. width: 568,
  944. videoId: id,
  945. playerVars: {autoplay: 1, controls: 0, iv_load_policy: 3, showinfo: 0, fs: 0},
  946. events: {
  947. 'onReady': function(event) {
  948. event.target.seekTo(Number(song.skipDuration));
  949. event.target.playVideo();
  950. event.target.setVolume(volume);
  951. },
  952. 'onStateChange': function(event){
  953. if (event.data == YT.PlayerState.PAUSED) {
  954. if (seekerBarInterval !== undefined) {
  955. Meteor.clearInterval(seekerBarInterval);
  956. seekerBarInterval = undefined;
  957. }
  958. }
  959. // if (event.data == YT.PlayerState.UNSTARTED) {
  960. // if (seekerBarInterval !== undefined) {
  961. // Meteor.clearInterval(seekerBarInterval);
  962. // seekerBarInterval = undefined;
  963. // }
  964. // $(".seeker-bar").css({width: "0"});
  965. // $("#time-elapsed").text("0:00");
  966. // $("#previewPlayerContainer").addClass("hide-preview");
  967. // }
  968. if (event.data == YT.PlayerState.PLAYING) {
  969. seekerBarInterval = Meteor.setInterval(function() {
  970. var duration = Session.get("song").duration;
  971. var timeElapsed = YTPlayer.getCurrentTime();
  972. var skipDuration = Session.get("song").skipDuration;
  973. if (duration <= (timeElapsed - skipDuration)) {
  974. YTPlayer.stopVideo();
  975. $("#play").attr("disabled", false);
  976. $("#stop").attr("disabled", true);
  977. $("#pause").attr("disabled", true);
  978. $("#forward").attr("disabled", true);
  979. $("#previewPlayerContainer").addClass("hide-preview");
  980. $(".seeker-bar").css({width: "0"});
  981. $("#time-elapsed").text("0:00");
  982. Meteor.clearInterval(seekerBarInterval);
  983. } else {
  984. var percentComplete = (timeElapsed - skipDuration) / duration * 100;
  985. $(".seeker-bar").css({width: percentComplete + "%"});
  986. var d = moment.duration(timeElapsed - skipDuration, 'seconds');
  987. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  988. }
  989. }, 100);
  990. $("#play").attr("disabled", true);
  991. $("#stop").attr("disabled", false);
  992. $("#pause").attr("disabled", false);
  993. $("#forward").attr("disabled", false);
  994. } else {
  995. $("#play").attr("disabled", false);
  996. $("#stop").attr("disabled", true);
  997. $("#pause").attr("disabled", true);
  998. $("#forward").attr("disabled", true);
  999. }
  1000. }
  1001. }
  1002. });
  1003. } else {
  1004. if (YTPlayer.getPlayerState() === 2) {
  1005. YTPlayer.playVideo();
  1006. } else {
  1007. YTPlayer.loadVideoById(id);
  1008. YTPlayer.seekTo(Number(song.skipDuration));
  1009. }
  1010. }
  1011. $("#previewPlayerContainer").removeClass("hide-preview");
  1012. }
  1013. },
  1014. "click #stop": function() {
  1015. $("#play").attr("disabled", false);
  1016. $("#stop").attr("disabled", true);
  1017. $("#pause").attr("disabled", true);
  1018. $("#forward").attr("disabled", true);
  1019. if (previewEndSongTimeout !== undefined) {
  1020. Meteor.clearTimeout(previewEndSongTimeout);
  1021. }
  1022. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) {
  1023. YTPlayer.stopVideo();
  1024. }
  1025. },
  1026. "click #pause": function() {
  1027. $("#play").attr("disabled", false);
  1028. $("#stop").attr("disabled", false);
  1029. $("#pause").attr("disabled", true);
  1030. $("#forward").attr("disabled", true);
  1031. if (previewEndSongTimeout !== undefined) {
  1032. Meteor.clearTimeout(previewEndSongTimeout);
  1033. }
  1034. if (YTPlayer !== undefined && YTPlayer.pauseVideo !== undefined) {
  1035. YTPlayer.pauseVideo();
  1036. }
  1037. },
  1038. "click #forward": function() {
  1039. var error = false;
  1040. if (YTPlayer !== undefined) {
  1041. var duration = Number(Session.get("song").duration) | 0;
  1042. var skipDuration = Number(Session.get("song").skipDuration) | 0;
  1043. if (YTPlayer.getDuration() < duration + skipDuration) {
  1044. var $toastContent = $('<span><strong>Error.</strong> The song duration is longer than the length of the video.</span>');
  1045. Materialize.toast($toastContent, 8000);
  1046. error = true;
  1047. } else {
  1048. YTPlayer.seekTo(skipDuration + duration - 10);
  1049. }
  1050. }
  1051. if (!error) {
  1052. if (previewEndSongTimeout !== undefined) {
  1053. Meteor.clearTimeout(previewEndSongTimeout);
  1054. }
  1055. previewEndSongTimeout = Meteor.setTimeout(function() {
  1056. if (YTPlayer !== undefined) {
  1057. YTPlayer.stopVideo();
  1058. }
  1059. $("#play").attr("disabled", false);
  1060. $("#stop").attr("disabled", true);
  1061. $("#pause").attr("disabled", true);
  1062. $("#forward").attr("disabled", true);
  1063. $("#previewPlayerContainer").addClass("hide-preview");
  1064. }, 10000);
  1065. }
  1066. },
  1067. "click #get-spotify-info": function() {
  1068. var search = $("#title").val();
  1069. var artistName = $("#artist").val();
  1070. getSpotifyInfo(search, function(data) {
  1071. for(var i in data){
  1072. for(var j in data[i].items){
  1073. if(search.indexOf(data[i].items[j].name) !== -1 && artistName.indexOf(data[i].items[j].artists[0].name) !== -1){
  1074. $("#img").val(data[i].items[j].album.images[0].url).change();
  1075. $("#duration").val(data[i].items[j].duration_ms / 1000).change();
  1076. return;
  1077. }
  1078. }
  1079. }
  1080. }, artistName);
  1081. },
  1082. "click #save-song-button": function() {_
  1083. var newSong = {};
  1084. newSong.mid = $("#mid").val();
  1085. newSong.id = $("#id").val();
  1086. newSong.likes = Number($("#likes").val());
  1087. newSong.dislikes = Number($("#dislikes").val());
  1088. newSong.title = $("#title").val();
  1089. newSong.artist = $("#artist").val();
  1090. newSong.img = $("#img").val();
  1091. newSong.duration = Number($("#duration").val());
  1092. newSong.skipDuration = $("#skip-duration").val();
  1093. newSong.requestedBy = Session.get("song").requestedBy;
  1094. newSong.genres = $("#genres").val() || [];
  1095. Meteor.call("updatePlaylistSong", newSong.mid, newSong, function(err, res) {
  1096. console.log(err, res);
  1097. if (err) {
  1098. var $toastContent = $('<span><strong>Song not saved.</strong> ' + err.reason + '</span>');
  1099. Materialize.toast($toastContent, 8000);
  1100. } else {
  1101. var $toastContent = $('<span><strong>Song saved!</strong> No errors were found.</span>');
  1102. Materialize.toast($toastContent, 4000);
  1103. Session.set("song", newSong);
  1104. }
  1105. });
  1106. }
  1107. });
  1108. Template.register.events({
  1109. "submit form": function(e){
  1110. e.preventDefault();
  1111. var username = $("#username").val();
  1112. var email = $("#email").val();
  1113. var password = $("#password").val();
  1114. var acceptedTermsAndPrivacy = $("#termsPrivacyBTN").is(":checked");
  1115. var captchaData = grecaptcha.getResponse();
  1116. if (acceptedTermsAndPrivacy) {
  1117. Meteor.call("createUserMethod", {username: username, email: email, password: password}, captchaData, function(err, res) {
  1118. grecaptcha.reset();
  1119. if (err) {
  1120. console.log(err);
  1121. var $toastContent = $('<span><strong>Oh snap!</strong> ' + err.reason + '</span>');
  1122. Materialize.toast($toastContent, 8000);
  1123. } else {
  1124. Meteor.loginWithPassword(username, password);
  1125. Accounts.onLogin(function(){
  1126. window.location.href = "/";
  1127. })
  1128. }
  1129. });
  1130. } else {
  1131. var $toastContent = $('<span><strong>Oh snap!</strong> Please read and accept the Terms and Conditions and the Privacy Policy.</span>');
  1132. Materialize.toast($toastContent, 8000);
  1133. }
  1134. },
  1135. "click #github-login": function(){
  1136. Meteor.loginWithGithub({loginStyle: "redirect"}, function(err, res) {
  1137. console.log(err, res);
  1138. });
  1139. }
  1140. });
  1141. Template.news.events({
  1142. "click #createArticleButton": function() {
  1143. var title = $("#title").val();
  1144. var content = $("#content").val();
  1145. var anonymous = $("#anonymous").is(":checked");
  1146. Meteor.call("createArticle", {title: title, content: content, anonymous: anonymous}, function(err, res) {
  1147. if (err) {
  1148. var $toastContent = $('<span><strong>Article not created.</strong> ' + err.reason + '</span>');
  1149. Materialize.toast($toastContent, 8000);
  1150. } else {
  1151. $('#createArticle').closeModal()
  1152. $("#title").val("").change();
  1153. $("#content").val("").change();
  1154. $("#anonymous").prop("checked", false).change();
  1155. }
  1156. });
  1157. }
  1158. });
  1159. Template.room.events({
  1160. "input #volume_slider": function() {
  1161. var volume = Number($("#volume_slider").val());
  1162. localStorage.setItem("volume", volume);
  1163. if (YTPlayer !== undefined) {
  1164. YTPlayer.setVolume(volume);
  1165. }
  1166. },
  1167. "click #add-song-modal-button": function() {
  1168. Session.set("songResults", []);
  1169. },
  1170. "click #return-button": function() {
  1171. Session.set("editingSong", false);
  1172. },
  1173. "click #removeSong": function(e) {
  1174. var id = $(e.target).data("result");
  1175. var songs = Session.get("songResults");
  1176. var currentSong;
  1177. songs = songs.filter(function(song) {
  1178. return id !== song.id;
  1179. });
  1180. Session.set("songResults", []);
  1181. Session.set("songResults", songs);
  1182. },
  1183. "click #addSong": function(e) {
  1184. var id = $(e.target).data("result");
  1185. var songs = Session.get("songResults");
  1186. var currentSong;
  1187. songs.forEach(function(song) {
  1188. if (song.id === id) {
  1189. currentSong = song;
  1190. }
  1191. });
  1192. Session.set("editingSong", true);
  1193. var title = currentSong.title;
  1194. var artist = currentSong.artist;
  1195. var img = currentSong.img;
  1196. getSpotifyInfo(title.replace(/\[.*\]/g, ""), function (data) {
  1197. if (data.tracks.items.length > 0) {
  1198. title = data.tracks.items[0].name;
  1199. var artists = [];
  1200. img = data.tracks.items[0].album.images[0].url;
  1201. data.tracks.items[0].artists.forEach(function (artist) {
  1202. artists.push(artist.name);
  1203. });
  1204. artist = artists.join(", ");
  1205. $("#title").val(title).change();
  1206. $("#artist").val(artist).change();
  1207. $("#img").val(img).change();
  1208. $("#id").val(id).change();
  1209. $("#genres").val(null).change();
  1210. } else {
  1211. $("#title").val(title).change();
  1212. $("#artist").val(artist).change();
  1213. $("#img").val(img).change();
  1214. $("#id").val(id).change();
  1215. $("#genres").val(null).change();
  1216. // I give up for now... Will fix this later. -Kris
  1217. }
  1218. });
  1219. },
  1220. "click #import-playlist-button": function () {
  1221. if (!Session.get("importingPlaylist")) {
  1222. Session.set("songResults", []);
  1223. var playlist_link = $("#playlist-url").val();
  1224. var playlist_id = gup("list", playlist_link);
  1225. var ytImportQueue = [];
  1226. var totalVideos = 0;
  1227. var videosInvalid = 0;
  1228. var videosInQueue = 0;
  1229. var videosInPlaylist = 0;
  1230. var ranOnce = false;
  1231. Session.set("importingPlaylist", true);
  1232. $("#import-playlist-button").attr("disabled", "");
  1233. $("#import-playlist-button").addClass("disabled");
  1234. $("#playlist-url").attr("disabled", "");
  1235. $("#playlist-url").addClass("disabled");
  1236. $("#import-progress").css({width: "0%"});
  1237. function makeAPICall(playlist_id, nextPageToken) {
  1238. if (nextPageToken !== undefined) {
  1239. nextPageToken = "&pageToken=" + nextPageToken;
  1240. } else {
  1241. nextPageToken = "";
  1242. }
  1243. $.ajax({
  1244. type: "GET",
  1245. url: "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=" + playlist_id + nextPageToken + "&key=AIzaSyAgBdacEWrHCHVPPM4k-AFM7uXg-Q__YXY",
  1246. applicationType: "application/json",
  1247. contentType: "json",
  1248. success: function (data) {
  1249. if (!ranOnce) {
  1250. ranOnce = true;
  1251. totalVideos = data.pageInfo.totalResults;
  1252. }
  1253. var nextToken = data.nextPageToken;
  1254. for (var i in data.items) {
  1255. var item = data.items[i];
  1256. if (item.snippet.thumbnails !== undefined) {
  1257. var genre = Session.get("type");
  1258. if (Playlists.find({
  1259. type: genre,
  1260. "songs.id": item.snippet.resourceId.videoId
  1261. }, {songs: {$elemMatch: {id: item.snippet.resourceId.videoId}}}).count() !== 0) {
  1262. videosInPlaylist++;
  1263. } else if (Queues.find({
  1264. type: genre,
  1265. "songs.id": item.snippet.resourceId.videoId
  1266. }, {songs: {$elemMatch: {id: item.snippet.resourceId.videoId}}}).count() !== 0) {
  1267. videosInQueue++;
  1268. } else {
  1269. var percentage = ytImportQueue.length / (totalVideos - videosInvalid) * 100;
  1270. $("#import-progress").css({width: percentage + "%"});
  1271. ytImportQueue.push({title: item.snippet.title, artist: item.snippet.channelTitle, id: item.snippet.resourceId.videoId, image: item.snippet.thumbnails.medium.url});
  1272. }
  1273. } else {
  1274. videosInvalid++;
  1275. }
  1276. }
  1277. if (nextToken !== undefined) {
  1278. makeAPICall(playlist_id, nextToken);
  1279. } else {
  1280. /*$("#playlist-import-queue > div > i").click(function () {
  1281. var title = $(this).parent().find("div > .song-result-title").text();
  1282. for (var i in ytImportQueue) {
  1283. if (ytImportQueue[i].title === title) {
  1284. ytImportQueue.splice(i, 1);
  1285. }
  1286. }
  1287. $(this).parent().remove();
  1288. Session.set("YTImportQueue", ytImportQueue);
  1289. });*/
  1290. Session.set("importingPlaylist", false);
  1291. $("#import-progress").css({width: "100%"});
  1292. $("#import-playlist-button").removeAttr("disabled");
  1293. $("#import-playlist-button").removeClass("disabled");
  1294. $("#playlist-url").removeAttr("disabled");
  1295. $("#playlist-url").removeClass("disabled");
  1296. Session.set("YTImportQueue", ytImportQueue);
  1297. Session.set("songResults", ytImportQueue);
  1298. }
  1299. },
  1300. error: function() {
  1301. Session.set("importingPlaylist", false);
  1302. $("#import-progress").css({width: "0%"});
  1303. $("#import-playlist-button").removeAttr("disabled");
  1304. $("#import-playlist-button").removeClass("disabled");
  1305. $("#playlist-url").removeAttr("disabled");
  1306. $("#playlist-url").removeClass("disabled");
  1307. }
  1308. })
  1309. }
  1310. makeAPICall(playlist_id);
  1311. }
  1312. },
  1313. "click #confirm-import": function () {
  1314. var YTImportQueue = Session.get("YTImportQueue");
  1315. $("#import-playlist-button").attr("disabled", "");
  1316. $("#import-playlist-button").addClass("disabled");
  1317. $("#playlist-url").attr("disabled", "");
  1318. $("#playlist-url").addClass("disabled");
  1319. $("#import-progress").css({width: "0%"});
  1320. var failed = 0;
  1321. var success = 0;
  1322. var processed = 0;
  1323. var total = YTImportQueue.length;
  1324. YTImportQueue.forEach(function (song) {
  1325. var songData = {id: song.id, title: song.title, artist: "NONE", genres: [Session.get("type")]};
  1326. Meteor.call("addSongToQueue", songData, function (err, res) {
  1327. if (err) {
  1328. console.log(err);
  1329. failed++;
  1330. } else {
  1331. success++;
  1332. }
  1333. processed++;
  1334. var percentage = processed / total * 100;
  1335. $("#import-progress").css({width: percentage + "%"});
  1336. if (processed === total) {
  1337. $("#import-progress").css({width: "0%"});
  1338. var $toastContent = $('<span>' + failed + ' songs failed to import. ' + success + ' songs successfully imported.</span>');
  1339. Materialize.toast($toastContent, 4000);
  1340. }
  1341. });
  1342. });
  1343. $("#import-playlist-button").removeAttr("disabled");
  1344. $("#import-playlist-button").removeClass("disabled");
  1345. $("#playlist-url").removeAttr("disabled", "");
  1346. $("#playlist-url").removeClass("disabled");
  1347. Session.set("songResults", []);
  1348. Session.set("YTImportQueue", [])
  1349. },
  1350. "click #global-chat-tab": function () {
  1351. $("#global-chat-tab").removeClass("unread-messages");
  1352. },
  1353. "click #sync": function () {
  1354. if (Session.get("currentSong") !== undefined) {
  1355. var room = Rooms.findOne({type: Session.get("type")});
  1356. if (room !== undefined) {
  1357. var timeIn = Date.now() - Session.get("currentSong").started - room.timePaused;
  1358. var skipDuration = Number(Session.get("currentSong").skipDuration) | 0;
  1359. if (YTPlayer !== undefined) {
  1360. YTPlayer.seekTo(skipDuration + timeIn / 1000);
  1361. }
  1362. }
  1363. }
  1364. },
  1365. "click #lock": function () {
  1366. Meteor.call("lockRoom", Session.get("type"));
  1367. var $parent = $("#lock").parent();
  1368. $("#lock").remove();
  1369. $parent.append('<a id="unlock"><i class="material-icons">lock_open</i></a>')
  1370. },
  1371. "click #unlock": function () {
  1372. Meteor.call("unlockRoom", Session.get("type"));
  1373. var $parent = $("#unlock").parent();
  1374. $("#unlock").remove();
  1375. $parent.append('<a id="lock"><i class="material-icons">lock_outline</i></a>')
  1376. },
  1377. "click #submit": function () {
  1378. if(Meteor.userId()){
  1379. sendMessageGlobal();
  1380. Meteor.setTimeout(function () {
  1381. $(".chat-ul").scrollTop(100000);
  1382. }, 1000)
  1383. } else {
  1384. var $toastContent = $('<span>Message not sent. You must log in</span>');
  1385. Materialize.toast($toastContent, 2000);
  1386. }
  1387. },
  1388. "keyup #chat-message": function (e) {
  1389. if (e.type === "keyup" && e.which === 13) {
  1390. if(Meteor.userId()){
  1391. e.preventDefault();
  1392. if (!$('#chat-message').data('dropdownshown')) {
  1393. sendMessageGlobal();
  1394. Meteor.setTimeout(function () {
  1395. $(".chat-ul").scrollTop(100000);
  1396. }, 1000)
  1397. }
  1398. } else {
  1399. var $toastContent = $('<span>Message not sent. You must log in</span>');
  1400. Materialize.toast($toastContent, 2000);
  1401. }
  1402. }
  1403. },
  1404. "click #like": function (e) {
  1405. $("#like").blur();
  1406. Meteor.call("likeSong", Session.get("currentSong").mid);
  1407. },
  1408. "click #dislike": function (e) {
  1409. $("#dislike").blur();
  1410. Meteor.call("dislikeSong", Session.get("currentSong").mid);
  1411. },
  1412. "click #vote-skip": function () {
  1413. Meteor.call("voteSkip", Session.get("type"), function (err, res) {
  1414. $("#vote-skip").addClass("disabled");
  1415. if(err){
  1416. var $toastContent = $('<span><strong>Vote not submitted</strong> ' + err.reason + '</span>');
  1417. Materialize.toast($toastContent, 4000);
  1418. }
  1419. });
  1420. },
  1421. "click #report-prev": function (e) {
  1422. if (Session.get("previousSong") !== undefined) {
  1423. Session.set("reportPrevious", true);
  1424. $("#report-prev").addClass("disabled");
  1425. $("#report-curr").removeClass("disabled");
  1426. }
  1427. },
  1428. "click #report-curr": function (e) {
  1429. Session.set("reportPrevious", false);
  1430. $("#report-prev").removeClass("disabled");
  1431. $("#report-curr").addClass("disabled");
  1432. },
  1433. "click #report-modal": function () {
  1434. Session.set("currentSongR", Session.get("currentSong"));
  1435. Session.set("previousSongR", Session.get("previousSong"));
  1436. },
  1437. "click #add-song-button": function (e) {
  1438. e.preventDefault();
  1439. parts = location.href.split('/');
  1440. var roomType = parts.pop();
  1441. var genre = roomType.toLowerCase();
  1442. var type = $("#type").val();
  1443. id = $("#id").val();
  1444. var title = $("#title").val();
  1445. var artist = $("#artist").val();
  1446. var genres = $("#genres").val() || [];
  1447. var songData = {type: type, id: id, title: title, artist: artist, genres: genres};
  1448. if (Songs.find({"id": songData.id}).count() > 0) {
  1449. var $toastContent = $('<span><strong>Song not added.</strong> This song has already been added.</span>');
  1450. Materialize.toast($toastContent, 8000);
  1451. } else if (Queues.find({"id": songData.id}).count() > 0) {
  1452. var $toastContent = $('<span><strong>Song not added.</strong> This song has already been requested.</span>');
  1453. Materialize.toast($toastContent, 3000);
  1454. } else {
  1455. Meteor.call("addSongToQueue", songData, function (err, res) {
  1456. console.log(err, res);
  1457. if (err) {
  1458. var $toastContent = $('<span><strong>Song not added.</strong> ' + err.reason + '</span>');
  1459. Materialize.toast($toastContent, 3000);
  1460. } else {
  1461. var $toastContent = $('<span><strong>Song added.</strong> Your song has succesfully been added to the queue.</span>');
  1462. Materialize.toast($toastContent, 3000);
  1463. $('#add_song_modal').closeModal();
  1464. Session.set("editingSong", false);
  1465. }
  1466. });
  1467. }
  1468. },
  1469. "click #toggle-video": function (e) {
  1470. e.preventDefault();
  1471. if (Session.get("mediaHidden")) {
  1472. $("#media-container").removeClass("hidden");
  1473. $("#toggle-video").text("Hide video");
  1474. Session.set("mediaHidden", false);
  1475. } else {
  1476. $("#media-container").addClass("hidden");
  1477. $("#toggle-video").text("Show video");
  1478. Session.set("mediaHidden", true);
  1479. }
  1480. },
  1481. "click #return": function (e) {
  1482. $("#add-info").hide();
  1483. $("#search-info").show();
  1484. },
  1485. "click #search-song": function () {
  1486. var songs = [];
  1487. Session.set("songResults", songs);
  1488. $.ajax({
  1489. type: "GET",
  1490. url: "https://www.googleapis.com/youtube/v3/search?part=snippet&q=" + $("#song-input").val() + "&key=AIzaSyAgBdacEWrHCHVPPM4k-AFM7uXg-Q__YXY&type=video&maxResults=25",
  1491. applicationType: "application/json",
  1492. contentType: "json",
  1493. success: function (data) {
  1494. for (var i in data.items) {
  1495. var item = data.items[i];
  1496. songs.push({title: item.snippet.title, artist: item.snippet.channelTitle, id: item.id.videoId, image: item.snippet.thumbnails.medium.url});
  1497. }
  1498. Session.set("songResults", songs);
  1499. /*$("#song-results > div").click(function () {
  1500. $("#search-info").hide();
  1501. $("#add-info").show();
  1502. var title = $(this).find("div > .song-result-title").text();
  1503. for (var i in songs) {
  1504. if (songs[i].title === title) {
  1505. var songObj = {
  1506. id: songs[i].id,
  1507. title: songs[i].title,
  1508. type: "youtube"
  1509. };
  1510. $("#title").val(songObj.title);
  1511. $("#artist").val("");
  1512. $("#id").val(songObj.id);
  1513. getSpotifyInfo(songObj.title.replace(/\[.*\]/g, ""), function (data) {
  1514. if (data.tracks.items.length > 0) {
  1515. $("#title").val(data.tracks.items[0].name);
  1516. var artists = [];
  1517. $("#img").val(data.tracks.items[0].album.images[2].url);
  1518. data.tracks.items[0].artists.forEach(function (artist) {
  1519. artists.push(artist.name);
  1520. });
  1521. $("#artist").val(artists.join(", "));
  1522. }
  1523. });
  1524. }
  1525. }
  1526. })*/
  1527. }
  1528. })
  1529. },
  1530. "click #volume-icon": function () {
  1531. var volume = 0;
  1532. var slider = $("#volume-slider").slider();
  1533. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
  1534. if (YTPlayer !== undefined) {
  1535. YTPlayer.setVolume(volume);
  1536. localStorage.setItem("volume", volume);
  1537. $("#volume-slider").slider("setValue", volume);
  1538. }
  1539. },
  1540. "click #play": function () {
  1541. Meteor.call("resumeRoom", Session.get("type"));
  1542. var $parent = $("#play").parent();
  1543. $("#play").remove();
  1544. $parent.append('<a id="pause"><i class="material-icons">pause</i></a>')
  1545. },
  1546. "click #pause": function () {
  1547. Meteor.call("pauseRoom", Session.get("type"));
  1548. var $parent = $("#pause").parent();
  1549. $("#pause").remove();
  1550. $parent.append('<a id="play"><i class="material-icons">play_arrow</i></a>')
  1551. },
  1552. "click #skip": function () {
  1553. Meteor.call("skipSong", Session.get("type"));
  1554. },
  1555. "click #shuffle": function () {
  1556. Meteor.call("shufflePlaylist", Session.get("type"));
  1557. },
  1558. "change input": function (e) {
  1559. /*if (e.target && e.target.id) {
  1560. var partsOfId = e.target.id.split("-");
  1561. partsOfId[1] = partsOfId[1].charAt(0).toUpperCase() + partsOfId[1].slice(1);
  1562. var camelCase = partsOfId.join("");
  1563. Session.set(camelCase, e.target.checked);
  1564. }*/
  1565. },
  1566. "click #report-song-button": function () {
  1567. var room = Session.get("type");
  1568. var reportData = {};
  1569. if (Session.get("reportPrevious") === false) {
  1570. reportData.song = Session.get("previousSongR").mid;
  1571. } else {
  1572. reportData.song = Session.get("currentSongR").mid;
  1573. }
  1574. reportData.type = [];
  1575. reportData.reason = [];
  1576. $(".report-layer-1 > div > input:checked").each(function (){
  1577. reportData.type.push(this.id);
  1578. });
  1579. $(".report-layer-2 input:checked").each(function () {
  1580. reportData.reason.push(this.id);
  1581. });
  1582. Meteor.call("submitReport", room, reportData, function () {
  1583. $("report_modal").closeModal();
  1584. });
  1585. },
  1586. "change #si_or_pl": function () {
  1587. Session.set("songResults", []);
  1588. Session.set("si_or_pl", $("#si_or_pl").val());
  1589. },
  1590. "click #close-modal-a": function () {
  1591. $("#select_single").attr("selected", true);
  1592. $("#search-info").show();
  1593. $("#playlist-import").hide();
  1594. },
  1595. "click #admin-dropdown a": function(){
  1596. Meteor.setTimeout(function(){
  1597. $(".dropdown-button").click();
  1598. }, 10);
  1599. }
  1600. });
  1601. Template.privateRoom.events({
  1602. "input #volume_slider": function() {
  1603. var volume = Number($("#volume_slider").val());
  1604. localStorage.setItem("volume", volume);
  1605. if (YTPlayer !== undefined) {
  1606. YTPlayer.setVolume(volume);
  1607. }
  1608. },
  1609. "click #global-chat-tab": function () {
  1610. $("#global-chat-tab").removeClass("unread-messages");
  1611. },
  1612. "click #sync": function () {
  1613. if (Session.get("currentSong") !== undefined) {
  1614. var room = PrivateRooms.findOne({name: Session.get("privateRoomName")});
  1615. if (room !== undefined) {
  1616. var timeIn = Date.now() - Session.get("currentSong").started - room.timePaused;
  1617. if (YTPlayer !== undefined) {
  1618. YTPlayer.seekTo(timeIn / 1000);
  1619. }
  1620. }
  1621. }
  1622. },
  1623. "click #lock": function () {
  1624. console.log("Lock");
  1625. console.log(Session.get("privateRoomName"));
  1626. Meteor.call("lockPrivateRoom", Session.get("privateRoomName"));
  1627. },
  1628. "click #unlock": function () {
  1629. console.log("Unlock");
  1630. console.log(Session.get("privateRoomName"));
  1631. Meteor.call("unlockPrivateRoom", Session.get("privateRoomName"));
  1632. },
  1633. "click #submit": function () {
  1634. if(Meteor.userId()){
  1635. sendMessageGlobal();
  1636. Meteor.setTimeout(function () {
  1637. $("#chat-ul").scrollTop(100000);
  1638. }, 1000)
  1639. } else {
  1640. var $toastContent = $('<span>Message not sent. You must log in</span>');
  1641. Materialize.toast($toastContent, 2000);
  1642. }
  1643. },
  1644. "keyup #chat-message": function (e) {
  1645. if (e.type === "keyup" && e.which === 13) {
  1646. if(Meteor.userId()){
  1647. e.preventDefault();
  1648. if (!$('#chat-message').data('dropdownshown')) {
  1649. sendMessageGlobal();
  1650. Meteor.setTimeout(function () {
  1651. $("#chat-ul").scrollTop(100000);
  1652. }, 1000)
  1653. }
  1654. } else {
  1655. var $toastContent = $('<span>Message not sent. You must log in</span>');
  1656. Materialize.toast($toastContent, 2000);
  1657. }
  1658. }
  1659. },
  1660. "click #add-allowed-submit": function (e) {
  1661. if(Meteor.userId()){
  1662. e.preventDefault();
  1663. Meteor.call("addAllowedToPrivateRoom", Session.get("privateRoomName"), $("#add-allowed").val());
  1664. $("#add-allowed").val("");
  1665. } else {
  1666. var $toastContent = $('<span>User not added. You must log in</span>');
  1667. Materialize.toast($toastContent, 2000);
  1668. }
  1669. },
  1670. "keyup #add-allowed": function (e) {
  1671. if (e.type === "keyup" && e.which === 13) {
  1672. $("#add-allowed-submit").click();
  1673. }
  1674. },
  1675. "click #vote-skip": function () {
  1676. Meteor.call("votePrivateSkip", Session.get("privateRoomName"), function (err, res) {
  1677. $("#vote-skip").addClass("disabled");
  1678. if(err){
  1679. var $toastContent = $('<span><strong>Vote not submitted</strong> ' + err.reason + '</span>');
  1680. Materialize.toast($toastContent, 4000);
  1681. }
  1682. });
  1683. },
  1684. "click #volume-icon": function () {
  1685. var volume = 0;
  1686. var slider = $("#volume-slider").slider();
  1687. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
  1688. if (YTPlayer !== undefined) {
  1689. YTPlayer.setVolume(volume);
  1690. localStorage.setItem("volume", volume);
  1691. $("#volume-slider").slider("setValue", volume);
  1692. }
  1693. },
  1694. "click #play": function () {
  1695. Meteor.call("resumePrivateRoom", Session.get("privateRoomName"));
  1696. },
  1697. "click #pause": function () {
  1698. Meteor.call("pausePrivateRoom", Session.get("privateRoomName"));
  1699. },
  1700. "click #skip": function () {
  1701. Meteor.call("skipPrivateSong", Session.get("privateRoomName"));
  1702. },
  1703. "click #admin-dropdown a": function(){
  1704. Meteor.setTimeout(function(){
  1705. $(".dropdown-button").click();
  1706. }, 10);
  1707. },
  1708. "click .remove-allowed": function(e) {
  1709. var user = $(e.target).data("user");
  1710. if (user === undefined) {
  1711. user = $(e.target).parent().data("user");
  1712. }
  1713. Meteor.call("removeAllowedFromPrivateRoom", Session.get("privateRoomName"), user);
  1714. },
  1715. "click .edit-playlist-button": function(e) {
  1716. if ($(e.target).hasClass("edit-playlist-button")) {
  1717. Session.set("editingPlaylistName", $(e.target).data("playlist"));
  1718. }
  1719. },
  1720. "click #add_playlist_video_submit": function() {
  1721. var id = $("#add_playlist_video").val();
  1722. var pp = Session.get("editingPlaylistName");
  1723. Meteor.call("addVideoToPrivatePlaylist", pp, id);
  1724. $("#add_playlist_video").val("");
  1725. },
  1726. "click .remove_playlist_button": function(e) {
  1727. var id = $(e.target).data("id");
  1728. Meteor.call("removeVideoFromPrivatePlaylist", Session.get("editingPlaylistName"), id);
  1729. },
  1730. "click #delete_playlist": function() {
  1731. Meteor.call("deletePrivatePlaylist", Session.get("editingPlaylistName"));
  1732. $("#edit_playlist_modal").closeModal();
  1733. },
  1734. "click #create_playlist_submit": function() {
  1735. var name = $("#create_playlist_name").val();
  1736. var displayName = $("#create_playlist_display_name").val();
  1737. Meteor.call("createPrivatePlaylist", name, displayName);
  1738. $("#create_playlist_modal").closeModal();
  1739. $("#create_playlist_name").val("");
  1740. $("#create_playlist_display_name").val("");
  1741. setTimeout(function() {
  1742. $(".edit-playlist-button").leanModal({
  1743. dismissible: true,
  1744. opacity: .5,
  1745. in_duration: 500,
  1746. out_duration: 200
  1747. });
  1748. }, 500);
  1749. },
  1750. "click .select-playlist": function(e) {
  1751. e.preventDefault();
  1752. $("#edit_playlist_modal").closeModal();
  1753. var name = $(e.target).data("playlist");
  1754. Meteor.call("setPlaylistForPrivateRoom", Session.get("privateRoomName"), name);
  1755. }
  1756. });
  1757. Template.home.events({
  1758. "click #create_private_room_submit": function () {
  1759. var name = $("#create_private_room_name").val();
  1760. var displayName = $("#create_private_room_display_name").val();
  1761. var description = $("#create_private_room_description").val();
  1762. Meteor.call("createPrivateRoom", name, displayName, true, description);
  1763. $("#create_private_room_name").val("");
  1764. $("#create_private_room_display_name").val("");
  1765. $("#create_private_room_description").val("");
  1766. $("#create_private_room").closeModal();
  1767. }
  1768. });
  1769. // Settings Template
  1770. Template.settings.events({
  1771. "change #showRating": function() {
  1772. Meteor.call("updateSettings", $("#showRating").is(":checked"), function(){});
  1773. },
  1774. "click #delete-account": function(){
  1775. $("#delete-account").text("Click to confirm");
  1776. $("#delete-account").click(function(){
  1777. var bool = confirm("Are you sure you want to delete your account?");
  1778. if(bool) {
  1779. Meteor.call("deleteAccount");
  1780. } else{
  1781. $("#delete-account").text("Delete");
  1782. }
  1783. })
  1784. },
  1785. "click #change-password": function(){
  1786. var oldPassword = $("#old-password").val();
  1787. var newPassword= $("#new-password").val();
  1788. var confirmPassword = $("#confirm-password").val();
  1789. if(newPassword === confirmPassword){
  1790. Accounts.changePassword(oldPassword, newPassword, function(err){
  1791. if(err){
  1792. $("#old-password").val("");
  1793. $("#new-password").val("");
  1794. $("#confirm-password").val("");
  1795. $("<div class='alert alert-danger alert-dismissible' role='alert' style='margin-bottom: 0'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'><i class='fa fa-times'></i></span></button><strong>Oh Snap! </strong>" + err.reason + "</div>").prependTo($("#head")).delay(7000).fadeOut(1000, function() { $(this).remove(); });
  1796. } else {
  1797. $("#old-password").val("");
  1798. $("#new-password").val("");
  1799. $("#confirm-password").val("");
  1800. $("<div class='alert alert-success alert-dismissible' role='alert' style='margin-bottom: 0'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'><i class='fa fa-times'></i></span></button><strong>Hooray!</strong> You changed your password successfully.</div>").prependTo($("#head")).delay(7000).fadeOut(1000, function() { $(this).remove(); });
  1801. }
  1802. });
  1803. }
  1804. }
  1805. });
  1806. var previewEndSongTimeout = undefined;