138d80202810e2e9055c673af30140e8e1f2f13d
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / DeploymentCtrl.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * 
22  */
23 app
24 .controller(
25 'DeploymentCtrl',
26 [
27 '$scope',
28 '$rootScope',
29 '$uibModalInstance',
30 '$http',
31 '$q',
32 'data',
33 'dialogs',
34 'cldsModelService',
35 function($scope, $rootScope, $uibModalInstance, $http, $q, data, dialogs, cldsModelService) {
36         function validate_and_set_deploy_parameters() {
37                         var form = $("#deployForm")[0];
38                         var obj = {};
39                         for( var i = 0; i < form.length; ++i ) {
40                                 var name = form[i].name;
41                                 var value = form[i].value;
42                                 if( name ) {
43                                         obj[ name ] = value;
44                                 }
45                         }
46
47                         var el = getGlobalProperty();
48                         el["dcaeDeployParameters"] = obj;
49                         $scope.saveGlobalProperties(JSON.stringify(el)).then(function(pars) {
50                                 updateGlobalProperties(el);
51                         }, function(data) {
52                         });
53         }
54
55         $scope.load_deploy_parameters = function() {
56                 var el = getDeploymentProperties();
57                 for (var key in el) {
58                         var propertyValue = el[key];
59                         $('#deployForm').append(
60                                 $('<label for="' + key + '" class="control-label">' + key + '  </label>'));
61                         $('#deployForm').append(
62                                 $('<input style="width: 100%; clear: both;" class="form-control" name="'
63                                 + key + '"></input>').val(propertyValue).html(propertyValue));
64                 }
65         }
66         $scope.deploy = function() {
67                 validate_and_set_deploy_parameters();
68                 $uibModalInstance.close();
69         };
70         $scope.close = function() {
71                 $uibModalInstance.dismiss();
72         };
73         $scope.saveGlobalProperties = function(form) {
74                 var modelName = getLoopName();
75                  var def = $q.defer();
76                  var svcUrl = "/restservices/clds/v2/loop/updateGlobalProperties/" + modelName;
77                  $http.post(svcUrl, form).success(function(data) {
78                          def.resolve(data);
79                  }).error(function(data) {
80                          def.reject("Save Global properties not successful");
81                  });
82                return def.promise;
83            };
84 } ]);