diff --git a/src/components/filetree.html b/src/components/filetree.html index a1c07bdd4..c5f3946c1 100644 --- a/src/components/filetree.html +++ b/src/components/filetree.html @@ -57,31 +57,6 @@ - - - - - diff --git a/src/components/filetree.js b/src/components/filetree.js index 13f4fd3f7..8751fa334 100644 --- a/src/components/filetree.js +++ b/src/components/filetree.js @@ -10,6 +10,8 @@ angular.module('Application').component('filetree', { view: '<', onUploadFile: '&', onUploadFolder: '&', + onRenameEntry: '&', + onExtractEntry: '&', onDeleteEntries: '&' }, templateUrl: 'components/filetree.html?<%= revision %>', @@ -148,42 +150,6 @@ function FileTreeController($scope, $translate, $timeout, Client) { return $scope.selected.indexOf(entry) !== -1; }; - $scope.extractStatus = { - error: null, - busy: false, - fileName: '' - }; - - function extract(entry) { - var filePath = sanitize($scope.cwd + '/' + entry.fileName); - - if (entry.isDirectory) return; - - // prevent it from getting closed - $('#extractModal').modal({ - backdrop: 'static', - keyboard: false - }); - - $scope.extractStatus.fileName = entry.fileName; - $scope.extractStatus.error = null; - $scope.extractStatus.busy = true; - - Client.filesExtract($scope.backendId, $scope.backendType, filePath, function (error) { - $scope.extractStatus.busy = false; - - if (error) { - console.error(error); - $scope.extractStatus.error = $translate.instant('filemanager.extract.error', error.message); - return; - } - - $('#extractModal').modal('hide'); - - $scope.refresh(); - }); - } - function download(entry) { var filePath = sanitize($scope.cwd + '/' + entry.fileName); @@ -316,6 +282,7 @@ function FileTreeController($scope, $translate, $timeout, Client) { $scope.$parent.refresh(); }; + // called from the parent $scope.onRefresh = function () { $scope.selected = []; @@ -592,38 +559,6 @@ function FileTreeController($scope, $translate, $timeout, Client) { } }; - $scope.renameEntry = { - busy: false, - error: null, - entry: null, - newName: '', - - show: function (entry) { - $scope.renameEntry.error = null; - $scope.renameEntry.entry = entry; - $scope.renameEntry.newName = entry.fileName; - $scope.renameEntry.busy = false; - - $('#renameEntryModal-' + $scope.$id).modal('show'); - }, - - submit: function () { - $scope.renameEntry.busy = true; - - var oldFilePath = sanitize($scope.cwd + '/' + $scope.renameEntry.entry.fileName); - var newFilePath = sanitize(($scope.renameEntry.newName[0] === '/' ? '' : ($scope.cwd + '/')) + $scope.renameEntry.newName); - - Client.filesRename($scope.backendId, $scope.backendType, oldFilePath, newFilePath, function (error) { - $scope.renameEntry.busy = false; - if (error) return Client.error(error); - - $scope.refresh(); - - $('#renameEntryModal-' + $scope.$id).modal('hide'); - }); - } - }; - $scope.mediaViewer = { type: '', src: '', @@ -741,14 +676,14 @@ function FileTreeController($scope, $translate, $timeout, Client) { }, { text: tr['filemanager.list.menu.rename'], enabled: function () { return $scope.selected.length === 1; }, - click: function ($itemScope, $event, entry) { $scope.renameEntry.show(entry); } + click: function ($itemScope, $event, entry) { ctrl.onRenameEntry({ cwd: $scope.cwd, entry: entry }); } }, { text: tr['filemanager.list.menu.chown'], click: function ($itemScope, $event, entry) { $scope.chownEntry.show(); } }, { text: tr['filemanager.list.menu.extract'], displayed: function ($itemScope, $event, entry) { return !entry.isDirectory && isArchive(entry.fileName); }, - click: function ($itemScope, $event, entry) { extract(entry); } + click: function ($itemScope, $event, entry) { ctrl.onExtractEntry({ cwd: $scope.cwd, entry: entry }); } }, { text: tr['filemanager.list.menu.download'], enabled: function () { return $scope.selected.length === 1; }, @@ -840,31 +775,12 @@ function FileTreeController($scope, $translate, $timeout, Client) { openPath('.'); - // DOM handlers, wait for elements to exist - setTimeout(function () { - $('.file-list').on('scroll', function (event) { - if (event.target.scrollTop > 10) event.target.classList.add('top-scroll-indicator'); - else event.target.classList.remove('top-scroll-indicator'); - }); + $('.file-list').on('scroll', function (event) { + if (event.target.scrollTop > 10) event.target.classList.add('top-scroll-indicator'); + else event.target.classList.remove('top-scroll-indicator'); + }); - // setup all the dialog focus handling - ['newFileModal', 'newDirectoryModal', 'renameEntryModal'].forEach(function (id) { - $('#' + id + '-' + $scope.$id).on('shown.bs.modal', function () { - $(this).find('[autofocus]:first').focus(); - }); - }); - - // selects filename (without extension) - ['renameEntryModal'].forEach(function (id) { - $('#' + id + '-' + $scope.$id).on('shown.bs.modal', function () { - var elem = $(this).find('[autofocus]:first'); - var text = elem.val(); - elem[0].setSelectionRange(0, text.indexOf('.')); - }); - }); - }, 0); - - // handle save shortcuts + // handle shortcuts window.addEventListener('keydown', function (event) { if ($scope.$parent.activeView !== $scope.view || $scope.$parent.viewerOpen || isModalVisible()) return; diff --git a/src/filemanager.html b/src/filemanager.html index 40b20be31..995ad0280 100644 --- a/src/filemanager.html +++ b/src/filemanager.html @@ -95,6 +95,56 @@ + + + + + +