brotherton-erpnext/erpnext/public/js/education/lms/lms.js

81 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-10-30 12:55:49 +00:00
import Vue from 'vue/dist/vue.js';
2019-04-09 07:27:56 +00:00
import VueRouter from 'vue-router/dist/vue-router.js';
import moment from 'moment/min/moment.min.js';
2018-11-13 11:33:18 +00:00
import lmsRoot from "./lmsRoot.vue";
2018-11-09 06:17:09 +00:00
import routes from './routes';
import './call';
2018-10-30 12:55:49 +00:00
2019-04-09 07:27:56 +00:00
Vue.use(VueRouter);
2018-10-30 12:55:49 +00:00
2018-11-09 12:55:19 +00:00
var store = {
2018-11-19 11:38:40 +00:00
enrolledPrograms: [],
2019-02-26 11:50:38 +00:00
enrolledCourses: []
2019-04-09 07:27:56 +00:00
};
2019-03-28 10:03:08 +00:00
// let profile_page = `<a class="dropdown-item" href="/lms#/Profile" rel="nofollow"> LMS Profile </a>`
// document.querySelector('#website-post-login > ul').innerHTML += profile_page
2018-10-30 12:55:49 +00:00
frappe.ready(() => {
2019-04-09 07:27:56 +00:00
frappe.provide('lms');
2018-11-09 12:55:19 +00:00
2019-04-09 07:27:56 +00:00
lms.moment = moment;
2018-11-26 13:46:54 +00:00
2018-11-13 11:17:46 +00:00
lms.store = new Vue({
2018-11-09 06:17:09 +00:00
data: store,
methods: {
2018-11-15 05:43:56 +00:00
updateEnrolledPrograms() {
2018-12-17 08:26:27 +00:00
if(this.checkLogin()) {
2018-11-15 05:43:56 +00:00
lms.call("get_program_enrollments").then(data => {
2019-04-09 07:27:56 +00:00
this.enrolledPrograms = data;
2018-11-15 05:43:56 +00:00
});
}
2018-11-09 12:55:19 +00:00
},
2018-11-15 05:43:56 +00:00
updateEnrolledCourses() {
2018-12-17 08:26:27 +00:00
if(this.checkLogin()) {
2018-11-23 11:46:33 +00:00
lms.call("get_all_course_enrollments").then(data => {
2019-04-09 07:27:56 +00:00
this.enrolledCourses = data;
2019-04-22 06:16:22 +00:00
});
2018-11-23 11:46:33 +00:00
}
2018-11-09 12:55:19 +00:00
},
2018-11-15 05:43:56 +00:00
checkLogin() {
2019-04-09 07:27:56 +00:00
return frappe.is_user_logged_in();
2018-11-09 12:55:19 +00:00
},
2018-11-15 05:43:56 +00:00
updateState() {
2019-04-09 07:27:56 +00:00
this.checkLogin();
this.updateEnrolledPrograms();
this.updateEnrolledCourses();
2018-11-09 12:55:19 +00:00
},
2018-12-06 14:43:20 +00:00
checkProgramEnrollment(programName) {
if(this.checkLogin()){
if(this.enrolledPrograms) {
if(this.enrolledPrograms.includes(programName)) {
2019-04-22 06:16:22 +00:00
return true;
2018-12-06 14:43:20 +00:00
}
else {
2019-04-22 06:16:22 +00:00
return false;
2018-12-06 14:43:20 +00:00
}
}
else {
2019-04-22 06:16:22 +00:00
return false;
2018-12-06 14:43:20 +00:00
}
}
else {
2019-04-22 06:16:22 +00:00
return false;
2018-12-06 14:43:20 +00:00
}
}
2018-11-09 12:55:19 +00:00
}
});
2018-11-13 11:17:46 +00:00
lms.view = new Vue({
el: "#lms-app",
2018-11-09 12:55:19 +00:00
router: new VueRouter({ routes }),
2018-11-13 11:33:18 +00:00
template: "<lms-root/>",
components: { lmsRoot },
2018-11-15 05:43:56 +00:00
mounted() {
2019-04-22 06:16:22 +00:00
lms.store.updateState();
2018-11-09 06:17:09 +00:00
}
});
2018-12-06 14:43:20 +00:00
lms.view.$router.afterEach((to, from) => {
2019-04-22 06:16:22 +00:00
window.scrollTo(0,0);
2019-04-09 07:27:56 +00:00
});
});