UNPKG

unserver-unify

Version:

306 lines (287 loc) 10.8 kB
'use strict'; angular.module('bamboo').controller('AdvHomeCtrl', function($scope, $state, loginService, HomeService, ApiService, $rootScope, $anchorScroll, $location, deviceDetector, courseBizModel, fullWidthService, $sce, AppConfig) { $rootScope.fullwidthflag = true; $scope.$on("$destroy", function() { console.log('-- destroy --'); fullWidthService.listen(); }); //console.log("--- home controller started !"); var self = this; this.school=loginService.school; this.defultCatphoto = "assets/images/category.jpg"; self.catBannerUrl = ApiService.SHOST + '/wiki/'; this.defaultCoursePhoto = ApiService.SHOST + "/public/images/videos.png"; this.defaultCompanyPhoto = "assets/images/company.png"; this.defaultjobPhoto = "assets/images/jobs.png"; this.defaultNewsPhoto = "assets/images/news_no-image1.jpg"; this.schoolIconUrl = this.schoolurl = $scope.schoolUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/"; $scope.appUrl = ApiService.APPURL; this.companypath = ApiService.SHOST + '/company/'; this.teacherPicUrl = ApiService.SHOST + "/photo/" + ApiService.RES + "/teachers/"; this.jobUrl = ApiService.SHOST + '/job/'; self.currency = (loginService.school.currency&&loginService.school.currency.sign)?loginService.school.currency.sign:'$'; if (loginService.isLogged || !loginService.school.advPageFlag) { console.log('--- go to home ---'); $state.go('index.home'); return; } if (loginService.subDomain == 'sgpower') { $state.go('index.sglogin'); return; } this.searchCoursesByCate = function(key){ $rootScope.courseCat = (key)?key:''; $state.go('index.courses'); } $scope.advType = loginService.school.homepageAdvType; console.info($state.current.name); this.limits = { courses: 4, news: 4, events: 4, teachers: 4, numberOfCourseCat: 8, }; // Slide starts this.schoolIconUrl = $scope.schoolUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/"; this.slides = $scope.slides = loginService.school.slides; angular.forEach($scope.slides, function(slide, index) { slide.imgurl = self.schoolurl + slide.img }) $scope.myInterval = 5000; $scope.AppLogoUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/schoolapp/" + loginService.school._id + "/"; $scope.urls = loginService.school.urls; // Slide Ends // Adv Section Starts HomeService.getHomeFeature(function(err,value) { $scope.advContent = value.content; $scope.advContent2 = value.content2; // self.about = value.detail; // self.aboutCN = value.chinese; $scope.advSlides = value.arrays; $scope.learningAdvSlides = value.arrays2; }) this.partnerPhotoPath = ApiService.SHOST + '/advinfo/'; HomeService.getPartner(function(err,partners) { // console.log(partners); self.partnerItems = partners; }) // Adv Sections Ends $scope.$on("$destroy", function() { // $rootScope.fullwidthflag = false; index.advertise // console.log($state.current.name); if ($state.current.name.indexOf('index.home') > -1 || $state.current.name.indexOf('index.advertise') > -1) {} else { $rootScope.fullwidthflag = false; } $rootScope.hideHeader = false; $rootScope.fullwidth = false; }); $scope.Bigslides = null; $scope.active = 0; $rootScope.fullscreenflag = true; $scope.$on("$destroy", function() { $rootScope.fullscreenflag = false; }); $scope._SHOST = ApiService.SHOST; $scope._RES = ApiService.RES; $scope.appUrl = ApiService.APPURL; this.publicUrl = $scope.publicUrl = ApiService.SHOST + "/public/images/"; this.newsPrefix = ApiService.SHOST + '/public/' + ApiService.RES + '/' + 'schoolnews' + '/'; this.newsdefaultImage = ApiService.SHOST + '/public/images/details.png'; this.blockcolor = ["one-blue", "one-grey", "one-orange", "one-default", "one-red", "one-green", "one-default", "one-blue", "one-default", ]; if (loginService.school.jobFlag) { var info = { action: "getrecents", } ApiService.post("/job", info).then(function(result) { // console.log(result); if (result.data.success) { console.log(result.data.data); self.jobs = result.data.data; } }); } if (loginService.school.companyFlag) { HomeService.getHomeCompanys(function(err, items) { self.companys = items; }) /* var info = { action: "gethomecompanys", } ApiService.post("/business", info).then(function(result) { console.log(result); if (result.data.success) { console.log(result.data.data); self.companys = result.data.data; // $scope.$apply(); } });*/ } if (loginService.school.teachersFlag) { HomeService.getHomeTeachers(function(err, items) { $scope.teachers = items; }) /* var info = { action: "gethometeachers", } ApiService.post("/site", info).then(function(result) { if (result.data.success) { $scope.teachers = result.data.data; } });*/ } HomeService.getAdvNews(function(err, value) { $scope._newses = value; }) /* ApiService.get('/newses').then(function(result) { if (result.data.success) { $scope._newses = result.data.data; // console.log($scope._newses); } });*/ // if(loginService.school.theme=="k12"){ if(loginService.school.theme=="t1"||loginService.school.theme=="t6"){ courseBizModel.getCategoryInfo().then(function(data) { console.log(data); self.catMap = data; // return callback(); }); HomeService.getHomeLatestCourses(8, function(err, courses) { self.contentready = true; $scope.lcourses = courses; // callback(); }) HomeService.getHomeTeachers(function(err, teachers) { console.log(teachers); $scope.teachers = teachers; }) } function getinfo() { var _info = { action: "getlastdailyreport", }; ApiService.post('/report', _info).then(function(result) { if (result.data.success) { console.log(result.data.data); self.report = result.data.data; } }); } getinfo(); var serviceFunctions = []; function getLatestCourses(callback) { HomeService.getHomeLatestCourses(self.limits.courses, function(err, courses) { self.contentready = true; $scope.latestCourses = courses; angular.forEach($scope.latestCourses, function(item, index) { if (item.infoOnlyFlag) { item.courseurl = "index.courses.infoonly"; } else { item.courseurl = "index.courses.info"; } }) return callback(); }) } serviceFunctions.push(getLatestCourses); function getHomeNews(callback) { HomeService.getHomeNews(function(err, value) { if (value) { console.log(value); $scope._newses = value.newses; if ($state.current.name == "index.home.cmec") { var text = ""; angular.forEach($scope._newses, function(value, key) { text += " " + value.name + " " + value.created.substring(0, 10) + " " + value.description; }); $scope.scrolltext = text; } $scope.scrolltext = text; $scope.events = value.events; $scope._topics = value.topics; if ($scope._newses.length > 0) { $scope.first_news = $scope._newses[0]; } } return callback(); }); } serviceFunctions.push(getHomeNews); function getAboutVideoInfo(callback) { console.log(ApiService.school); if (ApiService.school.aboutdoc) { ApiService.get("/schooldoc/" + ApiService.school.aboutdoc).then(function(result) { console.log(result); if (result.data.success) { self.aboutdoc = result.data.data || {}; self.about = self.aboutdoc.detail || ''; self.aboutCN = self.aboutdoc.chinese || ''; if(self.aboutdoc.content&&self.aboutdoc.content.video) { self.outlinemp4config = { sources: [{}], tracks: [{}], theme: AppConfig.videogular_theme, cuePoints: {} }; self.outlinemp4config.sources = [{}]; self.outlinemp4config.sources[0].src = self.getVideoUrl(self.aboutdoc.content.video); self.outlinemp4config.sources[0].type = 'video/mp4'; } else if(self.aboutdoc.content&&self.aboutdoc.content.youtube) { self.getVideoYoutubeUrl(); } console.log(self.aboutdoc); return callback(); } }) } else { return callback(); } } this.getVideoUrl = function(file) { return $sce.trustAsResourceUrl($scope.schoolUrl + encodeURI(file)); }; this.getVideoYoutubeUrl = function() { $scope.youtubeID = self.aboutdoc.content.youtube && youtubeEmbedUtils.getIdFromURL(self.aboutdoc.content.youtube); $scope.youtubeUrl = $sce.trustAsResourceUrl('//www.youtube.com/embed/' + $scope.youtubeID + '?&controls=1&showinfo=0'); }; serviceFunctions.push(getAboutVideoInfo); function getLearningFeatures(callback) { ApiService.get("/schooldoc/" + ApiService.school.homepageFunctionDoc).then(function(result) { console.log(result); if (result.data.success) { var value = result.data.data; $scope.learningSlides = value.arrays; return callback(); } else { return callback(); } }); } if(ApiService.school.homepageFunctionDoc){ serviceFunctions.push(getLearningFeatures); } console.log(serviceFunctions); var waterfall=contra; waterfall.waterfall(serviceFunctions,function(err){ console.log(err); }); if (loginService.school) { console.log(loginService.school); $scope.Bigslides = loginService.school.bslides; var index = 0; $scope.myInterval = 5000; $scope.description = loginService.school.description; $scope.AppLogoUrl = ApiService.SHOST + "/public/" + ApiService.RES + "/schoolapp/" + loginService.school._id + "/"; $scope.urls = loginService.school.urls; $scope.gotosection = function(id) { $location.hash("section_" + id); $anchorScroll(); } } this.searchCourses = function() { $rootScope.courseQ = (self.courseName)?self.courseName:''; $rootScope.courseCat = (self.courseCat)?self.courseCat:''; $state.go('index.courses'); } });