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 function PageAdmin(client
, formateur
, util
)
24 this.formateur
= formateur
27 this.pageEvent
= new PageEvent("admin", this.util
)
29 this.timeoutIDmajIPs
= null
32 PageAdmin
.prototype.contenu = function()
34 return '<h1>Trolls</h1>\
35 <p>Un troll est un sujet à débat, en général une question, affiché sur la page principale.</p>\
36 <p>Chaque semaine un troll est choisit au hasard parmis les trolls proposés et devient le troll de la semaine.</p>\
37 <form action="" id="nouveauTroll">\
39 <input class="troll" name="troll" type="text" maxlength="500" value=""></input>\
40 <button class="return" value="return">poster</button>\
43 <div id="trolls"></div>\
48 PageAdmin
.prototype.charger = function()
50 $("#page form#nouveauTroll").submit(function(){return false})
54 this.trolls
= new Trolls(this.client
, this.util
, this.formateur
)
59 $("#page form#nouveauTroll input.troll").focus()
61 $("#page form#nouveauTroll button.return").click(
64 thisPage
.posterTroll()
69 PageAdmin
.prototype.decharger = function()
71 this.pageEvent
.stopAttenteCourante()
74 PageAdmin
.prototype.posterTroll = function()
76 var thisPageAdmin
= this
78 var content
= $("#page form#nouveauTroll input.troll").val()
80 content
= content
.trim()
83 this.util
.messageDialogue("Le troll est vide")
89 "action" : "put_troll",
90 "cookie" : this.client
.cookie
,
94 ;;; dumpObj(dataToSend
)
100 data: this.util
.jsonVersAction(dataToSend
),
106 if (data
["reply"] == "ok")
108 $("#page form#nouveauTroll input.troll").val("")
110 else if (data
["reply"] == "error")
112 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
120 * Met à jour la liste des IP bannies.
122 PageAdmin
.prototype.majIPs = function()
124 if (this.timeoutIDmajIPs
)
125 clearTimeout(this.timeoutIDmajIPs
)
127 var thisPageAdmin
= this
131 "action" : "list_banned_ips",
132 "cookie" : this.client
.cookie
135 ;;; dumpObj(dataToSend
)
141 data: this.util
.jsonVersAction(dataToSend
),
147 if (data
["reply"] == "list_banned_ips")
150 for(var i
= 0; i
< data
["list"].length
; i
++)
152 var ip
= data
["list"][i
]
153 XHTML
+= '<div class="ban"><span class="ip">' + ip
["ip"] + '</span>|' +
154 '<span class="temps">' +
155 ip
["remaining_time"] +
157 for(var j
= 0; j
< ip
["users"].length
; j
++)
159 var user
= ip
["users"][j
]
160 XHTML
+= (j
> 0 ? ", " : "") +
161 '<span class="pseudo">' + thisPageAdmin
.formateur
.traitementComplet(user
["nick"]) + '</span>' +
162 (user
["login"] == "" ? "" : '<span class="login">(' + thisPageAdmin
.formateur
.traitementComplet(user
["login"]) + ')</span>')
164 XHTML
+= '<span class="deban">débannir</span></div>'
167 if (data
["list"].length
== 0)
168 XHTML
+= '<p>Aucune IP bannie</p>'
170 $("#ips").html(XHTML
)
175 var ip
= $(".ip", this).html()
176 $(".deban", this).click(
179 thisPageAdmin
.util
.messageDialogue("Êtes-vous sur de vouloir débannir l'IP ''" + ip
+ "'' ?", messageType
.question
,
182 thisPageAdmin
.deban(ip
)
192 else if (data
["reply"] == "error")
194 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
197 // rafraichissement toutes les minutes (je sais c'est mal)
198 // le problème est le rafraichissement des temps restant de bannissement qui doit êtrew fait du coté client
199 thisPageAdmin
.timeoutIDmajIPs
= setTimeout(function(){ thisPageAdmin
.majIPs() }, 60 * 1000)
205 PageAdmin
.prototype.deban = function(ip
)
207 var thisPageAdmin
= this
212 "cookie" : this.client
.cookie
,
216 ;;; dumpObj(dataToSend
)
222 data: this.util
.jsonVersAction(dataToSend
),
227 switch(data
["reply"])
230 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
233 // obsolète : plus besoin
234 /* thisPageAdmin.majIPs() */
242 PageAdmin
.prototype.waitEvent = function()
244 var thisPageAdmin
= this
246 this.pageEvent
.waitEvent(
247 function() { return { "last_troll" : thisPageAdmin
.trolls
.dernierTroll
}},
250 switch (data
["reply"])
253 thisPageAdmin
.trolls
.ajouterTrollEvent(data
)
255 case "troll_modified" :
256 thisPageAdmin
.trolls
.modifierTrollEvent(data
)
258 case "troll_deleted" :
259 thisPageAdmin
.trolls
.supprimerTrollEvent(data
)
261 case "banned_ips_refresh" :
262 thisPageAdmin
.majIPs()
265 thisTrolls
.util
.messageDialogue(data
["error_message"])
272 ///////////////////////////////////////////////////////////////////////////////////////////////////
275 function Troll(content
, author
)
277 this.content
= content
282 ///////////////////////////////////////////////////////////////////////////////////////////////////
285 function Trolls(client
, util
, formateur
)
289 this.formateur
= formateur
290 this.dernierTroll
= 0
295 Trolls
.prototype.ajouterTrollEvent = function(data
)
297 var thisTrolls
= this
300 for (var i
= 0; i
< data
["trolls"].length
; i
++)
302 var troll
= new Troll(data
["trolls"][i
]["content"], data
["trolls"][i
]["author"])
303 var trollId
= data
["trolls"][i
]["troll_id"]
304 thisTrolls
.trolls
[trollId
] = troll
307 '<div id="troll' + trollId
+ '" class="troll">' +
308 '<span class="content">' + thisTrolls
.formateur
.traitementComplet(troll
.content
, troll
.author
) + '</span>' +
309 '<span class="author"> - ' + thisTrolls
.formateur
.traitementComplet(troll
.author
) + '</span>' +
310 (data
["trolls"][i
]["author_id"] == thisTrolls
.client
.id
? '<span class="editTroll">éditer</span><span class="delTroll">Supprimer</span>' : '') +
313 $("#trolls").append(XHTML
)
314 $("#trolls .troll").filter(function(){return parseInt($(this).attr("id").substr(5)) > thisTrolls
.dernierTroll
}).each(
318 var id
= parseInt($(this).attr("id").substr(5))
320 $("a[@rel*=lightbox]", this).lightBox()
325 if (e
.which
== 13) // return
326 $(".modifier", this).click()
329 $(".delTroll", this).click(
332 thisTrolls
.util
.messageDialogue(
333 "Êtes-vous sur de vouloir supprimer le troll \"" + thisTrolls
.trolls
[id
].content
+ "\" ?",
334 messageType
.question
,
338 thisTrolls
.supprimer(id
)
345 $(".editTroll", this).click(
348 $("span", troll
).css("display", "none")
350 '<form><p><input class="content" type="text" size="50" maxlength="500" value="' +
351 thisTrolls
.trolls
[id
].content
+
352 '"></input><span class="modifier">modifier</span><span class="annuler">annuler</span></p></form>'
354 $("form input.content").focus()
356 var virerLeFormulaire = function()
358 $('form', troll
).remove()
359 $('span', troll
).css("display", "inline")
361 $("span.modifier", troll
).click(
364 var content
= $("form input.content", troll
).val()
366 thisTrolls
.modifier(id
, content
)
369 $("span.annuler", troll
).click( virerLeFormulaire
)
370 $("form", troll
).submit(function(){ return false})
376 if (data
["trolls"].length
> 0)
377 thisTrolls
.dernierTroll
= data
["trolls"][data
["trolls"].length
- 1]["troll_id"]
380 Trolls
.prototype.modifierTrollEvent = function(data
)
382 var thisTrolls
= this
383 $("#trolls #troll" + data
["troll_id"] + " .content").html(thisTrolls
.formateur
.traitementComplet(data
["content"], thisTrolls
.trolls
[data
["troll_id"]].author
))
384 $("#trolls #troll" + data
["troll_id"] + " a[@rel*=lightbox]").lightBox()
385 thisTrolls
.trolls
[data
["troll_id"]].content
= data
["content"]
388 Trolls
.prototype.supprimerTrollEvent = function(data
)
390 $("#trolls #troll"+data
["troll_id"]).remove()
393 Trolls
.prototype.modifier = function(id
, content
)
395 var thisTrolls
= this
399 "action" : "mod_troll",
400 "cookie" : this.client
.cookie
,
405 ;;; dumpObj(dataToSend
)
411 data: this.util
.jsonVersAction(dataToSend
),
416 if (data
["reply"] == "error")
418 thisTrolls
.util
.messageDialogue(data
["error_message"])
426 * Supprime un troll en fonction de son id.
428 Trolls
.prototype.supprimer = function(id
)
430 var thisTrolls
= this
434 "action" : "del_troll",
435 "cookie" : this.client
.cookie
,
439 ;;; dumpObj(dataToSend
)
445 data: this.util
.jsonVersAction(dataToSend
),
450 if (data
["reply"] == "error")
452 thisTrolls
.util
.messageDialogue(data
["error_message"])