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

74 lines
2.6 KiB
Vue

<template>
<button v-if="isLoggedIn" class='btn btn-primary btn-lg' @click="primaryAction()">{{ buttonName }}</button>
<a v-else class='btn btn-primary btn-lg' href="/login#signup">{{ buttonName }}</a>
</template>
<script>
export default {
name: "TopSectionButton",
data() {
return {
buttonName: '',
isLoggedIn: lms.store.checkLogin(),
nextContent: '',
nextContentType: '',
nextCourse: '',
link: '',
}
},
mounted() {
// if(this.isLoggedIn && this.$route.name == 'program'){
// this.getContinueData().then( data => {
// this.nextContent = data.content,
// this.nextContentType = data.content_type,
// this.nextCourse = data.course
// })
// }
this.computeButtons()
},
methods: {
computeButtons(){
if(this.isLoggedIn){
if(lms.store.enrolledPrograms.includes(this.$route.params.program_name)){
if(this.$route.name == 'home'){
this.buttonName = 'Explore Courses'
}
// else if(this.$route.name == 'program'){
// this.buttonName = 'Start Course'
// }
}
else {
this.buttonName = 'Enroll Now'
}
}
else{
this.buttonName = 'Sign Up'
}
},
// getContinueData() {
// lms.call({
// method: "get_continue_data",
// args: {
// program_name: this.$route.params.program_name
// }
// })
// },
primaryAction() {
if(this.$route.name == 'home'){
return
}
else if(this.$route.name == 'program' && lms.store.enrolledPrograms.includes(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}})
}
else {
lms.call("enroll_in_program",
{
program_name: this.$route.params.program_name,
student_email_id: frappe.session.user
}
)
lms.store.updateEnrolledPrograms()
}
},
}
};
</script>