Handlebars.registerHelper('if_eq', function (a, b, opts) { if (a == b) return !opts ? null : opts.fn(this); else return !opts ? null : opts.inverse(this); }); var searchSource = $("#search-template").html(); var albumSource = $("#album-template").html(); var searchTemplate = Handlebars.compile(searchSource); var albumTemplate = Handlebars.compile(albumSource); var movieTimer = 0; var tvimer = 0; var base = $('#baseUrl').text(); var tvLoaded = false; var albumLoaded = false; var mixItUpDefault = { animation: { enable: true }, load: { filter: 'all', sort: 'requestorder:desc' }, layout: { display: 'block' }, callbacks: { onMixStart: function (state, futureState) { $('.mix', this).removeAttr('data-bound').removeData('bound'); // fix for animation issues in other tabs } } }; initLoad(); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var target = $(e.target).attr('href'); var activeState = ""; var $ml = $('#movieList'); var $tvl = $('#tvList'); var $musicL = $('#musicList'); $('.approve-category,.delete-category').hide(); if (target === "#TvShowTab") { if (!tvLoaded) { tvLoaded = true; tvLoad(); } $('#approveTVShows,#deleteTVShows').show(); if ($ml.mixItUp('isLoaded')) { activeState = $ml.mixItUp('getState'); $ml.mixItUp('destroy'); } if ($musicL.mixItUp('isLoaded')) { activeState = $musicL.mixItUp('getState'); $musicL.mixItUp('destroy'); } //if ($tvl.mixItUp('isLoaded')) $tvl.mixItUp('destroy'); //$tvl.mixItUp(mixItUpConfig(activeState)); // init or reinit } if (target === "#MoviesTab") { $('#approveMovies,#deleteMovies').show(); if ($tvl.mixItUp('isLoaded')) { activeState = $tvl.mixItUp('getState'); $tvl.mixItUp('destroy'); } if ($musicL.mixItUp('isLoaded')) { activeState = $musicL.mixItUp('getState'); $musicL.mixItUp('destroy'); } if ($ml.mixItUp('isLoaded')) $ml.mixItUp('destroy'); $ml.mixItUp(mixItUpConfig(activeState)); // init or reinit } if (target === "#MusicTab") { if (!albumLoaded) { albumLoaded = true; albumLoad(); } $('#approveMusic,#deleteMusic').show(); if ($tvl.mixItUp('isLoaded')) { activeState = $tvl.mixItUp('getState'); $tvl.mixItUp('destroy'); } if ($ml.mixItUp('isLoaded')) { activeState = $ml.mixItUp('getState'); $ml.mixItUp('destroy'); } if ($musicL.mixItUp('isLoaded')) $musicL.mixItUp('destroy'); $musicL.mixItUp(mixItUpConfig(activeState)); // init or reinit } }); // Approve all $('#approveMovies').click(function (e) { e.preventDefault(); var buttonId = e.target.id; var origHtml = $(this).html(); if ($('#' + buttonId).text() === " Loading...") { return; } loadingButton(buttonId, "success"); var url = createBaseUrl(base, '/approval/approveallmovies'); $.ajax({ type: 'post', url: url, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! All Movie requests approved!", "success"); movieLoad(); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); }, complete: function (e) { finishLoading(buttonId, "success", origHtml); } }); }); $('#approveTVShows').click(function (e) { e.preventDefault(); var buttonId = e.target.id; var origHtml = $(this).html(); if ($('#' + buttonId).text() === " Loading...") { return; } loadingButton(buttonId, "warning"); var url = createBaseUrl(base, '/approval/approvealltvshows'); $.ajax({ type: 'post', url: url, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! All TV Show requests approved!", "success"); tvLoad(); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); }, complete: function (e) { finishLoading(buttonId, "warning", origHtml); } }); }); $('#deleteMovies').click(function (e) { e.preventDefault(); if (!confirm("Are you sure you want to delete all Movie requests?")) return; var buttonId = e.target.id; var origHtml = $(this).html(); if ($('#' + buttonId).text() === " Loading...") { return; } loadingButton(buttonId, "warning"); var url = createBaseUrl(base, '/approval/deleteallmovies'); $.ajax({ type: 'post', url: url, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! All Movie requests deleted!", "success"); movieLoad(); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); }, complete: function (e) { finishLoading(buttonId, "warning", origHtml); } }); }); $('#deleteTVShows').click(function (e) { e.preventDefault(); if (!confirm("Are you sure you want to delete all TV show requests?")) return; var buttonId = e.target.id; var origHtml = $(this).html(); if ($('#' + buttonId).text() === " Loading...") { return; } loadingButton(buttonId, "warning"); var url = createBaseUrl(base, '/approval/deletealltvshows'); $.ajax({ type: 'post', url: url, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! All TV Show requests deleted!", "success"); tvLoad(); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); }, complete: function (e) { finishLoading(buttonId, "success", origHtml); } }); }); $('#deleteMusic').click(function (e) { e.preventDefault(); if (!confirm("Are you sure you want to delete all album requests?")) return; var buttonId = e.target.id; var origHtml = $(this).html(); if ($('#' + buttonId).text() === " Loading...") { return; } loadingButton(buttonId, "warning"); var url = createBaseUrl(base, '/approval/deletealltvshows'); $.ajax({ type: 'post', url: url, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! All TV Show requests deleted!", "success"); tvLoad(); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); }, complete: function (e) { finishLoading(buttonId, "success", origHtml); } }); }); // filtering/sorting $('.filter,.sort', '.dropdown-menu').click(function (e) { var $this = $(this); $('.fa-check-square', $this.parents('.dropdown-menu:first')).removeClass('fa-check-square').addClass('fa-square-o'); $this.children('.fa').first().removeClass('fa-square-o').addClass('fa-check-square'); }); // Report Issue $(document).on("click", ".dropdownIssue", function (e) { var issue = $(this).attr("issue-select"); var id = e.target.id; // Other issue so the modal is opening if (issue == 4) { return; } e.preventDefault(); var $form = $('#report' + id); var data = $form.serialize(); data = data + "&issue=" + issue; $.ajax({ type: $form.prop('method'), url: $form.prop('action'), data: data, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! Added Issue.", "success"); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); } }); }); // Modal click $(".theSaveButton").click(function (e) { var comment = $("#commentArea").val(); e.preventDefault(); var $form = $("#commentForm"); var data = $form.serialize(); data = data + "&issue=" + 4 + "&comment=" + comment; $.ajax({ type: $form.prop("method"), url: $form.prop("action"), data: data, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! Added Issue.", "success"); $("#myModal").modal("hide"); } }, error: function (e) { console.log(e); generateNotify("Something went wrong!", "danger"); } }); }); // Note Modal click $(".theNoteSaveButton").click(function (e) { var comment = $("#noteArea").val(); e.preventDefault(); var $form = $("#noteForm"); var data = $form.serialize(); $.ajax({ type: $form.prop("method"), url: $form.prop("action"), data: data, dataType: "json", success: function (response) { if (checkJsonResponse(response)) { generateNotify("Success! Added Note.", "success"); $("#myModal").modal("hide"); $('#adminNotesArea' + e.target.value).html("