sonarr-repo-only/NzbDrone.Web/Scripts/backbone/views/qualityProfiles.js

76 lines
2.4 KiB
JavaScript
Raw Normal View History

2012-11-09 16:28:59 +00:00
QualityProfileView = Backbone.Marionette.ItemView.extend({
tagName: "div",
className: "quality-profile",
2012-11-24 08:03:38 +00:00
template: "#QualityProfileTemplate",
events: {
2012-12-03 03:08:26 +00:00
'click .quality-selectee': 'toggleAllowed',
'change .cutoff': 'changeCutoff',
'change .name': 'changeName'
2012-11-24 08:03:38 +00:00
},
toggleAllowed: function (e) {
//Add to cutoff
//Update model
2012-12-03 03:08:26 +00:00
var target = $(e.target);
2012-11-24 08:03:38 +00:00
2012-12-03 03:08:26 +00:00
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;
//Todo: Add/Remove from cutoff
//Find cutoff dropdown
var cutoff = ('select#' + id);
if (checked) {
$('<option>' + qualityType.Name + '</option>').val(qualityId).appendTo(cutoff);
}
else {
$(cutoff).find('option[value="' + qualityId + '"]').remove();
}
}
});
this.model.set({ "Qualities": qualities });
this.model.save();
},
changeCutoff: function(e) {
//Todo: save change
var cutoff = $(e.target).val();
this.model.set({ "Cutoff": cutoff });
this.model.save();
},
changeName: function(e) {
var name = $(e.target).val();
//Todo: update default quality dropdown
$('#DefaultQualityProfileId option[value="' + this.model.get("Id") + '"]').html(name);
this.model.set({ "Name": name });
this.model.save();
2012-11-24 08:03:38 +00:00
}
2012-11-07 00:41:34 +00:00
});
2012-11-09 16:28:59 +00:00
QualityProfileCollectionView = Backbone.Marionette.CompositeView.extend({
tagName: "div",
id: "quality-profile-collection",
itemView: QualityProfileView,
template: QualityProfileApp.Constants.Templates.QualityProfileCollection,
//appendHtml: function (collectionView, itemView) {
// collectionView.$('#collection').append(itemView.el);
//},
2012-11-07 00:41:34 +00:00
initialize: function () {
2012-11-09 16:28:59 +00:00
_.bindAll(this, 'render');
this.collection = new QualityProfileCollection();
this.collection.fetch();
this.collection.bind('reset', this.render);
2012-11-07 00:41:34 +00:00
}
});