Fixed what the merge before broke

This commit is contained in:
Per Ploug Krogslund
2013-07-28 01:05:56 +02:00
parent f9f54b3ee7
commit 9592c44849
2 changed files with 16 additions and 165 deletions

View File

@@ -9,9 +9,9 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
return {
/**
* @ngdoc function
* @name getAllProps
* @methodOf contentEditingHelper
* @ngdoc method
* @name umbraco.services.contentEditingHelper#getAllProps
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
@@ -30,9 +30,9 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
},
/**
* @ngdoc function
* @name reBindChangedProperties
* @methodOf contentEditingHelper
* @ngdoc method
* @name umbraco.services.contentEditingHelper#reBindChangedProperties
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
@@ -65,9 +65,9 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
},
/**
* @ngdoc function
* @name handleValidationErrors
* @methodOf contentEditingHelper
* @ngdoc method
* @name umbraco.services.contentEditingHelper#handleValidationErrors
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
@@ -122,8 +122,8 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
/**
* @ngdoc function
* @name handleSaveError
* @methodOf contentEditingHelper
* @name umbraco.services.contentEditingHelper#handleSaveError
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
@@ -163,8 +163,8 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
/**
* @ngdoc function
* @name handleSaveError
* @methodOf handleSuccessfulSave
* @name umbraco.services.contentEditingHelper#handleSaveError
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
@@ -201,8 +201,8 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
/**
* @ngdoc function
* @name redirectToCreatedContent
* @methodOf contentEditingHelper
* @name umbraco.services.contentEditingHelper#redirectToCreatedContent
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description

View File

@@ -408,153 +408,4 @@ function iconHelper() {
}
};
}
angular.module('umbraco.services').factory('iconHelper', iconHelper);
/**
* @ngdoc service
* @name umbraco.services.contentEditingHelper
* @description A helper service for content controllers when editing/creating/saving content.
**/
function contentEditingHelper($location, $routeParams, notificationsService, serverValidationManager) {
return {
/**
* @ngdoc method
* @name umbraco.services.contentEditingHelper#handleValidationErrors
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
* A function to handle the validation (ModelState) errors collection which will happen on a 403 error indicating validation errors
* It's worth noting that when a 403 occurs, the data is still saved just never published, though this depends on if the entity is a new
* entity and whether or not the data fulfils the absolute basic requirements like having a mandatory Name.
*/
handleValidationErrors: function (content, modelState) {
//get a list of properties since they are contained in tabs
var allProps = [];
for (var i = 0; i < content.tabs.length; i++) {
for (var p = 0; p < content.tabs[i].properties.length; p++) {
allProps.push(content.tabs[i].properties[p]);
}
}
//find the content property for the current error, for use in the loop below
function findContentProp(props, propAlias) {
return _.find(props, function (item) {
return (item.alias === propAlias);
});
}
for (var e in modelState) {
//the alias in model state can be in dot notation which indicates
// * the first part is the content property alias
// * the second part is the field to which the valiation msg is associated with
//There will always be at least 2 parts since all model errors for properties are prefixed with "Properties"
var parts = e.split(".");
if (parts.length > 1) {
var propertyAlias = parts[1];
//find the content property for the current error
var contentProperty = findContentProp(allProps, propertyAlias);
if (contentProperty) {
//if it contains 2 '.' then we will wire it up to a property's field
if (parts.length > 2) {
//add an error with a reference to the field for which the validation belongs too
serverValidationManager.addPropertyError(contentProperty, parts[2], modelState[e][0]);
}
else {
//add a generic error for the property, no reference to a specific field
serverValidationManager.addPropertyError(contentProperty, "", modelState[e][0]);
}
}
}
else {
//the parts are only 1, this means its not a property but a native content property
serverValidationManager.addFieldError(parts[0], modelState[e][0]);
}
//add to notifications
notificationsService.error("Validation", modelState[e][0]);
}
},
/**
* @ngdoc method
* @name umbraco.services.contentEditingHelper#handleSaveError
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
* A function to handle what happens when we have validation issues from the server side
*/
handleSaveError: function (err) {
//When the status is a 403 status, we have validation errors.
//Otherwise the error is probably due to invalid data (i.e. someone mucking around with the ids or something).
//Or, some strange server error
if (err.status === 403) {
//now we need to look through all the validation errors
if (err.data && (err.data.ModelState)) {
this.handleValidationErrors(err.data, err.data.ModelState);
if (!this.redirectToCreatedContent(err.data.id, err.data.ModelState)) {
//we are not redirecting because this is not new content, it is existing content. In this case
// we need to clear the server validation items. When we are creating new content we cannot clear
// the server validation items because we redirect and they need to persist until the validation is re-bound.
serverValidationManager.clear();
}
//indicates we've handled the server result
return true;
}
else {
//TODO: Implement an overlay showing the full YSOD like we had in v5
notificationsService.error("Server error", err);
}
}
else {
//TODO: Implement an overlay showing the full YSOD like we had in v5
notificationsService.error("Validation failed", err);
}
return false;
},
/**
* @ngdoc method
* @name umbraco.services.contentEditingHelper#redirectToCreatedContent
* @methodOf umbraco.services.contentEditingHelper
* @function
*
* @description
* Changes the location to be editing the newly created content after create was successful.
* We need to decide if we need to redirect to edito mode or if we will remain in create mode.
* We will only need to maintain create mode if we have not fulfilled the basic requirements for creating an entity which is at least having a name.
*/
redirectToCreatedContent: function (id, modelState) {
//only continue if we are currently in create mode and if there is no 'Name' modelstate errors
// since we need at least a name to create content.
if ($routeParams.create && (!modelState || !modelState["Name"])) {
//need to change the location to not be in 'create' mode. Currently the route will be something like:
// /belle/#/content/edit/1234?doctype=newsArticle&create=true
// but we need to remove everything after the query so that it is just:
// /belle/#/content/edit/9876 (where 9876 is the new id)
//clear the query strings
$location.search(null);
//change to new path
$location.path("/" + $routeParams.section + "/" + $routeParams.method + "/" + id);
//don't add a browser history for this
$location.replace();
return true;
}
return false;
}
};
}
angular.module('umbraco.services').factory('contentEditingHelper', contentEditingHelper);
angular.module('umbraco.services').factory('iconHelper', iconHelper);