2016-07-04 17:04:06 +08:00
|
|
|
|
|
|
|
|
2016-08-09 09:23:06 +08:00
|
|
|
app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){
|
|
|
|
common.checkLogin();
|
|
|
|
|
2016-07-04 17:04:06 +08:00
|
|
|
var vm = $scope;
|
|
|
|
|
|
|
|
vm.syllabus = rms.get('current_edit_syllobus');
|
|
|
|
|
|
|
|
var syllabus_id = $routeParams.id;
|
|
|
|
if(!vm.syllabus){
|
|
|
|
$http.get(config.apiUrl+"syllabuses/"+syllabus_id+"?token="+auth.token()).then(function(response){
|
|
|
|
console.log(response.data);
|
|
|
|
vm.syllabus = response.data.data;
|
2016-07-08 17:35:14 +08:00
|
|
|
if (vm.syllabus) {
|
|
|
|
for (var i in vm.syllabus.courses) {
|
|
|
|
var course = vm.syllabus.courses[i];
|
|
|
|
course.tmpname = course.name;
|
|
|
|
}
|
|
|
|
vm.syllabus.tmptitle = vm.syllabus.title;
|
|
|
|
}
|
2016-07-04 17:04:06 +08:00
|
|
|
});
|
|
|
|
}
|
2016-07-08 17:22:58 +08:00
|
|
|
console.log(vm.syllabus);
|
2016-07-04 17:04:06 +08:00
|
|
|
|
2016-07-08 16:23:07 +08:00
|
|
|
//名字用两份
|
2016-07-08 17:35:14 +08:00
|
|
|
if (vm.syllabus) {
|
|
|
|
for (var i in vm.syllabus.courses) {
|
|
|
|
var course = vm.syllabus.courses[i];
|
|
|
|
course.tmpname = course.name;
|
|
|
|
}
|
|
|
|
vm.syllabus.tmptitle = vm.syllabus.title;
|
2016-07-08 16:23:07 +08:00
|
|
|
}
|
2016-07-07 14:55:41 +08:00
|
|
|
//单弹框
|
|
|
|
vm.alertService_1 = alertService.create();
|
|
|
|
|
|
|
|
//双弹框
|
|
|
|
vm.alertService_2 = alertService.create();
|
|
|
|
|
2016-07-04 17:04:06 +08:00
|
|
|
vm.addClass = function(){
|
2016-07-08 16:23:07 +08:00
|
|
|
vm.syllabus.courses.push({can_setting:true});
|
2016-07-04 17:04:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
vm.deleteClass = function(index){
|
|
|
|
var course = vm.syllabus.courses[index];
|
|
|
|
if(course.id >0){
|
2016-07-07 14:55:41 +08:00
|
|
|
vm.alertService_2.showMessage('提示', '您确定要删除该班级吗?', function() {
|
|
|
|
$http.post(config.apiUrl+'courses/'+course.id+'/del', {
|
|
|
|
token: auth.token()
|
|
|
|
}).then(function(response){
|
|
|
|
if(response.data.status!=0){
|
2016-07-27 14:30:19 +08:00
|
|
|
vm.alertService_1.showMessage('提示', response.data.message);
|
2016-07-07 14:55:41 +08:00
|
|
|
} else {
|
|
|
|
vm.alertService_1.showMessage('提示', '删除班级成功', function(){
|
|
|
|
vm.syllabus.courses.splice(index, 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
console.log(response.data.data);
|
|
|
|
});
|
2016-07-04 17:04:06 +08:00
|
|
|
});
|
2016-07-07 14:55:41 +08:00
|
|
|
|
2016-07-04 17:04:06 +08:00
|
|
|
} else {
|
|
|
|
vm.syllabus.courses.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.newClass = function (frm, syllabus) {
|
|
|
|
frm.$setSubmitted();
|
|
|
|
console.log(syllabus);
|
|
|
|
|
|
|
|
if(!frm.$valid){
|
|
|
|
console.log(frm.$error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:23:07 +08:00
|
|
|
var add_courses = [];
|
|
|
|
var modify_courses = [];
|
|
|
|
|
2016-07-04 17:04:06 +08:00
|
|
|
for(var i in vm.syllabus.courses){
|
|
|
|
var course = vm.syllabus.courses[i];
|
2016-07-08 16:23:07 +08:00
|
|
|
if(!course.id){
|
|
|
|
add_courses.push(course.tmpname);
|
|
|
|
}
|
|
|
|
else if(course.tmpname != course.name){
|
|
|
|
modify_courses.push({id:course.id,name:course.tmpname});
|
2016-07-04 17:04:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-08 16:23:07 +08:00
|
|
|
$http.post(config.apiUrl+'syllabuses/'+syllabus_id+'/edit', {
|
2016-07-04 17:04:06 +08:00
|
|
|
token: auth.token(),
|
|
|
|
id: syllabus_id,
|
2016-07-08 16:23:07 +08:00
|
|
|
title:vm.syllabus.tmptitle,
|
|
|
|
add_courses: add_courses,
|
|
|
|
modify_courses: modify_courses
|
2016-07-04 17:04:06 +08:00
|
|
|
}).then(function(response){
|
|
|
|
if(response.data.status!=0){
|
2016-07-07 14:55:41 +08:00
|
|
|
vm.alertService_1.showMessage('出错了', response.data.message);
|
2016-07-04 17:04:06 +08:00
|
|
|
} else {
|
2016-07-07 14:55:41 +08:00
|
|
|
vm.alertService_1.showMessage('提示', '保存课程成功', function(){
|
2016-07-08 16:23:07 +08:00
|
|
|
// window.history.back();
|
|
|
|
rms.save('syllabuses',[]);
|
|
|
|
$location.path("/class_list");
|
|
|
|
|
2016-07-04 17:04:06 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
console.log(response.data.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}] );
|