diff --git a/index.html b/index.html index 457d8db2..9873a416 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@
diff --git a/js/app.js b/js/app.js index 7dbac916..03db2953 100644 --- a/js/app.js +++ b/js/app.js @@ -48,6 +48,7 @@ app = Sammy('#main', function (sam) { // Initialize storage var store = new Sammy.Store({name: 'storage', type: storageType}); var loaded = false; + var isInstalledTry = 3; /** * Helpers @@ -396,15 +397,38 @@ app = Sammy('#main', function (sam) { } }, 500); } + c.checkInstall(function(isInstalled) { if (isInstalled) { domain = window.location.hostname; $('div.loader').remove(); c.view('login', { 'domain': domain }); } else if (typeof isInstalled === 'undefined') { - setTimeout(function() { - c.redirect('#/'); - }, 5000); + if (isInstalledTry > 0) { + isInstalledTry--; + loaded = false; // Show pacman + setTimeout(function() { + c.redirect('#/'); + }, 5000); + } + else { + // Reset count + isInstalledTry = 3; + + // API is not responding after 3 try + $( document ).ajaxError(function( event, request, settings ) { + // Display error if status != 200. + // .ajaxError fire even with status code 200 because json is sometimes not valid. + if (request.status !== 200) c.flash('fail', y18n.t('api_not_responding', [request.status+' '+request.statusText] )); + + // Unbind directly + $(document).off('ajaxError'); + }); + + // Remove pacman + loaded = true; + $('div.loader').remove(); + } } else { $('div.loader').remove(); c.redirect('#/postinstall'); diff --git a/locales/en.json b/locales/en.json index e16b962f..4cfaacf8 100644 --- a/locales/en.json +++ b/locales/en.json @@ -56,6 +56,7 @@ "warning_first_user" : "You probably need to create a user first.", "unknown_action" : "Unknown action %s", "unknown_argument" : "Unknown argument : %s", + "api_not_responding" : "API is not responding (Error : %s)", "confirm_delete" : "Are you sure you want to delete %s ?", "confirm_change_maindomain" : "Are you sure you want to change the main domain ?", diff --git a/locales/fr.json b/locales/fr.json index 85844292..e4758a9b 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -55,6 +55,7 @@ "warning_first_user" : "Vous devez probablement d'abord créer un utilisateur.", "unknown_action" : "Action %s inconnue", "unknown_argument" : "Argument inconnu : %s", + "api_not_responding" : "l'API ne répond pas (Erreur : %s)", "confirm_delete" : "Êtes-vous sur de vouloir supprimer %s ?", "confirm_change_maindomain" : "Êtes-vous sur de vouloir changer le domaine principal ?",