app.controller('ProjectPublishNoteController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,common){ // common.checkLogin(); var vm = $scope; vm.current_project = rms.get('current_project'); var project_id = $routeParams.id; vm.alertService = alertService.create(); vm.notetitle = ""; vm.note = ""; if(!vm.current_project){ $http.get(config.apiUrl+ 'projects/'+project_id+"?token="+auth.token()).then( function(response) { console.log(response.data); if (response.data.status == 0){ vm.current_project = response.data.data; console.log("projects"); console.log(response.data.data); } else{ vm.alertService.showMessage('提示', response.data.message); } if(!vm.current_project){ vm.tip_1 = "该项目不存在或已被删除"; } } ); } vm.cancel = function(){ window.history.back(); }; //发布通知 只有老师能发布 vm.publishNote = function(){ if(vm.notetitle.length == 0) { vm.alertService.showMessage('提示', '标题不能为空'); return; } if(vm.note.length == 0) { vm.alertService.showMessage('提示', '内容不能为空'); return; } var text = vm.note.replace(/\n/g,'
'); $http.post(config.apiUrl + "projects/"+project_id+"/publishnote", {token: auth.token(),title: vm.notetitle, text: text} ).then(function(response){ if(response.data.status == 0) { vm.alertService.showMessage('提示', '发布成功',function(){ rms.save('project_activities_page',0); rms.save("project_activities",[]); rms.save("project_has_more",false); rms.save('tab_num',null); $location.path("/project").search({id: project_id}); }); } else{ vm.alertService.showMessage('提示', response.data.message); } }); }; }] );