3 input#modalNewprob.modal(type="checkbox" @change="infoMsg=''")
4 div#newprobDiv(role="dialog" data-checkbox="modalNewprob")
5 .card(@keyup.enter="newProblem()")
6 label#closeNewprob.modal-close(for="modalNewprob")
7 form(@submit.prevent="newProblem()" @keyup.enter="newProblem()")
9 label(for="selectVariant") {{ st.tr["Variant"] }}
10 select#selectVariant(v-model="newproblem.vid" @change="loadVariant()")
11 option(v-for="v in [emptyVar].concat(st.variants)" :value="v.id"
12 :selected="newproblem.vid==v.id")
15 label(for="inputFen") FEN
16 input#inputFen(type="text" v-model="newproblem.fen" @input="tryGetDiagram()")
18 textarea#instructions(:placeholder="st.tr['Instructions']")
19 textarea#solution(:placeholder="st.tr['Solution']")
22 p instru: v-html=... .replace("\n", "<br/>") --> si pas de tags détectés !
23 p solution: v-html=...
24 button(@click="newProblem()") {{ st.tr["Send problem"] }}
25 #dialog.text-center {{ st.tr[infoMsg] }}
28 button#newProblem(onClick="doClick('modalNewprob')") {{ st.tr["New problem"] }}
30 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
31 label(for="checkboxMine") {{ st.tr["My problems"] }}
32 input#checkboxMine(type="checkbox" v-model="onlyMines")
33 label(for="selectVariant") {{ st.tr["Variant"] }}
34 select#selectVariant(v-model="newproblem.vid")
35 option(v-for="v in [emptyVar].concat(st.variants)" :value="v.id")
37 // TODO: nice problems printing :: same as in preview ==> subComponent (inlined?)
38 div(v-for="p in problems" v-show="showProblem(p)")
46 import { store } from "@/store";
47 import { ajax } from "@/utils/ajax";
48 import { checkProblem } from "@/data/problemCheck";
49 import { getDiagram } from "@/utils/printDiagram";
73 ajax("/problems", "GET", (res) => {
74 this.problems = res.problems;
78 showProblem: function(p) {
79 return (this.vid == 0 || p.vid == this.vid) &&
80 (!this.onlyMines || p.uid != this.st.user.id);
82 loadVariant: async function() {
83 if (this.newproblem.vid == 0)
86 const variant = this.st.variants.find(v => v.id == this.newproblem.vid);
87 const vModule = await import("@/variants/" + variant.name + ".js");
88 window.V = vModule.VariantRules;
89 this.curVar = this.newproblem.vid;
90 this.tryGetDiagram(); //the FEN might be already filled
92 tryGetDiagram: async function() {
93 if (this.newproblem.vid == 0)
95 // Check through curVar if V is ready:
96 if (this.curVar == this.newproblem.vid && V.IsGoodFen(this.newproblem.fen))
98 const parsedFen = V.ParseFen(this.newproblem.fen);
100 position: parsedFen.position,
101 orientation: parsedFen.turn,
103 this.curDiag = getDiagram(args);
106 this.curDiag = "<p>FEN not yet correct</p>";
108 newProblem: function() {
109 const error = checkProblem(this.newproblem);
112 ajax("/problems", "POST", {prob:this.newproblem}, (ret) => {
113 this.infoMsg = this.st.tr["Problem sent!"];
114 let newProblem = Object.Assign({}, this.newproblem);
115 newProblem.id = ret.id;
116 this.problems = this.problems.concat(newProblem);
123 <style lang="sass" scoped>
126 margin: 10px auto 5px auto