From 3ea00589df90388456e8587b1bebdeab0f7e99fa Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Tue, 13 May 2008 21:14:53 +0000 Subject: [PATCH] =?utf8?q?ADD=20avancement=20sur=20les=20trolls,=20partie?= =?utf8?q?=20d'administration=20presque=20termin=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- css/1/pageAdmin.css | 33 ++++- css/1/pageMinichat.css | 5 +- doc/TODO.txt | 1 + doc/protocole3.txt | 4 +- js/euphorik.js | 22 ++-- js/pageAdmin.js | 185 +++++++++++++++++++++++++++-- modules/erl/euphorik_bd.erl | 16 ++- modules/erl/euphorik_protocole.erl | 9 +- 8 files changed, 248 insertions(+), 27 deletions(-) diff --git a/css/1/pageAdmin.css b/css/1/pageAdmin.css index 82626ef..91a0961 100644 --- a/css/1/pageAdmin.css +++ b/css/1/pageAdmin.css @@ -1,4 +1,35 @@ /* La page d'administration */ -#page.admin { +#page.admin p { + margin-left : 0px +} + + +#page.admin .troll { + margin-top: 10px +} + +#page.admin .troll .content { + padding: 2px; + border: 1px solid; + border-color: #253f18; + background-color: #0c2003; +} + +#page.admin .troll .author { + margin-left: 10px +} + +#page.admin .troll .editTroll { + margin-left: 10px; + font-size: 9px; + border: 1px solid; + cursor: pointer +} + +#page.admin .troll .delTroll { + margin-left: 10px; + font-size: 9px; + border: 1px solid; + cursor: pointer } diff --git a/css/1/pageMinichat.css b/css/1/pageMinichat.css index 80a2e33..a753ba5 100755 --- a/css/1/pageMinichat.css +++ b/css/1/pageMinichat.css @@ -9,13 +9,12 @@ } #smiles { - border-width: 1px 1px 1px 1px; + border: 1px solid; border-color: #253f18; - border-style: solid; + background-color: #0c2003; margin-bottom: 10px; padding: 1px; width: 140px; - background-color: #0c2003; position: absolute; display: none } diff --git a/doc/TODO.txt b/doc/TODO.txt index 52d85f6..f6b6b16 100755 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -163,6 +163,7 @@ 2 : Urgent 3 : Peu grave +[1] Possibilité d'enregistrer plusieurs users avec le même login [1] Lors de l'extraction d'une conv il arrive que la conv extractée soit bien créée mais vide, le bouton ne ferme pas la conv (très étrange, bug de firefox?) * Arrive une fois sur 20 environ * Jamais reproduit avec Opera diff --git a/doc/protocole3.txt b/doc/protocole3.txt index 1a91d33..8c383c7 100644 --- a/doc/protocole3.txt +++ b/doc/protocole3.txt @@ -220,7 +220,9 @@ s -> c [ { "troll_id" : 5, - "content" : "plop" + "content" : "plop", + "author" : "" + "author_id" : 2 } ] } diff --git a/js/euphorik.js b/js/euphorik.js index 8aaf875..d040dc3 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -74,6 +74,8 @@ function Util() }) } +var messageType = {informatif: 0, question: 1, erreur: 2} + /** * Affiche une boite de dialogue avec un message à l'intérieur. * @param message le message (string) @@ -105,9 +107,7 @@ Util.prototype.messageDialogue = function(message, type, boutons) $("#info").slideDown(200) this.timeoutMessageDialogue = setTimeout(fermer, conf.tempsAffichageMessageDialogue) -} - -var messageType = {informatif: 0, question: 1, erreur: 2} +} /** * Utilisé pour l'envoie de donnée avec la méthode ajax de jQuery. @@ -282,6 +282,11 @@ Formateur.prototype.getSmilesHTML = function() return XHTML } +/** + * Formatage complet d'un texte. + * @M le message + * @pseudo facultatif, permet de contruire le label des images sous la forme : " : " + */ Formateur.prototype.traitementComplet = function(M, pseudo) { return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo))) @@ -327,9 +332,6 @@ Formateur.prototype.remplacerBalisesHTML = function(M) Formateur.prototype.traiterURL = function(M, pseudo) { thisFormateur = this - - if (pseudo == undefined) - pseudo = "" var traitementUrl = function(url) { @@ -337,7 +339,7 @@ Formateur.prototype.traiterURL = function(M, pseudo) if (!thisFormateur.regexTestProtocoleExiste.test(url)) url = "http://" + url var extension = thisFormateur.getShort(url) - return "[" + extension[0] + "]" + return "[" + extension[0] + "]" } return M.replace(this.regexUrl, traitementUrl) } @@ -418,7 +420,8 @@ function Client(util) } Client.prototype.resetDonneesPersonnelles = function() -{ +{ + this.id = 0 this.pseudo = conf.pseudoDefaut this.login = "" this.password = "" @@ -690,7 +693,8 @@ Client.prototype.chargerDonnees = function(data) { this.cookie = data["cookie"] this.setCookie() - + + this.id = data["id"] this.login = data["login"] this.pseudo = data["nick"] this.email = data["email"] diff --git a/js/pageAdmin.js b/js/pageAdmin.js index 93b94d5..9be3ca1 100644 --- a/js/pageAdmin.js +++ b/js/pageAdmin.js @@ -12,7 +12,8 @@ function PageAdmin(client, formateur, util) PageAdmin.prototype.contenu = function() { return '

