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
}},
271 "troll_added" : function(data
){ thisPageAdmin
.trolls
.ajouterTrollEvent(data
) },
272 "troll_modified" : function(data
){ thisPageAdmin
.trolls
.modifierTrollEvent(data
) },
273 "troll_deleted" : function(data
){ thisPageAdmin
.trolls
.supprimerTrollEvent(data
) },
274 "banned_ips_refresh" : function(data
){ thisPageAdmin
.majIPs() },
278 thisTrolls
.util
.messageDialogue(data
["error_message"])
284 ///////////////////////////////////////////////////////////////////////////////////////////////////
287 * Représente un troll, pas grand chose finalement.
289 function Troll(content
, author
)
291 this.content
= content
296 ///////////////////////////////////////////////////////////////////////////////////////////////////
299 function Trolls(client
, util
, formateur
)
303 this.formateur
= formateur
304 this.dernierTroll
= 0
309 Trolls
.prototype.ajouterTrollEvent = function(data
)
311 var thisTrolls
= this
314 for (var i
= 0; i
< data
["trolls"].length
; i
++)
316 var troll
= new Troll(data
["trolls"][i
]["content"], data
["trolls"][i
]["author"])
317 var trollId
= data
["trolls"][i
]["troll_id"]
318 thisTrolls
.trolls
[trollId
] = troll
321 '<div id="troll' + trollId
+ '" class="troll">' +
322 '<span class="content">' + thisTrolls
.formateur
.traitementComplet(troll
.content
, troll
.author
) + '</span>' +
323 '<span class="author"> - ' + thisTrolls
.formateur
.traitementComplet(troll
.author
) + '</span>' +
324 (data
["trolls"][i
]["author_id"] == thisTrolls
.client
.id
? '<span class="editTroll">éditer</span><span class="delTroll">Supprimer</span>' : '') +
327 $("#trolls").append(XHTML
)
328 $("#trolls .troll").filter(function(){return parseInt($(this).attr("id").substr(5)) > thisTrolls
.dernierTroll
}).each(
332 var id
= parseInt($(this).attr("id").substr(5))
334 $("a[@rel*=lightbox]", this).lightBox()
339 if (e
.which
== 13) // return
340 $(".modifier", this).click()
343 $(".delTroll", this).click(
346 thisTrolls
.util
.messageDialogue(
347 "Êtes-vous sur de vouloir supprimer le troll \"" + thisTrolls
.trolls
[id
].content
+ "\" ?",
348 messageType
.question
,
352 thisTrolls
.supprimer(id
)
359 $(".editTroll", this).click(
362 $("span", troll
).css("display", "none")
364 '<form><p><input class="content" type="text" size="50" maxlength="500" value="' +
365 thisTrolls
.trolls
[id
].content
+
366 '"></input><span class="modifier">modifier</span><span class="annuler">annuler</span></p></form>'
368 $("form input.content").focus()
370 var virerLeFormulaire = function()
372 $('form', troll
).remove()
373 $('span', troll
).css("display", "inline")
375 $("span.modifier", troll
).click(
378 var content
= $("form input.content", troll
).val()
380 thisTrolls
.modifier(id
, content
)
383 $("span.annuler", troll
).click( virerLeFormulaire
)
384 $("form", troll
).submit(function(){ return false})
390 if (data
["trolls"].length
> 0)
391 thisTrolls
.dernierTroll
= data
["trolls"][data
["trolls"].length
- 1]["troll_id"]
394 Trolls
.prototype.modifierTrollEvent = function(data
)
396 var thisTrolls
= this
397 $("#trolls #troll" + data
["troll_id"] + " .content").html(thisTrolls
.formateur
.traitementComplet(data
["content"], thisTrolls
.trolls
[data
["troll_id"]].author
))
398 $("#trolls #troll" + data
["troll_id"] + " a[@rel*=lightbox]").lightBox()
399 thisTrolls
.trolls
[data
["troll_id"]].content
= data
["content"]
402 Trolls
.prototype.supprimerTrollEvent = function(data
)
404 $("#trolls #troll"+data
["troll_id"]).remove()
407 Trolls
.prototype.modifier = function(id
, content
)
409 var thisTrolls
= this
413 "action" : "mod_troll",
414 "cookie" : this.client
.cookie
,
419 ;; dumpObj(dataToSend
)
425 data: this.util
.jsonVersAction(dataToSend
),
430 if (data
["reply"] == "error")
432 thisTrolls
.util
.messageDialogue(data
["error_message"])
440 * Supprime un troll en fonction de son id.
442 Trolls
.prototype.supprimer = function(id
)
444 var thisTrolls
= this
448 "action" : "del_troll",
449 "cookie" : this.client
.cookie
,
453 ;; dumpObj(dataToSend
)
459 data: this.util
.jsonVersAction(dataToSend
),
464 if (data
["reply"] == "error")
466 thisTrolls
.util
.messageDialogue(data
["error_message"])