FIX nettoyer au déchargement de la page d'admin
[euphorik.git] / js / pageAdmin.js
1 // coding: utf-8
2
3 function PageAdmin(client, formateur, util)
4 {
5 this.nom = "admin"
6
7 this.client = client
8 this.formateur = formateur
9 this.util = util
10 }
11
12 PageAdmin.prototype.contenu = function()
13 {
14 return '<h1>Trolls</h1>\
15 <form id="nouveauTroll"><p>Nouveau troll\
16 <input class="troll" name="troll" type="text" size="80" maxlength="500" value=""></input>\
17 <button class="return" value="return">poster</button>\
18 </p></form><div id="trolls"></div>'
19 }
20
21 PageAdmin.prototype.charger = function()
22 {
23 $("#page form#nouveauTroll").submit(function(){return false})
24
25 var thisPage = this
26
27 this.trolls = new Trolls(this.util)
28 this.trolls.rafraichirTrolls()
29
30 $("#page form#nouveauTroll button.return").click(
31 function()
32 {
33 }
34 )
35 }
36
37 PageAdmin.prototype.decharger = function()
38 {
39 this.trolls.pageEvent.stopAttenteCourante()
40 }
41
42
43 ///////////////////////////////////////////////////////////////////////////////////////////////////
44
45 function Trolls(util)
46 {
47 this.util = util
48 this.dernierTroll = 0
49 this.pageEvent = new PageEvent("admin", this.util)
50 }
51
52 Trolls.prototype.rafraichirTrolls = function()
53 {
54 var thisTrolls = this
55
56 this.pageEvent.waitEvent(
57 function() { return { "last_troll" : thisTrolls.dernierTroll }},
58 function(data)
59 {
60 switch (data["reply"]) {
61 case "troll_added" :
62 var XHTML = ""
63 for (var i = 0; i < data["trolls"].length; i++)
64 {
65 thisTrolls.dernierTroll = data["trolls"][i]["troll_id"]
66 XHTML += '<p id="troll' + data["trolls"][i]["troll_id"] + '">' + data["trolls"][i]["content"] + '</p>'
67 }
68 $("#trolls").append(XHTML)
69 break
70 case "troll_modified" :
71 $("#trolls #troll"+data["troll_id"]).html(data["content"])
72 break
73 }
74 }
75 )
76 }