X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2FcourseList.js;h=020af5575399d9d62516c0ece15e054e0ab85ea4;hb=8a2b3260841fc5c2e0d24758bf94628ac52300d3;hp=238c1fccc5ce9aabec60c645f92afb3837169e07;hpb=047585562e1950713b0c6d73f6bd7939ab50e744;p=qomet.git diff --git a/public/javascripts/courseList.js b/public/javascripts/courseList.js index 238c1fc..020af55 100644 --- a/public/javascripts/courseList.js +++ b/public/javascripts/courseList.js @@ -1,69 +1,65 @@ -window.onload = function() { - - new Vue({ - el: '#courseList', - data: { - courseArray: courseArray, - newCourse: { - code: "", - description: "", - }, +new Vue({ + el: '#courseList', + data: { + courseArray: courseArray, + newCourse: { + code: "", + description: "", }, - mounted: function() { - $('.modal').modal(); + }, + mounted: function() { + $('.modal').modal(); + }, + methods: { + redirect: function(code) { + document.location.href = "/" + initials + "/" + code; }, - methods: { - redirect: function(code) { - document.location.href = "/" + initials + "/" + code; - }, - addCourse: function() { - if (!admin) - return; - // modal, fill code and description - let error = Validator.checkObject({code:this.newCourse.code}, "Course"); - if (!!error) - return alert(error); - else - $('#newCourse').modal('close'); - $.ajax("/add/course", + addCourse: function() { + if (!admin) + return; + // modal, fill code and description + let error = Validator.checkObject({code:this.newCourse.code}, "Course"); + if (!!error) + return alert(error); + else + $('#newCourse').modal('close'); + $.ajax("/add/course", + { + method: "GET", + data: this.newCourse, + dataType: "json", + success: res => { + if (!res.errmsg) + { + this.newCourse["code"] = ""; + this.newCourse["description"] = ""; + this.courseArray.push(res); + } + else + alert(res.errmsg); + }, + } + ); + }, + deleteCourse: function(course) { + if (!admin) + return; + if (confirm("Delete course '" + course.code + "' ?")) + $.ajax("/remove/course", { method: "GET", - data: this.newCourse, + data: { cid: course._id }, dataType: "json", success: res => { if (!res.errmsg) - { - this.newCourse["code"] = ""; - this.newCourse["description"] = ""; - this.courseArray.push(res); - } + this.courseArray.splice( this.courseArray.findIndex( item => { + return item._id == course._id; + }), 1 ); else alert(res.errmsg); }, } ); }, - deleteCourse: function(course) { - if (!admin) - return; - if (confirm("Delete course '" + course.code + "' ?")) - $.ajax("/remove/course", - { - method: "GET", - data: { cid: course._id }, - dataType: "json", - success: res => { - if (!res.errmsg) - this.courseArray.splice( this.courseArray.findIndex( item => { - return item._id == course._id; - }), 1 ); - else - alert(res.errmsg); - }, - } - ); - }, - } - }); - -}; + } +});