Trolls

\ -

Nouveau troll\ +

Chaque semaine un troll est choisit au hasard parmis les trolls proposés et devient le troll de la semaine.

\ +

\ \ \

' @@ -24,12 +25,13 @@ PageAdmin.prototype.charger = function() var thisPage = this - this.trolls = new Trolls(this.util) + this.trolls = new Trolls(this.client, this.util, this.formateur) this.trolls.rafraichirTrolls() $("#page form#nouveauTroll button.return").click( function() - { + { + thisPage.posterTroll() } ) } @@ -39,16 +41,125 @@ PageAdmin.prototype.decharger = function() this.trolls.pageEvent.stopAttenteCourante() } +PageAdmin.prototype.posterTroll = function() +{ + var thisPageAdmin = this + + var content = $("#page form#nouveauTroll input.troll").val() + + content = content.trim() + if (content == "") + { + this.util.messageDialogue("Le troll est vide") + return + } + + var dataToSend = + { + "action" : "put_troll", + "cookie" : this.client.cookie, + "content" : content + } + + ;;; dumpObj(dataToSend) + jQuery.ajax( + { + type: "POST", + url: "request", + dataType: "json", + data: this.util.jsonVersAction(dataToSend), + success: + function(data) + { + ;;; dumpObj(data) + + if (data["reply"] == "ok") + { + $("#page form#nouveauTroll input.troll").val("") + } + else if (data["reply"] == "error") + { + thisPageAdmin.util.messageDialogue(data["error_message"]) + } + } + } + ) +} /////////////////////////////////////////////////////////////////////////////////////////////////// -function Trolls(util) +function Trolls(client, util, formateur) { + this.client = client this.util = util + this.formateur = formateur this.dernierTroll = 0 this.pageEvent = new PageEvent("admin", this.util) } + +Trolls.prototype.modifier = function(id, content) +{ + var dataToSend = + { + "action" : "mod_troll", + "cookie" : this.client.cookie, + "troll_id" : id, + "content" : content + } + + ;;; dumpObj(dataToSend) + jQuery.ajax( + { + type: "POST", + url: "request", + dataType: "json", + data: this.util.jsonVersAction(dataToSend), + success: + function(data) + { + ;;; dumpObj(data) + if (data["reply"] == "error") + { + thisPageAdmin.util.messageDialogue(data["error_message"]) + } + } + } + ) +} + +/** + * Supprime un troll en fonction de son id. + */ +Trolls.prototype.supprimer = function(id) +{ + var dataToSend = + { + "action" : "del_troll", + "cookie" : this.client.cookie, + "troll_id" : id + } + + ;;; dumpObj(dataToSend) + jQuery.ajax( + { + type: "POST", + url: "request", + dataType: "json", + data: this.util.jsonVersAction(dataToSend), + success: + function(data) + { + ;;; dumpObj(data) + if (data["reply"] == "error") + { + thisPageAdmin.util.messageDialogue(data["error_message"]) + } + } + } + ) +} + Trolls.prototype.rafraichirTrolls = function() { var thisTrolls = this @@ -57,18 +168,76 @@ Trolls.prototype.rafraichirTrolls = function() function() { return { "last_troll" : thisTrolls.dernierTroll }}, function(data) { - switch (data["reply"]) { + switch (data["reply"]) + { case "troll_added" : var XHTML = "" for (var i = 0; i < data["trolls"].length; i++) { - thisTrolls.dernierTroll = data["trolls"][i]["troll_id"] - XHTML += '

' + data["trolls"][i]["content"] + '

