X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2FpageAdmin.js;h=9ed847e64530e2e43129a029051e171793342d6a;hp=fc1d51a80ff060e8857df49d533d226f7ecf1d22;hb=85dc0facbc2b2de826978fac3768db7949a6b92f;hpb=455f79e2ab07847ea6697e51245288832ae9fede diff --git a/js/pageAdmin.js b/js/pageAdmin.js index fc1d51a..9ed847e 100644 --- a/js/pageAdmin.js +++ b/js/pageAdmin.js @@ -21,12 +21,13 @@ /*jslint laxbreak:true */ -euphorik.PageAdmin = function(client, formateur, util) { +euphorik.PageAdmin = function(client, formateur, util, communication) { this.nom = "admin"; this.client = client; this.formateur = formateur; this.util = util; + this.communication = communication; this.comet = new Comet("admin", euphorik.conf.versionProtocole); @@ -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.formateur, this.communication); this.waitEvent(); @@ -102,26 +103,13 @@ euphorik.PageAdmin.prototype.posterTroll = function() { 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(i, ip) { - XHTML += '
' + ip.ip + '|' + - '' + - ip.remaining_time + - '|'; - ip.users.each(function(j, user) { - XHTML += (j > 0 ? ", " : "") + - '' + thisPageAdmin.formateur.traitementComplet(user.nick) + '' + - (user.login === "" ? "" : '(' + thisPageAdmin.formateur.traitementComplet(user.login) + ')'); - }); - XHTML += 'débannir
'; - }); - - if (data.list.length === 0) { - XHTML += '

Aucune IP bannie

'; - } - - $("#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 += '
' + ip.ip + '|' + + '' + + ip.remaining_time + + '|'; + ip.users.each(function(j, user) { + XHTML += (j > 0 ? ", " : "") + + '' + thisPageAdmin.formateur.traitementComplet(user.nick) + '' + + (user.login === "" ? "" : '(' + thisPageAdmin.formateur.traitementComplet(user.login) + ')'); + }); + XHTML += 'débannir
'; + }); + + if (data.list.length === 0) { + XHTML += '

Aucune IP bannie

'; + } + + $("#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(){} } ); - }); - } 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} + ); }; /** @@ -251,10 +213,11 @@ euphorik.Troll = function(content, author) { /////////////////////////////////////////////////////////////////////////////////////////////////// -euphorik.Trolls = function(client, util, formateur) { +euphorik.Trolls = function(client, util, formateur, communication) { this.client = client; this.util = util; this.formateur = formateur; + this.communication = communication; this.dernierTroll = 0; this.trolls = {}; @@ -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} + ); };