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

83 lines
3.0 KiB
JavaScript
Raw Normal View History

2016-06-27 11:09:25 +08:00
/**
* Created by guange on 16/6/27.
*/
2016-07-04 16:19:05 +08:00
app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms',
function ($scope, config, auth, $http, $location, alertService,rms) {
2016-07-02 23:46:45 +08:00
var vm = $scope;
2016-07-04 16:19:05 +08:00
vm.syllabuses = rms.get('syllabuses') || [];
2016-07-02 23:46:45 +08:00
vm.alertService_1 = alertService.create();
vm.alertService_3 = alertService.create();
2016-07-02 23:46:45 +08:00
var loadClassList = function () {
2016-07-04 16:19:05 +08:00
$http.get(config.apiUrl + "syllabuses?token=" + auth.token()).then(
2016-07-02 23:46:45 +08:00
function (response) {
console.log(response.data);
2016-07-04 16:19:05 +08:00
vm.syllabuses = response.data.data;
rms.save('syllabuses', vm.syllabuses);
2016-07-02 23:46:45 +08:00
}
);
};
2016-07-04 16:19:05 +08:00
if(vm.syllabuses.length<=0){
loadClassList();
}
2016-07-02 23:46:45 +08:00
vm.goClass = function (course_id) {
console.log(course_id);
$location.path("/class").search({id: course_id});
2016-06-27 11:09:25 +08:00
}
2016-07-02 23:46:45 +08:00
vm.newClass = function () {
//先判断下权限
$http.post(config.apiUrl + "syllabuses/auth",{token: auth.token()} ).then(
function (response) {
console.log(response.data);
if (response.data.auth == 0) {
vm.alertService_1.showMessage('提示', '非教师身份不能创建课程哦~');
}
else{
$location.path("/new_class");
}
}
);
2016-07-02 23:46:45 +08:00
}
2016-06-27 16:03:07 +08:00
2016-07-02 23:46:45 +08:00
vm.goResource = function () {
$location.path("/myresource");
}
vm.joinClass = function () {
vm.alertService_3.showMessage('提示', '请输入5位班级邀请码(不区分大小写)', function(){
if (vm.alertService_3.invite && vm.alertService_3.invite.length == 5) {
$http.post(config.apiUrl + "courses/join", {
token: auth.token(),
invite_code: vm.alertService_3.invite
}).then(function (response) {
console.log(response.data);
if (response.data.status != 0) {
vm.alertService_1.showMessage('提示', response.data.message);
} else {
vm.alertService_1.showMessage('提示', '加入课程成功');
vm.alertService_3.invite = "";
loadClassList();
}
});
} else {
if(vm.alertService_3.invite){
vm.alertService_1.showMessage('提示', '邀请码格式不正确');
2016-07-02 23:46:45 +08:00
}
}
});
2016-07-02 23:46:45 +08:00
};
2016-07-04 17:04:06 +08:00
vm.onSetting = function (syllabus) {
console.log(syllabus);
rms.save('current_edit_syllobus', syllabus);
$location.path("/edit_class").search({id: syllabus.id});
2016-07-02 23:46:45 +08:00
}
2016-06-27 11:09:25 +08:00
2016-07-02 23:46:45 +08:00
}]);