cardstories part 4: webservice and client complete

The server and client logic have been finished with the implementation of the vote and complete game state. The client cannot be used for anything but debug. Nevertheless, it was used to play a game to the end. The specifications for the simplest possible authentication mechanism have been completed and a trivial invitation user interface has been suggested.

implementing vote and complete states, server side

The comments describing the game logic in service.py were removed because they required as much time to maintain as the tests.
The player2game method was removed : it was designed at first to allow the player to get its private information. It has been obsoleted by the game method which returns all the relevant game information at once, only revealing the information that a given user is supposed to know. While implementing the logic of the vote and complete state, the structure returned by the game was modified to add the winner_card field and return the vote as a card number instead of its position in the board. It simplified the completeInteraction method which no longer needs to retrieve the board from the database.
The static method ord was written to factorize a few occurrences of the same logic.
For debug purposes, the decorations were added: borders for picked and voted cards during the vote state as well as for the winners during the complete state.
All occurrences of vote were converted from a position to the actual value of the card.

implementing vote and complete states, client side

In both static/index.html and static/test/index.html the list of all possible div was enumerated. Code has been written to hide() the non relevant parts. This is not yet consistent in all the code because a first approach was to try to use the first element of a list as a template to be repeated. It’s still unsure which approach is the more convenient.
The send function was implemented to factorize the code use in four functions

var success = function(data, status) {
if('error' in data) {
  $this.error(data.error);
} else {
  $this.setTimeout(function() { $this.game(player_id, game_id, root); }, 30);
}
};
var request = {
  async: false,
  timeout: 30000,
  url: $this.url + '?' + query,
  dataType: 'json',
  global: false,
  success: success,
  error: $this.xhr_error
};

The implementation of the vote state can be found in three separate functions which are used depending on the user status : vote_owner will watch the votes from everyone during the voting phase, vote_voter will be offered to vote except for the card picked during in the previous state and the vote_viewer will see the board with the sentence but cannot act. The implementation of the complete state is more straightforward because all the viewers are treated equally.
A bug was fixed that prevented the update of the DOM :

$this.setTimeout(function() { $this.game(player_id, game.id, element); }, 30);

was used everywhere regardless of the fact that element was not the root of the DOM on which the cardstories plugin was applied. It has been fixed by adding the cardstories_root class to the root of the DOM structure of interest to the plugin. And the line above was transformed into:

var root = $(element).parents('.cardstories_root');
$this.setTimeout(function() { $this.game(player_id, game.id, root); }, 30);

The players SQL table was removed because it was unused and the method to handle authentication became clearer.

authentication specifications

An even simpler way to authenticate the user is to ask for a nickname when there is none. This is a lot simpler than the proposed SHA1 generated key, and more readable too. It is very insecure but the goal is to offer the simplest possible way to play a game. The nick collisions will be infrequent enough to not be an inconveniences during the experimentation.

inviting friends

It may be enough to create a list of links such as

mailto:xavier@antoviaque.org?subject=http://cardstories.com/?game_id=5&player_id=xavier@antoviaque.org

from a list of emails provided in a text box. The default handler of the navigator will invoke a mailer that is presumably able to send the URL to the relevant person.