Manipulate the loader pacman with semantic helpers

This commit is contained in:
Alexandre Aubin 2019-10-19 03:09:13 +02:00
parent 8f2c959cdd
commit 392a4de64a
5 changed files with 35 additions and 29 deletions

View file

@ -523,8 +523,6 @@
if ((is_safe_for_install_color === "warning") || (is_safe_for_install_color === "danger")) 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( c.confirm(
y18n.t("applications"), y18n.t("applications"),
y18n.t("confirm_install_app_"+is_safe_for_install_color), y18n.t("confirm_install_app_"+is_safe_for_install_color),

View file

@ -24,20 +24,17 @@
$('#masthead').show() $('#masthead').show()
.find('.logout-btn').hide(); .find('.logout-btn').hide();
store.set('path-1', '#/login'); store.set('path-1', '#/login');
if ($('div.loader').length === 0) {
$('#main').append('<div class="loader loader-content"></div>'); c.showLoader();
}
c.checkInstall(function(isInstalled) { c.checkInstall(function(isInstalled) {
if (isInstalled) { if (isInstalled) {
// Remove loader c.hideLoader();
$('div.loader').remove();
// Pass domain to hide form field // Pass domain to hide form field
c.view('login', { 'domain': window.location.hostname }); c.view('login', { 'domain': window.location.hostname });
} else if (typeof isInstalled === 'undefined') { } else if (typeof isInstalled === 'undefined') {
if (app.isInstalledTry > 0) { if (app.isInstalledTry > 0) {
app.isInstalledTry--; app.isInstalledTry--;
app.loaded = false; // Show pacman
setTimeout(function() { setTimeout(function() {
c.redirect('#/'); c.redirect('#/');
}, 5000); }, 5000);
@ -56,12 +53,10 @@
$(document).off('ajaxError'); $(document).off('ajaxError');
}); });
// Remove pacman c.hideLoader();
app.loaded = true;
$('div.loader').remove();
} }
} else { } else {
$('div.loader').remove(); c.hideLoader();
c.redirect('#/postinstall'); c.redirect('#/postinstall');
} }
}); });

View file

@ -146,7 +146,7 @@
$('button[data-action="share"]').on("click", function() { $('button[data-action="share"]').on("click", function() {
c.api('GET', '/logs/display?path='+$(this).data('log-id')+'&share', {}, c.api('GET', '/logs/display?path='+$(this).data('log-id')+'&share', {},
function(data) { function(data) {
$('div.loader').remove(); c.hideLoader();
window.open(data.url, '_blank'); window.open(data.url, '_blank');
}); });
}); });
@ -241,8 +241,7 @@
$('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-power-off"></i> ' + y18n.t('tools_shuttingdown') + '</div></div>'); $('#main').replaceWith('<div id="main"><div class="alert alert-warning"><i class="fa-power-off"></i> ' + y18n.t('tools_shuttingdown') + '</div></div>');
} }
// Remove loader if any c.hideLoader();
$('div.loader').remove();
// Force scrollTop on page load // Force scrollTop on page load
$('html, body').scrollTop(0); $('html, body').scrollTop(0);

View file

@ -75,7 +75,7 @@
if (data.security["CVE-2017-5754"].vulnerable) { if (data.security["CVE-2017-5754"].vulnerable) {
c.flash('danger', y18n.t('meltdown')); c.flash('danger', y18n.t('meltdown'));
} }
$('div.loader').remove(); c.hideLoader();
}); });
}); });
}); });

View file

@ -133,10 +133,9 @@
if (window.navigator && window.navigator.language && (typeof data.locale === 'undefined')) { if (window.navigator && window.navigator.language && (typeof data.locale === 'undefined')) {
data.locale = y18n.locale || window.navigator.language.substr(0, 2); data.locale = y18n.locale || window.navigator.language.substr(0, 2);
} }
app.loaded = false;
if ($('div.loader').length === 0) { c.showLoader();
$('#main').append('<div class="loader loader-content"></div>');
}
call = function(uri, callback, method, data, callbackOnFailure) { call = function(uri, callback, method, data, callbackOnFailure) {
var args = data; var args = data;
@ -152,6 +151,10 @@
callbackOnFailure = function(xhr) { callbackOnFailure = function(xhr) {
// Postinstall is a custom case, we have to wait that // Postinstall is a custom case, we have to wait that
// operation is done before doing anything // 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)) { if ((uri === '/postinstall') && (post_installing)) {
interval = window.location.hostname === args.domain ? 20000 : 5000; interval = window.location.hostname === args.domain ? 20000 : 5000;
checkInstall = setInterval(function () { checkInstall = setInterval(function () {
@ -216,8 +219,7 @@
console.log(xhr); console.log(xhr);
} }
// Remove loader if any c.hideLoader();
$('div.loader').remove();
// Force scrollTop on page load // Force scrollTop on page load
$('html, body').scrollTop(0); $('html, body').scrollTop(0);
@ -285,10 +287,8 @@
callback = typeof callback !== 'undefined' ? callback : function() {}; callback = typeof callback !== 'undefined' ? callback : function() {};
enableSlide = (typeof enableSlide !== 'undefined') ? enableSlide : true; // Change to false to disable animation enableSlide = (typeof enableSlide !== 'undefined') ? enableSlide : true; // Change to false to disable animation
app.loaded = true;
// Hide loader and modal // Hide loader and modal
$('div.loader').remove(); c.hideLoader();
$('#modal').modal('hide'); $('#modal').modal('hide');
// Render content // Render content
@ -394,10 +394,14 @@
}, },
confirm: function(title, content, confirmCallback, cancelCallback) { confirm: function(title, content, confirmCallback, cancelCallback) {
c = this;
// Default callbacks // Default callbacks
confirmCallback = typeof confirmCallback !== 'undefined' ? confirmCallback : function() {}; confirmCallback = typeof confirmCallback !== 'undefined' ? confirmCallback : function() {};
cancelCallback = typeof cancelCallback !== 'undefined' ? cancelCallback : function() {}; cancelCallback = typeof cancelCallback !== 'undefined' ? cancelCallback : function() {};
c.hideLoader();
// Get modal element // Get modal element
var box = $('#modal'); var box = $('#modal');
@ -436,6 +440,18 @@
return box.modal('show'); 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('<div class="loader loader-content"></div>');
}
},
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 () { selectAllOrNone: function () {
// Remove active style from buttons // Remove active style from buttons
$(".select_all-none input").click(function(){ $(this).toggleClass("active"); }); $(".select_all-none input").click(function(){ $(this).toggleClass("active"); });
@ -545,8 +561,7 @@
// Get paste content element // Get paste content element
var preElement = $($(this).data('paste-content')); var preElement = $($(this).data('paste-content'));
// Add pacman loader c.showLoader();
$('#main').append('<div class="loader loader-content"></div>');
// Send to paste.yunohost.org // Send to paste.yunohost.org
$.ajax({ $.ajax({
@ -561,8 +576,7 @@
c.flash('fail', y18n.t('paste_error')); c.flash('fail', y18n.t('paste_error'));
}) })
.always(function(){ .always(function(){
// Remove pacman c.hideLoader();
$('div.loader').remove();
}); });
}); });
}, },