Harmonize with web version, better style, fix for Firefox 45.9.0 ESR
[qomet.git] / public / javascripts / courseList.js
1 new Vue({
2 el: '#courseList',
3 data: {
4 courseArray: courseArray,
5 newCourse: {
6 code: "",
7 description: "",
8 },
9 },
10 mounted: function() {
11 $('.modal').modal();
12 },
13 methods: {
14 redirect: function(code) {
15 document.location.href = "/" + initials + "/" + code;
16 },
17 addCourse: function() {
18 if (!admin)
19 return;
20 // modal, fill code and description
21 let error = Validator.checkObject({code:this.newCourse.code}, "Course");
22 if (!!error)
23 return alert(error);
24 else
25 $('#newCourse').modal('close');
26 $.ajax("/add/course",
27 {
28 method: "GET",
29 data: this.newCourse,
30 dataType: "json",
31 success: res => {
32 if (!res.errmsg)
33 {
34 this.newCourse["code"] = "";
35 this.newCourse["description"] = "";
36 this.courseArray.push(res);
37 }
38 else
39 alert(res.errmsg);
40 },
41 }
42 );
43 },
44 deleteCourse: function(course) {
45 if (!admin)
46 return;
47 if (confirm("Delete course '" + course.code + "' ?"))
48 $.ajax("/remove/course",
49 {
50 method: "GET",
51 data: { cid: course._id },
52 dataType: "json",
53 success: res => {
54 if (!res.errmsg)
55 this.courseArray.splice( this.courseArray.findIndex( item => {
56 return item._id == course._id;
57 }), 1 );
58 else
59 alert(res.errmsg);
60 },
61 }
62 );
63 },
64 }
65 });