+ methods: {
+ rankPeople: function() {
+ return this.players
+ .slice(1) //discard Toto
+ .map( p => { return Object.assign({}, p); }) //to not alter original array
+ .sort(this.sortByScore);
+ },
+ resetPlayers: function() {
+ this.players
+ .slice(1) //discard Toto
+ .forEach( p => {
+ p.pdt = 0;
+ p.session = 0;
+ p.available = 1;
+ });
+ this.writeScoreToDb();
+ document.getElementById("runPairing").click(); //TODO: hack...
+ },
+ restoreLast: function() {
+ let xhr = new XMLHttpRequest();
+ let self = this;
+ xhr.onreadystatechange = function() {
+ if (this.readyState == 4 && this.status == 200)
+ {
+ let players = JSON.parse(xhr.responseText);
+ if (players.length > 0)
+ {
+ players.unshift({ //add ghost 4th player for 3-players tables
+ prenom: "Toto",
+ nom: "",
+ pdt: 0,
+ session: 0,
+ available: 0,
+ });
+ self.players = players;
+ }
+ }
+ };
+ xhr.open("GET", "scripts/rw_players.php?restore=1", true);
+ xhr.send(null);
+ },
+ },