UNPKG

unserver-unify

Version:

114 lines (111 loc) 3.7 kB
'use strict'; angular.module('bamboo.course').controller('CourseSearchCtrl', function($stateParams, $rootScope, ApiService, loginService, $scope,courseBizModel,fullWidthService) { var _self = this; this.q = $stateParams.key; this.page = 1; this.rcourses = []; this.q; this.courseType = $stateParams.type; this.defaultCoursePhoto = ApiService.SHOST + "/public/images/videos.png"; if (loginService.school.coursephoto) { this.defaultCoursePhoto = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + ApiService.gid + "/" + loginService.school.coursephoto; } this.coursePhotoUrl = ApiService.SHOST + '/lcourse/'; if(_self.courseType == 'pre-book'){ _self.coursePhotoUrl = ApiService.SHOST + '/cfcourses/'; } if (loginService.subDomain == 'gsx') { $rootScope.fullwidthflag = true; } $scope.$on("$destroy", function() { console.log('-- destroy --'); fullWidthService.listen(); }); console.log("search ---"); //this.coursePhotoUrl = ApiService.SHOST + '/cfcourses/'; this.inspectorFlag = false; //console.log(loginService.user); if(!loginService.school.disableAdminStudy){ if (loginService.user && (loginService.user.is_admin || loginService.user.grole == 'admin' || loginService.user.grole == 'sysmanager' || loginService.user.grole == 'dinspector' || loginService.user.grole == 'sysinspector')) { this.inspectorFlag = true; } } var page = 0; var limit = 8; this.courses = []; var mycourses = []; this.pageChanged = function(newPage) { _self.page = newPage; _self.getCourses(_self.q); }; if (loginService.school.themecolors) { $scope.coursebtmStyle = { "background-color": loginService.school.themecolors.coursewidgetbtmcolor }; } function compareMyCourses(_courses) { if (mycourses && mycourses.length > 0) { angular.forEach(_courses, function(item, index) { var id = item._id; if (mycourses.indexOf(id) > -1) { item.mycourseFlag = true; } }) } angular.forEach(_courses, function(item, index) { if (item.infoOnlyFlag) { item.courseurl = "index.courses.infoonly"; } else if (_self.inspectorFlag || item.mycourseFlag) { item.courseurl = "index.courses.course"; } else { item.courseurl = "index.courses.info"; } }) _self.courses = _courses; console.log(_self.courses); } this.getCourses = function(q) { //self.searchObj console.log(q); //var qObj = JSON.parse(q); if(angular.isString(q)){ q = JSON.parse(q); } _self.searchObj = q; //turn on infoOnlyFlag when it is offline course if (_self.searchObj.type == "offline") { _self.searchObj.infoOnlyFlag = true; } console.log(q); var config = { start: (_self.page - 1) * limit, sort: { reverse: true, predicate: 'enrolledcounter' }, limit: limit, search:q }; courseBizModel.searchCourseByParams(config).then(function(result){ console.log(result); var courses = result.data.data.items; compareMyCourses(courses); _self.courses = courses; $scope.searchCount = result.data.data.counter || 0; $scope.searchName = q.name; }); } // not login if(loginService.isLogged){ loginService.getMyProfile().then(function(result) { mycourses = result.courses; if (_self.q && _self.q.length) { _self.getCourses(_self.q); } }) }else{ if (_self.q && _self.q.length) { _self.getCourses(_self.q); } } });