From 145229122cc003030ee96ce84d174992e5e1a9a0 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 27 Oct 2014 14:09:25 +1000 Subject: [PATCH] working on U4-5687 Fix issues with mini content editor that is launched from new Edit button in MNTP - fixes the fileManager part. --- .../services/contenteditinghelper.service.js | 7 +- .../common/services/filemanager.service.js | 67 ++++++------------- .../common/dialogs/content/edit.controller.js | 29 +------- .../views/content/content.edit.controller.js | 1 - .../contentpicker/contentpicker.controller.js | 29 ++++++-- 5 files changed, 47 insertions(+), 86 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js index 64cba5e793..cd329995b7 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js @@ -5,7 +5,7 @@ * @description A helper service for most editors, some methods are specific to content/media/member model types but most are used by * all editors to share logic and reduce the amount of replicated code among editors. **/ -function contentEditingHelper($q, $location, $routeParams, notificationsService, serverValidationManager, dialogService, formHelper, appState, keyboardService) { +function contentEditingHelper(fileManager, $q, $location, $routeParams, notificationsService, serverValidationManager, dialogService, formHelper, appState, keyboardService) { return { @@ -14,9 +14,6 @@ function contentEditingHelper($q, $location, $routeParams, notificationsService, if (!angular.isObject(args)) { throw "args must be an object"; } - if (!args.fileManager) { - throw "args.fileManager is not defined"; - } if (!args.scope) { throw "args.scope is not defined"; } @@ -35,7 +32,7 @@ function contentEditingHelper($q, $location, $routeParams, notificationsService, var deferred = $q.defer(); if (formHelper.submitForm({ scope: args.scope, statusMessage: args.statusMessage })) { - args.saveMethod(args.content, $routeParams.create, args.fileManager.getFiles()) + args.saveMethod(args.content, $routeParams.create, fileManager.getFiles()) .then(function (data) { formHelper.resetForm({ scope: args.scope, notifications: data.notifications }); diff --git a/src/Umbraco.Web.UI.Client/src/common/services/filemanager.service.js b/src/Umbraco.Web.UI.Client/src/common/services/filemanager.service.js index a4ee1c31fb..4057623675 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/filemanager.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/filemanager.service.js @@ -1,29 +1,18 @@ - -//This is the file manager class, for the normal angular service 'fileManager' an instance of this class is returned, -// however in some cases we also want to create sub-instances (non-singleton) of this class. An example for this is the mini -// content editor that is launched from inside of a content editor. If the global singleton instance is used for both editors, then -// they will be sharing the same file collection state which will cause unwanted side affects. So in the mini editor, we create -// a standalone instance of the file manager and dipose of it when the scope disposes. -function FileManager() { +/** + * @ngdoc service + * @name umbraco.services.fileManager + * @function + * + * @description + * Used by editors to manage any files that require uploading with the posted data, normally called by property editors + * that need to attach files. + * When a route changes successfully, we ensure that the collection is cleared. + */ +function fileManager() { var fileCollection = []; return { - - /** - * @ngdoc function - * @name umbraco.services.fileManager#createStandaloneInstance - * @methodOf umbraco.services.fileManager - * @function - * - * @description - * Attaches files to the current manager for the current editor for a particular property, if an empty array is set - * for the files collection that effectively clears the files for the specified editor. - */ - createStandaloneInstance: function() { - return new FileManager(); - }, - /** * @ngdoc function * @name umbraco.services.fileManager#addFiles @@ -31,12 +20,10 @@ function FileManager() { * @function * * @description - * in some cases we want to create stand alone instances (non-singleton) of the fileManager. An example for this is the mini - * content editor that is launched from inside of a content editor. If the default global singleton instance is used for both editors, then - * they will be sharing the same file collection state which will cause unwanted side affects. So in the mini editor, we create - * a standalone instance of the file manager and dipose of it when the scope disposes. + * Attaches files to the current manager for the current editor for a particular property, if an empty array is set + * for the files collection that effectively clears the files for the specified editor. */ - setFiles: function (propertyAlias, files) { + setFiles: function(propertyAlias, files) { //this will clear the files for the current property and then add the new ones for the current property fileCollection = _.reject(fileCollection, function (item) { return item.alias === propertyAlias; @@ -46,7 +33,7 @@ function FileManager() { fileCollection.push({ alias: propertyAlias, file: files[i] }); } }, - + /** * @ngdoc function * @name umbraco.services.fileManager#getFiles @@ -56,10 +43,10 @@ function FileManager() { * @description * Returns all of the files attached to the file manager */ - getFiles: function () { + getFiles: function() { return fileCollection; }, - + /** * @ngdoc function * @name umbraco.services.fileManager#clearFiles @@ -72,23 +59,7 @@ function FileManager() { clearFiles: function () { fileCollection = []; } - }; +}; } - -angular.module('umbraco.services').factory('fileManager', - - /** - * @ngdoc service - * @name umbraco.services.fileManager - * @function - * - * @description - * Used by editors to manage any files that require uploading with the posted data, normally called by property editors - * that need to attach files. - * When a route changes successfully, we ensure that the collection is cleared. - */ - function () { - //return a new instance of a file Manager - this will be a singleton per app - return new FileManager(); - }); \ No newline at end of file +angular.module('umbraco.services').factory('fileManager', fileManager); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/content/edit.controller.js index d89cd1e8ac..fb82432586 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/content/edit.controller.js @@ -3,12 +3,10 @@ function ContentEditDialogController($scope, $routeParams, $q, $timeout, $window $scope.defaultButton = null; $scope.subButtons = []; var dialogOptions = $scope.$parent.dialogOptions; - var fileManagerInstance = fileManager.createStandaloneInstance(); // This is a helper method to reduce the amount of code repitition for actions: Save, Publish, SendToPublish function performSave(args) { contentEditingHelper.contentEditorPerformSave({ - fileManager: fileManagerInstance, statusMessage: args.statusMessage, saveMethod: args.saveMethod, scope: $scope, @@ -45,7 +43,7 @@ function ContentEditDialogController($scope, $routeParams, $q, $timeout, $window saveAndPublish: $scope.saveAndPublish, sendToPublish: $scope.sendToPublish, save: $scope.save, - unPublish: $scope.unPublish + unPublish: angular.noop } }); $scope.defaultButton = buttons.defaultButton; @@ -72,27 +70,6 @@ function ContentEditDialogController($scope, $routeParams, $q, $timeout, $window }); } - $scope.unPublish = function () { - - if (formHelper.submitForm({ scope: $scope, statusMessage: "Unpublishing...", skipValidation: true })) { - - contentResource.unPublish($scope.content.id) - .then(function (data) { - - formHelper.resetForm({ scope: $scope, notifications: data.notifications }); - - contentEditingHelper.handleSuccessfulSave({ - scope: $scope, - savedContent: data, - rebindCallback: contentEditingHelper.reBindChangedProperties($scope.content, data) - }); - - init($scope.content); - }); - } - - }; - $scope.sendToPublish = function () { performSave({ saveMethod: contentResource.sendToPublish, statusMessage: "Sending..." }); }; @@ -117,10 +94,6 @@ function ContentEditDialogController($scope, $routeParams, $q, $timeout, $window } }; - //dispose the file manager instance - $scope.$on('$destroy', function () { - fileManagerInstance.clearFiles(); - }); } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js index a1f0f513d5..675e5b597f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.edit.controller.js @@ -68,7 +68,6 @@ function ContentEditController($scope, $rootScope, $routeParams, $q, $timeout, $ // This is a helper method to reduce the amount of code repitition for actions: Save, Publish, SendToPublish function performSave(args) { contentEditingHelper.contentEditorPerformSave({ - fileManager: fileManager, statusMessage: args.statusMessage, saveMethod: args.saveMethod, scope: $scope, diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js index 3f2652179a..afb3743e0a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js @@ -3,7 +3,7 @@ angular.module('umbraco') .controller("Umbraco.PropertyEditors.ContentPickerController", - function($scope, dialogService, entityResource, editorState, $log, iconHelper, $routeParams){ + function ($scope, dialogService, entityResource, editorState, $log, iconHelper, $routeParams, fileManager) { $scope.renderModel = []; $scope.ids = $scope.model.value ? $scope.model.value.split(',') : []; @@ -68,14 +68,35 @@ angular.module('umbraco') }; $scope.edit = function (node) { + + //We need to store the current files selected in the file manager locally because the fileManager + //is a singleton and is shared globally. The mini dialog will also be referencing the fileManager + //and we don't want it to be sharing the same files as the main editor. So we'll store the current files locally here, + //clear them out and then launch the dialog. When the dialog closes, we'll reset the fileManager to it's previous state. + + var currFiles = _.groupBy(fileManager.getFiles(), "alias"); + fileManager.clearFiles(); + dialogService.open({ template: "views/common/dialogs/content/edit.html", id: node.id, closeOnSave:true, tabFilter: ["Generic properties"], - callback: function(data){ - node.name = data.name; - } + callback: function(data) { + node.name = data.name; + //reset the fileManager to what it was + fileManager.clearFiles(); + _.each(currFiles, function (val, key) { + fileManager.setFiles(key, _.map(currFiles['upload'], function (i) { return i.file; })); + }); + }, + closeCallback: function() { + //reset the fileManager to what it was + fileManager.clearFiles(); + _.each(currFiles, function(val, key) { + fileManager.setFiles(key, _.map(currFiles['upload'], function (i) { return i.file; })); + }); + } }); };