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.
Prowlarr/UI/Cells/Edit/QualityCellEditor.js

71 lines
2.3 KiB

'use strict';
define(
[
'backgrid',
'Settings/Quality/Profile/QualityProfileSchemaCollection',
'Series/EpisodeFileModel'
], function (Backgrid, QualityProfileSchemaCollection, EpisodeFileModel) {
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();
var selected = _.find(self.schema.get('available'), { 'id': self.model.get(self.column.get("name")).quality.id });
if (selected) {
selected.selected = true;
}
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);
model.save();
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);
}
});
});