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 bddd95fbbe..02f6164f64 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 @@ -323,7 +323,6 @@ $scope.defaultButton = buttons.defaultButton; $scope.subButtons = buttons.subButtons; $scope.page.showPreviewButton = true; - } /** Syncs the content item to it's tree node - this occurs on first load and after saving */ @@ -938,22 +937,25 @@ }; $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; + const openPreviewWindow = () => { + // Chromes popup blocker will kick in if a window is opened + // without the initial scoped request. This trick will fix that. + // + const previewWindow = $window.open('preview/?init=true', 'umbpreview'); + + // Build the correct path so both /#/ and #/ work. + let query = 'id=' + content.id; + if ($scope.culture) { + query += "#?culture=" + $scope.culture; + } + previewWindow.location.href = Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + '/preview/?' + query; } - 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; + openPreviewWindow(); } else { var selectedVariant = $scope.content.variants[0]; @@ -967,10 +969,12 @@ } } - //ensure the save flag is set + //reset save flag for all variants + $scope.content.variants.forEach(variant => variant.save = false); + //ensure the save flag is set for the active variant selectedVariant.save = true; performSave({ saveMethod: $scope.saveMethod(), action: "save" }).then(function (data) { - previewWindow.location.href = redirect; + openPreviewWindow() }, function (err) { //validation issues .... });