Skip to content

Commit 6e8a988

Browse files
authored
Merge pull request #4 from TheDMSGroup/ENG-91-autocomplete-tokens
[ENG-119] Initial codemirror support for Raw and other JS improvements.
2 parents 05e1534 + c098b60 commit 6e8a988

15 files changed

+202
-137
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
.idea
2-
composer.lock
1+
# Standard .gitignore for a Mautic plugin.
2+
.*
3+
!.gitignore
4+
!.htaccess
5+
!.gitkeep
6+
!.travis.yml
37
vendor
48
node_modules

.travis.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Standard .travis.yml for a Mautic plugin. Adjust env variables as needed.
2+
env:
3+
global:
4+
# The exact plugin folder/bundle name.
5+
- "MAUTIC_PLUGIN=MauticContactClientBundle"
6+
7+
dist: precise
8+
9+
language: php
10+
11+
services:
12+
- mysql
13+
14+
php:
15+
- 5.6.19
16+
- 7.0
17+
- 7.1
18+
19+
before_install:
20+
21+
# Create mautictest database.
22+
- mysql -e 'CREATE DATABASE mautictest;'
23+
24+
# Turn off XDebug.
25+
- phpenv config-rm xdebug.ini || return
26+
27+
# Install dependencies in parallel.
28+
- travis_retry composer global require hirak/prestissimo
29+
30+
# Set to test environment for Symfony's commands in post install commands.
31+
- export SYMFONY_ENV="test"
32+
33+
# Install PHPSTAN for PHP 7+
34+
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.6" ]]; then composer global require phpstan/phpstan-shim:0.8.5; fi
35+
36+
# Clone the latest core release.
37+
- git clone -b master --single-branch --depth 1 https://github.com/mautic/mautic.git /tmp/mautic
38+
39+
# Combine core with our plugin.
40+
- mkdir -p /tmp/mautic/plugins/$MAUTIC_PLUGIN
41+
- rsync -r --delete-after --quiet $TRAVIS_BUILD_DIR/ /tmp/mautic/plugins/$MAUTIC_PLUGIN
42+
- rsync -r --delete-after --quiet /tmp/mautic/ $TRAVIS_BUILD_DIR/
43+
44+
install:
45+
46+
# Install core dependencies.
47+
- composer install
48+
49+
# Install plugin dependencies (if any).
50+
- composer require wikimedia/composer-merge-plugin
51+
- composer config extra.merge-plugin.include plugins/$MAUTIC_PLUGIN/composer.json
52+
53+
script:
54+
55+
# Run PHPUnit including core tests to find potential BC breaks.
56+
- bin/phpunit --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --fail-on-warning
57+
58+
# Run PHPSTAN analysis for PHP 7+ only in the scope of this plugin.
59+
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.6" ]]; then ~/.composer/vendor/phpstan/phpstan-shim/phpstan.phar analyse plugins/$MAUTIC_PLUGIN; fi
60+
61+
# Check code standards for PHP 7.1 only in the scope of this plugin.
62+
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then bin/php-cs-fixer fix -v --dry-run --diff plugins/$MAUTIC_PLUGIN; fi

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/build/contactclient.min.js.map

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.type.js

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,48 @@
11
// Logic for the payload type switch.
22
Mautic.contactclientType = function () {
33

4-
if (typeof window.contactclientTypeLoaded === 'undefined') {
5-
window.contactclientTypeLoaded = true;
6-
// Trigger payload tab visibility based on contactClient type.
7-
mQuery('input[name="contactclient[type]"]').change(function () {
8-
var val = mQuery('input[name="contactclient[type]"]:checked').val();
9-
if (val === 'api') {
10-
mQuery('#payload-tab').removeClass('hide');
11-
mQuery('.row.api_payload').removeClass('hide');
12-
mQuery('.row.file_payload').addClass('hide');
4+
// Trigger payload tab visibility based on contactClient type.
5+
mQuery('input[name="contactclient[type]"]').change(function () {
6+
var val = mQuery('input[name="contactclient[type]"]:checked').val();
7+
if (val === 'api') {
8+
mQuery('#payload-tab').removeClass('hide');
9+
mQuery('.row.api_payload').removeClass('hide');
10+
mQuery('.row.file_payload').addClass('hide');
1311

14-
// Mautic.contactclientApiPayload();
15-
Mautic.contactclientApiPayloadPre();
16-
}
17-
else if (val === 'file') {
18-
mQuery('#payload-tab').removeClass('hide');
19-
mQuery('.row.api_payload').addClass('hide');
20-
mQuery('.row.file_payload').removeClass('hide');
12+
// Mautic.contactclientApiPayload();
13+
Mautic.contactclientApiPayloadPre();
14+
}
15+
else if (val === 'file') {
16+
mQuery('#payload-tab').removeClass('hide');
17+
mQuery('.row.api_payload').addClass('hide');
18+
mQuery('.row.file_payload').removeClass('hide');
19+
20+
Mautic.contactclientFilePayload();
21+
}
22+
else {
23+
mQuery('#payload-tab').addClass('hide');
24+
}
25+
}).first().parent().parent().find('label.active input:first').trigger('change');
2126

22-
Mautic.contactclientFilePayload();
27+
// Hide the right column when Payload tab is open to give more room for
28+
// table entry.
29+
var activeTab = '#details';
30+
mQuery('.contactclient-tab').click(function () {
31+
var thisTab = mQuery(this).attr('href');
32+
if (thisTab !== activeTab) {
33+
activeTab = thisTab;
34+
if (activeTab === '#payload') {
35+
// Expanded view.
36+
mQuery('.contactclient-left').addClass('col-md-12').removeClass('col-md-9');
37+
mQuery('.contactclient-right').addClass('hide');
2338
}
2439
else {
25-
mQuery('#payload-tab').addClass('hide');
26-
}
27-
}).first().parent().parent().find('label.active input:first').trigger('change');
28-
29-
// Hide the right column when Payload tab is open to give more room for
30-
// table entry.
31-
var activeTab = '#details';
32-
mQuery('.contactclient-tab').click(function () {
33-
var thisTab = mQuery(this).attr('href');
34-
if (thisTab !== activeTab) {
35-
activeTab = thisTab;
36-
if (activeTab === '#payload') {
37-
// Expanded view.
38-
mQuery('.contactclient-left').addClass('col-md-12').removeClass('col-md-9');
39-
mQuery('.contactclient-right').addClass('hide');
40-
}
41-
else {
42-
// Standard view.
43-
mQuery('.contactclient-left').removeClass('col-md-12').addClass('col-md-9');
44-
mQuery('.contactclient-right').removeClass('hide');
45-
}
40+
// Standard view.
41+
mQuery('.contactclient-left').removeClass('col-md-12').addClass('col-md-9');
42+
mQuery('.contactclient-right').removeClass('hide');
4643
}
47-
});
48-
}
44+
}
45+
});
4946
};
5047

5148
Mautic.contactclientTypeChange = function (t) {

Assets/js/02.json_editor.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,28 @@ JSONEditor.defaults.options.expand_height = true;
164164

165165
// Custom validators.
166166
JSONEditor.defaults.custom_validators.push(function (schema, value, path) {
167+
// When a textarea with option "codemirror" is true, render codemirror.
168+
if (schema.format === 'textarea' && typeof schema.options !== 'undefined' && schema.options.codemirror === true) {
169+
mQuery('textarea[name=\'' + path.replace('root.', 'root[').split('.').join('][') + ']\']:first:visible:not(.codemirror-checked)').each(function () {
170+
var $input = mQuery(this);
171+
editor = CodeMirror.fromTextArea($input[0], {
172+
// mode: {
173+
// name: 'javascript',
174+
// json: true
175+
// },
176+
theme: 'material',
177+
gutters: ['CodeMirror-lint-markers'],
178+
// lint: 'json',
179+
lintOnChange: true,
180+
matchBrackets: true,
181+
autoCloseBrackets: true,
182+
lineNumbers: true,
183+
extraKeys: {'Ctrl-Space': 'autocomplete'},
184+
lineWrapping: true
185+
});
186+
}).addClass('codemirror-checked');
187+
}
188+
// Annual/fixed date support.
167189
var errors = [];
168190
if (schema.format === 'datestring') {
169191
if (!/^[0-9|yY]{4}-[0-9]{1,2}-[0-9]{1,2}$/.test(value) && !/^[0-9]{1,2}-[0-9]{1,2}$/.test(value)) {

Assets/js/03.api_payload.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// API Payload field.
22
// API Payload JSON Schema.
33
Mautic.contactclientApiPayloadPre = function () {
4-
var $apiPayload = mQuery('#contactclient_api_payload');
5-
if (typeof window.contactclientApiPayloadPreoaded === 'undefined' && $apiPayload.length) {
6-
7-
window.contactclientApiPayloadPreoaded = true;
4+
var $apiPayload = mQuery('#contactclient_api_payload:first:not(.hide)');
5+
if ($apiPayload.length) {
86

97
var tokenSource = 'plugin:mauticContactClient:getTokens';
108
if (typeof window.JSONEditor.tokenCache === 'undefined') {
@@ -35,10 +33,8 @@ Mautic.contactclientApiPayloadPre = function () {
3533
};
3634
Mautic.contactclientApiPayload = function () {
3735

38-
var $apiPayload = mQuery('#contactclient_api_payload');
39-
if (typeof window.contactclientApiPayloadLoaded === 'undefined' && $apiPayload.length) {
40-
41-
window.contactclientApiPayloadLoaded = true;
36+
var $apiPayload = mQuery('#contactclient_api_payload:first:not(.hide)');
37+
if ($apiPayload.length) {
4238

4339
var apiPayloadCodeMirror,
4440
apiPayloadJSONEditor;

Assets/js/04.exclusive.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Exclusive field.
22
Mautic.contactclientExclusive = function () {
3-
var $exclusive = mQuery('#contactclient_exclusive');
4-
if (typeof window.contactclientExclusiveLoaded === 'undefined' && $exclusive.length) {
5-
6-
window.contactclientExclusiveLoaded = true;
3+
var $exclusive = mQuery('#contactclient_exclusive:not(.hide):first');
4+
if ($exclusive.length) {
75

86
var exclusiveJSONEditor;
97

Assets/js/06.filter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// @todo - Filtering field.
22
Mautic.contactclientFilter = function () {
3-
var $filter = mQuery('#contactclient_filter');
4-
if (typeof window.contactclientFilterLoaded === 'undefined' && $filter.length) {
3+
var $filter = mQuery('#contactclient_filter:not(.hide):first');
4+
if ($filter.length) {
5+
56

6-
window.contactclientFilterLoaded = true;
77
}
88
};

Assets/js/07.limits.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Limits field.
22
Mautic.contactclientLimits = function () {
3-
var $limits = mQuery('#contactclient_limits');
4-
if (typeof window.contactclientLimitsLoaded === 'undefined' && $limits.length) {
5-
6-
window.contactclientLimitsLoaded = true;
3+
var $limits = mQuery('#contactclient_limits:not(.hide):first');
4+
if ($limits.length) {
75

86
var limitsJSONEditor;
97

0 commit comments

Comments
 (0)