2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 (function(window, angular, $) {
26 app.controller('policyeditorTabController', [
27 '$scope', '$translate', '$cookies', 'fileManagerConfig', 'item', 'fileNavigator', 'fileUploader',
28 function($scope, $translate, $cookies, fileManagerConfig, Item, FileNavigator, FileUploader) {
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;
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';
47 $scope.setTemplate = function(name) {
48 $scope.viewTemplate = $cookies.viewTemplate = name;
51 $scope.changeLanguage = function (locale) {
53 return $translate.use($cookies.language = locale);
55 $translate.use($cookies.language || fileManagerConfig.defaultLang);
58 $scope.touch = function(item) {
59 item = item instanceof Item ? item : new Item();
64 $scope.smartClick = function(item) {
65 if (item.isFolder()) {
66 return $scope.fileNavigator.folderClick(item);
69 return $scope.openImagePreview(item);
71 if (item.isEditable()) {
72 return $scope.openEditItem(item);
76 $scope.openImagePreview = function(item) {
77 item.inprocess = true;
78 $scope.modal('imagepreview')
79 .find('#imagepreview-target')
80 .attr('src', item.getUrl(true))
82 .on('load error', function() {
83 item.inprocess = false;
86 return $scope.touch(item);
89 $scope.openEditItem = function(item) {
92 return $scope.touch(item);
95 $scope.modal = function(id, hide) {
96 return $('#' + id).modal(hide ? 'hide' : 'show');
99 $scope.isInThisPath = function(path) {
100 var currentPath = $scope.fileNavigator.currentPath.join('/');
101 return currentPath.indexOf(path) !== -1;
104 $scope.edit = function(item) {
105 item.edit().then(function() {
106 $scope.modal('edit', true);
110 $scope.changePermissions = function(item) {
111 item.changePermissions().then(function() {
112 $scope.modal('changepermissions', true);
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');
122 item.copy().then(function() {
123 $scope.fileNavigator.refresh();
124 $scope.modal('copy', true);
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);
134 item.asyncSuccess = true;
136 item.asyncSuccess = false;
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);
146 item.asyncSuccess = true;
148 item.asyncSuccess = false;
152 $scope.remove = function(item) {
153 item.remove().then(function() {
154 $scope.fileNavigator.refresh();
155 $scope.modal('delete', true);
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');
165 item.rename().then(function() {
166 $scope.fileNavigator.refresh();
167 $scope.modal('rename', true);
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);
181 item.error = $translate.instant('error_invalid_filename');
186 $scope.uploadFiles = function() {
187 $scope.fileUploader.upload($scope.uploadFileList, $scope.fileNavigator.currentPath).then(function() {
188 $scope.fileNavigator.refresh();
189 $scope.modal('uploadfile', true);
191 var errorMsg = data.result && data.result.error || $translate.instant('error_uploading_files');
192 $scope.temp.error = errorMsg;
196 $scope.getQueryParam = function(param) {
198 window.location.search.substr(1).split('&').forEach(function(item) {
199 if (param === item.split('=')[0]) {
200 found = item.split('=')[1];
207 $scope.changeLanguage($scope.getQueryParam('lang'));
208 $scope.isWindows = $scope.getQueryParam('server') === 'Windows';
209 $scope.fileNavigator.refresh();
211 })(window, angular, jQuery);*/