From bbdb5aad154f23cc32efae05d825384e7e9849da Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Thu, 4 Feb 2016 07:58:01 +0700 Subject: [PATCH] improve challenge UI and anon support --- app/views/challenge/theirs.scala.html | 27 +++++++++++++++++++++++++-- public/javascripts/challenge.js | 17 +++++++++++++---- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/views/challenge/theirs.scala.html b/app/views/challenge/theirs.scala.html index 7c1b72e51d..b5706d866f 100644 --- a/app/views/challenge/theirs.scala.html +++ b/app/views/challenge/theirs.scala.html @@ -15,19 +15,42 @@ moreJs = js(c, json, false)) { @explanation(c) @c.initialFen.map { fen =>
- @views.html.game.miniBoard(fen, color = c.chessColor.name) + @views.html.game.miniBoard(fen, color = (!(c.chessColor)).name) } +
+ @c.status match { + case Status.Created | Status.Offline => { @if(!c.mode.rated || ctx.isAuth) { @if(c.mode.rated && c.unlimited) {
@trans.bewareTheGameIsRatedButHasNoClock()
} -
+
} else {

This game is rated
You must log in to join it.

} + } + case Status.Declined => { +
+

Challenge declined

+ @trans.playWithAnotherOpponent() +
+ } + case Status.Accepted => { +
+

Challenge accepted!

+ @trans.joinTheGame() +
+ } + case Status.Canceled => { +
+

Challenge canceled.

+ @trans.playWithAnotherOpponent() +
+ } + } } diff --git a/public/javascripts/challenge.js b/public/javascripts/challenge.js index 32b3f371d6..7f8969182c 100644 --- a/public/javascripts/challenge.js +++ b/public/javascripts/challenge.js @@ -1,7 +1,7 @@ lichess = lichess || {}; lichess.startChallenge = function(element, opts) { - console.log(opts); var challenge = opts.data.challenge; + var accepting; if (!opts.owner && lichess.openInMobileApp(challenge.id)) return; lichess.socket = new lichess.StrongSocket( opts.socketUrl, @@ -19,7 +19,8 @@ lichess.startChallenge = function(element, opts) { url: opts.xhrUrl, success(html) { $('.lichess_overboard').replaceWith($(html).find('.lichess_overboard')); - $('#challenge_redirect').each(function() { + init(); + if (!accepting) $('#challenge_redirect').each(function() { location.href = $(this).attr('href'); }); } @@ -28,6 +29,14 @@ lichess.startChallenge = function(element, opts) { } }); + var init = function() { + $('.lichess_overboard').find('form.accept').submit(function() { + accepting = true; + $(this).html('
'); + }); + }; + init(); + var pingNow = function() { if (document.getElementById('ping_challenge')) { lichess.socket.send('ping'); @@ -36,10 +45,10 @@ lichess.startChallenge = function(element, opts) { }; pingNow(); - Chessground(element.querySelector('.lichess_board'), { + var ground = Chessground(element.querySelector('.lichess_board'), { viewOnly: true, fen: challenge.initialFen, - orientation: challenge.color, + orientation: (opts.owner ^ challenge.color === 'black') ? 'white' : 'black', coordinates: false, disableContextMenu: true });