-Client.prototype.setCss = function(css)
-{
- if (this.css == css)
- return
-
- this.css = css
- jQuery("link#cssPrincipale").attr("href", this.css)
- this.majMenu()
-
- if (this.identifie())
- this.flush()
-}
-
-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
- this.flush(false)
-}
-
-Client.prototype.pagePrecedente = function(numConv)
-{
- if (numConv < 0)
- this.pagePrincipale += 1
- else
- this.conversations[numConv].page += 1
- this.flush(false)
-}
-
-/**
- * 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
- }
- this.flush(false)
- 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
- * @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})
- this.flush(false)
- 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()
-
- this.flush(false)
-}\r
-
-Client.prototype.getXMLlogin = function(login, password)
-{
- var XMLDocument = this.util.creerDocumentXMLAction()
- XMLDocument.documentElement.setAttribute("name", "login")
-
- var nodeLogin = XMLDocument.createElement("login")
- nodeLogin.appendChild(XMLDocument.createTextNode(login))
- XMLDocument.documentElement.appendChild(nodeLogin)
-
- var nodePassword = XMLDocument.createElement("password")
- nodePassword.appendChild(XMLDocument.createTextNode(password))
- XMLDocument.documentElement.appendChild(nodePassword)
-
- return XMLDocument
-}
-
-Client.prototype.getXMLloginCookie = function()
-{
- var XMLDocument = this.util.creerDocumentXMLAction()
- XMLDocument.documentElement.setAttribute("name", "login")
-
- var nodeCookie = XMLDocument.createElement("cookie")
- nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie))
- XMLDocument.documentElement.appendChild(nodeCookie)
-
- return XMLDocument
-}
-
-Client.prototype.getXMLEnregistrement = function(login, password)
-{
- var XMLDocument = this.util.creerDocumentXMLAction()
- XMLDocument.documentElement.setAttribute("name", "register")
-
- var nodeLogin = XMLDocument.createElement("login")
- nodeLogin.appendChild(XMLDocument.createTextNode(login))
- XMLDocument.documentElement.appendChild(nodeLogin)
-
- var nodePassword = XMLDocument.createElement("password")
- nodePassword.appendChild(XMLDocument.createTextNode(password))
- XMLDocument.documentElement.appendChild(nodePassword)
-
- return XMLDocument
-}
-
-/**
- * Sérialize le profile en XML.
- * TODO : méthode assez lourde, 3.25ms de moyenne
- */
-Client.prototype.getXMLProfile = function()
-{
- var XMLDocument = this.util.creerDocumentXMLAction()
- XMLDocument.documentElement.setAttribute("name", "profile")
-
- var nodeCookie = XMLDocument.createElement("cookie")
- nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie))
- XMLDocument.documentElement.appendChild(nodeCookie)
-
- var nodeLogin = XMLDocument.createElement("login")
- nodeLogin.appendChild(XMLDocument.createTextNode(this.login))
- XMLDocument.documentElement.appendChild(nodeLogin)
-
- var nodePassword = XMLDocument.createElement("password")
- nodePassword.appendChild(XMLDocument.createTextNode(this.password))
- XMLDocument.documentElement.appendChild(nodePassword)
-
- var nodePseudo = XMLDocument.createElement("pseudo")
- nodePseudo.appendChild(XMLDocument.createTextNode(this.pseudo))
- XMLDocument.documentElement.appendChild(nodePseudo)
-
- var nodeEmail = XMLDocument.createElement("email")
- nodeEmail.appendChild(XMLDocument.createTextNode(this.email))
- XMLDocument.documentElement.appendChild(nodeEmail)
-
- var nodeCSS = XMLDocument.createElement("css")
- nodeCSS.appendChild(XMLDocument.createTextNode(this.css))
- XMLDocument.documentElement.appendChild(nodeCSS)
-
- var nodePagePrincipale = XMLDocument.createElement("pagePrincipale")
- nodePagePrincipale.appendChild(XMLDocument.createTextNode(this.pagePrincipale < 1 ? 1 : this.pagePrincipale))
- XMLDocument.documentElement.appendChild(nodePagePrincipale)
-
- // mémorise les conversations affichées
- for (var i = 0; i < this.conversations.length; i++)
- {
- var nodeConv = XMLDocument.createElement("conversation")
- XMLDocument.documentElement.appendChild(nodeConv)
-
- var nodeRacine = XMLDocument.createElement("racine")
- nodeRacine.appendChild(XMLDocument.createTextNode(this.conversations[i].racine))
- nodeConv.appendChild(nodeRacine)
-
- var nodePage = XMLDocument.createElement("page")
- nodePage.appendChild(XMLDocument.createTextNode(this.conversations[i].page))
- nodeConv.appendChild(nodePage)
- }
-
- return XMLDocument
-}
-
-/**
- * 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.identifie = function()
-{
- return this.statut == statutType.enregistre || this.statut == statutType.identifie
-}
-
-Client.prototype.setStatut = function(statut)
-{ \r
- if(typeof(statut) == "string")\r
- {
- statut =
- statut == "enregistre" ?
- statutType.enregistre : (statut == "identifie" ? statutType.identifie : statutType.non_identifie) \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.util.xmlVersAction(this.getXMLloginCookie()))\r
-}
-
-Client.prototype.connexionLogin = function(login, password)
-{
- return this.connexion(this.util.xmlVersAction(this.getXMLlogin(login, password)))
-}\r
-
-Client.prototype.enregistrement = function(login, password)
-{
- if (this.identifie())
- {
- this.login = login
- this.password = password
- if(this.flush())
- this.setStatut(statutType.enregistre)
- return true
- }
- else\r
- {\r
- if (login == undefined) login = ""\r
- if (password == undefined) password = ""
- return this.connexion(this.util.xmlVersAction(this.getXMLEnregistrement(login, password)))\r
- }
-}
-
-Client.prototype.connexion = function(action)
-{
- //action.action.dump()
- thisClient = this
- jQuery.ajax(
- {
- async: false,
- type: "POST",
- url: "request",
- dataType: "xml",
- data: action,
- success:
- function(data)
- {
- //thisClient.util.serializer.serializeToString(data).dump("Charger client")
- thisClient.chargerDonnees(data)
- }
- }
- )
- return this.identifie()
-}\r
-\r
-Client.prototype.deconnexion = function()\r
-{\r
- this.setStatut(statutType.non_identifie) // deconnexion\r
- this.resetDonneesPersonnelles()\r
- this.delCookie ()\r
-}
-
-Client.prototype.chargerDonnees = function(data)
-{
- var thisClient = this
-
- this.setStatut(jQuery("statut", data.documentElement).text())
-
- if (this.identifie())
- {
- this.cookie = jQuery("cookie", data.documentElement).text()
- this.setCookie()
- \r
- this.login = jQuery("login", data.documentElement).text()
- this.pseudo = jQuery("pseudo", data.documentElement).text()\r
- this.email = jQuery("email", data.documentElement).text()\r
- this.css = jQuery("css", data.documentElement).text()
-
- // la page de la conversation principale
- var tmp = jQuery("pagePrincipale", data.documentElement)
- this.pagePrincipale = tmp.length < 1 ? 1 : parseInt(tmp.text())
-
- // met à jour la css
- if (this.css != "")
- {
- jQuery("link#cssPrincipale").attr("href", this.css)
- this.majMenu()
- }
- // les conversations
- this.conversations = new Array()
- jQuery("conversation", data.documentElement).each(
- function(i)
- {
- thisClient.conversations.push( { racine : jQuery("racine", this).text(), page : jQuery("page", this).text() } )
- }
- )
- }
- this.dernierMessageErreur = jQuery("information", data.documentElement).text()
-}
-
-/**
- * Met à jour les données personne sur serveur.
- * @param async de manière asynchrone ? défaut = true
- */
-Client.prototype.flush = function(async)
-{
- if (async == undefined)
- async = true
-
- thisClient = this
- //this.util.xmlVersAction(this.getXMLProfile()).action.dump("Flush client")
- jQuery.ajax(
- {
- async: async,
- type: "POST",
- url: "request",
- dataType: "xml",
- data: this.util.xmlVersAction(this.getXMLProfile()),
- 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.enregistre)
- {
- 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.identifie)
- {
- 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()
-
- \r