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
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