You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js

123 lines
4.3 KiB

QualityProfileView = Backbone.Marionette.ItemView.extend({
tagName: "div",
className: "quality-profile",
12 years ago
template: "#QualityProfileTemplate",
initialize: function() {
this.model.on('destroy', this.remove, this)
},
12 years ago
events: {
'click .quality-selectee': 'toggleAllowed',
'change .cutoff': 'changeCutoff',
'change .name': 'changeName',
'click .remove-profile': 'destroy'
12 years ago
},
toggleAllowed: function (e) {
//Add to cutoff
//Update model
var target = $(e.target);
12 years ago
var el = $(this.el);
12 years ago
var checked = $(target).attr('checked') != undefined;
var id = this.model.get("Id");
var qualities = _.clone(this.model.get("Qualities"));
_.each(qualities, function (qualityType) {
var qualityId = parseInt($(target).attr('data-quality-id'));
if (qualityType.Id == qualityId) {
qualityType.Allowed = checked;
12 years ago
//Find cutoff dropdown
12 years ago
var cutoff = $(el).find('.cutoff');
if (checked) {
$('<option>' + qualityType.Name + '</option>').val(qualityId).appendTo(cutoff);
}
else {
$(cutoff).find('option[value="' + qualityId + '"]').remove();
}
12 years ago
//Todo: auto-sort by weight (which is not the value)
//$(cutoff).html($($(cutoff).children("option")).sort(function(a, b) {
// return a.value == b.value ? 0 : a.value < b.value ? -1 : 1;
//}));
}
});
this.model.set({ "Qualities": qualities });
this.model.save();
},
changeCutoff: function(e) {
var cutoff = $(e.target).val();
this.model.set({ "Cutoff": cutoff });
this.model.save();
},
changeName: function(e) {
var name = $(e.target).val();
this.model.set({ "Name": name });
this.model.save(this.model, {
success: function (model) {
var id = model.get('Id');
var name = model.get('Name');
var exists = $('#DefaultQualityProfileId option[value="' + id + '"]');
if (exists.length == 0)
$('#DefaultQualityProfileId').append($('\<option\> \</option\>').val(id).html(name));
else
$('#DefaultQualityProfileId option[value="' + id + '"]').html(name);
}
});
},
destroy: function (e) {
e.preventDefault();
$("#DefaultQualityProfileId option[value='" + this.model.get('Id') + "']").remove();
this.model.destroy();
e.stopPropagation();
},
remove: function (e) {
$(this.el).remove();
12 years ago
}
12 years ago
});
QualityProfileCollectionView = Backbone.Marionette.CompositeView.extend({
tagName: "div",
id: "quality-profile-collection",
itemView: QualityProfileView,
template: QualityProfileApp.Constants.Templates.QualityProfileCollection,
12 years ago
initialize: function () {
_.bindAll(this, 'render');
this.collection = new QualityProfileCollection();
this.collection.fetch();
this.collection.bind('reset', this.render);
},
events: {
'click #add-profile': 'addProfile'
},
addProfile: function (e) {
12 years ago
e.preventDefault();
//Todo: Need to get the default profile from the server, instead of creating it manually...
12 years ago
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": 2, "Weight": 2, "Name": "DVD", "Allowed": false },
{ "Id": 4, "Weight": 4, "Name": "HDTV", "Allowed": false },
{ "Id": 5, "Weight": 5, "Name": "WEBDL-720p", "Allowed": false },
{ "Id": 3, "Weight": 7, "Name": "WEBDL-1080p", "Allowed": false },
{ "Id": 6, "Weight": 6, "Name": "Bluray720p", "Allowed": false },
{ "Id": 7, "Weight": 8, "Name": "Bluray1080p", "Allowed": false }
]
});
this.collection.add(newProfile);
12 years ago
}
});