' + XHTML += + '
' + + '' + thisTrolls.formateur.traitementComplet(data["trolls"][i]["content"], data["trolls"][i]["author"]) + '' + + '' + thisTrolls.formateur.traitementComplet(data["trolls"][i]["author"]) + '' + + (data["trolls"][i]["author_id"] == thisTrolls.client.id ? 'éditerSupprimer' : '') + + '
' } $("#trolls").append(XHTML) + $("#trolls .troll").filter(function(){return parseInt($(this).attr("id").substr(5)) > thisTrolls.dernierTroll}).each( + function() + { + var troll = this + var id = parseInt($(this).attr("id").substr(5)) + $(".delTroll", this).click( + function() + { + thisTrolls.util.messageDialogue( + "Êtes-vous sur de vouloir supprimer le troll \"" + $("#trolls .troll .content").html() + "\" ?", + messageType.question, + { + "oui" : function() + { + thisTrolls.supprimer(id) + }, + "non" : function(){} + } + ) + } + ) + $(".editTroll", this).click( + function() + { + $("span", troll).css("display", "none") + $(troll).append( + '

' + ) + var virerLeFormulaire = function() + { + $("form", troll).remove() + $("span", troll).css("display", "inline") + } + $("button.modifier", troll).click( + function() + { + var content = $("form input.content", troll).val() + virerLeFormulaire() + thisTrolls.modifier(id, content) + } + ) + $("button.annuler", troll).click( virerLeFormulaire ) + $("form", troll).submit(function(){ return false}) + } + ) + } + ) + + if (data["trolls"].length > 0) + thisTrolls.dernierTroll = data["trolls"][data["trolls"].length - 1]["troll_id"] break case "troll_modified" : - $("#trolls #troll"+data["troll_id"]).html(data["content"]) + $("#trolls #troll" + data["troll_id"] + " .content").html(data["content"]) + break + case "troll_deleted" : + $("#trolls #troll"+data["troll_id"]).remove() break } } diff --git a/modules/erl/euphorik_bd.erl b/modules/erl/euphorik_bd.erl index 8875973..28267f0 100755 --- a/modules/erl/euphorik_bd.erl +++ b/modules/erl/euphorik_bd.erl @@ -55,6 +55,7 @@ put_troll/2, mod_troll/2, del_troll/1, + troll_by_id/1, % versions : update_version/1, @@ -259,8 +260,7 @@ user_by_cookie(Cookie) -> user_by_id(ID) -> resultat_transaction(mnesia:transaction( fun() -> - Users = qlc:e(qlc:q([E || E <- mnesia:table(user), E#user.id =:= ID])), - case Users of + case qlc:e(qlc:q([E || E <- mnesia:table(user), E#user.id =:= ID])) of [User] -> {ok, User}; _ -> erreur end @@ -697,6 +697,18 @@ del_troll(Troll_id) -> end ). + +troll_by_id(Troll_id) -> + resultat_transaction(mnesia:transaction( + fun() -> + case qlc:e(qlc:q([T || T <- mnesia:table(troll), T#troll.id =:= Troll_id])) of + [T] -> {ok, T}; + _ -> + erreur + end + end + )). + update_version(1) -> mnesia:transform_table( diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index 24569de..fcce9c3 100755 --- a/modules/erl/euphorik_protocole.erl +++ b/modules/erl/euphorik_protocole.erl @@ -208,10 +208,13 @@ wait_event([{page, "admin"}, {last_troll, Last_troll}]) -> {trolls, {array, lists:map( fun(T) -> + {ok, User} = euphorik_bd:user_by_id(T#troll.id_user), {struct, [ {troll_id, T#troll.id}, - {content, T#troll.content} + {content, T#troll.content}, + {author, User#user.pseudo}, + {author_id, User#user.id} ] } end, @@ -390,7 +393,7 @@ mod_troll( User_id = User#user.id, case euphorik_bd:troll_by_id(Troll_id) of {ok, #troll{id_user = User_id}} -> - euphorik_bd:mod_troll(User#user.id, Content), + euphorik_bd:mod_troll(Troll_id, Content), json_reponse_ok(); _ -> erreur("Vous ne posséder pas ce troll") @@ -412,7 +415,7 @@ del_troll( User_id = User#user.id, case euphorik_bd:troll_by_id(Troll_id) of {ok, #troll{id_user = User_id}} -> - euphorik_bd:del_troll(User#user.id), + euphorik_bd:del_troll(Troll_id), json_reponse_ok(); _ -> erreur("Vous ne posséder pas ce troll") -- 2.43.0