working on U4-5687 Fix issues with mini content editor that is launched from new Edit button in MNTP - fixes the fileManager part.

This commit is contained in:
Shannon
2014-10-27 14:09:25 +10:00
parent 67ffeebe0d
commit 145229122c
5 changed files with 47 additions and 86 deletions

View File

@@ -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 });

View File

@@ -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();
});
angular.module('umbraco.services').factory('fileManager', fileManager);

View File

@@ -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();
});
}

View File

@@ -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,

View File

@@ -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; }));
});
}
});
};