Skip to content

Commit 35c92da

Browse files
authored
Merge pull request #91 from TheDMSGroup/ENG-370-ajax-warning
[ENG-370] Fix ajax warning w/ tokens and correct token functionality for overrides and file payloads.
2 parents 892a0aa + 70a5dd0 commit 35c92da

File tree

10 files changed

+221
-150
lines changed

10 files changed

+221
-150
lines changed

Assets/build/contactclient.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/build/contactclient.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/js/00.codemirror.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,27 @@ var CodeMirrorMustacheOverlay = function (config, parserConfig) {
2121
}
2222
if (ch === '}' && stream.next() === '}') {
2323
stream.eat('}');
24-
if (!window.CodeMirrorMustacheOverlayTokens.length && typeof window.JSONEditor.tokenCache['plugin:mauticContactClient:getTokens'] !== 'undefined') {
24+
if (
25+
!window.CodeMirrorMustacheOverlayTokens.length
26+
&& typeof window.JSONEditor.tokenCache !== 'undefined'
27+
&& typeof window.JSONEditor.tokenCache['plugin:mauticContactClient:getTokens'] !== 'undefined'
28+
) {
2529
mQuery.each(window.JSONEditor.tokenCache['plugin:mauticContactClient:getTokens'], function (key, value) {
2630
window.CodeMirrorMustacheOverlayTokens.push(key);
2731
});
2832
}
2933
var parts = word.split('|'),
3034
token = parts[0].trim(),
31-
tokenNoOpenClose = token.replace('#','').replace('/','');
32-
33-
if (window.CodeMirrorMustacheOverlayTokens.length && window.CodeMirrorMustacheOverlayTokens.indexOf(tokenNoOpenClose) === -1) {
35+
tokenNoOpenClose = token.replace('#', '').replace('/', '');
36+
if (
37+
window.CodeMirrorMustacheOverlayTokens.length
38+
&& window.CodeMirrorMustacheOverlayTokens.indexOf(tokenNoOpenClose) === -1
39+
) {
3440
return 'mustache-danger';
3541
}
3642
else if (typeof parts[1] !== 'undefined' || token[0] === '#' || token[0] === '/') {
37-
// Indicates a special token use (opening/closing/filter)
43+
// Indicates a special token use
44+
// (opening/closing/filter)
3845
return 'mustache-warn';
3946
}
4047
else {

Assets/js/05.file_payload.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Mautic.contactclientFilePayloadPre = function () {
88
if (typeof window.JSONEditor.tokenCache === 'undefined') {
99
window.JSONEditor.tokenCache = {};
1010
}
11+
if (typeof window.JSONEditor.tokenCacheTypes === 'undefined') {
12+
window.JSONEditor.tokenCacheTypes = {};
13+
}
14+
if (typeof window.JSONEditor.tokenCacheFormats === 'undefined') {
15+
window.JSONEditor.tokenCacheFormats = {};
16+
}
1117
if (typeof window.JSONEditor.tokenCache[tokenSource] === 'undefined') {
1218
window.JSONEditor.tokenCache[tokenSource] = {};
1319
window.JSONEditor.tokenCacheTypes[tokenSource] = {};
@@ -18,7 +24,7 @@ Mautic.contactclientFilePayloadPre = function () {
1824
data: {
1925
action: tokenSource,
2026
apiPayload: mQuery('#contactclient_api_payload:first').val(),
21-
filePayload: $filePayload
27+
filePayload: $filePayload.val()
2228
},
2329
cache: true,
2430
dataType: 'json',

Assets/js/09.integration.js

Lines changed: 183 additions & 131 deletions
Large diffs are not rendered by default.

Assets/js/14.token_helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// A date/time format helper modal to work in tandem with DateFormatHelper.php
1+
/* // A date/time format helper modal to work in tandem with DateFormatHelper.php
22
Mautic.contactclientTokenHelper = function (tokenSource, title, token, helper, type, field, selection) {
33
// Check that we don't already have a modal running, recreate?
44
mQuery('#tokenHelper').remove();
@@ -101,4 +101,4 @@ Mautic.contactclientTokenHelper = function (tokenSource, title, token, helper, t
101101
});
102102
})
103103
.modal('show');
104-
};
104+
}; */

Assets/json/file_payload.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@
701701
"title": "Value",
702702
"options": {
703703
"#comment": "These token properties are not standard, and only exist in this plugin.",
704+
"codeMirror": true,
704705
"tokenSource": "plugin:mauticContactClient:getTokens",
705706
"tokenPlaceholder": "Type a field name...",
706707
"infoText": "The value of the field being sent."

Assets/json/overrides.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"title": "Value",
3838
"options": {
3939
"#comment": "These token properties are not standard, and only exist in this plugin.",
40+
"codeMirror": true,
4041
"tokenSource": "plugin:mauticContactClient:getTokens",
4142
"tokenPlaceholder": "Type a field name...",
4243
"infoText": "The value of the field being sent."

Helper/TokenHelper.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ public function setContactClient(ContactClient $contactClient = null)
160160
}
161161

162162
/**
163-
* @param string $timzoneSource
164-
* @param string $timzoneDestination
163+
* @param string $timezoneSource
164+
* @param string $timezoneDestination
165165
*
166166
* @return $this
167167
*/
168-
public function setTimezones($timzoneSource = 'UTC', $timzoneDestination = 'UTC')
168+
public function setTimezones($timezoneSource = 'UTC', $timezoneDestination = 'UTC')
169169
{
170-
$this->dateFormatHelper = new DateFormatHelper($timzoneSource, $timzoneDestination);
170+
$this->dateFormatHelper = new DateFormatHelper($timezoneSource, $timezoneDestination);
171171
$this->engine->addHelper('date', $this->dateFormatHelper);
172172

173173
return $this;
@@ -281,8 +281,12 @@ public function addContextContact(Contact $contact = null)
281281
foreach ($fieldGroup as $fkey => $field) {
282282
$value = !empty($field['value']) ? $field['value'] : null;
283283
$type = !empty($field['type']) ? $field['type'] : null;
284-
if ($value && 'datetime' == $type) {
285-
$value = $this->dateFormatHelper->format($value);
284+
if ($value && in_array($type, ['datetime', 'date', 'time'])) {
285+
// Soft support for labels/values as dates/times.
286+
@$newValue = $this->dateFormatHelper->format($value);
287+
if (!empty($newValue)) {
288+
$value = $newValue;
289+
}
286290
}
287291
if ('core' == $fgKey) {
288292
$context[$fkey] = $value;

Integration/ClientIntegration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,12 @@ public function appendToForm(&$builder, $data, $formArea)
951951
'class' => 'btn btn-default',
952952
'tooltip' => 'mautic.contactclient.integration.overrides.tooltip',
953953
// Shim to get our javascript over the border and into Integration land.
954-
'onclick' => "if (typeof Mautic.contactclientIntegration === 'undefined') {".
954+
'onclick' => "if (typeof Mautic.contactclientIntegrationPre === 'undefined') {".
955955
" mQuery.getScript(mauticBasePath + '/' + mauticAssetPrefix + 'plugins/MauticContactClientBundle/Assets/build/contactclient.min.js', function(){".
956-
' Mautic.contactclientIntegration();'.
956+
' Mautic.contactclientIntegrationPre();'.
957957
' });'.
958958
'} else {'.
959-
' Mautic.contactclientIntegration();'.
959+
' Mautic.contactclientIntegrationPre();'.
960960
'}',
961961
'icon' => 'fa fa-wrench',
962962
],

0 commit comments

Comments
 (0)