+ },
+ loadMore: function(type, cb) {
+ if (type == "corr" && this.st.user.id > 0) {
+ ajax(
+ "/completedgames",
+ "GET",
+ {
+ credentials: true,
+ data: { cursor: this.cursor["corr"] },
+ success: (res) => {
+ const L = res.games.length;
+ if (L > 0) {
+ this.cursor["corr"] = res.games[L - 1].created;
+ let moreGames = res.games;
+ moreGames.forEach(g => {
+ g.type = "corr";
+ g.options = JSON.parse(g.options);
+ });
+ this.decorate(moreGames);
+ this.corrGames = this.corrGames.concat(moreGames);
+ }
+ else this.hasMore["corr"] = false;
+ if (!!cb) cb();
+ }
+ }
+ );
+ }
+ else if (type == "live") {
+ GameStorage.getNext(this.cursor["live"], localGames => {
+ const L = localGames.length;
+ if (L > 0) {
+ // Add "-1" because IDBKeyRange.upperBound includes boundary
+ this.cursor["live"] = localGames[L - 1].created - 1;
+ localGames.forEach(g => {
+ g.type = "live";
+ // TODO: remove patch on next line (options || "{}")
+ g.options = JSON.parse(g.options || "{}");
+ });
+ this.decorate(localGames);
+ this.liveGames = this.liveGames.concat(localGames);
+ }
+ else this.hasMore["live"] = false;
+ if (!!cb) cb();
+ });
+ }
+ else if (type == "import") {
+ ImportgameStorage.getNext(this.cursor["import"], importGames => {
+ const L = importGames.length;
+ if (L > 0) {
+ // Add "-1" because IDBKeyRange.upperBound includes boundary
+ this.cursor["import"] = importGames[L - 1].created - 1;
+ importGames.forEach(g => {
+ g.type = "import";
+ // TODO: remove following patch (options || "{}")
+ g.options = JSON.parse(g.options || "{}");
+ this.setVname(g);
+ });
+ this.importGames = this.importGames.concat(importGames);
+ }
+ else this.hasMore["import"] = false;
+ if (!!cb) cb();
+ });
+ }