diff --git a/lib/whitelabeler.js b/lib/whitelabeler.js index 29bdcd7..7cb820a 100644 --- a/lib/whitelabeler.js +++ b/lib/whitelabeler.js @@ -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(); }); /* @@ -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; @@ -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