2013-08-20 23:35:19 +00:00
|
|
|
'use strict';
|
|
|
|
define(
|
|
|
|
[
|
|
|
|
'backgrid',
|
2013-08-22 03:24:50 +00:00
|
|
|
'Settings/Quality/Profile/QualityProfileSchemaCollection',
|
|
|
|
'Series/EpisodeFileModel'
|
|
|
|
], function (Backgrid, QualityProfileSchemaCollection, EpisodeFileModel) {
|
2013-08-20 23:35:19 +00:00
|
|
|
return Backgrid.CellEditor.extend({
|
|
|
|
|
|
|
|
className: 'quality-cell-editor',
|
|
|
|
template : 'Cells/Edit/QualityCellEditorTemplate',
|
|
|
|
tagName : 'select',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'change': 'save',
|
|
|
|
'blur': 'close',
|
|
|
|
'keydown': 'close'
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var qualityProfileSchemaCollection = new QualityProfileSchemaCollection();
|
|
|
|
var promise = qualityProfileSchemaCollection.fetch();
|
|
|
|
|
|
|
|
promise.done(function () {
|
|
|
|
var templateName = self.template;
|
|
|
|
self.schema = qualityProfileSchemaCollection.first();
|
|
|
|
|
2013-08-21 15:24:09 +00:00
|
|
|
var selected = _.find(self.schema.get('available'), { 'id': self.model.get(self.column.get("name")).quality.id });
|
2013-09-09 00:35:39 +00:00
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
selected.selected = true;
|
|
|
|
}
|
2013-08-20 23:35:19 +00:00
|
|
|
|
|
|
|
self.templateFunction = Marionette.TemplateCache.get(templateName);
|
|
|
|
var data = self.schema.toJSON();
|
|
|
|
var html = self.templateFunction(data);
|
|
|
|
self.$el.html(html);
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
save: function (e) {
|
|
|
|
var model = this.model;
|
|
|
|
var column = this.column;
|
|
|
|
var selected = parseInt(this.$el.val());
|
|
|
|
|
|
|
|
var quality = _.find(this.schema.get('available'), { 'id': selected });
|
|
|
|
|
|
|
|
var newQuality = {
|
|
|
|
proper: false,
|
|
|
|
quality: quality
|
|
|
|
};
|
|
|
|
|
|
|
|
model.set(column.get("name"), newQuality);
|
2013-08-21 06:46:23 +00:00
|
|
|
model.save();
|
2013-08-20 23:35:19 +00:00
|
|
|
model.trigger("backgrid:edited", model, column, new Backgrid.Command(e));
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function (e) {
|
|
|
|
var model = this.model;
|
|
|
|
var column = this.column;
|
|
|
|
var command = new Backgrid.Command(e);
|
|
|
|
|
|
|
|
model.trigger("backgrid:edited", model, column, command);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|