2012-11-09 19:28:59 +03:00
|
|
|
QualityProfileView = Backbone.Marionette.ItemView.extend({
|
|
|
|
tagName: "div",
|
|
|
|
className: "quality-profile",
|
2012-11-24 11:03:38 +03:00
|
|
|
template: "#QualityProfileTemplate",
|
2012-12-05 19:34:43 +03:00
|
|
|
initialize: function() {
|
|
|
|
this.model.on('destroy', this.remove, this)
|
|
|
|
},
|
2012-11-24 11:03:38 +03:00
|
|
|
events: {
|
2012-12-03 06:08:26 +03:00
|
|
|
'click .quality-selectee': 'toggleAllowed',
|
|
|
|
'change .cutoff': 'changeCutoff',
|
2012-12-05 19:34:43 +03:00
|
|
|
'change .name': 'changeName',
|
|
|
|
'click .remove-profile': 'destroy'
|
2012-11-24 11:03:38 +03:00
|
|
|
},
|
|
|
|
toggleAllowed: function (e) {
|
|
|
|
//Add to cutoff
|
|
|
|
//Update model
|
2012-12-03 06:08:26 +03:00
|
|
|
var target = $(e.target);
|
2012-11-24 11:03:38 +03:00
|
|
|
|
2012-12-03 06:08:26 +03: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();
|
|
|
|
}
|
2012-12-06 04:19:17 +03: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 06:08:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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-12-05 19:34:43 +03:00
|
|
|
},
|
|
|
|
destroy: function (e) {
|
|
|
|
if (e === undefined)
|
|
|
|
return;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
this.model.destroy();
|
|
|
|
e.stopPropagation();
|
|
|
|
},
|
|
|
|
remove: function (e) {
|
|
|
|
$(this.el).remove();
|
2012-11-24 11:03:38 +03:00
|
|
|
}
|
2012-11-07 03:41:34 +03:00
|
|
|
});
|
|
|
|
|
2012-11-09 19:28:59 +03: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 03:41:34 +03:00
|
|
|
initialize: function () {
|
2012-11-09 19:28:59 +03:00
|
|
|
_.bindAll(this, 'render');
|
|
|
|
this.collection = new QualityProfileCollection();
|
|
|
|
this.collection.fetch();
|
|
|
|
this.collection.bind('reset', this.render);
|
2012-12-05 04:21:54 +03:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click #add-profile': 'addProfile'
|
|
|
|
},
|
|
|
|
addProfile: function (e) {
|
|
|
|
//Add new profile to collection
|
2012-12-05 19:34:43 +03:00
|
|
|
//Todo: How will we get the list of qualities (they would all be NOT allowed) - it all comes from the server side...
|
2012-12-05 04:21:54 +03:00
|
|
|
this.collection.add(new QualityProfile());
|
|
|
|
e.preventDefault();
|
2012-11-07 03:41:34 +03:00
|
|
|
}
|
|
|
|
});
|