管理课程
This commit is contained in:
parent
60367415fa
commit
48fb02a2d6
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<script src="/javascripts/wechat/controllers/login.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/activity.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/new_class.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/edit_class.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/blog.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/course_notice.js"></script>
|
||||
<script src="/javascripts/wechat/controllers/discussion.js"></script>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div class="blue-title">课程列表</div>
|
||||
|
||||
<div ng-repeat="syllabus in syllabuses">
|
||||
<div class="course-list-row f13 c-grey3 mt10"><img src="/images/wechat/plus.png" width="15" class="fl ml10 mt11 spread-btn" /><img src="/images/wechat/minus.png" width="15" class="fl ml10 mt11 retract-btn undis" /><span class="fl ml10">{{syllabus.title}}</span><img src="/images/wechat/setting.png" width="15" class="fr mr10 mt10" ng-click="onSetting()" /></div>
|
||||
<div class="course-list-row f13 c-grey3 mt10"><img src="/images/wechat/plus.png" width="15" class="fl ml10 mt11 spread-btn" /><img src="/images/wechat/minus.png" width="15" class="fl ml10 mt11 retract-btn undis" /><span class="fl ml10">{{syllabus.title}}</span><img src="/images/wechat/setting.png" width="15" class="fr mr10 mt10" ng-click="onSetting(syllabus)" /></div>
|
||||
<ul class="class-list f13 c-grey3">
|
||||
<li ng-click="goClass(course.id)" ng-repeat="course in syllabus.courses" ng-class="{'border-bottom-none': $last}">
|
||||
<img src="/images/wechat/dot.png" width="15px" class="class-list-dot" />
|
||||
|
@ -15,8 +15,6 @@
|
|||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="bottom-tab-wrap mt10">
|
||||
<a ng-click="newClass()" href="javascript:void(0);" class="weixin-tab link-blue2 border-top">新建课程</a>
|
||||
<a ng-click="joinClass()" class="weixin-tab link-blue2 border-top">加入班级</a>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<div class="post-container">
|
||||
<div loading-spinner></div>
|
||||
|
||||
<div class="blue-title">管理课程</div>
|
||||
<form novalidate name="classForm">
|
||||
<div class="course-list-row f13 c-grey3 mt30"><span class="fl ml15 c-grey3">课程</span><input class="new-class-input ml25" ng-model="syllabus.title" required placeholder="请输入课程名" /></div>
|
||||
|
||||
<div class="course-list-row f13 c-grey3 mt10" ng-repeat="course in syllabus.courses"><span class="fl ml15 c-grey3">班级</span><input required class="new-class-input ml25" ng-model="course.name" placeholder="请输入班级名" /><a ng-click="deleteClass($index)" class="fr mr10 c-grey6 delete-class-link">删除</a></div>
|
||||
<div class="tac"><a ng-click="addClass()" class="link-blue2 f13 mt15 inline-block add-class-link">+新增班级</a></div>
|
||||
<a ng-click="newClass(classForm, syllabus)" ng-class="['finish-btn', {'btn-disabled':!classForm.$valid} ]" >完成</a>
|
||||
</form>
|
||||
|
||||
<my-alert message="alertService.message" title="alertService.title" visible="alertService.visible" cb="alertService.cb"></my-alert>
|
||||
</div>
|
|
@ -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});
|
||||
}
|
||||
|
||||
}]);
|
|
@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}] );
|
|
@ -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'))
|
||||
|
|
Loading…
Reference in New Issue