From ff15ea4f2878d1a9c496f6172d7a5c57c90fdd59 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Tue, 9 Dec 2014 19:07:16 +0100 Subject: [PATCH] tweak notes --- app/controllers/Round.scala | 2 +- app/views/base/chatDom.scala.html | 2 +- modules/round/src/main/NoteApi.scala | 11 +++++++---- public/javascripts/big.js | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/Round.scala b/app/controllers/Round.scala index a41e36e898..00ab1f7462 100644 --- a/app/controllers/Round.scala +++ b/app/controllers/Round.scala @@ -137,7 +137,7 @@ object Round extends LilaController with TheftPrevention { implicit val req = ctx.body Form(single("text" -> text)).bindFromRequest.fold( err => fuccess(BadRequest), - text => Env.round.noteApi.set(gameId, me.id, text take 10000)) + text => Env.round.noteApi.set(gameId, me.id, text.trim take 10000)) } private def side(pov: Pov, isPlayer: Boolean)(implicit ctx: Context) = diff --git a/app/views/base/chatDom.scala.html b/app/views/base/chatDom.scala.html index e7de91f520..cb79b22d6a 100644 --- a/app/views/base/chatDom.scala.html +++ b/app/views/base/chatDom.scala.html @@ -23,7 +23,7 @@ @if(withNotes) {
- +
} diff --git a/modules/round/src/main/NoteApi.scala b/modules/round/src/main/NoteApi.scala index 80e2fab971..5b53941b9d 100644 --- a/modules/round/src/main/NoteApi.scala +++ b/modules/round/src/main/NoteApi.scala @@ -11,10 +11,13 @@ final class NoteApi(coll: Coll) { _ flatMap (_.getAs[String]("t")) getOrElse "" } - def set(gameId: String, userId: String, text: String) = coll.update( - BSONDocument("_id" -> makeId(gameId, userId)), - BSONDocument("$set" -> BSONDocument("t" -> text)), - upsert = true).void + def set(gameId: String, userId: String, text: String) = { + if (text.isEmpty) coll.remove(BSONDocument("_id" -> makeId(gameId, userId))) + else coll.update( + BSONDocument("_id" -> makeId(gameId, userId)), + BSONDocument("$set" -> BSONDocument("t" -> text)), + upsert = true) + }.void private def makeId(gameId: String, userId: String) = s"$gameId$userId" } diff --git a/public/javascripts/big.js b/public/javascripts/big.js index 46e2dbee95..eb0ff31fb6 100644 --- a/public/javascripts/big.js +++ b/public/javascripts/big.js @@ -974,7 +974,7 @@ var storage = { // Toggle Notes/Chat display $panels = self.element.find('div.chat_panels > div'); - $parent.on('click', 'a', function() { + $parent.find('.chat_menu').on('click', 'a', function() { var panel = $(this).data('panel'); $(this).siblings('.active').removeClass('active').end().addClass('active'); $panels.removeClass('active').filter('.' + panel).addClass('active');