- displayProblem: function(p) {
- return (
- (!this.selectedVar || p.vid == this.selectedVar) &&
- ((this.onlyMines && p.uid == this.st.user.id) ||
- (!this.onlyMines && p.uid != this.st.user.id))
- );
- },
- showProblem: function(p) {
- this.loadVariant(p.vid, () => {
- // The FEN is already checked at this stage:
- this.game.vname = p.vname;
- this.game.mycolor = V.ParseFen(p.fen).turn; //diagram orientation
- this.game.fenStart = p.fen;
- this.game.fen = p.fen;
- this.showOne = true;
- // $nextTick to be sure $refs["basegame"] exists
- this.$nextTick(() => {
- this.$refs["basegame"].re_setVariables(this.game); });
- this.copyProblem(p, this.curproblem);
- });
+ showProblem: function(p_id) {
+ const processWhenWeHaveProb = () => {
+ this.loadVariant(p.vid, () => {
+ this.onlyMine = (p.uid == this.st.user.id);
+ // The FEN is already checked at this stage:
+ this.game.vname = p.vname;
+ this.game.mycolor = V.ParseFen(p.fen).turn; //diagram orientation
+ this.game.fenStart = p.fen;
+ this.game.fen = p.fen;
+ this.showOne = true;
+ // $nextTick to be sure $refs["basegame"] exists
+ this.$nextTick(() => {
+ this.$refs["basegame"].re_setVariables(this.game); });
+ this.copyProblem(p, this.curproblem);
+ });
+ };
+ let p = undefined;
+ if (typeof p_id == "object") p = p_id;
+ else {
+ const problems = this.problems["others"].concat(this.problems["mine"]);
+ p = problems.find(prob => prob.id == p_id);
+ }
+ if (!p) {
+ // Bad luck: problem not in list. Get from server
+ ajax(
+ "/problems",
+ "GET",
+ {
+ data: { id: p_id },
+ success: (res) => {
+ this.decorate([res.problem], () => {
+ p = res.problem;
+ const mode = (p.uid == this.st.user.id ? "mine" : "others");
+ this.problems[mode].push(p);
+ processWhenWeHaveProb();
+ });
+ }
+ }
+ );
+ } else processWhenWeHaveProb();