admin_school_edit.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. app.controller('AdminSchoolEditCtrl', function($rootScope, $scope, $http, $timeout, $state, $window, $q, toaster, $stateParams, myConfig) {
  2. $scope.load = function(){
  3. $scope.schoolId = $stateParams.id;
  4. var p_province = $http({
  5. url : myConfig.admin + '/frame/province',
  6. method : 'GET'
  7. }).success(function(data) {
  8. if(data.code == 0){
  9. $scope.provinces = data.result;
  10. }else{
  11. $rootScope.dialogMsg(data.message, function(){
  12. window.location = "index.html";
  13. })
  14. }
  15. }).error(function() {
  16. });
  17. var p_area = $http({
  18. url : myConfig.admin + '/frame/area_all',
  19. method : 'GET'
  20. }).success(function(data) {
  21. if(data.code == 0){
  22. $scope.areas = data.result;
  23. }else{
  24. $rootScope.dialogMsg(data.message, function(){
  25. window.location = "index.html";
  26. })
  27. }
  28. }).error(function() {
  29. });
  30. var p_city = $http({
  31. url : myConfig.admin + '/frame/city_all',
  32. method : 'GET'
  33. }).success(function(data) {
  34. if(data.code == 0){
  35. $scope.cities = data.result;
  36. }else{
  37. $rootScope.dialogMsg(data.message, function(){
  38. window.location = "index.html";
  39. })
  40. }
  41. }).error(function() {
  42. });
  43. var p_school = $http({
  44. url : myConfig.admin + '/school/school?id=' + $scope.schoolId + '&session=' + $rootScope.session,
  45. method : 'GET'
  46. }).success(function(data) {
  47. if(data.code == 0){
  48. $scope.school = data.result;
  49. }else{
  50. $rootScope.dialogMsg(data.message, function(){
  51. window.location = "index.html";
  52. })
  53. }
  54. }).error(function() {
  55. });
  56. $scope.myPromise = $q.all([p_province, p_area, p_city, p_school]);
  57. }
  58. $scope.load();
  59. $scope.refreshArea = function(){
  60. $scope.login.graduate_school_area = null;
  61. $scope.login.graduate_school_city = null;
  62. $scope.myPromise = $http({
  63. url : myConfig.admin + '/frame/area/' + $scope.school.province_id,
  64. method : 'GET'
  65. }).success(function(data) {
  66. if(data.code == 0){
  67. $scope.areas = data.result;
  68. }
  69. }).error(function() {
  70. });
  71. }
  72. $scope.refreshCity = function(){
  73. $scope.login.graduate_school_city = null;
  74. $scope.myPromise = $http({
  75. url : myConfig.admin + '/frame/city/' + $scope.school.area_id,
  76. method : 'GET'
  77. }).success(function(data) {
  78. if(data.code == 0){
  79. $scope.cities = data.result;
  80. }
  81. }).error(function() {
  82. });
  83. }
  84. $scope.submitForm = function(isValid) {
  85. $scope.submitted = true;
  86. console.log('submitForm: ' + isValid);
  87. // check to make sure the form is completely valid
  88. if (isValid) {
  89. $scope.myPromise = $http({
  90. url : myConfig.admin + '/school/school?session=' + $rootScope.session,
  91. method : 'POST',
  92. data : angular.toJson($scope.school)
  93. }).success(function(data) {
  94. if(data.code == 0){
  95. toaster.pop('success', '操作成功!');
  96. }else{
  97. $rootScope.dialogMsg(data.errorMsg, function(){});
  98. }
  99. }).error(function() {
  100. });
  101. }
  102. };
  103. })