sonarr-repo-only/UI/Settings/MediaManagement/Naming/View.js

61 lines
1.9 KiB
JavaScript
Raw Normal View History

2013-07-14 07:00:50 +00:00
'use strict';
2013-07-05 03:26:07 +00:00
define(
[
'marionette',
'Mixins/AsModelBoundView'
], function (Marionette, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Settings/MediaManagement/Naming/ViewTemplate',
ui: {
2013-07-14 07:00:50 +00:00
namingOptions : '.x-naming-options',
2013-08-12 00:42:11 +00:00
renameEpisodesCheckbox: '.x-rename-episodes',
singleEpisodeExample : '.x-single-episode-example',
multiEpisodeExample : '.x-multi-episode-example'
2013-07-05 03:26:07 +00:00
},
events: {
2013-07-14 07:00:50 +00:00
'change .x-rename-episodes': '_setNamingOptionsVisibility'
2013-07-05 03:26:07 +00:00
},
onRender: function () {
if (!this.model.get('renameEpisodes')) {
2013-07-14 07:00:50 +00:00
this.ui.namingOptions.hide();
}
2013-08-12 00:42:11 +00:00
this.listenTo(this.model, 'change', this._updateExamples);
this._updateExamples();
2013-07-05 03:26:07 +00:00
},
2013-07-14 07:00:50 +00:00
_setNamingOptionsVisibility: function () {
2013-07-05 03:26:07 +00:00
var checked = this.ui.renameEpisodesCheckbox.prop('checked');
2013-07-14 07:00:50 +00:00
if (checked) {
this.ui.namingOptions.slideDown();
2013-07-05 03:26:07 +00:00
}
else {
2013-07-14 07:00:50 +00:00
this.ui.namingOptions.slideUp();
2013-07-05 03:26:07 +00:00
}
2013-08-12 00:42:11 +00:00
},
_updateExamples: function () {
2013-08-12 00:42:11 +00:00
var self = this;
2013-08-12 00:42:11 +00:00
var promise = $.ajax({
type: 'GET',
2013-09-14 07:10:19 +00:00
url : window.NzbDrone.ApiRoot + '/config/naming/samples',
data: this.model.toJSON()
2013-08-12 00:42:11 +00:00
});
promise.done(function (result) {
self.ui.singleEpisodeExample.html(result.singleEpisodeExample);
self.ui.multiEpisodeExample.html(result.multiEpisodeExample);
});
2013-07-05 03:26:07 +00:00
}
});
return AsModelBoundView.call(view);
});