socialforge/public/javascripts/wechat/controllers/edit_class_member.js

111 lines
3.7 KiB
JavaScript
Raw Normal View History

2016-07-27 14:30:19 +08:00
app.controller('EditClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
common.checkLogin();
2016-07-27 14:30:19 +08:00
var vm = $scope;
// vm.current_edit_member = rms.get('current_edit_member');
vm.current_edit_member = null;
vm.alertService = alertService.create();
var course_id = $routeParams.id;
var user_id = $routeParams.user_id;
2016-08-02 15:50:15 +08:00
vm.teacher = false; //教师
vm.assistant = false; //教辅
vm.student = false; //学生.
vm.tmpteacher = false; //教师
vm.tmpassistant = false; //教辅
vm.tmpstudent = false; //学生
2016-07-27 14:30:19 +08:00
if(!vm.current_edit_member){
$http.post(config.apiUrl+'courses/get_member_info', {
token: auth.token(),
id: course_id,
user_id:user_id
}).then(function(response){
if(response.data.status!=0){
vm.alertService.showMessage('提示', response.data.message);
} else {
2016-08-02 15:50:15 +08:00
console.log(response);
2016-07-27 14:30:19 +08:00
course_id = response.data.course_id;
user_id = response.data.user_id;
vm.current_edit_member = response.data.member_info;
vm.current_roles_id = vm.current_edit_member.roles_id;
2016-08-02 15:50:15 +08:00
for(var i in vm.current_roles_id){
if(vm.current_roles_id[i] == 9){
vm.teacher = true;
vm.tmpteacher = true;
}
else if(vm.current_roles_id[i] == 7){
vm.assistant = true;
vm.tmpassistant = true;
}
else if(vm.current_roles_id[i] == 10){
vm.student = true;
vm.tmpstudent = true;
}
}
2016-07-27 14:30:19 +08:00
}
});
}
vm.cancel = function(){
2016-08-01 13:54:10 +08:00
// vm.alertService.showMessage('提示', '您确定不对角色进行变更吗?', function(){
// window.history.back();
// });
window.history.back();
2016-07-27 14:30:19 +08:00
};
vm.edit_member_role = function(){
2016-08-02 15:50:15 +08:00
if((vm.teacher == vm.tmpteacher)&& (vm.assistant == vm.tmpassistant)&&(vm.student == vm.tmpstudent)){
2016-07-27 14:30:19 +08:00
vm.alertService.showMessage('提示', "该用户当前已是该角色");
return;
}
2016-08-02 15:50:15 +08:00
if((vm.teacher == false)&& (vm.assistant == false)&&(vm.student == false)){
vm.alertService.showMessage('提示', "请至少选择一种角色");
return;
}
2016-07-27 14:30:19 +08:00
$http.post(config.apiUrl+'courses/edit_member_role', {
token: auth.token(),
id: course_id,
user_id:vm.current_edit_member.user.id,
2016-08-02 15:50:15 +08:00
teacher_flag:vm.teacher,
assistant_flag:vm.assistant,
student_flag:vm.student
2016-07-27 14:30:19 +08:00
}).then(function(response){
if(response.data.status!=0){
vm.alertService.showMessage('提示', response.data.message);
} else {
vm.alertService.showMessage('提示', '修改角色成功', function(){
// window.history.back();
$location.path("/class").search({id: course_id,tag:1});
2016-07-27 14:30:19 +08:00
});
}
});
};
vm.selectRole = function(role_id){
2016-08-02 15:50:15 +08:00
if (role_id == 7){
if(!vm.teacher){
vm.assistant = !vm.assistant;
}
}
else if (role_id == 9){
if(!vm.assistant){
vm.teacher = !vm.teacher;
}
}
else if (role_id == 10){
vm.student = !vm.student;
}
2016-07-27 14:30:19 +08:00
}
}] );