brotherton-erpnext/erpnext/public/js/education/web-academy/components/AcademyTopSectionButton.vue

70 lines
2.4 KiB
Vue
Raw Normal View History

2018-11-03 09:18:42 +00:00
<template>
2018-11-07 16:42:55 +00:00
<button v-if="isLoggedIn" class='btn btn-primary btn-lg' @click="primaryAction()">{{ buttonName }}</button>
2018-11-03 10:44:34 +00:00
<a v-else class='btn btn-primary btn-lg' href="/login#signup">{{ buttonName }}</a>
2018-11-03 09:18:42 +00:00
</template>
<script>
export default {
name: "AcademyTopSectionButton",
data() {
return {
buttonName: '',
2018-11-03 12:33:01 +00:00
isLoggedIn: this.$root.$data.checkLogin(),
nextContent: '',
nextContentType: '',
nextCourse: '',
link: '',
2018-11-03 09:18:42 +00:00
}
},
mounted() {
2018-11-03 12:33:01 +00:00
if(this.isLoggedIn && this.$route.name == 'program'){
2018-11-07 16:42:55 +00:00
frappe.call({
method: "erpnext.www.academy.get_continue_data",
args: {
program_name: this.$route.params.code
}
}).then( r => {
this.nextContent = r.message.content,
this.nextContentType = r.message.content_type,
this.nextCourse = r.message.course
})
2018-11-03 12:33:01 +00:00
}
if(this.isLoggedIn){
2018-11-07 16:42:55 +00:00
if(this.$root.$data.checkProgramEnrollment(this.$route.params.code)){
if(this.$route.name == 'home'){
this.buttonName = 'Explore Courses'
}
else if(this.$route.name == 'program'){
this.buttonName = 'Start Course'
}
}
else {
this.buttonName = 'Enroll Now'
2018-11-03 10:44:34 +00:00
}
}
else{
this.buttonName = 'Sign Up'
2018-11-07 16:42:55 +00:00
}
2018-11-03 10:44:34 +00:00
},
methods: {
2018-11-07 16:42:55 +00:00
primaryAction() {
2018-11-03 10:44:34 +00:00
if(this.$route.name == 'home'){
2018-11-07 16:42:55 +00:00
return
2018-11-03 10:44:34 +00:00
}
2018-11-07 16:42:55 +00:00
else if(this.$route.name == 'program' && this.$root.$data.checkProgramEnrollment(this.$route.params.code)){
this.$router.push({ name: 'content', params: { code: this.$route.params.code, course: this.nextCourse, type: this.nextContentType, content: this.nextContent}})
2018-11-03 09:18:42 +00:00
}
2018-11-07 16:42:55 +00:00
else {
frappe.call({
method: "erpnext.www.academy.enroll_in_program",
args:{
program_name: this.$route.params.code,
student_email_id: frappe.session.user
}
})
this.$root.$data.updateEnrolledPrograms()
}
},
2018-11-03 09:18:42 +00:00
}
};
</script>