diff --git a/src/UI/Cells/MovieTitleCell.js b/src/UI/Cells/MovieTitleCell.js index 4ae8fe20c..652d1ebf3 100644 --- a/src/UI/Cells/MovieTitleCell.js +++ b/src/UI/Cells/MovieTitleCell.js @@ -4,8 +4,8 @@ module.exports = TemplatedCell.extend({ className : 'series-title-cell', template : 'Cells/SeriesTitleTemplate', - render : function() { - this.$el.html(this.model.get("movie").get("title")); //Hack, but somehow handlebar helper does not work. - return this; - } + // render : function() { + // this.$el.html(this.model.get("movie").get("title")); //Hack, but somehow handlebar helper does not work. + // return this; + // } }); diff --git a/src/UI/Controller.js b/src/UI/Controller.js index eb5168daa..89775a3ba 100644 --- a/src/UI/Controller.js +++ b/src/UI/Controller.js @@ -11,6 +11,7 @@ var ReleaseLayout = require('./Release/ReleaseLayout'); var SystemLayout = require('./System/SystemLayout'); var SeasonPassLayout = require('./SeasonPass/SeasonPassLayout'); var SeriesEditorLayout = require('./Series/Editor/SeriesEditorLayout'); +var MovieEditorLayout = require('./Movies/Editor/MovieEditorLayout'); module.exports = NzbDroneController.extend({ addSeries : function(action) { @@ -61,5 +62,10 @@ module.exports = NzbDroneController.extend({ seriesEditor : function() { this.setTitle('Series Editor'); this.showMainRegion(new SeriesEditorLayout()); + }, + + movieEditor : function() { + this.setTitle('Movie Editor'); + this.showMainRegion(new MovieEditorLayout()); } }); diff --git a/src/UI/Movies/Editor/MovieEditorFooterView.js b/src/UI/Movies/Editor/MovieEditorFooterView.js new file mode 100644 index 000000000..d764b1aa1 --- /dev/null +++ b/src/UI/Movies/Editor/MovieEditorFooterView.js @@ -0,0 +1,126 @@ +var _ = require('underscore'); +var Marionette = require('marionette'); +var vent = require('vent'); +var Profiles = require('../../Profile/ProfileCollection'); +var RootFolders = require('../../AddMovies/RootFolders/RootFolderCollection'); +var RootFolderLayout = require('../../AddMovies/RootFolders/RootFolderLayout'); +var UpdateFilesSeriesView = require('./Organize/OrganizeFilesView'); +var Config = require('../../Config'); + +module.exports = Marionette.ItemView.extend({ + template : 'Movies/Editor/MovieEditorFooterViewTemplate', + + ui : { + monitored : '.x-monitored', + profile : '.x-profiles', + seasonFolder : '.x-season-folder', + rootFolder : '.x-root-folder', + selectedCount : '.x-selected-count', + container : '.series-editor-footer', + actions : '.x-action' + }, + + events : { + 'click .x-save' : '_updateAndSave', + 'change .x-root-folder' : '_rootFolderChanged', + 'click .x-organize-files' : '_organizeFiles' + }, + + templateHelpers : function() { + return { + profiles : Profiles, + rootFolders : RootFolders.toJSON() + }; + }, + + initialize : function(options) { + this.seriesCollection = options.collection; + + RootFolders.fetch().done(function() { + RootFolders.synced = true; + }); + + this.editorGrid = options.editorGrid; + this.listenTo(this.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.profile.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('profileId', 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.edited = true; + }); + + this.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.actions.attr('disabled', 'disabled'); + } else { + this.ui.actions.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(); + }, + + _organizeFiles : function() { + var selected = this.editorGrid.getSelectedModels(); + var updateFilesSeriesView = new UpdateFilesSeriesView({ series : selected }); + this.listenToOnce(updateFilesSeriesView, 'updatingFiles', this._afterSave); + + vent.trigger(vent.Commands.OpenModalCommand, updateFilesSeriesView); + } +}); \ No newline at end of file diff --git a/src/UI/Movies/Editor/MovieEditorFooterViewTemplate.hbs b/src/UI/Movies/Editor/MovieEditorFooterViewTemplate.hbs new file mode 100644 index 000000000..ad81687d5 --- /dev/null +++ b/src/UI/Movies/Editor/MovieEditorFooterViewTemplate.hbs @@ -0,0 +1,54 @@ +
diff --git a/src/UI/Movies/Editor/MovieEditorLayout.js b/src/UI/Movies/Editor/MovieEditorLayout.js new file mode 100644 index 000000000..dbbb5f4f5 --- /dev/null +++ b/src/UI/Movies/Editor/MovieEditorLayout.js @@ -0,0 +1,153 @@ +var vent = require('vent'); +var Marionette = require('marionette'); +var Backgrid = require('backgrid'); +var EmptyView = require('../Index/EmptyView'); +var MoviesCollection = require('../MoviesCollection'); +var MovieTitleCell = require('../../Cells/MovieTitleCell'); +var ProfileCell = require('../../Cells/ProfileCell'); +var SelectAllCell = require('../../Cells/SelectAllCell'); +var ToolbarLayout = require('../../Shared/Toolbar/ToolbarLayout'); +var FooterView = require('./MovieEditorFooterView'); +require('../../Mixins/backbone.signalr.mixin'); + +module.exports = Marionette.Layout.extend({ + template : 'Movies/Editor/MovieEditorLayoutTemplate', + + regions : { + seriesRegion : '#x-series-editor', + toolbar : '#x-toolbar' + }, + + ui : { + monitored : '.x-monitored', + profiles : '.x-profiles', + rootFolder : '.x-root-folder', + selectedCount : '.x-selected-count' + }, + + events : { + 'click .x-save' : '_updateAndSave', + 'change .x-root-folder' : '_rootFolderChanged' + }, + + columns : [ + { + name : '', + cell : SelectAllCell, + headerCell : 'select-all', + sortable : false + }, + { + name : 'title', + label : 'Title', + cell : MovieTitleCell, + cellValue : 'this' + }, + { + name : 'profileId', + label : 'Profile', + cell : ProfileCell + }, + { + name : 'path', + label : 'Path', + cell : 'string' + } + ], + + leftSideButtons : { + type : 'default', + storeState : false, + items : [ + { + title : 'Update Library', + icon : 'icon-sonarr-refresh', + command : 'refreshseries', + successMessage : 'Library was updated!', + errorMessage : 'Library update failed!' + } + ] + }, + + initialize : function() { + this.movieCollection = MoviesCollection.clone(); + this.movieCollection.shadowCollection.bindSignalR(); + this.listenTo(this.movieCollection, 'save', this.render); + + this.filteringOptions = { + type : 'radio', + storeState : true, + menuKey : 'serieseditor.filterMode', + defaultAction : 'all', + items : [ + { + key : 'all', + title : '', + tooltip : 'All', + icon : 'icon-sonarr-all', + callback : this._setFilter + }, + { + key : 'monitored', + title : '', + tooltip : 'Monitored Only', + icon : 'icon-sonarr-monitored', + callback : this._setFilter + } + ] + }; + }, + + onRender : function() { + this._showToolbar(); + this._showTable(); + }, + + onClose : function() { + vent.trigger(vent.Commands.CloseControlPanelCommand); + }, + + _showTable : function() { + if (this.movieCollection.shadowCollection.length === 0) { + this.seriesRegion.show(new EmptyView()); + this.toolbar.close(); + return; + } + + this.columns[0].sortedCollection = this.movieCollection; + + this.editorGrid = new Backgrid.Grid({ + collection : this.movieCollection, + columns : this.columns, + className : 'table table-hover' + }); + + this.seriesRegion.show(this.editorGrid); + this._showFooter(); + }, + + _showToolbar : function() { + this.toolbar.show(new ToolbarLayout({ + left : [ + this.leftSideButtons + ], + right : [ + this.filteringOptions + ], + context : this + })); + }, + + _showFooter : function() { + vent.trigger(vent.Commands.OpenControlPanelCommand, new FooterView({ + editorGrid : this.editorGrid, + collection : this.movieCollection + })); + }, + + _setFilter : function(buttonContext) { + var mode = buttonContext.model.get('key'); + + this.movieCollection.setFilterMode(mode); + } +}); \ No newline at end of file diff --git a/src/UI/Movies/Editor/MovieEditorLayoutTemplate.hbs b/src/UI/Movies/Editor/MovieEditorLayoutTemplate.hbs new file mode 100644 index 000000000..1d0519894 --- /dev/null +++ b/src/UI/Movies/Editor/MovieEditorLayoutTemplate.hbs @@ -0,0 +1,7 @@ + + +