Rename preview for full series and season

New: Preview before renaming files
This commit is contained in:
Mark McDowall
2013-11-26 00:06:28 -08:00
parent bb37444a99
commit e42ac25657
29 changed files with 449 additions and 111 deletions
+38
View File
@@ -0,0 +1,38 @@
'use strict';
define(
[
'backbone',
'Rename/RenamePreviewModel'
], function (Backbone, RenamePreviewModel) {
return Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/rename',
model: RenamePreviewModel,
originalFetch: Backbone.Collection.prototype.fetch,
initialize: function (options) {
if (!options.seriesId) {
throw 'seriesId is required';
}
this.seriesId = options.seriesId;
this.seasonNumber = options.seasonNumber;
},
fetch: function (options) {
if (!this.seriesId) {
throw 'seriesId is required';
}
options = options || {};
options.data = {};
options.data.seriesId = this.seriesId;
if (this.seasonNumber) {
options.data.seasonNumber = this.seasonNumber;
}
return this.originalFetch.call(this, options);
}
});
});
@@ -0,0 +1,11 @@
'use strict';
define(
[
'marionette',
'Rename/RenamePreviewItemView'
], function (Marionette, RenamePreviewItemView) {
return Marionette.CollectionView.extend({
itemView : RenamePreviewItemView
});
});
@@ -0,0 +1,10 @@
'use strict';
define(
[
'vent',
'marionette'
], function (vent, Marionette) {
return Marionette.ItemView.extend({
template: 'Rename/RenamePreviewEmptyCollectionViewTemplate'
});
});
@@ -0,0 +1,3 @@
<div class="alert alert-success">
Success! My work is done, no files to rename.
</div>
+13
View File
@@ -0,0 +1,13 @@
'use strict';
define(
[
'vent',
'marionette',
'Mixins/AsModelBoundView'
], function (vent, Marionette, AsModelBoundView) {
var view = Marionette.ItemView.extend({
template: 'Rename/RenamePreviewItemViewTemplate'
});
return AsModelBoundView.apply(view);
});
@@ -0,0 +1,25 @@
<div class="rename-preview-item">
<div class="row">
<div class="span1">
<label class="checkbox toggle well" title="Rename file">
<input type="checkbox" name="rename"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-warning slide-button"/>
</label>
</div>
<div class="span9">
<div class="row">
<div class="span1">Existing</div>
<div class="span8">{{existingPath}}</div>
</div>
<div class="row">
<div class="span1">Suggested</div>
<div class="span8">{{newPath}}</div>
</div>
</div>
</div>
</div>
+93
View File
@@ -0,0 +1,93 @@
'use strict';
define(
[
'underscore',
'vent',
'marionette',
'Rename/RenamePreviewCollection',
'Rename/RenamePreviewCollectionView',
'Rename/RenamePreviewEmptyCollectionView',
'Shared/LoadingView',
'Commands/CommandController'
], function (_, vent, Marionette, RenamePreviewCollection, RenamePreviewCollectionView, EmptyCollectionView, LoadingView, CommandController) {
return Marionette.Layout.extend({
template: 'Rename/RenamePreviewLayoutTemplate',
regions: {
renamePreviews : '#rename-previews'
},
ui: {
pathInfo: '.x-path-info'
},
events: {
'click .x-organize': '_organizeFiles'
},
initialize: function (options) {
this.model = options.series;
this.seasonNumber = options.seasonNumber;
var viewOptions = {};
viewOptions.seriesId = this.model.id;
viewOptions.seasonNumber = this.seasonNumber;
this.collection = new RenamePreviewCollection(viewOptions);
this.listenTo(this.collection, 'sync', this._showPreviews);
this.collection.fetch();
},
onRender: function() {
this.renamePreviews.show(new LoadingView());
},
_showPreviews: function () {
if (this.collection.length === 0) {
this.ui.pathInfo.hide();
this.renamePreviews.show(new EmptyCollectionView());
return;
}
this.collection.invoke('set', { rename: true });
this.renamePreviews.show(new RenamePreviewCollectionView({ collection: this.collection }));
},
_organizeFiles: function () {
if (this.collection.length === 0) {
vent.trigger(vent.Commands.CloseModalCommand);
}
var files = _.map(this.collection.where({ rename: true }), function (model) {
return model.get('episodeFileId');
});
if (files.length === 0) {
vent.trigger(vent.Commands.CloseModalCommand);
return;
}
if (this.seasonNumber) {
CommandController.Execute('renameFiles', {
name : 'renameFiles',
seriesId : this.model.id,
seasonNumber: this.seasonNumber,
files : files
});
}
else {
CommandController.Execute('renameFiles', {
name : 'renameFiles',
seriesId : this.model.id,
seasonNumber: -1,
files : files
});
}
vent.trigger(vent.Commands.CloseModalCommand);
}
});
});
@@ -0,0 +1,19 @@
<div class="rename-preview-modal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>
Organize & Rename
</h3>
</div>
<div class="modal-body">
<div class="alert alert-info x-path-info">All paths are relative to: <strong>{{path}}</strong></div>
<div id="rename-previews"></div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">close</button>
<button class="btn x-organize">Organize</button>
</div>
</div>
+9
View File
@@ -0,0 +1,9 @@
'use strict';
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
});
});