- postNewProblem: function() {
- const fen = document.getElementById("newpbFen").value;
- const instructions = document.getElementById("newpbInstructions").value;
- const solution = document.getElementById("newpbSolution").value;
-
+ previewNewProblem: function() {
+ if (!V.IsGoodFen(this.newProblem.fen))
+ return alert(translations["Bad FEN description"]);
+ if (this.newProblem.instructions.trim().length == 0)
+ return alert(translations["Empty instructions"]);
+ if (this.newProblem.solution.trim().length == 0)
+ return alert(translations["Empty solution"]);
+ this.newProblem.stage = "preview";
+ },
+ sendNewProblem: function() {
+ // Send it to the server and close modal
+ ajax("/problems/" + variant, "POST", {
+ fen: this.newProblem.fen,
+ instructions: this.newProblem.instructions,
+ solution: this.newProblem.solution,
+ }, response => {
+ this.newProblem.added = Date.now();
+ this.problems.push(JSON.parse(JSON.stringify(this.newProblem)));
+ document.getElementById("modal-newproblem").checked = false;
+ this.newProblem.stage = "nothing";
+ });