X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=js%2Feuphorik.js;h=4b76b93a5fff367cc39989334bcf9d5fe123fa2d;hb=42445687d95289c3c3f70e1e8d76278107a8b125;hp=fafa85418db926b6fc86883a58fe56f2b412e3d6;hpb=cded85bdaf899cef1ba38d2ee6fd24c67f2abc52;p=euphorik.git diff --git a/js/euphorik.js b/js/euphorik.js index fafa854..4b76b93 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -12,7 +12,7 @@ * Normalement 'const' à la place de 'var' mais non supporté par IE7. */ var conf = { - nbMessageAffiche : 80, // (par page) + nbMessageAffiche : 10, // (par page) pseudoDefaut : "", tempsAffichageMessageDialogue : 4000, // en ms smiles : { @@ -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") } @@ -72,8 +73,7 @@ function Util() { if(typeof XMLSerializer != "undefined") this.serializer = new XMLSerializer() - - // fermeture des dialogues d + jQuery("#info .fermer").click(function(){ jQuery("#info").slideUp(50) }) @@ -124,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) @@ -299,7 +303,7 @@ Formateur.prototype.traitementComplet = function(M, pseudo) } /** - * FIXME : Cette méthode est attrocement lourde !! + * FIXME : Cette méthode est attrocement lourde ! A optimiser. */ Formateur.prototype.traiterSmiles = function(M) { @@ -413,6 +417,8 @@ Client.prototype.resetDonneesPersonnelles = function() this.email = "" this.css = jQuery("link#cssPrincipale").attr("href") + this.pagePrincipale = 1 + // les conversations, une conversation est un objet possédant les attributs suivants : // - racine (entier) // - page (entier) @@ -432,15 +438,74 @@ Client.prototype.setCss = function(css) 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() + 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) } Client.prototype.getXMLlogin = function(login, password) @@ -513,6 +578,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() @@ -542,24 +611,23 @@ Client.prototype.getXMLProfile = function() 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 - if (this.conversations.length > 0) + for (var i = 0; i < this.conversations.length; i++) { - var nodeConversations = XMLDocument.createElement("conversations") - XMLDocument.documentElement.appendChild(nodeConversations) - for (var i = 0; i < this.conversations.length; i++) - { - var nodeConv = XMLDocument.createElement("conversation") - nodeConversations.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) - } + 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 @@ -680,6 +748,7 @@ Client.prototype.enregistrement = function(login, password) Client.prototype.connexion = function(action) { + //action.action.dump() thisClient = this jQuery.ajax( { @@ -691,6 +760,7 @@ Client.prototype.connexion = function(action) success: function(data) { + //thisClient.util.serializer.serializeToString(data).dump("Charger client") thisClient.chargerDonnees(data) } } @@ -707,6 +777,8 @@ Client.prototype.deconnexion = function() Client.prototype.chargerDonnees = function(data) { + var thisClient = this + this.setStatut(jQuery("statut", data.documentElement).text()) if (this.identifie()) @@ -718,26 +790,43 @@ Client.prototype.chargerDonnees = function(data) this.pseudo = jQuery("pseudo", data.documentElement).text() this.email = jQuery("email", data.documentElement).text() 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() +Client.prototype.flush = function(async) { + if (async == undefined) + 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: true, + async: async, type: "POST", url: "request", dataType: "xml",