Skip to content

Commit

Permalink
Merge pull request #91 from TheDMSGroup/ENG-370-ajax-warning
Browse files Browse the repository at this point in the history
[ENG-370] Fix ajax warning w/ tokens and correct token functionality for overrides and file payloads.
  • Loading branch information
heathdutton authored Jul 3, 2018
2 parents 892a0aa + 70a5dd0 commit 35c92da
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Assets/build/contactclient.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Assets/build/contactclient.min.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions Assets/js/00.codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ var CodeMirrorMustacheOverlay = function (config, parserConfig) {
}
if (ch === '}' && stream.next() === '}') {
stream.eat('}');
if (!window.CodeMirrorMustacheOverlayTokens.length && typeof window.JSONEditor.tokenCache['plugin:mauticContactClient:getTokens'] !== 'undefined') {
if (
!window.CodeMirrorMustacheOverlayTokens.length
&& typeof window.JSONEditor.tokenCache !== 'undefined'
&& typeof window.JSONEditor.tokenCache['plugin:mauticContactClient:getTokens'] !== 'undefined'
) {
mQuery.each(window.JSONEditor.tokenCache['plugin:mauticContactClient:getTokens'], function (key, value) {
window.CodeMirrorMustacheOverlayTokens.push(key);
});
}
var parts = word.split('|'),
token = parts[0].trim(),
tokenNoOpenClose = token.replace('#','').replace('/','');

if (window.CodeMirrorMustacheOverlayTokens.length && window.CodeMirrorMustacheOverlayTokens.indexOf(tokenNoOpenClose) === -1) {
tokenNoOpenClose = token.replace('#', '').replace('/', '');
if (
window.CodeMirrorMustacheOverlayTokens.length
&& window.CodeMirrorMustacheOverlayTokens.indexOf(tokenNoOpenClose) === -1
) {
return 'mustache-danger';
}
else if (typeof parts[1] !== 'undefined' || token[0] === '#' || token[0] === '/') {
// Indicates a special token use (opening/closing/filter)
// Indicates a special token use
// (opening/closing/filter)
return 'mustache-warn';
}
else {
Expand Down
8 changes: 7 additions & 1 deletion Assets/js/05.file_payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Mautic.contactclientFilePayloadPre = function () {
if (typeof window.JSONEditor.tokenCache === 'undefined') {
window.JSONEditor.tokenCache = {};
}
if (typeof window.JSONEditor.tokenCacheTypes === 'undefined') {
window.JSONEditor.tokenCacheTypes = {};
}
if (typeof window.JSONEditor.tokenCacheFormats === 'undefined') {
window.JSONEditor.tokenCacheFormats = {};
}
if (typeof window.JSONEditor.tokenCache[tokenSource] === 'undefined') {
window.JSONEditor.tokenCache[tokenSource] = {};
window.JSONEditor.tokenCacheTypes[tokenSource] = {};
Expand All @@ -18,7 +24,7 @@ Mautic.contactclientFilePayloadPre = function () {
data: {
action: tokenSource,
apiPayload: mQuery('#contactclient_api_payload:first').val(),
filePayload: $filePayload
filePayload: $filePayload.val()
},
cache: true,
dataType: 'json',
Expand Down
314 changes: 183 additions & 131 deletions Assets/js/09.integration.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Assets/js/14.token_helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// A date/time format helper modal to work in tandem with DateFormatHelper.php
/* // A date/time format helper modal to work in tandem with DateFormatHelper.php
Mautic.contactclientTokenHelper = function (tokenSource, title, token, helper, type, field, selection) {
// Check that we don't already have a modal running, recreate?
mQuery('#tokenHelper').remove();
Expand Down Expand Up @@ -101,4 +101,4 @@ Mautic.contactclientTokenHelper = function (tokenSource, title, token, helper, t
});
})
.modal('show');
};
}; */
1 change: 1 addition & 0 deletions Assets/json/file_payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@
"title": "Value",
"options": {
"#comment": "These token properties are not standard, and only exist in this plugin.",
"codeMirror": true,
"tokenSource": "plugin:mauticContactClient:getTokens",
"tokenPlaceholder": "Type a field name...",
"infoText": "The value of the field being sent."
Expand Down
1 change: 1 addition & 0 deletions Assets/json/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"title": "Value",
"options": {
"#comment": "These token properties are not standard, and only exist in this plugin.",
"codeMirror": true,
"tokenSource": "plugin:mauticContactClient:getTokens",
"tokenPlaceholder": "Type a field name...",
"infoText": "The value of the field being sent."
Expand Down
16 changes: 10 additions & 6 deletions Helper/TokenHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ public function setContactClient(ContactClient $contactClient = null)
}

/**
* @param string $timzoneSource
* @param string $timzoneDestination
* @param string $timezoneSource
* @param string $timezoneDestination
*
* @return $this
*/
public function setTimezones($timzoneSource = 'UTC', $timzoneDestination = 'UTC')
public function setTimezones($timezoneSource = 'UTC', $timezoneDestination = 'UTC')
{
$this->dateFormatHelper = new DateFormatHelper($timzoneSource, $timzoneDestination);
$this->dateFormatHelper = new DateFormatHelper($timezoneSource, $timezoneDestination);
$this->engine->addHelper('date', $this->dateFormatHelper);

return $this;
Expand Down Expand Up @@ -281,8 +281,12 @@ public function addContextContact(Contact $contact = null)
foreach ($fieldGroup as $fkey => $field) {
$value = !empty($field['value']) ? $field['value'] : null;
$type = !empty($field['type']) ? $field['type'] : null;
if ($value && 'datetime' == $type) {
$value = $this->dateFormatHelper->format($value);
if ($value && in_array($type, ['datetime', 'date', 'time'])) {
// Soft support for labels/values as dates/times.
@$newValue = $this->dateFormatHelper->format($value);
if (!empty($newValue)) {
$value = $newValue;
}
}
if ('core' == $fgKey) {
$context[$fkey] = $value;
Expand Down
6 changes: 3 additions & 3 deletions Integration/ClientIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,12 @@ public function appendToForm(&$builder, $data, $formArea)
'class' => 'btn btn-default',
'tooltip' => 'mautic.contactclient.integration.overrides.tooltip',
// Shim to get our javascript over the border and into Integration land.
'onclick' => "if (typeof Mautic.contactclientIntegration === 'undefined') {".
'onclick' => "if (typeof Mautic.contactclientIntegrationPre === 'undefined') {".
" mQuery.getScript(mauticBasePath + '/' + mauticAssetPrefix + 'plugins/MauticContactClientBundle/Assets/build/contactclient.min.js', function(){".
' Mautic.contactclientIntegration();'.
' Mautic.contactclientIntegrationPre();'.
' });'.
'} else {'.
' Mautic.contactclientIntegration();'.
' Mautic.contactclientIntegrationPre();'.
'}',
'icon' => 'fa fa-wrench',
],
Expand Down

0 comments on commit 35c92da

Please sign in to comment.