Skip to content

Commit 14757d6

Browse files
committed
2 parents 882fcad + 4eb963a commit 14757d6

18 files changed

+337
-106
lines changed

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
@using Umbraco.Cms.Integrations.Crm.Dynamics.Models.ViewModels;
2+
@using Umbraco.Cms.Integrations.Crm.Dynamics.Models;
23

34
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<FormViewModel>
45

56
@{
67
var id = Guid.NewGuid();
78
}
89

9-
@if (Model.IframeEmbedded)
10+
@if (Model != null)
1011
{
11-
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id></iframe>
12-
<script>
13-
var sandboxSrc = "https://@(Model.Hostname)/t/formsandbox/@(Model.WebsiteId)/@(Model.FormBlockId)?ad="
14-
+ encodeURIComponent(document.location.toString()); document.getElementById('@id').setAttribute('src', sandboxSrc);
15-
</script>
12+
@if (Model.Module.HasFlag(DynamicsModule.Outbound))
13+
{
14+
@if (Model.IframeEmbedded)
15+
{
16+
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id></iframe>
17+
<script>
18+
var sandboxSrc = "https://@(Model.Hostname)/t/formsandbox/@(Model.WebsiteId)/@(Model.FormBlockId)?ad="
19+
+ encodeURIComponent(document.location.toString()); document.getElementById('@id').setAttribute('src', sandboxSrc);
20+
</script>
21+
}
22+
else
23+
{
24+
<div data-form-block-id="@Model.FormBlockId"></div>
25+
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/form-loader.js?v=1.84.2007"></script>
26+
<div id="@Model.ContainerId"></div>
27+
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/ws-tracking.js?v=1.84.2007"></script>
28+
<div class="@Model.ContainerClass" style="display:none"
29+
data-website-id="@Model.WebsiteId" data-hostname="@Model.Hostname"></div>
30+
}
31+
}
32+
else
33+
{
34+
@if (Model.IframeEmbedded)
35+
{
36+
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id src="@Model.StandaloneUrl"></iframe>
37+
}
38+
else
39+
{
40+
@Html.Raw(Model.Html)
41+
}
42+
}
1643
}
17-
else
18-
{
19-
<div data-form-block-id="@Model.FormBlockId"></div>
20-
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/form-loader.js?v=1.84.2007"></script>
21-
<div id="@Model.ContainerId"></div>
22-
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/ws-tracking.js?v=1.84.2007"></script>
23-
<div class="@Model.ContainerClass" style="display:none"
24-
data-website-id="@Model.WebsiteId" data-hostname="@Model.Hostname"></div>
25-
}

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

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

