2016-07-27 14:30:19 +08:00
|
|
|
|
|
|
|
|
2016-08-09 09:23:06 +08:00
|
|
|
app.controller('EditClassMemberController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
|
2016-08-22 14:09:29 +08:00
|
|
|
// common.checkLogin();
|
2016-08-09 09:23:06 +08:00
|
|
|
|
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();
|
2016-08-31 17:19:12 +08:00
|
|
|
//双弹框
|
|
|
|
vm.alertService_2 = alertService.create();
|
2016-07-27 14:30:19 +08:00
|
|
|
|
|
|
|
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-08-31 17:19:12 +08:00
|
|
|
vm.buttongrey = true;
|
2016-09-20 14:58:37 +08:00
|
|
|
vm.selectid = 0;
|
|
|
|
|
|
|
|
vm.show_1 = true;
|
|
|
|
vm.show_2 = false;
|
|
|
|
vm.show_3 = false;
|
2016-08-31 17:19:12 +08:00
|
|
|
|
2016-08-02 15:50:15 +08:00
|
|
|
|
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){
|
2016-08-31 17:19:12 +08:00
|
|
|
vm.alertService.showMessage('提示', response.data.message,function(){
|
|
|
|
$location.path("/class").search({id: course_id,tag:1});
|
|
|
|
});
|
2016-07-27 14:30:19 +08:00
|
|
|
} 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-09-20 14:58:37 +08:00
|
|
|
vm.selectid = response.data.course_group_id;
|
|
|
|
vm.course_group_id = vm.selectid;
|
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-09-20 14:58:37 +08:00
|
|
|
|
|
|
|
$http.get(config.apiUrl + 'courses/course_groups/'+course_id+'?token='+auth.token()).then(
|
|
|
|
function(response) {
|
|
|
|
console.log("groups=");
|
|
|
|
console.log(response);
|
|
|
|
if(response.data.status == 0) {
|
|
|
|
vm.groups = response.data.data;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
vm.groups = [];
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
};
|
|
|
|
|
2016-08-31 17:19:12 +08:00
|
|
|
vm.deleteMember = function(user_id){
|
|
|
|
vm.alertService_2.showMessage('提示', "是否确认删除成员",function(){
|
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
url: apiUrl + "courses/" + course_id+"/deletemember",
|
|
|
|
data:{token:auth.token(),user_id:user_id}
|
|
|
|
}).then(function successCallback(response) {
|
|
|
|
console.log(response.data);
|
|
|
|
|
|
|
|
if(response.data.status == 0){
|
|
|
|
vm.alertService.showMessage('提示', response.data.message,function(){
|
|
|
|
//确定
|
|
|
|
$location.path("/class").search({id: course_id,tag:1});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
vm.alertService.showMessage('提示', response.data.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-07-27 14:30:19 +08:00
|
|
|
vm.edit_member_role = function(){
|
2016-08-31 17:19:12 +08:00
|
|
|
if(vm.buttongrey == true){
|
2016-07-27 14:30:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-20 14:58:37 +08:00
|
|
|
if(vm.show_2){
|
2016-08-31 17:19:12 +08:00
|
|
|
//删除成员
|
|
|
|
vm.deleteMember(vm.current_edit_member.user.id);
|
2016-08-02 15:50:15 +08:00
|
|
|
}
|
2016-09-20 14:58:37 +08:00
|
|
|
else if(vm.show_3){
|
|
|
|
//加入分班
|
|
|
|
$http.post(config.apiUrl+'courses/user_edit_coursegroup', {
|
|
|
|
token: auth.token(),
|
|
|
|
id: course_id,
|
|
|
|
course_group_id:vm.selectid,
|
|
|
|
user_id:vm.current_edit_member.user.id
|
|
|
|
}).then(function(response){
|
|
|
|
console.log(response);
|
|
|
|
if(response.data.status == 0){
|
|
|
|
vm.alertService.showMessage('提示', "修改分班成功!",function(){
|
|
|
|
$location.path("/class").search({id: course_id,tag:1});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
vm.alertService.showMessage('提示', response.data.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-08-31 17:19:12 +08:00
|
|
|
else{
|
|
|
|
if((vm.teacher == vm.tmpteacher)&& (vm.assistant == vm.tmpassistant)&&(vm.student == vm.tmpstudent)){
|
|
|
|
vm.alertService.showMessage('提示', "该用户当前已是该角色");
|
|
|
|
return;
|
|
|
|
}
|
2016-08-02 15:50:15 +08:00
|
|
|
|
2016-08-31 17:19:12 +08:00
|
|
|
if((vm.teacher == false)&& (vm.assistant == false)&&(vm.student == false)){
|
|
|
|
vm.alertService.showMessage('提示', "请至少选择一种角色");
|
|
|
|
return;
|
2016-07-27 14:30:19 +08:00
|
|
|
}
|
2016-08-31 17:19:12 +08:00
|
|
|
|
|
|
|
$http.post(config.apiUrl+'courses/edit_member_role', {
|
|
|
|
token: auth.token(),
|
|
|
|
id: course_id,
|
|
|
|
user_id:vm.current_edit_member.user.id,
|
|
|
|
teacher_flag:vm.teacher,
|
|
|
|
assistant_flag:vm.assistant,
|
|
|
|
student_flag:vm.student
|
|
|
|
}).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-08-31 17:19:12 +08:00
|
|
|
|
|
|
|
if((vm.teacher == vm.tmpteacher)&& (vm.assistant == vm.tmpassistant)&&(vm.student == vm.tmpstudent)){
|
|
|
|
vm.buttongrey = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
vm.buttongrey = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((vm.teacher == false)&& (vm.assistant == false)&&(vm.student == false)){
|
|
|
|
vm.buttongrey = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-20 14:58:37 +08:00
|
|
|
vm.clickDeleteMember = function(){
|
|
|
|
vm.show_2 = !vm.show_2;
|
|
|
|
if(vm.show_2){
|
|
|
|
vm.show_1 = false;
|
|
|
|
vm.show_3 = false;
|
|
|
|
vm.buttongrey = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-31 17:19:12 +08:00
|
|
|
vm.clickChangeRole = function(){
|
2016-09-20 14:58:37 +08:00
|
|
|
vm.show_1 = !vm.show_1;
|
|
|
|
|
|
|
|
if(vm.show_1){
|
|
|
|
vm.show_2 = false;
|
|
|
|
vm.show_3 = false;
|
|
|
|
if((vm.teacher == vm.tmpteacher)&& (vm.assistant == vm.tmpassistant)&&(vm.student == vm.tmpstudent)){
|
|
|
|
vm.buttongrey = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
vm.buttongrey = false;
|
|
|
|
}
|
2016-08-31 17:19:12 +08:00
|
|
|
}
|
2016-09-20 14:58:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
vm.clickSelectGroup = function(){
|
|
|
|
vm.show_3 = !vm.show_3;
|
|
|
|
|
|
|
|
if(vm.show_3){
|
|
|
|
vm.show_1 = false;
|
|
|
|
vm.show_2 = false;
|
|
|
|
if(vm.selectid != vm.course_group_id){
|
|
|
|
vm.buttongrey = false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
vm.buttongrey = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
vm.selectGroup = function(id){
|
|
|
|
vm.selectid = id;
|
|
|
|
if(vm.course_group_id != vm.selectid){
|
2016-08-31 17:19:12 +08:00
|
|
|
vm.buttongrey = false;
|
|
|
|
}
|
2016-09-20 14:58:37 +08:00
|
|
|
else{
|
|
|
|
vm.buttongrey = true;
|
|
|
|
}
|
2016-08-31 17:19:12 +08:00
|
|
|
};
|
2016-07-27 14:30:19 +08:00
|
|
|
|
|
|
|
}] );
|