-Client.prototype.pageSuivante = function(numConv)
-{
- if (numConv < 0 && this.pagePrincipale > 1)
- this.pagePrincipale -= 1
- else if (this.conversations[numConv].page > 1)
- this.conversations[numConv].page -= 1
-}
-
-Client.prototype.pagePrecedente = function(numConv)
-{
- if (numConv < 0)
- this.pagePrincipale += 1
- else
- this.conversations[numConv].page += 1
-}
-
-/**
- * Définit la première page pour la conversation donnée.
- * @return true si la page a changé sinon false
- */
-Client.prototype.goPremierePage = function(numConv)
-{
- if (numConv < 0)
- {
- if (this.pagePrincipale == 1)
- return false
- this.pagePrincipale = 1
- }
- else
- {
- if (this.conversations[numConv].page == 1)
- return false
- this.conversations[numConv].page = 1
- }
- return true
-}
-
-/**
- * Ajoute une conversation à la vue de l'utilisateur.
- * Le profile de l'utilisateur est directement sauvegardé sur le serveur.
- * @param racines la racine de la conversation (integer)
- * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà)
- */
-Client.prototype.ajouterConversation = function(racine)
-{
- // vérification s'il elle n'existe pas déjà
- for (var i = 0; i < this.conversations.length; i++)
- if (this.conversations[i].racine == racine)
- return false
-
- this.conversations.push({racine : racine, page : 1})
- return true
-}
-
-Client.prototype.supprimerConversation = function(num)
-{
- if (num < 0 || num >= this.conversations.length) return
-
- // décalage TODO : supprimer le dernier élément
- for (var i = num; i < this.conversations.length - 1; i++)
- this.conversations[i] = this.conversations[i+1]
- this.conversations.pop()
-}
-
-Client.prototype.getJSONLogin = function(login, password)
-{
- return {
- "action" : "authentification",
- "login" : login,
- "password" : password
- }
-}
-
-Client.prototype.getJSONLoginCookie = function()
-{
- return {
- "action" : "authentification",
- "cookie" : this.cookie
- }
-}
-
-/**
- * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible
- * de s'autentifier avec (login, password).
- */
-Client.prototype.getJSONEnregistrement = function(login, password)
-{
- var mess = { "action" : "register" }
-
- if (login != undefined && password != undefined)
- {
- mess["login"] = login
- mess["password"] = password
- }
-
- return mess;
-}
-
-Client.prototype.getJSONConversations = function()
-{
- var conversations = new Array()
- for (var i = 0; i < this.conversations.length; i++)
- conversations.push({ "racine" : this.conversations[i].racine, "page" : this.conversations[i].page})
- return conversations
-}
-
-Client.prototype.getJSONProfile = function()
-{
- return {
- "action" : "set_profile",
- "cookie" : this.cookie,
- "login" : this.login,
- "password" : this.password,
- "nick" : this.pseudo,
- "email" : this.email,
- "css" : this.css,
- "main_page" : this.pagePrincipale < 1 ? 1 : this.pagePrincipale,
- "conversations" : this.getJSONConversations()
- }
-}
-
-/**
- * Renvoie null si pas définit.
- */
-Client.prototype.getCookie = function()
-{
- var cookie = this.regexCookie.exec(document.cookie)
- if (cookie == null) this.cookie = null
- else this.cookie = cookie[1]
-}\r
-\r
-Client.prototype.delCookie = function()\r
-{\r
- document.cookie = "cookie=; max-age=0"\r
-}
-
-Client.prototype.setCookie = function(cookie)
-{
- if (this.cookie == null)
- return
-
- document.cookie =
- "cookie="+this.cookie+
- "; max-age=" + (60 * 60 * 24 * 365)
-}
-
-Client.prototype.authentifie = function()
-{
- return this.statut == statutType.auth_registered || this.statut == statutType.auth_not_registered
-}
-
-Client.prototype.setStatut = function(statut)
-{
- // conversation en "enum" si en "string"\r
- if (typeof(statut) == "string")\r
- {
- statut =
- statut == "registered" ?
- statutType.auth_registered :
- (statut == "auth_not_registered" ? statutType.auth_not_registered : statutType.deconnected)\r
- } \r
- \r
- if (statut == this.statut) return \r
- \r
- this.statut = statut \r
- this.majMenu()
-}
-\r
-/**\r
- * Effectue la connexion vers le serveur.\r
- * Cette fonction est bloquante tant que la connexion n'a pas été établie.\r
- * S'il existe un cookie en local on s'authentifie directement avec lui.\r
- * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.\r
- */\r
-Client.prototype.connexionCookie = function()\r
-{\r
- this.getCookie()\r
- if (this.cookie == null) return false;
- return this.connexion(this.getJSONLoginCookie())\r
-}
-
-Client.prototype.connexionLogin = function(login, password)
-{
- return this.connexion(this.getJSONLogin(login, password))
-}\r
-
-Client.prototype.enregistrement = function(login, password)
-{
- if (this.authentifie())
- {
- this.login = login
- this.password = password
- if(this.flush())
- this.setStatut(statutType.auth_registered)
- return true
- }
- else\r
- {
- return this.connexion(this.getJSONEnregistrement(login, password))\r
- }
-}
-
-Client.prototype.connexion = function(messageJson)
-{
- ;;; dumpObj(messageJson)
- thisClient = this
- jQuery.ajax(
- {
- async: false,
- type: "POST",
- url: "request",
- dataType: "json",
- data: this.util.jsonVersAction(messageJson),
- success:
- function(data)
- {
- ;;; dumpObj(data)
- thisClient.chargerDonnees(data)
- }
- }
- )
- return this.authentifie()
-}\r
-\r
-Client.prototype.deconnexion = function()\r
-{\r
- this.setStatut(statutType.deconnected) // deconnexion\r
- this.resetDonneesPersonnelles()\r
- this.delCookie ()\r
-}
-
-Client.prototype.chargerDonnees = function(data)
-{
- var thisClient = this
-
- this.setStatut(data["status"])
-
- if (this.authentifie())
- {
- this.cookie = data["cookie"]
- this.setCookie()
- \r
- this.login = data["login"]
- this.pseudo = data["nick"]\r
- this.email = data["email"]\r
- this.css = data["css"]
-
- // la page de la conversation principale
- this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"]
-
- // met à jour la css
- if (this.css != "")
- {
- jQuery("link#cssPrincipale").attr("href", this.css)
- this.majMenu()
- }
- // les conversations
- thisClient.conversations = data["conversations"]
-
- }
- this.dernierMessageErreur = data["error_message"]
-}
-
-/**
- * Met à jour les données personne sur serveur.
- * @param async de manière asynchrone ? défaut = true
- * @return false si le flush n'a pas pû se faire sinon true
- */
-Client.prototype.flush = function(async)
-{
- if (async == undefined)
- async = true
-
- if (!this.authentifie())
- return false
-
- thisClient = this
- ;;; dumpObj(this.getJSONProfile())
- jQuery.ajax(
- {
- async: async,
- type: "POST",
- url: "request",
- dataType: "json",
- data: this.util.jsonVersAction(this.getJSONProfile()),
- success:
- function(data)
- {
- //thisClient.util.log(thisClient.util.serializer.serializeToString(data))
- }
- }
- )
- // TODO : retourner false si un problème est survenu lors de l'update du profile
- return true
-}
-
-Client.prototype.majMenu = function()
-{
- var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
-
- // met à jour le menu
- if (this.statut == statutType.auth_registered)
- {
- jQuery("#menu .profile").css("display", displayType).text("profile")\r
- jQuery("#menu .logout").css("display", displayType)
- jQuery("#menu .register").css("display", "none")
- }
- else if (this.statut == statutType.auth_not_registered)
- {
- jQuery("#menu .profile").css("display", "none")\r
- jQuery("#menu .logout").css("display", displayType)
- jQuery("#menu .register").css("display", displayType)
- }
- else
- {
- jQuery("#menu .profile").css("display", displayType).text("login")\r
- jQuery("#menu .logout").css("display", "none")
- jQuery("#menu .register").css("display", displayType)
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-jQuery.noConflict()
-
-// charge dynamiquement le script de debug
-;;; jQuery.ajax({async : false, url : "js/debug.js", dataType : "script"})
- \r