2014-01-30 09:41:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014
|
|
|
|
|
*
|
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
|
* or later.
|
|
|
|
|
*
|
|
|
|
|
* See the COPYING-README file.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
(function() {
|
2014-04-04 16:46:08 +00:00
|
|
|
|
/**
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @class OCA.Files.FileList
|
|
|
|
|
* @classdesc
|
|
|
|
|
*
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* The FileList class manages a file list view.
|
|
|
|
|
* A file list view consists of a controls bar and
|
|
|
|
|
* a file list table.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
*
|
|
|
|
|
* @param $el container element with existing markup for the #controls
|
|
|
|
|
* and a table
|
|
|
|
|
* @param [options] map of options, see other parameters
|
|
|
|
|
* @param [options.scrollContainer] scrollable container, defaults to $(window)
|
|
|
|
|
* @param [options.dragOptions] drag options, disabled by default
|
|
|
|
|
* @param [options.folderDropOptions] folder drop options, disabled by default
|
2014-04-04 16:46:08 +00:00
|
|
|
|
*/
|
2014-05-12 17:54:20 +00:00
|
|
|
|
var FileList = function($el, options) {
|
|
|
|
|
this.initialize($el, options);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
};
|
2014-06-23 21:56:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* @memberof OCA.Files
|
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
|
FileList.prototype = {
|
2014-07-21 21:07:52 +00:00
|
|
|
|
SORT_INDICATOR_ASC_CLASS: 'icon-triangle-n',
|
|
|
|
|
SORT_INDICATOR_DESC_CLASS: 'icon-triangle-s',
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
id: 'files',
|
2014-05-08 20:06:30 +00:00
|
|
|
|
appName: t('files', 'Files'),
|
|
|
|
|
isEmpty: true,
|
|
|
|
|
useUndo:true,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Top-level container with controls and file list
|
|
|
|
|
*/
|
|
|
|
|
$el: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Files table
|
|
|
|
|
*/
|
|
|
|
|
$table: null,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List of rows (table tbody)
|
|
|
|
|
*/
|
|
|
|
|
$fileList: null,
|
|
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* @type OCA.Files.BreadCrumb
|
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
|
breadcrumb: null,
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type OCA.Files.FileSummary
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
fileSummary: null,
|
2014-06-23 21:56:10 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the file list was initialized already.
|
|
|
|
|
* @type boolean
|
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
|
initialized: false,
|
|
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* Number of files per page
|
|
|
|
|
*
|
|
|
|
|
* @return {int} page size
|
|
|
|
|
*/
|
2014-10-11 13:10:54 +00:00
|
|
|
|
pageSize: function() {
|
2014-10-15 13:24:03 +00:00
|
|
|
|
return Math.ceil(this.$container.height() / 50);
|
2014-10-11 13:10:54 +00:00
|
|
|
|
},
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Array of files in the current folder.
|
|
|
|
|
* The entries are of file data.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
*
|
|
|
|
|
* @type Array.<Object>
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
files: [],
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* File actions handler, defaults to OCA.Files.FileActions
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type OCA.Files.FileActions
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
fileActions: null,
|
|
|
|
|
|
2014-12-11 16:36:14 +00:00
|
|
|
|
/**
|
|
|
|
|
* Whether selection is allowed, checkboxes and selection overlay will
|
|
|
|
|
* be rendered
|
|
|
|
|
*/
|
|
|
|
|
_allowSelection: true,
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Map of file id to file data
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type Object.<int, Object>
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_selectedFiles: {},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Summary of selected files.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type OCA.Files.FileSummary
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_selectionSummary: null,
|
|
|
|
|
|
2014-12-18 09:26:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* If not empty, only files containing this string will be shown
|
|
|
|
|
* @type String
|
|
|
|
|
*/
|
|
|
|
|
_filter: '',
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sort attribute
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type String
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_sort: 'name',
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sort direction: 'asc' or 'desc'
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type String
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_sortDirection: 'asc',
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sort comparator function for the current sort
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type Function
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_sortComparator: null,
|
|
|
|
|
|
2014-08-15 14:52:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* Whether to do a client side sort.
|
|
|
|
|
* When false, clicking on a table header will call reload().
|
|
|
|
|
* When true, clicking on a table header will simply resort the list.
|
|
|
|
|
*/
|
|
|
|
|
_clientSideSort: false,
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Current directory
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @type String
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_currentDirectory: null,
|
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
_dragOptions: null,
|
|
|
|
|
_folderDropOptions: null,
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Initialize the file list and its components
|
2014-05-12 17:54:20 +00:00
|
|
|
|
*
|
|
|
|
|
* @param $el container element with existing markup for the #controls
|
|
|
|
|
* and a table
|
|
|
|
|
* @param options map of options, see other parameters
|
2014-09-04 10:20:11 +00:00
|
|
|
|
* @param options.scrollContainer scrollable container, defaults to $(window)
|
|
|
|
|
* @param options.dragOptions drag options, disabled by default
|
|
|
|
|
* @param options.folderDropOptions folder drop options, disabled by default
|
|
|
|
|
* @param options.scrollTo name of file to scroll to after the first load
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @private
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
2014-05-12 17:54:20 +00:00
|
|
|
|
initialize: function($el, options) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var self = this;
|
2014-05-12 17:54:20 +00:00
|
|
|
|
options = options || {};
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (this.initialized) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-04-04 16:46:08 +00:00
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
if (options.dragOptions) {
|
|
|
|
|
this._dragOptions = options.dragOptions;
|
|
|
|
|
}
|
|
|
|
|
if (options.folderDropOptions) {
|
|
|
|
|
this._folderDropOptions = options.folderDropOptions;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el = $el;
|
2014-12-01 15:17:28 +00:00
|
|
|
|
if (options.id) {
|
|
|
|
|
this.id = options.id;
|
|
|
|
|
}
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$container = options.scrollContainer || $(window);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$table = $el.find('table:first');
|
|
|
|
|
this.$fileList = $el.find('#fileList');
|
2014-05-20 14:01:34 +00:00
|
|
|
|
this._initFileActions(options.fileActions);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.files = [];
|
|
|
|
|
this._selectedFiles = {};
|
|
|
|
|
this._selectionSummary = new OCA.Files.FileSummary();
|
2014-04-03 18:57:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.fileSummary = this._createSummary();
|
2014-04-03 18:57:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.setSort('name', 'asc');
|
2014-04-04 12:34:07 +00:00
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
var breadcrumbOptions = {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
onClick: _.bind(this._onClickBreadCrumb, this),
|
2014-05-12 17:54:20 +00:00
|
|
|
|
getCrumbUrl: function(part) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
return self.linkTo(part.dir);
|
|
|
|
|
}
|
2014-05-12 17:54:20 +00:00
|
|
|
|
};
|
|
|
|
|
// if dropping on folders is allowed, then also allow on breadcrumbs
|
|
|
|
|
if (this._folderDropOptions) {
|
|
|
|
|
breadcrumbOptions.onDrop = _.bind(this._onDropOnBreadCrumb, this);
|
|
|
|
|
}
|
|
|
|
|
this.breadcrumb = new OCA.Files.BreadCrumb(breadcrumbOptions);
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.find('#controls').prepend(this.breadcrumb.$el);
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.find('thead th .columntitle').click(_.bind(this._onClickHeader, this));
|
2014-02-11 15:52:56 +00:00
|
|
|
|
|
2014-05-23 17:02:50 +00:00
|
|
|
|
this._onResize = _.debounce(_.bind(this._onResize, this), 100);
|
|
|
|
|
$(window).resize(this._onResize);
|
|
|
|
|
|
|
|
|
|
this.$el.on('show', this._onResize);
|
2014-04-03 18:57:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$fileList.on('click','td.filename>a.name', _.bind(this._onClickFile, this));
|
2014-12-11 17:20:04 +00:00
|
|
|
|
this.$fileList.on('change', 'td.filename>.selectCheckBox', _.bind(this._onClickFileCheckbox, this));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.on('urlChanged', _.bind(this._onUrlChanged, this));
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$el.find('.select-all').click(_.bind(this._onClickSelectAll, this));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.find('.download').click(_.bind(this._onClickDownloadSelected, this));
|
|
|
|
|
this.$el.find('.delete-selected').click(_.bind(this._onClickDeleteSelected, this));
|
|
|
|
|
|
|
|
|
|
this.setupUploadEvents();
|
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$container.on('scroll', _.bind(this._onScroll, this));
|
2014-09-04 10:20:11 +00:00
|
|
|
|
|
|
|
|
|
if (options.scrollTo) {
|
|
|
|
|
this.$fileList.one('updated', function() {
|
|
|
|
|
self.scrollTo(options.scrollTo);
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-12-01 15:17:28 +00:00
|
|
|
|
|
|
|
|
|
OC.Plugins.attach('OCA.Files.FileList', this);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
2014-06-27 11:36:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* Destroy / uninitialize this instance.
|
|
|
|
|
*/
|
|
|
|
|
destroy: function() {
|
|
|
|
|
// TODO: also unregister other event handlers
|
2014-07-09 10:26:33 +00:00
|
|
|
|
this.fileActions.off('registerAction', this._onFileActionsUpdated);
|
|
|
|
|
this.fileActions.off('setDefault', this._onFileActionsUpdated);
|
2014-12-01 15:17:28 +00:00
|
|
|
|
OC.Plugins.detach('OCA.Files.FileList', this);
|
2014-06-27 11:36:18 +00:00
|
|
|
|
},
|
|
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* Initializes the file actions, set up listeners.
|
|
|
|
|
*
|
|
|
|
|
* @param {OCA.Files.FileActions} fileActions file actions
|
|
|
|
|
*/
|
2014-05-20 14:01:34 +00:00
|
|
|
|
_initFileActions: function(fileActions) {
|
|
|
|
|
this.fileActions = fileActions;
|
|
|
|
|
if (!this.fileActions) {
|
|
|
|
|
this.fileActions = new OCA.Files.FileActions();
|
|
|
|
|
this.fileActions.registerDefaultActions();
|
|
|
|
|
}
|
2014-06-27 11:36:18 +00:00
|
|
|
|
this._onFileActionsUpdated = _.debounce(_.bind(this._onFileActionsUpdated, this), 100);
|
2014-07-09 10:26:33 +00:00
|
|
|
|
this.fileActions.on('registerAction', this._onFileActionsUpdated);
|
|
|
|
|
this.fileActions.on('setDefault', this._onFileActionsUpdated);
|
2014-05-20 14:01:34 +00:00
|
|
|
|
},
|
|
|
|
|
|
2014-05-23 17:02:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* Event handler for when the window size changed
|
|
|
|
|
*/
|
|
|
|
|
_onResize: function() {
|
|
|
|
|
var containerWidth = this.$el.width();
|
|
|
|
|
var actionsWidth = 0;
|
|
|
|
|
$.each(this.$el.find('#controls .actions'), function(index, action) {
|
|
|
|
|
actionsWidth += $(action).outerWidth();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// substract app navigation toggle when visible
|
|
|
|
|
containerWidth -= $('#app-navigation-toggle').width();
|
|
|
|
|
|
|
|
|
|
this.breadcrumb.setMaxWidth(containerWidth - actionsWidth - 10);
|
|
|
|
|
},
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Event handler for when the URL changed
|
|
|
|
|
*/
|
|
|
|
|
_onUrlChanged: function(e) {
|
|
|
|
|
if (e && e.dir) {
|
|
|
|
|
this.changeDirectory(e.dir, false, true);
|
2013-10-28 19:22:06 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selected/deselects the given file element and updated
|
|
|
|
|
* the internal selection cache.
|
|
|
|
|
*
|
|
|
|
|
* @param $tr single file row element
|
|
|
|
|
* @param state true to select, false to deselect
|
|
|
|
|
*/
|
|
|
|
|
_selectFileEl: function($tr, state) {
|
2014-12-11 17:20:04 +00:00
|
|
|
|
var $checkbox = $tr.find('td.filename>.selectCheckBox');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var oldData = !!this._selectedFiles[$tr.data('id')];
|
|
|
|
|
var data;
|
|
|
|
|
$checkbox.prop('checked', state);
|
|
|
|
|
$tr.toggleClass('selected', state);
|
|
|
|
|
// already selected ?
|
|
|
|
|
if (state === oldData) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
data = this.elementToFile($tr);
|
|
|
|
|
if (state) {
|
|
|
|
|
this._selectedFiles[$tr.data('id')] = data;
|
|
|
|
|
this._selectionSummary.add(data);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
delete this._selectedFiles[$tr.data('id')];
|
|
|
|
|
this._selectionSummary.remove(data);
|
|
|
|
|
}
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$el.find('.select-all').prop('checked', this._selectionSummary.getTotal() === this.files.length);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler for when clicking on files to select them
|
|
|
|
|
*/
|
|
|
|
|
_onClickFile: function(event) {
|
|
|
|
|
var $tr = $(event.target).closest('tr');
|
|
|
|
|
if (event.ctrlKey || event.shiftKey) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (event.shiftKey) {
|
|
|
|
|
var $lastTr = $(this._lastChecked);
|
|
|
|
|
var lastIndex = $lastTr.index();
|
|
|
|
|
var currentIndex = $tr.index();
|
|
|
|
|
var $rows = this.$fileList.children('tr');
|
|
|
|
|
|
|
|
|
|
// last clicked checkbox below current one ?
|
|
|
|
|
if (lastIndex > currentIndex) {
|
|
|
|
|
var aux = lastIndex;
|
|
|
|
|
lastIndex = currentIndex;
|
|
|
|
|
currentIndex = aux;
|
|
|
|
|
}
|
2014-04-04 16:46:08 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// auto-select everything in-between
|
|
|
|
|
for (var i = lastIndex + 1; i < currentIndex; i++) {
|
|
|
|
|
this._selectFileEl($rows.eq(i), true);
|
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
else {
|
|
|
|
|
this._lastChecked = $tr;
|
|
|
|
|
}
|
2014-12-11 17:20:04 +00:00
|
|
|
|
var $checkbox = $tr.find('td.filename>.selectCheckBox');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this._selectFileEl($tr, !$checkbox.prop('checked'));
|
|
|
|
|
this.updateSelectionSummary();
|
|
|
|
|
} else {
|
|
|
|
|
var filename = $tr.attr('data-file');
|
|
|
|
|
var renaming = $tr.data('renaming');
|
|
|
|
|
if (!renaming) {
|
|
|
|
|
this.fileActions.currentFile = $tr.find('td');
|
|
|
|
|
var mime = this.fileActions.getCurrentMimeType();
|
|
|
|
|
var type = this.fileActions.getCurrentType();
|
|
|
|
|
var permissions = this.fileActions.getCurrentPermissions();
|
|
|
|
|
var action = this.fileActions.getDefault(mime,type, permissions);
|
|
|
|
|
if (action) {
|
|
|
|
|
event.preventDefault();
|
2014-05-20 14:01:34 +00:00
|
|
|
|
// also set on global object for legacy apps
|
|
|
|
|
window.FileActions.currentFile = this.fileActions.currentFile;
|
2014-05-19 11:18:44 +00:00
|
|
|
|
action(filename, {
|
|
|
|
|
$file: $tr,
|
|
|
|
|
fileList: this,
|
2014-05-20 09:44:18 +00:00
|
|
|
|
fileActions: this.fileActions,
|
|
|
|
|
dir: $tr.attr('data-path') || this.getCurrentDirectory()
|
2014-05-19 11:18:44 +00:00
|
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler for when clicking on a file's checkbox
|
|
|
|
|
*/
|
|
|
|
|
_onClickFileCheckbox: function(e) {
|
|
|
|
|
var $tr = $(e.target).closest('tr');
|
|
|
|
|
this._selectFileEl($tr, !$tr.hasClass('selected'));
|
|
|
|
|
this._lastChecked = $tr;
|
|
|
|
|
this.updateSelectionSummary();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler for when selecting/deselecting all files
|
|
|
|
|
*/
|
|
|
|
|
_onClickSelectAll: function(e) {
|
|
|
|
|
var checked = $(e.target).prop('checked');
|
2014-12-11 17:20:04 +00:00
|
|
|
|
this.$fileList.find('td.filename>.selectCheckBox').prop('checked', checked)
|
2014-05-08 20:06:30 +00:00
|
|
|
|
.closest('tr').toggleClass('selected', checked);
|
|
|
|
|
this._selectedFiles = {};
|
|
|
|
|
this._selectionSummary.clear();
|
|
|
|
|
if (checked) {
|
|
|
|
|
for (var i = 0; i < this.files.length; i++) {
|
|
|
|
|
var fileData = this.files[i];
|
|
|
|
|
this._selectedFiles[fileData.id] = fileData;
|
|
|
|
|
this._selectionSummary.add(fileData);
|
|
|
|
|
}
|
2014-04-04 16:46:08 +00:00
|
|
|
|
}
|
2014-04-08 15:09:57 +00:00
|
|
|
|
this.updateSelectionSummary();
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler for when clicking on "Download" for the selected files
|
|
|
|
|
*/
|
|
|
|
|
_onClickDownloadSelected: function(event) {
|
|
|
|
|
var files;
|
|
|
|
|
var dir = this.getCurrentDirectory();
|
|
|
|
|
if (this.isAllSelected()) {
|
|
|
|
|
files = OC.basename(dir);
|
|
|
|
|
dir = OC.dirname(dir) || '/';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
files = _.pluck(this.getSelectedFiles(), 'name');
|
|
|
|
|
}
|
|
|
|
|
OC.redirect(this.getDownloadUrl(files, dir));
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler for when clicking on "Delete" for the selected files
|
|
|
|
|
*/
|
|
|
|
|
_onClickDeleteSelected: function(event) {
|
|
|
|
|
var files = null;
|
|
|
|
|
if (!this.isAllSelected()) {
|
|
|
|
|
files = _.pluck(this.getSelectedFiles(), 'name');
|
|
|
|
|
}
|
|
|
|
|
this.do_delete(files);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler when clicking on a table header
|
|
|
|
|
*/
|
|
|
|
|
_onClickHeader: function(e) {
|
|
|
|
|
var $target = $(e.target);
|
|
|
|
|
var sort;
|
|
|
|
|
if (!$target.is('a')) {
|
|
|
|
|
$target = $target.closest('a');
|
|
|
|
|
}
|
|
|
|
|
sort = $target.attr('data-sort');
|
|
|
|
|
if (sort) {
|
|
|
|
|
if (this._sort === sort) {
|
2014-08-15 14:52:41 +00:00
|
|
|
|
this.setSort(sort, (this._sortDirection === 'desc')?'asc':'desc', true);
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
else {
|
2014-07-17 19:31:54 +00:00
|
|
|
|
if ( sort === 'name' ) { //default sorting of name is opposite to size and mtime
|
2014-08-15 14:52:41 +00:00
|
|
|
|
this.setSort(sort, 'asc', true);
|
2014-07-08 17:52:28 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2014-08-15 14:52:41 +00:00
|
|
|
|
this.setSort(sort, 'desc', true);
|
2014-07-08 17:52:28 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler when clicking on a bread crumb
|
|
|
|
|
*/
|
|
|
|
|
_onClickBreadCrumb: function(e) {
|
|
|
|
|
var $el = $(e.target).closest('.crumb'),
|
|
|
|
|
$targetDir = $el.data('dir');
|
|
|
|
|
|
|
|
|
|
if ($targetDir !== undefined) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
this.changeDirectory($targetDir);
|
|
|
|
|
}
|
|
|
|
|
},
|
2014-02-12 13:50:23 +00:00
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* Event handler for when scrolling the list container.
|
|
|
|
|
* This appends/renders the next page of entries when reaching the bottom.
|
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
|
_onScroll: function(e) {
|
2014-08-07 22:27:31 +00:00
|
|
|
|
if (this.$container.scrollTop() + this.$container.height() > this.$el.height() - 300) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this._nextPage(true);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event handler when dropping on a breadcrumb
|
|
|
|
|
*/
|
|
|
|
|
_onDropOnBreadCrumb: function( event, ui ) {
|
|
|
|
|
var $target = $(event.target);
|
|
|
|
|
if (!$target.is('.crumb')) {
|
|
|
|
|
$target = $target.closest('.crumb');
|
|
|
|
|
}
|
|
|
|
|
var targetPath = $(event.target).data('dir');
|
|
|
|
|
var dir = this.getCurrentDirectory();
|
|
|
|
|
while (dir.substr(0,1) === '/') {//remove extra leading /'s
|
|
|
|
|
dir = dir.substr(1);
|
|
|
|
|
}
|
|
|
|
|
dir = '/' + dir;
|
|
|
|
|
if (dir.substr(-1,1) !== '/') {
|
|
|
|
|
dir = dir + '/';
|
|
|
|
|
}
|
|
|
|
|
// do nothing if dragged on current dir
|
|
|
|
|
if (targetPath === dir || targetPath + '/' === dir) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var files = this.getSelectedFiles();
|
|
|
|
|
if (files.length === 0) {
|
|
|
|
|
// single one selected without checkbox?
|
|
|
|
|
files = _.map(ui.helper.find('tr'), this.elementToFile);
|
2014-04-04 16:46:08 +00:00
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.move(_.pluck(files, 'name'), targetPath);
|
|
|
|
|
},
|
2014-02-12 13:50:23 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets a new page title
|
|
|
|
|
*/
|
|
|
|
|
setPageTitle: function(title){
|
|
|
|
|
if (title) {
|
|
|
|
|
title += ' - ';
|
|
|
|
|
} else {
|
|
|
|
|
title = '';
|
|
|
|
|
}
|
|
|
|
|
title += this.appName;
|
|
|
|
|
// Sets the page title with the " - ownCloud" suffix as in templates
|
|
|
|
|
window.document.title = title + ' - ' + oc_defaults.title;
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Returns the tr element for a given file name
|
|
|
|
|
* @param fileName file name
|
|
|
|
|
*/
|
|
|
|
|
findFileEl: function(fileName){
|
|
|
|
|
// use filterAttr to avoid escaping issues
|
|
|
|
|
return this.$fileList.find('tr').filterAttr('data-file', fileName);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the file data from a given file element.
|
|
|
|
|
* @param $el file tr element
|
|
|
|
|
* @return file data
|
|
|
|
|
*/
|
|
|
|
|
elementToFile: function($el){
|
|
|
|
|
$el = $($el);
|
|
|
|
|
return {
|
|
|
|
|
id: parseInt($el.attr('data-id'), 10),
|
|
|
|
|
name: $el.attr('data-file'),
|
|
|
|
|
mimetype: $el.attr('data-mime'),
|
|
|
|
|
type: $el.attr('data-type'),
|
|
|
|
|
size: parseInt($el.attr('data-size'), 10),
|
2014-11-20 15:53:32 +00:00
|
|
|
|
etag: $el.attr('data-etag'),
|
|
|
|
|
permissions: parseInt($el.attr('data-permissions'), 10)
|
2014-05-08 20:06:30 +00:00
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Appends the next page of files into the table
|
|
|
|
|
* @param animate true to animate the new elements
|
2014-07-01 19:32:04 +00:00
|
|
|
|
* @return array of DOM elements of the newly added files
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_nextPage: function(animate) {
|
|
|
|
|
var index = this.$fileList.children().length,
|
2014-10-11 13:10:54 +00:00
|
|
|
|
count = this.pageSize(),
|
2014-12-18 09:26:41 +00:00
|
|
|
|
hidden,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
tr,
|
|
|
|
|
fileData,
|
|
|
|
|
newTrs = [],
|
|
|
|
|
isAllSelected = this.isAllSelected();
|
|
|
|
|
|
|
|
|
|
if (index >= this.files.length) {
|
2014-07-01 19:32:04 +00:00
|
|
|
|
return false;
|
2014-04-03 18:57:06 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
while (count > 0 && index < this.files.length) {
|
|
|
|
|
fileData = this.files[index];
|
2014-12-18 09:26:41 +00:00
|
|
|
|
if (this._filter) {
|
|
|
|
|
hidden = fileData.name.toLowerCase().indexOf(this._filter.toLowerCase()) === -1;
|
|
|
|
|
} else {
|
|
|
|
|
hidden = false;
|
|
|
|
|
}
|
|
|
|
|
tr = this._renderRow(fileData, {updateSummary: false, silent: true, hidden: hidden});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$fileList.append(tr);
|
|
|
|
|
if (isAllSelected || this._selectedFiles[fileData.id]) {
|
|
|
|
|
tr.addClass('selected');
|
2014-12-11 17:20:04 +00:00
|
|
|
|
tr.find('.selectCheckBox').prop('checked', true);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
if (animate) {
|
|
|
|
|
tr.addClass('appear transparent');
|
|
|
|
|
}
|
2014-07-01 19:32:04 +00:00
|
|
|
|
newTrs.push(tr);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
index++;
|
|
|
|
|
count--;
|
2014-04-03 18:57:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 19:32:04 +00:00
|
|
|
|
// trigger event for newly added rows
|
|
|
|
|
if (newTrs.length > 0) {
|
|
|
|
|
this.$fileList.trigger($.Event('fileActionsReady', {fileList: this, $files: newTrs}));
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (animate) {
|
|
|
|
|
// defer, for animation
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
|
for (var i = 0; i < newTrs.length; i++ ) {
|
|
|
|
|
newTrs[i].removeClass('transparent');
|
|
|
|
|
}
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
2014-07-01 19:32:04 +00:00
|
|
|
|
return newTrs;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-06-27 11:36:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* Event handler for when file actions were updated.
|
|
|
|
|
* This will refresh the file actions on the list.
|
|
|
|
|
*/
|
|
|
|
|
_onFileActionsUpdated: function() {
|
|
|
|
|
var self = this;
|
2014-07-01 19:32:04 +00:00
|
|
|
|
var $files = this.$fileList.find('tr');
|
|
|
|
|
if (!$files.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$files.each(function() {
|
|
|
|
|
self.fileActions.display($(this).find('td.filename'), false, self);
|
2014-06-27 11:36:18 +00:00
|
|
|
|
});
|
2014-07-01 19:32:04 +00:00
|
|
|
|
this.$fileList.trigger($.Event('fileActionsReady', {fileList: this, $files: $files}));
|
|
|
|
|
|
2014-06-27 11:36:18 +00:00
|
|
|
|
},
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the files to be displayed in the list.
|
|
|
|
|
* This operation will re-render the list and update the summary.
|
|
|
|
|
* @param filesArray array of file data (map)
|
|
|
|
|
*/
|
|
|
|
|
setFiles: function(filesArray) {
|
|
|
|
|
// detach to make adding multiple rows faster
|
|
|
|
|
this.files = filesArray;
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$fileList.empty();
|
2014-02-11 14:57:45 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// clear "Select all" checkbox
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$el.find('.select-all').prop('checked', false);
|
2014-04-11 10:46:12 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.isEmpty = this.files.length === 0;
|
|
|
|
|
this._nextPage();
|
2014-04-11 10:46:12 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.updateEmptyContent();
|
2014-02-20 14:36:52 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.fileSummary.calculate(filesArray);
|
2014-02-11 14:57:45 +00:00
|
|
|
|
|
2014-06-23 10:55:42 +00:00
|
|
|
|
this._selectedFiles = {};
|
|
|
|
|
this._selectionSummary.clear();
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.updateSelectionSummary();
|
|
|
|
|
$(window).scrollTop(0);
|
|
|
|
|
|
|
|
|
|
this.$fileList.trigger(jQuery.Event("updated"));
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new table row element using the given file data.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {OCA.Files.FileInfo} fileData file info attributes
|
|
|
|
|
* @param options map of attributes
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* @return new tr element (not appended to the table)
|
|
|
|
|
*/
|
|
|
|
|
_createRow: function(fileData, options) {
|
|
|
|
|
var td, simpleSize, basename, extension, sizeColor,
|
|
|
|
|
icon = OC.Util.replaceSVGIcon(fileData.icon),
|
|
|
|
|
name = fileData.name,
|
|
|
|
|
type = fileData.type || 'file',
|
2014-12-05 13:54:43 +00:00
|
|
|
|
mtime = parseInt(fileData.mtime, 10),
|
2014-05-08 20:06:30 +00:00
|
|
|
|
mime = fileData.mimetype,
|
2014-05-21 10:54:34 +00:00
|
|
|
|
path = fileData.path,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
linkUrl;
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
2014-12-05 13:54:43 +00:00
|
|
|
|
if (isNaN(mtime)) {
|
|
|
|
|
mtime = new Date().getTime()
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (type === 'dir') {
|
|
|
|
|
mime = mime || 'httpd/unix-directory';
|
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
//containing tr
|
|
|
|
|
var tr = $('<tr></tr>').attr({
|
|
|
|
|
"data-id" : fileData.id,
|
|
|
|
|
"data-type": type,
|
|
|
|
|
"data-size": fileData.size,
|
|
|
|
|
"data-file": name,
|
|
|
|
|
"data-mime": mime,
|
|
|
|
|
"data-mtime": mtime,
|
|
|
|
|
"data-etag": fileData.etag,
|
2014-05-26 18:32:24 +00:00
|
|
|
|
"data-permissions": fileData.permissions || this.getDirectoryPermissions()
|
2014-05-08 20:06:30 +00:00
|
|
|
|
});
|
2014-02-11 14:57:45 +00:00
|
|
|
|
|
2014-07-10 15:25:46 +00:00
|
|
|
|
if (fileData.mountType) {
|
|
|
|
|
tr.attr('data-mounttype', fileData.mountType);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 10:54:34 +00:00
|
|
|
|
if (!_.isUndefined(path)) {
|
|
|
|
|
tr.attr('data-path', path);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
path = this.getCurrentDirectory();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (type === 'dir') {
|
|
|
|
|
// use default folder icon
|
|
|
|
|
icon = icon || OC.imagePath('core', 'filetypes/folder');
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
else {
|
|
|
|
|
icon = icon || OC.imagePath('core', 'filetypes/file');
|
2014-02-11 14:57:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// filename td
|
2014-12-11 16:36:14 +00:00
|
|
|
|
td = $('<td class="filename"></td>');
|
|
|
|
|
|
2014-02-11 14:57:45 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// linkUrl
|
|
|
|
|
if (type === 'dir') {
|
2014-04-30 15:42:35 +00:00
|
|
|
|
linkUrl = this.linkTo(path + '/' + name);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2014-04-30 15:42:35 +00:00
|
|
|
|
linkUrl = this.getDownloadUrl(name, path);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2014-12-11 16:36:14 +00:00
|
|
|
|
if (this._allowSelection) {
|
|
|
|
|
td.append(
|
|
|
|
|
'<input id="select-' + this.id + '-' + fileData.id +
|
2014-12-11 17:20:04 +00:00
|
|
|
|
'" type="checkbox" class="selectCheckBox"/><label for="select-' + this.id + '-' + fileData.id + '">' +
|
2014-12-11 16:36:14 +00:00
|
|
|
|
'<div class="thumbnail" style="background-image:url(' + icon + '); background-size: 32px;"></div>' +
|
2014-12-17 13:12:13 +00:00
|
|
|
|
'<span class="hidden-visually">' + t('files', 'Select') + '</span>' +
|
2014-12-11 16:36:14 +00:00
|
|
|
|
'</label>'
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
td.append('<div class="thumbnail" style="background-image:url(' + icon + '); background-size: 32px;"></div>');
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var linkElem = $('<a></a>').attr({
|
|
|
|
|
"class": "name",
|
|
|
|
|
"href": linkUrl
|
|
|
|
|
});
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// from here work on the display name
|
|
|
|
|
name = fileData.displayName || name;
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// split extension from filename for non dirs
|
|
|
|
|
if (type !== 'dir' && name.indexOf('.') !== -1) {
|
|
|
|
|
basename = name.substr(0, name.lastIndexOf('.'));
|
|
|
|
|
extension = name.substr(name.lastIndexOf('.'));
|
|
|
|
|
} else {
|
|
|
|
|
basename = name;
|
|
|
|
|
extension = false;
|
|
|
|
|
}
|
2014-06-06 12:00:18 +00:00
|
|
|
|
var nameSpan=$('<span></span>').addClass('nametext');
|
2014-06-07 18:24:21 +00:00
|
|
|
|
var innernameSpan = $('<span></span>').addClass('innernametext').text(basename);
|
2014-06-06 12:00:18 +00:00
|
|
|
|
nameSpan.append(innernameSpan);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
linkElem.append(nameSpan);
|
|
|
|
|
if (extension) {
|
|
|
|
|
nameSpan.append($('<span></span>').addClass('extension').text(extension));
|
|
|
|
|
}
|
2014-08-27 09:28:31 +00:00
|
|
|
|
if (fileData.extraData) {
|
|
|
|
|
if (fileData.extraData.charAt(0) === '/') {
|
|
|
|
|
fileData.extraData = fileData.extraData.substr(1);
|
|
|
|
|
}
|
|
|
|
|
nameSpan.addClass('extra-data').attr('title', fileData.extraData);
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// dirs can show the number of uploaded files
|
|
|
|
|
if (type === 'dir') {
|
|
|
|
|
linkElem.append($('<span></span>').attr({
|
|
|
|
|
'class': 'uploadtext',
|
|
|
|
|
'currentUploads': 0
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
td.append(linkElem);
|
|
|
|
|
tr.append(td);
|
2014-02-12 13:50:23 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// size column
|
|
|
|
|
if (typeof(fileData.size) !== 'undefined' && fileData.size >= 0) {
|
2014-06-02 08:38:46 +00:00
|
|
|
|
simpleSize = humanFileSize(parseInt(fileData.size, 10), true);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
sizeColor = Math.round(160-Math.pow((fileData.size/(1024*1024)),2));
|
|
|
|
|
} else {
|
|
|
|
|
simpleSize = t('files', 'Pending');
|
|
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
td = $('<td></td>').attr({
|
|
|
|
|
"class": "filesize",
|
|
|
|
|
"style": 'color:rgb(' + sizeColor + ',' + sizeColor + ',' + sizeColor + ')'
|
|
|
|
|
}).text(simpleSize);
|
|
|
|
|
tr.append(td);
|
|
|
|
|
|
2014-07-02 15:20:56 +00:00
|
|
|
|
// date column (1000 milliseconds to seconds, 60 seconds, 60 minutes, 24 hours)
|
|
|
|
|
// difference in days multiplied by 5 - brightest shade for files older than 32 days (160/5)
|
|
|
|
|
var modifiedColor = Math.round(((new Date()).getTime() - mtime )/1000/60/60/24*5 );
|
2014-07-02 14:37:15 +00:00
|
|
|
|
// ensure that the brightest color is still readable
|
|
|
|
|
if (modifiedColor >= '160') {
|
|
|
|
|
modifiedColor = 160;
|
|
|
|
|
}
|
2014-12-05 13:54:43 +00:00
|
|
|
|
var formatted;
|
|
|
|
|
var text;
|
|
|
|
|
if (mtime > 0) {
|
|
|
|
|
formatted = formatDate(mtime);
|
|
|
|
|
text = OC.Util.relativeModifiedDate(mtime);
|
|
|
|
|
} else {
|
|
|
|
|
formatted = t('files', 'Unable to determine date');
|
|
|
|
|
text = '?';
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
td = $('<td></td>').attr({ "class": "date" });
|
|
|
|
|
td.append($('<span></span>').attr({
|
|
|
|
|
"class": "modified",
|
2014-12-05 13:54:43 +00:00
|
|
|
|
"title": formatted,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
"style": 'color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')'
|
2014-12-05 13:54:43 +00:00
|
|
|
|
}).text(text));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
tr.find('.filesize').text(simpleSize);
|
|
|
|
|
tr.append(td);
|
|
|
|
|
return tr;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds an entry to the files array and also into the DOM
|
|
|
|
|
* in a sorted manner.
|
|
|
|
|
*
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {OCA.Files.FileInfo} fileData map of file attributes
|
|
|
|
|
* @param {Object} [options] map of attributes
|
|
|
|
|
* @param {boolean} [options.updateSummary] true to update the summary
|
|
|
|
|
* after adding (default), false otherwise. Defaults to true.
|
|
|
|
|
* @param {boolean} [options.silent] true to prevent firing events like "fileActionsReady",
|
|
|
|
|
* defaults to false.
|
|
|
|
|
* @param {boolean} [options.animate] true to animate the thumbnail image after load
|
|
|
|
|
* defaults to true.
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* @return new tr element (not appended to the table)
|
|
|
|
|
*/
|
|
|
|
|
add: function(fileData, options) {
|
|
|
|
|
var index = -1;
|
|
|
|
|
var $tr;
|
|
|
|
|
var $rows;
|
|
|
|
|
var $insertionPoint;
|
2014-07-17 10:42:09 +00:00
|
|
|
|
options = _.extend({animate: true}, options || {});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
// there are three situations to cover:
|
|
|
|
|
// 1) insertion point is visible on the current page
|
|
|
|
|
// 2) insertion point is on a not visible page (visible after scrolling)
|
|
|
|
|
// 3) insertion point is at the end of the list
|
|
|
|
|
|
|
|
|
|
$rows = this.$fileList.children();
|
|
|
|
|
index = this._findInsertionIndex(fileData);
|
|
|
|
|
if (index > this.files.length) {
|
|
|
|
|
index = this.files.length;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$insertionPoint = $rows.eq(index);
|
|
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// is the insertion point visible ?
|
|
|
|
|
if ($insertionPoint.length) {
|
|
|
|
|
// only render if it will really be inserted
|
|
|
|
|
$tr = this._renderRow(fileData, options);
|
|
|
|
|
$insertionPoint.before($tr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// if insertion point is after the last visible
|
|
|
|
|
// entry, append
|
|
|
|
|
if (index === $rows.length) {
|
|
|
|
|
$tr = this._renderRow(fileData, options);
|
|
|
|
|
this.$fileList.append($tr);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-11 15:52:56 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.isEmpty = false;
|
|
|
|
|
this.files.splice(index, 0, fileData);
|
2014-02-11 15:52:56 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if ($tr && options.animate) {
|
|
|
|
|
$tr.addClass('appear transparent');
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
|
$tr.removeClass('transparent');
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-09-04 10:33:38 +00:00
|
|
|
|
if (options.scrollTo) {
|
|
|
|
|
this.scrollTo(fileData.name);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// defaults to true if not defined
|
|
|
|
|
if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) {
|
|
|
|
|
this.fileSummary.add(fileData, true);
|
|
|
|
|
this.updateEmptyContent();
|
|
|
|
|
}
|
2014-04-17 13:54:45 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
return $tr;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new row element based on the given attributes
|
|
|
|
|
* and returns it.
|
|
|
|
|
*
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {OCA.Files.FileInfo} fileData map of file attributes
|
|
|
|
|
* @param {Object} [options] map of attributes
|
|
|
|
|
* @param {int} [options.index] index at which to insert the element
|
|
|
|
|
* @param {boolean} [options.updateSummary] true to update the summary
|
|
|
|
|
* after adding (default), false otherwise. Defaults to true.
|
|
|
|
|
* @param {boolean} [options.animate] true to animate the thumbnail image after load
|
|
|
|
|
* defaults to true.
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* @return new tr element (not appended to the table)
|
|
|
|
|
*/
|
|
|
|
|
_renderRow: function(fileData, options) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
var type = fileData.type || 'file',
|
|
|
|
|
mime = fileData.mimetype,
|
2014-04-30 15:42:35 +00:00
|
|
|
|
path = fileData.path || this.getCurrentDirectory(),
|
2014-05-08 20:06:30 +00:00
|
|
|
|
permissions = parseInt(fileData.permissions, 10) || 0;
|
|
|
|
|
|
|
|
|
|
if (fileData.isShareMountPoint) {
|
|
|
|
|
permissions = permissions | OC.PERMISSION_UPDATE;
|
|
|
|
|
}
|
2014-04-17 13:54:45 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (type === 'dir') {
|
|
|
|
|
mime = mime || 'httpd/unix-directory';
|
|
|
|
|
}
|
|
|
|
|
var tr = this._createRow(
|
|
|
|
|
fileData,
|
|
|
|
|
options
|
|
|
|
|
);
|
|
|
|
|
var filenameTd = tr.find('td.filename');
|
|
|
|
|
|
|
|
|
|
// TODO: move dragging to FileActions ?
|
|
|
|
|
// enable drag only for deletable files
|
2014-05-12 17:54:20 +00:00
|
|
|
|
if (this._dragOptions && permissions & OC.PERMISSION_DELETE) {
|
|
|
|
|
filenameTd.draggable(this._dragOptions);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
// allow dropping on folders
|
2014-05-12 17:54:20 +00:00
|
|
|
|
if (this._folderDropOptions && fileData.type === 'dir') {
|
|
|
|
|
filenameTd.droppable(this._folderDropOptions);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (options.hidden) {
|
|
|
|
|
tr.addClass('hidden');
|
|
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// display actions
|
2014-05-19 13:20:44 +00:00
|
|
|
|
this.fileActions.display(filenameTd, !options.silent, this);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
if (fileData.isPreviewAvailable) {
|
2014-12-11 16:36:14 +00:00
|
|
|
|
var iconDiv = filenameTd.find('.thumbnail');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// lazy load / newly inserted td ?
|
2014-07-17 10:42:09 +00:00
|
|
|
|
if (options.animate) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.lazyLoadPreview({
|
2014-04-30 15:42:35 +00:00
|
|
|
|
path: path + '/' + fileData.name,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
mime: mime,
|
|
|
|
|
etag: fileData.etag,
|
|
|
|
|
callback: function(url) {
|
2014-12-11 16:36:14 +00:00
|
|
|
|
iconDiv.css('background-image', 'url(' + url + ')');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// set the preview URL directly
|
|
|
|
|
var urlSpec = {
|
2014-04-30 15:42:35 +00:00
|
|
|
|
file: path + '/' + fileData.name,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
c: fileData.etag
|
|
|
|
|
};
|
|
|
|
|
var previewUrl = this.generatePreviewUrl(urlSpec);
|
|
|
|
|
previewUrl = previewUrl.replace('(', '%28').replace(')', '%29');
|
2014-12-11 16:36:14 +00:00
|
|
|
|
iconDiv.css('background-image', 'url(' + previewUrl + ')');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tr;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Returns the current directory
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @method getCurrentDirectory
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* @return current directory
|
|
|
|
|
*/
|
|
|
|
|
getCurrentDirectory: function(){
|
|
|
|
|
return this._currentDirectory || this.$el.find('#dir').val() || '/';
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Returns the directory permissions
|
|
|
|
|
* @return permission value as integer
|
|
|
|
|
*/
|
|
|
|
|
getDirectoryPermissions: function() {
|
|
|
|
|
return parseInt(this.$el.find('#permissions').val(), 10);
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* @brief Changes the current directory and reload the file list.
|
|
|
|
|
* @param targetDir target directory (non URL encoded)
|
|
|
|
|
* @param changeUrl false if the URL must not be changed (defaults to true)
|
|
|
|
|
* @param {boolean} force set to true to force changing directory
|
|
|
|
|
*/
|
|
|
|
|
changeDirectory: function(targetDir, changeUrl, force) {
|
2014-06-30 14:27:31 +00:00
|
|
|
|
var self = this;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var currentDir = this.getCurrentDirectory();
|
|
|
|
|
targetDir = targetDir || '/';
|
|
|
|
|
if (!force && currentDir === targetDir) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this._setCurrentDir(targetDir, changeUrl);
|
2014-06-30 14:27:31 +00:00
|
|
|
|
this.reload().then(function(success){
|
|
|
|
|
if (!success) {
|
|
|
|
|
self.changeDirectory(currentDir, true);
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
linkTo: function(dir) {
|
|
|
|
|
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the current directory name and updates the breadcrumb.
|
|
|
|
|
* @param targetDir directory to display
|
|
|
|
|
* @param changeUrl true to also update the URL, false otherwise (default)
|
|
|
|
|
*/
|
|
|
|
|
_setCurrentDir: function(targetDir, changeUrl) {
|
2014-05-12 17:54:20 +00:00
|
|
|
|
var previousDir = this.getCurrentDirectory(),
|
2014-05-08 20:06:30 +00:00
|
|
|
|
baseDir = OC.basename(targetDir);
|
|
|
|
|
|
|
|
|
|
if (baseDir !== '') {
|
|
|
|
|
this.setPageTitle(baseDir);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.setPageTitle();
|
|
|
|
|
}
|
2014-04-07 21:45:35 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this._currentDirectory = targetDir;
|
2014-04-04 12:34:07 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// legacy stuff
|
|
|
|
|
this.$el.find('#dir').val(targetDir);
|
2014-04-04 14:11:31 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (changeUrl !== false) {
|
|
|
|
|
this.$el.trigger(jQuery.Event('changeDirectory', {
|
|
|
|
|
dir: targetDir,
|
|
|
|
|
previousDir: previousDir
|
|
|
|
|
}));
|
2014-04-04 12:34:07 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.breadcrumb.setDirectory(this.getCurrentDirectory());
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Sets the current sorting and refreshes the list
|
|
|
|
|
*
|
|
|
|
|
* @param sort sort attribute name
|
|
|
|
|
* @param direction sort direction, one of "asc" or "desc"
|
2014-08-15 14:52:41 +00:00
|
|
|
|
* @param update true to update the list, false otherwise (default)
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
2014-08-15 14:52:41 +00:00
|
|
|
|
setSort: function(sort, direction, update) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var comparator = FileList.Comparators[sort] || FileList.Comparators.name;
|
|
|
|
|
this._sort = sort;
|
|
|
|
|
this._sortDirection = (direction === 'desc')?'desc':'asc';
|
|
|
|
|
this._sortComparator = comparator;
|
2014-07-17 10:48:50 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (direction === 'desc') {
|
|
|
|
|
this._sortComparator = function(fileInfo1, fileInfo2) {
|
|
|
|
|
return -comparator(fileInfo1, fileInfo2);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
this.$el.find('thead th .sort-indicator')
|
2014-07-17 10:48:50 +00:00
|
|
|
|
.removeClass(this.SORT_INDICATOR_ASC_CLASS)
|
|
|
|
|
.removeClass(this.SORT_INDICATOR_DESC_CLASS)
|
|
|
|
|
.toggleClass('hidden', true)
|
|
|
|
|
.addClass(this.SORT_INDICATOR_DESC_CLASS);
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.find('thead th.column-' + sort + ' .sort-indicator')
|
2014-07-17 10:48:50 +00:00
|
|
|
|
.removeClass(this.SORT_INDICATOR_ASC_CLASS)
|
|
|
|
|
.removeClass(this.SORT_INDICATOR_DESC_CLASS)
|
|
|
|
|
.toggleClass('hidden', false)
|
2014-05-08 20:06:30 +00:00
|
|
|
|
.addClass(direction === 'desc' ? this.SORT_INDICATOR_DESC_CLASS : this.SORT_INDICATOR_ASC_CLASS);
|
2014-08-15 14:52:41 +00:00
|
|
|
|
if (update) {
|
|
|
|
|
if (this._clientSideSort) {
|
|
|
|
|
this.files.sort(this._sortComparator);
|
|
|
|
|
this.setFiles(this.files);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.reload();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
2014-07-17 10:48:50 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
2014-07-04 09:45:36 +00:00
|
|
|
|
* Reloads the file list using ajax call
|
|
|
|
|
*
|
|
|
|
|
* @return ajax call object
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
reload: function() {
|
|
|
|
|
this._selectedFiles = {};
|
|
|
|
|
this._selectionSummary.clear();
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$el.find('.select-all').prop('checked', false);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.showMask();
|
|
|
|
|
if (this._reloadCall) {
|
|
|
|
|
this._reloadCall.abort();
|
|
|
|
|
}
|
|
|
|
|
this._reloadCall = $.ajax({
|
|
|
|
|
url: this.getAjaxUrl('list'),
|
|
|
|
|
data: {
|
|
|
|
|
dir : this.getCurrentDirectory(),
|
|
|
|
|
sort: this._sort,
|
|
|
|
|
sortdirection: this._sortDirection
|
|
|
|
|
}
|
2014-04-04 14:11:31 +00:00
|
|
|
|
});
|
2014-06-30 14:27:31 +00:00
|
|
|
|
var callBack = this.reloadCallback.bind(this);
|
|
|
|
|
return this._reloadCall.then(callBack, callBack);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
reloadCallback: function(result) {
|
|
|
|
|
delete this._reloadCall;
|
|
|
|
|
this.hideMask();
|
|
|
|
|
|
|
|
|
|
if (!result || result.status === 'error') {
|
2014-07-04 12:08:48 +00:00
|
|
|
|
// if the error is not related to folder we're trying to load, reload the page to handle logout etc
|
|
|
|
|
if (result.data.error === 'authentication_error' ||
|
|
|
|
|
result.data.error === 'token_expired' ||
|
|
|
|
|
result.data.error === 'application_not_enabled'
|
|
|
|
|
) {
|
|
|
|
|
OC.redirect(OC.generateUrl('apps/files'));
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
OC.Notification.show(result.data.message);
|
2014-06-30 14:27:31 +00:00
|
|
|
|
return false;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2014-04-17 13:54:45 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (result.status === 404) {
|
|
|
|
|
// go back home
|
|
|
|
|
this.changeDirectory('/');
|
2014-06-30 14:27:31 +00:00
|
|
|
|
return false;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
// aborted ?
|
|
|
|
|
if (result.status === 0){
|
2014-06-30 14:27:31 +00:00
|
|
|
|
return true;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2013-02-22 16:21:57 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// TODO: should rather return upload file size through
|
|
|
|
|
// the files list ajax call
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.updateStorageStatistics(true);
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (result.data.permissions) {
|
|
|
|
|
this.setDirectoryPermissions(result.data.permissions);
|
|
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.setFiles(result.data.files);
|
2014-07-04 12:08:48 +00:00
|
|
|
|
return true;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
updateStorageStatistics: function(force) {
|
|
|
|
|
OCA.Files.Files.updateStorageStatistics(this.getCurrentDirectory(), force);
|
|
|
|
|
},
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
getAjaxUrl: function(action, params) {
|
2014-05-12 17:54:20 +00:00
|
|
|
|
return OCA.Files.Files.getAjaxUrl(action, params);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getDownloadUrl: function(files, dir) {
|
2014-05-12 17:54:20 +00:00
|
|
|
|
return OCA.Files.Files.getDownloadUrl(files, dir || this.getCurrentDirectory());
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a preview URL based on the URL space.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param urlSpec attributes for the URL
|
|
|
|
|
* @param {int} urlSpec.x width
|
|
|
|
|
* @param {int} urlSpec.y height
|
|
|
|
|
* @param {String} urlSpec.file path to the file
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* @return preview URL
|
|
|
|
|
*/
|
|
|
|
|
generatePreviewUrl: function(urlSpec) {
|
|
|
|
|
urlSpec = urlSpec || {};
|
|
|
|
|
if (!urlSpec.x) {
|
|
|
|
|
urlSpec.x = this.$table.data('preview-x') || 36;
|
2013-10-28 19:22:06 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (!urlSpec.y) {
|
|
|
|
|
urlSpec.y = this.$table.data('preview-y') || 36;
|
2013-10-28 19:22:06 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
urlSpec.y *= window.devicePixelRatio;
|
|
|
|
|
urlSpec.x *= window.devicePixelRatio;
|
|
|
|
|
urlSpec.forceIcon = 0;
|
|
|
|
|
return OC.generateUrl('/core/preview.png?') + $.param(urlSpec);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lazy load a file's preview.
|
2014-05-26 18:32:24 +00:00
|
|
|
|
*
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* @param path path of the file
|
|
|
|
|
* @param mime mime type
|
|
|
|
|
* @param callback callback function to call when the image was loaded
|
|
|
|
|
* @param etag file etag (for caching)
|
|
|
|
|
*/
|
|
|
|
|
lazyLoadPreview : function(options) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var path = options.path;
|
|
|
|
|
var mime = options.mime;
|
|
|
|
|
var ready = options.callback;
|
|
|
|
|
var etag = options.etag;
|
|
|
|
|
|
|
|
|
|
// get mime icon url
|
|
|
|
|
OCA.Files.Files.getMimeIcon(mime, function(iconURL) {
|
|
|
|
|
var previewURL,
|
|
|
|
|
urlSpec = {};
|
|
|
|
|
ready(iconURL); // set mimeicon URL
|
|
|
|
|
|
|
|
|
|
urlSpec.file = OCA.Files.Files.fixPath(path);
|
|
|
|
|
|
|
|
|
|
if (etag){
|
|
|
|
|
// use etag as cache buster
|
|
|
|
|
urlSpec.c = etag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.warn('OCA.Files.FileList.lazyLoadPreview(): missing etag argument');
|
|
|
|
|
}
|
2014-02-20 14:16:45 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
previewURL = self.generatePreviewUrl(urlSpec);
|
|
|
|
|
previewURL = previewURL.replace('(', '%28');
|
|
|
|
|
previewURL = previewURL.replace(')', '%29');
|
|
|
|
|
|
|
|
|
|
// preload image to prevent delay
|
|
|
|
|
// this will make the browser cache the image
|
|
|
|
|
var img = new Image();
|
|
|
|
|
img.onload = function(){
|
|
|
|
|
// if loading the preview image failed (no preview for the mimetype) then img.width will < 5
|
|
|
|
|
if (img.width > 5) {
|
|
|
|
|
ready(previewURL);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
img.src = previewURL;
|
|
|
|
|
});
|
|
|
|
|
},
|
2014-02-20 14:16:45 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
setDirectoryPermissions: function(permissions) {
|
|
|
|
|
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
|
|
|
|
this.$el.find('#permissions').val(permissions);
|
|
|
|
|
this.$el.find('.creatable').toggleClass('hidden', !isCreatable);
|
|
|
|
|
this.$el.find('.notCreatable').toggleClass('hidden', isCreatable);
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Shows/hides action buttons
|
|
|
|
|
*
|
|
|
|
|
* @param show true for enabling, false for disabling
|
|
|
|
|
*/
|
|
|
|
|
showActions: function(show){
|
|
|
|
|
this.$el.find('.actions,#file_action_panel').toggleClass('hidden', !show);
|
|
|
|
|
if (show){
|
|
|
|
|
// make sure to display according to permissions
|
|
|
|
|
var permissions = this.getDirectoryPermissions();
|
|
|
|
|
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
|
|
|
|
this.$el.find('.creatable').toggleClass('hidden', !isCreatable);
|
|
|
|
|
this.$el.find('.notCreatable').toggleClass('hidden', isCreatable);
|
|
|
|
|
// remove old style breadcrumbs (some apps might create them)
|
|
|
|
|
this.$el.find('#controls .crumb').remove();
|
|
|
|
|
// refresh breadcrumbs in case it was replaced by an app
|
|
|
|
|
this.breadcrumb.render();
|
2013-08-29 19:56:14 +00:00
|
|
|
|
}
|
|
|
|
|
else{
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.find('.creatable, .notCreatable').addClass('hidden');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Enables/disables viewer mode.
|
|
|
|
|
* In viewer mode, apps can embed themselves under the controls bar.
|
|
|
|
|
* In viewer mode, the actions of the file list will be hidden.
|
|
|
|
|
* @param show true for enabling, false for disabling
|
|
|
|
|
*/
|
|
|
|
|
setViewerMode: function(show){
|
|
|
|
|
this.showActions(!show);
|
|
|
|
|
this.$el.find('#filestable').toggleClass('hidden', show);
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$el.trigger(new $.Event('changeViewerMode', {viewerModeEnabled: show}));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Removes a file entry from the list
|
|
|
|
|
* @param name name of the file to remove
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {Object} [options] map of attributes
|
|
|
|
|
* @param {boolean} [options.updateSummary] true to update the summary
|
|
|
|
|
* after removing, false otherwise. Defaults to true.
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* @return deleted element
|
|
|
|
|
*/
|
|
|
|
|
remove: function(name, options){
|
|
|
|
|
options = options || {};
|
|
|
|
|
var fileEl = this.findFileEl(name);
|
|
|
|
|
var index = fileEl.index();
|
|
|
|
|
if (!fileEl.length) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (this._selectedFiles[fileEl.data('id')]) {
|
|
|
|
|
// remove from selection first
|
|
|
|
|
this._selectFileEl(fileEl, false);
|
|
|
|
|
this.updateSelectionSummary();
|
|
|
|
|
}
|
2014-05-12 17:54:20 +00:00
|
|
|
|
if (this._dragOptions && (fileEl.data('permissions') & OC.PERMISSION_DELETE)) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// file is only draggable when delete permissions are set
|
|
|
|
|
fileEl.find('td.filename').draggable('destroy');
|
|
|
|
|
}
|
|
|
|
|
this.files.splice(index, 1);
|
|
|
|
|
fileEl.remove();
|
|
|
|
|
// TODO: improve performance on batch update
|
|
|
|
|
this.isEmpty = !this.files.length;
|
|
|
|
|
if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) {
|
|
|
|
|
this.updateEmptyContent();
|
|
|
|
|
this.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')}, true);
|
2013-08-29 19:56:14 +00:00
|
|
|
|
}
|
2013-08-17 11:07:18 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var lastIndex = this.$fileList.children().length;
|
|
|
|
|
// if there are less elements visible than one page
|
|
|
|
|
// but there are still pending elements in the array,
|
|
|
|
|
// then directly append the next page
|
2014-10-11 13:10:54 +00:00
|
|
|
|
if (lastIndex < this.files.length && lastIndex < this.pageSize()) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this._nextPage(true);
|
|
|
|
|
}
|
2013-08-17 11:07:18 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
return fileEl;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Finds the index of the row before which the given
|
|
|
|
|
* fileData should be inserted, considering the current
|
|
|
|
|
* sorting
|
2014-06-23 21:56:10 +00:00
|
|
|
|
*
|
|
|
|
|
* @param {OCA.Files.FileInfo} fileData file info
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
_findInsertionIndex: function(fileData) {
|
|
|
|
|
var index = 0;
|
|
|
|
|
while (index < this.files.length && this._sortComparator(fileData, this.files[index]) > 0) {
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
return index;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Moves a file to a given target folder.
|
|
|
|
|
*
|
|
|
|
|
* @param fileNames array of file names to move
|
|
|
|
|
* @param targetPath absolute target path
|
|
|
|
|
*/
|
|
|
|
|
move: function(fileNames, targetPath) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var dir = this.getCurrentDirectory();
|
|
|
|
|
var target = OC.basename(targetPath);
|
|
|
|
|
if (!_.isArray(fileNames)) {
|
|
|
|
|
fileNames = [fileNames];
|
|
|
|
|
}
|
|
|
|
|
_.each(fileNames, function(fileName) {
|
|
|
|
|
var $tr = self.findFileEl(fileName);
|
2014-12-17 12:12:57 +00:00
|
|
|
|
var $thumbEl = $tr.find('.thumbnail');
|
|
|
|
|
var oldBackgroundImage = $thumbEl.css('background-image');
|
|
|
|
|
$thumbEl.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// TODO: improve performance by sending all file names in a single call
|
|
|
|
|
$.post(
|
|
|
|
|
OC.filePath('files', 'ajax', 'move.php'),
|
|
|
|
|
{
|
|
|
|
|
dir: dir,
|
|
|
|
|
file: fileName,
|
|
|
|
|
target: targetPath
|
|
|
|
|
},
|
|
|
|
|
function(result) {
|
|
|
|
|
if (result) {
|
|
|
|
|
if (result.status === 'success') {
|
|
|
|
|
// if still viewing the same directory
|
|
|
|
|
if (self.getCurrentDirectory() === dir) {
|
|
|
|
|
// recalculate folder size
|
|
|
|
|
var oldFile = self.findFileEl(target);
|
|
|
|
|
var newFile = self.findFileEl(fileName);
|
|
|
|
|
var oldSize = oldFile.data('size');
|
|
|
|
|
var newSize = oldSize + newFile.data('size');
|
|
|
|
|
oldFile.data('size', newSize);
|
|
|
|
|
oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize));
|
|
|
|
|
|
|
|
|
|
// TODO: also update entry in FileList.files
|
|
|
|
|
|
|
|
|
|
self.remove(fileName);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
OC.Notification.hide();
|
|
|
|
|
if (result.status === 'error' && result.data.message) {
|
|
|
|
|
OC.Notification.show(result.data.message);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
OC.Notification.show(t('files', 'Error moving file.'));
|
|
|
|
|
}
|
|
|
|
|
// hide notification after 10 sec
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
OC.Notification.hide();
|
|
|
|
|
}, 10000);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error'));
|
|
|
|
|
}
|
2014-12-17 12:12:57 +00:00
|
|
|
|
$thumbEl.css('background-image', oldBackgroundImage);
|
2014-05-12 17:54:20 +00:00
|
|
|
|
}
|
|
|
|
|
);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
});
|
2013-11-06 09:55:19 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Triggers file rename input field for the given file name.
|
|
|
|
|
* If the user enters a new name, the file will be renamed.
|
|
|
|
|
*
|
|
|
|
|
* @param oldname file name of the file to rename
|
|
|
|
|
*/
|
|
|
|
|
rename: function(oldname) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var tr, td, input, form;
|
|
|
|
|
tr = this.findFileEl(oldname);
|
|
|
|
|
var oldFileInfo = this.files[tr.index()];
|
|
|
|
|
tr.data('renaming',true);
|
|
|
|
|
td = tr.children('td.filename');
|
|
|
|
|
input = $('<input type="text" class="filename"/>').val(oldname);
|
|
|
|
|
form = $('<form></form>');
|
|
|
|
|
form.append(input);
|
|
|
|
|
td.children('a.name').hide();
|
|
|
|
|
td.append(form);
|
|
|
|
|
input.focus();
|
|
|
|
|
//preselect input
|
|
|
|
|
var len = input.val().lastIndexOf('.');
|
|
|
|
|
if ( len === -1 ||
|
|
|
|
|
tr.data('type') === 'dir' ) {
|
|
|
|
|
len = input.val().length;
|
|
|
|
|
}
|
|
|
|
|
input.selectRange(0, len);
|
|
|
|
|
var checkInput = function () {
|
|
|
|
|
var filename = input.val();
|
|
|
|
|
if (filename !== oldname) {
|
|
|
|
|
// Files.isFileNameValid(filename) throws an exception itself
|
2014-05-12 17:54:20 +00:00
|
|
|
|
OCA.Files.Files.isFileNameValid(filename);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (self.inList(filename)) {
|
|
|
|
|
throw t('files', '{new_name} already exists', {new_name: filename});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
};
|
2013-08-27 09:18:59 +00:00
|
|
|
|
|
2014-06-23 14:35:11 +00:00
|
|
|
|
function restore() {
|
|
|
|
|
input.tipsy('hide');
|
|
|
|
|
tr.data('renaming',false);
|
|
|
|
|
form.remove();
|
|
|
|
|
td.children('a.name').show();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
form.submit(function(event) {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
2014-06-23 14:35:11 +00:00
|
|
|
|
if (input.hasClass('error')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
try {
|
|
|
|
|
var newName = input.val();
|
2014-12-17 12:12:57 +00:00
|
|
|
|
var $thumbEl = tr.find('.thumbnail');
|
2014-05-16 10:43:36 +00:00
|
|
|
|
input.tipsy('hide');
|
|
|
|
|
form.remove();
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (newName !== oldname) {
|
|
|
|
|
checkInput();
|
2014-05-16 10:43:36 +00:00
|
|
|
|
// mark as loading (temp element)
|
2014-12-17 12:12:57 +00:00
|
|
|
|
$thumbEl.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
|
2014-05-16 10:43:36 +00:00
|
|
|
|
tr.attr('data-file', newName);
|
|
|
|
|
var basename = newName;
|
|
|
|
|
if (newName.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
|
|
|
|
basename = newName.substr(0, newName.lastIndexOf('.'));
|
|
|
|
|
}
|
|
|
|
|
td.find('a.name span.nametext').text(basename);
|
|
|
|
|
td.children('a.name').show();
|
|
|
|
|
tr.find('.fileactions, .action').addClass('hidden');
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
$.ajax({
|
|
|
|
|
url: OC.filePath('files','ajax','rename.php'),
|
|
|
|
|
data: {
|
2014-06-06 13:13:02 +00:00
|
|
|
|
dir : tr.attr('data-path') || self.getCurrentDirectory(),
|
2014-05-08 20:06:30 +00:00
|
|
|
|
newname: newName,
|
|
|
|
|
file: oldname
|
|
|
|
|
},
|
|
|
|
|
success: function(result) {
|
|
|
|
|
var fileInfo;
|
|
|
|
|
if (!result || result.status === 'error') {
|
2014-08-11 23:13:30 +00:00
|
|
|
|
OC.dialogs.alert(result.data.message, t('files', 'Could not rename file'));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
fileInfo = oldFileInfo;
|
2014-08-08 14:11:07 +00:00
|
|
|
|
if (result.data.code === 'sourcenotfound') {
|
|
|
|
|
self.remove(result.data.newname, {updateSummary: true});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fileInfo = result.data;
|
|
|
|
|
}
|
|
|
|
|
// reinsert row
|
|
|
|
|
self.files.splice(tr.index(), 1);
|
|
|
|
|
tr.remove();
|
2014-07-01 19:32:04 +00:00
|
|
|
|
tr = self.add(fileInfo, {updateSummary: false, silent: true});
|
|
|
|
|
self.$fileList.trigger($.Event('fileActionsReady', {fileList: self, $files: $(tr)}));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-05-16 10:43:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
// add back the old file info when cancelled
|
|
|
|
|
self.files.splice(tr.index(), 1);
|
|
|
|
|
tr.remove();
|
2014-07-01 19:32:04 +00:00
|
|
|
|
tr = self.add(oldFileInfo, {updateSummary: false, silent: true});
|
|
|
|
|
self.$fileList.trigger($.Event('fileActionsReady', {fileList: self, $files: $(tr)}));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
input.attr('title', error);
|
|
|
|
|
input.tipsy({gravity: 'w', trigger: 'manual'});
|
|
|
|
|
input.tipsy('show');
|
|
|
|
|
input.addClass('error');
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
input.keyup(function(event) {
|
|
|
|
|
// verify filename on typing
|
|
|
|
|
try {
|
|
|
|
|
checkInput();
|
|
|
|
|
input.tipsy('hide');
|
|
|
|
|
input.removeClass('error');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
input.attr('title', error);
|
|
|
|
|
input.tipsy({gravity: 'w', trigger: 'manual'});
|
|
|
|
|
input.tipsy('show');
|
|
|
|
|
input.addClass('error');
|
|
|
|
|
}
|
|
|
|
|
if (event.keyCode === 27) {
|
2014-06-23 14:35:11 +00:00
|
|
|
|
restore();
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
input.click(function(event) {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
input.blur(function() {
|
|
|
|
|
form.trigger('submit');
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
inList:function(file) {
|
|
|
|
|
return this.findFileEl(file).length;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Delete the given files from the given dir
|
|
|
|
|
* @param files file names list (without path)
|
|
|
|
|
* @param dir directory in which to delete the files, defaults to the current
|
|
|
|
|
* directory
|
|
|
|
|
*/
|
|
|
|
|
do_delete:function(files, dir) {
|
|
|
|
|
var self = this;
|
|
|
|
|
var params;
|
|
|
|
|
if (files && files.substr) {
|
|
|
|
|
files=[files];
|
|
|
|
|
}
|
|
|
|
|
if (files) {
|
|
|
|
|
for (var i=0; i<files.length; i++) {
|
|
|
|
|
var deleteAction = this.findFileEl(files[i]).children("td.date").children(".action.delete");
|
2014-09-22 16:24:32 +00:00
|
|
|
|
deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Finish any existing actions
|
|
|
|
|
if (this.lastAction) {
|
|
|
|
|
this.lastAction();
|
|
|
|
|
}
|
2014-04-04 14:38:27 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
params = {
|
|
|
|
|
dir: dir || this.getCurrentDirectory()
|
|
|
|
|
};
|
|
|
|
|
if (files) {
|
|
|
|
|
params.files = JSON.stringify(files);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// no files passed, delete all in current dir
|
|
|
|
|
params.allfiles = true;
|
|
|
|
|
// show spinner for all files
|
2014-09-22 16:24:32 +00:00
|
|
|
|
this.$fileList.find('tr>td.date .action.delete').removeClass('icon-delete').addClass('icon-loading-small');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2014-04-04 14:38:27 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
$.post(OC.filePath('files', 'ajax', 'delete.php'),
|
|
|
|
|
params,
|
|
|
|
|
function(result) {
|
2014-04-11 10:46:12 +00:00
|
|
|
|
if (result.status === 'success') {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (params.allfiles) {
|
|
|
|
|
self.setFiles([]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$.each(files,function(index,file) {
|
|
|
|
|
var fileEl = self.remove(file, {updateSummary: false});
|
|
|
|
|
// FIXME: not sure why we need this after the
|
|
|
|
|
// element isn't even in the DOM any more
|
2014-12-11 17:20:04 +00:00
|
|
|
|
fileEl.find('.selectCheckBox').prop('checked', false);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
fileEl.removeClass('selected');
|
|
|
|
|
self.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')});
|
|
|
|
|
});
|
2014-04-11 10:46:12 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// TODO: this info should be returned by the ajax call!
|
|
|
|
|
self.updateEmptyContent();
|
|
|
|
|
self.fileSummary.update();
|
|
|
|
|
self.updateSelectionSummary();
|
2014-05-12 17:54:20 +00:00
|
|
|
|
self.updateStorageStatistics();
|
2014-04-11 10:46:12 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (result.status === 'error' && result.data.message) {
|
|
|
|
|
OC.Notification.show(result.data.message);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
OC.Notification.show(t('files', 'Error deleting file.'));
|
2014-04-11 10:46:12 +00:00
|
|
|
|
}
|
|
|
|
|
// hide notification after 10 sec
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
OC.Notification.hide();
|
|
|
|
|
}, 10000);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (params.allfiles) {
|
|
|
|
|
// reload the page as we don't know what files were deleted
|
|
|
|
|
// and which ones remain
|
|
|
|
|
self.reload();
|
2013-11-27 20:34:19 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
$.each(files,function(index,file) {
|
|
|
|
|
var deleteAction = self.findFileEl(file).find('.action.delete');
|
2014-09-22 16:24:32 +00:00
|
|
|
|
deleteAction.removeClass('icon-loading-small').addClass('icon-delete');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
});
|
2013-05-02 22:15:28 +00:00
|
|
|
|
}
|
2012-07-30 16:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Creates the file summary section
|
|
|
|
|
*/
|
|
|
|
|
_createSummary: function() {
|
|
|
|
|
var $tr = $('<tr class="summary"></tr>');
|
|
|
|
|
this.$el.find('tfoot').append($tr);
|
|
|
|
|
|
|
|
|
|
return new OCA.Files.FileSummary($tr);
|
|
|
|
|
},
|
|
|
|
|
updateEmptyContent: function() {
|
|
|
|
|
var permissions = this.getDirectoryPermissions();
|
|
|
|
|
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
|
|
|
|
this.$el.find('#emptycontent').toggleClass('hidden', !isCreatable || !this.isEmpty);
|
|
|
|
|
this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Shows the loading mask.
|
|
|
|
|
*
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @see OCA.Files.FileList#hideMask
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
showMask: function() {
|
|
|
|
|
// in case one was shown before
|
|
|
|
|
var $mask = this.$el.find('.mask');
|
|
|
|
|
if ($mask.exists()) {
|
|
|
|
|
return;
|
2014-02-13 19:20:00 +00:00
|
|
|
|
}
|
2012-10-14 19:04:08 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$table.addClass('hidden');
|
|
|
|
|
|
|
|
|
|
$mask = $('<div class="mask transparent"></div>');
|
|
|
|
|
|
|
|
|
|
$mask.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
|
|
|
|
|
$mask.css('background-repeat', 'no-repeat');
|
|
|
|
|
this.$el.append($mask);
|
|
|
|
|
|
|
|
|
|
$mask.removeClass('transparent');
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Hide the loading mask.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @see OCA.Files.FileList#showMask
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
hideMask: function() {
|
|
|
|
|
this.$el.find('.mask').remove();
|
|
|
|
|
this.$table.removeClass('hidden');
|
|
|
|
|
},
|
|
|
|
|
scrollTo:function(file) {
|
2014-09-04 10:20:11 +00:00
|
|
|
|
if (!_.isArray(file)) {
|
|
|
|
|
file = [file];
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2014-09-04 10:20:11 +00:00
|
|
|
|
this.highlightFiles(file, function($tr) {
|
|
|
|
|
$tr.addClass('searchresult');
|
|
|
|
|
$tr.one('hover', function() {
|
|
|
|
|
$tr.removeClass('searchresult');
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
2014-12-18 09:26:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* @deprecated use setFilter(filter)
|
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
|
filter:function(query) {
|
2014-12-18 09:26:41 +00:00
|
|
|
|
this.setFilter('');
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated use setFilter('')
|
|
|
|
|
*/
|
|
|
|
|
unfilter:function() {
|
|
|
|
|
this.setFilter('');
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* hide files matching the given filter
|
|
|
|
|
* @param filter
|
|
|
|
|
*/
|
|
|
|
|
setFilter:function(filter) {
|
|
|
|
|
this._filter = filter;
|
2014-12-18 22:11:42 +00:00
|
|
|
|
this.fileSummary.setFilter(filter, this.files);
|
2014-12-18 23:49:05 +00:00
|
|
|
|
this.hideIrrelevantUIWhenNoFilesMatch();
|
2014-12-18 09:26:41 +00:00
|
|
|
|
var that = this;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$fileList.find('tr').each(function(i,e) {
|
2014-12-18 09:26:41 +00:00
|
|
|
|
var $e = $(e);
|
|
|
|
|
if ($e.data('file').toString().toLowerCase().indexOf(filter.toLowerCase()) === -1) {
|
|
|
|
|
$e.addClass('hidden');
|
|
|
|
|
that.$container.trigger('scroll');
|
|
|
|
|
} else {
|
|
|
|
|
$e.removeClass('hidden');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2013-07-31 20:24:52 +00:00
|
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
2014-12-18 23:49:05 +00:00
|
|
|
|
hideIrrelevantUIWhenNoFilesMatch:function() {
|
2014-12-18 22:11:42 +00:00
|
|
|
|
if (this._filter && this.fileSummary.summary.totalDirs + this.fileSummary.summary.totalFiles === 0) {
|
|
|
|
|
this.$el.find('#filestable thead th').addClass('hidden');
|
2014-12-18 23:49:05 +00:00
|
|
|
|
this.$el.find('#emptycontent').addClass('hidden');
|
2015-01-02 11:50:21 +00:00
|
|
|
|
if ( $('#searchresults').length === 0 || $('#searchresults').hasClass('hidden')) {
|
|
|
|
|
this.$el.find('#nofilterresults').removeClass('hidden').
|
2015-01-02 13:59:55 +00:00
|
|
|
|
find('p').text(t('files', "No entries in this folder match '{filter}'", {filter:this._filter}));
|
2015-01-02 11:50:21 +00:00
|
|
|
|
}
|
2014-12-18 22:11:42 +00:00
|
|
|
|
} else {
|
2014-12-18 23:49:05 +00:00
|
|
|
|
this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
|
|
|
|
|
this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
|
2015-01-02 11:50:21 +00:00
|
|
|
|
this.$el.find('#nofilterresults').addClass('hidden');
|
2014-12-18 22:11:42 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2014-12-18 09:26:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* get the current filter
|
|
|
|
|
* @param filter
|
|
|
|
|
*/
|
|
|
|
|
getFilter:function(filter) {
|
|
|
|
|
return this._filter;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Update UI based on the current selection
|
|
|
|
|
*/
|
|
|
|
|
updateSelectionSummary: function() {
|
|
|
|
|
var summary = this._selectionSummary.summary;
|
2014-05-12 17:54:20 +00:00
|
|
|
|
var canDelete;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (summary.totalFiles === 0 && summary.totalDirs === 0) {
|
|
|
|
|
this.$el.find('#headerName a.name>span:first').text(t('files','Name'));
|
|
|
|
|
this.$el.find('#headerSize a>span:first').text(t('files','Size'));
|
|
|
|
|
this.$el.find('#modified a>span:first').text(t('files','Modified'));
|
|
|
|
|
this.$el.find('table').removeClass('multiselect');
|
|
|
|
|
this.$el.find('.selectedActions').addClass('hidden');
|
2013-07-31 20:24:52 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
else {
|
2014-11-20 15:53:32 +00:00
|
|
|
|
canDelete = (this.getDirectoryPermissions() & OC.PERMISSION_DELETE) && this.isSelectedDeletable();
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.find('.selectedActions').removeClass('hidden');
|
|
|
|
|
this.$el.find('#headerSize a>span:first').text(OC.Util.humanFileSize(summary.totalSize));
|
|
|
|
|
var selection = '';
|
|
|
|
|
if (summary.totalDirs > 0) {
|
|
|
|
|
selection += n('files', '%n folder', '%n folders', summary.totalDirs);
|
|
|
|
|
if (summary.totalFiles > 0) {
|
|
|
|
|
selection += ' & ';
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
|
if (summary.totalFiles > 0) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
selection += n('files', '%n file', '%n files', summary.totalFiles);
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
this.$el.find('#headerName a.name>span:first').text(selection);
|
|
|
|
|
this.$el.find('#modified a>span:first').text('');
|
|
|
|
|
this.$el.find('table').addClass('multiselect');
|
2014-05-12 17:54:20 +00:00
|
|
|
|
this.$el.find('.delete-selected').toggleClass('hidden', !canDelete);
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
2014-11-20 15:53:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* Check whether all selected files are deletable
|
|
|
|
|
*/
|
|
|
|
|
isSelectedDeletable: function() {
|
|
|
|
|
return _.reduce(this.getSelectedFiles(), function(deletable, file) {
|
|
|
|
|
return deletable && (file.permissions & OC.PERMISSION_DELETE);
|
|
|
|
|
}, true);
|
|
|
|
|
},
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns whether all files are selected
|
|
|
|
|
* @return true if all files are selected, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
isAllSelected: function() {
|
2014-05-12 17:54:20 +00:00
|
|
|
|
return this.$el.find('.select-all').prop('checked');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the file info of the selected files
|
|
|
|
|
*
|
|
|
|
|
* @return array of file names
|
|
|
|
|
*/
|
|
|
|
|
getSelectedFiles: function() {
|
|
|
|
|
return _.values(this._selectedFiles);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getUniqueName: function(name) {
|
|
|
|
|
if (this.findFileEl(name).exists()) {
|
|
|
|
|
var numMatch;
|
|
|
|
|
var parts=name.split('.');
|
|
|
|
|
var extension = "";
|
|
|
|
|
if (parts.length > 1) {
|
|
|
|
|
extension=parts.pop();
|
|
|
|
|
}
|
|
|
|
|
var base=parts.join('.');
|
|
|
|
|
numMatch=base.match(/\((\d+)\)/);
|
|
|
|
|
var num=2;
|
|
|
|
|
if (numMatch && numMatch.length>0) {
|
2014-07-04 12:08:48 +00:00
|
|
|
|
num=parseInt(numMatch[numMatch.length-1], 10)+1;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
base=base.split('(');
|
|
|
|
|
base.pop();
|
|
|
|
|
base=$.trim(base.join('('));
|
|
|
|
|
}
|
|
|
|
|
name=base+' ('+num+')';
|
|
|
|
|
if (extension) {
|
|
|
|
|
name = name+'.'+extension;
|
|
|
|
|
}
|
|
|
|
|
// FIXME: ugly recursion
|
|
|
|
|
return this.getUniqueName(name);
|
2014-02-12 13:50:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
return name;
|
|
|
|
|
},
|
2014-05-12 17:54:20 +00:00
|
|
|
|
|
2014-09-04 17:58:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* Shows a "permission denied" notification
|
|
|
|
|
*/
|
|
|
|
|
_showPermissionDeniedNotification: function() {
|
|
|
|
|
var message = t('core', 'You don’t have permission to upload or create files here');
|
|
|
|
|
OC.Notification.show(message);
|
|
|
|
|
//hide notification after 10 sec
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
OC.Notification.hide();
|
|
|
|
|
}, 5000);
|
|
|
|
|
},
|
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
|
/**
|
|
|
|
|
* Setup file upload events related to the file-upload plugin
|
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
|
setupUploadEvents: function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
// handle upload events
|
|
|
|
|
var fileUploadStart = this.$el.find('#file_upload_start');
|
|
|
|
|
|
2014-05-23 17:02:50 +00:00
|
|
|
|
// detect the progress bar resize
|
|
|
|
|
fileUploadStart.on('resized', this._onResize);
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
fileUploadStart.on('fileuploaddrop', function(e, data) {
|
|
|
|
|
OC.Upload.log('filelist handle fileuploaddrop', e, data);
|
|
|
|
|
|
2014-05-21 13:55:29 +00:00
|
|
|
|
var dropTarget = $(e.originalEvent.target);
|
2014-05-22 09:16:42 +00:00
|
|
|
|
// check if dropped inside this container and not another one
|
|
|
|
|
if (dropTarget.length && !self.$el.is(dropTarget) && !self.$el.has(dropTarget).length) {
|
2014-05-12 17:54:20 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 13:55:29 +00:00
|
|
|
|
// find the closest tr or crumb to use as target
|
|
|
|
|
dropTarget = dropTarget.closest('tr, .crumb');
|
|
|
|
|
|
|
|
|
|
// if dropping on tr or crumb, drag&drop upload to folder
|
|
|
|
|
if (dropTarget && (dropTarget.data('type') === 'dir' ||
|
|
|
|
|
dropTarget.hasClass('crumb'))) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
// remember as context
|
|
|
|
|
data.context = dropTarget;
|
|
|
|
|
|
2014-09-04 17:58:49 +00:00
|
|
|
|
// if permissions are specified, only allow if create permission is there
|
|
|
|
|
var permissions = dropTarget.data('permissions');
|
|
|
|
|
if (!_.isUndefined(permissions) && (permissions & OC.PERMISSION_CREATE) === 0) {
|
|
|
|
|
self._showPermissionDeniedNotification();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var dir = dropTarget.data('file');
|
|
|
|
|
// if from file list, need to prepend parent dir
|
|
|
|
|
if (dir) {
|
|
|
|
|
var parentDir = self.getCurrentDirectory();
|
|
|
|
|
if (parentDir[parentDir.length - 1] !== '/') {
|
|
|
|
|
parentDir += '/';
|
|
|
|
|
}
|
|
|
|
|
dir = parentDir + dir;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// read full path from crumb
|
|
|
|
|
dir = dropTarget.data('dir') || '/';
|
|
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-06-18 18:38:51 +00:00
|
|
|
|
// add target dir
|
|
|
|
|
data.targetDir = dir;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
} else {
|
2014-05-21 13:55:29 +00:00
|
|
|
|
// we are dropping somewhere inside the file list, which will
|
|
|
|
|
// upload the file to the current directory
|
2014-06-18 18:38:51 +00:00
|
|
|
|
data.targetDir = self.getCurrentDirectory();
|
2014-05-21 13:55:29 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// cancel uploads to current dir if no permission
|
2014-05-12 17:54:20 +00:00
|
|
|
|
var isCreatable = (self.getDirectoryPermissions() & OC.PERMISSION_CREATE) !== 0;
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (!isCreatable) {
|
2014-09-04 17:58:49 +00:00
|
|
|
|
self._showPermissionDeniedNotification();
|
2014-05-08 20:06:30 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
fileUploadStart.on('fileuploadadd', function(e, data) {
|
|
|
|
|
OC.Upload.log('filelist handle fileuploadadd', e, data);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
//finish delete if we are uploading a deleted file
|
|
|
|
|
if (self.deleteFiles && self.deleteFiles.indexOf(data.files[0].name)!==-1) {
|
|
|
|
|
self.finishDelete(null, true); //delete file before continuing
|
|
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// add ui visualization to existing folder
|
|
|
|
|
if (data.context && data.context.data('type') === 'dir') {
|
|
|
|
|
// add to existing folder
|
|
|
|
|
|
|
|
|
|
// update upload counter ui
|
|
|
|
|
var uploadText = data.context.find('.uploadtext');
|
|
|
|
|
var currentUploads = parseInt(uploadText.attr('currentUploads'), 10);
|
|
|
|
|
currentUploads += 1;
|
|
|
|
|
uploadText.attr('currentUploads', currentUploads);
|
|
|
|
|
|
|
|
|
|
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
|
|
|
|
if (currentUploads === 1) {
|
|
|
|
|
var img = OC.imagePath('core', 'loading.gif');
|
2014-12-17 12:12:57 +00:00
|
|
|
|
data.context.find('.thumbnail').css('background-image', 'url(' + img + ')');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
uploadText.text(translatedText);
|
|
|
|
|
uploadText.show();
|
|
|
|
|
} else {
|
|
|
|
|
uploadText.text(translatedText);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
});
|
|
|
|
|
/*
|
|
|
|
|
* when file upload done successfully add row to filelist
|
|
|
|
|
* update counter when uploading to sub folder
|
|
|
|
|
*/
|
|
|
|
|
fileUploadStart.on('fileuploaddone', function(e, data) {
|
|
|
|
|
OC.Upload.log('filelist handle fileuploaddone', e, data);
|
|
|
|
|
|
|
|
|
|
var response;
|
|
|
|
|
if (typeof data.result === 'string') {
|
|
|
|
|
response = data.result;
|
|
|
|
|
} else {
|
|
|
|
|
// fetch response from iframe
|
|
|
|
|
response = data.result[0].body.innerText;
|
2013-10-15 14:14:23 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
var result=$.parseJSON(response);
|
|
|
|
|
|
|
|
|
|
if (typeof result[0] !== 'undefined' && result[0].status === 'success') {
|
|
|
|
|
var file = result[0];
|
|
|
|
|
var size = 0;
|
|
|
|
|
|
|
|
|
|
if (data.context && data.context.data('type') === 'dir') {
|
|
|
|
|
|
|
|
|
|
// update upload counter ui
|
|
|
|
|
var uploadText = data.context.find('.uploadtext');
|
|
|
|
|
var currentUploads = parseInt(uploadText.attr('currentUploads'), 10);
|
|
|
|
|
currentUploads -= 1;
|
|
|
|
|
uploadText.attr('currentUploads', currentUploads);
|
|
|
|
|
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
|
|
|
|
if (currentUploads === 0) {
|
|
|
|
|
var img = OC.imagePath('core', 'filetypes/folder');
|
2014-12-17 12:12:57 +00:00
|
|
|
|
data.context.find('.thumbnail').css('background-image', 'url(' + img + ')');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
uploadText.text(translatedText);
|
|
|
|
|
uploadText.hide();
|
|
|
|
|
} else {
|
|
|
|
|
uploadText.text(translatedText);
|
|
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// update folder size
|
|
|
|
|
size = parseInt(data.context.data('size'), 10);
|
|
|
|
|
size += parseInt(file.size, 10);
|
|
|
|
|
data.context.attr('data-size', size);
|
|
|
|
|
data.context.find('td.filesize').text(humanFileSize(size));
|
|
|
|
|
} else {
|
|
|
|
|
// only append new file if uploaded into the current folder
|
2014-06-19 15:19:28 +00:00
|
|
|
|
if (file.directory !== self.getCurrentDirectory()) {
|
|
|
|
|
// Uploading folders actually uploads a list of files
|
|
|
|
|
// for which the target directory (file.directory) might lie deeper
|
|
|
|
|
// than the current directory
|
|
|
|
|
|
|
|
|
|
var fileDirectory = file.directory.replace('/','').replace(/\/$/, "");
|
|
|
|
|
var currentDirectory = self.getCurrentDirectory().replace('/','').replace(/\/$/, "") + '/';
|
|
|
|
|
|
|
|
|
|
if (currentDirectory !== '/') {
|
|
|
|
|
// abort if fileDirectory does not start with current one
|
|
|
|
|
if (fileDirectory.indexOf(currentDirectory) !== 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove the current directory part
|
|
|
|
|
fileDirectory = fileDirectory.substr(currentDirectory.length);
|
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
2014-06-19 15:19:28 +00:00
|
|
|
|
// only take the first section of the path
|
|
|
|
|
fileDirectory = fileDirectory.split('/');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
2014-06-19 15:19:28 +00:00
|
|
|
|
var fd;
|
|
|
|
|
// if the first section exists / is a subdir
|
|
|
|
|
if (fileDirectory.length) {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
fileDirectory = fileDirectory[0];
|
|
|
|
|
|
2014-06-19 15:19:28 +00:00
|
|
|
|
// See whether it is already in the list
|
|
|
|
|
fd = self.findFileEl(fileDirectory);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (fd.length === 0) {
|
|
|
|
|
var dir = {
|
|
|
|
|
name: fileDirectory,
|
|
|
|
|
type: 'dir',
|
|
|
|
|
mimetype: 'httpd/unix-directory',
|
|
|
|
|
permissions: file.permissions,
|
|
|
|
|
size: 0,
|
|
|
|
|
id: file.parentId
|
|
|
|
|
};
|
2014-06-19 15:19:28 +00:00
|
|
|
|
fd = self.add(dir, {insert: true});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
2014-05-26 18:32:24 +00:00
|
|
|
|
|
2014-06-19 15:19:28 +00:00
|
|
|
|
// update folder size
|
|
|
|
|
size = parseInt(fd.attr('data-size'), 10);
|
|
|
|
|
size += parseInt(file.size, 10);
|
|
|
|
|
fd.attr('data-size', size);
|
|
|
|
|
fd.find('td.filesize').text(OC.Util.humanFileSize(size));
|
|
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-03-13 16:26:37 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// add as stand-alone row to filelist
|
|
|
|
|
size = t('files', 'Pending');
|
|
|
|
|
if (data.files[0].size>=0) {
|
|
|
|
|
size=data.files[0].size;
|
|
|
|
|
}
|
|
|
|
|
//should the file exist in the list remove it
|
|
|
|
|
self.remove(file.name);
|
2013-03-13 16:26:37 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
// create new file context
|
|
|
|
|
data.context = self.add(file, {animate: true});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
fileUploadStart.on('fileuploadstop', function(e, data) {
|
|
|
|
|
OC.Upload.log('filelist handle fileuploadstop', e, data);
|
2013-03-13 16:26:37 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
//if user pressed cancel hide upload chrome
|
|
|
|
|
if (data.errorThrown === 'abort') {
|
|
|
|
|
//cleanup uploading to a dir
|
|
|
|
|
var uploadText = $('tr .uploadtext');
|
2014-02-19 13:47:29 +00:00
|
|
|
|
var img = OC.imagePath('core', 'filetypes/folder');
|
2014-12-17 12:12:57 +00:00
|
|
|
|
uploadText.parents('td.filename').find('.thumbnail').css('background-image', 'url(' + img + ')');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
uploadText.fadeOut();
|
|
|
|
|
uploadText.attr('currentUploads', 0);
|
2013-03-13 16:26:37 +00:00
|
|
|
|
}
|
2014-05-12 17:54:20 +00:00
|
|
|
|
self.updateStorageStatistics();
|
2014-05-08 20:06:30 +00:00
|
|
|
|
});
|
|
|
|
|
fileUploadStart.on('fileuploadfail', function(e, data) {
|
|
|
|
|
OC.Upload.log('filelist handle fileuploadfail', e, data);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
//if user pressed cancel hide upload chrome
|
|
|
|
|
if (data.errorThrown === 'abort') {
|
|
|
|
|
//cleanup uploading to a dir
|
|
|
|
|
var uploadText = $('tr .uploadtext');
|
|
|
|
|
var img = OC.imagePath('core', 'filetypes/folder');
|
2014-12-17 12:12:57 +00:00
|
|
|
|
uploadText.parents('td.filename').find('.thumbnail').css('background-image', 'url(' + img + ')');
|
2014-05-08 20:06:30 +00:00
|
|
|
|
uploadText.fadeOut();
|
|
|
|
|
uploadText.attr('currentUploads', 0);
|
2013-10-15 14:14:23 +00:00
|
|
|
|
}
|
2014-05-12 17:54:20 +00:00
|
|
|
|
self.updateStorageStatistics();
|
2014-05-08 20:06:30 +00:00
|
|
|
|
});
|
2013-03-13 16:26:37 +00:00
|
|
|
|
|
2014-06-19 18:11:57 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Scroll to the last file of the given list
|
|
|
|
|
* Highlight the list of files
|
2014-09-04 10:20:11 +00:00
|
|
|
|
* @param files array of filenames,
|
|
|
|
|
* @param {Function} [highlightFunction] optional function
|
|
|
|
|
* to be called after the scrolling is finished
|
2014-06-19 18:11:57 +00:00
|
|
|
|
*/
|
2014-09-04 10:20:11 +00:00
|
|
|
|
highlightFiles: function(files, highlightFunction) {
|
2014-06-19 18:11:57 +00:00
|
|
|
|
// Detection of the uploaded element
|
|
|
|
|
var filename = files[files.length - 1];
|
|
|
|
|
var $fileRow = this.findFileEl(filename);
|
|
|
|
|
|
|
|
|
|
while(!$fileRow.exists() && this._nextPage(false) !== false) { // Checking element existence
|
|
|
|
|
$fileRow = this.findFileEl(filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$fileRow.exists()) { // Element not present in the file list
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var currentOffset = this.$container.scrollTop();
|
|
|
|
|
var additionalOffset = this.$el.find("#controls").height()+this.$el.find("#controls").offset().top;
|
|
|
|
|
|
|
|
|
|
// Animation
|
|
|
|
|
var _this = this;
|
2014-10-15 08:14:20 +00:00
|
|
|
|
var $scrollContainer = this.$container;
|
|
|
|
|
if ($scrollContainer[0] === window) {
|
|
|
|
|
// need to use "body" to animate scrolling
|
|
|
|
|
// when the scroll container is the window
|
|
|
|
|
$scrollContainer = $('body');
|
|
|
|
|
}
|
|
|
|
|
$scrollContainer.animate({
|
2014-06-19 18:11:57 +00:00
|
|
|
|
// Scrolling to the top of the new element
|
|
|
|
|
scrollTop: currentOffset + $fileRow.offset().top - $fileRow.height() * 2 - additionalOffset
|
|
|
|
|
}, {
|
|
|
|
|
duration: 500,
|
|
|
|
|
complete: function() {
|
|
|
|
|
// Highlighting function
|
2014-09-04 10:20:11 +00:00
|
|
|
|
var highlightRow = highlightFunction;
|
|
|
|
|
|
|
|
|
|
if (!highlightRow) {
|
|
|
|
|
highlightRow = function($fileRow) {
|
|
|
|
|
$fileRow.addClass("highlightUploaded");
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$fileRow.removeClass("highlightUploaded");
|
|
|
|
|
}, 2500);
|
|
|
|
|
};
|
|
|
|
|
}
|
2014-06-19 18:11:57 +00:00
|
|
|
|
|
|
|
|
|
// Loop over uploaded files
|
|
|
|
|
for(var i=0; i<files.length; i++) {
|
|
|
|
|
var $fileRow = _this.findFileEl(files[i]);
|
|
|
|
|
|
|
|
|
|
if($fileRow.length !== 0) { // Checking element existence
|
|
|
|
|
highlightRow($fileRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sort comparators.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @namespace OCA.Files.FileList.Comparators
|
|
|
|
|
* @private
|
2014-05-08 20:06:30 +00:00
|
|
|
|
*/
|
|
|
|
|
FileList.Comparators = {
|
|
|
|
|
/**
|
|
|
|
|
* Compares two file infos by name, making directories appear
|
|
|
|
|
* first.
|
|
|
|
|
*
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {OCA.Files.FileInfo} fileInfo1 file info
|
|
|
|
|
* @param {OCA.Files.FileInfo} fileInfo2 file info
|
|
|
|
|
* @return {int} -1 if the first file must appear before the second one,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* 0 if they are identify, 1 otherwise.
|
|
|
|
|
*/
|
|
|
|
|
name: function(fileInfo1, fileInfo2) {
|
|
|
|
|
if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') {
|
|
|
|
|
return -1;
|
2013-03-13 16:26:37 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-02-18 11:29:05 +00:00
|
|
|
|
return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name);
|
2014-05-08 20:06:30 +00:00
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Compares two file infos by size.
|
|
|
|
|
*
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {OCA.Files.FileInfo} fileInfo1 file info
|
|
|
|
|
* @param {OCA.Files.FileInfo} fileInfo2 file info
|
|
|
|
|
* @return {int} -1 if the first file must appear before the second one,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* 0 if they are identify, 1 otherwise.
|
|
|
|
|
*/
|
|
|
|
|
size: function(fileInfo1, fileInfo2) {
|
|
|
|
|
return fileInfo1.size - fileInfo2.size;
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* Compares two file infos by timestamp.
|
|
|
|
|
*
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {OCA.Files.FileInfo} fileInfo1 file info
|
|
|
|
|
* @param {OCA.Files.FileInfo} fileInfo2 file info
|
|
|
|
|
* @return {int} -1 if the first file must appear before the second one,
|
2014-05-08 20:06:30 +00:00
|
|
|
|
* 0 if they are identify, 1 otherwise.
|
|
|
|
|
*/
|
|
|
|
|
mtime: function(fileInfo1, fileInfo2) {
|
|
|
|
|
return fileInfo1.mtime - fileInfo2.mtime;
|
2013-03-13 16:26:37 +00:00
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
|
};
|
2013-09-08 15:29:43 +00:00
|
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* File info attributes.
|
|
|
|
|
*
|
|
|
|
|
* @todo make this a real class in the future
|
|
|
|
|
* @typedef {Object} OCA.Files.FileInfo
|
|
|
|
|
*
|
|
|
|
|
* @property {int} id file id
|
|
|
|
|
* @property {String} name file name
|
|
|
|
|
* @property {String} [path] file path, defaults to the list's current path
|
|
|
|
|
* @property {String} mimetype mime type
|
|
|
|
|
* @property {String} type "file" for files or "dir" for directories
|
|
|
|
|
* @property {int} permissions file permissions
|
|
|
|
|
* @property {int} mtime modification time in milliseconds
|
|
|
|
|
* @property {boolean} [isShareMountPoint] whether the file is a share mount
|
|
|
|
|
* point
|
|
|
|
|
* @property {boolean} [isPreviewAvailable] whether a preview is available
|
|
|
|
|
* for the given file type
|
|
|
|
|
* @property {String} [icon] path to the mime type icon
|
|
|
|
|
* @property {String} etag etag of the file
|
|
|
|
|
*/
|
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
|
OCA.Files.FileList = FileList;
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
// FIXME: unused ?
|
|
|
|
|
OCA.Files.FileList.useUndo = (window.onbeforeunload)?true:false;
|
2013-10-22 16:11:03 +00:00
|
|
|
|
$(window).bind('beforeunload', function () {
|
2014-05-08 20:06:30 +00:00
|
|
|
|
if (OCA.Files.FileList.lastAction) {
|
|
|
|
|
OCA.Files.FileList.lastAction();
|
2012-07-30 16:21:58 +00:00
|
|
|
|
}
|
2011-08-03 22:22:44 +00:00
|
|
|
|
});
|
2013-10-22 16:11:03 +00:00
|
|
|
|
$(window).unload(function () {
|
2012-11-05 17:42:44 +00:00
|
|
|
|
$(window).trigger('beforeunload');
|
|
|
|
|
});
|
2013-07-03 17:50:03 +00:00
|
|
|
|
|
2011-08-03 22:22:44 +00:00
|
|
|
|
});
|