X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fclient.js;h=1e872799ca8ab670f49da5d6aff9531f5f0db9ed;hp=917ae8ee85594c056f3c5f80b760353bcc4b9b2a;hb=5d9992368bb386d2e606ae037c5478fe10ac70e8;hpb=eb44db02bab9c8b082201aa153dea8229432e894 diff --git a/js/client.js b/js/client.js index 917ae8e..1e87279 100644 --- a/js/client.js +++ b/js/client.js @@ -35,14 +35,14 @@ euphorik.Client = function(util, communication) { this.util = util; this.communication = communication; - + this.cookie = null; this.regexCookie = /cookie=([^;]*)/; - + this.resetPersonalData(); - + this.setStatus(euphorik.Client.statusType.disconnected); - + // If true then each data change is flushed to the server. // Active only for opera which doesn't support the unload event. this.autoflush = $.browser.opera; @@ -50,14 +50,18 @@ euphorik.Client = function(util, communication) { // The three status of a client. euphorik.Client.statusType = { - // authentified and registered : The user can post messages and can modify his profile + // Authentified and registered : The user can post messages and can modify his profile. auth_registered : 0, - // authentified but not registered : The user can only post messages + // Authentified but not registered : The user can only post messages. auth_not_registered : 1, - // disconnected (the initial state) : The user cannot post message + // Disconnected (the initial state) : The user cannot post message. disconnected : 2 }; +/** + * Reset all the local personal data. Does not erase the remote data. + * This function is used during disconnecting. + */ euphorik.Client.prototype.resetPersonalData = function() { this.id = 0; this.nick = euphorik.conf.defaultNick; @@ -70,18 +74,24 @@ euphorik.Client.prototype.resetPersonalData = function() { this.viewTimes = true; this.viewTooltips = true; this.cookie = undefined; - + this.mainConversationPage = 1; this.ekMaster = false; this.ostentatiousMaster = "light"; - - // les conversations, une conversation est un objet possédant les propriétés suivantes : - // - root (entier) - // - page (entier) - // - reduit (bool) + + // The user opened conversations. + // Each conversation object owns theses properties : + // - root (integer) + // - page (integer) + // - isCollapsed (bool) this.conversations = []; }; +/** + * Set the CSS. Dynamically change the href to the CSS in the DOM. + * @css The relative path to the CSS file, for example : + * "styles/1/euphorik.css". + */ euphorik.Client.prototype.setCss = function(css) { if (this.css === css || !css) { return; @@ -89,12 +99,17 @@ euphorik.Client.prototype.setCss = function(css) { this.css = css; $("link#mainCss").attr("href", this.css); + if (this.autoflush) { this.flush(true); } }; -euphorik.Client.prototype.pageSuivante = function(numConv) { +/** + * Change the current page to the next one for the given conversation. + * @numConv The number of the conversation. + */ +euphorik.Client.prototype.nextPage = function(numConv) { if (numConv < 0 && this.mainConversationPage > 1) { this.mainConversationPage -= 1; } else if (this.conversations[numConv].page > 1) { @@ -102,7 +117,11 @@ euphorik.Client.prototype.pageSuivante = function(numConv) { } }; -euphorik.Client.prototype.pagePrecedente = function(numConv) { +/** + * Change the current page to the previous one for the given conversation. + * @numConv The number of the conversation. + */ +euphorik.Client.prototype.previousPage = function(numConv) { if (numConv < 0) { this.mainConversationPage += 1; } else { @@ -114,8 +133,7 @@ euphorik.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 */ -euphorik.Client.prototype.goPremierePage = function(numConv) -{ +euphorik.Client.prototype.goFirstPage = function(numConv) { if (numConv < 0) { if (this.mainConversationPage === 1) { return false; @@ -137,7 +155,7 @@ euphorik.Client.prototype.goPremierePage = function(numConv) * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà) */ euphorik.Client.prototype.ajouterConversation = function(racine) { - // vérification s'il elle n'existe pas déjà + // vérification s'il elle n'existe pas déjà var existe = false; this.conversations.each(function(i, conv) { if (conv.root === racine) { @@ -147,12 +165,12 @@ euphorik.Client.prototype.ajouterConversation = function(racine) { if (existe) { return false; } - - this.conversations.push({root : racine, page : 1, reduit : false}); + + this.conversations.push({root : racine, page : 1, isCollapsed : false}); if (this.autoflush) { this.flush(true); } - + return true; }; @@ -160,13 +178,13 @@ euphorik.Client.prototype.supprimerConversation = function(num) { if (num < 0 || num >= this.conversations.length) { return; } - - // décalage TODO : supprimer le dernier élément + + // 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(); - + if (this.autoflush) { this.flush(true); } @@ -175,7 +193,7 @@ euphorik.Client.prototype.supprimerConversation = function(num) { euphorik.Client.prototype.getJSONConversations = function() { var conversations = []; this.conversations.each(function(i, conv) { - conversations.push({ "root" : conv.root, "minimized" : conv.reduit }); + conversations.push({ "root" : conv.root, "minimized" : conv.isCollapsed }); }); return conversations; }; @@ -224,11 +242,11 @@ euphorik.Client.prototype.setCookie = function() { if (!this.cookie) { return; } - + // doesn't work under IE.... /*document.cookie = "cookie=" + this.cookie + "; max-age=" + (60 * 60 * 24 * 365) */ - - document.cookie = + + document.cookie = "cookie="+this.cookie+"; expires=" + new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365).toUTCString(); }; @@ -237,7 +255,7 @@ euphorik.Client.prototype.authentifie = function() { }; euphorik.Client.prototype.setStatus = function(statut) -{ +{ // conversation en "enum" si en "string" if (typeof(statut) === "string") { statut = @@ -245,20 +263,20 @@ euphorik.Client.prototype.setStatus = function(statut) euphorik.Client.statusType.auth_registered : (statut === "auth_not_registered" ? euphorik.Client.statusType.auth_not_registered : euphorik.Client.statusType.disconnected); } - + if (statut === this.statut) { return; } - + this.statut = statut; - + this.majMenu(); this.majLogo(); }; - -/** - * Try to authentify the client with the cookie information. - * Do nothing if there is no cookie. + +/** + * Try to authentify the client with the cookie information. + * Do nothing if there is no cookie. */ euphorik.Client.prototype.connectionCookie = function() { this.getCookie(); @@ -272,7 +290,7 @@ euphorik.Client.prototype.connexionLogin = function(login, password) { return this.connexion("authentification", {"login" : login, "password" : password }); }; -euphorik.Client.prototype.enregistrement = function(login, password) { +euphorik.Client.prototype.enregistrement = function(login, password) { if (this.authentifie()) { this.login = login; this.password = password; @@ -292,14 +310,14 @@ euphorik.Client.prototype.enregistrement = function(login, password) { */ euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { var mess = {}; - + if (login && password) { mess.login = login; mess.password = password; } - + mess.profile = this.getJSONProfileInfos(); - + return mess; }; @@ -308,7 +326,7 @@ euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { */ euphorik.Client.prototype.connexion = function(action, messageJson) { var thisClient = this; - + this.communication.requete( action, messageJson, @@ -335,13 +353,13 @@ euphorik.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 ? data.ek_master : false; - + this.setStatus(data.status); - + if (this.authentifie()) { this.cookie = data.cookie; this.setCookie(); - + this.id = data.id; this.login = data.login; this.nick = data.profile.nick; @@ -352,16 +370,16 @@ euphorik.Client.prototype.chargerDonnees = function(data) { this.viewTimes = data.profile.view_times; this.viewTooltips = data.profile.view_tooltips; this.ostentatiousMaster = data.profile.ostentatious_master; - + // la page de la conversation principale this.mainConversationPage = 1; - + // les conversations this.conversations = data.profile.conversations; this.conversations.map(function(conv) { - return { root : conv.root, page : 1, reduit : conv.minimized }; + return { root : conv.root, page : 1, isCollapsed : conv.minimized }; }); - + this.majBulle(); this.majCssSelectionee(); } @@ -374,19 +392,19 @@ euphorik.Client.prototype.chargerDonnees = function(data) { */ euphorik.Client.prototype.flush = function(async) { async = async || false; - + if (!this.authentifie()) { return false; } - + var thisClient = this; var ok = true; - + this.communication.requete( "set_profile", this.getJSONProfile(), function(data) { - thisClient.majBulle(); + thisClient.majBulle(); }, function(data) { thisClient.util.messageDialog(data.error_message); @@ -394,7 +412,7 @@ euphorik.Client.prototype.flush = function(async) { }, async ); - + return ok; }; @@ -402,8 +420,8 @@ euphorik.Client.prototype.majMenu = function() { var displayType = "block"; $("#menu .admin").css("display", this.ekMaster ? displayType : "none"); - - // met à jour le menu + + // met à jour le menu if (this.statut === euphorik.Client.statusType.auth_registered) { $("#menu .profile").css("display", displayType).text("profile"); $("#menu .logout").css("display", displayType);