Skip to content

Commit 5702f90

Browse files
committed
Fix RealTime forms rendering mode.
1 parent 52146e1 commit 5702f90

File tree

9 files changed

+69
-23
lines changed

9 files changed

+69
-23
lines changed

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/Render/DynamicsForm.cshtml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var id = Guid.NewGuid();
77
}
88

9-
@if (string.IsNullOrEmpty(Model.RawHtml))
9+
@if (Model.Module == Umbraco.Cms.Integrations.Crm.Dynamics.Models.DynamicsModule.Outbound)
1010
{
1111
@if (Model.IframeEmbedded)
1212
{
@@ -28,5 +28,12 @@
2828
}
2929
else
3030
{
31-
@Html.Raw(Model.RawHtml)
31+
@if (Model.IframeEmbedded)
32+
{
33+
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id src="@Model.StandaloneUrl"></iframe>
34+
}
35+
else
36+
{
37+
@Html.Raw(Model.Html)
38+
}
3239
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/Render/DynamicsFormV8.cshtml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
var id = Guid.NewGuid();
77
}
88

9-
@if (!string.IsNullOrEmpty(Model.RawHtml))
9+
@if (Model.Module == Umbraco.Cms.Integrations.Crm.Dynamics.Models.DynamicsModule.Outbound)
1010
{
1111
@if (Model.IframeEmbedded)
1212
{
@@ -26,8 +26,14 @@
2626
data-website-id="@Model.WebsiteId" data-hostname="@Model.Hostname"></div>
2727
}
2828
}
29-
3029
else
3130
{
32-
@Html.Raw(Model.RawHtml)
31+
@if (Model.IframeEmbedded)
32+
{
33+
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id src="@Model.StandaloneUrl"></iframe>
34+
}
35+
else
36+
{
37+
@Html.Raw(Model.Html)
38+
}
3339
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/formpickereditor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</li>
2828
</ul>
2929
</div>
30-
<div class="dynOverlayGroup" ng-if="vm.isConnected && vm.selectedForm.module == 'Outbound'">
30+
<div class="dynOverlayGroup" ng-if="vm.isConnected">
3131
<umb-toggle checked="vm.iframeEmbedded"
3232
on-click="vm.toggleRenderMode()"
3333
show-labels="true"

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/module-configuration.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
</li>
1313
<li>
1414
<umb-radiobutton name="moduleConfiguration"
15-
value="Real-Time"
15+
value="RealTime"
1616
model="model.value"
17-
text="Real-Time"
17+
text="RealTime"
1818
required="true">
1919
</umb-radiobutton>
2020
</li>

src/Umbraco.Cms.Integrations.Crm.Dynamics/Editors/DynamicsFormPickerValueConverter.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,33 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub
4141

4242
var jObject = JObject.Parse(source.ToString());
4343

44-
var vm = new FormViewModel();
44+
var vm = new FormViewModel
45+
{
46+
IframeEmbedded = (bool)jObject["iframeEmbedded"]
47+
};
4548

4649
var module = (DynamicsModule)Enum.Parse(typeof(DynamicsModule), jObject["module"].ToString());
50+
51+
vm.Module = module;
52+
4753
if (module == DynamicsModule.Outbound)
4854
{
4955

5056
var embedCode = jObject["embedCode"].ToString();
51-
var iframeEmbedd = (bool)jObject["iframeEmbedded"];
5257

53-
vm = new FormViewModel
54-
{
55-
IframeEmbedded = iframeEmbedd,
56-
FormBlockId = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.DataFormBlockId),
57-
ContainerId = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.ContainerId),
58-
ContainerClass = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.ContainerClass),
59-
WebsiteId = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.DataWebsiteId),
60-
Hostname = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.DataHostname)
61-
};
58+
vm.FormBlockId = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.DataFormBlockId);
59+
vm.ContainerId = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.ContainerId);
60+
vm.ContainerClass = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.ContainerClass);
61+
vm.WebsiteId = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.DataWebsiteId);
62+
vm.Hostname = embedCode.ParseDynamicsEmbedCodeAttributeValue(Constants.EmbedAttribute.DataHostname);
6263
}
6364
else
6465
{
6566
var form = _dynamicsService.GetRealTimeForm(jObject["id"].ToString()).ConfigureAwait(false).GetAwaiter().GetResult();
66-
vm.RawHtml = form.RawHtml;
67+
if (form != null)
68+
{
69+
vm.Html = form.StandaloneHtml;
70+
}
6771
}
6872

6973
return vm;

src/Umbraco.Cms.Integrations.Crm.Dynamics/Models/Dtos/FormDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class FormDto
1313
[JsonProperty("rawHtml")]
1414
public string RawHtml { get; set; }
1515

16+
[JsonProperty("standaloneHtml")]
17+
public string StandaloneHtml { get; set; }
18+
1619
[JsonProperty("module")]
1720
public DynamicsModule Module { get; set; }
1821
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/Models/Dtos/RealTimeFormDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ public class RealTimeFormDto
1212

1313
[JsonProperty("msdynmkt_formhtml")]
1414
public string FormHtml { get; set; }
15+
16+
[JsonProperty("msdynmkt_standalonehtml")]
17+
public string StandaloneHtml { get; set; }
1518
}
1619
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/Models/ViewModels/FormViewModel.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
using System.Linq;
23

34
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Models.ViewModels
45
{
@@ -22,6 +23,27 @@ public class FormViewModel
2223
[JsonProperty("hostname")]
2324
public string Hostname { get; set; }
2425

25-
public string RawHtml { get; set; }
26+
public DynamicsModule Module { get; set; }
27+
28+
public string Html { get; set; }
29+
30+
public string StandaloneUrl
31+
{
32+
get
33+
{
34+
const string dataCachedFormUrlKey = "data-cached-form-url=";
35+
36+
var dataCachedFromUrl = Html.Split(' ').FirstOrDefault(p => p.Contains("data-cached-form-url"));
37+
if (string.IsNullOrEmpty(dataCachedFromUrl))
38+
{
39+
return string.Empty;
40+
}
41+
42+
return dataCachedFromUrl
43+
.Replace("'", "")
44+
.Substring(dataCachedFromUrl.IndexOf(dataCachedFormUrlKey) + dataCachedFormUrlKey.Length)
45+
.Replace("forms", "standaloneforms");
46+
}
47+
}
2648
}
2749
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/Services/DynamicsService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@ public async Task<FormDto> GetRealTimeForm(string id)
161161

162162
var forms = await Get<RealTimeFormDto>(oauthConfiguration.AccessToken, Constants.Modules.RealTimePath);
163163

164-
if (!forms.Value.Any(p => p.Id == id)) return null;
164+
if (forms == null || !forms.Value.Any(p => p.Id == id)) return null;
165165

166166
var form = forms.Value.First(p => p.Id == id);
167167
return new FormDto
168168
{
169-
RawHtml = form.FormHtml
169+
RawHtml = form.FormHtml,
170+
StandaloneHtml = form.StandaloneHtml
170171
};
171172
}
172173

0 commit comments

Comments
 (0)