9-
@if (Model.IframeEmbedded)
9+
@if (Model != null)
1010
{
11-
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id></iframe>
12-
<script>
13-
var sandboxSrc = "https://@(Model.Hostname)/t/formsandbox/@(Model.WebsiteId)/@(Model.FormBlockId)?ad="
14-
+ encodeURIComponent(document.location.toString()); document.getElementById('@id').setAttribute('src', sandboxSrc);
15-
</script>
16-
}
17-
else
18-
{
19-
<div data-form-block-id="@Model.FormBlockId"></div>
20-
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/form-loader.js?v=1.84.2007"></script>
21-
<div id="@Model.ContainerId"></div>
22-
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/ws-tracking.js?v=1.84.2007"></script>
23-
<div class="@Model.ContainerClass" style="display:none"
24-
data-website-id="@Model.WebsiteId" data-hostname="@Model.Hostname"></div>
11+
@if (Model.Module.HasFlag(DynamicsModule.Outbound))
12+
{
13+
@if (Model.IframeEmbedded)
14+
{
15+
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id></iframe>
16+
<script>
17+
var sandboxSrc = "https://@(Model.Hostname)/t/formsandbox/@(Model.WebsiteId)/@(Model.FormBlockId)?ad="
18+
+ encodeURIComponent(document.location.toString()); document.getElementById('@id').setAttribute('src', sandboxSrc);
19+
</script>
20+
}
21+
else
22+
{
23+
<div data-form-block-id="@Model.FormBlockId"></div>
24+
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/form-loader.js?v=1.84.2007"></script>
25+
<div id="@Model.ContainerId"></div>
26+
<script src="https://mktdplp102cdn.azureedge.net/public/latest/js/ws-tracking.js?v=1.84.2007"></script>
27+
<div class="@Model.ContainerClass" style="display:none"
28+
data-website-id="@Model.WebsiteId" data-hostname="@Model.Hostname"></div>
29+
}
30+
}
31+
else
32+
{
33+
@if (Model.IframeEmbedded)
34+
{
35+
<iframe frameBorder="0" style="width:100%;height:100%;" id=@id src="@Model.StandaloneUrl"></iframe>
36+
}
37+
else
38+
{
39+
@Html.Raw(Model.Html)
40+
}
41+
}
2542
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/dynamics.resource.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
$http.get(`${apiEndpoint}/GetSystemUserFullName`),
2525
"Failed");
2626
},
27-
getForms: function () {
27+
getForms: function (module) {
2828
return umbRequestHelper.resourcePromise(
29-
$http.get(`${apiEndpoint}/GetForms`),
29+
$http.get(`${apiEndpoint}/GetForms?module=${module}`),
3030
"Failed");
3131
},
3232
getEmbedCode: function (formId) {

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/formpicker.controller.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@
1919

2020
vm.saveForm = function (form) {
2121

22-
umbracoCmsIntegrationsCrmDynamicsResource.getEmbedCode(form.id).then(function (response) {
22+
if (form.iframeEmbedded && form.module === "Outbound") {
23+
umbracoCmsIntegrationsCrmDynamicsResource.getEmbedCode(form.id).then(function (response) {
2324

24-
if (response.length == 0) {
25-
notificationsService.warning("Dynamics API", "Unable to embed selected form. Please check if it is live.");
26-
}
25+
if (response.length == 0) {
26+
notificationsService.warning("Dynamics API", "Unable to embed selected form. Please check if it is live.");
27+
}
2728

28-
form.embedCode = response;
29+
form.embedCode = response;
30+
});
31+
}
2932

30-
$scope.model.value = form;
31-
});
33+
$scope.model.value = form;
3234
}
3335

3436
vm.removeForm = function () {
@@ -41,13 +43,16 @@
4143

4244
vm.openDynamicsFormPickerOverlay = function () {
4345

46+
var module = $scope.model.config.module === "Both"
47+
? "Outbound | Real-Time"
48+
: $scope.model.config.module;
4449
var options = {
45-
title: "Dynamics - Marketing Forms",
50+
title: `Dynamics - ${module} Marketing Forms`,
4651
subtitle: "Select a form",
52+
module: $scope.model.config.module,
4753
view: "/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/formpickereditor.html",
4854
size: "medium",
4955
selectForm: function (form, iframeEmbedded) {
50-
5156
if (form.id !== undefined) {
5257
form.iframeEmbedded = iframeEmbedded;
5358

@@ -67,15 +72,14 @@
6772
function loadForms() {
6873
vm.loading = true;
6974
vm.formsLoading = true;
70-
umbracoCmsIntegrationsCrmDynamicsResource.getForms().then(function (response) {
75+
umbracoCmsIntegrationsCrmDynamicsResource.getForms($scope.model.module).then(function (response) {
7176
vm.dynamicsFormsList = [];
72-
if (response) {
73-
response.value.forEach(item => {
77+
if (response && response.length > 0) {
78+
response.forEach(item => {
7479
vm.dynamicsFormsList.push({
75-
id: item.msdyncrm_marketingformid,
76-
name: item.msdyncrm_name,
77-
embedCode: "",
78-
iframeEmbedded: vm.iframeEmbedded
80+
id: item.id,
81+
name: item.name,
82+
module: item.module
7983
});
8084
});
8185
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/package.manifest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"allowPackageTelemetry": true,
55
"javascript": [
66
"~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/configuration.controller.js",
7+
"~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/modules-configuration.controller.js",
78
"~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/formpicker.controller.js",
89
"~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/dynamics.resource.js",
910
"~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/js/oauthconfiguration.directive.js"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
</div>
1919
<div class="dynOverlayGroup" ng-if="vm.isConnected">
2020
<ul class="dynFormsList">
21-
<li ng-repeat="form in vm.dynamicsFormsList | orderBy:'name' | filter:vm.searchTerm" ng-click="vm.selectedForm = form"
21+
<li ng-repeat="form in vm.dynamicsFormsList | orderBy:'module' | filter:vm.searchTerm" ng-click="vm.selectedForm = form"
2222
ng-class="{ 'dynFormSelected': vm.selectedForm == form }" role="button" tabindex="0">
2323
<a href="" ng-attr-title="form.name">
2424
<i class="icon-umb-contour"></i>
25-
<span class="formLine">{{form.name}}</span>
25+
<span class="formLine">{{form.name}} - {{form.module}}</span>
2626
</a>
2727
</li>
2828
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<div>
2+
3+
<ng-form name="moduleConfigurationForm" class="flex">
4+
<ul class="inline">
5+
<li class="-no-padding-left">
6+
<umb-radiobutton name="moduleConfiguration"
7+
value="Outbound"
8+
model="model.value"
9+
text="Outbound"
10+
required="true">
11+
</umb-radiobutton>
12+
</li>
13+
<li>
14+
<umb-radiobutton name="moduleConfiguration"
15+
value="RealTime"
16+
model="model.value"
17+
text="RealTime"
18+
required="true">
19+
</umb-radiobutton>
20+
</li>
21+
<li>
22+
<umb-radiobutton name="moduleConfiguration"
23+
value="Both"
24+
model="model.value"
25+
text="Both"
26+
required="true">
27+
</umb-radiobutton>
28+
</li>
29+
</ul>
30+
31+
<span ng-messages="moduleConfigurationForm.moduleConfiguration.$error" show-validation-on-submit>
32+
<span class="help-inline" ng-message="required"><localize key="general_required">Required</localize></span>
33+
</span>
34+
</ng-form>
35+
</div>

src/Umbraco.Cms.Integrations.Crm.Dynamics/Constants.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,12 @@ public static class Configuration
5858

5959
public const string UmbracoCmsIntegrationsCrmDynamicsTokenEndpointKey = "Umbraco.Cms.Integrations.Crm.Dynamics.TokenEndpoint";
6060
}
61+
62+
public static class Modules
63+
{
64+
public const string OutboundPath = "msdyncrm_marketingforms";
65+
66+
public const string RealTimePath = "msdynmkt_marketingforms";
67+
}
6168
}
6269
}

src/Umbraco.Cms.Integrations.Crm.Dynamics/Controllers/FormsController.cs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@
1212
using Umbraco.Web.WebApi;
1313
#endif
1414
using System;
15-
using System.Collections.Generic;
16-
using System.Net;
1715
using System.Net.Http;
18-
using System.Net.Http.Headers;
1916
using System.Threading.Tasks;
20-
using Newtonsoft.Json;
21-
using Newtonsoft.Json.Linq;
2217
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
2318
using Umbraco.Cms.Integrations.Crm.Dynamics.Models.Dtos;
2419
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
25-
using System.Linq;
2620
using static Umbraco.Cms.Integrations.Crm.Dynamics.DynamicsComposer;
21+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models;
22+
using System.Collections;
23+
using System.Collections.Generic;
2724

2825
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Controllers
2926
{
@@ -94,26 +91,8 @@ public async Task<string> GetAccessToken([FromBody] OAuthRequestDto authRequestD
9491
await _authorizationService.GetAccessTokenAsync(authRequestDto.Code);
9592

9693
[HttpGet]
97-
public async Task<ResponseDto<FormDto>> GetForms()
98-
{
99-
var oauthConfiguration = _dynamicsConfigurationService.GetOAuthConfiguration();
100-
101-
var requestMessage = new HttpRequestMessage
102-
{
103-
Method = HttpMethod.Get,
104-
RequestUri = new Uri($"{_settings.HostUrl}{_settings.ApiPath}msdyncrm_marketingforms")
105-
};
106-
requestMessage.Headers.Authorization =
107-
new AuthenticationHeaderValue("Bearer", oauthConfiguration.AccessToken);
108-
109-
var response = await ClientFactory().SendAsync(requestMessage);
110-
111-
if (!response.IsSuccessStatusCode) return null;
112-
113-
var result = await response.Content.ReadAsStringAsync();
114-
115-
return JsonConvert.DeserializeObject<ResponseDto<FormDto>>(result);
116-
}
94+
public async Task<IEnumerable<FormDto>> GetForms(string module) =>
95+
await _dynamicsService.GetForms((DynamicsModule)Enum.Parse(typeof(DynamicsModule), module));
11796

11897
[HttpGet]
11998
public async Task<string> GetEmbedCode(string formId) => await _dynamicsService.GetEmbedCode(formId);

src/Umbraco.Cms.Integrations.Crm.Dynamics/DynamicsFormPickerConfiguration.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ namespace Umbraco.Cms.Integrations.Crm.Dynamics
99
{
1010
public class DynamicsFormPickerConfiguration
1111
{
12-
[ConfigurationField("configuration", name: "Configuration", view: "~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/configuration.html",
12+
[ConfigurationField("configuration",
13+
name: "Configuration",
14+
view: "~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/configuration.html",
1315
Description = "Connect with your Microsoft account.")]
1416
public string IsConnected { get; set; }
17+
18+
[ConfigurationField("module",
19+
name: "Modules",
20+
view: "~/App_Plugins/UmbracoCms.Integrations/Crm/Dynamics/views/module-configuration.html",
21+
Description = "Select the Microsoft Dynamics module you want to use."
22+
)]
23+
public string Module { get; set; }
1524
}
1625
}

0 commit comments

Comments
 (0)