X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;ds=inline;f=js%2FpageAdmin.js;h=9ed847e64530e2e43129a029051e171793342d6a;hb=0cca28444881b1a405525b10960915a638936fdd;hp=2a6cbc18bb1758b4df6c9d7d29b1da5c60aad523;hpb=cdff108e3b859493cff8e3f37fc8b52cb20d75d5;p=euphorik.git
diff --git a/js/pageAdmin.js b/js/pageAdmin.js
index 2a6cbc1..9ed847e 100644
--- a/js/pageAdmin.js
+++ b/js/pageAdmin.js
@@ -17,18 +17,19 @@
// along with Euphorik. If not, see .
//
// La page d'administation, ne peut être accédée que par les ekMaster (admins)
-
-/*jslint laxbreak:true */
-
-euphorik.PageAdmin = function(client, formateur, util) {
+/*jslint laxbreak:true */
+
+
+euphorik.PageAdmin = function(client, formateur, util, communication) {
this.nom = "admin";
this.client = client;
this.formateur = formateur;
this.util = util;
+ this.communication = communication;
- this.pageEvent = new euphorik.PageEvent("admin", this.util);
+ this.comet = new Comet("admin", euphorik.conf.versionProtocole);
// le timer qui rappelle periodiquement le rafraichissement des IP bannies
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.formateur, this.communication);
this.waitEvent();
@@ -80,11 +81,11 @@ euphorik.PageAdmin.prototype.charger = function() {
* Interface des pages.
*/
euphorik.PageAdmin.prototype.decharger = function() {
- this.pageEvent.stopAttenteCourante();
+ this.comet.stopAttenteCourante();
// supprime le rafraichissement période des ips
if (this.timeoutIDmajIPs) {
- clearTimeout(this.timeoutIDmajIPs);
+ clearTimeout(this.timeoutIDmajIPs);
}
};
@@ -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("");
+ }
+ );
};
/**
@@ -129,67 +117,55 @@ euphorik.PageAdmin.prototype.posterTroll = function() {
*/
euphorik.PageAdmin.prototype.majIPs = function() {
if (this.timeoutIDmajIPs) {
- clearTimeout(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(ip) {
- XHTML += '
' + ip.ip + '|' +
- '' +
- ip.remaining_time +
- '|';
- ip.users.each(function(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}
+ );
};
/**
@@ -224,7 +186,7 @@ euphorik.PageAdmin.prototype.deban = function(ip) {
euphorik.PageAdmin.prototype.waitEvent = function() {
var thisPageAdmin = this;
- this.pageEvent.waitEvent(
+ this.comet.waitEvent(
function() { return { "last_troll" : thisPageAdmin.trolls.dernierTroll }; },
{
"troll_added" : function(data){ thisPageAdmin.trolls.ajouterTrollEvent(data); },
@@ -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 = {};
@@ -263,12 +226,12 @@ euphorik.Trolls = function(client, util, formateur) {
euphorik.Trolls.prototype.ajouterTrollEvent = function(data) {
var thisTrolls = this;
- var XHTML = "";
- data.trolls.each(function(trollData) {
+ var XHTML = "";
+ 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 +=
'' +
'
' + thisTrolls.formateur.traitementComplet(troll.content, troll.author) + '' +
@@ -287,10 +250,10 @@ euphorik.Trolls.prototype.ajouterTrollEvent = function(data) {
$(this).keypress(
function(e) {
if (e.which === 13) { // return
- $(".modifier", this).click();
+ $(".modifier", this).click();
}
}
- );
+ );
$(".delTroll", this).click(
function() {
@@ -305,12 +268,12 @@ euphorik.Trolls.prototype.ajouterTrollEvent = function(data) {
}
);
}
- );
+ );
$(".editTroll", this).click(
function() {
$("span", troll).css("display", "none");
- $(troll).append(
+ $(troll).append(
'
'
@@ -336,7 +299,7 @@ euphorik.Trolls.prototype.ajouterTrollEvent = function(data) {
);
if (data.trolls.length > 0) {
- thisTrolls.dernierTroll = data.trolls[data.trolls.length - 1].troll_id;
+ thisTrolls.dernierTroll = data.trolls[data.trolls.length - 1].troll_id;
}
};
@@ -347,56 +310,23 @@ euphorik.Trolls.prototype.modifierTrollEvent = function(data) {
thisTrolls.trolls[data.troll_id].content = data.content;
};
-Trolls.prototype.supprimerTrollEvent = function(data) {
+euphorik.Trolls.prototype.supprimerTrollEvent = function(data) {
$("#trolls #troll" + data.troll_id).remove();
};
-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);
- }
- }
- });
+euphorik.Trolls.prototype.modifier = function(id, content) {
+ 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}
+ );
};