+ // $nextTick to be sure $refs["basegame"] exists
+ this.$nextTick(() => {
+ this.$refs["basegame"].re_setVariables(this.game); });
+ this.curproblem.showSolution = false; //in case of
+ 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();
+ },
+ gotoPrevNext: function(prob, dir) {
+ const mode = (this.onlyMine ? "mine" : "others");
+ const problems = this.problems[mode];
+ const startIdx = problems.findIndex(p => p.id == prob.id);
+ const nextIdx = startIdx + dir;
+ if (nextIdx >= 0 && nextIdx < problems.length)
+ this.setHrefPid(problems[nextIdx]);
+ else if (this.hasMore[mode]) {
+ this.loadMore(
+ mode,
+ (nbProbs) => {
+ if (nbProbs > 0) this.gotoPrevNext(prob, dir);
+ else alert(this.st.tr["No more problems"]);
+ }
+ );
+ }
+ else alert(this.st.tr["No more problems"]);
+ },
+ prepareNewProblem: function() {
+ this.resetCurProb();
+ this.adjustHeight("instructions");
+ this.adjustHeight("solution");
+ window.doClick("modalNewprob");