1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00

Fix: Deleting a QualityProfile will now remove it from the view.

Java script moved to a separate file so it can be debugged.
This commit is contained in:
Mark McDowall 2012-01-30 23:19:52 -08:00
parent 26adbf2602
commit 9c5efdb3b4
4 changed files with 130 additions and 126 deletions

View File

@ -380,6 +380,7 @@
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
<Content Include="Scripts\NzbDrone\addSeries.js" />
<Content Include="Scripts\NzbDrone\AutoComplete.js" />
<Content Include="Scripts\NzbDrone\qualitySettings.js" />
<Content Include="Scripts\NzbDrone\grid.js" />
<Content Include="Scripts\NzbDrone\settings.js" />
<Content Include="Scripts\NzbDrone\localSearch.js" />

View File

@ -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($('\<option\> \</option\>').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')) {
$('<option>' + name + '</option>').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);
});
}

View File

@ -15,4 +15,5 @@
@section Scripts{
@Html.IncludeScript("NzbDrone/settings.js")
@Html.IncludeScript("NzbDrone/qualitySettings.js")
}

View File

@ -94,135 +94,10 @@
</div>
@section Scripts{
@Html.IncludeScript("MicrosoftAjax.js")
<script type="text/javascript">
var deleteQualityProfileUrl = '@Url.Action("DeleteQualityProfile", "Settings")';
$('.quality-selectee').livequery(function () {
$(this).button();
});
$(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);
}
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($('\<option\> \</option\>').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')) {
$('<option>' + name + '</option>').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);
});
}
</script>
}