-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()\r
- \r
- if (this.autoflush) this.flush(true)
-}
-
-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({ "root" : this.conversations[i].root, "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,
- "nick_format" : this.nickFormat,
- "view_times" : this.viewTimes,
- "view_tooltips" : this.viewTooltips,
- "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 == "auth_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
- }
- return false
- }
- 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)
- if (data["reply"] == "error")
- thisClient.util.messageDialogue(data["error_message"])
- else
- thisClient.chargerDonnees(data)
- }
- }
- )
- return this.authentifie()
-}\r
-\r
-Client.prototype.deconnexion = function()\r
-{
- this.flush(true)
- this.delCookie()
- this.resetDonneesPersonnelles()\r
- this.setStatut(statutType.deconnected) // deconnexion\r
-}
-
-Client.prototype.chargerDonnees = function(data)
-{
- // la modification du statut qui suit met à jour le menu, le menu dépend (page admin)
- // de l'état ekMaster
- this.ekMaster = data["ek_master"] != undefined ? data["ek_master"] : false
-
- this.setStatut(data["status"])
-
- if (this.authentifie())
- {
- this.cookie = data["cookie"]
- this.setCookie()
-
- this.id = data["id"]\r
- this.login = data["login"]
- this.pseudo = data["nick"]\r
- this.email = data["email"]\r
- this.setCss(data["css"])
- this.nickFormat = data["nick_format"]
- this.viewTimes = data["view_times"]
- this.viewTooltips = data["view_tooltips"]
-
- // la page de la conversation principale
- this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"]
-
- // les conversations
- this.conversations = data["conversations"]
-
- this.majBulle()
- }
-}
-
-/**
- * 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 = false
-
- if (!this.authentifie())
- return false
-
- var thisClient = this
- var ok = true
-
- ;; dumpObj(this.getJSONProfile())
- jQuery.ajax(
- {
- async: async,
- type: "POST",
- url: "request",
- dataType: "json",
- data: this.util.jsonVersAction(this.getJSONProfile()),
- success:
- function(data)
- {
- ;; dumpObj(data)
- if (data["reply"] == "error")
- {
- thisClient.util.messageDialogue(data["error_message"])
- ok = false
- }
- else
- {
- thisClient.majBulle()
- }
- }
- }
- )
-
- return ok
-}
-
-Client.prototype.majMenu = function()
-{
- // TODO : à virer : ne plus changer de style de display ... spa beau .. ou trouver une autre méthode
- // var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
- displayType = "block"
-
- $("#menu .admin").css("display", this.ekMaster ? displayType : "none")
-
- // met à jour le menu
- if (this.statut == statutType.auth_registered)
- {
- $("#menu .profile").css("display", displayType).text("profile")\r
- $("#menu .logout").css("display", displayType)
- $("#menu .register").css("display", "none")
- }
- else if (this.statut == statutType.auth_not_registered)
- {
- $("#menu .profile").css("display", "none")\r
- $("#menu .logout").css("display", displayType)
- $("#menu .register").css("display", displayType)
- }
- else
- {
- $("#menu .profile").css("display", displayType).text("login")\r
- $("#menu .logout").css("display", "none")
- $("#menu .register").css("display", displayType)
- }
-}
-
-/**
- * Met à jour l'affichage des infos bulles en fonction du profile.
- */
-Client.prototype.majBulle = function()
-{
- this.util.bulleActive = this.viewTooltips
-}
-
-Client.prototype.slap = function(userId, raison)
-{
- var thisClient = this
-
- jQuery.ajax({
- type: "POST",
- url: "request",
- dataType: "json",
- data: this.util.jsonVersAction(
- {
- "action" : "slap",
- "cookie" : thisClient.cookie,
- "user_id" : userId,
- "reason" : raison
- }),
- success:
- function(data)
- {
- if (data["reply"] == "error")
- thisClient.util.messageDialogue(data["error_message"])
- }
- })
-}
-
-Client.prototype.ban = function(userId, raison, minutes)
-{
- var thisClient = this
-
- // par défaut un ban correspond à 3 jours
- if (typeof(minutes) == "undefined")
- minutes = conf.tempsBan;
-
- jQuery.ajax({
- type: "POST",
- url: "request",
- dataType: "json",
- data: this.util.jsonVersAction(
- {
- "action" : "ban",
- "cookie" : thisClient.cookie,
- "duration" : minutes,
- "user_id" : userId,
- "reason" : raison
- }),
- success:
- function(data)
- {
- if (data["reply"] == "error")
- thisClient.util.messageDialogue(data["error_message"])
- }
- })
-}
-
-Client.prototype.kick = function(userId, raison)
-{
- this.ban(userId, raison, conf.tempsKick)
-}