brotherton-erpnext/erpnext/public/js/education/lms/lms.js
2019-02-19 13:06:32 +05:30

74 lines
1.5 KiB
JavaScript

import Vue from 'vue/dist/vue.js';
import VueRouter from 'vue-router/dist/vue-router.js'
import lmsRoot from "./lmsRoot.vue";
import routes from './routes';
import './call';
Vue.use(VueRouter)
var store = {
isLogin: false,
enrolledPrograms: new Set(),
enrolledCourses: {}
}
frappe.ready(() => {
frappe.provide('lms')
// frappe.utils.make_event_emitter(lms);
lms.store = new Vue({
data: store,
methods: {
updateEnrolledPrograms() {
if(this.isLogin) {
lms.call("get_program_enrollments").then(data => {
if(data){
data.forEach(element => {
this.enrolledPrograms.add(element)
})
}
});
if (lms.debug) console.log('Updated Enrolled Programs', this.enrolledPrograms)
}
},
updateEnrolledCourses() {
lms.call("get_course_enrollments").then(data => {
if(data) this.enrolledCourses = data
})
if (lms.debug) console.log('Updated Enrolled Courses', this.enrolledCourses)
},
checkLogin() {
if(frappe.session.user === "Guest"){
if (lms.debug) console.log('No Session')
this.isLogin = false
}
else {
if (lms.debug) console.log('Current User: ', frappe.session.user)
this.isLogin = true
}
return this.isLogin
},
updateState() {
this.checkLogin()
this.updateEnrolledPrograms()
this.updateEnrolledCourses()
},
}
});
lms.view = new Vue({
el: "#lms-app",
router: new VueRouter({ routes }),
template: "<lms-root/>",
components: { lmsRoot },
mounted() {
lms.store.updateState()
}
});
lms.debug = true
})