Skip to content

Commit

Permalink
fix enabling of quickRequest Buttons and reset timer when removing ac…
Browse files Browse the repository at this point in the history
…tive match
  • Loading branch information
mkleine committed May 8, 2012
1 parent a1ad61c commit ebbba6b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions client/ui-client/ui/resources/javascript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function removeMatch(toRemove){
model.activeMatch = null;
$("#currentMatch_"+toRemove._id).fadeOut(500, function() {
$(this).remove();
updateTimer(new Date());
});

} else {
Expand Down Expand Up @@ -276,19 +277,15 @@ function initUi() {
});

$("#quickRequestCompleteMatch").text("Wir sind komplett!").click(function(){
if(model.waitingMatches.concat(model.activeMatch).every(function(match){
return (match.player1 != model.userName && match.player2 != model.userName && match.player3 != model.userName && match.player4 != model.userName);
})) {
if(mayRequestMatch()) {
coreFoosClient.registerMatch([model.userName, model.userName, model.userName, model.userName], updateClientState);
} else {
console.info("already registered");
}
});

$("#quickRequestMatch").text("Ich will spielen!").click(function(){
if(model.waitingPlayers.every(function(player){
return player.name != model.userName;
})) {
if(mayRequestMatch()) {
coreFoosClient.registerMatch([model.userName], updateClientState);
} else {
console.log('already registered!');
Expand All @@ -311,7 +308,19 @@ function initUi() {
});

});
}

/**
* The current User may request a match only if he's not listed in any request queue or currently active
* @return {Boolean}
*/
function mayRequestMatch() {
return model.waitingPlayers.every(function(player){
return player.name != model.userName;
}) &&
model.waitingMatches.concat(model.activeMatch).every(function(match){
return !match || (match.player1 != model.userName && match.player2 != model.userName && match.player3 != model.userName && match.player4 != model.userName);
});
}

function checkCurrentPlayerActive(players){
Expand Down

0 comments on commit ebbba6b

Please sign in to comment.