'use strict'; angular.module('ModuleAB', [ 'ngRoute', 'ui.bootstrap', 'angular-loading-bar', 'ngAnimate', 'ModuleAB.appsets', 'ModuleAB.records', 'ModuleAB.policies', 'ModuleAB.hosts', 'ModuleAB.paths', 'ModuleAB.backupsets', 'ModuleAB.oss', 'ModuleAB.oas', 'ModuleAB.users', 'ModuleAB.clientjobs', 'ModuleAB.faillogs', ]) .config(['$routeProvider', function($routeProvider) { $routeProvider.otherwise({ redirectTo: '/hosts' }); }]) .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) { cfpLoadingBarProvider.includeSpinner = false; }]) .controller("topNavBar", ['$scope', '$http', '$uibModal', '$rootScope', '$window', function($scope, $http, $uibModal, $rootScope, $window) { $rootScope.dismiss = function() { $rootScope.fadein = ''; }; $rootScope.dismiss(); $http({ method: "GET", url: "/api/v1/auth/check" }).then(function(response) { $scope.session = response.data; $rootScope.loaded = true; }, function(response) { $window.location.href = "/login"; }); $scope.logout = function() { $http({ method: "GET", url: "/api/v1/auth/logout" }).then(function(response) { $window.location.href = "/login"; }, function(response) { switch (response.status) { case 401: $window.location.href = "/login"; break; } }); }; $scope.about = function() { $uibModal.open({ templateUrl: "aboutModal.html", controller: "aboutModal" }); }; $scope.profile = function() { $uibModal.open({ templateUrl: "userProfileModal.html", controller: "userProfileModal", resolve: { session: function() { return $scope.session; } } }); }; } ]) .controller('aboutModal', function($scope, $http, $uibModalInstance) { $http({ method: "GET", url: "/api/v1/version" }).then(function(response) { $scope.version = response.data; }); $scope.cancel = function() { $uibModalInstance.dismiss('cancel'); }; }) .controller('userProfileModal', function($scope, $http, $uibModalInstance, $window, session) { $http({ method: "GET", url: "/api/v1/users/" + session.name }).then(function(response) { $scope.user = response.data[0]; $scope.password2 = $scope.user.password; }, function(response) { $rootScope.alertType = 'alert-warning'; $rootScope.fadein = 'fadein-opacity'; switch (response.status) { case 401: $window.location.href = "/login"; break; case 403: $rootScope.failMessage = "没ææé"; break; case 404: $rootScope.failMessage = "æ æ¤ç¨æ·"; break; case 500: $rootScope.failMessage = "æå¡å¨é误ï¼è§æ§å¶å°è¾åº"; console.log(response.data); break; default: $rootScope.failMessage = "é讯æ é"; break; } }); $scope.doJob = function() { if ($scope.user.loginname == '') { $scope.modalInfoFadein = "fadein-opacity"; $scope.modalInfoMsg = "ç»å½åä¸è½ä¸ºç©º"; return; } if ($scope.user.name == '') { $scope.modalInfoFadein = "fadein-opacity"; $scope.modalInfoMsg = "æ¾ç¤ºåä¸è½ä¸ºç©º"; return; } if (!$scope.user.password.match(/.{8,32}/)) { $scope.modalInfoFadein = "fadein-opacity"; $scope.modalInfoMsg = "å¯ç é¿åº¦ä¸º8-32ä½ï¼"; return; } if ($scope.user.password != $scope.password2) { $scope.modalInfoFadein = "fadein-opacity"; $scope.modalInfoMsg = "两次è¾å ¥çå¯ç ä¸ä¸è´ï¼"; return; } $http({ method: "PUT", url: "/api/v1/users/" + $scope.user.loginname, data: $scope.user }).then(function(response) { $uibModalInstance.close(response.status); }, function(response) { $scope.modalInfoFadein = "fadein-opacity"; switch (response.status) { case 400: $scope.modalInfoMsg = "æ°æ®é误"; break; case 401: $scope.modalInfoMsg = "æªç»å½"; window.location.href = "/login"; break; case 403: $scope.modalInfoMsg = "访é®è¢«æç»"; break; case 404: $scope.modalInfoMsg = "æ æ¤ç¨æ·"; break; case 500: $scope.modalInfoMsg = "æå¡å¨é误ï¼è§æ§å¶å°è¾åº"; console.log(response.data); break; default: $scope.modalInfoMsg = "é讯æ é"; break; } }); }; $scope.cancel = function() { $uibModalInstance.dismiss('cancel'); }; });