db0a42c9d0c37911a5a70d84f9b06d2fbbae5b0e
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" 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 input.troll").focus()
33 $("#page form#nouveauTroll button.return").click(
36 thisPage
.posterTroll()
41 PageAdmin
.prototype.decharger = function()
43 this.trolls
.pageEvent
.stopAttenteCourante()
46 PageAdmin
.prototype.posterTroll = function()
48 var thisPageAdmin
= this
50 var content
= $("#page form#nouveauTroll input.troll").val()
52 content
= content
.trim()
55 this.util
.messageDialogue("Le troll est vide")
61 "action" : "put_troll",
62 "cookie" : this.client
.cookie
,
66 ;;; dumpObj(dataToSend
)
72 data: this.util
.jsonVersAction(dataToSend
),
78 if (data
["reply"] == "ok")
80 $("#page form#nouveauTroll input.troll").val("")
82 else if (data
["reply"] == "error")
84 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
92 ///////////////////////////////////////////////////////////////////////////////////////////////////
95 function Troll(content
, author
)
97 this.content
= content
102 ///////////////////////////////////////////////////////////////////////////////////////////////////
105 function Trolls(client
, util
, formateur
)
109 this.formateur
= formateur
110 this.dernierTroll
= 0
111 this.pageEvent
= new PageEvent("admin", this.util
)
117 Trolls
.prototype.modifier = function(id
, content
)
121 "action" : "mod_troll",
122 "cookie" : this.client
.cookie
,
127 ;;; dumpObj(dataToSend
)
133 data: this.util
.jsonVersAction(dataToSend
),
138 if (data
["reply"] == "error")
140 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
148 * Supprime un troll en fonction de son id.
150 Trolls
.prototype.supprimer = function(id
)
154 "action" : "del_troll",
155 "cookie" : this.client
.cookie
,
159 ;;; dumpObj(dataToSend
)
165 data: this.util
.jsonVersAction(dataToSend
),
170 if (data
["reply"] == "error")
172 thisPageAdmin
.util
.messageDialogue(data
["error_message"])
179 Trolls
.prototype.rafraichirTrolls = function()
181 var thisTrolls
= this
183 this.pageEvent
.waitEvent(
184 function() { return { "last_troll" : thisTrolls
.dernierTroll
}},
187 switch (data
["reply"])
191 for (var i
= 0; i
< data
["trolls"].length
; i
++)
193 var troll
= new Troll(data
["trolls"][i
]["content"], data
["trolls"][i
]["author"])
194 var trollId
= data
["trolls"][i
]["troll_id"]
195 thisTrolls
.trolls
[trollId
] = troll
198 '<div id="troll' + trollId
+ '" class="troll">' +
199 '<span class="content">' + thisTrolls
.formateur
.traitementComplet(troll
.content
, troll
.author
) + '</span>' +
200 '<span class="author"> - ' + thisTrolls
.formateur
.traitementComplet(troll
.author
) + '</span>' +
201 (data
["trolls"][i
]["author_id"] == thisTrolls
.client
.id
? '<span class="editTroll">éditer</span><span class="delTroll">Supprimer</span>' : '') +
204 $("#trolls").append(XHTML
)
205 $("#trolls .troll").filter(function(){return parseInt($(this).attr("id").substr(5)) > thisTrolls
.dernierTroll
}).each(
209 var id
= parseInt($(this).attr("id").substr(5))
211 $("a[@rel*=lightbox]", this).lightBox()
216 if (e
.which
== 13) // return
217 $(".modifier", this).click()
220 $(".delTroll", this).click(
223 thisTrolls
.util
.messageDialogue(
224 "Êtes-vous sur de vouloir supprimer le troll \"" + $("#trolls .troll .content").html() + "\" ?",
225 messageType
.question
,
229 thisTrolls
.supprimer(id
)
236 $(".editTroll", this).click(
239 $("span", troll
).css("display", "none")
241 '<form><p><input class="content" type="text" size="50" maxlength="500" value="' +
242 thisTrolls
.trolls
[id
].content
+
243 '"></input><span class="modifier">modifier</span><span class="annuler">annuler</span></p></form>'
245 $("form input.content").focus()
247 var virerLeFormulaire = function()
249 $("form", troll
).remove()
250 $('span', troll
).css("display", "inline")
252 $("span.modifier", troll
).click(
255 var content
= $("form input.content", troll
).val()
257 thisTrolls
.modifier(id
, content
)
260 $("span.annuler", troll
).click( virerLeFormulaire
)
261 $("form", troll
).submit(function(){ return false})
267 if (data
["trolls"].length
> 0)
268 thisTrolls
.dernierTroll
= data
["trolls"][data
["trolls"].length
- 1]["troll_id"]
270 case "troll_modified" :
271 $("#trolls #troll" + data
["troll_id"] + " .content").html(thisTrolls
.formateur
.traitementComplet(data
["content"], thisTrolls
.trolls
[data
["troll_id"]].author
))
272 $("#trolls #troll" + data
["troll_id"] + " a[@rel*=lightbox]").lightBox()
273 thisTrolls
.trolls
[data
["troll_id"]].content
= data
["content"]
275 case "troll_deleted" :
276 $("#trolls #troll"+data
["troll_id"]).remove()