- ajax("/problems", "POST", {prob:this.newproblem}, (ret) => {
- this.infoMsg = this.st.tr["Problem sent!"];
- let newProblem = Object.Assign({}, this.newproblem);
- newProblem.id = ret.id;
- this.problems = this.problems.concat(newProblem);
- });
+ const edit = this.curproblem.id > 0;
+ this.infoMsg = "Processing... Please wait";
+ ajax(
+ "/problems",
+ edit ? "PUT" : "POST",
+ {prob: this.curproblem},
+ (ret) => {
+ if (edit)
+ {
+ let editedP = this.problems.find(p => p.id == this.curproblem.id);
+ this.copyProblem(this.curproblem, editedP);
+ }
+ else //new problem
+ {
+ let newProblem = Object.assign({}, this.curproblem);
+ newProblem.id = ret.id;
+ this.problems = this.problems.concat(newProblem);
+ }
+ this.resetCurProb();
+ this.infoMsg = "";
+ }
+ );
+ },
+ editProblem: function(prob) {
+ if (!prob.diag)
+ this.setDiagram(prob); //possible because V is loaded at this stage
+ this.copyProblem(prob, this.curproblem);
+ doClick('modalNewprob');
+ },
+ deleteProblem: function(prob) {
+ if (confirm(this.st.tr["Are you sure?"]))
+ ajax("/problems", "DELETE", {pid:prob.id});