mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 01:23:53 -07:00
Quality type sizes moved to backbone + SS (API)
This commit is contained in:
parent
5ba1c0eceb
commit
c8621b8100
24 changed files with 244 additions and 356 deletions
|
@ -1,7 +1,7 @@
|
|||
$(document).ready(function () {
|
||||
|
||||
//All forms are ajax forms
|
||||
$("form").livequery(function () {
|
||||
$("form").livequery(function () {
|
||||
|
||||
var options = {
|
||||
type: 'post',
|
||||
|
@ -16,7 +16,6 @@
|
|||
$(this).removeAttr('disabled');
|
||||
});
|
||||
|
||||
|
||||
//All buttons are jQueryUI buttons
|
||||
$('button, input[type="button"], input[type="submit"], input[type="reset"]').livequery(function () {
|
||||
$(this).button();
|
||||
|
|
|
@ -1,80 +1,4 @@
|
|||
var deleteQualityProfileUrl = '../../Settings/DeleteQualityProfile';
|
||||
|
||||
$(document).on('click', '.delete-profile', function (e) {
|
||||
var container = $(this).closest('.profileSection');
|
||||
var id = $(container).attr('data-profile-id');
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: deleteQualityProfileUrl,
|
||||
data: jQuery.param({ profileId: id }),
|
||||
success: function (data, textStatus, jqXHR) {
|
||||
$(container).remove();
|
||||
removeOption(id);
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
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 getProfileId(obj) {
|
||||
var parentProfileSection = $(obj).closest('.profileSection');
|
||||
return parentProfileSection.attr('data-profile-id');
|
||||
}
|
||||
|
||||
function getCleanId(obj) {
|
||||
var parentProfileSection = $(obj).parents('.profileSection');
|
||||
return parentProfileSection.children('.cleanId').val();
|
||||
}
|
||||
|
||||
$(document).on('keyup', '.profileName_textbox', function () {
|
||||
var value = $(this).val();
|
||||
|
||||
$(this).closest('.profileSection').find('.titleText').text(value);
|
||||
var profileId = getProfileId(this);
|
||||
|
||||
renameOption(value, profileId);
|
||||
}).keyup();
|
||||
|
||||
$(document).on('click', '.quality-selectee', function () {
|
||||
var id = $(this).attr('id');
|
||||
var cleanId = getCleanId(this);
|
||||
var cutoff = '#' + cleanId + '_Cutoff';
|
||||
var name = jQuery('[for="' + id + '"]').children('.ui-button-text').text();
|
||||
var qualityId = $(this).attr('data-quality-id');
|
||||
|
||||
//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>').val(qualityId).appendTo(cutoff);
|
||||
}
|
||||
|
||||
//Remove option from cutoff SelectList
|
||||
else {
|
||||
$(cutoff).find('option[value="' + qualityId + '"]').remove();
|
||||
}
|
||||
});
|
||||
|
||||
var sliderOptions = {
|
||||
var sliderOptions = {
|
||||
min: 0,
|
||||
max: 200,
|
||||
value: 0,
|
||||
|
@ -88,14 +12,19 @@ var sliderOptions = {
|
|||
$(this).siblings('.slider-value').val(ui.value);
|
||||
$(this).siblings('.30-minute').text(ui.value * 30);
|
||||
$(this).siblings('.60-minute').text(ui.value * 60);
|
||||
},
|
||||
change: function (event, ui) {
|
||||
$(this).siblings('.slider-value').val(ui.value).trigger('change');
|
||||
}
|
||||
};
|
||||
|
||||
function setupSliders() {
|
||||
$(".slider").each(function () {
|
||||
var localOptions = sliderOptions;
|
||||
localOptions["value"] = $(this).siblings('.slider-value').val();
|
||||
$('.quality-selectee').livequery(function () {
|
||||
$(this).button();
|
||||
});
|
||||
|
||||
$(this).empty().slider(localOptions);
|
||||
});
|
||||
}
|
||||
$('.slider').livequery(function () {
|
||||
var localOptions = sliderOptions;
|
||||
localOptions["value"] = $(this).siblings('.slider-value').val();
|
||||
|
||||
$(this).empty().slider(localOptions);
|
||||
});
|
||||
|
|
19
NzbDrone.Web/Scripts/backbone/apps/qualityTypeApp.js
Normal file
19
NzbDrone.Web/Scripts/backbone/apps/qualityTypeApp.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
QualityTypeApp = {};
|
||||
|
||||
QualityTypeApp.Views = {};
|
||||
QualityTypeApp.Models = {};
|
||||
QualityTypeApp.Collections = {};
|
||||
|
||||
QualityTypeApp.App = new Backbone.Marionette.Application();
|
||||
|
||||
// Setup default application views
|
||||
QualityTypeApp.App.addInitializer(function () {
|
||||
|
||||
QualityTypeApp.App.addRegions({
|
||||
mainRegion: '#sliders'
|
||||
});
|
||||
|
||||
var qualityTypes = new QualityTypeCollectionView();
|
||||
|
||||
QualityTypeApp.App.mainRegion.show(qualityTypes);
|
||||
});
|
|
@ -1,7 +0,0 @@
|
|||
$(function () {
|
||||
// Legacy support for templating
|
||||
utils.loadTemplate(['QualityProfilesView', 'QualityProfileView'],
|
||||
function () {
|
||||
NzbDrone.App.start();
|
||||
});
|
||||
});
|
|
@ -3,4 +3,11 @@
|
|||
QualityProfileCollection: '#QualityProfileCollectionTemplate',
|
||||
QualityProfile: '#QualityProfileTemplate'
|
||||
},
|
||||
};
|
||||
|
||||
QualityTypeApp.Constants = {
|
||||
Templates: {
|
||||
QualityTypeCollection: '#QualityTypeCollectionTemplate',
|
||||
QualityType: '#QualityTypeTemplate'
|
||||
},
|
||||
};
|
|
@ -1,57 +0,0 @@
|
|||
(function (nzbDrone) {
|
||||
|
||||
var appController = function () {
|
||||
return {
|
||||
home: function (id) {
|
||||
|
||||
// if (!this.homeView) {
|
||||
// this.homeView = new HomeView();
|
||||
// }
|
||||
// $('#content').html(this.homeView.el);
|
||||
|
||||
nzbDrone.App.Layout.content.show(new nzbDrone.Views.HomeView());
|
||||
|
||||
this.menuItemSelected('home-menu');
|
||||
},
|
||||
|
||||
list: function (page) {
|
||||
|
||||
var p = page ? parseInt(page, 10) : 1;
|
||||
var profileList = new ProfileCollection();
|
||||
profileList.fetch({
|
||||
success: function () {
|
||||
$('#content').html(new QualityProfilesView({ model: profileList, page: p }).el);
|
||||
}
|
||||
});
|
||||
this.menuItemSelected('home-menu');
|
||||
},
|
||||
|
||||
wineDetails: function (id) {
|
||||
var profile = new Profile({ id: id });
|
||||
profile.fetch({
|
||||
success: function () {
|
||||
$('#content').html(new QualityProfileView({ model: profile }).el);
|
||||
}
|
||||
});
|
||||
this.menuItemSelected();
|
||||
},
|
||||
|
||||
addWine: function () {
|
||||
var wine = new Profile();
|
||||
$('#content').html(new QualityProfileView({ model: wine }).el);
|
||||
this.menuItemSelected('add-menu');
|
||||
},
|
||||
|
||||
menuItemSelected: function (item) {
|
||||
|
||||
// Using the application vent object as our global event aggregator
|
||||
nzbDrone.App.vent.trigger(
|
||||
nzbDrone.Constants.Events.MenuItemSelected, // Event name
|
||||
item); // Options
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
nzbDrone.AppController = appController;
|
||||
|
||||
})(window.NodeCellar);
|
38
NzbDrone.Web/Scripts/backbone/models/qualityType.js
Normal file
38
NzbDrone.Web/Scripts/backbone/models/qualityType.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
window.QualityType = Backbone.Model.extend({
|
||||
|
||||
urlRoot: '/api/qualitytypes',
|
||||
|
||||
idAttribute: 'Id',
|
||||
|
||||
initialize: function () {
|
||||
this.validators = {};
|
||||
},
|
||||
|
||||
validateItem: function (key) {
|
||||
return (this.validators[key]) ? this.validators[key](this.get(key)) : { isValid: true };
|
||||
},
|
||||
|
||||
// TODO: Implement Backbone's standard validate() method instead.
|
||||
validateAll: function () {
|
||||
|
||||
var messages = {};
|
||||
|
||||
for (var key in this.validators) {
|
||||
if (this.validators.hasOwnProperty(key)) {
|
||||
var check = this.validators[key](this.get(key));
|
||||
if (check.isValid === false) {
|
||||
messages[key] = check.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _.size(messages) > 0 ? { isValid: false, messages: messages } : { isValid: true };
|
||||
},
|
||||
|
||||
defaults: {
|
||||
Id: null,
|
||||
Name: '',
|
||||
MaxSize: 100,
|
||||
MinSize: 0
|
||||
}
|
||||
});
|
|
@ -0,0 +1,4 @@
|
|||
window.QualityTypeCollection = Backbone.Collection.extend({
|
||||
model: QualityType,
|
||||
url: '/api/qualitytypes'
|
||||
});
|
|
@ -1,53 +0,0 @@
|
|||
window.utils = {
|
||||
|
||||
// Asynchronously load templates located in separate .html files
|
||||
loadTemplate: function (views, callback) {
|
||||
|
||||
var deferreds = [];
|
||||
|
||||
$.each(views, function (index, view) {
|
||||
if (window[view]) {
|
||||
deferreds.push($.get('tpl/' + view + '.html', function (data) {
|
||||
window[view].prototype.template = _.template(data);
|
||||
}));
|
||||
} else {
|
||||
alert(view + ' not found');
|
||||
}
|
||||
});
|
||||
|
||||
$.when.apply(null, deferreds).done(callback);
|
||||
},
|
||||
|
||||
displayValidationErrors: function (messages) {
|
||||
for (var key in messages) {
|
||||
if (messages.hasOwnProperty(key)) {
|
||||
this.addValidationError(key, messages[key]);
|
||||
}
|
||||
}
|
||||
this.showAlert('Warning!', 'Fix validation errors and try again', 'alert-warning');
|
||||
},
|
||||
|
||||
addValidationError: function (field, message) {
|
||||
var controlGroup = $('#' + field).parent().parent();
|
||||
controlGroup.addClass('error');
|
||||
$('.help-inline', controlGroup).html(message);
|
||||
},
|
||||
|
||||
removeValidationError: function (field) {
|
||||
var controlGroup = $('#' + field).parent().parent();
|
||||
controlGroup.removeClass('error');
|
||||
$('.help-inline', controlGroup).html('');
|
||||
},
|
||||
|
||||
showAlert: function (title, text, klass) {
|
||||
$('.alert').removeClass('alert-error alert-warning alert-success alert-info');
|
||||
$('.alert').addClass(klass);
|
||||
$('.alert').html('<strong>' + title + '</strong> ' + text);
|
||||
$('.alert').show();
|
||||
},
|
||||
|
||||
hideAlert: function () {
|
||||
$('.alert').hide();
|
||||
}
|
||||
|
||||
};
|
|
@ -107,15 +107,15 @@ QualityProfileCollectionView = Backbone.Marionette.CompositeView.extend({
|
|||
//Todo: Need to get the default profile from the server, instead of creating it manually...
|
||||
var newProfile = new QualityProfile({
|
||||
Name: '', Cutoff: 0, Qualities: [
|
||||
{ "Id": 0, "Weight": 0, "Name": "Unknown", "Allowed": false },
|
||||
{ "Id": 1, "Weight": 1, "Name": "SDTV", "Allowed": false },
|
||||
{ "Id": 8, "Weight": 2, "Name": "WEBDL-480p", "Allowed": false },
|
||||
{ "Id": 2, "Weight": 3, "Name": "DVD", "Allowed": false },
|
||||
{ "Id": 4, "Weight": 4, "Name": "HDTV", "Allowed": false },
|
||||
{ "Id": 5, "Weight": 5, "Name": "WEBDL-720p", "Allowed": false },
|
||||
{ "Id": 4, "Weight": 4, "Name": "HDTV-720p", "Allowed": false },
|
||||
{ "Id": 9, "Weight": 5, "Name": "HDTV-1080p", "Allowed": false },
|
||||
{ "Id": 5, "Weight": 6, "Name": "WEBDL-720p", "Allowed": false },
|
||||
{ "Id": 3, "Weight": 6, "Name": "WEBDL-1080p", "Allowed": false },
|
||||
{ "Id": 6, "Weight": 7, "Name": "Bluray720p", "Allowed": false },
|
||||
{ "Id": 7, "Weight": 8, "Name": "Bluray1080p", "Allowed": false }
|
||||
{ "Id": 6, "Weight": 8, "Name": "Bluray720p", "Allowed": false },
|
||||
{ "Id": 7, "Weight": 9, "Name": "Bluray1080p", "Allowed": false }
|
||||
]
|
||||
});
|
||||
//Todo: It would be nice to not have to save this on add (via create)
|
||||
|
|
29
NzbDrone.Web/Scripts/backbone/views/qualityTypes.js
Normal file
29
NzbDrone.Web/Scripts/backbone/views/qualityTypes.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
QualityTypeView = Backbone.Marionette.ItemView.extend({
|
||||
tagName: "div",
|
||||
className: "quality-type",
|
||||
template: QualityTypeApp.Constants.Templates.QualityType,
|
||||
events: {
|
||||
'change .slider-value': 'changeSize'
|
||||
},
|
||||
changeSize: function (e) {
|
||||
var target = $(e.target);
|
||||
var maxSize = parseInt($(target).val());
|
||||
|
||||
this.model.set({ "MaxSize": maxSize });
|
||||
this.model.save();
|
||||
}
|
||||
});
|
||||
|
||||
QualityTypeCollectionView = Backbone.Marionette.CompositeView.extend({
|
||||
tagName: "div",
|
||||
id: "quality-type-collection",
|
||||
itemView: QualityTypeView,
|
||||
template: QualityTypeApp.Constants.Templates.QualityTypeCollection,
|
||||
|
||||
initialize: function () {
|
||||
_.bindAll(this, 'render');
|
||||
this.collection = new QualityTypeCollection();
|
||||
this.collection.fetch();
|
||||
this.collection.bind('reset', this.render);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue