diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index cb1db09d8..917a396e2 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -396,6 +396,23 @@ module Mobile present :status,0 end + desc '删除课程' + params do + requires :token, type: String + end + post ':course_id/del' do + authenticate! + c = Course.find(params[:course_id]) + if c.members.count > 1 + {status: -1, message: '已经有成员加入,不能删除'} + else + c.delete! + present :status,0 + end + + + end + end end end diff --git a/app/api/mobile/apis/syllabuses.rb b/app/api/mobile/apis/syllabuses.rb index f8286f56d..47989155e 100644 --- a/app/api/mobile/apis/syllabuses.rb +++ b/app/api/mobile/apis/syllabuses.rb @@ -18,6 +18,18 @@ module Mobile present :status, 0 end + desc "获取某个大纲" + params do + requires :token, type: String + end + get ':id' do + authenticate! + + sy = ::Syllabus.find(params[:id]) + present :data, sy, with: Mobile::Entities::Syllabus + present :status, 0 + end + desc "新建大纲" params do requires :token, type: String @@ -41,6 +53,8 @@ module Mobile end + + end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e81251f63..a9d84c2d9 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1090,7 +1090,7 @@ class CoursesController < ApplicationController #删除课程 #删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到 def destroy - @course.update_attributes(:is_delete => true) + @course.delete! @course = nil redirect_to user_url(User.current) end diff --git a/app/models/course.rb b/app/models/course.rb index 408a86ad7..d98ac0f1e 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -173,6 +173,10 @@ class Course < ActiveRecord::Base ) end + def delete! + update_attribute(:is_delete, true) + end + def visible?(user=User.current) user.allowed_to?(:view_course, self) end diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index 3ca452a34..a9254829b 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -41,6 +41,7 @@ + diff --git a/public/assets/wechat/class_list.html b/public/assets/wechat/class_list.html index aded4e443..919eb1364 100644 --- a/public/assets/wechat/class_list.html +++ b/public/assets/wechat/class_list.html @@ -3,7 +3,7 @@
课程列表
-
{{syllabus.title}}
+
{{syllabus.title}}
- -
新建课程 加入班级 diff --git a/public/assets/wechat/edit_class.html b/public/assets/wechat/edit_class.html new file mode 100644 index 000000000..a1a243b12 --- /dev/null +++ b/public/assets/wechat/edit_class.html @@ -0,0 +1,14 @@ +
+
+ +
管理课程
+
+
课程
+ +
班级删除
+ + 完成 +
+ + +
diff --git a/public/javascripts/wechat/controllers/class_list.js b/public/javascripts/wechat/controllers/class_list.js index c30be8bcb..2896d508d 100644 --- a/public/javascripts/wechat/controllers/class_list.js +++ b/public/javascripts/wechat/controllers/class_list.js @@ -61,8 +61,10 @@ app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$lo } }; - vm.onSetting = function () { - vm.alertService.showMessage('提示', '此功能正在开发中'); + vm.onSetting = function (syllabus) { + console.log(syllabus); + rms.save('current_edit_syllobus', syllabus); + $location.path("/edit_class").search({id: syllabus.id}); } }]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/edit_class.js b/public/javascripts/wechat/controllers/edit_class.js new file mode 100644 index 000000000..8520a6eca --- /dev/null +++ b/public/javascripts/wechat/controllers/edit_class.js @@ -0,0 +1,77 @@ + + +app.controller('EditClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms', function($scope, $http, auth, config, alertService, $location,$routeParams, rms){ + var vm = $scope; + + vm.syllabus = rms.get('current_edit_syllobus'); + console.log(vm.syllabus); + + 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; + }); + } + + vm.alertService = alertService.create(); + vm.addClass = function(){ + vm.syllabus.courses.push({}); + }; + + vm.deleteClass = function(index){ + var course = vm.syllabus.courses[index]; + if(course.id >0){ + $http.post(config.apiUrl+'courses/'+course.id+'/del', { + token: auth.token() + }).then(function(response){ + if(response.data.status!=0){ + vm.alertService.showMessage('出错了', response.data.message); + } else { + vm.alertService.showMessage('提示', '删除班级成功', function(){ + vm.syllabus.courses.splice(index, 1); + }); + } + console.log(response.data.data); + }); + } 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; + } + + var courses = []; + for(var i in vm.syllabus.courses){ + var course = vm.syllabus.courses[i]; + if(course.id>0){ + courses.push(course.name); + } + } + + $http.post(config.apiUrl+"syllabuses", { + token: auth.token(), + id: syllabus_id, + courses: courses + }).then(function(response){ + if(response.data.status!=0){ + vm.alertService.showMessage('出错了', response.data.message); + } else { + vm.alertService.showMessage('提示', '保存课程成功', function(){ + window.history.back(); + }); + } + console.log(response.data.data); + }); + + } + +}] ); \ No newline at end of file diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js index ea6dca05d..2c63609b0 100644 --- a/public/javascripts/wechat/others/routes.js +++ b/public/javascripts/wechat/others/routes.js @@ -32,6 +32,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func .when('/blog_comment/:id', makeRoute('blog_detail.html', 'BlogController')) .when('/class', makeRoute('class.html', 'ClassController')) .when('/new_class', makeRoute('new_class.html', 'NewClassController')) + .when('/edit_class', makeRoute('edit_class.html', 'EditClassController')) .when('/class_list', makeRoute('class_list.html', 'ClassListController')) .when('/myresource', makeRoute('myresource.html', 'MyResourceController')) .when('/invite_code', makeRoute('invite_code.html', 'InviteCodeController'))