/** * Created by guange on 16/6/27. */ app.controller('ProjectListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService','rms', function ($scope, config, auth, $http, $location, alertService,rms) { var vm = $scope; vm.projects = rms.get('projects') || []; vm.alertService_1 = alertService.create(); vm.alertService_3 = alertService.create(); var loadProjectList = function () { $http.get(config.apiUrl + "projects?token=" + auth.token()).then( function (response) { console.log(response.data); vm.projects = response.data.data; rms.save('projects', vm.projects); } ); }; if(vm.projects.length<=0){ loadProjectList(); } vm.goProject = function (project_id) { console.log(project_id); $location.path("/project").search({id: project_id}); } vm.newProject = function () { //先判断下权限 $http.post(config.apiUrl + "projects/auth",{token: auth.token()} ).then( function (response) { console.log(response.data); if (response.data.auth == 0) { vm.alertService_1.showMessage('提示', '非教师身份不能创建课程哦~'); } else{ $location.path("/new_project"); } } ); } vm.joinProject = function () { vm.alertService_3.showMessage('提示', '请输入6位项目邀请码(不区分大小写)', 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('提示', '邀请码格式不正确'); } } }); }; vm.onSetting = function (project) { console.log(project); rms.save('current_edit_project', project); $location.path("/edit_project").search({id: project.id}); } }]);