diff --git a/composer.json b/composer.json index c2563b8..142cbf7 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "bower-asset/ng-file-upload": "^12.0.1", "bower-asset/ngclipboard": "^1.1.1", "kartik-v/yii2-widget-select2": "^2.0.0", - "rmrevin/yii2-fontawesome": "~2.9" + "rmrevin/yii2-fontawesome": "~2.9", + "yii2assets/yii2-fullscreen-modal": "^1.0.2" }, "extra": { "bootstrap": "hrzg\\filemanager\\Bootstrap", diff --git a/src/assets/dist/angular-filemanager.min.js b/src/assets/dist/angular-filemanager.min.js index 3f55af6..d9c2f7f 100755 --- a/src/assets/dist/angular-filemanager.min.js +++ b/src/assets/dist/angular-filemanager.min.js @@ -24,13 +24,13 @@ if(leftBorder>=window.innerWidth-width){ leftBorder-=width; } - + menu.hide().css( { - position: 'fixed', + position: 'absolute', left: leftBorder, top: e.pageY-offset.top }).show(); - + e.preventDefault(); }); @@ -56,7 +56,7 @@ return undefined; }; } - + })(window, angular, jQuery); (function(angular, $) { @@ -65,302 +65,283 @@ '$scope', '$rootScope', '$window', '$translate', '$http', 'fileManagerConfig', 'item', 'fileNavigator', 'apiMiddleware', function($scope, $rootScope, $window, $translate, $http, fileManagerConfig, Item, FileNavigator, ApiMiddleware) { - var $storage = $window.localStorage; - $scope.config = fileManagerConfig; - $scope.reverse = false; - $scope.predicate = ['model.type', 'model.name']; - $scope.order = function(predicate) { - $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false; - $scope.predicate[1] = predicate; - }; - $scope.query = ''; - $scope.fileNavigator = new FileNavigator(); - $scope.apiMiddleware = new ApiMiddleware(); - $scope.uploadFileList = []; - $scope.viewTemplate = $storage.getItem('viewTemplate') || 'main-icons.html'; - $scope.fileList = []; - $scope.temps = []; - - $scope.$watch('temps', function() { - if ($scope.singleSelection()) { - $scope.temp = $scope.singleSelection(); - } else { - $scope.temp = new Item({rights: 644}); - $scope.temp.multiple = true; - } - $scope.temp.revert(); - }); + var $storage = $window.localStorage; + $scope.config = fileManagerConfig; + $scope.reverse = false; + $scope.predicate = ['model.type', 'model.name']; + $scope.order = function(predicate) { + $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false; + $scope.predicate[1] = predicate; + }; + $scope.query = ''; + $scope.fileNavigator = new FileNavigator(); + $scope.apiMiddleware = new ApiMiddleware(); + $scope.uploadFileList = []; + $scope.viewTemplate = $storage.getItem('viewTemplate') || 'main-icons.html'; + $scope.fileList = []; + $scope.temps = []; + + $scope.$watch('temps', function() { + if ($scope.singleSelection()) { + $scope.temp = $scope.singleSelection(); + } else { + $scope.temp = new Item({rights: 644}); + $scope.temp.multiple = true; + } + $scope.temp.revert(); + }); - $scope.fileNavigator.onRefresh = function() { - $scope.temps = []; - $scope.query = ''; - $rootScope.selectedModalPath = $scope.fileNavigator.currentPath; - }; + $scope.fileNavigator.onRefresh = function() { + $scope.temps = []; + $scope.query = ''; + $rootScope.selectedModalPath = $scope.fileNavigator.currentPath; + }; - $scope.setTemplate = function(name) { - $storage.setItem('viewTemplate', name); - $scope.viewTemplate = name; - }; + $scope.setTemplate = function(name) { + $storage.setItem('viewTemplate', name); + $scope.viewTemplate = name; + }; - $scope.changeLanguage = function (locale) { - if (locale) { - $storage.setItem('language', locale); - return $translate.use(locale); - } - $translate.use($storage.getItem('language') || fileManagerConfig.defaultLang); - }; + $scope.changeLanguage = function (locale) { + if (locale) { + $storage.setItem('language', locale); + return $translate.use(locale); + } + $translate.use($storage.getItem('language') || fileManagerConfig.defaultLang); + }; - $scope.isSelected = function(item) { - return $scope.temps.indexOf(item) !== -1; - }; + $scope.isSelected = function(item) { + return $scope.temps.indexOf(item) !== -1; + }; - $scope.selectOrUnselect = function(item, $event) { - var indexInTemp = $scope.temps.indexOf(item); - var isRightClick = $event && $event.which == 3; + $scope.selectOrUnselect = function(item, $event) { + var indexInTemp = $scope.temps.indexOf(item); + var isRightClick = $event && $event.which == 3; - if ($event && $event.target.hasAttribute('prevent')) { + if ($event && $event.target.hasAttribute('prevent')) { + $scope.temps = []; + return; + } + if (! item || (isRightClick && $scope.isSelected(item))) { + return; + } + if ($event && $event.shiftKey && !isRightClick) { + var list = $scope.fileList; + var indexInList = list.indexOf(item); + var lastSelected = $scope.temps[0]; + var i = list.indexOf(lastSelected); + var current = undefined; + if (lastSelected && list.indexOf(lastSelected) < indexInList) { $scope.temps = []; + while (i <= indexInList) { + current = list[i]; + !$scope.isSelected(current) && $scope.temps.push(current); + i++; + } return; } - if (! item || (isRightClick && $scope.isSelected(item))) { - return; - } - if ($event && $event.shiftKey && !isRightClick) { - var list = $scope.fileList; - var indexInList = list.indexOf(item); - var lastSelected = $scope.temps[0]; - var i = list.indexOf(lastSelected); - var current = undefined; - if (lastSelected && list.indexOf(lastSelected) < indexInList) { - $scope.temps = []; - while (i <= indexInList) { - current = list[i]; - !$scope.isSelected(current) && $scope.temps.push(current); - i++; - } - return; - } - if (lastSelected && list.indexOf(lastSelected) > indexInList) { - $scope.temps = []; - while (i >= indexInList) { - current = list[i]; - !$scope.isSelected(current) && $scope.temps.push(current); - i--; - } - return; + if (lastSelected && list.indexOf(lastSelected) > indexInList) { + $scope.temps = []; + while (i >= indexInList) { + current = list[i]; + !$scope.isSelected(current) && $scope.temps.push(current); + i--; } - } - if ($event && !isRightClick && ($event.ctrlKey || $event.metaKey)) { - $scope.isSelected(item) ? $scope.temps.splice(indexInTemp, 1) : $scope.temps.push(item); return; } - $scope.temps = [item]; - }; - - $scope.singleSelection = function() { - return $scope.temps.length === 1 && $scope.temps[0]; - }; + } + if ($event && !isRightClick && ($event.ctrlKey || $event.metaKey)) { + $scope.isSelected(item) ? $scope.temps.splice(indexInTemp, 1) : $scope.temps.push(item); + return; + } + $scope.temps = [item]; + }; - $scope.totalSelecteds = function() { - return { - total: $scope.temps.length - }; - }; + $scope.singleSelection = function() { + return $scope.temps.length === 1 && $scope.temps[0]; + }; - $scope.selectionHas = function(type) { - return $scope.temps.find(function(item) { - return item && item.model.type === type; - }); + $scope.totalSelecteds = function() { + return { + total: $scope.temps.length }; + }; - $scope.prepareNewFolder = function() { - var item = new Item(null, $scope.fileNavigator.currentPath); - $scope.temps = [item]; - return item; - }; + $scope.selectionHas = function(type) { + return $scope.temps.find(function(item) { + return item && item.model.type === type; + }); + }; - $scope.smartClick = function(item) { - var pick = $scope.config.allowedActions.pickFiles; - if (item.isFolder()) { - return $scope.fileNavigator.folderClick(item); - } + $scope.prepareNewFolder = function() { + var item = new Item(null, $scope.fileNavigator.currentPath); + $scope.temps = [item]; + return item; + }; - if (typeof $scope.config.pickCallback === 'function' && pick) { - var callbackSuccess = $scope.config.pickCallback(item.model); - if (callbackSuccess === true) { - return; - } - } + $scope.smartClick = function(item) { + var pick = $scope.config.allowedActions.pickFiles; + if (item.isFolder()) { + return $scope.fileNavigator.folderClick(item); + } - if (item.isImage()) { - if ($scope.config.previewImagesInModal) { - return $scope.openImagePreview(item); - } - return $scope.apiMiddleware.download(item, true); + if (typeof $scope.config.pickCallback === 'function' && pick) { + var callbackSuccess = $scope.config.pickCallback(item.model); + if (callbackSuccess === true) { + return; } + } - if (item.isEditable()) { - return $scope.openEditItem(item); + if (item.isImage()) { + if ($scope.config.previewImagesInModal) { + return $scope.openImagePreview(item); } - }; + return $scope.apiMiddleware.download(item, true); + } - $scope.openImagePreview = function() { - var item = $scope.singleSelection(); - $scope.apiMiddleware.apiHandler.inprocess = true; - $scope.modal('imagepreview', null, true) - .find('#imagepreview-target') - .attr('src', $scope.apiMiddleware.getUrl(item)) - .unbind('load error') - .on('load error', function() { - $scope.apiMiddleware.apiHandler.inprocess = false; - $scope.$apply(); - }); - }; + if (item.isEditable()) { + return $scope.openEditItem(item); + } + }; - $scope.openEditItem = function() { - var item = $scope.singleSelection(); - $scope.apiMiddleware.getContent(item).then(function(data) { - item.tempModel.content = item.model.content = data.result; + $scope.openImagePreview = function() { + var item = $scope.singleSelection(); + $scope.apiMiddleware.apiHandler.inprocess = true; + $scope.modal('imagepreview', null, true) + .find('#imagepreview-target') + .attr('src', $scope.apiMiddleware.getUrl(item)) + .unbind('load error') + .on('load error', function() { + $scope.apiMiddleware.apiHandler.inprocess = false; + $scope.$apply(); }); - $scope.modal('edit'); - }; + }; - $scope.modal = function(id, hide, returnElement) { - var element = $('#' + id); - element.modal(hide ? 'hide' : 'show'); - $scope.apiMiddleware.apiHandler.error = ''; - $scope.apiMiddleware.apiHandler.asyncSuccess = false; - return returnElement ? element : true; - }; + $scope.openEditItem = function() { + var item = $scope.singleSelection(); + $scope.apiMiddleware.getContent(item).then(function(data) { + item.tempModel.content = item.model.content = data.result; + }); + $scope.modal('edit'); + }; - $scope.modalWithPathSelector = function(id) { - $rootScope.selectedModalPath = $scope.fileNavigator.currentPath; - return $scope.modal(id); - }; + $scope.modal = function(id, hide, returnElement) { + var element = $('#' + id); + element.modal(hide ? 'hide' : 'show'); + $scope.apiMiddleware.apiHandler.error = ''; + $scope.apiMiddleware.apiHandler.asyncSuccess = false; + return returnElement ? element : true; + }; - $scope.isInThisPath = function(path) { - var currentPath = $scope.fileNavigator.currentPath.join('/'); - return currentPath.indexOf(path) !== -1; - }; + $scope.modalWithPathSelector = function(id) { + $rootScope.selectedModalPath = $scope.fileNavigator.currentPath; + return $scope.modal(id); + }; - $scope.edit = function() { - $scope.apiMiddleware.edit($scope.singleSelection()).then(function() { - $scope.modal('edit', true); - }); + $scope.isInThisPath = function(path) { + var currentPath = $scope.fileNavigator.currentPath.join('/'); + return currentPath.indexOf(path) !== -1; + }; + + $scope.edit = function() { + $scope.apiMiddleware.edit($scope.singleSelection()).then(function() { + $scope.modal('edit', true); + }); + }; + + $scope.updatePermissions = function () { + var item = $scope.singleSelection(); + var apiUrl = fileManagerConfig.permissionsUrl; + var data = { + action: 'resolvePermissions', + path: item.model.fullPath() }; - $scope.updatePermissions = function () { - var item = $scope.singleSelection(); - var apiUrl = fileManagerConfig.permissionsUrl; - var data = { - action: 'resolvePermissions', - path: item.model.fullPath() - }; - - $http.post(apiUrl, data) - .success(function (data) { - item.model.authRead = data.auth.read; - item.model.authUpdate = data.auth.update; - item.model.authDelete = data.auth.delete; - }).error(function () { + $http.post(apiUrl, data) + .success(function (data) { + item.model.authRead = data.auth.read; + item.model.authUpdate = data.auth.update; + item.model.authDelete = data.auth.delete; + }).error(function () { $scope.apiMiddleware.apiHandler.error = $translate.instant('error_get_permissions'); })['finally'](function () { - $scope.modal('changepermissions', false); - }); - }; - $scope.changePermissions = function() { - var item = $scope.singleSelection(); - $scope.apiMiddleware.changePermissions(item.tempModel).then(function() { - $scope.modal('changepermissions', true); - }); - }; - - $scope.rename = function() { - var item = $scope.singleSelection(); - var name = item.tempModel.name; - var samePath = item.tempModel.path.join('') === item.model.path.join(''); - if (!name || (samePath && $scope.fileNavigator.fileNameExists(name))) { - $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); - return false; - } - $scope.apiMiddleware.rename(item).then(function() { - $scope.fileNavigator.refresh(); - $scope.modal('rename', true); - }); - }; + $scope.modal('changepermissions', false); + }); + }; + $scope.changePermissions = function() { + var item = $scope.singleSelection(); + $scope.apiMiddleware.changePermissions(item.tempModel).then(function() { + $scope.modal('changepermissions', true); + }); + }; - $scope.refreshLocation = function(recycle) { - $scope.fileNavigator.refresh(recycle); - }; + $scope.rename = function() { + var item = $scope.singleSelection(); + var name = item.tempModel.name; + var samePath = item.tempModel.path.join('') === item.model.path.join(''); + if (!name || (samePath && $scope.fileNavigator.fileNameExists(name))) { + $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); + return false; + } + $scope.apiMiddleware.rename(item).then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('rename', true); + }); + }; - $scope.downloadLink = function() { - var item = $scope.singleSelection(); - if ($scope.selectionHas('dir')) { - return; - } + $scope.refreshLocation = function(recycle) { + $scope.fileNavigator.refresh(recycle); + }; - var itemFullPath = item.model.fullPath(); + $scope.downloadLink = function() { + var item = $scope.singleSelection(); + if ($scope.selectionHas('dir')) { + return; + } - // generate download url - var downloadData = { - action: 'download', - path: itemFullPath - }; + var itemFullPath = item.model.fullPath(); - // generate stream url - var streamData = { - action: 'stream', - path: itemFullPath - }; + // generate download url + var downloadData = { + action: 'download', + path: itemFullPath + }; - var domain = window.location.protocol + '//' + window.location.host; - var downloadPath = [fileManagerConfig.downloadFileUrl, $.param(downloadData)].join('?'); - var streamPath = [fileManagerConfig.downloadFileUrl, $.param(streamData)].join('?'); + // generate stream url + var streamData = { + action: 'stream', + path: itemFullPath + }; - $scope.dlLink = domain + downloadPath; - $scope.streamLink = streamPath; - $scope.path = itemFullPath; + var domain = window.location.protocol + '//' + window.location.host; + var downloadPath = [fileManagerConfig.downloadFileUrl, $.param(downloadData)].join('?'); + var streamPath = [fileManagerConfig.downloadFileUrl, $.param(streamData)].join('?'); - //open modal - $scope.modal('downloadlink', false); - }; + $scope.dlLink = domain + downloadPath; + $scope.streamLink = streamPath; + $scope.path = itemFullPath; - $scope.download = function() { - var item = $scope.singleSelection(); - if ($scope.selectionHas('dir')) { - return; - } - if (item) { - return $scope.apiMiddleware.download(item); - } - return $scope.apiMiddleware.downloadMultiple($scope.temps); - }; + //open modal + $scope.modal('downloadlink', false); + }; - $scope.copy = function() { - var item = $scope.singleSelection(); - if (item) { - var name = item.tempModel.name.trim(); - var nameExists = $scope.fileNavigator.fileNameExists(name); - if (nameExists && validateSamePath(item)) { - $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); - return false; - } - if (!name) { - $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); - return false; - } - } - $scope.apiMiddleware.copy($scope.temps, $rootScope.selectedModalPath).then(function() { - $scope.fileNavigator.refresh(); - $scope.modal('copy', true); - }); - }; + $scope.download = function() { + var item = $scope.singleSelection(); + if ($scope.selectionHas('dir')) { + return; + } + if (item) { + return $scope.apiMiddleware.download(item); + } + return $scope.apiMiddleware.downloadMultiple($scope.temps); + }; - $scope.compress = function() { - var name = $scope.temp.tempModel.name.trim(); + $scope.copy = function() { + var item = $scope.singleSelection(); + if (item) { + var name = item.tempModel.name.trim(); var nameExists = $scope.fileNavigator.fileNameExists(name); - - if (nameExists && validateSamePath($scope.temp)) { + if (nameExists && validateSamePath(item)) { $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); return false; } @@ -368,172 +349,232 @@ $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); return false; } + } + $scope.apiMiddleware.copy($scope.temps, $rootScope.selectedModalPath).then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('copy', true); + }); + }; - $scope.apiMiddleware.compress($scope.temps, name, $rootScope.selectedModalPath).then(function() { - $scope.fileNavigator.refresh(); - if (! $scope.config.compressAsync) { - return $scope.modal('compress', true); - } - $scope.apiMiddleware.apiHandler.asyncSuccess = true; - }, function() { - $scope.apiMiddleware.apiHandler.asyncSuccess = false; - }); - }; + $scope.compress = function() { + var name = $scope.temp.tempModel.name.trim(); + var nameExists = $scope.fileNavigator.fileNameExists(name); - $scope.extract = function() { - var item = $scope.temp; - var name = $scope.temp.tempModel.name.trim(); - var nameExists = $scope.fileNavigator.fileNameExists(name); + if (nameExists && validateSamePath($scope.temp)) { + $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); + return false; + } + if (!name) { + $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); + return false; + } - if (nameExists && validateSamePath($scope.temp)) { - $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); - return false; - } - if (!name) { - $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); - return false; + $scope.apiMiddleware.compress($scope.temps, name, $rootScope.selectedModalPath).then(function() { + $scope.fileNavigator.refresh(); + if (! $scope.config.compressAsync) { + return $scope.modal('compress', true); } + $scope.apiMiddleware.apiHandler.asyncSuccess = true; + }, function() { + $scope.apiMiddleware.apiHandler.asyncSuccess = false; + }); + }; - $scope.apiMiddleware.extract(item, name, $rootScope.selectedModalPath).then(function() { - $scope.fileNavigator.refresh(); - if (! $scope.config.extractAsync) { - return $scope.modal('extract', true); - } - $scope.apiMiddleware.apiHandler.asyncSuccess = true; - }, function() { - $scope.apiMiddleware.apiHandler.asyncSuccess = false; - }); - }; + $scope.extract = function() { + var item = $scope.temp; + var name = $scope.temp.tempModel.name.trim(); + var nameExists = $scope.fileNavigator.fileNameExists(name); - $scope.remove = function() { - $scope.apiMiddleware.remove($scope.temps).then(function() { - $scope.fileNavigator.refresh(); - $scope.modal('remove', true); - }); - }; + if (nameExists && validateSamePath($scope.temp)) { + $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); + return false; + } + if (!name) { + $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); + return false; + } - $scope.move = function() { - var anyItem = $scope.singleSelection() || $scope.temps[0]; - if (anyItem && validateSamePath(anyItem)) { - $scope.apiMiddleware.apiHandler.error = $translate.instant('error_cannot_move_same_path'); - return false; + $scope.apiMiddleware.extract(item, name, $rootScope.selectedModalPath).then(function() { + $scope.fileNavigator.refresh(); + if (! $scope.config.extractAsync) { + return $scope.modal('extract', true); } - $scope.apiMiddleware.move($scope.temps, $rootScope.selectedModalPath).then(function() { - $scope.fileNavigator.refresh(); - $scope.modal('move', true); - }); - }; + $scope.apiMiddleware.apiHandler.asyncSuccess = true; + }, function() { + $scope.apiMiddleware.apiHandler.asyncSuccess = false; + }); + }; - $scope.createFolder = function() { - var item = $scope.singleSelection(); - var name = item.tempModel.name; - if (!name || $scope.fileNavigator.fileNameExists(name)) { - return $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); - } - $scope.apiMiddleware.createFolder(item).then(function() { - $scope.fileNavigator.refresh(); - $scope.modal('newfolder', true); - }); - }; + $scope.remove = function() { + $scope.apiMiddleware.remove($scope.temps).then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('remove', true); + }); + }; - $scope.addForUpload = function($files) { - $scope.uploadFileList = $scope.uploadFileList.concat($files); - $scope.modal('uploadfile'); - }; + $scope.move = function() { + var anyItem = $scope.singleSelection() || $scope.temps[0]; + if (anyItem && validateSamePath(anyItem)) { + $scope.apiMiddleware.apiHandler.error = $translate.instant('error_cannot_move_same_path'); + return false; + } + $scope.apiMiddleware.move($scope.temps, $rootScope.selectedModalPath).then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('move', true); + }); + }; - $scope.removeFromUpload = function(index) { - $scope.uploadFileList.splice(index, 1); - }; + $scope.createFolder = function() { + var item = $scope.singleSelection(); + var name = item.tempModel.name; + if (!name || $scope.fileNavigator.fileNameExists(name)) { + return $scope.apiMiddleware.apiHandler.error = $translate.instant('error_invalid_filename'); + } + $scope.apiMiddleware.createFolder(item).then(function() { + $scope.fileNavigator.refresh(); + $scope.modal('newfolder', true); + }); + }; - $scope.uploadFiles = function() { - $scope.apiMiddleware.upload($scope.uploadFileList, $scope.fileNavigator.currentPath).then(function() { - $scope.fileNavigator.refresh(); - $scope.uploadFileList = []; - $scope.modal('uploadfile', true); - }, function(data) { - var errorMsg = data.result && data.result.error || $translate.instant('error_uploading_files'); - $scope.apiMiddleware.apiHandler.error = errorMsg; - }); - }; + $scope.addForUpload = function($files) { + $scope.uploadFileList = $scope.uploadFileList.concat($files); + $scope.modal('uploadfile'); + }; - var validateSamePath = function(item) { - var selectedPath = $rootScope.selectedModalPath.join(''); - var selectedItemsPath = item && item.model.path.join(''); - return selectedItemsPath === selectedPath; - }; + $scope.removeFromUpload = function(index) { + $scope.uploadFileList.splice(index, 1); + }; - var getQueryParam = function(param) { - var found = $window.location.search.substr(1).split('&').filter(function(item) { - return param === item.split('=')[0]; - }); - return found[0] && found[0].split('=')[1] || undefined; - }; + $scope.uploadFiles = function() { + $scope.apiMiddleware.upload($scope.uploadFileList, $scope.fileNavigator.currentPath).then(function() { + $scope.fileNavigator.refresh(); + $scope.uploadFileList = []; + $scope.modal('uploadfile', true); + }, function(data) { + var errorMsg = data.result && data.result.error || $translate.instant('error_uploading_files'); + $scope.apiMiddleware.apiHandler.error = errorMsg; + }); + }; - $scope.changeLanguage(getQueryParam('lang')); - $scope.isWindows = getQueryParam('server') === 'Windows'; - $scope.fileNavigator.refresh(); + var validateSamePath = function(item) { + var selectedPath = $rootScope.selectedModalPath.join(''); + var selectedItemsPath = item && item.model.path.join(''); + return selectedItemsPath === selectedPath; + }; + + var getQueryParam = function(param) { + var found = $window.location.search.substr(1).split('&').filter(function(item) { + return param === item.split('=')[0]; + }); + return found[0] && found[0].split('=')[1] || undefined; + }; + + $scope.changeLanguage(getQueryParam('lang')); + $scope.isWindows = getQueryParam('server') === 'Windows'; + $scope.fileNavigator.refresh(); - }]); + }]); })(angular, jQuery); (function(angular) { 'use strict'; - angular.module('FileManagerApp').controller('ModalFileManagerCtrl', + angular.module('FileManagerApp').controller('ModalFileManagerCtrl', ['$scope', '$rootScope', 'fileNavigator', function($scope, $rootScope, FileNavigator) { - $scope.reverse = false; - $scope.predicate = ['model.type', 'model.name']; - $scope.fileNavigator = new FileNavigator(); - $rootScope.selectedModalPath = []; + $scope.reverse = false; + $scope.predicate = ['model.type', 'model.name']; + $scope.fileNavigator = new FileNavigator(); + $rootScope.selectedModalPath = []; - $scope.order = function(predicate) { - $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false; - $scope.predicate[1] = predicate; - }; + $scope.order = function(predicate) { + $scope.reverse = ($scope.predicate[1] === predicate) ? !$scope.reverse : false; + $scope.predicate[1] = predicate; + }; - $scope.select = function(item) { - $rootScope.selectedModalPath = item.model.fullPath().split('/'); - $scope.modal('selector', true); - }; + $scope.select = function(item) { + $rootScope.selectedModalPath = item.model.fullPath().split('/'); + $scope.modal('selector', true); + }; - $scope.selectCurrent = function() { - $rootScope.selectedModalPath = $scope.fileNavigator.currentPath; - $scope.modal('selector', true); - }; + $scope.selectCurrent = function() { + $rootScope.selectedModalPath = $scope.fileNavigator.currentPath; + $scope.modal('selector', true); + }; - $scope.selectedFilesAreChildOfPath = function(item) { - var path = item.model.fullPath(); - return $scope.temps.find(function(item) { - var itemPath = item.model.fullPath(); - if (path == itemPath) { - return true; - } - /* - if (path.startsWith(itemPath)) { - fixme names in same folder like folder-one and folder-one-two - at the moment fixed hidding affected folders - } - */ - }); - }; + $scope.selectedFilesAreChildOfPath = function(item) { + var path = item.model.fullPath(); + return $scope.temps.find(function(item) { + var itemPath = item.model.fullPath(); + if (path == itemPath) { + return true; + } + /* + if (path.startsWith(itemPath)) { + fixme names in same folder like folder-one and folder-one-two + at the moment fixed hidding affected folders + } + */ + }); + }; - $rootScope.openNavigator = function(path) { - $scope.fileNavigator.currentPath = path; - $scope.fileNavigator.refresh(); - $scope.modal('selector'); - }; + $rootScope.openNavigator = function(path) { + $scope.fileNavigator.currentPath = path; + $scope.fileNavigator.refresh(); + $scope.modal('selector'); + }; - $rootScope.getSelectedPath = function() { - var path = $rootScope.selectedModalPath.filter(Boolean); - var result = '/' + path.join('/'); - if ($scope.singleSelection() && !$scope.singleSelection().isFolder()) { - result += '/' + $scope.singleSelection().tempModel.name; - } - return result.replace(/\/\//, '/'); - }; + $rootScope.getSelectedPath = function() { + var path = $rootScope.selectedModalPath.filter(Boolean); + var result = '/' + path.join('/'); + if ($scope.singleSelection() && !$scope.singleSelection().isFolder()) { + result += '/' + $scope.singleSelection().tempModel.name; + } + return result.replace(/\/\//, '/'); + }; + + }]); +})(angular); +(function(angular) { + 'use strict'; + var app = angular.module('FileManagerApp'); + + app.directive('angularFilemanager', ['$parse', 'fileManagerConfig', function($parse, fileManagerConfig) { + return { + restrict: 'EA', + templateUrl: fileManagerConfig.tplPath + '/main.html' + }; + }]); + + app.directive('ngFile', ['$parse', function($parse) { + return { + restrict: 'A', + link: function(scope, element, attrs) { + var model = $parse(attrs.ngFile); + var modelSetter = model.assign; + + element.bind('change', function() { + scope.$apply(function() { + modelSetter(scope, element[0].files); + }); + }); + } + }; + }]); - }]); + app.directive('ngRightClick', ['$parse', function($parse) { + return function(scope, element, attrs) { + var fn = $parse(attrs.ngRightClick); + element.bind('contextmenu', function(event) { + scope.$apply(function() { + event.preventDefault(); + fn(scope, {$event: event}); + }); + }); + }; + }]); + })(angular); + (function(angular) { 'use strict'; angular.module('FileManagerApp').service('chmod', function () { @@ -650,6 +691,7 @@ var Item = function(model, path) { var rawModel = { name: model && model.name || '', + thumbnail: model && model.thumbnail || '', path: path || [], type: model && model.type || 'file', size: model && parseInt(model.size || 0), @@ -711,47 +753,6 @@ return Item; }]); })(angular); -(function(angular) { - 'use strict'; - var app = angular.module('FileManagerApp'); - - app.directive('angularFilemanager', ['$parse', 'fileManagerConfig', function($parse, fileManagerConfig) { - return { - restrict: 'EA', - templateUrl: fileManagerConfig.tplPath + '/main.html' - }; - }]); - - app.directive('ngFile', ['$parse', function($parse) { - return { - restrict: 'A', - link: function(scope, element, attrs) { - var model = $parse(attrs.ngFile); - var modelSetter = model.assign; - - element.bind('change', function() { - scope.$apply(function() { - modelSetter(scope, element[0].files); - }); - }); - } - }; - }]); - - app.directive('ngRightClick', ['$parse', function($parse) { - return function(scope, element, attrs) { - var fn = $parse(attrs.ngRightClick); - element.bind('contextmenu', function(event) { - scope.$apply(function() { - event.preventDefault(); - fn(scope, {$event: event}); - }); - }); - }; - }]); - -})(angular); - (function(angular) { 'use strict'; var app = angular.module('FileManagerApp'); @@ -780,22 +781,22 @@ }]); app.filter('humanReadableFileSize', ['$filter', 'fileManagerConfig', function($filter, fileManagerConfig) { - // See https://en.wikipedia.org/wiki/Binary_prefix - var decimalByteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; - var binaryByteUnits = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; - - return function(input) { - var i = -1; - var fileSizeInBytes = input; - - do { - fileSizeInBytes = fileSizeInBytes / 1024; - i++; - } while (fileSizeInBytes > 1024); - - var result = fileManagerConfig.useBinarySizePrefixes ? binaryByteUnits[i] : decimalByteUnits[i]; - return Math.max(fileSizeInBytes, 0.1).toFixed(1) + ' ' + result; - }; + // See https://en.wikipedia.org/wiki/Binary_prefix + var decimalByteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; + var binaryByteUnits = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; + + return function(input) { + var i = -1; + var fileSizeInBytes = input; + + do { + fileSizeInBytes = fileSizeInBytes / 1024; + i++; + } while (fileSizeInBytes > 1024); + + var result = fileManagerConfig.useBinarySizePrefixes ? binaryByteUnits[i] : decimalByteUnits[i]; + return Math.max(fileSizeInBytes, 0.1).toFixed(1) + ' ' + result; + }; }]); })(angular); @@ -855,6 +856,10 @@ compressAsync: false, extractAsync: false, pickCallback: null, + thumbnailUrlPrefix: '', + thumbnailUrlSuffix: '', + enableThumbnails: true, + enableIconPreviewView: false, isEditableFilePattern: /\.(txt|diff?|patch|svg|asc|cnf|cfg|conf|html?|.html|cfm|cgi|aspx?|ini|pl|py|md|css|cs|js|jsp|log|htaccess|htpasswd|gitignore|gitattributes|env|json|atom|eml|rss|markdown|sql|xml|xslt?|sh|rb|as|bat|cmd|cob|for|ftn|frm|frx|inc|lisp|scm|coffee|php[3-6]?|java|c|cbl|go|h|scala|vb|tmpl|lock|go|yml|yaml|tsv|lst)$/i, isImageFilePattern: /\.(jpe?g|gif|bmp|png|svg|tiff?)$/i, @@ -2040,683 +2045,691 @@ angular.module('FileManagerApp').service('apiHandler', ['$http', '$q', '$window', '$translate', 'Upload', function ($http, $q, $window, $translate, Upload) { - $http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; - - var ApiHandler = function() { - this.inprocess = false; - this.asyncSuccess = false; - this.error = ''; - }; - - ApiHandler.prototype.deferredHandler = function(data, deferred, code, defaultMsg) { - if (!data || typeof data !== 'object') { - this.error = 'Error %s - Bridge response error, please check the API docs or this ajax response.'.replace('%s', code); - } - if (code == 404) { - this.error = 'Error 404 - Backend bridge is not working, please check the ajax response.'; - } - if (data.result && data.result.error) { - this.error = data.result.error; - } - if (!this.error && data.error) { - this.error = data.error.message; - } - if (!this.error && defaultMsg) { - this.error = defaultMsg; - } - if (this.error) { - return deferred.reject(data); - } - return deferred.resolve(data); - }; - - ApiHandler.prototype.list = function(apiUrl, path, customDeferredHandler, recycle) { - var self = this; - var dfHandler = customDeferredHandler || self.deferredHandler; - var deferred = $q.defer(); - var data = { - action: 'list', - path: path, - recycle: recycle - }; - - self.inprocess = true; - self.error = ''; - - $http.post(apiUrl, data).success(function(data, code) { - dfHandler(data, deferred, code); - }).error(function(data, code) { - dfHandler(data, deferred, code, 'Unknown error listing, check the response'); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + $http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; - ApiHandler.prototype.copy = function(apiUrl, items, path, singleFilename) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'copy', - items: items, - newPath: path - }; - - if (singleFilename && items.length === 1) { - data.singleFilename = singleFilename; - } + var ApiHandler = function() { + this.inprocess = false; + this.asyncSuccess = false; + this.error = ''; + }; - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_copying')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + ApiHandler.prototype.deferredHandler = function(data, deferred, code, defaultMsg) { + if (!data || typeof data !== 'object') { + this.error = 'Error %s - Bridge response error, please check the API docs or this ajax response.'.replace('%s', code); + } + if (code == 404) { + this.error = 'Error 404 - Backend bridge is not working, please check the ajax response.'; + } + if (data.result && data.result.error) { + this.error = data.result.error; + } + if (!this.error && data.error) { + this.error = data.error.message; + } + if (!this.error && defaultMsg) { + this.error = defaultMsg; + } + if (this.error) { + return deferred.reject(data); + } + return deferred.resolve(data); + }; - ApiHandler.prototype.move = function(apiUrl, items, path) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'move', - items: items, - newPath: path - }; - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_moving')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + ApiHandler.prototype.list = function(apiUrl, path, customDeferredHandler, recycle) { + var self = this; + var dfHandler = customDeferredHandler || self.deferredHandler; + var deferred = $q.defer(); + var data = { + action: 'list', + path: path, + recycle: recycle + }; + + self.inprocess = true; + self.error = ''; + + $http.post(apiUrl, data).success(function(data, code) { + dfHandler(data, deferred, code); + }).error(function(data, code) { + dfHandler(data, deferred, code, 'Unknown error listing, check the response'); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - ApiHandler.prototype.remove = function(apiUrl, items) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'remove', - items: items - }; - - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_deleting')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; + ApiHandler.prototype.copy = function(apiUrl, items, path, singleFilename) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'copy', + items: items, + newPath: path }; - ApiHandler.prototype.upload = function(apiUrl, destination, files) { - var self = this; - var deferred = $q.defer(); - self.inprocess = true; - self.progress = 0; - self.error = ''; + if (singleFilename && items.length === 1) { + data.singleFilename = singleFilename; + } + + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_copying')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - var data = { - destination: destination - }; + ApiHandler.prototype.move = function(apiUrl, items, path) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'move', + items: items, + newPath: path + }; + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_moving')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - for (var i = 0; i < files.length; i++) { - data['file-' + i] = files[i]; - } + ApiHandler.prototype.remove = function(apiUrl, items) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'remove', + items: items + }; + + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_deleting')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - if (files && files.length) { - Upload.upload({ - url: apiUrl, - data: data - }).then(function (data) { - self.deferredHandler(data.data, deferred, data.status); - }, function (data) { - self.deferredHandler(data.data, deferred, data.status, 'Unknown error uploading files'); - }, function (evt) { - self.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)) - 1; - })['finally'](function() { - self.inprocess = false; - self.progress = 0; - }); - } + ApiHandler.prototype.upload = function(apiUrl, destination, files) { + var self = this; + var deferred = $q.defer(); + self.inprocess = true; + self.progress = 0; + self.error = ''; - return deferred.promise; + var data = { + destination: destination }; - ApiHandler.prototype.getContent = function(apiUrl, itemPath) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'getContent', - item: itemPath - }; - - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_getting_content')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + for (var i = 0; i < files.length; i++) { + data['file-' + i] = files[i]; + } - ApiHandler.prototype.edit = function(apiUrl, itemPath, content) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'edit', - item: itemPath, - content: content - }; - - self.inprocess = true; - self.error = ''; - - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_modifying')); + if (files && files.length) { + Upload.upload({ + url: apiUrl, + data: data + }).then(function (data) { + self.deferredHandler(data.data, deferred, data.status); + }, function (data) { + self.deferredHandler(data.data, deferred, data.status, 'Unknown error uploading files'); + }, function (evt) { + self.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)) - 1; })['finally'](function() { self.inprocess = false; + self.progress = 0; }); - return deferred.promise; - }; + } - ApiHandler.prototype.rename = function(apiUrl, itemPath, newPath) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'rename', - item: itemPath, - newItemPath: newPath - }; - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_renaming')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + return deferred.promise; + }; - ApiHandler.prototype.getUrl = function(apiUrl, path) { - var data = { - action: 'download', - path: path - }; - return path && [apiUrl, $.param(data)].join('?'); + ApiHandler.prototype.getContent = function(apiUrl, itemPath) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'getContent', + item: itemPath + }; + + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_getting_content')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + ApiHandler.prototype.edit = function(apiUrl, itemPath, content) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'edit', + item: itemPath, + content: content }; - ApiHandler.prototype.download = function(apiUrl, itemPath, toFilename, downloadByAjax, forceNewWindow) { - var self = this; - var url = this.getUrl(apiUrl, itemPath); + self.inprocess = true; + self.error = ''; - if (!downloadByAjax || forceNewWindow || !$window.saveAs) { - !$window.saveAs && $window.console.log('Your browser dont support ajax download, downloading by default'); - return !!$window.open(url, '_blank', ''); - } + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_modifying')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - var deferred = $q.defer(); - self.inprocess = true; - $http.get(url).success(function(data) { - var bin = new $window.Blob([data]); - deferred.resolve(data); - $window.saveAs(bin, toFilename); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_downloading')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; + ApiHandler.prototype.rename = function(apiUrl, itemPath, newPath) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'rename', + item: itemPath, + newItemPath: newPath + }; + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_renaming')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + ApiHandler.prototype.getUrl = function(apiUrl, path) { + var data = { + action: 'download', + path: path }; + return path && [apiUrl, $.param(data)].join('?'); + }; - ApiHandler.prototype.downloadMultiple = function(apiUrl, items, toFilename, downloadByAjax, forceNewWindow) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'downloadMultiple', - items: items, - toFilename: toFilename - }; - var url = [apiUrl, $.param(data)].join('?'); - - if (!downloadByAjax || forceNewWindow || !$window.saveAs) { - !$window.saveAs && $window.console.log('Your browser dont support ajax download, downloading by default'); - return !!$window.open(url, '_blank', ''); - } + ApiHandler.prototype.download = function(apiUrl, itemPath, toFilename, downloadByAjax, forceNewWindow) { + var self = this; + var url = this.getUrl(apiUrl, itemPath); - self.inprocess = true; - $http.get(apiUrl).success(function(data) { - var bin = new $window.Blob([data]); - deferred.resolve(data); - $window.saveAs(bin, toFilename); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_downloading')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + if (!downloadByAjax || forceNewWindow || !$window.saveAs) { + !$window.saveAs && $window.console.log('Your browser dont support ajax download, downloading by default'); + return !!$window.open(url, '_blank', ''); + } + + var deferred = $q.defer(); + self.inprocess = true; + $http.get(url).success(function(data) { + var bin = new $window.Blob([data]); + deferred.resolve(data); + $window.saveAs(bin, toFilename); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_downloading')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - ApiHandler.prototype.compress = function(apiUrl, items, compressedFilename, path) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'compress', - items: items, - destination: path, - compressedFilename: compressedFilename - }; - - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_compressing')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; + ApiHandler.prototype.downloadMultiple = function(apiUrl, items, toFilename, downloadByAjax, forceNewWindow) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'downloadMultiple', + items: items, + toFilename: toFilename }; + var url = [apiUrl, $.param(data)].join('?'); - ApiHandler.prototype.extract = function(apiUrl, item, folderName, path) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'extract', - item: item, - destination: path, - folderName: folderName - }; - - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_extracting')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + if (!downloadByAjax || forceNewWindow || !$window.saveAs) { + !$window.saveAs && $window.console.log('Your browser dont support ajax download, downloading by default'); + return !!$window.open(url, '_blank', ''); + } + + self.inprocess = true; + $http.get(apiUrl).success(function(data) { + var bin = new $window.Blob([data]); + deferred.resolve(data); + $window.saveAs(bin, toFilename); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_downloading')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; + + ApiHandler.prototype.compress = function(apiUrl, items, compressedFilename, path) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'compress', + items: items, + destination: path, + compressedFilename: compressedFilename + }; + + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_compressing')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - ApiHandler.prototype.changePermissions = function(apiUrl, item) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'changePermissions', - path: item.fullPath(), - item: item - }; - - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_changing_perms')); - })['finally'](function() { - self.inprocess = false; - }); - return deferred.promise; - }; + ApiHandler.prototype.extract = function(apiUrl, item, folderName, path) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'extract', + item: item, + destination: path, + folderName: folderName + }; + + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_extracting')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - ApiHandler.prototype.createFolder = function(apiUrl, path) { - var self = this; - var deferred = $q.defer(); - var data = { - action: 'createFolder', - newPath: path - }; - - self.inprocess = true; - self.error = ''; - $http.post(apiUrl, data).success(function(data, code) { - self.deferredHandler(data, deferred, code); - }).error(function(data, code) { - self.deferredHandler(data, deferred, code, $translate.instant('error_creating_folder')); - })['finally'](function() { - self.inprocess = false; - }); + ApiHandler.prototype.changePermissions = function(apiUrl, item) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'changePermissions', + path: item.fullPath(), + item: item + }; + + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_changing_perms')); + })['finally'](function() { + self.inprocess = false; + }); + return deferred.promise; + }; - return deferred.promise; - }; + ApiHandler.prototype.createFolder = function(apiUrl, path) { + var self = this; + var deferred = $q.defer(); + var data = { + action: 'createFolder', + newPath: path + }; + + self.inprocess = true; + self.error = ''; + $http.post(apiUrl, data).success(function(data, code) { + self.deferredHandler(data, deferred, code); + }).error(function(data, code) { + self.deferredHandler(data, deferred, code, $translate.instant('error_creating_folder')); + })['finally'](function() { + self.inprocess = false; + }); + + return deferred.promise; + }; - ApiHandler.prototype.slug = function(str) { - var trimmed = $.trim(str); - var $slug = trimmed.replace(/[^a-z0-9-]/gi, '-'). + ApiHandler.prototype.slug = function(str) { + var trimmed = $.trim(str); + var $slug = trimmed.replace(/[^a-z0-9-]/gi, '-'). replace(/-+/g, '-'). replace(/^-|-$/g, ''); - return $slug.toLowerCase(); - }; + return $slug.toLowerCase(); + }; - return ApiHandler; + return ApiHandler; - }]); + }]); })(angular, jQuery); (function(angular) { 'use strict'; - angular.module('FileManagerApp').service('apiMiddleware', ['$window', 'fileManagerConfig', 'apiHandler', + angular.module('FileManagerApp').service('apiMiddleware', ['$window', 'fileManagerConfig', 'apiHandler', function ($window, fileManagerConfig, ApiHandler) { - var ApiMiddleware = function() { - this.apiHandler = new ApiHandler(); - }; + var ApiMiddleware = function() { + this.apiHandler = new ApiHandler(); + }; - ApiMiddleware.prototype.getPath = function(arrayPath) { - return '/' + arrayPath.join('/'); - }; + ApiMiddleware.prototype.getPath = function(arrayPath) { + return '/' + arrayPath.join('/'); + }; - ApiMiddleware.prototype.getFileList = function(files) { - return (files || []).map(function(file) { - return file && file.model.fullPath(); - }); - }; + ApiMiddleware.prototype.getFileList = function(files) { + return (files || []).map(function(file) { + return file && file.model.fullPath(); + }); + }; - ApiMiddleware.prototype.getFilePath = function(item) { - return item && item.model.fullPath(); - }; + ApiMiddleware.prototype.getFilePath = function(item) { + return item && item.model.fullPath(); + }; - ApiMiddleware.prototype.list = function(path, customDeferredHandler, recycle) { - return this.apiHandler.list(fileManagerConfig.listUrl, this.getPath(path), customDeferredHandler, recycle); - }; + ApiMiddleware.prototype.list = function(path, customDeferredHandler, recycle) { + return this.apiHandler.list(fileManagerConfig.listUrl, this.getPath(path), customDeferredHandler, recycle); + }; - ApiMiddleware.prototype.copy = function(files, path) { - var items = this.getFileList(files); - var singleFilename = items.length === 1 ? files[0].tempModel.name : undefined; - return this.apiHandler.copy(fileManagerConfig.copyUrl, items, this.getPath(path), singleFilename); - }; + ApiMiddleware.prototype.copy = function(files, path) { + var items = this.getFileList(files); + var singleFilename = items.length === 1 ? files[0].tempModel.name : undefined; + return this.apiHandler.copy(fileManagerConfig.copyUrl, items, this.getPath(path), singleFilename); + }; - ApiMiddleware.prototype.move = function(files, path) { - var items = this.getFileList(files); - return this.apiHandler.move(fileManagerConfig.moveUrl, items, this.getPath(path)); - }; + ApiMiddleware.prototype.move = function(files, path) { + var items = this.getFileList(files); + return this.apiHandler.move(fileManagerConfig.moveUrl, items, this.getPath(path)); + }; - ApiMiddleware.prototype.remove = function(files) { - var items = this.getFileList(files); - return this.apiHandler.remove(fileManagerConfig.removeUrl, items); - }; + ApiMiddleware.prototype.remove = function(files) { + var items = this.getFileList(files); + return this.apiHandler.remove(fileManagerConfig.removeUrl, items); + }; - ApiMiddleware.prototype.upload = function(files, path) { - if (! $window.FormData) { - throw new Error('Unsupported browser version'); - } + ApiMiddleware.prototype.upload = function(files, path) { + if (! $window.FormData) { + throw new Error('Unsupported browser version'); + } - var destination = this.getPath(path); + var destination = this.getPath(path); - return this.apiHandler.upload(fileManagerConfig.uploadUrl, destination, files); - }; + return this.apiHandler.upload(fileManagerConfig.uploadUrl, destination, files); + }; - ApiMiddleware.prototype.getContent = function(item) { - var itemPath = this.getFilePath(item); - return this.apiHandler.getContent(fileManagerConfig.getContentUrl, itemPath); - }; + ApiMiddleware.prototype.getContent = function(item) { + var itemPath = this.getFilePath(item); + return this.apiHandler.getContent(fileManagerConfig.getContentUrl, itemPath); + }; - ApiMiddleware.prototype.edit = function(item) { - var itemPath = this.getFilePath(item); - return this.apiHandler.edit(fileManagerConfig.editUrl, itemPath, item.tempModel.content); - }; + ApiMiddleware.prototype.edit = function(item) { + var itemPath = this.getFilePath(item); + return this.apiHandler.edit(fileManagerConfig.editUrl, itemPath, item.tempModel.content); + }; - ApiMiddleware.prototype.rename = function(item) { - var itemPath = this.getFilePath(item); - var newPath = item.tempModel.fullPath(); - return this.apiHandler.rename(fileManagerConfig.renameUrl, itemPath, newPath); - }; + ApiMiddleware.prototype.rename = function(item) { + var itemPath = this.getFilePath(item); + var newPath = item.tempModel.fullPath(); + return this.apiHandler.rename(fileManagerConfig.renameUrl, itemPath, newPath); + }; - ApiMiddleware.prototype.getUrl = function(item) { - var itemPath = this.getFilePath(item); - return this.apiHandler.getUrl(fileManagerConfig.downloadFileUrl, itemPath); - }; + ApiMiddleware.prototype.getUrl = function(item) { + var itemPath = this.getFilePath(item); + return this.apiHandler.getUrl(fileManagerConfig.downloadFileUrl, itemPath); + }; - ApiMiddleware.prototype.getThumbnailUrl = function(item) { - var itemPath = this.getFilePath(item); - return fileManagerConfig.thumbnailUrlPrefix + this.apiHandler.getUrl(fileManagerConfig.downloadFileUrl, itemPath) + fileManagerConfig.thumbnailUrlSuffix; - }; + ApiMiddleware.prototype.getThumbnailUrl = function(item) { + var itemPath = this.getFilePath(item); + return fileManagerConfig.thumbnailUrlPrefix + this.apiHandler.getUrl(fileManagerConfig.downloadFileUrl, itemPath) + fileManagerConfig.thumbnailUrlSuffix; + }; - ApiMiddleware.prototype.download = function(item, forceNewWindow) { - var itemPath = this.getFilePath(item); - var toFilename = item.model.name; + ApiMiddleware.prototype.enableThumbnails = function () { + return fileManagerConfig.enableThumbnails; + }; + + ApiMiddleware.prototype.enableIconPreviewView = function () { + return fileManagerConfig.enableIconPreviewView; + }; - if (item.isFolder()) { - return; - } + ApiMiddleware.prototype.download = function(item, forceNewWindow) { + var itemPath = this.getFilePath(item); + var toFilename = item.model.name; - return this.apiHandler.download( - fileManagerConfig.downloadFileUrl, - itemPath, - toFilename, - fileManagerConfig.downloadFilesByAjax, - forceNewWindow - ); - }; + if (item.isFolder()) { + return; + } + + return this.apiHandler.download( + fileManagerConfig.downloadFileUrl, + itemPath, + toFilename, + fileManagerConfig.downloadFilesByAjax, + forceNewWindow + ); + }; - ApiMiddleware.prototype.downloadMultiple = function(files, forceNewWindow) { - var items = this.getFileList(files); - var timestamp = new Date().getTime().toString().substr(8, 13); - var toFilename = timestamp + '-' + fileManagerConfig.multipleDownloadFileName; - - return this.apiHandler.downloadMultiple( - fileManagerConfig.downloadMultipleUrl, - items, - toFilename, - fileManagerConfig.downloadFilesByAjax, - forceNewWindow - ); - }; + ApiMiddleware.prototype.downloadMultiple = function(files, forceNewWindow) { + var items = this.getFileList(files); + var timestamp = new Date().getTime().toString().substr(8, 13); + var toFilename = timestamp + '-' + fileManagerConfig.multipleDownloadFileName; + + return this.apiHandler.downloadMultiple( + fileManagerConfig.downloadMultipleUrl, + items, + toFilename, + fileManagerConfig.downloadFilesByAjax, + forceNewWindow + ); + }; - ApiMiddleware.prototype.compress = function(files, compressedFilename, path) { - var items = this.getFileList(files); - return this.apiHandler.compress(fileManagerConfig.compressUrl, items, compressedFilename, this.getPath(path)); - }; + ApiMiddleware.prototype.compress = function(files, compressedFilename, path) { + var items = this.getFileList(files); + return this.apiHandler.compress(fileManagerConfig.compressUrl, items, compressedFilename, this.getPath(path)); + }; - ApiMiddleware.prototype.extract = function(item, folderName, path) { - var itemPath = this.getFilePath(item); - return this.apiHandler.extract(fileManagerConfig.extractUrl, itemPath, folderName, this.getPath(path)); - }; + ApiMiddleware.prototype.extract = function(item, folderName, path) { + var itemPath = this.getFilePath(item); + return this.apiHandler.extract(fileManagerConfig.extractUrl, itemPath, folderName, this.getPath(path)); + }; - ApiMiddleware.prototype.changePermissions = function(item) { - return this.apiHandler.changePermissions(fileManagerConfig.permissionsUrl, item); - }; + ApiMiddleware.prototype.changePermissions = function(item) { + return this.apiHandler.changePermissions(fileManagerConfig.permissionsUrl, item); + }; - ApiMiddleware.prototype.createFolder = function(item) { - item.tempModel.name = this.apiHandler.slug(item.tempModel.name); - var path = item.tempModel.fullPath(); - return this.apiHandler.createFolder(fileManagerConfig.createFolderUrl, path); - }; + ApiMiddleware.prototype.createFolder = function(item) { + item.tempModel.name = this.apiHandler.slug(item.tempModel.name); + var path = item.tempModel.fullPath(); + return this.apiHandler.createFolder(fileManagerConfig.createFolderUrl, path); + }; - return ApiMiddleware; + return ApiMiddleware; - }]); + }]); })(angular); (function(angular) { 'use strict'; angular.module('FileManagerApp').service('fileNavigator', [ 'apiMiddleware', 'fileManagerConfig', 'item', function (ApiMiddleware, fileManagerConfig, Item) { - var FileNavigator = function() { - this.apiMiddleware = new ApiMiddleware(); - this.requesting = false; - this.fileList = []; - this.currentPath = []; - this.history = []; - this.error = ''; + var FileNavigator = function() { + this.apiMiddleware = new ApiMiddleware(); + this.requesting = false; + this.fileList = []; + this.currentPath = []; + this.history = []; + this.error = ''; - this.onRefresh = function() {}; - }; + this.onRefresh = function() {}; + }; - FileNavigator.prototype.deferredHandler = function(data, deferred, code, defaultMsg) { - if (!data || typeof data !== 'object') { - this.error = 'Error %s - Bridge response error, please check the API docs or this ajax response.'.replace('%s', code); - } - if (code == 404) { - this.error = 'Error 404 - Backend bridge is not working, please check the ajax response.'; - } - if (!this.error && data.result && data.result.error) { - this.error = data.result.error; - } - if (!this.error && data.error) { - this.error = data.error.message; - } - if (!this.error && defaultMsg) { - this.error = defaultMsg; - } - if (this.error) { - return deferred.reject(data); - } - return deferred.resolve(data); - }; + FileNavigator.prototype.deferredHandler = function(data, deferred, code, defaultMsg) { + if (!data || typeof data !== 'object') { + this.error = 'Error %s - Bridge response error, please check the API docs or this ajax response.'.replace('%s', code); + } + if (code == 404) { + this.error = 'Error 404 - Backend bridge is not working, please check the ajax response.'; + } + if (!this.error && data.result && data.result.error) { + this.error = data.result.error; + } + if (!this.error && data.error) { + this.error = data.error.message; + } + if (!this.error && defaultMsg) { + this.error = defaultMsg; + } + if (this.error) { + return deferred.reject(data); + } + return deferred.resolve(data); + }; - FileNavigator.prototype.list = function(recycle) { - return this.apiMiddleware.list(this.currentPath, this.deferredHandler.bind(this), recycle); - }; + FileNavigator.prototype.list = function(recycle) { + return this.apiMiddleware.list(this.currentPath, this.deferredHandler.bind(this), recycle); + }; - FileNavigator.prototype.refresh = function(recycle) { - var self = this; - var path = self.currentPath.join('/'); - self.requesting = true; - self.fileList = []; - return self.list(recycle).then(function(data) { - self.fileList = (data.result || []).map(function(file) { - return new Item(file, self.currentPath); - }); - self.buildTree(path); - self.onRefresh(); - }).finally(function() { - self.requesting = false; + FileNavigator.prototype.refresh = function(recycle) { + var self = this; + var path = self.currentPath.join('/'); + self.requesting = true; + self.fileList = []; + return self.list(recycle).then(function(data) { + self.fileList = (data.result || []).map(function (file) { + return new Item(file, self.currentPath); }); - }; - - FileNavigator.prototype.buildTree = function(path) { - var flatNodes = [], selectedNode = {}; - - function recursive(parent, item, path) { - var absName = path ? (path + '/' + item.model.name) : item.model.name; - if (parent.name.trim() && path.trim().indexOf(parent.name) !== 0) { - parent.nodes = []; - } - if (parent.name !== path) { - parent.nodes.forEach(function(nd) { - recursive(nd, item, path); - }); - } else { - for (var e in parent.nodes) { - if (parent.nodes[e].name === absName) { - return; - } - } - parent.nodes.push({item: item, name: absName, nodes: []}); - } - - parent.nodes = parent.nodes.sort(function(a, b) { - return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : a.name.toLowerCase() === b.name.toLowerCase() ? 0 : 1; + self.buildTree(path); + self.onRefresh(); + }).finally(function() { + self.requesting = false; + }); + }; + + FileNavigator.prototype.buildTree = function(path) { + var flatNodes = [], selectedNode = {}; + + function recursive(parent, item, path) { + var absName = path ? (path + '/' + item.model.name) : item.model.name; + if (parent.name.trim() && path.trim().indexOf(parent.name) !== 0) { + parent.nodes = []; + } + if (parent.name !== path) { + parent.nodes.forEach(function(nd) { + recursive(nd, item, path); }); - } - - function flatten(node, array) { - array.push(node); - for (var n in node.nodes) { - flatten(node.nodes[n], array); + } else { + for (var e in parent.nodes) { + if (parent.nodes[e].name === absName) { + return; + } } + parent.nodes.push({item: item, name: absName, nodes: []}); } + + parent.nodes = parent.nodes.sort(function(a, b) { + return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : a.name.toLowerCase() === b.name.toLowerCase() ? 0 : 1; + }); + } - function findNode(data, path) { - return data.filter(function (n) { - return n.name === path; - })[0]; + function flatten(node, array) { + array.push(node); + for (var n in node.nodes) { + flatten(node.nodes[n], array); } + } - !this.history.length && this.history.push({name: '', nodes: []}); - flatten(this.history[0], flatNodes); - selectedNode = findNode(flatNodes, path); - selectedNode && (selectedNode.nodes = []); + function findNode(data, path) { + return data.filter(function (n) { + return n.name === path; + })[0]; + } - for (var o in this.fileList) { - var item = this.fileList[o]; - item instanceof Item && item.isFolder() && recursive(this.history[0], item, path); - } - }; + !this.history.length && this.history.push({name: '', nodes: []}); + flatten(this.history[0], flatNodes); + selectedNode = findNode(flatNodes, path); + selectedNode && (selectedNode.nodes = []); - FileNavigator.prototype.folderClick = function(item) { - this.currentPath = []; - if (item && item.isFolder()) { - this.currentPath = item.model.fullPath().split('/').splice(1); - } - this.refresh(); - }; + for (var o in this.fileList) { + var item = this.fileList[o]; + item instanceof Item && item.isFolder() && recursive(this.history[0], item, path); + } + }; - FileNavigator.prototype.upDir = function() { - if (this.currentPath[0]) { - this.currentPath = this.currentPath.slice(0, -1); - this.refresh(); - } - }; + FileNavigator.prototype.folderClick = function(item) { + this.currentPath = []; + if (item && item.isFolder()) { + this.currentPath = item.model.fullPath().split('/').splice(1); + } + this.refresh(); + }; - FileNavigator.prototype.goTo = function(index) { - this.currentPath = this.currentPath.slice(0, index + 1); + FileNavigator.prototype.upDir = function() { + if (this.currentPath[0]) { + this.currentPath = this.currentPath.slice(0, -1); this.refresh(); - }; + } + }; - FileNavigator.prototype.fileNameExists = function(fileName) { - return this.fileList.find(function(item) { - return fileName.trim && item.model.name.trim() === fileName.trim(); - }); - }; + FileNavigator.prototype.goTo = function(index) { + this.currentPath = this.currentPath.slice(0, index + 1); + this.refresh(); + }; - FileNavigator.prototype.listHasFolders = function() { - return this.fileList.find(function(item) { - return item.model.type === 'dir'; - }); - }; + FileNavigator.prototype.fileNameExists = function(fileName) { + return this.fileList.find(function(item) { + return fileName.trim && item.model.name.trim() === fileName.trim(); + }); + }; + + FileNavigator.prototype.listHasFolders = function() { + return this.fileList.find(function(item) { + return item.model.type === 'dir'; + }); + }; - return FileNavigator; - }]); + return FileNavigator; + }]); })(angular); -/* +/* * Angular JS Multi Select - * Creates a dropdown-like button with checkboxes. + * Creates a dropdown-like button with checkboxes. * * Project started on: Tue, 14 Jan 2014 - 5:18:02 PM * Current version: 4.0.0 - * + * * Released under the MIT License * -------------------------------------------------------------------------------- * The MIT License (MIT) * * Copyright (c) 2014 Ignatius Steven (https://github.com/isteven) * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all + * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * -------------------------------------------------------------------------------- */ @@ -2725,52 +2738,52 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' , [ '$sce', '$timeout', '$templateCache', function ( $sce, $timeout, $templateCache ) { return { - restrict: + restrict: 'AE', - scope: - { - // models - inputModel : '=', - outputModel : '=', - - // settings based on attribute - isDisabled : '=', - - // callbacks - onClear : '&', - onClose : '&', - onSearchChange : '&', - onItemClick : '&', - onOpen : '&', - onReset : '&', - onSelectAll : '&', - onSelectNone : '&', - - // i18n - translation : '=' - }, - - /* + scope: + { + // models + inputModel : '=', + outputModel : '=', + + // settings based on attribute + isDisabled : '=', + + // callbacks + onClear : '&', + onClose : '&', + onSearchChange : '&', + onItemClick : '&', + onOpen : '&', + onReset : '&', + onSelectAll : '&', + onSelectNone : '&', + + // i18n + translation : '=' + }, + + /* * The rest are attributes. They don't need to be parsed / binded, so we can safely access them by value. * - buttonLabel, directiveId, helperElements, itemLabel, maxLabels, orientation, selectionMode, minSearchLength, * tickProperty, disableProperty, groupProperty, searchProperty, maxHeight, outputProperties */ + + templateUrl: + 'isteven-multi-select.htm', - templateUrl: - 'isteven-multi-select.htm', - - link: function ( $scope, element, attrs ) { + link: function ( $scope, element, attrs ) { $scope.backUp = []; - $scope.varButtonLabel = ''; + $scope.varButtonLabel = ''; $scope.spacingProperty = ''; - $scope.indexProperty = ''; + $scope.indexProperty = ''; $scope.orientationH = false; $scope.orientationV = true; $scope.filteredModel = []; - $scope.inputLabel = { labelFilter: '' }; - $scope.tabIndex = 0; + $scope.inputLabel = { labelFilter: '' }; + $scope.tabIndex = 0; $scope.lang = {}; $scope.helperStatus = { all : true, @@ -2779,7 +2792,7 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' filter : true }; - var + var prevTabIndex = 0, helperItems = [], helperItemsLength = 0, @@ -2788,38 +2801,38 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' selectedItems = [], formElements = [], vMinSearchLength = 0, - clickedItem = null + clickedItem = null // v3.0.0 // clear button clicked - $scope.clearClicked = function( e ) { + $scope.clearClicked = function( e ) { $scope.inputLabel.labelFilter = ''; $scope.updateFilter(); - $scope.select( 'clear', e ); + $scope.select( 'clear', e ); } // A little hack so that AngularJS ng-repeat can loop using start and end index like a normal loop // http://stackoverflow.com/questions/16824853/way-to-ng-repeat-defined-number-of-times-instead-of-repeating-over-array $scope.numberToArray = function( num ) { - return new Array( num ); + return new Array( num ); } // Call this function when user type on the filter field - $scope.searchChanged = function() { + $scope.searchChanged = function() { if ( $scope.inputLabel.labelFilter.length < vMinSearchLength && $scope.inputLabel.labelFilter.length > 0 ) { return false; - } + } $scope.updateFilter(); } $scope.updateFilter = function() - { + { // we check by looping from end of input-model $scope.filteredModel = []; var i = 0; if ( typeof $scope.inputModel === 'undefined' ) { - return false; + return false; } for( i = $scope.inputModel.length - 1; i >= 0; i-- ) { @@ -2828,39 +2841,39 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' if ( typeof $scope.inputModel[ i ][ attrs.groupProperty ] !== 'undefined' && $scope.inputModel[ i ][ attrs.groupProperty ] === false ) { $scope.filteredModel.push( $scope.inputModel[ i ] ); } - - // if it's data + + // if it's data var gotData = false; - if ( typeof $scope.inputModel[ i ][ attrs.groupProperty ] === 'undefined' ) { - - // If we set the search-key attribute, we use this loop. + if ( typeof $scope.inputModel[ i ][ attrs.groupProperty ] === 'undefined' ) { + + // If we set the search-key attribute, we use this loop. if ( typeof attrs.searchProperty !== 'undefined' && attrs.searchProperty !== '' ) { for (var key in $scope.inputModel[ i ] ) { - if ( + if ( typeof $scope.inputModel[ i ][ key ] !== 'boolean' - && String( $scope.inputModel[ i ][ key ] ).toUpperCase().indexOf( $scope.inputLabel.labelFilter.toUpperCase() ) >= 0 + && String( $scope.inputModel[ i ][ key ] ).toUpperCase().indexOf( $scope.inputLabel.labelFilter.toUpperCase() ) >= 0 && attrs.searchProperty.indexOf( key ) > -1 ) { gotData = true; break; } - } + } } // if there's no search-key attribute, we use this one. Much better on performance. else { for ( var key in $scope.inputModel[ i ] ) { - if ( + if ( typeof $scope.inputModel[ i ][ key ] !== 'boolean' - && String( $scope.inputModel[ i ][ key ] ).toUpperCase().indexOf( $scope.inputLabel.labelFilter.toUpperCase() ) >= 0 + && String( $scope.inputModel[ i ][ key ] ).toUpperCase().indexOf( $scope.inputLabel.labelFilter.toUpperCase() ) >= 0 ) { gotData = true; break; } - } + } } - if ( gotData === true ) { + if ( gotData === true ) { // push $scope.filteredModel.push( $scope.inputModel[ i ] ); } @@ -2869,79 +2882,79 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' // if it's group start if ( typeof $scope.inputModel[ i ][ attrs.groupProperty ] !== 'undefined' && $scope.inputModel[ i ][ attrs.groupProperty ] === true ) { - if ( typeof $scope.filteredModel[ $scope.filteredModel.length - 1 ][ attrs.groupProperty ] !== 'undefined' - && $scope.filteredModel[ $scope.filteredModel.length - 1 ][ attrs.groupProperty ] === false ) { + if ( typeof $scope.filteredModel[ $scope.filteredModel.length - 1 ][ attrs.groupProperty ] !== 'undefined' + && $scope.filteredModel[ $scope.filteredModel.length - 1 ][ attrs.groupProperty ] === false ) { $scope.filteredModel.pop(); } else { $scope.filteredModel.push( $scope.inputModel[ i ] ); } } - } - - $scope.filteredModel.reverse(); - - $timeout( function() { + } - $scope.getFormElements(); + $scope.filteredModel.reverse(); + + $timeout( function() { - // Callback: on filter change + $scope.getFormElements(); + + // Callback: on filter change if ( $scope.inputLabel.labelFilter.length > vMinSearchLength ) { var filterObj = []; angular.forEach( $scope.filteredModel, function( value, key ) { - if ( typeof value !== 'undefined' ) { - if ( typeof value[ attrs.groupProperty ] === 'undefined' ) { + if ( typeof value !== 'undefined' ) { + if ( typeof value[ attrs.groupProperty ] === 'undefined' ) { var tempObj = angular.copy( value ); - var index = filterObj.push( tempObj ); + var index = filterObj.push( tempObj ); delete filterObj[ index - 1 ][ $scope.indexProperty ]; - delete filterObj[ index - 1 ][ $scope.spacingProperty ]; + delete filterObj[ index - 1 ][ $scope.spacingProperty ]; } } }); - $scope.onSearchChange({ - data: - { - keyword: $scope.inputLabel.labelFilter, - result: filterObj - } + $scope.onSearchChange({ + data: + { + keyword: $scope.inputLabel.labelFilter, + result: filterObj + } }); } },0); }; // List all the input elements. We need this for our keyboard navigation. - // This function will be called everytime the filter is updated. + // This function will be called everytime the filter is updated. // Depending on the size of filtered mode, might not good for performance, but oh well.. - $scope.getFormElements = function() { + $scope.getFormElements = function() { formElements = []; - var + var selectButtons = [], inputField = [], checkboxes = [], clearButton = []; - + // If available, then get select all, select none, and reset buttons - if ( $scope.helperStatus.all || $scope.helperStatus.none || $scope.helperStatus.reset ) { - selectButtons = element.children().children().next().children().children()[ 0 ].getElementsByTagName( 'button' ); + if ( $scope.helperStatus.all || $scope.helperStatus.none || $scope.helperStatus.reset ) { + selectButtons = element.children().children().next().children().children()[ 0 ].getElementsByTagName( 'button' ); // If available, then get the search box and the clear button - if ( $scope.helperStatus.filter ) { - // Get helper - search and clear button. - inputField = element.children().children().next().children().children().next()[ 0 ].getElementsByTagName( 'input' ); - clearButton = element.children().children().next().children().children().next()[ 0 ].getElementsByTagName( 'button' ); + if ( $scope.helperStatus.filter ) { + // Get helper - search and clear button. + inputField = element.children().children().next().children().children().next()[ 0 ].getElementsByTagName( 'input' ); + clearButton = element.children().children().next().children().children().next()[ 0 ].getElementsByTagName( 'button' ); } } else { - if ( $scope.helperStatus.filter ) { - // Get helper - search and clear button. - inputField = element.children().children().next().children().children()[ 0 ].getElementsByTagName( 'input' ); + if ( $scope.helperStatus.filter ) { + // Get helper - search and clear button. + inputField = element.children().children().next().children().children()[ 0 ].getElementsByTagName( 'input' ); clearButton = element.children().children().next().children().children()[ 0 ].getElementsByTagName( 'button' ); } } - + // Get checkboxes if ( !$scope.helperStatus.all && !$scope.helperStatus.none && !$scope.helperStatus.reset && !$scope.helperStatus.filter ) { checkboxes = element.children().children().next()[ 0 ].getElementsByTagName( 'input' ); @@ -2950,58 +2963,58 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' checkboxes = element.children().children().next().children().next()[ 0 ].getElementsByTagName( 'input' ); } - // Push them into global array formElements[] + // Push them into global array formElements[] for ( var i = 0; i < selectButtons.length ; i++ ) { formElements.push( selectButtons[ i ] ); } for ( var i = 0; i < inputField.length ; i++ ) { formElements.push( inputField[ i ] ); } for ( var i = 0; i < clearButton.length ; i++ ) { formElements.push( clearButton[ i ] ); } - for ( var i = 0; i < checkboxes.length ; i++ ) { formElements.push( checkboxes[ i ] ); } - } + for ( var i = 0; i < checkboxes.length ; i++ ) { formElements.push( checkboxes[ i ] ); } + } // check if an item has attrs.groupProperty (be it true or false) $scope.isGroupMarker = function( item , type ) { - if ( typeof item[ attrs.groupProperty ] !== 'undefined' && item[ attrs.groupProperty ] === type ) return true; + if ( typeof item[ attrs.groupProperty ] !== 'undefined' && item[ attrs.groupProperty ] === type ) return true; return false; } $scope.removeGroupEndMarker = function( item ) { - if ( typeof item[ attrs.groupProperty ] !== 'undefined' && item[ attrs.groupProperty ] === false ) return false; + if ( typeof item[ attrs.groupProperty ] !== 'undefined' && item[ attrs.groupProperty ] === false ) return false; return true; - } + } // call this function when an item is clicked - $scope.syncItems = function( item, e, ng_repeat_index ) { + $scope.syncItems = function( item, e, ng_repeat_index ) { e.preventDefault(); e.stopPropagation(); // if the directive is globaly disabled, do nothing - if ( typeof attrs.disableProperty !== 'undefined' && item[ attrs.disableProperty ] === true ) { + if ( typeof attrs.disableProperty !== 'undefined' && item[ attrs.disableProperty ] === true ) { return false; } // if item is disabled, do nothing - if ( typeof attrs.isDisabled !== 'undefined' && $scope.isDisabled === true ) { + if ( typeof attrs.isDisabled !== 'undefined' && $scope.isDisabled === true ) { return false; - } + } // if end group marker is clicked, do nothing if ( typeof item[ attrs.groupProperty ] !== 'undefined' && item[ attrs.groupProperty ] === false ) { return false; - } + } - var index = $scope.filteredModel.indexOf( item ); + var index = $scope.filteredModel.indexOf( item ); // if the start of group marker is clicked ( only for multiple selection! ) // how it works: // - if, in a group, there are items which are not selected, then they all will be selected - // - if, in a group, all items are selected, then they all will be de-selected - if ( typeof item[ attrs.groupProperty ] !== 'undefined' && item[ attrs.groupProperty ] === true ) { + // - if, in a group, all items are selected, then they all will be de-selected + if ( typeof item[ attrs.groupProperty ] !== 'undefined' && item[ attrs.groupProperty ] === true ) { // this is only for multiple selection, so if selection mode is single, do nothing if ( typeof attrs.selectionMode !== 'undefined' && attrs.selectionMode.toUpperCase() === 'SINGLE' ) { return false; } - + var i,j,k; var startIndex = 0; var endIndex = $scope.filteredModel.length - 1; @@ -3010,44 +3023,44 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' // nest level is to mark the depth of the group. // when you get into a group (start group marker), nestLevel++ // when you exit a group (end group marker), nextLevel-- - var nestLevel = 0; + var nestLevel = 0; // we loop throughout the filtered model (not whole model) - for( i = index ; i < $scope.filteredModel.length ; i++) { + for( i = index ; i < $scope.filteredModel.length ; i++) { // this break will be executed when we're done processing each group - if ( nestLevel === 0 && i > index ) + if ( nestLevel === 0 && i > index ) { break; } - + if ( typeof $scope.filteredModel[ i ][ attrs.groupProperty ] !== 'undefined' && $scope.filteredModel[ i ][ attrs.groupProperty ] === true ) { - + // To cater multi level grouping if ( tempArr.length === 0 ) { - startIndex = i + 1; - } + startIndex = i + 1; + } nestLevel = nestLevel + 1; - } + } // if group end else if ( typeof $scope.filteredModel[ i ][ attrs.groupProperty ] !== 'undefined' && $scope.filteredModel[ i ][ attrs.groupProperty ] === false ) { - nestLevel = nestLevel - 1; + nestLevel = nestLevel - 1; - // cek if all are ticked or not - if ( tempArr.length > 0 && nestLevel === 0 ) { + // cek if all are ticked or not + if ( tempArr.length > 0 && nestLevel === 0 ) { - var allTicked = true; + var allTicked = true; endIndex = i; - for ( j = 0; j < tempArr.length ; j++ ) { + for ( j = 0; j < tempArr.length ; j++ ) { if ( typeof tempArr[ j ][ $scope.tickProperty ] !== 'undefined' && tempArr[ j ][ $scope.tickProperty ] === false ) { allTicked = false; break; } - } + } if ( allTicked === true ) { for ( j = startIndex; j <= endIndex ; j++ ) { @@ -3065,19 +3078,19 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' $scope.inputModel[ inputModelIndex ][ $scope.tickProperty ] = false; } } - } + } } else { for ( j = startIndex; j <= endIndex ; j++ ) { if ( typeof $scope.filteredModel[ j ][ attrs.groupProperty ] === 'undefined' ) { if ( typeof attrs.disableProperty === 'undefined' ) { - $scope.filteredModel[ j ][ $scope.tickProperty ] = true; + $scope.filteredModel[ j ][ $scope.tickProperty ] = true; // we refresh input model as well inputModelIndex = $scope.filteredModel[ j ][ $scope.indexProperty ]; $scope.inputModel[ inputModelIndex ][ $scope.tickProperty ] = true; - } + } else if ( $scope.filteredModel[ j ][ attrs.disableProperty ] !== true ) { $scope.filteredModel[ j ][ $scope.tickProperty ] = true; // we refresh input model as well @@ -3085,16 +3098,16 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' $scope.inputModel[ inputModelIndex ][ $scope.tickProperty ] = true; } } - } - } + } + } } } - + // if data - else { - tempArr.push( $scope.filteredModel[ i ] ); + else { + tempArr.push( $scope.filteredModel[ i ] ); } - } + } } // if an item (not group marker) is clicked @@ -3102,18 +3115,18 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' // If it's single selection mode if ( typeof attrs.selectionMode !== 'undefined' && attrs.selectionMode.toUpperCase() === 'SINGLE' ) { - + // first, set everything to false - for( i=0 ; i < $scope.filteredModel.length ; i++) { - $scope.filteredModel[ i ][ $scope.tickProperty ] = false; - } - for( i=0 ; i < $scope.inputModel.length ; i++) { - $scope.inputModel[ i ][ $scope.tickProperty ] = false; - } - + for( i=0 ; i < $scope.filteredModel.length ; i++) { + $scope.filteredModel[ i ][ $scope.tickProperty ] = false; + } + for( i=0 ; i < $scope.inputModel.length ; i++) { + $scope.inputModel[ i ][ $scope.tickProperty ] = false; + } + // then set the clicked item to true - $scope.filteredModel[ index ][ $scope.tickProperty ] = true; - } + $scope.filteredModel[ index ][ $scope.tickProperty ] = true; + } // Multiple else { @@ -3121,29 +3134,29 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' } // we refresh input model as well - var inputModelIndex = $scope.filteredModel[ index ][ $scope.indexProperty ]; - $scope.inputModel[ inputModelIndex ][ $scope.tickProperty ] = $scope.filteredModel[ index ][ $scope.tickProperty ]; - } + var inputModelIndex = $scope.filteredModel[ index ][ $scope.indexProperty ]; + $scope.inputModel[ inputModelIndex ][ $scope.tickProperty ] = $scope.filteredModel[ index ][ $scope.tickProperty ]; + } // we execute the callback function here - clickedItem = angular.copy( item ); - if ( clickedItem !== null ) { + clickedItem = angular.copy( item ); + if ( clickedItem !== null ) { $timeout( function() { delete clickedItem[ $scope.indexProperty ]; - delete clickedItem[ $scope.spacingProperty ]; + delete clickedItem[ $scope.spacingProperty ]; $scope.onItemClick( { data: clickedItem } ); - clickedItem = null; - }, 0 ); - } - + clickedItem = null; + }, 0 ); + } + $scope.refreshOutputModel(); - $scope.refreshButton(); + $scope.refreshButton(); // We update the index here prevTabIndex = $scope.tabIndex; $scope.tabIndex = ng_repeat_index + helperItemsLength; - - // Set focus on the hidden checkbox + + // Set focus on the hidden checkbox e.target.focus(); // set & remove CSS style @@ -3152,67 +3165,67 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' if ( typeof attrs.selectionMode !== 'undefined' && attrs.selectionMode.toUpperCase() === 'SINGLE' ) { // on single selection mode, we then hide the checkbox layer - $scope.toggleCheckboxes( e ); + $scope.toggleCheckboxes( e ); } - } + } // update $scope.outputModel - $scope.refreshOutputModel = function() { - + $scope.refreshOutputModel = function() { + $scope.outputModel = []; - var + var outputProps = [], tempObj = {}; // v4.0.0 - if ( typeof attrs.outputProperties !== 'undefined' ) { - outputProps = attrs.outputProperties.split(' '); - angular.forEach( $scope.inputModel, function( value, key ) { - if ( - typeof value !== 'undefined' - && typeof value[ attrs.groupProperty ] === 'undefined' - && value[ $scope.tickProperty ] === true + if ( typeof attrs.outputProperties !== 'undefined' ) { + outputProps = attrs.outputProperties.split(' '); + angular.forEach( $scope.inputModel, function( value, key ) { + if ( + typeof value !== 'undefined' + && typeof value[ attrs.groupProperty ] === 'undefined' + && value[ $scope.tickProperty ] === true ) { tempObj = {}; - angular.forEach( value, function( value1, key1 ) { - if ( outputProps.indexOf( key1 ) > -1 ) { - tempObj[ key1 ] = value1; + angular.forEach( value, function( value1, key1 ) { + if ( outputProps.indexOf( key1 ) > -1 ) { + tempObj[ key1 ] = value1; } }); - var index = $scope.outputModel.push( tempObj ); + var index = $scope.outputModel.push( tempObj ); delete $scope.outputModel[ index - 1 ][ $scope.indexProperty ]; - delete $scope.outputModel[ index - 1 ][ $scope.spacingProperty ]; + delete $scope.outputModel[ index - 1 ][ $scope.spacingProperty ]; } - }); + }); } else { - angular.forEach( $scope.inputModel, function( value, key ) { - if ( - typeof value !== 'undefined' - && typeof value[ attrs.groupProperty ] === 'undefined' - && value[ $scope.tickProperty ] === true + angular.forEach( $scope.inputModel, function( value, key ) { + if ( + typeof value !== 'undefined' + && typeof value[ attrs.groupProperty ] === 'undefined' + && value[ $scope.tickProperty ] === true ) { var temp = angular.copy( value ); - var index = $scope.outputModel.push( temp ); + var index = $scope.outputModel.push( temp ); delete $scope.outputModel[ index - 1 ][ $scope.indexProperty ]; - delete $scope.outputModel[ index - 1 ][ $scope.spacingProperty ]; + delete $scope.outputModel[ index - 1 ][ $scope.spacingProperty ]; } - }); + }); } } // refresh button label $scope.refreshButton = function() { - $scope.varButtonLabel = ''; - var ctr = 0; + $scope.varButtonLabel = ''; + var ctr = 0; // refresh button label... if ( $scope.outputModel.length === 0 ) { - // https://github.com/isteven/angular-multi-select/pull/19 + // https://github.com/isteven/angular-multi-select/pull/19 $scope.varButtonLabel = $scope.lang.nothingSelected; } - else { + else { var tempMaxLabels = $scope.outputModel.length; if ( typeof attrs.maxLabels !== 'undefined' && attrs.maxLabels !== '' ) { tempMaxLabels = attrs.maxLabels; @@ -3224,85 +3237,85 @@ angular.module( 'isteven-multi-select', ['ng'] ).directive( 'istevenMultiSelect' } else { $scope.more = false; - } - + } + angular.forEach( $scope.inputModel, function( value, key ) { - if ( typeof value !== 'undefined' && value[ attrs.tickProperty ] === true ) { - if ( ctr < tempMaxLabels ) { + if ( typeof value !== 'undefined' && value[ attrs.tickProperty ] === true ) { + if ( ctr < tempMaxLabels ) { $scope.varButtonLabel += ( $scope.varButtonLabel.length > 0 ? ',