1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-29 02:57:15 +02:00
Sonarr/UI/Settings/Quality/Profile/EditQualityProfileView.js

75 lines
2.4 KiB
JavaScript
Raw Normal View History

'use strict';
2013-06-19 04:02:23 +03:00
define(['app', 'marionette', 'Mixins/AsModelBoundView'], function (App, Marionette, AsModelBoundView) {
2013-06-19 04:02:23 +03:00
var view = Marionette.ItemView.extend({
2013-05-31 08:56:00 +03:00
template: 'Settings/Quality/Profile/EditQualityProfileTemplate',
ui: {
cutoff: '.x-cutoff'
},
events: {
'click .x-save' : '_saveQualityProfile',
2013-05-31 08:56:00 +03:00
'dblclick .x-available-list': '_moveQuality',
'dblclick .x-allowed-list' : '_moveQuality'
},
initialize: function (options) {
this.profileCollection = options.profileCollection;
},
2013-05-31 08:56:00 +03:00
_moveQuality: function (event) {
var quality;
var qualityId = event.target.value;
var availableCollection = new Backbone.Collection(this.model.get('available'));
availableCollection.comparator = function (model) {
return model.get('weight');
};
var allowedCollection = new Backbone.Collection(this.model.get('allowed'));
allowedCollection.comparator = function (model) {
return model.get('weight');
};
if (availableCollection.get(qualityId)) {
quality = availableCollection.get(qualityId);
availableCollection.remove(quality);
allowedCollection.add(quality);
}
else if (allowedCollection.get(qualityId)) {
quality = allowedCollection.get(qualityId);
allowedCollection.remove(quality);
availableCollection.add(quality);
}
else {
throw 'couldnt find quality id ' + qualityId;
}
this.model.set('available', availableCollection.toJSON());
this.model.set('allowed', allowedCollection.toJSON());
this.render();
},
_saveQualityProfile: function () {
var self = this;
var cutoff = _.findWhere(this.model.get('allowed'), { id: parseInt(this.ui.cutoff.val())});
this.model.set('cutoff', cutoff);
var promise = this.model.save();
if (promise) {
promise.done(function () {
self.profileCollection.add(self.model, { merge: true });
2013-07-24 04:15:58 +03:00
App.vent.trigger(App.Commands.CloseModalCommand);
});
}
}
});
2013-06-19 04:02:23 +03:00
return AsModelBoundView.call(view);
2013-06-01 20:38:21 +03:00
});