Lidarr/UI/Settings/MediaManagement/Naming/View.js

63 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
},
2013-07-14 07:00:50 +00:00
onRender: function(){
if(!this.model.get('renameEpisodes')){
this.ui.namingOptions.hide();
}
2013-08-12 00:42:11 +00:00
this.listenTo(this.model, 'change', this._buildExamples);
this._buildExamples();
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
},
_buildExamples: function () {
var self = this;
var data = this.model.toJSON();
data.id = 0;
var promise = $.ajax({
type: 'POST',
url : window.ApiRoot + '/naming',
data: JSON.stringify(data)
});
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);
});