New: Mass series editor

This commit is contained in:
Mark McDowall
2013-12-08 21:25:27 -08:00
parent f76c4700a6
commit a9ece10144
26 changed files with 606 additions and 34 deletions
@@ -0,0 +1,150 @@
'use strict';
define(
[
'underscore',
'marionette',
'backgrid',
'vent',
'Series/SeriesCollection',
'Quality/QualityProfileCollection',
'AddSeries/RootFolders/Collection',
'Shared/Toolbar/ToolbarLayout',
'AddSeries/RootFolders/Layout',
'Config'
], function (_,
Marionette,
Backgrid,
vent,
SeriesCollection,
QualityProfiles,
RootFolders,
ToolbarLayout,
RootFolderLayout,
Config) {
return Marionette.ItemView.extend({
template: 'Series/Editor/SeriesEditorFooterViewTemplate',
ui: {
monitored : '.x-monitored',
qualityProfile: '.x-quality-profiles',
seasonFolder : '.x-season-folder',
rootFolder : '.x-root-folder',
selectedCount : '.x-selected-count',
saveButton : '.x-save',
container : '.series-editor-footer'
},
events: {
'click .x-save' : '_updateAndSave',
'change .x-root-folder': '_rootFolderChanged'
},
templateHelpers: function () {
return {
qualityProfiles: QualityProfiles,
rootFolders : RootFolders.toJSON()
};
},
initialize: function (options) {
RootFolders.fetch().done(function () {
RootFolders.synced = true;
});
this.editorGrid = options.editorGrid;
this.listenTo(SeriesCollection, 'backgrid:selected', this._updateInfo);
this.listenTo(RootFolders, 'all', this.render);
},
onRender: function () {
this._updateInfo();
},
_updateAndSave: function () {
var selected = this.editorGrid.getSelectedModels();
var monitored = this.ui.monitored.val();
var profile = this.ui.qualityProfile.val();
var seasonFolder = this.ui.seasonFolder.val();
var rootFolder = this.ui.rootFolder.val();
_.each(selected, function (model) {
if (monitored === 'true') {
model.set('monitored', true);
}
else if (monitored === 'false') {
model.set('monitored', false);
}
if (profile !== 'noChange') {
model.set('qualityProfileId', parseInt(profile, 10));
}
if (seasonFolder === 'true') {
model.set('seasonFolder', true);
}
else if (seasonFolder === 'false') {
model.set('seasonFolder', false);
}
if (rootFolder !== 'noChange') {
var rootFolderPath = RootFolders.get(parseInt(rootFolder, 10));
model.set('rootFolderPath', rootFolderPath.get('path'));
}
model.trigger('backgrid:select', model, false);
});
this.ui.monitored.val('noChange');
this.ui.qualityProfile.val('noChange');
this.ui.seasonFolder.val('noChange');
this.ui.rootFolder.val('noChange');
SeriesCollection.save();
},
_updateInfo: function () {
var selected = this.editorGrid.getSelectedModels();
var selectedCount = selected.length;
this.ui.selectedCount.html('{0} series selected'.format(selectedCount));
if (selectedCount === 0) {
this.ui.monitored.attr('disabled', '');
this.ui.qualityProfile.attr('disabled', '');
this.ui.seasonFolder.attr('disabled', '');
this.ui.rootFolder.attr('disabled', '');
this.ui.saveButton.attr('disabled', '');
}
else {
this.ui.monitored.removeAttr('disabled', '');
this.ui.qualityProfile.removeAttr('disabled', '');
this.ui.seasonFolder.removeAttr('disabled', '');
this.ui.rootFolder.removeAttr('disabled', '');
this.ui.saveButton.removeAttr('disabled', '');
}
},
_rootFolderChanged: function () {
var rootFolderValue = this.ui.rootFolder.val();
if (rootFolderValue === 'addNew') {
var rootFolderLayout = new RootFolderLayout();
this.listenToOnce(rootFolderLayout, 'folderSelected', this._setRootFolder);
vent.trigger(vent.Commands.OpenModalCommand, rootFolderLayout);
}
else {
Config.setValue(Config.Keys.DefaultRootFolderId, rootFolderValue);
}
},
_setRootFolder: function (options) {
vent.trigger(vent.Commands.CloseModalCommand);
this.ui.rootFolder.val(options.model.id);
this._rootFolderChanged();
}
});
});
@@ -0,0 +1,50 @@
<div class="series-editor-footer">
<div class="row">
<div class="span2">Monitored</div>
<div class="span2">Quality Profile</div>
<div class="span2">Season Folder</div>
<div class="span4">Root Folder</div>
</div>
<div class="row">
<div class="span2">
<select class="span2 x-monitored">
<option value="noChange">No change</option>
<option value="true">Monitored</option>
<option value="false">Unmonitored</option>
</select>
</div>
<div class="span2">
<select class="span2 x-quality-profiles">
<option value="noChange">No change</option>
{{#each qualityProfiles.models}}
<option value="{{id}}">{{attributes.name}}</option>
{{/each}}
</select>
</div>
<div class="span2">
<select class="span2 x-season-folder">
<option value="noChange">No change</option>
<option value="true">Yes</option>
<option value="false">No</option>
</select>
</div>
<div class="span3">
<select class="span3 x-root-folder" validation-name="RootFolderPath">
<option value="noChange">No change</option>
{{#each rootFolders}}
<option value="{{id}}">{{path}}</option>
{{/each}}
<option value="addNew">Add a different path</option>
</select>
</div>
<span class="pull-right">
<span class="selected-count x-selected-count">0 series selected</span>
<button class="btn btn-primary x-save">Save</button>
</span>
</div>
</div>
+153
View File
@@ -0,0 +1,153 @@
'use strict';
define(
[
'vent',
'marionette',
'backgrid',
'Series/Index/EmptyView',
'Series/SeriesCollection',
'Cells/SeriesTitleCell',
'Cells/QualityProfileCell',
'Cells/SeriesStatusCell',
'Cells/SeasonFolderCell',
'Shared/Toolbar/ToolbarLayout',
'Series/Editor/SeriesEditorFooterView'
], function (vent,
Marionette,
Backgrid,
EmptyView,
SeriesCollection,
SeriesTitleCell,
QualityProfileCell,
SeriesStatusCell,
SeasonFolderCell,
ToolbarLayout,
FooterView) {
return Marionette.Layout.extend({
template: 'Series/Editor/SeriesEditorLayoutTemplate',
regions: {
seriesRegion: '#x-series-editor',
toolbar : '#x-toolbar'
},
ui: {
monitored : '.x-monitored',
qualityProfiles: '.x-quality-profiles',
rootFolder : '.x-root-folder',
selectedCount : '.x-selected-count'
},
events: {
'click .x-save' : '_updateAndSave',
'change .x-root-folder': '_rootFolderChanged'
},
columns:
[
{
name : '',
cell : 'select-row',
headerCell: 'select-all',
sortable : false
},
{
name : 'statusWeight',
label : '',
cell : SeriesStatusCell
},
{
name : 'title',
label : 'Title',
cell : SeriesTitleCell,
cellValue: 'this'
},
{
name : 'qualityProfileId',
label: 'Quality',
cell : QualityProfileCell
},
{
name : 'monitored',
label: 'Season Folder',
cell : SeasonFolderCell
},
{
name : 'path',
label: 'Path',
cell : 'string'
}
],
leftSideButtons: {
type : 'default',
storeState: false,
items :
[
{
title : 'Season Pass',
icon : 'icon-bookmark',
route : 'seasonpass'
},
{
title : 'Update Library',
icon : 'icon-refresh',
command : 'refreshseries',
successMessage: 'Library was updated!',
errorMessage : 'Library update failed!'
}
]
},
initialize: function () {
this.listenTo(SeriesCollection, 'sync', this._showTable);
this.listenTo(SeriesCollection, 'remove', this._showTable);
},
onRender: function () {
this._showToolbar();
this._showTable();
this._fetchCollection();
},
onClose: function () {
vent.trigger(vent.Commands.CloseControlPanelCommand);
},
_showTable: function () {
if (SeriesCollection.length === 0) {
this.seriesRegion.show(new EmptyView());
this.toolbar.close();
return;
}
this.editorGrid = new Backgrid.Grid({
collection: SeriesCollection,
columns : this.columns,
className : 'table table-hover'
});
this.seriesRegion.show(this.editorGrid);
this._showFooter();
},
_fetchCollection: function () {
SeriesCollection.fetch();
},
_showToolbar: function () {
this.toolbar.show(new ToolbarLayout({
left :
[
this.leftSideButtons
],
context: this
}));
},
_showFooter: function () {
vent.trigger(vent.Commands.OpenControlPanelCommand, new FooterView({ editorGrid: this.editorGrid }));
}
});
});
@@ -0,0 +1,7 @@
<div id="x-toolbar"></div>
<div class="row">
<div class="span12">
<div id="x-series-editor" class="series-"></div>
</div>
</div>
+5
View File
@@ -109,6 +109,11 @@ define(
icon : 'icon-bookmark',
route : 'seasonpass'
},
{
title : 'Series Editor',
icon : 'icon-nd-edit',
route : 'serieseditor'
},
{
title : 'RSS Sync',
icon : 'icon-rss',
+26 -1
View File
@@ -1,10 +1,11 @@
'use strict';
define(
[
'underscore',
'backbone',
'Series/SeriesModel',
'api!series'
], function (Backbone, SeriesModel, SeriesData) {
], function (_, Backbone, SeriesModel, SeriesData) {
var Collection = Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/series',
model: SeriesModel,
@@ -16,6 +17,30 @@ define(
state: {
sortKey: 'title',
order : -1
},
save: function () {
var self = this;
var proxy = _.extend( new Backbone.Model(),
{
id: '',
url: self.url + '/editor',
toJSON: function()
{
return self.filter(function (model) {
return model.hasChanged();
});
}
});
this.listenTo(proxy, 'sync', function (proxyModel, models) {
this.add(models, { merge: true });
});
return proxy.save();
}
});
+13
View File
@@ -288,4 +288,17 @@
font-size : 24px;
margin-top : 3px;
}
}
//Editor
.series-editor-footer {
width: 1100px;
color: #f5f5f5;
margin-left: auto;
margin-right: auto;
.selected-count {
margin-right: 10px;
}
}