diff --git a/src/js/yunohost/controllers/apps.js b/src/js/yunohost/controllers/apps.js index e3bf8432..b27c59c3 100644 --- a/src/js/yunohost/controllers/apps.js +++ b/src/js/yunohost/controllers/apps.js @@ -523,8 +523,6 @@ if ((is_safe_for_install_color === "warning") || (is_safe_for_install_color === "danger")) { - // Disable the pacman while we ask for confirmation - $('div.loader').remove(); c.confirm( y18n.t("applications"), y18n.t("confirm_install_app_"+is_safe_for_install_color), diff --git a/src/js/yunohost/controllers/home.js b/src/js/yunohost/controllers/home.js index 54e201d6..d3361df6 100644 --- a/src/js/yunohost/controllers/home.js +++ b/src/js/yunohost/controllers/home.js @@ -24,20 +24,17 @@ $('#masthead').show() .find('.logout-btn').hide(); store.set('path-1', '#/login'); - if ($('div.loader').length === 0) { - $('#main').append('
'); - } + + c.showLoader(); c.checkInstall(function(isInstalled) { if (isInstalled) { - // Remove loader - $('div.loader').remove(); + c.hideLoader(); // Pass domain to hide form field c.view('login', { 'domain': window.location.hostname }); } else if (typeof isInstalled === 'undefined') { if (app.isInstalledTry > 0) { app.isInstalledTry--; - app.loaded = false; // Show pacman setTimeout(function() { c.redirect('#/'); }, 5000); @@ -56,12 +53,10 @@ $(document).off('ajaxError'); }); - // Remove pacman - app.loaded = true; - $('div.loader').remove(); + c.hideLoader(); } } else { - $('div.loader').remove(); + c.hideLoader(); c.redirect('#/postinstall'); } }); diff --git a/src/js/yunohost/controllers/tools.js b/src/js/yunohost/controllers/tools.js index 52c69133..4e62c693 100644 --- a/src/js/yunohost/controllers/tools.js +++ b/src/js/yunohost/controllers/tools.js @@ -146,7 +146,7 @@ $('button[data-action="share"]').on("click", function() { c.api('GET', '/logs/display?path='+$(this).data('log-id')+'&share', {}, function(data) { - $('div.loader').remove(); + c.hideLoader(); window.open(data.url, '_blank'); }); }); @@ -241,8 +241,7 @@ $('#main').replaceWith('
' + y18n.t('tools_shuttingdown') + '
'); } - // Remove loader if any - $('div.loader').remove(); + c.hideLoader(); // Force scrollTop on page load $('html, body').scrollTop(0); diff --git a/src/js/yunohost/events.js b/src/js/yunohost/events.js index 28e121db..5cfb10c4 100644 --- a/src/js/yunohost/events.js +++ b/src/js/yunohost/events.js @@ -75,7 +75,7 @@ if (data.security["CVE-2017-5754"].vulnerable) { c.flash('danger', y18n.t('meltdown')); } - $('div.loader').remove(); + c.hideLoader(); }); }); }); diff --git a/src/js/yunohost/helpers.js b/src/js/yunohost/helpers.js index a43aa396..1617e371 100644 --- a/src/js/yunohost/helpers.js +++ b/src/js/yunohost/helpers.js @@ -133,10 +133,9 @@ if (window.navigator && window.navigator.language && (typeof data.locale === 'undefined')) { data.locale = y18n.locale || window.navigator.language.substr(0, 2); } - app.loaded = false; - if ($('div.loader').length === 0) { - $('#main').append('
'); - } + + c.showLoader(); + call = function(uri, callback, method, data, callbackOnFailure) { var args = data; @@ -152,6 +151,10 @@ callbackOnFailure = function(xhr) { // Postinstall is a custom case, we have to wait that // operation is done before doing anything + // + // TODO / FIXME : maybe we should add this as a + // callbackonfailure during the actual api call instead + // of hard-coding it here... if ((uri === '/postinstall') && (post_installing)) { interval = window.location.hostname === args.domain ? 20000 : 5000; checkInstall = setInterval(function () { @@ -216,8 +219,7 @@ console.log(xhr); } - // Remove loader if any - $('div.loader').remove(); + c.hideLoader(); // Force scrollTop on page load $('html, body').scrollTop(0); @@ -285,10 +287,8 @@ callback = typeof callback !== 'undefined' ? callback : function() {}; enableSlide = (typeof enableSlide !== 'undefined') ? enableSlide : true; // Change to false to disable animation - app.loaded = true; - // Hide loader and modal - $('div.loader').remove(); + c.hideLoader(); $('#modal').modal('hide'); // Render content @@ -394,10 +394,14 @@ }, confirm: function(title, content, confirmCallback, cancelCallback) { + c = this; + // Default callbacks confirmCallback = typeof confirmCallback !== 'undefined' ? confirmCallback : function() {}; cancelCallback = typeof cancelCallback !== 'undefined' ? cancelCallback : function() {}; + c.hideLoader(); + // Get modal element var box = $('#modal'); @@ -436,6 +440,18 @@ return box.modal('show'); }, + showLoader: function() { + app.loaded = false; // Not sure if that's really useful ... this is from old code with no explanation what it really does ... + if ($('div.loader').length === 0) { + $('#main').append('
'); + } + }, + + hideLoader: function() { + app.loaded = true; // Not sure if that's really useful ... this is from old code with no explanation what it really does ... + $('div.loader').remove(); + }, + selectAllOrNone: function () { // Remove active style from buttons $(".select_all-none input").click(function(){ $(this).toggleClass("active"); }); @@ -545,8 +561,7 @@ // Get paste content element var preElement = $($(this).data('paste-content')); - // Add pacman loader - $('#main').append('
'); + c.showLoader(); // Send to paste.yunohost.org $.ajax({ @@ -561,8 +576,7 @@ c.flash('fail', y18n.t('paste_error')); }) .always(function(){ - // Remove pacman - $('div.loader').remove(); + c.hideLoader(); }); }); },