[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / controller / ImportDictionaryController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 app.controller('importDictionaryController' ,  function ($scope, $modalInstance, message, $http, PolicyAppService, UserInfoServiceDS2, Notification){ 
21
22         /*getting user info from session*/
23         var userid = null;
24         UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
25         .then(function (response) {                     
26                 userid = response.userid;               
27         });
28
29         $scope.importButton = true;
30         var fd;
31         $scope.uploadFile = function(files) {
32                 fd = new FormData();
33                 fd.append("file", files[0]);
34                 var fileExtension = files[0].name.split(".")[1];
35                 if(fileExtension == "csv"){
36                         $scope.importButton = false;
37                         $scope.$apply();
38                 }else{
39                         Notification.error("Upload the Dictionary file extends with .csv format");
40                 }
41         };
42         
43         $scope.submitUpload = function(){
44                 $http.post("saveDictionary/dictionary/import_dictionary", fd,  {
45                         withCredentials: false,
46                         headers: {'Content-Type': undefined},
47                         transformRequest: angular.identity
48                 }).success(function(){
49                         Notification.success("Dictionary Uploaded Successfully");
50                         $scope.importButton = true;
51                 }).error(function(){
52                          Notification.error("Dictionary Upload Failed");
53                 });
54         };
55
56 $scope.close = function() {
57         $modalInstance.close();
58 };
59 });