UNPKG

unserver-unify

Version:

97 lines (93 loc) 3.04 kB
angular.module('bamboo.material').controller('PositionCtrl', function(ApiService, loginService, $stateParams) { var _self = this; this.id = this.currentId = $stateParams.id; this.item = {}; this.editmode; this.photoPath = ApiService.SHOST + '/position/'; this.defaultJobPhoto = "/assets/images/jobs.png"; this.coursePhotoUrl = ApiService.SHOST + '/lcourse/'; this.defaultpic = ApiService.SHOST + '/public/images/videos.png'; function getInfo(id) { var info = { action: 'getposition', id: id, } ApiService.post("/business", info).then(function(result) { // console.log(result); if (result.data.success) { console.log(result.data.data); _self.item = result.data.data || {}; _self.imageUrl = _self.item.photo ? _self.photoPath + _self.item.photo : _self.defaultProjectPhoto; } }); _self.getCourses(); } this.getCourses = function() { var info = { action: 'getpublishpositioncourses', pid: _self.currentId, } ApiService.post("/business", info).then(function(result) { // console.log(result); if (result.data.success) { console.log(result.data.data); // _self.courses = result.data.data; compareMyCourses(result.data.data) ; // _self.imageUrl = _self.item.photo ? _self.photoPath + _self.item.photo : _self.defaultProjectPhoto; } }); } function compareMyCourses(items) { loginService.getMyProfile().then(function(result) { // console.log(result); var mycourses = result.courses; console.log("Mycourses", mycourses); // callback(mycourses); if (mycourses && mycourses.length > 0) { console.log("-- check --"); console.log("-- timeout --"); angular.forEach(items, function(item, index) { var id = item._id; if (mycourses.indexOf(id) > -1) { item.mycourseFlag = true; } }) } angular.forEach(items, function(item, index) { if(item.infoOnlyFlag ){ item.courseurl = "index.courses.infoonly"; } else if( item.mycourseFlag) { item.courseurl = "index.courses.course"; } else { item.courseurl = "index.courses.info"; } }) _self.courses = items; }); } this.show = function(id) { _self.currentId = id; getInfo(id); } function getAllPositions() { var info = { action: 'getallcoursepositions', // id:id, } ApiService.post("/business", info).then(function(result) { if (result.data.success) { console.log(result.data.data); _self.allpositions = result.data.data; if(!_self.id&&_self.allpositions.length>0){ _self.currentId = _self.allpositions[0]._id; getInfo(_self.allpositions[0]._id) } } }); } if(_self.id){ getInfo(_self.id) } getAllPositions(); });