2013-06-25 07:43:16 +03:00
|
|
|
'use strict';
|
2013-06-25 02:41:59 +03:00
|
|
|
|
|
|
|
define(
|
|
|
|
[
|
|
|
|
'app',
|
|
|
|
'marionette',
|
|
|
|
'Settings/Quality/Profile/EditQualityProfileView',
|
|
|
|
'Settings/Quality/Profile/DeleteView',
|
2013-07-06 03:29:29 +03:00
|
|
|
'Series/SeriesCollection',
|
2013-06-25 03:41:32 +03:00
|
|
|
'Mixins/AsModelBoundView',
|
2013-07-06 03:29:29 +03:00
|
|
|
'Settings/Quality/Profile/AllowedLabeler',
|
|
|
|
'bootstrap',
|
2013-06-25 02:41:59 +03:00
|
|
|
|
2013-07-06 03:29:29 +03:00
|
|
|
], function (App, Marionette, EditProfileView, DeleteProfileView, SeriesCollection, AsModelBoundView) {
|
2013-06-25 02:41:59 +03:00
|
|
|
|
|
|
|
var view = Marionette.ItemView.extend({
|
|
|
|
template: 'Settings/Quality/Profile/QualityProfileTemplate',
|
2013-06-25 03:41:32 +03:00
|
|
|
tagName : 'li',
|
2013-06-25 02:41:59 +03:00
|
|
|
|
|
|
|
ui: {
|
2013-07-06 03:29:29 +03:00
|
|
|
'progressbar' : '.progress .bar',
|
|
|
|
'deleteButton': '.x-delete'
|
2013-06-25 02:41:59 +03:00
|
|
|
},
|
2013-06-24 07:48:47 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
events: {
|
2013-06-25 03:41:32 +03:00
|
|
|
'click .x-edit' : '_editProfile',
|
|
|
|
'click .x-delete': '_deleteProfile'
|
2013-06-25 02:41:59 +03:00
|
|
|
},
|
|
|
|
|
2013-06-25 10:21:10 +03:00
|
|
|
initialize: function () {
|
|
|
|
this.listenTo(this.model, 'sync', this.render);
|
2013-07-06 03:29:29 +03:00
|
|
|
this.listenTo(SeriesCollection, 'all', this._updateDisableStatus)
|
2013-06-25 10:21:10 +03:00
|
|
|
},
|
|
|
|
|
2013-06-25 03:41:32 +03:00
|
|
|
_editProfile: function () {
|
2013-06-25 10:21:10 +03:00
|
|
|
var view = new EditProfileView({ model: this.model, profileCollection: this.model.collection });
|
2013-06-25 02:41:59 +03:00
|
|
|
App.modalRegion.show(view);
|
|
|
|
},
|
|
|
|
|
2013-06-25 03:41:32 +03:00
|
|
|
_deleteProfile: function () {
|
2013-07-06 03:29:29 +03:00
|
|
|
if (this._isQualityInUse()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
var view = new DeleteProfileView({ model: this.model });
|
|
|
|
App.modalRegion.show(view);
|
2013-07-06 03:29:29 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return AsModelBoundView.call(view);
|
|
|
|
});
|