Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / editorTabController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP 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
21 /*
22 /!**
23  *!/
24 (function(window, angular, $) {
25     'use strict';
26    app.controller('policyeditorTabController', [
27         '$scope', '$translate', '$cookies', 'fileManagerConfig', 'item', 'fileNavigator', 'fileUploader',
28         function($scope, $translate, $cookies, fileManagerConfig, Item, FileNavigator, FileUploader) {
29
30 /!*app.controller('policyeditorTabController', function ($scope, $translate, $cookies, fileManagerConfig, Item, FileNavigator, FileUploader){*!/
31     $( "#dialog" ).hide();
32     $scope.config = fileManagerConfig;
33     $scope.reverse = false;
34     $scope.predicate = ['model.type', 'model.name'];
35     $scope.order = function(predicate) {
36         $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false;
37         $scope.predicate[1] = predicate;
38     };
39
40     $scope.query = '';
41     $scope.temp = new Item();
42     $scope.fileNavigator = new FileNavigator();
43     $scope.fileUploader = FileUploader;
44     $scope.uploadFileList = [];
45     $scope.viewTemplate = $cookies.viewTemplate || 'main-table.html';
46
47     $scope.setTemplate = function(name) {
48         $scope.viewTemplate = $cookies.viewTemplate = name;
49     };
50
51     $scope.changeLanguage = function (locale) {
52         if (locale) {
53             return $translate.use($cookies.language = locale);
54         }
55         $translate.use($cookies.language || fileManagerConfig.defaultLang);
56     };
57
58     $scope.touch = function(item) {
59         item = item instanceof Item ? item : new Item();
60         item.revert();
61         $scope.temp = item;
62     };
63
64     $scope.smartClick = function(item) {
65         if (item.isFolder()) {
66             return $scope.fileNavigator.folderClick(item);
67         }
68         if (item.isImage()) {
69             return $scope.openImagePreview(item);
70         }
71         if (item.isEditable()) {
72             return $scope.openEditItem(item);
73         }
74     };
75
76     $scope.openImagePreview = function(item) {
77         item.inprocess = true;
78         $scope.modal('imagepreview')
79             .find('#imagepreview-target')
80             .attr('src', item.getUrl(true))
81             .unbind('load error')
82             .on('load error', function() {
83                 item.inprocess = false;
84                 $scope.$apply();
85             });
86         return $scope.touch(item);
87     };
88
89     $scope.openEditItem = function(item) {
90         item.getContent();
91         $scope.modal('edit');
92         return $scope.touch(item);
93     };
94
95     $scope.modal = function(id, hide) {
96         return $('#' + id).modal(hide ? 'hide' : 'show');
97     };
98
99     $scope.isInThisPath = function(path) {
100         var currentPath = $scope.fileNavigator.currentPath.join('/');
101         return currentPath.indexOf(path) !== -1;
102     };
103
104     $scope.edit = function(item) {
105         item.edit().then(function() {
106             $scope.modal('edit', true);
107         });
108     };
109
110     $scope.changePermissions = function(item) {
111         item.changePermissions().then(function() {
112             $scope.modal('changepermissions', true);
113         });
114     };
115
116     $scope.copy = function(item) {
117         var samePath = item.tempModel.path.join() === item.model.path.join();
118         if (samePath && $scope.fileNavigator.fileNameExists(item.tempModel.name)) {
119             item.error = $translate.instant('error_invalid_filename');
120             return false;
121         }
122         item.copy().then(function() {
123             $scope.fileNavigator.refresh();
124             $scope.modal('copy', true);
125         });
126     };
127
128     $scope.compress = function(item) {
129         item.compress().then(function() {
130             $scope.fileNavigator.refresh();
131             if (! $scope.config.compressAsync) {
132                 return $scope.modal('compress', true);
133             }
134             item.asyncSuccess = true;
135         }, function() {
136             item.asyncSuccess = false;
137         });
138     };
139
140     $scope.extract = function(item) {
141         item.extract().then(function() {
142             $scope.fileNavigator.refresh();
143             if (! $scope.config.extractAsync) {
144                 return $scope.modal('extract', true);
145             }
146             item.asyncSuccess = true;
147         }, function() {
148             item.asyncSuccess = false;
149         });
150     };
151
152     $scope.remove = function(item) {
153         item.remove().then(function() {
154             $scope.fileNavigator.refresh();
155             $scope.modal('delete', true);
156         });
157     };
158
159     $scope.rename = function(item) {
160         var samePath = item.tempModel.path.join() === item.model.path.join();
161         if (samePath && $scope.fileNavigator.fileNameExists(item.tempModel.name)) {
162             item.error = $translate.instant('error_invalid_filename');
163             return false;
164         }
165         item.rename().then(function() {
166             $scope.fileNavigator.refresh();
167             $scope.modal('rename', true);
168         });
169     };
170
171     $scope.createFolder = function(item) {
172         var name = item.tempModel.name && item.tempModel.name.trim();
173         item.tempModel.type = 'dir';
174         item.tempModel.path = $scope.fileNavigator.currentPath;
175         if (name && !$scope.fileNavigator.fileNameExists(name)) {
176             item.createFolder().then(function() {
177                 $scope.fileNavigator.refresh();
178                 $scope.modal('newfolder', true);
179             });
180         } else {
181             item.error = $translate.instant('error_invalid_filename');
182             return false;
183         }
184     };
185
186     $scope.uploadFiles = function() {
187         $scope.fileUploader.upload($scope.uploadFileList, $scope.fileNavigator.currentPath).then(function() {
188             $scope.fileNavigator.refresh();
189             $scope.modal('uploadfile', true);
190         }, function(data) {
191             var errorMsg = data.result && data.result.error || $translate.instant('error_uploading_files');
192             $scope.temp.error = errorMsg;
193         });
194     };
195
196     $scope.getQueryParam = function(param) {
197         var found;
198         window.location.search.substr(1).split('&').forEach(function(item) {
199             if (param ===  item.split('=')[0]) {
200                 found = item.split('=')[1];
201                 return false;
202             }
203         });
204         return found;
205     };
206
207     $scope.changeLanguage($scope.getQueryParam('lang'));
208     $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
209     $scope.fileNavigator.refresh();
210         }]);
211 })(window, angular, jQuery);*/