return this.replace(/\s+$/, "");\r
}\r
\r
-String.prototype.dump = function()\r
-{\r
+String.prototype.dump = function(titre)\r
+{
+ titre = titre == undefined ? "" : titre\r
if (typeof dump != "undefined")\r
{\r
- dump("\n--- EUPHORIK.CH ---\n")\r
+ dump("\n--- EUPHORIK.CH : " + titre + " ---\n")\r
dump(this)\r
dump("\n------\n")\r
}\r
return documentXML.xml\r
}\r
+var documentXMLBase = undefined // singleton
Util.prototype.creerDocumentXMLAction = function()
-{\r
- if (document.implementation && document.implementation.createDocument)\r
- {\r
- // var doc = document.implementation.createDocument("", "action", null)
- var parser = new DOMParser();
- var doc = parser.parseFromString("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<action/>", "text/xml")
- //alert(this.serializeXML(doc))
- return doc\r
- }\r
- else if (window.ActiveXObject)\r
+{
+ // FIXME : essayer de garder le doc de base en cache (singleton) et d'en retourner une copie
+ if (true)//documentXMLBase == undefined)
{\r
- var doc = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM")\r
- doc.appendChild(doc.createElement("action"));\r
- //doc.loadXML("<action></action>")\r
- //alert(doc.documentElement)\r
- //doc.createElement("action")\r
- return doc\r
- }
+ if (document.implementation && document.implementation.createDocument)\r
+ {\r
+ // var doc = document.implementation.createDocument("", "action", null)
+ var parser = new DOMParser();
+ documentXMLBase = parser.parseFromString("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<action/>", "text/xml")
+ //alert(this.serializeXML(doc))\r
+ }\r
+ else if (window.ActiveXObject)\r
+ {\r
+ documentXMLBase = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM")\r
+ documentXMLBase.appendChild(doc.createElement("action"));\r
+ //doc.loadXML("<action></action>")\r
+ //alert(doc.documentElement)\r
+ //doc.createElement("action")\r
+ }
+ }
+ return documentXMLBase
}
Util.prototype.xmlVersAction = function(xml)
//return {action: this.to_utf8(this.serializeXML(xml /*, "UTF-8"*/))}
return {action: this.serializeXML(xml)}
}
+
+/**
+ * Utilisé pour l'envoie de donnée avec la méthode ajax de jQuery.
+ */
+Util.prototype.jsonVersAction = function(json)
+{
+ // FIXME : ne plus encapsuler json dans de l'xml (problème avec yaws)
+ return {action: "<json>" + JSON.stringify(json) + "</json>" }
+}
\r
Util.prototype.md5 = function(chaine)\r
{\r
Formateur.prototype.traitementComplet = function(M, pseudo)
{
- return this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo))
+ return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo)))
+}
+
+/**
+ * Transforme les liens en entités clickables.
+ * Un lien vers une conversation permet d'ouvrire celle ci, elle se marque comme ceci dans un message :
+ * "{5F}" ou 5F est la racine de la conversation.
+ * Ce lien sera transformer en <span class="lienConv">{5F}</span> pouvant être clické pour créer la conv 5F.
+ */
+Formateur.prototype.traiterLiensConv = function(M)
+{
+ return M.replace(
+ /\{\w+\}/g,
+ function(lien)
+ {
+ return "<span class=\"lienConv\">" + lien + "</span>"
+ }
+ )
}
\r
/**\r
- * FIXME : Cette méthode est attrocement lourde !!\r
+ * FIXME : Cette méthode est attrocement lourde ! A optimiser.\r
*/
Formateur.prototype.traiterSmiles = function(M)
{
\r
this.cookie = null
this.regexCookie = new RegExp("^cookie=([^;]*)")
- \r
- // Obsolète
- //this.captchaCrypt = null
// données personnels\r
this.resetDonneesPersonnelles()
}
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
+ else
this.conversations[numConv].page += 1
this.flush(false)
}
-Client.prototype.pagePrecedente = function(numConv)
+/**
+ * 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)
- this.pagePrincipale -= 1
- else
- this.conversations[numConv].page -= 1
+ {
+ 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
}
/**
return XMLDocument
}
+Client.prototype.getJSONLogin = function(login, password)
+{
+ return {
+ "action" : "authentification",
+ "login" : login,
+ "password" : password
+ }
+}
+
Client.prototype.getXMLloginCookie = function()
{
var XMLDocument = this.util.creerDocumentXMLAction()
return XMLDocument
}
-\r
-/* Obsolète
-Client.prototype.getXMLloginCaptcha = function(captchaCrypt, captchaInput)
-{
- var XMLDocument = this.util.creerDocumentXMLAction()
- XMLDocument.documentElement.setAttribute("name", "loginCaptcha")
-
- var nodecaptchaCrypt = XMLDocument.createElement("captchaCrypt")
- nodecaptchaCrypt.appendChild(XMLDocument.createTextNode(captchaCrypt))
- XMLDocument.documentElement.appendChild(nodecaptchaCrypt)
-
- var nodecaptchaInput = XMLDocument.createElement("captchaInput")
- nodecaptchaInput.appendChild(XMLDocument.createTextNode(captchaInput))
- XMLDocument.documentElement.appendChild(nodecaptchaInput)
-
- return XMLDocument
-}*/
-\r
-/* Obsolète
-Client.prototype.getXMLgenerationCaptcha = function()
-{
- var XMLDocument = this.util.creerDocumentXMLAction()
- XMLDocument.documentElement.setAttribute("name", "generationCaptcha")
-
- return XMLDocument
-}*/
Client.prototype.getXMLEnregistrement = function(login, password)
{
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.appendChild(nodeCSS)
var nodePagePrincipale = XMLDocument.createElement("pagePrincipale")
- nodePagePrincipale.appendChild(XMLDocument.createTextNode(this.pagePrincipale))
+ nodePagePrincipale.appendChild(XMLDocument.createTextNode(this.pagePrincipale < 1 ? 1 : this.pagePrincipale))
XMLDocument.documentElement.appendChild(nodePagePrincipale)
// mémorise les conversations affichées
\r
this.statut = statut \r
this.majMenu()
-}\r
-
-/**
- * Demande la génération d'un captcha au serveur et l'affiche.
- */\r
- /* Obsolète
-Client.prototype.afficherCaptcha = function(query)
-{
- var thisClient = this
-
- $.post("request", this.util.xmlVersAction(this.getXMLgenerationCaptcha()),
- function(data, textStatus)
- {
- var chemin = jQuery("chemin", data.documentElement).text()
- thisClient.captchaCrypt = jQuery("captchaCrypt", data.documentElement).text()
- jQuery(query).prepend(
- "<p id=\"captcha\" >Es-tu un bot ? <img class=\"captchaImg\" src=\"" + chemin + "\" />" +
- "<input name=\"captchaInput\" type=\"text\" size=\"5\" max_length=\"5\" ></p>"
- )
- }
- )
}
-
-Client.prototype.cacherCaptcha = function()
-{
- jQuery("#captcha").remove()
-}*/
\r
/**\r
* Effectue la connexion vers le serveur.\r
Client.prototype.connexionLogin = function(login, password)
{
- return this.connexion(this.util.xmlVersAction(this.getXMLlogin(login, password)))
-}
-\r
-/* Obsolète\r
-Client.prototype.connexionCaptcha = function()
-{
- return this.connexion(this.util.xmlVersAction(this.getXMLloginCaptcha(this.captchaCrypt, jQuery("#captcha input").val())))
-}*/
+ // return this.connexion(this.util.xmlVersAction(this.getXMLlogin(login, password)))
+ return this.connexion(this.util.jsonVersAction(this.getJSONLogin(login, password)))
+}\r
Client.prototype.enregistrement = function(login, password)
{
Client.prototype.connexion = function(action)
{
- //action.action.dump()
+ action.action.dump("Connexion client")
thisClient = this
jQuery.ajax(
{
async: false,
type: "POST",
url: "request",
- dataType: "xml",
+ dataType: "json",
data: action,
success:
function(data)
{
- //thisClient.util.serializer.serializeToString(data).dump()
+ thisClient.util.serializer.serializeToString(data).dump("Charger client")
thisClient.chargerDonnees(data)
}
}
// la page de la conversation principale
var tmp = jQuery("pagePrincipale", data.documentElement)
- this.pagePrincipale = tmp.length < 1 ? 1 : tmp.text()
+ this.pagePrincipale = tmp.length < 1 ? 1 : parseInt(tmp.text())
// met à jour la css
if (this.css != "")
async = true
thisClient = this
- //thisClient.util.log(this.util.xmlVersAction(this.getXMLProfile()).action)
+ this.util.xmlVersAction(this.getXMLProfile()).action.dump("Flush client")
jQuery.ajax(
{
async: async,