Radarr/UI/Settings/Quality/Profile/QualityProfileView.js

72 lines
2.3 KiB
JavaScript
Raw Normal View History

2013-06-25 04:43:16 +00:00
'use strict';
define(
[
'app',
'marionette',
'Settings/Quality/Profile/EditQualityProfileView',
'Settings/Quality/Profile/DeleteView',
'Series/SeriesCollection',
2013-06-25 00:41:32 +00:00
'Mixins/AsModelBoundView',
'Settings/Quality/Profile/AllowedLabeler',
'bootstrap',
], function (App, Marionette, EditProfileView, DeleteProfileView, SeriesCollection, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Settings/Quality/Profile/QualityProfileTemplate',
2013-06-25 00:41:32 +00:00
tagName : 'li',
ui: {
'progressbar' : '.progress .bar',
'deleteButton': '.x-delete'
},
events: {
2013-06-25 00:41:32 +00:00
'click .x-edit' : '_editProfile',
'click .x-delete': '_deleteProfile'
},
initialize: function () {
this.listenTo(this.model, 'sync', this.render);
this.listenTo(SeriesCollection, 'all', this._updateDisableStatus)
},
2013-06-25 00:41:32 +00:00
_editProfile: function () {
var view = new EditProfileView({ model: this.model, profileCollection: this.model.collection });
App.modalRegion.show(view);
},
2013-06-25 00:41:32 +00:00
_deleteProfile: function () {
if (this._isQualityInUse()) {
return;
}
var view = new DeleteProfileView({ model: this.model });
App.modalRegion.show(view);
},
onRender: function () {
this._updateDisableStatus();
},
_updateDisableStatus: function () {
if (this._isQualityInUse()) {
this.ui.deleteButton.addClass('disabled');
this.ui.deleteButton.attr('title', 'Can\'t delete quality profiles attached to a series.');
}
else {
this.ui.deleteButton.removeClass('disabled');
this.ui.deleteButton.attr('title', 'Delete Quality Profile');
}
},
_isQualityInUse: function () {
return SeriesCollection.where({'qualityProfileId': this.model.id}).length !== 0;
}
});
return AsModelBoundView.call(view);
});