Fix preview issue for new (empty) variants (#13455)

* Fix save and preview for new (unsaved) variants

* Rework & simplify
This commit is contained in:
Kenn Jacobsen
2022-11-23 08:34:39 +01:00
committed by GitHub
parent f13a9d419d
commit bce29f44f8

View File

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