- ajax("/problems/" + variant.name, "POST", { //TODO: with variant._id ?
- fen: this.newProblem.fen,
- instructions: this.newProblem.instructions,
- solution: this.newProblem.solution,
- }, response => {
- this.modalProb.added = Date.now();
- this.curProblems().push(JSON.parse(JSON.stringify(this.modalProb)));
- document.getElementById("modal-newproblem").checked = false;
- this.modalProb.preview = false;
- });
+ ajax(
+ "/problems/" + variant.name, //TODO: with variant.id ?
+ (this.modalProb.id > 0 ? "PUT" : "POST"),
+ this.modalProb,
+ response => {
+ document.getElementById("modal-newproblem").checked = false;
+ if (this.modalProb.id == 0)
+ {
+ this.modalProb.added = Date.now();
+ this.modalProb.preview = false;
+ this.curProblems().push(JSON.parse(JSON.stringify(this.modalProb)));
+ }
+ else
+ this.modalProb.id = 0;
+ }
+ );
+ },
+ // TODO: catch signal edit or delete ; on edit: modify modalProb and show modal
+ deleteProblem: function(pid) {
+ // TODO: AJAX call
+ // TODO: delete problem in curProblems() list