UNPKG

unserver-unify

Version:

531 lines (514 loc) 17.4 kB
'use strict'; angular.module('bamboo.company').filter('monthName', [function() { return function(monthNumber) { //1 = January var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; return monthNames[monthNumber - 1]; } }]); angular.module('bamboo.company').controller('CompanyDetailCtrl', function($scope, loginService, CommonService, ApiService, $rootScope, $state, $sce, $stateParams, $document, $window, fullWidthService, loginDlgSvs, companyCommentBizModel) { var _self = this; this.topics = []; console.info($stateParams); this.cid = $stateParams.cid; this.defaultPhoto = "assets/images/company.png"; this.jobphotoUrl = ApiService.SHOST + '/job/'; this.defaultJobsPhoto = "/assets/images/jobs.png"; this.photoUrl = ApiService.SHOST + '/project/'; this.defaultProjectPhoto = "/assets/images/project1.png"; this.companypath = ApiService.SHOST + '/company/'; this.teacherPicUrl = ApiService.SHOST + "/photo/" + ApiService.RES + "/teachers/"; this.publicUrl = ApiService.SHOST + "/public/images/"; this.newsPhotoUrl = ApiService.SHOST + "/companynews/"; this.bannerUrl = ApiService.SHOST + "/company/"; this.defaultPersonPhotoUrl = this.publicUrl + "user_icon&48.png"; this.picUrl = ApiService.SHOST + "/cfcourses/"; this.offlinepicUrl = ApiService.SHOST + "/ofcourses/"; this.defaultCoursePhoto = ApiService.SHOST + "/public/images/videos.png"; //default news photo this.defaultNewsPhoto = "assets/images/news_no-image1.jpg"; //default anno photo this.defaultAnnoPhoto = "assets/images/announcement_no-image1.jpg"; //default awards photo this.defaultAwardsPhoto = "assets/images/awards.png"; this.start = 0; $rootScope.fullwidthflag = true; $scope.$on("$destroy", function() { console.log('-- destroy --'); console.log($state.current.name); fullWidthService.listen(); }); this.productFlag = loginService.school.productFlag; this.setTab = function(_tab) { _self.tab = _tab; console.log(_self.tab) } if (loginService.school.homepage == 'genx' || loginService.school.homepage=='fmas'|| loginService.subDomain == 'poiz'|| loginService.subDomain == 'clinic'|| loginService.subDomain == 'jobs'|| loginService.subDomain == 'imall' || loginService.school.homepage == 'poiz') { console.log('-- full width --'); $rootScope.fullwidthflag = true; } else { console.log('-- normal width --'); $rootScope.fullwidthflag = false; } setTabPage(); $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { // do something console.info(toState.name); setTabPage(toState.name); }); function setTabPage(stateName) { console.log($state.current.name); stateName = stateName || $state.current.name; _self.tab = 'overview'; switch (stateName) { case 'index.company.detail.overview': _self.tab = 'overview'; getOverview(); break; case 'index.company.detail.products': _self.tab = 'products'; getCompanyProducts(); break; case 'index.company.detail.course': _self.tab = 'course'; getCompanyCourse(); break; case 'index.company.detail.pbcourse': _self.tab = 'pbcourse'; getPreBookCourse(); break; case 'index.company.detail.ofcourse': _self.tab = 'ofcourse'; getOfflineCourse(); break; case 'index.company.detail.teachers': _self.tab = 'teachers'; getTeachers(); break; case 'index.company.detail.newslist': _self.tab = 'news'; getNews(); break; case 'index.company.detail.announcmentlist': _self.tab = 'anno'; getAnnouncements(); break; case 'index.company.detail.aboutus.school': _self.tab = 'aboutus'; break; case 'index.company.detail.certificate.detail': case 'index.company.detail.certificate': _self.tab = 'cert'; break; case 'index.company.detail.awards.detail': case 'index.company.detail.awards': _self.tab = 'award'; break; case 'index.company.detail.usecase.detail': case 'index.company.detail.usecase': _self.tab = 'usecase'; break; case 'index.company.detail.jobs': _self.tab = 'jobs'; break; default: if ($state.current.name.indexOf('index.company.detail.aboutus') >= 0) { _self.tab = 'aboutus'; } else { _self.tab = 'overview'; } } console.log(_self.tab) } function scroll() { var top = 550; var duration = 1500; //milliseconds //Scroll to the exact position console.log("scroll..."); $document.scrollTo(0, top, duration); } console.log(ApiService.SHOST); $scope.myInterval = 5000; this.imagePicUrl = ApiService.PSURL + "/avatar/"; if (loginService.user && loginService.user.avatar) { _self.profileImg = _self.imagePicUrl + loginService.user._id + '/' + loginService.user.avatar } else { _self.profileImg = _self.defaultPersonPhotoUrl; } function getCompanyJobs() { var info = { cid: $stateParams.cid, limit: 200, action: 'getcompanyjobs' }; console.log(info); ApiService.post("/job", info).then(function(result) { if (result.data.success) { $scope.jobs = _self.jobs = result.data.data.items; console.log(_self.jobs); } }); } this.toggledrop = function() { if ($scope.dropdown) { $scope.dropdown = false; } else { $scope.dropdown = true; } } function getCompanyProjects() { var info = { cid: $stateParams.cid, limit: 2, action: 'getcompanyprojects' }; console.log(info); ApiService.post("/project", info).then(function(result) { if (result.data.success) { console.log(result.data.data); _self.projects = result.data.data.items; console.log(_self.projects); } }); } var commentstart = 0; function getLatestTopics() { var info = { action: 'getcompanycomments', comId: $stateParams.cid, limit: 5, //limit: 1, start: _self.start } ApiService.post('/business', info).then(function(result) { if (result.data.success && result.data.data) { console.log(result.data.data); _self.topics = result.data.data.items; _self.commentscount = result.data.data.counter; _self.start = _self.topics.length; angular.forEach(_self.topics, function(val, index) { val.avatar_url = CommonService.getAvatarSrc(val.author); }) } }); } this.getMore = function() { var conf = { action: 'getcompanycomments', comId: $stateParams.cid, limit: 1, start: _self.start }; console.log(conf); companyBizModel.getCompanyCommentsByConf(conf).then(function(data) { console.log(data); _self.topics = _self.topics.concat(data.items); _self.start = _self.topics.length; }); } this.delete = function(topic) { var info = { action: 'deletecompanycomment', id: topic._id, } ApiService.post('/business', info).then(function(result) { console.log(result); //getLatestTopics(); $scope.Comment.reload(); }); }; this.sendComment = function() { if (!loginService.user) { loginDlgSvs.openLoginDialog(); return; } var params = { object: { content: _self.commentscontent, }, comId: $stateParams.cid, action: "createcompanycomment", }; ApiService.post('/business', params).then(function(result) { if (result.data.success) { //commentstart = 0; //_self.start = 0; _self.commentscontent = ""; //getLatestTopics(); $scope.Comment.reload(); } else { CommonService.showError('Update Fail!'); } }); } function showCompany() { var info = { action: "getcompany", id: $stateParams.cid }; console.log(); ApiService.post("/business", info).then(function(result) { if (result.data.success) { console.log(result.data); _self.item = result.data.data || {}; $rootScope.CompanyName = _self.item.name; console.log(_self.item); _self.imageUrl = _self.item.photo ? _self.companypath + _self.item._id + '/' + _self.item.photo : _self.defaultPhoto; _self.advsImageUrl = _self.item.advs ? _self.companypath + _self.item._id + '/' + _self.item.advs : null; if (_self.item.audio) { _self.item.audiourl = $sce.trustAsResourceUrl(_self.companypath + _self.item._id + '/' + encodeURI(_self.item.audio)); } if (_self.item.lat) { /* uiGmapGoogleMapApi.then(function() { $scope.map = { center: { latitude: _self.item.lat, longitude: _self.item.lng }, zoom: 14 }; //_self.item.mapaddress = $sce.trustAsResourceUrl('https://www.google.com/maps/embed/v1/place?q=' + _self.item.postcode + '%20singapore&key=AIzaSyCDpjAui7Bp-lfs3akUG4zGId3RAyhGA1M'); console.log($scope.map); // $scope.$apply(); })*/ } if (_self.item.jobs) { getCompanyJobs(); } if (_self.item.projects) { getCompanyProjects(); } getLatestTopics(); } }); } showCompany(); function getCompanyCourse() { var info = { action: "getcompanycourses", start: 0, limit: 50, comId: $stateParams.cid }; ApiService.post('/business', info).then(function(result) { if (result.data.success) { console.log(result.data.data); var _CourseItems = result.data.data.items; if (loginService.user) { loginService.getMyProfile().then(function(result) { var mycourses = result.courses; //console.log("Mycourses", mycourses); if (mycourses && mycourses.length > 0) { angular.forEach(_CourseItems, function(item, index) { //console.log(item); var id = item._id; if (item.infoOnlyFlag) { item.courseurl = "index.courses.infoonly"; } else if (mycourses.indexOf(id) > -1) { item.courseurl = "index.courses.course"; } else { item.courseurl = "index.courses.info"; } }) } else { angular.forEach(_CourseItems, function(val, idx) { val.courseurl = "index.courses.info"; }); } $scope.CourseItems = _CourseItems; console.log($scope.CourseItems); }) } else { angular.forEach(_CourseItems, function(val, idx) { val.courseurl = "index.courses.info"; }); $scope.CourseItems = _CourseItems; } $scope.counters = result.data.data.count; } else { $scope.CourseItems = []; } }); } function getCompanyProducts() { var info = { start: 0, limit: Number.MAX_SAFE_INTEGER, action: "getcompanyproducts", exId: $stateParams.cid }; ApiService.post("/business", info).then(function(result) { console.log(result); if (result.data.success) { $scope.productItems = result.data.data.items; console.log($scope.productItems); $scope.productCount = result.data.data.counter; } }); } function getTeachers() { var info = { start: 0, limit: 8, comId: $stateParams.cid, action: 'getcompanyteachers', }; ApiService.post("/business", info).then(function(result) { if (result.data.success) { // console.log(result.data.data); _self.editors = []; angular.forEach(result.data.data.items, function(teacher, index) { if (teacher.photo && !teacher.avatarflag) { teacher.photourl = _self.teacherPicUrl + teacher.teacherId + "/" + teacher.photo; } else if (teacher.avatar) { var user = { id: teacher._id, avatar: teacher.avatar, } teacher.photourl = CommonService.getAvatarSrc(user); } else { teacher.photourl = _self.defaultPersonPhotoUrl; } _self.editors.push(teacher); }) console.log(_self.editors); } }); } this.getitems = function(tableState) { var limit = tableState.pagination.number; var start = tableState.pagination.start; var search = tableState.search.predicateObject; var info = { start: start, limit: self.itemNumber, sort: tableState.sort, search: search, action: "getgroupnewses", comId: self.cid, type:'company', }; /* if ($state.current.name.indexOf('annoucements') > -1) { info.action = "getcompanyannoucements"; } */ console.log(info); ApiService.post("/advinfo", info).then(function(result) { // console.log(result); if (result.data.success) { console.log(result.data.data.items); $scope.displayedItems = result.data.data.items; $scope.total = result.data.data.counter; console.log($scope.total) tableState.pagination.numberOfPages = Math.ceil(result.data.data.counter / limit); } }); } function getNews() { var info = { start: 0, limit: 4, action: "getgroupnewses", comId: $stateParams.cid, type:'company', }; console.log(info); ApiService.post("/advinfo", info).then(function(result) { console.log(result); if (result.data.success && result.data.data) { $scope.newsList = result.data.data.items || []; console.log($scope.newsList.length); console.log($scope.newsList); } }); } function getAnnouncements() { var info = { start: 0, limit: 4, action: "getcompanyannoucements", comId: $stateParams.cid, }; ApiService.post("/news", info).then(function(result) { if (result.data.success && result.data.data) { $scope.annoucementsList = result.data.data.items || []; console.log($scope.annoucementsList); console.log($scope.annoucementsList.length); } }); } function getOfflineCourse() { var info = { start: 0, limit: Number.MAX_SAFE_INTEGER, action: "getcompanyenableofcourses", comId: _self.cid }; console.log(info); return ApiService.post('/ofcourse', info).then(function(result) { console.log(result.data.data); _self.offLineCourses = result.data.data.items; //$scope.displayCourses =[].concat($scope.courses); //$scope.totalCount = result.data.data.counter; angular.forEach(_self.offLineCourses, function(item, index) { if (item.photo) { item.photourl = _self.offlinepicUrl + item.photo; } else { item.photourl = _self.defaultCoursePhoto; } }) }); } function getPreBookCourse() { var info = { start: 0, limit: Number.MAX_SAFE_INTEGER, action: "getcompanyenablecfcourses", comId: _self.cid }; // console.log(info); return ApiService.post('/cfcourse', info).then(function(result) { // console.log(result.data.data); _self.preBookCourses = result.data.data.items; //$scope.displayCourses =[].concat($scope.courses); //$scope.totalCount = result.data.data.counter; angular.forEach(_self.preBookCourses, function(item, index) { if (item.photo) { item.photourl = _self.picUrl + item.photo; } else { item.photourl = _self.defaultCoursePhoto; } }) }); } function getCompanySummary() { var info = { action: 'getlastcompanyreport', cid: _self.cid }; ApiService.post("/report", info).then(function(result) { console.log(result); if (result.data.success && result.data.data) { $scope.comSummary = result.data.data || []; console.log($scope.comSummary); } }); } getCompanySummary(); function getOverview() { getTeachers(); getCompanyCourse(); getNews(); getAnnouncements(); getCompanyProducts(); getPreBookCourse(); getOfflineCourse(); } var conf = { action: 'getcompanycomments', comId: $stateParams.cid, limit: 3, start: 0 }; $scope.Comment = new companyCommentBizModel(conf); console.log($scope.Comment); });