Commit dd89cbf7 authored by Floréal Cabanettes's avatar Floréal Cabanettes

Add loading to page loads

parent e2ee67c4
......@@ -202,4 +202,51 @@ button#goback {
margin-top: 25px;
padding: 5px 10px;
font-size: 14pt;
}
/* Loading */
div.loading {
/*display: none;*/
z-index: 2000;
position: fixed;
top: 5px;
right: 40px;
}
.lds-facebook {
display: inline-block;
position: relative;
width: 30px;
height: 30px;
}
.lds-facebook div {
display: inline-block;
position: absolute;
left: 6px;
width: 13px;
background: #fff;
animation: lds-facebook 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite;
}
.lds-facebook div:nth-child(1) {
left: 6px;
animation-delay: -0.24s;
}
.lds-facebook div:nth-child(2) {
left: 26px;
animation-delay: -0.12s;
}
.lds-facebook div:nth-child(3) {
left: 45px;
animation-delay: 0s;
}
@keyframes lds-facebook {
0% {
top: 6px;
height: 45px;
}
50%, 100% {
top: 12px;
height: 26px;
}
}
\ No newline at end of file
......@@ -22,6 +22,14 @@
<h1>Track my bank!</h1>
<div class="loading" style="display: none">
<div class="lds-facebook">
<div></div>
<div></div>
<div></div>
</div>
</div>
<div id="notify" style="display: none;">
</div>
......
......@@ -280,38 +280,50 @@ trackmybank.notify = async function(level, message) {
});
};
trackmybank.ajax = function (url, data, success, error, method = "POST", async = true) {
let options = {
method: method,
data: data,
success: success,
error: error || function (res) {
if (res.status === 0) {
trackmybank.notify("error", "Vérifiez votre connexion internet.");
return false;
} else {
try {
data = JSON.parse(res.responseText);
if ("message" in data) {
trackmybank.notify("error", data.message);
return true;
trackmybank.ajax = function (url, data, success_m, error_m, method = "POST", async = true) {
let loading = $(".loading");
loading.show();
setTimeout(function() {
let options = {
method: method,
data: data,
success: function (data, success) {
success_m(data, success);
loading.hide();
},
error: function (res) {
loading.hide();
if (error_m === undefined) {
if (res.status === 0) {
trackmybank.notify("error", "Vérifiez votre connexion internet.");
return false;
} else {
try {
data = JSON.parse(res.responseText);
if ("message" in data) {
trackmybank.notify("error", data.message);
return true;
}
} catch (e) {
// do nothing
}
trackmybank.notify("error", "Une erreur est survenue. Veuillez contacter le support.");
}
} catch (e) {
// do nothing
} else {
error_m(res);
}
trackmybank.notify("error", "Une erreur est survenue. Veuillez contacter le support.");
},
async: async,
};
if (credentials.token !== undefined) {
options["beforeSend"] = function (xhr) {
xhr.setRequestHeader("Authorization", "Token " + credentials.token);
}
},
async: async,
};
if (credentials.token !== undefined) {
options["beforeSend"] = function (xhr) {
xhr.setRequestHeader("Authorization", "Token " + credentials.token);
}
}
$.ajax(url,
options
);
$.ajax(url,
options
);
}, 0);
};
trackmybank.post = function (url, data, success, error, async = true) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment