fix challenge cancel/decline from quicklist
parent
f14b8ce0e6
commit
17edc5067c
|
@ -42,6 +42,6 @@ object Ai extends LilaController {
|
|||
infos => WS.url(replyToUrl).post(lila.analyse.Info encodeList infos)
|
||||
)
|
||||
}
|
||||
funit
|
||||
fuccess(Ok)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,8 @@ object Challenge extends LilaController {
|
|||
}
|
||||
|
||||
def cancel(id: String) = Open { implicit ctx =>
|
||||
OptionFuResult(env.api byId id) { challenge =>
|
||||
if (isMine(challenge)) env.api cancel challenge inject Redirect(routes.Lobby.home)
|
||||
OptionFuResult(env.api byId id) { c =>
|
||||
if (isMine(c)) env.api cancel c
|
||||
else notFound
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,10 @@ private[controllers] trait LilaController
|
|||
|
||||
protected implicit def LilaHtmlToResult(content: Html): Result = Ok(content)
|
||||
|
||||
protected implicit def LilaFunitToResult(funit: Funit): Fu[Result] = funit inject Ok("ok")
|
||||
protected implicit def LilaFunitToResult(funit: Funit)(implicit ctx: Context): Fu[Result] =
|
||||
negotiate(
|
||||
html = fuccess(Ok("ok")),
|
||||
api = _ => fuccess(Ok(Json.obj("ok" -> true)) as JSON))
|
||||
|
||||
implicit def lang(implicit req: RequestHeader) = Env.i18n.pool lang req
|
||||
|
||||
|
|
|
@ -59,6 +59,15 @@ module.exports = function(env) {
|
|||
}.bind(this));
|
||||
}.bind(this);
|
||||
|
||||
this.cancel = function(id) {
|
||||
this.data.out.forEach(function(c) {
|
||||
if (c.id === id) {
|
||||
c.declined = true;
|
||||
xhr.cancel(id);
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
|
||||
xhr.load().then(this.update);
|
||||
|
||||
var showUser = function(user) {
|
||||
|
|
|
@ -35,18 +35,18 @@ function inButtons(ctrl, c) {
|
|||
action: '/challenge/' + c.id + '/accept'
|
||||
}, m('button', {
|
||||
'type': 'submit',
|
||||
class: 'submit button accept',
|
||||
class: 'button accept',
|
||||
'data-icon': 'E'
|
||||
})),
|
||||
m('form', m('button', {
|
||||
m('button', {
|
||||
'type': 'submit',
|
||||
class: 'submit button decline',
|
||||
'data-icon': 'L',
|
||||
onclick: function(e) {
|
||||
onclick: function() {
|
||||
ctrl.decline(c.id);
|
||||
return false;
|
||||
}
|
||||
}))
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -58,14 +58,14 @@ function outButtons(ctrl, c) {
|
|||
href: '/' + c.id
|
||||
}, 'View challenge')
|
||||
]),
|
||||
m('form', {
|
||||
method: 'post',
|
||||
action: '/challenge/' + c.id + '/cancel'
|
||||
}, m('button', {
|
||||
'type': 'submit',
|
||||
class: 'submit button decline',
|
||||
m('button', {
|
||||
class: 'button decline',
|
||||
'data-icon': 'L',
|
||||
})),
|
||||
onclick: function() {
|
||||
ctrl.cancel(c.id);
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ function allChallenges(ctrl, d, nb) {
|
|||
}
|
||||
|
||||
function empty(ctrl, d) {
|
||||
return m('div.empty', 'No challenges.');
|
||||
return m('div.empty.text[data-icon=]', 'No challenges.');
|
||||
}
|
||||
|
||||
module.exports = function(ctrl) {
|
||||
|
|
|
@ -21,7 +21,14 @@ module.exports = {
|
|||
return m.request({
|
||||
method: 'POST',
|
||||
url: '/challenge/' + id + '/decline',
|
||||
config: xhrConfig,
|
||||
config: xhrConfig
|
||||
});
|
||||
},
|
||||
cancel: function(id) {
|
||||
return m.request({
|
||||
method: 'POST',
|
||||
url: '/challenge/' + id + '/cancel',
|
||||
config: xhrConfig
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue