3 function PageAdmin(client
, formateur
, util
)
8 this.formateur
= formateur
12 PageAdmin
.prototype.contenu = function()
14 return '<h1>Trolls</h1>\
15 <p>Chaque semaine un troll est choisit au hasard parmis les trolls proposés et devient le troll de la semaine.</p>\
16 <form id="nouveauTroll"><p>\
17 <input class="troll" name="troll" type="text" size="80" maxlength="500" value=""></input>\
18 <button class="return" value="return">poster</button>\
19 </p></form><div id="trolls"></div>'
22 PageAdmin
.prototype.charger = function()
24 $("#page form#nouveauTroll").submit(function(){return false})
28 this.trolls
= new Trolls(this.client
, this.util
, this.formateur
)
29 this.trolls
.rafraichirTrolls()
31 $("#page form#nouveauTroll button.return").click(
34 thisPage
.posterTroll()
39 PageAdmin
.prototype.decharger = function()
41 this.trolls
.pageEvent
.stopAttenteCourante()
44 PageAdmin
.prototype.posterTroll = function()
46 var thisPageAdmin
= this
48 var content
= $("#page form#nouveauTroll input.troll").val()
50 content
= content
.trim()
53 this.util
.messageDialogue("Le troll est vide")
59 "action" : "put_troll",
60 "cookie" : this.client
.cookie
,
64 ;;; dumpObj(dataToSend
)
70 data: this.util
.jsonVersAction(dataToSend
),
76 if (data
["reply"] == "ok")
78 $("#page form#nouveauTroll input.troll").val("")
80 else if (data
["reply"] == "error")
82 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
89 ///////////////////////////////////////////////////////////////////////////////////////////////////
91 function Trolls(client
, util
, formateur
)
95 this.formateur
= formateur
97 this.pageEvent
= new PageEvent("admin", this.util
)
101 Trolls
.prototype.modifier = function(id
, content
)
105 "action" : "mod_troll",
106 "cookie" : this.client
.cookie
,
111 ;;; dumpObj(dataToSend
)
117 data: this.util
.jsonVersAction(dataToSend
),
122 if (data
["reply"] == "error")
124 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
132 * Supprime un troll en fonction de son id.
134 Trolls
.prototype.supprimer = function(id
)
138 "action" : "del_troll",
139 "cookie" : this.client
.cookie
,
143 ;;; dumpObj(dataToSend
)
149 data: this.util
.jsonVersAction(dataToSend
),
154 if (data
["reply"] == "error")
156 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
163 Trolls
.prototype.rafraichirTrolls = function()
165 var thisTrolls
= this
167 this.pageEvent
.waitEvent(
168 function() { return { "last_troll" : thisTrolls
.dernierTroll
}},
171 switch (data
["reply"])
175 for (var i
= 0; i
< data
["trolls"].length
; i
++)
178 '<div id="troll' + data
["trolls"][i
]["troll_id"] + '" class="troll">' +
179 '<span class="content">' + thisTrolls
.formateur
.traitementComplet(data
["trolls"][i
]["content"], data
["trolls"][i
]["author"]) + '</span>' +
180 '<span class="author">' + thisTrolls
.formateur
.traitementComplet(data
["trolls"][i
]["author"]) + '</span>' +
181 (data
["trolls"][i
]["author_id"] == thisTrolls
.client
.id
? '<span class="editTroll">éditer</span><span class="delTroll">Supprimer</span>' : '') +
184 $("#trolls").append(XHTML
)
185 $("#trolls .troll").filter(function(){return parseInt($(this).attr("id").substr(5)) > thisTrolls
.dernierTroll
}).each(
189 var id
= parseInt($(this).attr("id").substr(5))
190 $(".delTroll", this).click(
193 thisTrolls
.util
.messageDialogue(
194 "Êtes-vous sur de vouloir supprimer le troll \"" + $("#trolls .troll .content").html() + "\" ?",
195 messageType
.question
,
199 thisTrolls
.supprimer(id
)
206 $(".editTroll", this).click(
209 $("span", troll
).css("display", "none")
211 '<form><p><input class="content" type="text" size="50" maxlength="500" value="' +
212 $(".contentPasFormate", troll
).html() +
213 '"></input><span class="modifier">modifier</span><span class="annuler">annuler</span></p></form>'
215 var virerLeFormulaire = function()
217 $("form", troll
).remove()
218 $('span', troll
).css("display", "inline")
220 $("span.modifier", troll
).click(
223 var content
= $("form input.content", troll
).val()
225 thisTrolls
.modifier(id
, content
)
228 $("span.annuler", troll
).click( virerLeFormulaire
)
229 $("form", troll
).submit(function(){ return false})
235 if (data
["trolls"].length
> 0)
236 thisTrolls
.dernierTroll
= data
["trolls"][data
["trolls"].length
- 1]["troll_id"]
238 case "troll_modified" :
239 $("#trolls #troll" + data
["troll_id"] + " .content").html(thisTrolls
.formateur
.traitementComplet(data
["content"], $("#trolls #troll" + data
["troll_id"] + " .author").html()))
240 $("#trolls #troll" + data
["troll_id"] + " .contentPasFormat").html(data
["content"])
242 case "troll_deleted" :
243 $("#trolls #troll"+data
["troll_id"]).remove()