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",
|
2012-12-05 16:34:43 +00:00
|
|
|
|
initialize: function() {
|
|
|
|
|
this.model.on('destroy', this.remove, this)
|
|
|
|
|
},
|
2012-11-24 08:03:38 +00:00
|
|
|
|
events: {
|
2012-12-03 03:08:26 +00:00
|
|
|
|
'click .quality-selectee': 'toggleAllowed',
|
|
|
|
|
'change .cutoff': 'changeCutoff',
|
2012-12-05 16:34:43 +00:00
|
|
|
|
'change .name': 'changeName',
|
|
|
|
|
'click .remove-profile': 'destroy'
|
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-12-11 04:39:35 +00:00
|
|
|
|
var el = $(this.el);
|
2012-11-24 08:03:38 +00:00
|
|
|
|
|
2012-12-03 03:08:26 +00:00
|
|
|
|
var checked = $(target).attr('checked') != undefined;
|
|
|
|
|
|
|
|
|
|
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;
|
2012-12-11 04:39:35 +00:00
|
|
|
|
|
2012-12-03 03:08:26 +00:00
|
|
|
|
//Find cutoff dropdown
|
2013-01-29 03:40:49 +00:00
|
|
|
|
var cutoffLocal = $(el).find('.cutoff');
|
2012-12-03 03:08:26 +00:00
|
|
|
|
|
|
|
|
|
if (checked) {
|
2013-01-29 03:40:49 +00:00
|
|
|
|
$('<option>' + qualityType.Name + '</option>').val(qualityId).appendTo(cutoffLocal);
|
2012-12-03 03:08:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
2013-01-29 03:40:49 +00:00
|
|
|
|
$(cutoffLocal).find('option[value="' + qualityId + '"]').remove();
|
2012-12-03 03:08:26 +00:00
|
|
|
|
}
|
2012-12-06 01:19:17 +00:00
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
//}));
|
2012-12-03 03:08:26 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-01-29 03:40:49 +00:00
|
|
|
|
var cutoff = $(el).find('.cutoff');
|
|
|
|
|
if (cutoff[0].length === 0)
|
|
|
|
|
this.model.set({ "Cutoff": 0 });
|
|
|
|
|
|
|
|
|
|
if (cutoff[0].length === 1)
|
|
|
|
|
this.model.set({ "Cutoff": cutoff.val() });
|
|
|
|
|
|
2012-12-03 03:08:26 +00:00
|
|
|
|
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 });
|
2012-12-11 06:45:52 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
2012-12-05 16:34:43 +00:00
|
|
|
|
},
|
|
|
|
|
destroy: function (e) {
|
|
|
|
|
e.preventDefault();
|
2012-12-11 06:45:52 +00:00
|
|
|
|
|
|
|
|
|
$("#DefaultQualityProfileId option[value='" + this.model.get('Id') + "']").remove();
|
|
|
|
|
|
2012-12-05 16:34:43 +00:00
|
|
|
|
this.model.destroy();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
},
|
|
|
|
|
remove: function (e) {
|
|
|
|
|
$(this.el).remove();
|
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,
|
|
|
|
|
|
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-12-05 01:21:54 +00:00
|
|
|
|
},
|
|
|
|
|
events: {
|
|
|
|
|
'click #add-profile': 'addProfile'
|
|
|
|
|
},
|
|
|
|
|
addProfile: function (e) {
|
2012-12-11 04:39:35 +00:00
|
|
|
|
e.preventDefault();
|
2012-12-11 06:45:52 +00:00
|
|
|
|
|
|
|
|
|
//Todo: Need to get the default profile from the server, instead of creating it manually...
|
2012-12-11 04:39:35 +00:00
|
|
|
|
var newProfile = new QualityProfile({
|
2013-01-02 03:24:03 +00:00
|
|
|
|
Name: 'New Profile', Cutoff: 0, Qualities: [
|
2012-12-11 04:39:35 +00:00
|
|
|
|
{ "Id": 1, "Weight": 1, "Name": "SDTV", "Allowed": false },
|
2012-12-31 08:14:01 +00:00
|
|
|
|
{ "Id": 8, "Weight": 2, "Name": "WEBDL-480p", "Allowed": false },
|
|
|
|
|
{ "Id": 2, "Weight": 3, "Name": "DVD", "Allowed": false },
|
2013-01-02 02:06:55 +00:00
|
|
|
|
{ "Id": 4, "Weight": 4, "Name": "HDTV-720p", "Allowed": false },
|
|
|
|
|
{ "Id": 9, "Weight": 5, "Name": "HDTV-1080p", "Allowed": false },
|
2013-01-09 08:15:06 +00:00
|
|
|
|
{ "Id": 10, "Weight": 6, "Name": "Raw-HD", "Allowed": false },
|
|
|
|
|
{ "Id": 5, "Weight": 7, "Name": "WEBDL-720p", "Allowed": false },
|
|
|
|
|
{ "Id": 3, "Weight": 7, "Name": "WEBDL-1080p", "Allowed": false },
|
|
|
|
|
{ "Id": 6, "Weight": 9, "Name": "Bluray720p", "Allowed": false },
|
|
|
|
|
{ "Id": 7, "Weight": 10, "Name": "Bluray1080p", "Allowed": false }
|
2012-12-11 04:39:35 +00:00
|
|
|
|
]
|
|
|
|
|
});
|
2012-12-31 08:18:39 +00:00
|
|
|
|
//Todo: It would be nice to not have to save this on add (via create)
|
2012-12-31 08:14:01 +00:00
|
|
|
|
this.collection.create(newProfile);
|
2012-11-07 00:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
});
|