X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fproblems.js;h=9117ebfc2e10de3b4235c0fa5152b31037d81886;hb=b5fb8e693dc82037eec2617a7dc49d838a9a8441;hp=dbd8340c96236d023f1d88b27ef2b38676ae7e9e;hpb=7931e479adf93c87771ded1892a0873af72ae46d;p=vchess.git diff --git a/public/javascripts/components/problems.js b/public/javascripts/components/problems.js index dbd8340c..9117ebfc 100644 --- a/public/javascripts/components/problems.js +++ b/public/javascripts/components/problems.js @@ -1,7 +1,13 @@ Vue.component('my-problems', { data: function () { return { - problems: problemArray //initial value + problems: problemArray, //initial value + newProblem: { + fen: V.GenRandInitFen(), + instructions: "", + solution: "", + stage: "nothing", //or "preview" after new problem is filled + }, }; }, template: ` @@ -9,43 +15,46 @@ Vue.component('my-problems', { - +
-
+

Add problem

-
+
- +
-

- Allowed HTML tags: - <p>,<br>,<,ul>,<ol>,<li> -

+

Safe HTML tags allowed

- - +
-

- Note: if you made a mistake, please let me know at - contact@vchess.club -

+
+ + + +
+ + +
+
`, computed: { sortedProblems: function() { - console.log("call"); // Newest problem first return this.problems.sort((p1,p2) => { return p2.added - p1.added; }); }, @@ -54,6 +63,10 @@ Vue.component('my-problems', { }, }, methods: { + // Propagate "show problem" event to parent component (my-variant) + bubbleUp: function(problem) { + this.$emit('show-problem', JSON.stringify(problem)); + }, fetchProblems: function(direction) { return; //TODO: re-activate after server side is implemented (see routes/all.js) if (this.problems.length == 0) @@ -79,18 +92,22 @@ Vue.component('my-problems', { showNewproblemModal: function() { document.getElementById("modal-newproblem").checked = true; }, - postNewProblem: function() { - const fen = document.getElementById("newpbFen").value; - if (!V.IsGoodFen(fen)) + previewNewProblem: function() { + if (!V.IsGoodFen(this.newProblem.fen)) return alert("Bad FEN string"); - const instructions = document.getElementById("newpbInstructions").value; - const solution = document.getElementById("newpbSolution").value; + this.newProblem.stage = "preview"; + }, + sendNewProblem: function() { + // Send it to the server and close modal ajax("/problems/" + variant, "POST", { - fen: fen, - instructions: instructions, - solution: solution, + 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"; }); }, },