Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit 8bc5a7b

Browse files
authored
Merge pull request #196 from Matthew-Wise/getpreview-195
Fix for 195
2 parents 693fb87 + 1aeb016 commit 8bc5a7b

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/Our.Umbraco.DocTypeGridEditor/Web/Controllers/DocTypeGridEditorApiController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUr
159159
}
160160

161161
// Set the culture for the preview
162-
if (page != null)
162+
if (page != null && page.Cultures != null)
163163
{
164-
var currentCulture = page.GetCultureFromDomains();
165-
if (page.Cultures != null && page.Cultures.ContainsKey(currentCulture))
164+
var currentCulture = string.IsNullOrWhiteSpace(data.Culture) ? page.GetCultureFromDomains() : data.Culture;
165+
if (currentCulture != null && page.Cultures.ContainsKey(currentCulture))
166166
{
167167
var culture = new CultureInfo(page.Cultures[currentCulture].Culture);
168168
UmbracoContext.PublishedRequest.Culture = culture;

src/Our.Umbraco.DocTypeGridEditor/Web/Models/PreviewData.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ public class PreviewData
2222

2323
[DataMember(Name = "viewPath")]
2424
public string ViewPath { get; set; }
25+
26+
[DataMember(Name = "culture")]
27+
public string Culture { get; set; }
2528
}
2629
}

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.controllers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@
151151

152152
$scope.setPreview = function (model) {
153153
if ($scope.control.editor.config && "enablePreview" in $scope.control.editor.config && $scope.control.editor.config.enablePreview) {
154+
var activeVariant = editorState.current.variants.find(v => v.active);
155+
var culture = activeVariant ? activeVariant.language.culture : null;
154156
dtgeResources.getEditorMarkupForDocTypePartial(editorState.current.id, model.id,
155157
$scope.control.editor.alias, model.dtgeContentTypeAlias, model.value,
156158
$scope.control.editor.config.viewPath,
157159
$scope.control.editor.config.previewViewPath,
158-
!!editorState.current.publishDate)
160+
!!editorState.current.publishDate, culture)
159161
.then(function (response) {
160162
var htmlResult = response.data;
161163
if (htmlResult.trim().length > 0) {

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.resources.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'Failed to retrieve datatypes'
3535
);
3636
},
37-
getEditorMarkupForDocTypePartial: function (pageId, id, editorAlias, contentTypeAlias, value, viewPath, previewViewPath, published) {
37+
getEditorMarkupForDocTypePartial: function (pageId, id, editorAlias, contentTypeAlias, value, viewPath, previewViewPath, published, culture) {
3838
var url = Umbraco.Sys.ServerVariables.umbracoSettings.umbracoPath + "/backoffice/DocTypeGridEditorApi/DocTypeGridEditorApi/GetPreviewMarkup?dtgePreview=1&pageId=" + pageId;
3939
return $http({
4040
method: 'POST',
@@ -45,7 +45,8 @@
4545
contentTypeAlias: contentTypeAlias,
4646
value: JSON.stringify(value),
4747
viewPath: viewPath,
48-
previewViewPath: previewViewPath
48+
previewViewPath: previewViewPath,
49+
culture: culture
4950
}),
5051
headers: {
5152
'Content-Type': 'application/x-www-form-urlencoded'

0 commit comments

Comments
 (0)