From 9c5efdb3b49601da2ca97f348aec231e89630432 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 30 Jan 2012 23:19:52 -0800 Subject: [PATCH] Fix: Deleting a QualityProfile will now remove it from the view. Java script moved to a separate file so it can be debugged. --- NzbDrone.Web/NzbDrone.Web.csproj | 1 + .../Scripts/NzbDrone/qualitySettings.js | 127 ++++++++++++++++++ NzbDrone.Web/Views/Settings/Index.cshtml | 1 + NzbDrone.Web/Views/Settings/Quality.cshtml | 127 +----------------- 4 files changed, 130 insertions(+), 126 deletions(-) create mode 100644 NzbDrone.Web/Scripts/NzbDrone/qualitySettings.js diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 711a65f64..b6a2e430f 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -380,6 +380,7 @@ + diff --git a/NzbDrone.Web/Scripts/NzbDrone/qualitySettings.js b/NzbDrone.Web/Scripts/NzbDrone/qualitySettings.js new file mode 100644 index 000000000..18ddd0a0e --- /dev/null +++ b/NzbDrone.Web/Scripts/NzbDrone/qualitySettings.js @@ -0,0 +1,127 @@ +var deleteQualityProfileUrl = '../../Settings/DeleteQualityProfile'; + +$(document).ready(function () { + setupSliders(); +}); + +$("#addItem").live('click', function () { + $.ajax({ + url: this.href, + cache: false, + success: function (html) { + $("#profiles").append(html); + + } + }); + return false; +}); + +function deleteProfile(id) { + sendToServer(id); + var profileDiv = '#profile_' + id; + $(profileDiv).remove(); +} + +function renameOption(text, value) { + $("#DefaultQualityProfileId option[value='" + value + "']").html(text); +} + +function addOption(text, value) { + var myCombo = $('#DefaultQualityProfileId'); + + var exists = $("#DefaultQualityProfileId option[value='" + value + "']"); + + if (exists.length == 0) + myCombo.append($('\ \').val(value).html(text)); +} + +function removeOption(value) { + $("#DefaultQualityProfileId option[value='" + value + "']").remove(); +} + +function sendToServer(id) { + $.ajax({ + type: "POST", + url: deleteQualityProfileUrl, + data: jQuery.param({ profileId: id }), + error: function (req, status, error) { + alert("Sorry! We could not delete your Profile at this time. " + error); + }, + success: function (data, textStatus, jqXHR) { + if (data == "ok") { + $("#profile_" + id).remove(); + removeOption(id); + } + + else { + alert(data); + } + } + }); +} + +function getProfileId(obj) { + var parentProfileSection = $(obj).parents('.profileSection'); + return parentProfileSection.children('.qualityProfileId').val(); +} + +function getCleanId(obj) { + var parentProfileSection = $(obj).parents('.profileSection'); + return parentProfileSection.children('.cleanId').val(); +} + +$(".profileName_textbox").live('keyup', function () { + var value = $(this).val(); + var profileId = getProfileId(this); + $("#title_" + profileId).text(value); + renameOption(value, profileId); +}).keyup(); + +$('.quality-selectee').live('click', function () { + var id = $(this).attr('id'); + var cleanId = getCleanId(this); + var cutoff = '#' + cleanId + '_Cutoff'; + var name = jQuery('[for="' + id + '"]').children('.ui-button-text').text(); + + //Remove 'Unknown' + $(cutoff + ' option').each(function () { if ($(this).text().indexOf('Unknown') > -1) $(cutoff + ' option').remove(':contains("' + $(this).text() + '")'); }); + + //Add option to cutoff SelectList + if ($(this).attr('checked')) { + $('').appendTo(cutoff); + } + + //Remove option from cutoff SelectList + else { + $(cutoff + ' option').each(function () { + if ($(this).text().indexOf(name) > -1) + $(cutoff + ' option').remove(':contains("' + $(this).text() + '")'); + }); + } +}); + +var sliderOptions = { + min: 0, + max: 200, + value: 0, + step: 1, + create: function (event, ui) { + var startingValue = $(this).siblings('.slider-value').val(); + $(this).siblings('.30-minute').text(startingValue * 30); + $(this).siblings('.60-minute').text(startingValue * 60); + }, + slide: function (event, ui) { + $(this).siblings('.slider-value').val(ui.value); + $(this).siblings('.30-minute').text(ui.value * 30); + $(this).siblings('.60-minute').text(ui.value * 60); + } +}; + +function setupSliders() { + $(".slider").each(function () { + var localOptions = sliderOptions; + localOptions["value"] = $(this).siblings('.slider-value').val(); + + $(this).empty().slider(localOptions); + }); +} \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Index.cshtml b/NzbDrone.Web/Views/Settings/Index.cshtml index 09c5b6ceb..599d69b53 100644 --- a/NzbDrone.Web/Views/Settings/Index.cshtml +++ b/NzbDrone.Web/Views/Settings/Index.cshtml @@ -15,4 +15,5 @@ @section Scripts{ @Html.IncludeScript("NzbDrone/settings.js") + @Html.IncludeScript("NzbDrone/qualitySettings.js") } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/Quality.cshtml b/NzbDrone.Web/Views/Settings/Quality.cshtml index 71fe9c0b4..2fa24df23 100644 --- a/NzbDrone.Web/Views/Settings/Quality.cshtml +++ b/NzbDrone.Web/Views/Settings/Quality.cshtml @@ -94,135 +94,10 @@ @section Scripts{ @Html.IncludeScript("MicrosoftAjax.js") + }