ddde6906d5afb362ea4c4b7797633d0c39f4614c
2 // Copyright 2008 Grégory Burri
4 // This file is part of Euphorik.
6 // Euphorik is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // Euphorik is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
19 // La page d'administation, ne peut être accédée que par les ekMaster (admins)
21 function PageAdmin(client
, formateur
, util
)
26 this.formateur
= formateur
29 this.pageEvent
= new PageEvent("admin", this.util
)
31 // le timer qui rappelle periodiquement le rafraichissement des IP bannies
32 this.timeoutIDmajIPs
= null
36 * Interface des pages.
38 PageAdmin
.prototype.contenu = function()
42 <p>Un troll est un sujet à débat, en général une question, affiché sur la page principale.</p>\
43 <p>Chaque semaine un troll est choisi au hasard parmis les trolls proposés et devient le troll de la semaine.</p>\
44 <form action="" id="nouveauTroll">\
46 <input class="troll" name="troll" type="text" maxlength="500" value=""></input>\
47 <button class="return" value="return">poster</button>\
50 <div id="trolls"></div>\
56 * Interface des pages.
58 PageAdmin
.prototype.charger = function()
60 $("#page form#nouveauTroll").submit(function(){return false})
64 // la liste des trolls proposés par les ekMasters
65 this.trolls
= new Trolls(this.client
, this.util
, this.formateur
)
71 $("#page form#nouveauTroll input.troll").focus()
73 $("#page form#nouveauTroll button.return").click(
76 thisPage
.posterTroll()
82 * Interface des pages.
84 PageAdmin
.prototype.decharger = function()
86 this.pageEvent
.stopAttenteCourante()
88 // supprime le rafraichissement période des ips
89 if (this.timeoutIDmajIPs
)
90 clearTimeout(this.timeoutIDmajIPs
)
94 * Post un troll, le contenu est lu à partir de "input.troll".
96 PageAdmin
.prototype.posterTroll = function()
98 var thisPageAdmin
= this
100 var content
= $("#page form#nouveauTroll input.troll").val()
102 content
= content
.trim()
105 this.util
.messageDialogue("Le troll est vide")
111 "action" : "put_troll",
112 "cookie" : this.client
.cookie
,
116 ;; dumpObj(dataToSend
)
122 data: this.util
.jsonVersAction(dataToSend
),
128 if (data
["reply"] == "ok")
130 $("#page form#nouveauTroll input.troll").val("")
132 else if (data
["reply"] == "error")
134 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
142 * Met à jour la liste des IP bannies.
144 PageAdmin
.prototype.majIPs = function()
146 if (this.timeoutIDmajIPs
)
147 clearTimeout(this.timeoutIDmajIPs
)
149 var thisPageAdmin
= this
153 "action" : "list_banned_ips",
154 "cookie" : this.client
.cookie
157 ;; dumpObj(dataToSend
)
163 data: this.util
.jsonVersAction(dataToSend
),
169 if (data
["reply"] == "list_banned_ips")
172 for(var i
= 0; i
< data
["list"].length
; i
++)
174 var ip
= data
["list"][i
]
175 XHTML
+= '<div class="ban"><span class="ip">' + ip
["ip"] + '</span>|' +
176 '<span class="temps">' +
177 ip
["remaining_time"] +
179 for(var j
= 0; j
< ip
["users"].length
; j
++)
181 var user
= ip
["users"][j
]
182 XHTML
+= (j
> 0 ? ", " : "") +
183 '<span class="pseudo">' + thisPageAdmin
.formateur
.traitementComplet(user
["nick"]) + '</span>' +
184 (user
["login"] == "" ? "" : '<span class="login">(' + thisPageAdmin
.formateur
.traitementComplet(user
["login"]) + ')</span>')
186 XHTML
+= '<span class="deban">débannir</span></div>'
189 if (data
["list"].length
== 0)
190 XHTML
+= '<p>Aucune IP bannie</p>'
192 $("#ips").html(XHTML
)
197 var ip
= $(".ip", this).html()
198 $(".deban", this).click(
201 thisPageAdmin
.util
.messageDialogue("Êtes-vous sur de vouloir débannir l'IP ''" + ip
+ "'' ?", messageType
.question
,
204 thisPageAdmin
.deban(ip
)
214 else if (data
["reply"] == "error")
216 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
219 // rafraichissement toutes les minutes (je sais c'est mal)
220 // le problème est le rafraichissement des temps restant de bannissement qui doit être fait du coté client
221 thisPageAdmin
.timeoutIDmajIPs
= setTimeout(function(){ thisPageAdmin
.majIPs() }, 60 * 1000)
228 * Débannie une ip donnée.
230 PageAdmin
.prototype.deban = function(ip
)
232 var thisPageAdmin
= this
237 "cookie" : this.client
.cookie
,
241 ;; dumpObj(dataToSend
)
247 data: this.util
.jsonVersAction(dataToSend
),
252 if(data
["reply"] == "error")
254 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
262 * Attente d'événement de la part du serveur.
264 PageAdmin
.prototype.waitEvent = function()
266 var thisPageAdmin
= this
268 this.pageEvent
.waitEvent(
269 function() { return { "last_troll" : thisPageAdmin
.trolls
.dernierTroll
}},
272 switch (data
["reply"])
275 thisPageAdmin
.trolls
.ajouterTrollEvent(data
)
277 case "troll_modified" :
278 thisPageAdmin
.trolls
.modifierTrollEvent(data
)
280 case "troll_deleted" :
281 thisPageAdmin
.trolls
.supprimerTrollEvent(data
)
283 case "banned_ips_refresh" :
284 thisPageAdmin
.majIPs()
287 thisTrolls
.util
.messageDialogue(data
["error_message"])
294 ///////////////////////////////////////////////////////////////////////////////////////////////////
297 * Représente un troll, pas grand chose finalement.
299 function Troll(content
, author
)
301 this.content
= content
306 ///////////////////////////////////////////////////////////////////////////////////////////////////
309 function Trolls(client
, util
, formateur
)
313 this.formateur
= formateur
314 this.dernierTroll
= 0
319 Trolls
.prototype.ajouterTrollEvent = function(data
)
321 var thisTrolls
= this
324 for (var i
= 0; i
< data
["trolls"].length
; i
++)
326 var troll
= new Troll(data
["trolls"][i
]["content"], data
["trolls"][i
]["author"])
327 var trollId
= data
["trolls"][i
]["troll_id"]
328 thisTrolls
.trolls
[trollId
] = troll
331 '<div id="troll' + trollId
+ '" class="troll">' +
332 '<span class="content">' + thisTrolls
.formateur
.traitementComplet(troll
.content
, troll
.author
) + '</span>' +
333 '<span class="author"> - ' + thisTrolls
.formateur
.traitementComplet(troll
.author
) + '</span>' +
334 (data
["trolls"][i
]["author_id"] == thisTrolls
.client
.id
? '<span class="editTroll">éditer</span><span class="delTroll">Supprimer</span>' : '') +
337 $("#trolls").append(XHTML
)
338 $("#trolls .troll").filter(function(){return parseInt($(this).attr("id").substr(5)) > thisTrolls
.dernierTroll
}).each(
342 var id
= parseInt($(this).attr("id").substr(5))
344 $("a[@rel*=lightbox]", this).lightBox()
349 if (e
.which
== 13) // return
350 $(".modifier", this).click()
353 $(".delTroll", this).click(
356 thisTrolls
.util
.messageDialogue(
357 "Êtes-vous sur de vouloir supprimer le troll \"" + thisTrolls
.trolls
[id
].content
+ "\" ?",
358 messageType
.question
,
362 thisTrolls
.supprimer(id
)
369 $(".editTroll", this).click(
372 $("span", troll
).css("display", "none")
374 '<form><p><input class="content" type="text" size="50" maxlength="500" value="' +
375 thisTrolls
.trolls
[id
].content
+
376 '"></input><span class="modifier">modifier</span><span class="annuler">annuler</span></p></form>'
378 $("form input.content").focus()
380 var virerLeFormulaire = function()
382 $('form', troll
).remove()
383 $('span', troll
).css("display", "inline")
385 $("span.modifier", troll
).click(
388 var content
= $("form input.content", troll
).val()
390 thisTrolls
.modifier(id
, content
)
393 $("span.annuler", troll
).click( virerLeFormulaire
)
394 $("form", troll
).submit(function(){ return false})
400 if (data
["trolls"].length
> 0)
401 thisTrolls
.dernierTroll
= data
["trolls"][data
["trolls"].length
- 1]["troll_id"]
404 Trolls
.prototype.modifierTrollEvent = function(data
)
406 var thisTrolls
= this
407 $("#trolls #troll" + data
["troll_id"] + " .content").html(thisTrolls
.formateur
.traitementComplet(data
["content"], thisTrolls
.trolls
[data
["troll_id"]].author
))
408 $("#trolls #troll" + data
["troll_id"] + " a[@rel*=lightbox]").lightBox()
409 thisTrolls
.trolls
[data
["troll_id"]].content
= data
["content"]
412 Trolls
.prototype.supprimerTrollEvent = function(data
)
414 $("#trolls #troll"+data
["troll_id"]).remove()
417 Trolls
.prototype.modifier = function(id
, content
)
419 var thisTrolls
= this
423 "action" : "mod_troll",
424 "cookie" : this.client
.cookie
,
429 ;; dumpObj(dataToSend
)
435 data: this.util
.jsonVersAction(dataToSend
),
440 if (data
["reply"] == "error")
442 thisTrolls
.util
.messageDialogue(data
["error_message"])
450 * Supprime un troll en fonction de son id.
452 Trolls
.prototype.supprimer = function(id
)
454 var thisTrolls
= this
458 "action" : "del_troll",
459 "cookie" : this.client
.cookie
,
463 ;; dumpObj(dataToSend
)
469 data: this.util
.jsonVersAction(dataToSend
),
474 if (data
["reply"] == "error")
476 thisTrolls
.util
.messageDialogue(data
["error_message"])