+ function() {
+ thisPage.posterTroll();
+ }
+ );
+};
+
+/**
+ * Interface des pages.
+ */
+euphorik.PageAdmin.prototype.decharger = function() {
+ this.comet.stopAttenteCourante();
+
+ // supprime le rafraichissement période des ips
+ if (this.timeoutIDmajIPs) {
+ clearTimeout(this.timeoutIDmajIPs);
+ }
+};
+
+/**
+ * Post un troll, le contenu est lu à partir de "input.troll".
+ */
+euphorik.PageAdmin.prototype.posterTroll = function() {
+ var thisPageAdmin = this;
+
+ var content = $("#page form#nouveauTroll input.troll").val();
+
+ content = content.trim();
+ if (content === "") {
+ this.util.messageDialogue("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);
+ }
+ }
+ });
+};
+
+/**
+ * Met à jour la liste des IP bannies.
+ */
+euphorik.PageAdmin.prototype.majIPs = function() {
+ if (this.timeoutIDmajIPs) {
+ clearTimeout(this.timeoutIDmajIPs);
+ }
+
+ 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 += '<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="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(){}
+ }
+ );
+ }
+ );
+ });
+ } 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);
+ }
+ });
+};
+
+/**
+ * Débannie une ip donnée.
+ */
+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);
+ }
+ }
+ });
+};
+
+/**
+ * Attente d'événement de la part du serveur.
+ */
+euphorik.PageAdmin.prototype.waitEvent = function() {
+ var thisPageAdmin = this;
+
+ this.comet.waitEvent(
+ function() { return { "last_troll" : thisPageAdmin.trolls.dernierTroll }; },
+ {
+ "troll_added" : function(data){ thisPageAdmin.trolls.ajouterTrollEvent(data); },
+ "troll_modified" : function(data){ thisPageAdmin.trolls.modifierTrollEvent(data); },
+ "troll_deleted" : function(data){ thisPageAdmin.trolls.supprimerTrollEvent(data); },
+ "banned_ips_refresh" : function(data){ thisPageAdmin.majIPs(); },
+ "error" :
+ function(data) {
+ thisTrolls.util.messageDialogue(data.error_message);
+ }