UNPKG

unserver-unify

Version:

166 lines 6.27 kB
'user strict'; angular.module('bamboo.user').service('UserService', function(ApiService, CommonService, $state, $translate) { var self = this; // service to get user profile based on the user's loginname this.getUserProfileByLoginname = function(loginname, callback) { // show error message for if no callback, as the data get below cannot passed to controller if (!callback) { console.log('Trying to get user profile without callback for user: ' + loginname); return; } ApiService.get('/profile/' + loginname).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get user profile failed: ' + _err); } }); } // service to get users info by users' loginname this.getUsersInfoByLoginnames = function(loginnames, callback) { if (!callback) { console.log('try to get users info without callback'); return; } var info = { action: "getuserslist", names: loginnames }; ApiService.post("/user", info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get users profile failed: ' + _err); } }) } this.UserApi = function(info, callback) { ApiService.post("/user", info).then(function(result) { if (result.data.success) { if (callback) { callback(result.data.data); } else { $state.reload(); } } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get users profile failed: ' + _err); } }) } // service to get teacher's profile by the teacher's loginname this.getTeacherInfoByLoginname = function(loginname, callback) { // show error message if no callback, as the data get below cannot passed to controller if (!callback) { console.log('Try to get teacherinfo without callback for teacher: ' + loginname); return; } ApiService.get('/teacher/' + loginname).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr($translate.instant('Get Teacherinfo failed:') + _err); } }) } // service to get teachers' info by the teachers' loginname this.getTeachersInfoByLoginnames = function(loginnames, callback) { if (!callback) { console.log('Try to get teachers info without callback'); return; } var info = { names: loginnames, action: 'getteachersinfo', }; ApiService.post('/user', info).then(function(result) { if (result.data.success) { callback(result.data.data) } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get Teachersinfo failed: ' + _err); } }) } // service to get teacher's blog by userid and support remote page this.getTeacherOnePageBlog = function(userid, page, limits, tab, callback) { if (!callback) { console.log('Try to get teacher blog without callback'); } var info = { action: 'getuserblogs', page: page, // page number to be loaded, starts from 0 limit: limits, // items # returns within one page id: userid, // teacher's userid tab: tab // blog's category, null for all category }; console.log(info); ApiService.post('/blogs', info).then(function(result) { if (result.data.success) { callback(result.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get posts info failed: ' + _err); } }) } // service to get user's topic by ID this.getUserTopicByID = function(id, callback) { // show error if no callback, as the data get below cannot passed to controller if (!callback) { console.log('Try to get user topic without callback!'); return; } ApiService.get('/userapi/recent_blogs/' + id).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get User Topics failed: ' + _err); } }) } // service to get teacher's courses info this.getTeacherCoursesByLoginname = function(loginname, callback) { // log error if no callback if (!callback) { console.log('Try to get teacher courses without callback!'); return; } var info = { action: 'getteachingcourses', uid: loginname }; ApiService.post('/lcourses', info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get Teacher Courses failed: ' + _err); } }) } // service to get teacher's class info this.getTeacherClassesByLoginname = function(loginname, callback) { // log error if no callback if (!callback) { console.log('Try to get teacher classes without callback!'); return; } var info = { action: 'getteacherclasses', name: loginname }; ApiService.post('/classes', info).then(function(result) { if (result.data.success) { callback(result.data.data); } else { var _err = result.data.error || '' + result.data.info || ''; CommonService.showNoBlockErr('Get Teacher Classes failed: ' + _err); } }) } })