X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fproblems.js;h=d9265a36fcecb7a4df65d24d88f18d7bcef6f6f8;hb=77fa6d1fe6306f1f9dcd3c363bba8965b602d237;hp=68830a4f7f9af93c281455eb43b8521f9a41aaf5;hpb=c794dbb87592782913af0a09784ed25e019e4d10;p=vchess.git
diff --git a/public/javascripts/components/problems.js b/public/javascripts/components/problems.js
index 68830a4f..d9265a36 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: "",
+ instructions: "",
+ solution: "",
+ stage: "nothing", //or "preview" after new problem is filled
+ },
};
},
template: `
@@ -10,36 +16,41 @@ Vue.component('my-problems', {
+ v-for="(p,idx) in sortedProblems"
+ v-bind:prob="p" v-bind:preview="false" v-bind:key="idx">
-
+
+
+
+
+
+
+
+
+
+
`,
@@ -82,18 +93,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";
});
},
},