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

49 lines
1.3 KiB
JavaScript

app.controller('NewProjectController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms','common', function($scope, $http, auth, config, alertService, $location,rms,common){
// common.checkLogin();
var vm = $scope;
vm.alertService = alertService.create();
vm.project = {
name:""
};
vm.addClass = function(){
vm.syllabus.courses.push({});
};
vm.deleteClass = function(index){
vm.syllabus.courses.splice(index, 1);
}
vm.newProject = function (frm, project) {
frm.$setSubmitted();
console.log(project);
if(!frm.$valid){
console.log(frm.$error);
return;
}
$http.post(config.apiUrl+"projects/create", {
token: auth.token(),
name: project.name
}).then(function(response){
if(response.data.status!=0){
vm.alertService.showMessage('出错了', response.data.message);
} else {
vm.alertService.showMessage('提示', '新建项目成功', function(){
// window.history.back();
rms.save('projects',[]);
$location.path("/project_list");
});
}
console.log(response.data.data);
});
}
}] );