app.controller('AdminSchoolEditCtrl', function($rootScope, $scope, $http, $timeout, $state, $window, $q, toaster, $stateParams, myConfig) { $scope.load = function(){ $scope.schoolId = $stateParams.id; var p_province = $http({ url : myConfig.admin + '/frame/province', method : 'GET' }).success(function(data) { if(data.code == 0){ $scope.provinces = data.result; }else{ $rootScope.dialogMsg(data.message, function(){ window.location = "index.html"; }) } }).error(function() { }); var p_area = $http({ url : myConfig.admin + '/frame/area_all', method : 'GET' }).success(function(data) { if(data.code == 0){ $scope.areas = data.result; }else{ $rootScope.dialogMsg(data.message, function(){ window.location = "index.html"; }) } }).error(function() { }); var p_city = $http({ url : myConfig.admin + '/frame/city_all', method : 'GET' }).success(function(data) { if(data.code == 0){ $scope.cities = data.result; }else{ $rootScope.dialogMsg(data.message, function(){ window.location = "index.html"; }) } }).error(function() { }); var p_school = $http({ url : myConfig.admin + '/school/school?id=' + $scope.schoolId + '&session=' + $rootScope.session, method : 'GET' }).success(function(data) { if(data.code == 0){ $scope.school = data.result; }else{ $rootScope.dialogMsg(data.message, function(){ window.location = "index.html"; }) } }).error(function() { }); $scope.myPromise = $q.all([p_province, p_area, p_city, p_school]); } $scope.load(); $scope.refreshArea = function(){ $scope.login.graduate_school_area = null; $scope.login.graduate_school_city = null; $scope.myPromise = $http({ url : myConfig.admin + '/frame/area/' + $scope.school.province_id, method : 'GET' }).success(function(data) { if(data.code == 0){ $scope.areas = data.result; } }).error(function() { }); } $scope.refreshCity = function(){ $scope.login.graduate_school_city = null; $scope.myPromise = $http({ url : myConfig.admin + '/frame/city/' + $scope.school.area_id, method : 'GET' }).success(function(data) { if(data.code == 0){ $scope.cities = data.result; } }).error(function() { }); } $scope.submitForm = function(isValid) { $scope.submitted = true; console.log('submitForm: ' + isValid); // check to make sure the form is completely valid if (isValid) { $scope.myPromise = $http({ url : myConfig.admin + '/school/school?session=' + $rootScope.session, method : 'POST', data : angular.toJson($scope.school) }).success(function(data) { if(data.code == 0){ toaster.pop('success', '操作成功!'); }else{ $rootScope.dialogMsg(data.errorMsg, function(){}); } }).error(function() { }); } }; })