Browse Source

维护企业信息、申请SAAS、默认路由

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@1258 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
suntg 10 years ago
parent
commit
fda8f5c1b3

+ 120 - 2
src/main/webapp/resources/js/index/app.js

@@ -7,7 +7,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 	app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
 		$urlRouterProvider.otherwise('/index');
 		$stateProvider.state('index', {
-			url : "",
+			url : "/index",
 			views : {
 				"left-view" : {
 					templateUrl : "static/tpl/index/home/left.html"
@@ -2688,8 +2688,10 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 		
 	}]);
 	
-	app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', function($scope, AccountEnterprise){
+	app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', function($scope, AccountEnterprise, toaster, $state, $modal){
+		$scope.loading = true;
 		AccountEnterprise.get({}, function(data){
+			$scope.loading = false;
 			$scope.enterprise = data;
 		});
 		AccountEnterprise.growth({}, function(data){
@@ -2707,6 +2709,121 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 				$scope.growth = growth;
 			}
 		});
+		
+		// 更新企业信息
+		$scope.updateDetailInfo = function(){
+			$scope.loading = true;
+			AccountEnterprise.save($scope.enterprise, function(){
+				$scope.loading = false;
+				$scope.connectionEditing = false;
+				toaster.pop('success', '提示', '修改企业信息成功');
+				$state.reload();
+			}, function(response){
+				$scope.loading = false;
+				toaster.pop('error', '修改信息失败', response.data);
+			});
+		};
+		
+		// 申请Saas
+		$scope.applySaas = function(){
+			if($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
+				var modalInstance = $modal.open({
+					animation: true,
+					templateUrl: 'static/tpl/index/account/applySaas.html',
+					controller: 'ApplySaasCtrl',
+					resolve: {
+						enterprise: function(){return $scope.enterprise;}
+					}
+				});
+				
+				modalInstance.result.then(function(){
+					$state.reload();
+				}, function(){
+					
+				});
+			} else {
+				toaster.pop('info', '请完善信息', '申请SAAS服务请先完善企业详细信息');
+			}
+		};
+	}]);
+	
+	// 申请Saas Controller
+	app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http){
+		$scope.enterprise = enterprise;
+		$scope.checking = false;
+		
+		$scope.$watch('enterprise.enSaasUrl', function(){
+			if($scope.enterprise.enSaasUrl) {
+				$http.get('signup/saasUrlEnable', {
+					params: {
+						enSaasUrl: $scope.enterprise.enSaasUrl
+					}
+				}).success(function(data){
+					if(data && data == 'true') {
+						$scope.applySaasForm.enSaasUrl.$setValidity('available', true);
+					} else {
+						$scope.applySaasForm.enSaasUrl.$setValidity('available', false);
+						$scope.enSaasUrlErrorInfo = 'SAAS域名已被使用';
+					}
+				}).error(function(){
+					$scope.applySaasForm.enSaasUrl.$setValidity('available', false);
+					$scope.enSaasUrlErrorInfo = '验证出错';
+				});
+			} else {
+				$scope.applySaasForm.enSaasUrl.$setValidity('available', false);
+			}
+		});
+		
+		var setSaasUrl = function(url) {
+			var index = url.indexOf('www.');
+			if(index != -1) {//包含www.
+				var substr = url.substring(index+4, url.length);
+				$scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
+			} else {
+				$scope.enterprise.enSaasUrl = getHost(url);
+			}
+		};
+		
+		// 解析获取网址的一级域名
+		var getHost = function(host){
+			var newhost;
+			var domain;
+			var ArrDomain = new Array('.com.cn','.net.cn','.org.cn','.gov.cn','.com','.cn','.tel','.mobi','.net','.org','.asia','.me','.cc','.name','.info');//枚举所有后缀
+			for(var k in ArrDomain){
+				var re = eval('/\\' + ArrDomain[k] + '$/g');
+				newhost = host.replace(re, '');
+				if(newhost != host){
+					domain = ArrDomain[k];
+					break;
+				}
+			}
+			var hostar = newhost.split('.');
+			var s = hostar[hostar.length-1];
+			return s;
+		};
+		
+		// 设置Saas域名为官网网址一级域名
+		if($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
+		
+		$scope.apply = function(){
+			$scope.loading = true;
+			AccountEnterprise.applySaas({
+				enUU: $scope.enterprise.uu,
+				enSaasUrl: $scope.enterprise.enSaasUrl,
+				enAdminPassword: $scope.enterprise.enAdminPassword
+			}, {}, function(){
+				$scope.loading = false;
+				toaster.pop('success', '申请成功', '已提交系统开通SAAS服务,开通后将会发送邮件至管理员邮箱');
+				$modalInstance.close();
+			}, function(response){
+				$scope.loading = false;
+				toaster.pop('error', '申请失败', response.data);
+			});
+		};
+
+  		$scope.cancel = function () {
+    		$modalInstance.dismiss();
+  		};
 	}]);
 	
 	app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', function($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert){
@@ -2948,6 +3065,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'service/Purc', 'ser
 		};
 	}]);
 	
+	// 修改密码Controller
 	app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function($scope, $modalInstance, user, AccountUser, toaster){
 		$scope.user = user;
 		$scope.checking = false;

+ 4 - 0
src/main/webapp/resources/js/index/services/Account.js

@@ -4,6 +4,10 @@ define([ 'ngResource' ], function() {
 			growth: {
 				url: 'account/enterprise/growth',
 				isArray: true
+			},
+			applySaas: {
+				url: 'account/enterprise/applySaas',
+				method: 'POST'
 			}
 		});
 	}]).factory('AccountUser', ['$resource', function($resource) {