X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fclient.js;h=93e5dae4d1f2b1d8ad921f7012acac710bc3aa96;hp=92009f521e6f7cf26055d40c3a9f169234b020e7;hb=972919ab7f5651cd721eb6eec75f7150fdeaf347;hpb=1146f3264ff7535ff3408230140414789c3c25da diff --git a/js/client.js b/js/client.js index 92009f5..93e5dae 100644 --- a/js/client.js +++ b/js/client.js @@ -21,8 +21,9 @@ /** * Représente l'utilisateur du site. */ -euphorik.Client = function(util) { +euphorik.Client = function(util, communication) { this.util = util; + this.communication = communication this.cookie = null; this.regexCookie = /^cookie=([^;]*)/; @@ -105,12 +106,12 @@ euphorik.Client.prototype.pagePrecedente = function(numConv) { euphorik.Client.prototype.goPremierePage = function(numConv) { if (numConv < 0) { - if (this.pagePrincipale == 1) { + if (this.pagePrincipale === 1) { return false; } this.pagePrincipale = 1; } else { - if (this.conversations[numConv].page == 1) { + if (this.conversations[numConv].page === 1) { return false; } this.conversations[numConv].page = 1; @@ -126,7 +127,7 @@ euphorik.Client.prototype.goPremierePage = function(numConv) */ euphorik.Client.prototype.ajouterConversation = function(racine) { // vérification s'il elle n'existe pas déjà - var existe = false + var existe = false; this.conversations.each(function(i, conv) { if (conv.root === racine) { existe = true; @@ -180,13 +181,17 @@ euphorik.Client.prototype.getJSONLoginCookie = function() { * de s'autentifier avec (login, password). */ euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { - var mess = { "header" : { "action" : "register", "version" : euphorik.conf.versionProtocole } }; + var mess = { + "header" : { "action" : "register","version" : euphorik.conf.versionProtocole } + }; if (login && password) { mess.login = login; mess.password = password; } + mess.profile = this.getJSONProfileInfos(); + return mess; }; @@ -204,6 +209,12 @@ euphorik.Client.prototype.getJSONProfile = function() { "cookie" : this.cookie, "login" : this.login, "password" : this.password, + "profile" : this.getJSONProfileInfos() + }; +}; + +euphorik.Client.prototype.getJSONProfileInfos = function() { + return { "nick" : this.pseudo, "email" : this.email, "css" : this.css, @@ -302,27 +313,22 @@ euphorik.Client.prototype.enregistrement = function(login, password) { }; /** - * Connexion. Réalisé de manière synchrone. + * Connexion. Réalisée de manière synchrone. */ -euphorik.Client.prototype.connexion = function(messageJson) { +euphorik.Client.prototype.connexion = function(action, messageJson) { var thisClient = this; - jQuery.ajax({ - async: false, - type: "POST", - url: "request", - dataType: "json", - data: this.util.jsonVersAction(messageJson), - success: - function(data){ - if (data.reply === "error") { - thisClient.util.messageDialogue(data.error_message); - // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification - thisClient.delCookie(); - } else { - thisClient.chargerDonnees(data); - } - } - }); + + this.communication.requete( + action, + messageJson, + function(data) { + thisClient.chargerDonnees(data); + }, + function() { + thisClient.util.messageDialogue(data.error_message); + thisClient.delCookie(); // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification + } + ); return this.authentifie(); }; @@ -346,20 +352,20 @@ euphorik.Client.prototype.chargerDonnees = function(data) { this.id = data.id; this.login = data.login; - this.pseudo = data.nick; - this.email = data.email; - this.setCss(data.css); - this.chatOrder = data.chat_order; - this.nickFormat = data.nick_format; - this.viewTimes = data.view_times; - this.viewTooltips = data.view_tooltips; - this.ostentatiousMaster = data.ostentatious_master; + this.pseudo = data.profile.nick; + this.email = data.profile.email; + this.setCss(data.profile.css); + this.chatOrder = data.profile.chat_order; + this.nickFormat = data.profile.nick_format; + this.viewTimes = data.profile.view_times; + this.viewTooltips = data.profile.view_tooltips; + this.ostentatiousMaster = data.profile.ostentatious_master; // la page de la conversation principale this.pagePrincipale = 1; // les conversations - this.conversations = data.conversations; + this.conversations = data.profile.conversations; this.conversations.map(function(conv) { return { root : conv.root, page : 1, reduit : conv.minimized }; }); @@ -409,11 +415,11 @@ euphorik.Client.prototype.majMenu = function() { $("#menu .admin").css("display", this.ekMaster ? displayType : "none"); // met à jour le menu - if (this.statut == euphorik.Client.statutType.auth_registered) { + if (this.statut === euphorik.Client.statutType.auth_registered) { $("#menu .profile").css("display", displayType).text("profile"); $("#menu .logout").css("display", displayType); $("#menu .register").css("display", "none"); - } else if (this.statut == euphorik.Client.statutType.auth_not_registered) { + } else if (this.statut === euphorik.Client.statutType.auth_not_registered) { $("#menu .profile").css("display", "none"); $("#menu .logout").css("display", displayType); $("#menu .register").css("display", displayType);