diff --git a/PlexRequests.UI/Content/requests.js b/PlexRequests.UI/Content/requests-1.7.js similarity index 96% rename from PlexRequests.UI/Content/requests.js rename to PlexRequests.UI/Content/requests-1.7.js index b3a820cf4..96b7ae4da 100644 --- a/PlexRequests.UI/Content/requests.js +++ b/PlexRequests.UI/Content/requests-1.7.js @@ -1,561 +1,561 @@ -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 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').hide(); - if (target === "#TvShowTab") { - $('#approveTVShows').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').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") { - $('#approveMusic').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, "success"); - 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, "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("
Note from Admin: " + comment + "
"); - } - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); -}); - -// Update the modal -$('#myModal').on('show.bs.modal', function (event) { - var button = $(event.relatedTarget); // Button that triggered the modal - var id = button.data('identifier'); // Extract info from data-* attributes - - var modal = $(this); - modal.find('.theSaveButton').val(id); // Add ID to the button - var requestField = modal.find('input'); - requestField.val(id); // Add ID to the hidden field -}); - -// Update the note modal -$('#noteModal').on('show.bs.modal', function (event) { - var button = $(event.relatedTarget); // Button that triggered the modal - var id = button.data('identifier'); // Extract info from data-* attributes - - var modal = $(this); - modal.find('.theNoteSaveButton').val(id); // Add ID to the button - var requestField = modal.find('.noteId'); - requestField.val(id); // Add ID to the hidden field -}); - -// Delete -$(document).on("click", ".delete", function (e) { - e.preventDefault(); - var buttonId = e.target.id; - var $form = $('#delete' + buttonId); - - $.ajax({ - type: $form.prop('method'), - url: $form.prop('action'), - data: $form.serialize(), - dataType: "json", - success: function (response) { - - if (checkJsonResponse(response)) { - generateNotify("Success! Request Deleted.", "success"); - - $("#" + buttonId + "Template").slideUp(); - } - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); - -}); - -// Approve single request -$(document).on("click", ".approve", function (e) { - e.preventDefault(); - var $this = $(this); - var $form = $this.parents('form').first(); - - if ($this.text() === " Loading...") { - return; - } - - loadingButton($this.attr('id'), "success"); - - approveRequest($form, null, function () { - $("#" + $this.attr('id') + "notapproved").prop("class", "fa fa-check"); - - var $group = $this.parent('.btn-split'); - if ($group.length > 0) { - $group.remove(); - } - else { - $this.remove(); - } - }); -}); - -$(document).on("click", ".approve-with-quality", function (e) { - e.preventDefault(); - var $this = $(this); - var $button = $this.parents('.btn-split').children('.approve').first(); - var qualityId = e.target.id - var $form = $this.parents('form').first(); - - if ($button.text() === " Loading...") { - return; - } - - loadingButton($button.attr('id'), "success"); - - approveRequest($form, qualityId, function () { - $("#" + $button.attr('id') + "notapproved").prop("class", "fa fa-check"); - $this.parents('.btn-split').remove(); - }); - -}); - -// Clear issues -$(document).on("click", ".clear", function (e) { - e.preventDefault(); - var buttonId = e.target.id; - var $form = $('#clear' + buttonId); - - $.ajax({ - type: $form.prop('method'), - url: $form.prop('action'), - data: $form.serialize(), - dataType: "json", - success: function (response) { - - if (checkJsonResponse(response)) { - generateNotify("Success! Issues Cleared.", "info"); - $('#issueArea' + buttonId).html("
Issue: None
"); - } - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); - -}); - -// Change Availability -$(document).on("click", ".change", function (e) { - e.preventDefault(); - var buttonId = e.target.id; - - var availablity = $("button[custom-availibility='" + buttonId + "']").val(); - var $form = $('#change' + buttonId); - var data = $form.serialize(); - data = data + "&Available=" + availablity; - - $.ajax({ - type: $form.prop('method'), - url: $form.prop('action'), - data: data, - dataType: "json", - success: function (response) { - - if (checkJsonResponse(response)) { - generateNotify("Success! Availibility changed.", "info"); - var button = $("button[custom-availibility='" + buttonId + "']"); - var icon = $('#availableIcon' + buttonId); - var approvedIcon = $("#"+buttonId + "notapproved"); - - if (response.available) { - button.text("Mark Unavailable"); - button.val("false"); - button.prop("class", "btn btn-sm btn-info-outline change"); - icon.prop("class", "fa fa-check"); - approvedIcon.prop("class", "fa fa-check"); - - } else { - button.text("Mark Available"); - button.prop("class", "btn btn-sm btn-success-outline change"); - icon.prop("class", "fa fa-times"); - approvedIcon.prop("class", "fa fa-times"); - button.val("true"); - } - } - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); - -}); - -function approveRequest($form, qualityId, successCallback) { - - var formData = $form.serialize(); - if (qualityId) formData += ("&qualityId=" + qualityId); - - $.ajax({ - type: $form.prop('method'), - url: $form.prop('action'), - data: formData, - dataType: "json", - success: function (response) { - - if (checkJsonResponse(response)) { - if (response.message) { - generateNotify(response.message, "success"); - } else { - generateNotify("Success! Request Approved.", "success"); - } - - if (successCallback) { - successCallback(); - } - } - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); -} - -function mixItUpConfig(activeState) { - var conf = mixItUpDefault; - - if (activeState) { - if (activeState.activeFilter) conf['load']['filter'] = activeState.activeFilter; - if (activeState.activeSort) conf['load']['sort'] = activeState.activeSort; - } - return conf; -}; - -function initLoad() { - movieLoad(); - tvLoad(); - albumLoad(); -} - -function movieLoad() { - var $ml = $('#movieList'); - if ($ml.mixItUp('isLoaded')) { - activeState = $ml.mixItUp('getState'); - $ml.mixItUp('destroy'); - } - $ml.html(""); - - var url = createBaseUrl(base, '/requests/movies'); - $.ajax(url).success(function (results) { - if (results.length > 0) { - results.forEach(function (result) { - var context = buildRequestContext(result, "movie"); - var html = searchTemplate(context); - $ml.append(html); - }); - } - else { - $ml.html(noResultsHtml.format("movie")); - } - $ml.mixItUp(mixItUpConfig()); - }); -}; - -function tvLoad() { - var $tvl = $('#tvList'); - if ($tvl.mixItUp('isLoaded')) { - activeState = $tvl.mixItUp('getState'); - $tvl.mixItUp('destroy'); - } - $tvl.html(""); - var url = createBaseUrl(base, '/requests/tvshows'); - $.ajax(url).success(function (results) { - if (results.length > 0) { - results.forEach(function (result) { - var context = buildRequestContext(result, "tv"); - var html = searchTemplate(context); - $tvl.append(html); - }); - } - else { - $tvl.html(noResultsHtml.format("tv show")); - } - $tvl.mixItUp(mixItUpConfig()); - }); -}; - -function albumLoad() { - var $albumL = $('#musicList'); - if ($albumL.mixItUp('isLoaded')) { - activeState = $albumL.mixItUp('getState'); - $albumL.mixItUp('destroy'); - } - $albumL.html(""); - var url = createBaseUrl(base, '/requests/albums'); - $.ajax(url).success(function (results) { - if (results.length > 0) { - results.forEach(function (result) { - var context = buildRequestContext(result, "album"); - var html = albumTemplate(context); - $albumL.append(html); - }); - } - else { - $albumL.html(noResultsMusic.format("albums")); - } - $albumL.mixItUp(mixItUpConfig()); - }); -}; - -// Builds the request context. -function buildRequestContext(result, type) { - var context = { - posterPath: result.posterPath, - id: result.providerId, - title: result.title, - overview: result.overview, - year: result.releaseYear, - type: type, - status: result.status, - releaseDate: Humanize(result.releaseDate), - releaseDateTicks: result.releaseDateTicks, - approved: result.approved, - requestedUsers: result.requestedUsers ? result.requestedUsers.join(', ') : '', - requestedDate: Humanize(result.requestedDate), - requestedDateTicks: result.requestedDateTicks, - released: result.released, - available: result.available, - admin: result.admin, - issues: result.issues, - otherMessage: result.otherMessage, - requestId: result.id, - adminNote: result.adminNotes, - imdb: result.imdbId, - seriesRequested: result.tvSeriesRequestType, - coverArtUrl: result.coverArtUrl, - qualities: result.qualities, - hasQualities: result.qualities && result.qualities.length > 0, - artist: result.artistName, - musicBrainzId : result.musicBrainzId - }; - - return context; -} - +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 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').hide(); + if (target === "#TvShowTab") { + $('#approveTVShows').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').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") { + $('#approveMusic').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, "success"); + 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, "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("
Note from Admin: " + comment + "
"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); +}); + +// Update the modal +$('#myModal').on('show.bs.modal', function (event) { + var button = $(event.relatedTarget); // Button that triggered the modal + var id = button.data('identifier'); // Extract info from data-* attributes + + var modal = $(this); + modal.find('.theSaveButton').val(id); // Add ID to the button + var requestField = modal.find('input'); + requestField.val(id); // Add ID to the hidden field +}); + +// Update the note modal +$('#noteModal').on('show.bs.modal', function (event) { + var button = $(event.relatedTarget); // Button that triggered the modal + var id = button.data('identifier'); // Extract info from data-* attributes + + var modal = $(this); + modal.find('.theNoteSaveButton').val(id); // Add ID to the button + var requestField = modal.find('.noteId'); + requestField.val(id); // Add ID to the hidden field +}); + +// Delete +$(document).on("click", ".delete", function (e) { + e.preventDefault(); + var buttonId = e.target.id; + var $form = $('#delete' + buttonId); + + $.ajax({ + type: $form.prop('method'), + url: $form.prop('action'), + data: $form.serialize(), + dataType: "json", + success: function (response) { + + if (checkJsonResponse(response)) { + generateNotify("Success! Request Deleted.", "success"); + + $("#" + buttonId + "Template").slideUp(); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + +}); + +// Approve single request +$(document).on("click", ".approve", function (e) { + e.preventDefault(); + var $this = $(this); + var $form = $this.parents('form').first(); + + if ($this.text() === " Loading...") { + return; + } + + loadingButton($this.attr('id'), "success"); + + approveRequest($form, null, function () { + $("#" + $this.attr('id') + "notapproved").prop("class", "fa fa-check"); + + var $group = $this.parent('.btn-split'); + if ($group.length > 0) { + $group.remove(); + } + else { + $this.remove(); + } + }); +}); + +$(document).on("click", ".approve-with-quality", function (e) { + e.preventDefault(); + var $this = $(this); + var $button = $this.parents('.btn-split').children('.approve').first(); + var qualityId = e.target.id + var $form = $this.parents('form').first(); + + if ($button.text() === " Loading...") { + return; + } + + loadingButton($button.attr('id'), "success"); + + approveRequest($form, qualityId, function () { + $("#" + $button.attr('id') + "notapproved").prop("class", "fa fa-check"); + $this.parents('.btn-split').remove(); + }); + +}); + +// Clear issues +$(document).on("click", ".clear", function (e) { + e.preventDefault(); + var buttonId = e.target.id; + var $form = $('#clear' + buttonId); + + $.ajax({ + type: $form.prop('method'), + url: $form.prop('action'), + data: $form.serialize(), + dataType: "json", + success: function (response) { + + if (checkJsonResponse(response)) { + generateNotify("Success! Issues Cleared.", "info"); + $('#issueArea' + buttonId).html("
Issue: None
"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + +}); + +// Change Availability +$(document).on("click", ".change", function (e) { + e.preventDefault(); + var buttonId = e.target.id; + + var availablity = $("button[custom-availibility='" + buttonId + "']").val(); + var $form = $('#change' + buttonId); + var data = $form.serialize(); + data = data + "&Available=" + availablity; + + $.ajax({ + type: $form.prop('method'), + url: $form.prop('action'), + data: data, + dataType: "json", + success: function (response) { + + if (checkJsonResponse(response)) { + generateNotify("Success! Availibility changed.", "info"); + var button = $("button[custom-availibility='" + buttonId + "']"); + var icon = $('#availableIcon' + buttonId); + var approvedIcon = $("#"+buttonId + "notapproved"); + + if (response.available) { + button.text("Mark Unavailable"); + button.val("false"); + button.prop("class", "btn btn-sm btn-info-outline change"); + icon.prop("class", "fa fa-check"); + approvedIcon.prop("class", "fa fa-check"); + + } else { + button.text("Mark Available"); + button.prop("class", "btn btn-sm btn-success-outline change"); + icon.prop("class", "fa fa-times"); + approvedIcon.prop("class", "fa fa-times"); + button.val("true"); + } + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + +}); + +function approveRequest($form, qualityId, successCallback) { + + var formData = $form.serialize(); + if (qualityId) formData += ("&qualityId=" + qualityId); + + $.ajax({ + type: $form.prop('method'), + url: $form.prop('action'), + data: formData, + dataType: "json", + success: function (response) { + + if (checkJsonResponse(response)) { + if (response.message) { + generateNotify(response.message, "success"); + } else { + generateNotify("Success! Request Approved.", "success"); + } + + if (successCallback) { + successCallback(); + } + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); +} + +function mixItUpConfig(activeState) { + var conf = mixItUpDefault; + + if (activeState) { + if (activeState.activeFilter) conf['load']['filter'] = activeState.activeFilter; + if (activeState.activeSort) conf['load']['sort'] = activeState.activeSort; + } + return conf; +}; + +function initLoad() { + movieLoad(); + tvLoad(); + albumLoad(); +} + +function movieLoad() { + var $ml = $('#movieList'); + if ($ml.mixItUp('isLoaded')) { + activeState = $ml.mixItUp('getState'); + $ml.mixItUp('destroy'); + } + $ml.html(""); + + var url = createBaseUrl(base, '/requests/movies'); + $.ajax(url).success(function (results) { + if (results.length > 0) { + results.forEach(function (result) { + var context = buildRequestContext(result, "movie"); + var html = searchTemplate(context); + $ml.append(html); + }); + } + else { + $ml.html(noResultsHtml.format("movie")); + } + $ml.mixItUp(mixItUpConfig()); + }); +}; + +function tvLoad() { + var $tvl = $('#tvList'); + if ($tvl.mixItUp('isLoaded')) { + activeState = $tvl.mixItUp('getState'); + $tvl.mixItUp('destroy'); + } + $tvl.html(""); + var url = createBaseUrl(base, '/requests/tvshows'); + $.ajax(url).success(function (results) { + if (results.length > 0) { + results.forEach(function (result) { + var context = buildRequestContext(result, "tv"); + var html = searchTemplate(context); + $tvl.append(html); + }); + } + else { + $tvl.html(noResultsHtml.format("tv show")); + } + $tvl.mixItUp(mixItUpConfig()); + }); +}; + +function albumLoad() { + var $albumL = $('#musicList'); + if ($albumL.mixItUp('isLoaded')) { + activeState = $albumL.mixItUp('getState'); + $albumL.mixItUp('destroy'); + } + $albumL.html(""); + var url = createBaseUrl(base, '/requests/albums'); + $.ajax(url).success(function (results) { + if (results.length > 0) { + results.forEach(function (result) { + var context = buildRequestContext(result, "album"); + var html = albumTemplate(context); + $albumL.append(html); + }); + } + else { + $albumL.html(noResultsMusic.format("albums")); + } + $albumL.mixItUp(mixItUpConfig()); + }); +}; + +// Builds the request context. +function buildRequestContext(result, type) { + var context = { + posterPath: result.posterPath, + id: result.providerId, + title: result.title, + overview: result.overview, + year: result.releaseYear, + type: type, + status: result.status, + releaseDate: Humanize(result.releaseDate), + releaseDateTicks: result.releaseDateTicks, + approved: result.approved, + requestedUsers: result.requestedUsers ? result.requestedUsers.join(', ') : '', + requestedDate: Humanize(result.requestedDate), + requestedDateTicks: result.requestedDateTicks, + released: result.released, + available: result.available, + admin: result.admin, + issues: result.issues, + otherMessage: result.otherMessage, + requestId: result.id, + adminNote: result.adminNotes, + imdb: result.imdbId, + seriesRequested: result.tvSeriesRequestType, + coverArtUrl: result.coverArtUrl, + qualities: result.qualities, + hasQualities: result.qualities && result.qualities.length > 0, + artist: result.artistName, + musicBrainzId : result.musicBrainzId + }; + + return context; +} + diff --git a/PlexRequests.UI/Content/search.js b/PlexRequests.UI/Content/search-1.7.js similarity index 95% rename from PlexRequests.UI/Content/search.js rename to PlexRequests.UI/Content/search-1.7.js index 7bbd54a63..96e6a3bd0 100644 --- a/PlexRequests.UI/Content/search.js +++ b/PlexRequests.UI/Content/search-1.7.js @@ -1,453 +1,462 @@ -Handlebars.registerHelper('if_eq', function (a, b, opts) { - if (a == b) - return opts.fn(this); - else - return opts.inverse(this); -}); - - - -$(function () { - - var searchSource = $("#search-template").html(); - var seasonsSource = $("#seasons-template").html(); - var musicSource = $("#music-template").html(); - var searchTemplate = Handlebars.compile(searchSource); - var musicTemplate = Handlebars.compile(musicSource); - var seasonsTemplate = Handlebars.compile(seasonsSource); - - var base = $('#baseUrl').text(); - - var searchTimer = 0; - - // fix for selecting a default tab - var $tabs = $('#nav-tabs').children('li'); - if ($tabs.filter(function (li) { return $(li).hasClass('active') }).length <= 0) { - $tabs.first().children('a:first-child').tab('show'); - } - - $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { - focusSearch($($(e.target).attr('href'))); - }); - focusSearch($('li.active a', '#nav-tabs').first().attr('href')); - - // Get the user notification setting - var url = createBaseUrl(base, '/search/notifyuser/'); - $.ajax({ - type: "get", - url: url, - dataType: "json", - success: function (response) { - $('#notifyUser').prop("checked", response); - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); - - // Type in movie search - $("#movieSearchContent").on("input", function () { - if (searchTimer) { - clearTimeout(searchTimer); - } - searchTimer = setTimeout(movieSearch, 400); - - }); - - $('#moviesComingSoon').on('click', function (e) { - e.preventDefault(); - moviesComingSoon(); - }); - - $('#moviesInTheaters').on('click', function (e) { - e.preventDefault(); - moviesInTheaters(); - }); - - // Type in TV search - $("#tvSearchContent").on("input", function () { - if (searchTimer) { - clearTimeout(searchTimer); - } - searchTimer = setTimeout(tvSearch, 400); - }); - - // Click TV dropdown option - $(document).on("click", ".dropdownTv", function (e) { - e.preventDefault(); - var buttonId = e.target.id; - if ($("#" + buttonId).attr('disabled')) { - return; - } - - $("#" + buttonId).prop("disabled", true); - loadingButton(buttonId, "primary"); - - - var $form = $('#form' + buttonId); - var data = $form.serialize(); - var seasons = $(this).attr("season-select"); - if (seasons === "2") { - // Send over the latest - data = data + "&seasons=latest"; - } - if (seasons === "1") { - // Send over the first season - data = data + "&seasons=first"; - } - - var type = $form.prop('method'); - var url = $form.prop('action'); - - sendRequestAjax(data, type, url, buttonId); - }); - - // Search Music - $("#musicSearchContent").on("input", function () { - if (searchTimer) { - clearTimeout(searchTimer); - } - searchTimer = setTimeout(musicSearch, 400); - - }); - - // Click Request for movie - $(document).on("click", ".requestMovie", function (e) { - e.preventDefault(); - var buttonId = e.target.id; - if ($("#" + buttonId).attr('disabled')) { - return; - } - - $("#" + buttonId).prop("disabled", true); - loadingButton(buttonId, "primary"); - - - var $form = $('#form' + buttonId); - - var type = $form.prop('method'); - var url = $form.prop('action'); - var data = $form.serialize(); - - sendRequestAjax(data, type, url, buttonId); - - }); - - // Click Request for album - $(document).on("click", ".requestAlbum", function (e) { - e.preventDefault(); - var buttonId = e.target.id; - if ($("#" + buttonId).attr('disabled')) { - return; - } - - $("#" + buttonId).prop("disabled", true); - loadingButton(buttonId, "primary"); - - - var $form = $('#form' + buttonId); - - var type = $form.prop('method'); - var url = $form.prop('action'); - var data = $form.serialize(); - - sendRequestAjax(data, type, url, buttonId); - }); - - // Enable/Disable user notifications - $('#saveNotificationSettings') - .click(function (e) { - e.preventDefault(); - var url = createBaseUrl(base, '/search/notifyuser/'); - var checked = $('#notifyUser').prop('checked'); - $.ajax({ - type: "post", - url: url, - data: { notify: checked }, - dataType: "json", - success: function (response) { - console.log(response); - if (response.result === true) { - generateNotify(response.message || "Success!", "success"); - } else { - generateNotify(response.message, "warning"); - } - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); - }); - - function focusSearch($content) { - if ($content.length > 0) { - $('input[type=text].form-control', $content).first().focus(); - } - } - - function sendRequestAjax(data, type, url, buttonId) { - $.ajax({ - type: type, - url: url, - data: data, - dataType: "json", - success: function (response) { - console.log(response); - if (response.result === true) { - generateNotify(response.message || "Success!", "success"); - - $('#' + buttonId).html(" Requested"); - $('#' + buttonId).removeClass("btn-primary-outline"); - $('#' + buttonId).removeAttr("data-toggle"); - $('#' + buttonId).addClass("btn-success-outline"); - } else { - generateNotify(response.message, "warning"); - $('#' + buttonId).html(" Request"); - $('#' + buttonId).attr("data-toggle", "dropdown"); - $("#" + buttonId).removeAttr("disabled"); - } - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); - } - - function movieSearch() { - var query = $("#movieSearchContent").val(); - var url = createBaseUrl(base, '/search/movie/'); - query ? getMovies(url + query) : resetMovies(); - } - - function moviesComingSoon() { - var url = createBaseUrl(base, '/search/movie/upcoming'); - getMovies(url); - } - - function moviesInTheaters() { - var url = createBaseUrl(base, '/search/movie/playing'); - getMovies(url); - } - - function getMovies(url) { - resetMovies(); - - $('#movieSearchButton').attr("class", "fa fa-spinner fa-spin"); - $.ajax(url).success(function (results) { - if (results.length > 0) { - results.forEach(function (result) { - var context = buildMovieContext(result); - - var html = searchTemplate(context); - $("#movieList").append(html); - }); - } - else { - $("#movieList").html(noResultsHtml); - } - $('#movieSearchButton').attr("class", "fa fa-search"); - }); - }; - - function resetMovies() { - $("#movieList").html(""); - } - - function tvSearch() { - var query = $("#tvSearchContent").val(); - - var url = createBaseUrl(base, '/search/tv/'); - query ? getTvShows(url + query) : resetTvShows(); - } - - function getTvShows(url) { - resetTvShows(); - - $('#tvSearchButton').attr("class", "fa fa-spinner fa-spin"); - $.ajax(url).success(function (results) { - if (results.length > 0) { - results.forEach(function (result) { - var context = buildTvShowContext(result); - var html = searchTemplate(context); - $("#tvList").append(html); - }); - } - else { - $("#tvList").html(noResultsHtml); - } - $('#tvSearchButton').attr("class", "fa fa-search"); - }); - }; - - function resetTvShows() { - $("#tvList").html(""); - } - - function musicSearch() { - var url = createBaseUrl(base, '/search/music/'); - var query = $("#musicSearchContent").val(); - query ? getMusic(url + query) : resetMusic(); - } - - function getMusic(url) { - resetMusic(); - - $('#musicSearchButton').attr("class", "fa fa-spinner fa-spin"); - $.ajax(url).success(function (results) { - if (results.length > 0) { - results.forEach(function (result) { - var context = buildMusicContext(result); - - var html = musicTemplate(context); - $("#musicList").append(html); - getCoverArt(context.id); - }); - } - else { - $("#musicList").html(noResultsMusic); - } - $('#musicSearchButton').attr("class", "fa fa-search"); - }); - }; - - function resetMusic() { - $("#musicList").html(""); - } - - function getCoverArt(artistId) { - - var url = createBaseUrl(base, '/search/music/coverart/'); - $.ajax(url + artistId).success(function (result) { - if (result) { - $('#' + artistId + "imageDiv").html(" poster"); - } - }); - }; - - function buildMovieContext(result) { - var date = new Date(result.releaseDate); - var year = date.getFullYear(); - var context = { - posterPath: result.posterPath, - id: result.id, - title: result.title, - overview: result.overview, - voteCount: result.voteCount, - voteAverage: result.voteAverage, - year: year, - type: "movie", - imdb: result.imdbId, - requested: result.requested, - approved: result.approved, - available: result.available - }; - - return context; - } - - function buildTvShowContext(result) { - var date = new Date(result.firstAired); - var year = date.getFullYear(); - var context = { - posterPath: result.banner, - id: result.id, - title: result.seriesName, - overview: result.overview, - year: year, - type: "tv", - imdb: result.imdbId, - requested: result.requested, - approved: result.approved, - available: result.available - }; - return context; - } - - function buildMusicContext(result) { - - var context = { - id: result.id, - title: result.title, - overview: result.overview, - year: result.releaseDate, - type: "album", - trackCount: result.trackCount, - coverArtUrl: result.coverArtUrl, - artist: result.artist, - releaseType: result.releaseType, - country: result.country, - requested: result.requested, - approved: result.approved, - available: result.available - }; - - return context; - } - - $('#seasonsModal').on('show.bs.modal', function (event) { - var button = $(event.relatedTarget); // Button that triggered the modal - var id = button.data('identifier'); // Extract info from data-* attributes - var url = createBaseUrl(base, '/search/seasons/'); - - $.ajax({ - type: "get", - url: url, - data: { tvId: id }, - dataType: "json", - success: function (results) { - var $content = $("#seasonsBody"); - $('#selectedSeasonsId').val(id); - results.forEach(function(result) { - var context = buildSeasonsContext(result); - $content.append(seasonsTemplate(context)); - }); - }, - error: function (e) { - console.log(e); - generateNotify("Something went wrong!", "danger"); - } - }); - - function buildSeasonsContext(result) { - var context = { - id: result - }; - return context; - }; - }); - - $('#seasonsRequest').click(function(e) { - e.preventDefault(); - var tvId = $('#selectedSeasonsId').val(); - var url = createBaseUrl(base, '/search/seasons/'); - - if ($("#" + tvId).attr('disabled')) { - return; - } - - $("#" + tvId).prop("disabled", true); - loadingButton(tvId, "primary"); - - - var $form = $('#form' + tvId); - var data = $form.serialize(); - var seasonsParam = "&seasons="; - - var testimonials = document.querySelectorAll('.selectedSeasons'); - Array.prototype.forEach.call(testimonials, function (elements, index) { - seasonsParam = seasonsParam + elements.text() + ","; - }); - - data = data + seasonsParam; - - var type = $form.prop('method'); - var url = $form.prop('action'); - - sendRequestAjax(data, type, url, tvId); - - }); - -}); +Handlebars.registerHelper('if_eq', function (a, b, opts) { + if (a == b) + return opts.fn(this); + else + return opts.inverse(this); +}); + + + +$(function () { + + var searchSource = $("#search-template").html(); + var seasonsSource = $("#seasons-template").html(); + var musicSource = $("#music-template").html(); + var searchTemplate = Handlebars.compile(searchSource); + var musicTemplate = Handlebars.compile(musicSource); + var seasonsTemplate = Handlebars.compile(seasonsSource); + + var base = $('#baseUrl').text(); + + var searchTimer = 0; + + // fix for selecting a default tab + var $tabs = $('#nav-tabs').children('li'); + if ($tabs.filter(function (li) { return $(li).hasClass('active') }).length <= 0) { + $tabs.first().children('a:first-child').tab('show'); + } + + $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + focusSearch($($(e.target).attr('href'))); + }); + focusSearch($('li.active a', '#nav-tabs').first().attr('href')); + + // Get the user notification setting + var url = createBaseUrl(base, '/search/notifyuser/'); + $.ajax({ + type: "get", + url: url, + dataType: "json", + success: function (response) { + $('#notifyUser').prop("checked", response); + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + + // Type in movie search + $("#movieSearchContent").on("input", function () { + if (searchTimer) { + clearTimeout(searchTimer); + } + searchTimer = setTimeout(movieSearch, 400); + + }); + + $('#moviesComingSoon').on('click', function (e) { + e.preventDefault(); + moviesComingSoon(); + }); + + $('#moviesInTheaters').on('click', function (e) { + e.preventDefault(); + moviesInTheaters(); + }); + + // Type in TV search + $("#tvSearchContent").on("input", function () { + if (searchTimer) { + clearTimeout(searchTimer); + } + searchTimer = setTimeout(tvSearch, 400); + }); + + // Click TV dropdown option + $(document).on("click", ".dropdownTv", function (e) { + e.preventDefault(); + var buttonId = e.target.id; + if ($("#" + buttonId).attr('disabled')) { + return; + } + + $("#" + buttonId).prop("disabled", true); + loadingButton(buttonId, "primary"); + + + var $form = $('#form' + buttonId); + var data = $form.serialize(); + var seasons = $(this).attr("season-select"); + if (seasons === "2") { + // Send over the latest + data = data + "&seasons=latest"; + } + if (seasons === "1") { + // Send over the first season + data = data + "&seasons=first"; + } if (seasons === "0") { + // Send over the first season + data = data + "&seasons=all"; + } + + var type = $form.prop('method'); + var url = $form.prop('action'); + + sendRequestAjax(data, type, url, buttonId); + }); + + // Search Music + $("#musicSearchContent").on("input", function () { + if (searchTimer) { + clearTimeout(searchTimer); + } + searchTimer = setTimeout(musicSearch, 400); + + }); + + // Click Request for movie + $(document).on("click", ".requestMovie", function (e) { + e.preventDefault(); + var buttonId = e.target.id; + if ($("#" + buttonId).attr('disabled')) { + return; + } + + $("#" + buttonId).prop("disabled", true); + loadingButton(buttonId, "primary"); + + + var $form = $('#form' + buttonId); + + var type = $form.prop('method'); + var url = $form.prop('action'); + var data = $form.serialize(); + + sendRequestAjax(data, type, url, buttonId); + + }); + + // Click Request for album + $(document).on("click", ".requestAlbum", function (e) { + e.preventDefault(); + var buttonId = e.target.id; + if ($("#" + buttonId).attr('disabled')) { + return; + } + + $("#" + buttonId).prop("disabled", true); + loadingButton(buttonId, "primary"); + + + var $form = $('#form' + buttonId); + + var type = $form.prop('method'); + var url = $form.prop('action'); + var data = $form.serialize(); + + sendRequestAjax(data, type, url, buttonId); + }); + + // Enable/Disable user notifications + $('#saveNotificationSettings') + .click(function (e) { + e.preventDefault(); + var url = createBaseUrl(base, '/search/notifyuser/'); + var checked = $('#notifyUser').prop('checked'); + $.ajax({ + type: "post", + url: url, + data: { notify: checked }, + dataType: "json", + success: function (response) { + console.log(response); + if (response.result === true) { + generateNotify(response.message || "Success!", "success"); + } else { + generateNotify(response.message, "warning"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + }); + + function focusSearch($content) { + if ($content.length > 0) { + $('input[type=text].form-control', $content).first().focus(); + } + } + + function sendRequestAjax(data, type, url, buttonId) { + $.ajax({ + type: type, + url: url, + data: data, + dataType: "json", + success: function (response) { + console.log(response); + if (response.result === true) { + generateNotify(response.message || "Success!", "success"); + + $('#' + buttonId).html(" Requested"); + $('#' + buttonId).removeClass("btn-primary-outline"); + $('#' + buttonId).removeAttr("data-toggle"); + $('#' + buttonId).addClass("btn-success-outline"); + } else { + generateNotify(response.message, "warning"); + $('#' + buttonId).html(" Request"); + $('#' + buttonId).attr("data-toggle", "dropdown"); + $("#" + buttonId).removeAttr("disabled"); + } + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + } + + function movieSearch() { + var query = $("#movieSearchContent").val(); + var url = createBaseUrl(base, '/search/movie/'); + query ? getMovies(url + query) : resetMovies(); + } + + function moviesComingSoon() { + var url = createBaseUrl(base, '/search/movie/upcoming'); + getMovies(url); + } + + function moviesInTheaters() { + var url = createBaseUrl(base, '/search/movie/playing'); + getMovies(url); + } + + function getMovies(url) { + resetMovies(); + + $('#movieSearchButton').attr("class", "fa fa-spinner fa-spin"); + $.ajax(url).success(function (results) { + if (results.length > 0) { + results.forEach(function (result) { + var context = buildMovieContext(result); + + var html = searchTemplate(context); + $("#movieList").append(html); + }); + } + else { + $("#movieList").html(noResultsHtml); + } + $('#movieSearchButton').attr("class", "fa fa-search"); + }); + }; + + function resetMovies() { + $("#movieList").html(""); + } + + function tvSearch() { + var query = $("#tvSearchContent").val(); + + var url = createBaseUrl(base, '/search/tv/'); + query ? getTvShows(url + query) : resetTvShows(); + } + + function getTvShows(url) { + resetTvShows(); + + $('#tvSearchButton').attr("class", "fa fa-spinner fa-spin"); + $.ajax(url).success(function (results) { + if (results.length > 0) { + results.forEach(function (result) { + var context = buildTvShowContext(result); + var html = searchTemplate(context); + $("#tvList").append(html); + }); + } + else { + $("#tvList").html(noResultsHtml); + } + $('#tvSearchButton').attr("class", "fa fa-search"); + }); + }; + + function resetTvShows() { + $("#tvList").html(""); + } + + function musicSearch() { + var url = createBaseUrl(base, '/search/music/'); + var query = $("#musicSearchContent").val(); + query ? getMusic(url + query) : resetMusic(); + } + + function getMusic(url) { + resetMusic(); + + $('#musicSearchButton').attr("class", "fa fa-spinner fa-spin"); + $.ajax(url).success(function (results) { + if (results.length > 0) { + results.forEach(function (result) { + var context = buildMusicContext(result); + + var html = musicTemplate(context); + $("#musicList").append(html); + getCoverArt(context.id); + }); + } + else { + $("#musicList").html(noResultsMusic); + } + $('#musicSearchButton').attr("class", "fa fa-search"); + }); + }; + + function resetMusic() { + $("#musicList").html(""); + } + + function getCoverArt(artistId) { + + var url = createBaseUrl(base, '/search/music/coverart/'); + $.ajax(url + artistId).success(function (result) { + if (result) { + $('#' + artistId + "imageDiv").html(" poster"); + } + }); + }; + + function buildMovieContext(result) { + var date = new Date(result.releaseDate); + var year = date.getFullYear(); + var context = { + posterPath: result.posterPath, + id: result.id, + title: result.title, + overview: result.overview, + voteCount: result.voteCount, + voteAverage: result.voteAverage, + year: year, + type: "movie", + imdb: result.imdbId, + requested: result.requested, + approved: result.approved, + available: result.available + }; + + return context; + } + + function buildTvShowContext(result) { + var date = new Date(result.firstAired); + var year = date.getFullYear(); + var context = { + posterPath: result.banner, + id: result.id, + title: result.seriesName, + overview: result.overview, + year: year, + type: "tv", + imdb: result.imdbId, + requested: result.requested, + approved: result.approved, + available: result.available + }; + return context; + } + + function buildMusicContext(result) { + + var context = { + id: result.id, + title: result.title, + overview: result.overview, + year: result.releaseDate, + type: "album", + trackCount: result.trackCount, + coverArtUrl: result.coverArtUrl, + artist: result.artist, + releaseType: result.releaseType, + country: result.country, + requested: result.requested, + approved: result.approved, + available: result.available + }; + + return context; + } + + $('#seasonsModal').on('show.bs.modal', function (event) { + var button = $(event.relatedTarget); // Button that triggered the modal + var id = button.data('identifier'); // Extract info from data-* attributes + var url = createBaseUrl(base, '/search/seasons/'); + + $.ajax({ + type: "get", + url: url, + data: { tvId: id }, + dataType: "json", + success: function (results) { + var $content = $("#seasonsBody"); + $content.html(""); + $('#selectedSeasonsId').val(id); + results.forEach(function(result) { + var context = buildSeasonsContext(result); + $content.append(seasonsTemplate(context)); + }); + }, + error: function (e) { + console.log(e); + generateNotify("Something went wrong!", "danger"); + } + }); + + function buildSeasonsContext(result) { + var context = { + id: result + }; + return context; + }; + }); + + $('#seasonsRequest').click(function(e) { + e.preventDefault(); + var tvId = $('#selectedSeasonsId').val(); + var url = createBaseUrl(base, '/search/seasons/'); + + if ($("#" + tvId).attr('disabled')) { + return; + } + + $("#" + tvId).prop("disabled", true); + loadingButton(tvId, "primary"); + + + var $form = $('#form' + tvId); + var data = $form.serialize(); + var seasonsParam = "&seasons="; + + var $checkedSeasons = $('.selectedSeasons:checkbox:checked'); + $checkedSeasons.each(function (index, element) { + if (index < $checkedSeasons.length -1) { + seasonsParam = seasonsParam + element.id + ","; + } else { + seasonsParam = seasonsParam + element.id; + } + }); + + + data = data + seasonsParam; + + var type = $form.prop('method'); + var url = $form.prop('action'); + + sendRequestAjax(data, type, url, tvId); + + }); + +}); diff --git a/PlexRequests.UI/Content/site.js b/PlexRequests.UI/Content/site-1.7.js similarity index 96% rename from PlexRequests.UI/Content/site.js rename to PlexRequests.UI/Content/site-1.7.js index e08d5835d..4887b10b0 100644 --- a/PlexRequests.UI/Content/site.js +++ b/PlexRequests.UI/Content/site-1.7.js @@ -1,79 +1,79 @@ -String.prototype.format = String.prototype.f = function () { - var s = this, - i = arguments.length; - - while (i--) { - s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); - } - return s; -} - -function Humanize(date) { - var mNow = moment(); - var mDate = moment(date).local(); - return moment.duration(mNow - mDate).humanize() + (mNow.isBefore(mDate) ? ' from now' : ' ago'); -} - -function generateNotify(message, type) { - // type = danger, warning, info, successs - $.notify({ - // options - message: message - }, { - // settings - type: type, - animate: { - enter: 'animated bounceInDown', - exit: 'animated bounceOutUp' - }, - newest_on_top: true - - }); -} - -function checkJsonResponse(response) { - if (response.result === true) { - return true; - } else { - generateNotify(response.message, "warning"); - return false; - } -} - -function loadingButton(elementId, originalCss) { - var $element = $('#' + elementId); - $element.removeClass("btn-" + originalCss + "-outline").addClass("btn-primary-outline").addClass('disabled').html(" Loading..."); - - // handle split-buttons - var $dropdown = $element.next('.dropdown-toggle') - if ($dropdown.length > 0) { - $dropdown.removeClass("btn-" + originalCss + "-outline").addClass("btn-primary-outline").addClass('disabled'); - } -} - -function finishLoading(elementId, originalCss, html) { - var $element = $('#' + elementId); - $element.removeClass("btn-primary-outline").removeClass('disabled').addClass("btn-" + originalCss + "-outline").html(html); - - // handle split-buttons - var $dropdown = $element.next('.dropdown-toggle') - if ($dropdown.length > 0) { - $dropdown.removeClass("btn-primary-outline").removeClass('disabled').addClass("btn-" + originalCss + "-outline"); - } -} - -function createBaseUrl(base, url) { - if (base) { - if (url.charAt(0) === "/") { - url = "/" + base + url; - } else { - url = "/" + base + "/" + url; - } - } - return url; -} - -var noResultsHtml = "
" + - "
Sorry, we didn't find any results!
"; -var noResultsMusic = "
" + +String.prototype.format = String.prototype.f = function () { + var s = this, + i = arguments.length; + + while (i--) { + s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); + } + return s; +} + +function Humanize(date) { + var mNow = moment(); + var mDate = moment(date).local(); + return moment.duration(mNow - mDate).humanize() + (mNow.isBefore(mDate) ? ' from now' : ' ago'); +} + +function generateNotify(message, type) { + // type = danger, warning, info, successs + $.notify({ + // options + message: message + }, { + // settings + type: type, + animate: { + enter: 'animated bounceInDown', + exit: 'animated bounceOutUp' + }, + newest_on_top: true + + }); +} + +function checkJsonResponse(response) { + if (response.result === true) { + return true; + } else { + generateNotify(response.message, "warning"); + return false; + } +} + +function loadingButton(elementId, originalCss) { + var $element = $('#' + elementId); + $element.removeClass("btn-" + originalCss + "-outline").addClass("btn-primary-outline").addClass('disabled').html(" Loading..."); + + // handle split-buttons + var $dropdown = $element.next('.dropdown-toggle') + if ($dropdown.length > 0) { + $dropdown.removeClass("btn-" + originalCss + "-outline").addClass("btn-primary-outline").addClass('disabled'); + } +} + +function finishLoading(elementId, originalCss, html) { + var $element = $('#' + elementId); + $element.removeClass("btn-primary-outline").removeClass('disabled').addClass("btn-" + originalCss + "-outline").html(html); + + // handle split-buttons + var $dropdown = $element.next('.dropdown-toggle') + if ($dropdown.length > 0) { + $dropdown.removeClass("btn-primary-outline").removeClass('disabled').addClass("btn-" + originalCss + "-outline"); + } +} + +function createBaseUrl(base, url) { + if (base) { + if (url.charAt(0) === "/") { + url = "/" + base + url; + } else { + url = "/" + base + "/" + url; + } + } + return url; +} + +var noResultsHtml = "
" + + "
Sorry, we didn't find any results!
"; +var noResultsMusic = "
" + "
Sorry, we didn't find any results!
"; \ No newline at end of file diff --git a/PlexRequests.UI/Helpers/BaseUrlHelper.cs b/PlexRequests.UI/Helpers/BaseUrlHelper.cs index f1af840c6..175f1f4c3 100644 --- a/PlexRequests.UI/Helpers/BaseUrlHelper.cs +++ b/PlexRequests.UI/Helpers/BaseUrlHelper.cs @@ -68,7 +68,7 @@ namespace PlexRequests.UI.Helpers sb.AppendLine($""); sb.AppendLine($""); sb.AppendLine($""); - sb.AppendLine($""); + sb.AppendLine($""); sb.AppendLine($""); sb.AppendLine($""); sb.AppendLine($""); @@ -84,7 +84,7 @@ namespace PlexRequests.UI.Helpers var content = GetContentUrl(assetLocation); - sb.AppendLine($""); + sb.AppendLine($""); return helper.Raw(sb.ToString()); } @@ -96,7 +96,7 @@ namespace PlexRequests.UI.Helpers var content = GetContentUrl(assetLocation); - sb.AppendLine($""); + sb.AppendLine($""); return helper.Raw(sb.ToString()); } diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 843ce6e70..01edd5264 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -47,6 +47,8 @@ using PlexRequests.Store; using PlexRequests.UI.Helpers; using PlexRequests.UI.Models; using System.Threading.Tasks; +using System.Windows.Forms; + using PlexRequests.Api.Models.Tv; using PlexRequests.Store.Models; using PlexRequests.Store.Repository; @@ -638,9 +640,20 @@ namespace PlexRequests.UI.Modules seasonsList.Add(model.SeasonCount); model.SeasonsRequested = "Latest"; break; - default: + case "all": model.SeasonsRequested = "All"; break; + default: + var split = seasons.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + var seasonsCount = new int[split.Length]; + for (var i = 0; i < split.Length; i++) + { + int tryInt; + int.TryParse(split[i], out tryInt); + seasonsCount[i] = tryInt; + } + seasonsList.AddRange(seasonsCount); + break; } model.SeasonList = seasonsList.ToArray(); diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 419471606..3e9703a4c 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -370,10 +370,10 @@ pace.css Always - + PreserveNewest - + PreserveNewest @@ -545,7 +545,7 @@ - + PreserveNewest diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index ce2769fdb..64f56a0ce 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -280,7 +280,7 @@