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