Remove ECOMP in headers
[clamp.git] / src / main / resources / META-INF / resources / designer / scripts / FileUploadCtrl.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 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
24 app.controller('fileUploadCtrl', ['$scope', '$rootScope','fileUpload', function($scope, $rootScope,fileUpload){
25     console.log("///////////fileUploadCtrl");
26         $rootScope.isAllOption = false;
27         
28
29     
30 //-----For Required Radio button functionality
31     
32  
33
34     $scope.requiredonly= function(){
35         console.log("requiredonly");
36         //var tempArray = $rootScope.SUT;
37         //var tempParam = tempArray.parameters;
38         //alert("testParam.length:"+tempParam.length);
39         var parameter=$scope.parArray;
40
41         
42         var param=$scope.parameters; 
43         
44         var i=0;
45
46         $('.req').each(function(){
47             console.log(".req");
48                             var newID='requiredval'+i;
49                             //jQuery(this).prev("req").attr("requiredval", "newID");
50                             //$(this).attr("requiredval","newID");
51                             //var newval=$(this).val(newID);
52                             var newval=$(this).attr('id',newID);
53                             console.log("Angular id: "+newval);
54                             if(i<param.length){
55                                 document.getElementById(newID).disabled=false;
56                             if (parameter[i]){
57                                 param[i].required=parameter[i];
58                                         //document.getElementById(newID).disabled=true;
59                                         document.getElementById(newID).checked=true;
60                                         }
61                                         else{
62                                         param[i].required=parameter[i]; 
63                                         //document.getElementById(newID).disabled=false;
64                                         document.getElementById(newID).checked=false;
65                                 }
66                             }
67                             i++;
68                         });
69     };
70     
71
72     $scope.allrequired= function(){
73         console.log("allrequired");
74         var param=$scope.parameters;
75         var i=0;
76         $('.req').each(function(){
77             console.log("req");
78                 var newID='requiredval'+i;
79                             //jQuery(this).prev("req").attr("requiredval", "newID");
80                             //$(this).attr("requiredval","newID");
81                             //var newval=$(this).val(newID);
82                             var newval=$(this).attr('id',newID);
83                             console.log("Angular id: "+newval);
84                             if(i<param.length){
85                                 param[i].required=true;
86                                 document.getElementById(newID).checked=true;
87                                 document.getElementById(newID).disabled=true;
88                     }
89                     i++;
90                 });
91
92       };
93
94     
95 $scope.uploadSUTFile = function(element){
96 console.log("uploadSUTFile");   
97         $scope.$apply(function($scope) {
98         console.log("apply");
99              $rootScope.isAllOption = false;
100              $rootScope.isStatic = true;            
101              $scope.requiredval= false;      
102              $rootScope.rightTabName ="UTM Build Configuration";
103                  $rootScope.testSet = null;
104                  
105                 if($rootScope.isStatic == true){
106                         document.getElementById('buidConfigBtn').style.visibility  = "hidden";
107                 }
108         var file = element.files[0];/*$scope.requestFile;*/
109         
110         console.log('file is ' + JSON.stringify(file));
111         
112         $rootScope.file_type="SUT";
113         
114         var uploadUrl = "/utm-service/sut_upload/uploadSUT";
115         
116         fileUpload.uploadFileToUrl(file, uploadUrl)
117         .then(function(pars) {
118             console.log("uploadFileToUrl");
119                 $rootScope.SUT =  pars;
120                 console.log("file name :"+pars.name);
121                 $scope.fileName = pars.name;
122                 $scope.parameters = pars.parameters;
123                 
124                 $scope.constraints =pars.constraints;
125                 $scope.relations =pars.relations;
126                 var  con  = $scope.constraints;
127         },
128         function(data) {
129             console.log("data");
130                 //alert("File upload failed and parameters not returned");
131         });
132         angular.forEach(
133                     angular.element("input[type='file']"),
134                     function(inputElem) {
135                     console.log("inputElem");
136                       angular.element(inputElem).val(null);
137                     });
138         
139           
140         
141         });
142     };
143     
144     $scope.buildConfig = function(){
145     console.log("buildConfig");         
146         $rootScope.isStatic = true;     
147         $rootScope.rightTabName ="UTM Build Configuration";
148         document.getElementById('buidConfigBtn').style.visibility  = "hidden";
149         $rootScope.testset = null;
150                 
151         
152     };
153     
154   /*  $scope.close = function(){
155         $modalInstance.close('closed');
156     };
157     
158     $scope.importSchema= function(){    
159          var file = $scope.requestFile;
160          console.log('file is ' + JSON.stringify(file));
161          var uploadUrl = "/utm-service/schema_upload/uploadSchema";
162          fileUpload.uploadFileToUrl(file, uploadUrl)
163          .then(function(pars) {                 
164                 $rootScope.SUT =  pars;
165                 console.log("file name :"+pars.name);
166                 $scope.fileName = pars.name;
167                 $scope.parameters = pars.parameters;            
168                 var param = pars.parameters;
169          },
170          function(data) {
171                 //alert("File upload failed and parameters not returned");
172          });
173
174                 
175     };  */
176     
177
178
179     
180     
181 }]);
182
183 function clearFileInput(id) 
184
185     console.log("clearFileInput");
186     var oldInput = document.getElementById(id); 
187
188     var newInput = document.createElement("input"); 
189
190     newInput.type = "file"; 
191     newInput.id = oldInput.id; 
192     newInput.name = oldInput.name; 
193     newInput.className = oldInput.className; 
194     newInput.style.cssText = oldInput.style.cssText; 
195     // TODO: copy any other relevant attributes 
196
197     oldInput.parentNode.replaceChild(newInput, oldInput); 
198 }