70 lines
2.4 KiB
Vue
Raw Normal View History

2018-11-03 14:48:42 +05:30
<template>
2018-11-07 22:12:55 +05:30
<button v-if="isLoggedIn" class='btn btn-primary btn-lg' @click="primaryAction()">{{ buttonName }}</button>
2018-11-03 16:14:34 +05:30
<a v-else class='btn btn-primary btn-lg' href="/login#signup">{{ buttonName }}</a>
2018-11-03 14:48:42 +05:30
</template>
<script>
export default {
name: "AcademyTopSectionButton",
data() {
return {
buttonName: '',
2018-11-12 12:50:54 +05:30
isLoggedIn: academy.store.checkLogin(),
2018-11-03 18:03:01 +05:30
nextContent: '',
nextContentType: '',
nextCourse: '',
link: '',
2018-11-03 14:48:42 +05:30
}
},
mounted() {
2018-11-03 18:03:01 +05:30
if(this.isLoggedIn && this.$route.name == 'program'){
2018-11-07 22:12:55 +05:30
frappe.call({
method: "erpnext.www.academy.get_continue_data",
args: {
2018-11-12 12:50:54 +05:30
program_name: this.$route.params.program_name
2018-11-07 22:12:55 +05:30
}
}).then( r => {
this.nextContent = r.message.content,
this.nextContentType = r.message.content_type,
this.nextCourse = r.message.course
})
2018-11-03 18:03:01 +05:30
}
if(this.isLoggedIn){
2018-11-12 12:50:54 +05:30
if(academy.store.checkProgramEnrollment(this.$route.params.program_name)){
2018-11-07 22:12:55 +05:30
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 16:14:34 +05:30
}
}
else{
this.buttonName = 'Sign Up'
2018-11-07 22:12:55 +05:30
}
2018-11-03 16:14:34 +05:30
},
methods: {
2018-11-07 22:12:55 +05:30
primaryAction() {
2018-11-03 16:14:34 +05:30
if(this.$route.name == 'home'){
2018-11-07 22:12:55 +05:30
return
2018-11-03 16:14:34 +05:30
}
2018-11-12 12:50:54 +05:30
else if(this.$route.name == 'program' && academy.store.checkProgramEnrollment(this.$route.params.program_name)){
this.$router.push({ name: 'content', params: { program_name: this.$route.params.program_name, course: this.nextCourse, type: this.nextContentType, content: this.nextContent}})
2018-11-03 14:48:42 +05:30
}
2018-11-07 22:12:55 +05:30
else {
frappe.call({
method: "erpnext.www.academy.enroll_in_program",
args:{
2018-11-12 12:50:54 +05:30
program_name: this.$route.params.program_name,
2018-11-07 22:12:55 +05:30
student_email_id: frappe.session.user
}
})
2018-11-12 12:50:54 +05:30
academy.store.updateEnrolledPrograms()
2018-11-07 22:12:55 +05:30
}
},
2018-11-03 14:48:42 +05:30
}
};
</script>