Skip to content

Commit

Permalink
Give better error messages on mautic installation fail
Browse files Browse the repository at this point in the history
  • Loading branch information
pjrobertson authored Jan 19, 2019
1 parent 2974e6d commit 562387e
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions lib/whitelabeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,7 @@ $("input.mautic_hover").on('move.spectrum change.spectrum', function(e, tinycolo
|--------------------------------------------------------------------------
*/
$('body').on('change', 'input#mautic-path', function() {
var element = $(this);
$('small.path-fail, small.path-success').hide();
$.get( window.location.href, { q: 'version', path: $('input#mautic-path').val() }, function(data) {
if ( data == 0 ) {
validPath = false;
$(element).parent('div').children('small.path-fail').fadeIn();
} else {
$('span.version').text(data);
validPath = true;
$(element).parent('div').children('small.path-success').fadeIn();
}
});
checkMauticVersion();
});

/*
Expand Down Expand Up @@ -103,17 +92,8 @@ $(document).ready(function(){
$('input#mautic-hover').val(mautic_hover);
$('#waiting-for-input span.dots').addClass('blink');
$('input#mautic-url').val(window.location.href);

$.get( window.location.href, { q: 'version', path: $('input#mautic-path').val() }, function(data) {
if (data == 0) {
$('input#mautic-path').parent('div').children('small.path-fail').fadeIn();
validPath = false;
} else {
$('span.version').text(data);
validPath = true;
$('input#mautic-path').parent('div').children('small.path-success').fadeIn();
}
});

checkMauticVersion();
$.get( window.location.href, { q: 'url', url: encodeURIComponent($('input#mautic-url').val()) }, function(data) {
if (data == 1) {
validDomain = true;
Expand Down Expand Up @@ -218,6 +198,34 @@ function clearConsole() {
$('div#console p').css('display', 'none');
}

/*
|--------------------------------------------------------------------------
| Checks mautic install version
|--------------------------------------------------------------------------
*/
function checkMauticVersion($element) {
var $element = $('input#mautic-path');
$('small.path-fail, small.path-success').hide();
$.get( window.location.href, { q: 'version', path: $('input#mautic-path').val() }, function(data) {
data = JSON.parse(data);
if (!data.valid) {
validPath = false;
var $errorElement = $element.parent('div').children('small.path-fail');
if (data.version) {
// a mautic installation was found, but the version is not compatible with mautic-whitelabeler
$errorElement.text("A Mautic installation was found, but its version (" + data.version + ") is incompatible with mautic whitelabeler.")
} else {
$errorElement.text("Mautic installation not found here.");
}
$errorElement.fadeIn();
} else {
$('span.version').text(data.version);
validPath = true;
$element.parent('div').children('small.path-success').fadeIn();
}
});
}

/*
|--------------------------------------------------------------------------
| Run whitelabel functions
Expand Down

0 comments on commit 562387e

Please sign in to comment.