MOD french -> english (6)
[euphorik.git] / js / pageAdmin.js
index 06c2ca5..f94f9ab 100644 (file)
 /*jslint laxbreak:true */
 
 
-euphorik.PageAdmin = function(client, formateur, util) {
-   this.nom = "admin";
+euphorik.PageAdmin = function(client, formater, util, communication) {
+   this.name = "admin";
    
    this.client = client;
-   this.formateur = formateur;
+   this.formater = formater;
    this.util = util;
+   this.communication = communication;
    
-   this.comet = new Comet("admin", euphorik.conf.versionProtocole);
+   this.comet = this.communication.createCometConnection("admin");
    
-   // le timer qui rappelle periodiquement le rafraichissement des IP bannies
+   // a timer which will periodically refresh the banned IP list
    this.timeoutIDmajIPs = null;
 };
 
@@ -61,7 +62,7 @@ euphorik.PageAdmin.prototype.charger = function() {
    var thisPage = this;
    
    // la liste des trolls proposés par les ekMasters
-   this.trolls = new euphorik.Trolls(this.client, this.util, this.formateur);
+   this.trolls = new euphorik.Trolls(this.client, this.util, this.formater, this.communication);
    
    this.waitEvent();
    
@@ -98,30 +99,17 @@ euphorik.PageAdmin.prototype.posterTroll = function() {
    
    content = content.trim();
    if (content === "") {
-      this.util.messageDialogue("Le troll est vide");
+      this.util.messageDialog("Le troll est vide");
       return;
    }
 
-   var dataToSend = {
-      "header" : { "action" : "put_troll", "version" : euphorik.conf.versionProtocole },
-      "cookie" : this.client.cookie,
-      "content" : content
-   };
-
-   jQuery.ajax({
-      type: "POST",
-      url: "request",
-      dataType: "json",
-      data: this.util.jsonVersAction(dataToSend),
-      success:
-         function(data){               
-            if (data.reply === "ok") {
-               $("#page form#nouveauTroll input.troll").val("");
-            } else if (data.reply === "error") {
-               thisPageAdmin.util.messageDialogue(data.error_message);
-            }
-         }
-   });
+   this.communication.requete(
+      "put_troll",
+      {"cookie" : this.client.cookie, "content" : content},
+      function(data) {
+         $("#page form#nouveauTroll input.troll").val("");
+      }
+   );
 };
 
 /**
@@ -133,63 +121,51 @@ euphorik.PageAdmin.prototype.majIPs = function() {
    }
 
    var thisPageAdmin = this;
-
-   var dataToSend = {
-      "header" : { "action" : "list_banned_ips", "version" : euphorik.conf.versionProtocole },
-      "cookie" : this.client.cookie
-   };
-
-   jQuery.ajax({
-      type: "POST",
-      url: "request",
-      dataType: "json",
-      data: this.util.jsonVersAction(dataToSend),
-      success:
-         function(data) {               
-            if (data.reply === "list_banned_ips") {
-               var XHTML = "";
-               data.list.each(function(ip) {
-                  XHTML += '<div class="ban"><span class="ip">' + ip.ip + '</span>|' +
-                     '<span class="temps">' +
-                     ip.remaining_time +
-                     '</span>|';
-                  ip.users.each(function(user) {
-                     XHTML += (j > 0 ? ", " : "") +
-                        '<span class="pseudo">' + thisPageAdmin.formateur.traitementComplet(user.nick) + '</span>' +
-                        (user.login === "" ? "" : '<span class="login">(' + thisPageAdmin.formateur.traitementComplet(user.login) + ')</span>');
-                  });
-                  XHTML += '<span class="deban">débannir</span></div>';
-               });
-               
-               if (data.list.length === 0) {
-                  XHTML += '<p>Aucune IP bannie</p>';
-               }
-                  
-               $("#ips").html(XHTML);
-               
-               $(".ban").each(function() {
-                  var ip = $(".ip", this).html();
-                  $(".deban", this).click(
-                     function() {
-                        thisPageAdmin.util.messageDialogue("Êtes-vous sur de vouloir débannir l'IP ''" + ip + "'' ?", euphorik.Util.messageType.question,
-                           {"Oui" : function() {
-                                 thisPageAdmin.deban(ip);
-                              },
-                            "Non" : function(){}
-                           }
-                        );
+   
+   this.communication.requete(
+      "list_banned_ips",
+      {"cookie" : this.client.cookie},
+      function(data) {   
+         var XHTML = "";
+         data.list.each(function(i, ip) {
+            XHTML += '<div class="ban"><span class="ip">' + ip.ip + '</span>|' +
+               '<span class="temps">' +
+               ip.remaining_time +
+               '</span>|';
+            ip.users.each(function(j, user) {
+               XHTML += (j > 0 ? ", " : "") +
+                  '<span class="nick">' + thisPageAdmin.formater.traitementComplet(user.nick) + '</span>' +
+                  (user.login === "" ? "" : '<span class="login">(' + thisPageAdmin.formater.traitementComplet(user.login) + ')</span>');
+            });
+            XHTML += '<span class="deban">débannir</span></div>';
+         });
+         
+         if (data.list.length === 0) {
+            XHTML += '<p>Aucune IP bannie</p>';
+         }
+            
+         $("#ips").html(XHTML);
+         
+         $(".ban").each(function() {
+            var ip = $(".ip", this).html();
+            $(".deban", this).click(
+               function() {
+                  thisPageAdmin.util.messageDialog("Êtes-vous sur de vouloir débannir l'IP ''" + ip + "'' ?", euphorik.Util.messageType.question,
+                     {"Oui" : function() {
+                           thisPageAdmin.deban(ip);
+                        },
+                      "Non" : function(){}
                      }
                   );
-               });
-            } else if (data.reply === "error") {
-               thisPageAdmin.util.messageDialogue(data.error_message);
-            }
+               }
+            );
+         });
             
-            // rafraichissement toutes les minutes (je sais c'est mal)
-            // le problème est le rafraichissement des temps restant de bannissement qui doit être fait du coté client
-            thisPageAdmin.timeoutIDmajIPs = setTimeout(function(){ thisPageAdmin.majIPs(); }, 60 * 1000);
-         }
-   });
+         // rafraichissement toutes les minutes (je sais c'est mal)
+         // le problème est le rafraichissement des temps restant de bannissement qui doit être fait du coté client
+         thisPageAdmin.timeoutIDmajIPs = setTimeout(function(){ thisPageAdmin.majIPs(); }, 60 * 1000);
+      }
+   );
 };
 
 /**
@@ -197,25 +173,11 @@ euphorik.PageAdmin.prototype.majIPs = function() {
   */
 euphorik.PageAdmin.prototype.deban = function(ip) {
    var thisPageAdmin = this;
-
-   var dataToSend = {
-      "header" : { "action" : "unban", "version" : euphorik.conf.versionProtocole },
-      "cookie" : this.client.cookie,
-      "ip" : ip
-   };
-
-   jQuery.ajax({
-      type: "POST",
-      url: "request",
-      dataType: "json",
-      data: this.util.jsonVersAction(dataToSend),
-      success:
-         function(data){
-            if(data.reply === "error") {
-               thisPageAdmin.util.messageDialogue(data.error_message);
-            }
-         }
-   });
+   
+   this.communication.requete(
+      "unban", 
+      {"cookie" : this.client.cookie, "ip" : ip}
+   );
 };
 
 /**
@@ -233,7 +195,7 @@ euphorik.PageAdmin.prototype.waitEvent = function() {
          "banned_ips_refresh" : function(data){ thisPageAdmin.majIPs(); },
          "error" :
             function(data) {
-               thisTrolls.util.messageDialogue(data.error_message);
+               thisTrolls.util.messageDialog(data.error_message);
             }
       }
    );
@@ -251,10 +213,11 @@ euphorik.Troll = function(content, author) {
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-euphorik.Trolls = function(client, util, formateur) {
+euphorik.Trolls = function(client, util, formater, communication) {
    this.client = client;
    this.util = util;
-   this.formateur = formateur;
+   this.formater = formater;
+   this.communication = communication;
    this.dernierTroll = 0;
    
    this.trolls = {};
@@ -264,15 +227,15 @@ euphorik.Trolls.prototype.ajouterTrollEvent = function(data) {
    var thisTrolls = this;
 
    var XHTML = "";
-   data.trolls.each(function(trollData) {
+   data.trolls.each(function(i, trollData) {
       var troll = new euphorik.Troll(trollData.content, trollData.author);
       var trollId = trollData.troll_id;
       thisTrolls.trolls[trollId] = troll;
-   
+      
       XHTML +=
          '<div id="troll' + trollId + '" class="troll">' +
-         '<span class="content">' + thisTrolls.formateur.traitementComplet(troll.content, troll.author) + '</span>' +
-         '<span class="author"> - ' + thisTrolls.formateur.traitementComplet(troll.author) + '</span>' +
+         '<span class="content">' + thisTrolls.formater.traitementComplet(troll.content, troll.author) + '</span>' +
+         '<span class="author"> - ' + thisTrolls.formater.traitementComplet(troll.author) + '</span>' +
          (trollData.author_id === thisTrolls.client.id ? '<span class="editTroll">éditer</span><span class="delTroll">Supprimer</span>' : '') +
          '</div>';
    });
@@ -294,7 +257,7 @@ euphorik.Trolls.prototype.ajouterTrollEvent = function(data) {
          
          $(".delTroll", this).click(
             function() {
-               thisTrolls.util.messageDialogue(
+               thisTrolls.util.messageDialog(
                   "Êtes-vous sur de vouloir supprimer le troll \"" + thisTrolls.trolls[id].content + "\" ?",
                   euphorik.Util.messageType.question,
                   {
@@ -342,7 +305,7 @@ euphorik.Trolls.prototype.ajouterTrollEvent = function(data) {
 
 euphorik.Trolls.prototype.modifierTrollEvent = function(data) {
    var thisTrolls = this;
-   $("#trolls #troll" + data.troll_id + " .content").html(thisTrolls.formateur.traitementComplet(data.content, thisTrolls.trolls[data.troll_id].author));
+   $("#trolls #troll" + data.troll_id + " .content").html(thisTrolls.formater.traitementComplet(data.content, thisTrolls.trolls[data.troll_id].author));
    $("#trolls #troll" + data.troll_id + " a[@rel*=lightbox]").lightBox();
    thisTrolls.trolls[data.troll_id].content = data.content;
 };
@@ -352,51 +315,18 @@ euphorik.Trolls.prototype.supprimerTrollEvent = function(data) {
 };
 
 euphorik.Trolls.prototype.modifier = function(id, content) {
-   var thisTrolls = this;
-   
-   var dataToSend = {
-      "header" : { "action" : "mod_troll", "version" : euphorik.conf.versionProtocole },
-      "cookie" : this.client.cookie,
-      "troll_id" : id,
-      "content" : content
-   };
-
-   jQuery.ajax({
-      type: "POST",
-      url: "request",
-      dataType: "json",
-      data: this.util.jsonVersAction(dataToSend),
-      success:
-         function(data) {
-            if (data.reply === "error") {
-               thisTrolls.util.messageDialogue(data.error_message);
-            }
-         }
-   });
+   this.communication.requete(
+      "mod_troll",
+      {"cookie" : this.client.cookie, "troll_id" : id, "content" : content}
+   );
 };
 
 /**
   * Supprime un troll en fonction de son id.
   */
 euphorik.Trolls.prototype.supprimer = function(id) {
-   var thisTrolls = this;
-
-   var dataToSend = {
-      "header" : { "action" : "del_troll", "version" : euphorik.conf.versionProtocole },
-      "cookie" : this.client.cookie,
-      "troll_id" : id
-   };
-
-   jQuery.ajax({
-      type: "POST",
-      url: "request",
-      dataType: "json",
-      data: this.util.jsonVersAction(dataToSend),
-      success:
-         function(data) {
-            if (data.reply === "error") {
-               thisTrolls.util.messageDialogue(data.error_message);
-            }
-         }
-   });
+   this.communication.requete(
+      "del_troll",
+      {"cookie" : this.client.cookie, "troll_id" : id}
+   );
 };