Skip to content
Snippets Groups Projects
Commit 872fe527 authored by MaximeOLIVA's avatar MaximeOLIVA
Browse files

modif client

parent 0481ddc8
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -82,7 +82,7 @@ function changePassword(formData) {
document.getElementById("pwderror").innerHTML = "Password too short. Must be 6 characters at leats."
} else if (req.status == 400){
document.getElementById("pwderror").innerHTML = "Missing information"
}
}
}
}
}
......@@ -184,7 +184,7 @@ function signOut() {
let messageDiv = document.getElementById("error");
let req = new XMLHttpRequest();
req.open("POST", "/users/sign_out", true);
req.open("PUT", "/users/sign_out", true);
req.setRequestHeader("Content-type", "application/json;charset=UTF-8");
req.setRequestHeader("token", localStorage.getItem("token"));
req.send(null);
......@@ -268,16 +268,6 @@ function openTab(tabName) {
var i, tabcontent, tablinks;
localStorage.setItem("tab", tabName);
if(tabName != "browsePage") {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "/account/get/message/" + localStorage.getItem("browsed_email"), true);
xhttp.setRequestHeader("token", localStorage.getItem("token"));
xhttp.send();
if (xhttp.readyState == 4 && xhttp.status != 204){
localStorage.removeItem("browsed_email");
}
}
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
......@@ -292,7 +282,7 @@ function openTab(tabName) {
if(tabName == "homePage") {
display_wall_info(localStorage.getItem("email_username"), "HP");
} else if (tabName == "browsePage") {
} else if (tabName == "browsePage" && localStorage.getItem("browsed_email") != null) {
display_wall_info(localStorage.getItem("browsed_email"), "BP");
}
......@@ -308,26 +298,27 @@ function display_wall_info(email, tab) {
let data_user;
get_user_info(email, tab, function(data){
data_user = data;
if(data_user.success) {
if(tab == "BP") {
if(data_user != null) {
if(data_user.success) {
if(tab == "BP") {
browsecontent = document.getElementsByClassName("browsecontent");
for (i = 0; i < browsecontent.length; i++) {
document.getElementById("browse_error").style.display = "none";
browsecontent[i].style.display = "block";
}
}
fills_data(tab, data_user);
display_wall(email, tab);
} else {
browsecontent = document.getElementsByClassName("browsecontent");
for (i = 0; i < browsecontent.length; i++) {
document.getElementById("browse_error").style.display = "none";
browsecontent[i].style.display = "block";
browsecontent[i].style.display = "none";
}
if (localStorage.getItem("browsed_email") != null){
document.getElementById("browse_error").style.display = "block";
document.getElementById("browse_error").innerHTML = data_user.message;
}
}
fills_data(tab, data_user);
display_wall(email, tab);
} else {
browsecontent = document.getElementsByClassName("browsecontent");
for (i = 0; i < browsecontent.length; i++) {
browsecontent[i].style.display = "none";
}
if (localStorage.getItem("browsed_email") != null){
document.getElementById("browse_error").style.display = "block";
document.getElementById("browse_error").innerHTML = data_user.message;
}
}
});
}
......@@ -335,7 +326,8 @@ function display_wall_info(email, tab) {
function get_user_info(email, tab, callback) {
//call the server if data aren't already stored
if((tab == "BP") && (localStorage.getItem("browsed_email") != email || data_user_browse == null)) {
if((tab == "BP") && (localStorage.getItem("browsed_email") != email || data_user_browse == null)
&& (localStorage.getItem("browsed_email") != null)) {
let req = new XMLHttpRequest();
req.open("GET", "/account/get/data/" + email, true);
req.setRequestHeader("token", localStorage.getItem("token"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment