From 4b7520b6f84ae45f684eb4d8ca681fabe37c14b8 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Feb 2019 12:06:55 +1100 Subject: [PATCH] Updates the validation warning for media and members --- .../components/content/edit.controller.js | 67 +++++++++---------- .../src/views/media/media.edit.controller.js | 30 ++++++--- .../views/member/member.edit.controller.js | 26 ++++--- 3 files changed, 70 insertions(+), 53 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 5fad72f316..e5b0dbf201 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 @@ -810,47 +810,42 @@ }; $scope.preview = function (content) { + // Chromes popup blocker will kick in if a window is opened + // without the initial scoped request. This trick will fix that. + // + var previewWindow = $window.open('preview/?init=true', 'umbpreview'); + // Build the correct path so both /#/ and #/ work. + var query = 'id=' + content.id; + if ($scope.culture) { + query += "#?culture=" + $scope.culture; + } + var redirect = Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/preview/?' + query; - if (!$scope.busy) { - - // Chromes popup blocker will kick in if a window is opened - // without the initial scoped request. This trick will fix that. - // - var previewWindow = $window.open('preview/?init=true', 'umbpreview'); - - // Build the correct path so both /#/ and #/ work. - var query = 'id=' + content.id; + //The user cannot save if they don't have access to do that, in which case we just want to preview + //and that's it otherwise they'll get an unauthorized access message + if (!_.contains(content.allowedActions, "A")) { + previewWindow.location.href = redirect; + } + else { + var selectedVariant = $scope.content.variants[0]; if ($scope.culture) { - query += "#?culture=" + $scope.culture; - } - var redirect = Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/preview/?' + query; - - //The user cannot save if they don't have access to do that, in which case we just want to preview - //and that's it otherwise they'll get an unauthorized access message - if (!_.contains(content.allowedActions, "A")) { - previewWindow.location.href = redirect; - } - else { - var selectedVariant = $scope.content.variants[0]; - if ($scope.culture) { - var found = _.find($scope.content.variants, function (v) { - return (v.language && v.language.culture === $scope.culture); - }); - - if(found){ - selectedVariant = found; - } - } - - //ensure the save flag is set - selectedVariant.save = true; - performSave({ saveMethod: $scope.saveMethod(), action: "save" }).then(function (data) { - previewWindow.location.href = redirect; - }, function (err) { - //validation issues .... + var found = _.find($scope.content.variants, function (v) { + return (v.language && v.language.culture === $scope.culture); }); + + if (found) { + selectedVariant = found; + } } + + //ensure the save flag is set + selectedVariant.save = true; + performSave({ saveMethod: $scope.saveMethod(), action: "save" }).then(function (data) { + previewWindow.location.href = redirect; + }, function (err) { + //validation issues .... + }); } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js index 1f898230ac..8dda2d6669 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js @@ -7,7 +7,7 @@ * The controller for the media editor */ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, - entityResource, navigationService, notificationsService, angularHelper, + entityResource, navigationService, notificationsService, localizationService, serverValidationManager, contentEditingHelper, fileManager, formHelper, editorState, umbRequestHelper, $http, eventsService) { @@ -155,12 +155,25 @@ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, }); } } - + + /** Just shows a simple notification that there are client side validation issues to be fixed */ + function showValidationNotification() { + //TODO: We need to make the validation UI much better, there's a lot of inconsistencies in v8 including colors, issues with the property groups and validation errors between variants + + //need to show a notification else it's not clear there was an error. + localizationService.localizeMany([ + "speechBubbles_validationFailedHeader", + "speechBubbles_validationFailedMessage" + ] + ).then(function (data) { + notificationsService.error(data[0], data[1]); + }); + } + $scope.save = function () { - if (!$scope.busy && formHelper.submitForm({ scope: $scope })) { - - $scope.busy = true; + if (formHelper.submitForm({ scope: $scope })) { + $scope.page.saveButtonState = "busy"; mediaResource.save($scope.content, create, fileManager.getFiles()) @@ -176,7 +189,6 @@ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, }); editorState.set($scope.content); - $scope.busy = false; syncTreeNode($scope.content, data.path); @@ -199,12 +211,12 @@ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, }); editorState.set($scope.content); - $scope.busy = false; $scope.page.saveButtonState = "error"; }); - }else{ - $scope.busy = false; + } + else { + showValidationNotification(); } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js index a3c74c56d1..bf32f83c4e 100644 --- a/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/member/member.edit.controller.js @@ -6,7 +6,7 @@ * @description * The controller for the member editor */ -function MemberEditController($scope, $routeParams, $location, $q, $window, appState, memberResource, entityResource, navigationService, notificationsService, angularHelper, serverValidationManager, contentEditingHelper, fileManager, formHelper, umbModelMapper, editorState, umbRequestHelper, $http) { +function MemberEditController($scope, $routeParams, $location, appState, memberResource, entityResource, navigationService, notificationsService, localizationService, serverValidationManager, contentEditingHelper, fileManager, formHelper, editorState, umbRequestHelper, $http) { //setup scope vars $scope.page = {}; @@ -18,7 +18,6 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS $scope.page.listViewPath = null; $scope.page.saveButtonState = "init"; $scope.page.exportButton = "init"; - $scope.busy = false; $scope.page.listViewPath = ($routeParams.page && $routeParams.listName) ? "/member/member/list/" + $routeParams.listName + "?page=" + $routeParams.page @@ -131,14 +130,26 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS if(content.membershipScenario === 0) { $scope.page.nameLocked = true; } + } + /** Just shows a simple notification that there are client side validation issues to be fixed */ + function showValidationNotification() { + //TODO: We need to make the validation UI much better, there's a lot of inconsistencies in v8 including colors, issues with the property groups and validation errors between variants + + //need to show a notification else it's not clear there was an error. + localizationService.localizeMany([ + "speechBubbles_validationFailedHeader", + "speechBubbles_validationFailedMessage" + ] + ).then(function (data) { + notificationsService.error(data[0], data[1]); + }); } $scope.save = function() { - if (!$scope.busy && formHelper.submitForm({ scope: $scope })) { + if (formHelper.submitForm({ scope: $scope })) { - $scope.busy = true; $scope.page.saveButtonState = "busy"; memberResource.save($scope.content, $routeParams.create, fileManager.getFiles()) @@ -155,7 +166,6 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS }); editorState.set($scope.content); - $scope.busy = false; $scope.page.saveButtonState = "success"; var path = buildTreePath(data); @@ -172,12 +182,12 @@ function MemberEditController($scope, $routeParams, $location, $q, $window, appS }); editorState.set($scope.content); - $scope.busy = false; $scope.page.saveButtonState = "error"; }); - }else{ - $scope.busy = false; + } + else { + showValidationNotification(); } };