X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fproblems.js;h=3bd13f63baf8856259deca647cfece614feaef7f;hb=45109880413a50dec3a07298b987fb07d60630b2;hp=dbd8340c96236d023f1d88b27ef2b38676ae7e9e;hpb=7931e479adf93c87771ded1892a0873af72ae46d;p=vchess.git
diff --git a/public/javascripts/components/problems.js b/public/javascripts/components/problems.js
index dbd8340c..3bd13f63 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,41 @@ Vue.component('my-problems', {
-
-
+
+
+ // TODO: we don't want exactly the same display (-date +solution)
+
+
+
`,
computed: {
sortedProblems: function() {
- console.log("call");
// Newest problem first
return this.problems.sort((p1,p2) => { return p2.added - p1.added; });
},
@@ -54,6 +58,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 +87,20 @@ 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 => {
document.getElementById("modal-newproblem").checked = false;
+ this.newProblem.stage = "nothing";
});
},
},