From bc8f8366c29d81e091da9d65d0eff59566c97a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 20 Jan 2021 14:11:12 +0100 Subject: [PATCH 1/2] Call rebindCallback on errors as well (#9688) (cherry picked from commit 6d712b0d16b1f2d85c53d020fa68fb41bb0d3d5c) # Conflicts: # src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js # src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js --- .../components/content/edit.controller.js | 7 ++++++- .../services/contenteditinghelper.service.js | 17 ++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index d02c48750a..a47a3125c9 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -271,6 +271,7 @@ * @param {any} app the active content app */ function createButtons(content) { + // for trashed and element type items, the save button is the primary action - otherwise it's a secondary action $scope.page.saveButtonStyle = content.trashed || content.isElement || content.isBlueprint ? "primary" : "info"; @@ -468,6 +469,10 @@ return $q.when(data); }, function (err) { + + //needs to be manually set for infinite editing mode + $scope.page.isNew = false; + syncTreeNode($scope.content, $scope.content.path); resetNestedFieldValiation(fieldsToRollback); @@ -974,7 +979,7 @@ $scope.appChanged = function (activeApp) { $scope.activeApp = activeApp; - + _.forEach($scope.content.apps, function (app) { app.active = false; if (app.alias === $scope.activeApp.alias) { 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 4ffd0c3c0b..d469a6d24a 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 @@ -84,7 +84,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt //when true, the url will change but it won't actually re-route //this is merely here for compatibility, if only the content/media/members used this service we'd prob be ok but tons of editors //use this service unfortunately and probably packages too. - args.softRedirect = false; + args.softRedirect = false; } @@ -125,7 +125,10 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt softRedirect: args.softRedirect, err: err, rebindCallback: function () { - rebindCallback.apply(self, [args.content, err.data]); + // if the error contains data, we want to map that back as we want to continue editing this save. Especially important when the content is new as the returned data will contain ID etc. + if(err.data) { + rebindCallback.apply(self, [args.content, err.data]); + } } }); @@ -301,7 +304,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt } // if publishing is allowed also allow schedule publish - // we add this manually becuase it doesn't have a permission so it wont + // we add this manually becuase it doesn't have a permission so it wont // get picked up by the loop through permissions if (_.contains(args.content.allowedActions, "U")) { buttons.subButtons.push(createButtonDefinition("SCHEDULE")); @@ -625,7 +628,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt if (!args.err) { throw "args.err cannot be null"; } - + //When the status is a 400 status with a custom header: X-Status-Reason: Validation failed, 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 @@ -643,7 +646,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt if (!this.redirectToCreatedContent(args.err.data.id, args.softRedirect) || args.softRedirect) { // If we are not redirecting it's because this is not newly created content, else in some cases we are - // soft-redirecting which means the URL will change but the route wont (i.e. creating content). + // soft-redirecting which means the URL will change but the route wont (i.e. creating content). // In this case we need to detect what properties have changed and re-bind them with the server data. if (args.rebindCallback && angular.isFunction(args.rebindCallback)) { @@ -690,7 +693,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt if (!this.redirectToCreatedContent(args.redirectId ? args.redirectId : args.savedContent.id, args.softRedirect) || args.softRedirect) { // If we are not redirecting it's because this is not newly created content, else in some cases we are - // soft-redirecting which means the URL will change but the route wont (i.e. creating content). + // soft-redirecting which means the URL will change but the route wont (i.e. creating content). // In this case we need to detect what properties have changed and re-bind them with the server data. if (args.rebindCallback && angular.isFunction(args.rebindCallback)) { @@ -726,7 +729,7 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt navigationService.setSoftRedirect(); } //change to new path - $location.path("/" + $routeParams.section + "/" + $routeParams.tree + "/" + $routeParams.method + "/" + id); + $location.path("/" + $routeParams.section + "/" + $routeParams.tree + "/" + $routeParams.method + "/" + id); //don't add a browser history for this $location.replace(); return true; From 52e8da2ff2672a9d67d4d2a4d379a5f2cdc20bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 20 Jan 2021 14:26:40 +0100 Subject: [PATCH 2/2] Call rebindCallback on errors as well (#9690) (cherry picked from commit da0c82aabdfdb8ecf78f6abf7e890d06534e972b) --- .../directives/components/content/edit.controller.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index a47a3125c9..b26ec26d60 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -461,7 +461,7 @@ syncTreeNode($scope.content, data.path, false, args.reloadChildren); - eventsService.emit("content.saved", { content: $scope.content, action: args.action }); + eventsService.emit("content.saved", { content: $scope.content, action: args.action, valid: true }); resetNestedFieldValiation(fieldsToRollback); ensureDirtyIsSetIfAnyVariantIsDirty(); @@ -470,11 +470,14 @@ }, function (err) { - //needs to be manually set for infinite editing mode - $scope.page.isNew = false; syncTreeNode($scope.content, $scope.content.path); + if (err.status === 400 && err.data) { + // content was saved but is invalid. + eventsService.emit("content.saved", { content: $scope.content, action: args.action, valid: false }); + } + resetNestedFieldValiation(fieldsToRollback); return $q.reject(err);