X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=js%2Feuphorik.js;h=bd0cd3ad403a73b316a39a35fdd77600bf4ccbd0;hb=35b6b48d4c8fe3a262a4f01f9b97f0b2d7fdbbdf;hp=8487f776b7a483a387839202d146d193ce2c9a63;hpb=0531ee46484ef22f402191cc4dc84ca07f155fe4;p=euphorik.git
diff --git a/js/euphorik.js b/js/euphorik.js
index 8487f77..bd0cd3a 100755
--- a/js/euphorik.js
+++ b/js/euphorik.js
@@ -53,11 +53,12 @@ String.prototype.rtrim = function()
return this.replace(/\s+$/, "");
}
-String.prototype.dump = function()
-{
+String.prototype.dump = function(titre)
+{
+ titre = titre == undefined ? "" : titre
if (typeof dump != "undefined")
{
- dump("\n--- EUPHORIK.CH ---\n")
+ dump("\n--- EUPHORIK.CH : " + titre + " ---\n")
dump(this)
dump("\n------\n")
}
@@ -123,25 +124,29 @@ Util.prototype.serializeXML = function(documentXML)
return documentXML.xml
}
+var documentXMLBase = undefined // singleton
Util.prototype.creerDocumentXMLAction = function()
-{
- if (document.implementation && document.implementation.createDocument)
- {
- // var doc = document.implementation.createDocument("", "action", null)
- var parser = new DOMParser();
- var doc = parser.parseFromString("\n", "text/xml")
- //alert(this.serializeXML(doc))
- return doc
- }
- else if (window.ActiveXObject)
+{
+ // FIXME : essayer de garder le doc de base en cache (singleton) et d'en retourner une copie
+ if (true)//documentXMLBase == undefined)
{
- var doc = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM")
- doc.appendChild(doc.createElement("action"));
- //doc.loadXML("")
- //alert(doc.documentElement)
- //doc.createElement("action")
- return doc
- }
+ if (document.implementation && document.implementation.createDocument)
+ {
+ // var doc = document.implementation.createDocument("", "action", null)
+ var parser = new DOMParser();
+ documentXMLBase = parser.parseFromString("\n", "text/xml")
+ //alert(this.serializeXML(doc))
+ }
+ else if (window.ActiveXObject)
+ {
+ documentXMLBase = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM")
+ documentXMLBase.appendChild(doc.createElement("action"));
+ //doc.loadXML("")
+ //alert(doc.documentElement)
+ //doc.createElement("action")
+ }
+ }
+ return documentXMLBase
}
Util.prototype.xmlVersAction = function(xml)
@@ -149,6 +154,15 @@ 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.stringify(json) + "" }
+}
Util.prototype.md5 = function(chaine)
{
@@ -294,11 +308,28 @@ Formateur.prototype.getSmilesHTML = function()
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 {5F} pouvant être clické pour créer la conv 5F.
+ */
+Formateur.prototype.traiterLiensConv = function(M)
+{
+ return M.replace(
+ /\{\w+\}/g,
+ function(lien)
+ {
+ return "" + lien + ""
+ }
+ )
}
/**
- * FIXME : Cette méthode est attrocement lourde !!
+ * FIXME : Cette méthode est attrocement lourde ! A optimiser.
*/
Formateur.prototype.traiterSmiles = function(M)
{
@@ -391,9 +422,6 @@ function Client(util)
this.cookie = null
this.regexCookie = new RegExp("^cookie=([^;]*)")
-
- // Obsolète
- //this.captchaCrypt = null
// données personnels
this.resetDonneesPersonnelles()
@@ -434,21 +462,43 @@ Client.prototype.setCss = function(css)
}
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
}
/**
@@ -497,6 +547,15 @@ Client.prototype.getXMLlogin = function(login, password)
return XMLDocument
}
+Client.prototype.getJSONLogin = function(login, password)
+{
+ return {
+ "action" : "authentification",
+ "login" : login,
+ "password" : password
+ }
+}
+
Client.prototype.getXMLloginCookie = function()
{
var XMLDocument = this.util.creerDocumentXMLAction()
@@ -508,32 +567,6 @@ Client.prototype.getXMLloginCookie = function()
return XMLDocument
}
-
-/* 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
-}*/
-
-/* Obsolète
-Client.prototype.getXMLgenerationCaptcha = function()
-{
- var XMLDocument = this.util.creerDocumentXMLAction()
- XMLDocument.documentElement.setAttribute("name", "generationCaptcha")
-
- return XMLDocument
-}*/
Client.prototype.getXMLEnregistrement = function(login, password)
{
@@ -551,6 +584,10 @@ 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()
@@ -581,7 +618,7 @@ Client.prototype.getXMLProfile = function()
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
@@ -645,33 +682,7 @@ Client.prototype.setStatut = function(statut)
this.statut = statut
this.majMenu()
-}
-
-/**
- * Demande la génération d'un captcha au serveur et l'affiche.
- */
- /* 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(
- "
Es-tu un bot ? " +
- "
"
- )
- }
- )
}
-
-Client.prototype.cacherCaptcha = function()
-{
- jQuery("#captcha").remove()
-}*/
/**
* Effectue la connexion vers le serveur.
@@ -688,14 +699,9 @@ Client.prototype.connexionCookie = function()
Client.prototype.connexionLogin = function(login, password)
{
- return this.connexion(this.util.xmlVersAction(this.getXMLlogin(login, password)))
-}
-
-/* Obsolète
-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)))
+}
Client.prototype.enregistrement = function(login, password)
{
@@ -717,19 +723,19 @@ 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)
}
}
@@ -762,7 +768,7 @@ Client.prototype.chargerDonnees = function(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 != "")
@@ -792,7 +798,7 @@ Client.prototype.flush = function(async)
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,