UNPKG

unserver-unify

Version:

106 lines (103 loc) 3.53 kB
angular.module('bamboo.coursebundle').controller("BundleCtrl", function($scope, $window, loginService, $location, $stateParams, ApiService, CommonService, $rootScope, $translate) { this.id = $stateParams.bid; var self = this; this.item = {}; this.defaultPhotoUrl = "assets/images/course_no-image.jpg"; this.picUrl = ApiService.SHOST + "/bundlephotos/" + self.id + '/'; this.coursePhotoUrl = ApiService.SHOST + '/lcourse/'; this.defaultpic = ApiService.SHOST + '/public/images/videos.png'; if (loginService.school.coursephoto) { this.defaultpic = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + loginService.school.coursephoto; } self.currency = (loginService.school.currency&&loginService.school.currency.sign)?loginService.school.currency.sign:'$'; function getInfo() { var info = { action: 'getBundleInfo', id: self.id, } ApiService.post('/coursebundle', info).then(function(data) { console.log(data); var result = data.data.data; self.item = result.bundle; $rootScope.bundleName= self.item.name; self.imageUrl = self.item.photo ? self.picUrl + self.item.photo : null; self.courses = result.courses; console.log(self.item); console.log(self.courses); }); } getInfo() if (loginService.isLogged) { checkMyBundle(); } function checkMyBundle() { var info = { action: 'checkMyBundle', bid: self.id, } ApiService.post('/coursebundle', info).then(function(result) { console.log(result.data.data); if (result.data.success && result.data.data) { self.enrolled = result.data.data.enrolled; self.applied = result.data.data.apply; } }); } this.buy = function() { var info = { action: "paypalBuyBundle", bid: self.id, url: $location.absUrl(), } ApiService.post('/payment', info).then(function(result) { console.log(result); if (result.data.success) { console.log(result.data.data); if (result.data.data.redirectUrl) { CommonService.showInfo('Redirect to Payment Page , Please wait ...'); $window.location.href = result.data.data.redirectUrl; } } }); } this.coupon = function() { CommonService.changeText("Enter your coupon code :").then(function(result) { // console.log(result); if (!result || result.length < 6) { return CommonService.showError("Invald code!"); } var info = { action: "activeByCoupon", bid: self.id, code: result, } console.log(info); ApiService.post('/coursebundle', info).then(function(result) { console.log(result); if (result.data.success) { CommonService.showInfo('Coupon code successfully registered,...'); self.diableEnrol = true } else { CommonService.showError(result.data.error); } }); }); } this.apply = function() { var info = { action: "apply", bid: self.id, } console.log(info); ApiService.post('/coursebundle', info).then(function(result) { console.log(result); if (result.data.success) { CommonService.showInfo($translate.instant('Application submited!')); checkMyBundle(); } else { CommonService.showError(result.data.error); } }); } });