ClusterController.js 3.4 KB
Newer Older
lepdou committed
1 2 3 4 5 6 7 8 9
cluster_module.controller('ClusterController',
                          ['$scope', '$location', '$window', 'toastr', 'AppService', 'EnvService', 'ClusterService',
                           'AppUtil',
                           function ($scope, $location, $window, toastr, AppService, EnvService, ClusterService,
                                     AppUtil) {

                               var params = AppUtil.parseParams($location.$$url);
                               $scope.appId = params.appid;

lepdou committed
10 11
                               $scope.step = 1;
                               
12 13
                               $scope.submitBtnDisabled = false;
                               
lepdou committed
14 15 16 17 18
                               EnvService.find_all_envs().then(function (result) {
                                   $scope.envs = [];
                                   result.forEach(function (env) {
                                       $scope.envs.push({name: env, checked: false});

lepdou committed
19 20
                                   });
                                   $(".apollo-container").removeClass("hidden");
lepdou committed
21 22 23 24 25 26
                               }, function (result) {
                                   toastr.error(AppUtil.errorMsg(result), "加载环境信息出错");
                               });

                               $scope.clusterName = '';

lepdou committed
27 28 29 30 31 32
                               $scope.switchChecked = function (env,  $event) {
                                   env.checked = !env.checked;
                                   $event.stopPropagation();
                               };

                               $scope.toggleEnvCheckedStatus = function (env) {
lepdou committed
33 34 35 36
                                   env.checked = !env.checked;
                               };

                               $scope.create = function () {
lepdou committed
37

lepdou committed
38
                                   var noEnvChecked = true;
lepdou committed
39
                                   $scope.envs.forEach(function (env) {
lepdou committed
40 41
                                       if (env.checked) {
                                           noEnvChecked = false;
42
                                           $scope.submitBtnDisabled = true;
lepdou committed
43 44 45 46 47 48
                                           ClusterService.create_cluster($scope.appId, env.name,
                                                                         {
                                                                             name: $scope.clusterName,
                                                                             appId: $scope.appId
                                                                         }).then(function (result) {
                                               toastr.success(env.name, "集群创建成功");
lepdou committed
49
                                               $scope.step = 2;
50
                                               $scope.submitBtnDisabled = false;
lepdou committed
51 52
                                           }, function (result) {
                                               toastr.error(AppUtil.errorMsg(result), "集群创建失败");
53
                                               $scope.submitBtnDisabled = false;
lepdou committed
54 55
                                           })
                                       }
lepdou committed
56
                                   });
lepdou committed
57

lepdou committed
58 59 60 61
                                   if (noEnvChecked){
                                       toastr.warning("请选择环境");
                                   }

lepdou committed
62 63 64
                               };

                           }]);