- previewProblem: function() {
- if (!V.IsGoodFen(this.modalProb.fen))
- return alert(translations["Bad FEN description"]);
- if (this.modalProb.instructions.trim().length == 0)
- return alert(translations["Empty instructions"]);
- if (this.modalProb.solution.trim().length == 0)
- return alert(translations["Empty solution"]);
- Vue.set(this.modalProb, "preview", true);
- },
- editProblem: function(prob) {
- this.modalProb = prob;
- Vue.set(this.modalProb, "preview", false);
- document.getElementById("modal-newproblem").checked = true;
- },
- deleteProblem: function(pid) {
- ajax(
- "/problems/" + pid,
- "DELETE",
- response => {
- // Delete problem from the list on client side
- let problems = this.curProblems();
- const pIdx = problems.findIndex(p => p.id == pid);
- problems.splice(pIdx, 1);
- }
- );
- },
- sendProblem: function() {
- // Send it to the server and close modal
- ajax(
- "/problems/" + variant.id,
- (this.modalProb.id > 0 ? "PUT" : "POST"),
- this.modalProb,
- response => {
- document.getElementById("modal-newproblem").checked = false;
- Vue.set(this.modalProb, "preview", false);
- if (this.modalProb.id == 0)
- {
- this.myProblems.unshift({
- added: Date.now(),
- id: response.id,
- uid: user.id,
- fen: this.modalProb.fen,
- instructions: this.modalProb.instructions,
- solution: this.modalProb.solution,
- });
- if (!this.curProb && this.display != "mine")
- this.display = "mine";
- }
- else
- this.modalProb.id = 0;
- }
- );
- },