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-02-11 15:52:56 +00:00
|
|
|
/* global OC, t, n, FileList, FileActions, Files, FileSummary, BreadCrumb */
|
2014-02-12 13:50:23 +00:00
|
|
|
/* global dragOptions, folderDropOptions */
|
2013-10-28 19:22:06 +00:00
|
|
|
window.FileList = {
|
2014-02-20 14:16:45 +00:00
|
|
|
appName: t('files', 'Files'),
|
2013-10-28 19:22:06 +00:00
|
|
|
isEmpty: true,
|
2012-04-15 13:48:02 +00:00
|
|
|
useUndo:true,
|
2013-10-28 19:22:06 +00:00
|
|
|
$el: $('#filestable'),
|
|
|
|
$fileList: $('#fileList'),
|
|
|
|
breadcrumb: null,
|
2014-02-11 15:52:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instance of FileSummary
|
|
|
|
*/
|
|
|
|
fileSummary: null,
|
2013-10-28 19:22:06 +00:00
|
|
|
initialized: false,
|
|
|
|
|
2014-02-11 14:57:45 +00:00
|
|
|
// number of files per page
|
|
|
|
pageSize: 20,
|
|
|
|
// zero based page number
|
|
|
|
pageNumber: 0,
|
|
|
|
totalPages: 0,
|
|
|
|
|
2014-04-04 12:34:07 +00:00
|
|
|
/**
|
|
|
|
* Compare two file info objects, sorting by
|
|
|
|
* folders first, then by name.
|
|
|
|
*/
|
|
|
|
_fileInfoCompare: function(fileInfo1, fileInfo2) {
|
|
|
|
if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return fileInfo1.name.localeCompare(fileInfo2.name);
|
|
|
|
},
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Initialize the file list and its components
|
|
|
|
*/
|
|
|
|
initialize: function() {
|
|
|
|
var self = this;
|
|
|
|
if (this.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: FileList should not know about global elements
|
|
|
|
this.$el = $('#filestable');
|
|
|
|
this.$fileList = $('#fileList');
|
2014-04-04 12:34:07 +00:00
|
|
|
this.files = [];
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-02-11 15:52:56 +00:00
|
|
|
this.fileSummary = this._createSummary();
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
this.breadcrumb = new BreadCrumb({
|
|
|
|
onClick: this._onClickBreadCrumb,
|
|
|
|
onDrop: this._onDropOnBreadCrumb,
|
|
|
|
getCrumbUrl: function(part, index) {
|
|
|
|
return self.linkTo(part.dir);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#controls').prepend(this.breadcrumb.$el);
|
|
|
|
|
|
|
|
$(window).resize(function() {
|
|
|
|
// TODO: debounce this ?
|
|
|
|
var width = $(this).width();
|
|
|
|
FileList.breadcrumb.resize(width, false);
|
|
|
|
});
|
2014-02-12 13:50:23 +00:00
|
|
|
|
|
|
|
this.$fileList.on('click','td.filename a', this._onClickFile);
|
|
|
|
this.$fileList.on('change', 'td.filename input:checkbox', this._onClickFileCheckbox);
|
|
|
|
this.$el.find('#select_all').click(this._onClickSelectAll);
|
|
|
|
this.$el.find('.download').click(this._onClickDownloadSelected);
|
|
|
|
this.$el.find('.delete-selected').click(this._onClickDeleteSelected);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when clicking on files to select them
|
|
|
|
*/
|
|
|
|
_onClickFile: function(event) {
|
|
|
|
if (event.ctrlKey || event.shiftKey) {
|
|
|
|
event.preventDefault();
|
|
|
|
if (event.shiftKey) {
|
|
|
|
var last = $(FileList._lastChecked).parent().parent().prevAll().length;
|
|
|
|
var first = $(this).parent().parent().prevAll().length;
|
|
|
|
var start = Math.min(first, last);
|
|
|
|
var end = Math.max(first, last);
|
|
|
|
var rows = $(this).parent().parent().parent().children('tr');
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
$(rows).each(function(index) {
|
|
|
|
if (index === i) {
|
|
|
|
var checkbox = $(this).children().children('input:checkbox');
|
|
|
|
$(checkbox).attr('checked', 'checked');
|
|
|
|
$(checkbox).parent().parent().addClass('selected');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var checkbox = $(this).parent().children('input:checkbox');
|
|
|
|
FileList._lastChecked = checkbox;
|
|
|
|
if ($(checkbox).attr('checked')) {
|
|
|
|
$(checkbox).removeAttr('checked');
|
|
|
|
$(checkbox).parent().parent().removeClass('selected');
|
|
|
|
$('#select_all').removeAttr('checked');
|
|
|
|
} else {
|
|
|
|
$(checkbox).attr('checked', 'checked');
|
|
|
|
$(checkbox).parent().parent().toggleClass('selected');
|
|
|
|
var selectedCount = $('td.filename input:checkbox:checked').length;
|
|
|
|
if (selectedCount === $('td.filename input:checkbox').length) {
|
|
|
|
$('#select_all').attr('checked', 'checked');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FileList.updateSelectionSummary();
|
|
|
|
} else {
|
|
|
|
var filename=$(this).parent().parent().attr('data-file');
|
|
|
|
var tr = FileList.findFileEl(filename);
|
|
|
|
var renaming=tr.data('renaming');
|
|
|
|
if (!renaming) {
|
|
|
|
FileActions.currentFile = $(this).parent();
|
|
|
|
var mime=FileActions.getCurrentMimeType();
|
|
|
|
var type=FileActions.getCurrentType();
|
|
|
|
var permissions = FileActions.getCurrentPermissions();
|
|
|
|
var action=FileActions.getDefault(mime,type, permissions);
|
|
|
|
if (action) {
|
|
|
|
event.preventDefault();
|
|
|
|
action(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when clicking on a file's checkbox
|
|
|
|
*/
|
|
|
|
_onClickFileCheckbox: function(event) {
|
|
|
|
// FIXME: not sure what the difference is supposed to be with FileList._onClickFile
|
|
|
|
if (event.shiftKey) {
|
|
|
|
var last = $(FileList._lastChecked).parent().parent().prevAll().length;
|
|
|
|
var first = $(this).parent().parent().prevAll().length;
|
|
|
|
var start = Math.min(first, last);
|
|
|
|
var end = Math.max(first, last);
|
|
|
|
var rows = $(this).parent().parent().parent().children('tr');
|
|
|
|
for (var i = start; i < end; i++) {
|
|
|
|
$(rows).each(function(index) {
|
|
|
|
if (index === i) {
|
|
|
|
var checkbox = $(this).children().children('input:checkbox');
|
|
|
|
$(checkbox).attr('checked', 'checked');
|
|
|
|
$(checkbox).parent().parent().addClass('selected');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var selectedCount=$('td.filename input:checkbox:checked').length;
|
|
|
|
$(this).parent().parent().toggleClass('selected');
|
|
|
|
if (!$(this).attr('checked')) {
|
|
|
|
$('#select_all').attr('checked',false);
|
|
|
|
} else {
|
|
|
|
if (selectedCount===$('td.filename input:checkbox').length) {
|
|
|
|
$('#select_all').attr('checked',true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FileList.updateSelectionSummary();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when selecting/deselecting all files
|
|
|
|
*/
|
|
|
|
_onClickSelectAll: function(e) {
|
|
|
|
var checked = $(this).prop('checked');
|
|
|
|
FileList.$fileList.find('td.filename input:checkbox').prop('checked', checked)
|
|
|
|
.parent().parent().toggleClass('selected', checked);
|
|
|
|
FileList.updateSelectionSummary();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when clicking on "Download" for the selected files
|
|
|
|
*/
|
|
|
|
_onClickDownloadSelected: function(event) {
|
|
|
|
var files;
|
|
|
|
var dir = FileList.getCurrentDirectory();
|
|
|
|
if (FileList.isAllSelected()) {
|
|
|
|
files = OC.basename(dir);
|
|
|
|
dir = OC.dirname(dir) || '/';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
files = FileList.getSelectedFiles('name');
|
|
|
|
}
|
|
|
|
OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.'));
|
|
|
|
OC.redirect(Files.getDownloadUrl(files, dir));
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when clicking on "Delete" for the selected files
|
|
|
|
*/
|
|
|
|
_onClickDeleteSelected: function(event) {
|
|
|
|
var files = null;
|
|
|
|
if (!FileList.isAllSelected()) {
|
|
|
|
files = FileList.getSelectedFiles('name');
|
|
|
|
}
|
|
|
|
FileList.do_delete(files);
|
|
|
|
event.preventDefault();
|
|
|
|
return false;
|
2013-10-28 19:22:06 +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();
|
|
|
|
FileList.changeDirectory($targetDir);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-11 14:57:45 +00:00
|
|
|
_onScroll: function(e) {
|
|
|
|
if (this.pageNumber + 1 >= this.totalPages) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
if ($(window).scrollTop() + $(window).height() > $(document).height() - 500) {
|
2014-02-11 14:57:45 +00:00
|
|
|
this._nextPage(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Event handler when dropping on a breadcrumb
|
|
|
|
*/
|
|
|
|
_onDropOnBreadCrumb: function( event, ui ) {
|
|
|
|
var target=$(this).data('dir');
|
|
|
|
var dir = FileList.getCurrentDirectory();
|
|
|
|
while(dir.substr(0,1) === '/') {//remove extra leading /'s
|
|
|
|
dir=dir.substr(1);
|
|
|
|
}
|
|
|
|
dir = '/' + dir;
|
|
|
|
if (dir.substr(-1,1) !== '/') {
|
|
|
|
dir = dir + '/';
|
|
|
|
}
|
|
|
|
if (target === dir || target+'/' === dir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var files = ui.helper.find('tr');
|
|
|
|
$(files).each(function(i,row) {
|
|
|
|
var dir = $(row).data('dir');
|
|
|
|
var file = $(row).data('filename');
|
|
|
|
//slapdash selector, tracking down our original element that the clone budded off of.
|
|
|
|
var origin = $('tr[data-id=' + $(row).data('origin') + ']');
|
|
|
|
var td = origin.children('td.filename');
|
|
|
|
var oldBackgroundImage = td.css('background-image');
|
|
|
|
td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
|
|
|
|
$.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: target }, function(result) {
|
|
|
|
if (result) {
|
|
|
|
if (result.status === 'success') {
|
|
|
|
FileList.remove(file);
|
2014-02-12 13:50:23 +00:00
|
|
|
FileList.updateSelectionSummary();
|
2013-10-28 19:22:06 +00:00
|
|
|
$('#notification').hide();
|
|
|
|
} else {
|
|
|
|
$('#notification').hide();
|
|
|
|
$('#notification').text(result.data.message);
|
|
|
|
$('#notification').fadeIn();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error'));
|
|
|
|
}
|
|
|
|
td.css('background-image', oldBackgroundImage);
|
|
|
|
});
|
2013-08-17 11:07:18 +00:00
|
|
|
});
|
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-02-11 23:54:35 +00:00
|
|
|
/**
|
|
|
|
* Sets a new page title
|
|
|
|
*/
|
|
|
|
setPageTitle: function(title){
|
2014-02-20 13:56:28 +00:00
|
|
|
if (title) {
|
|
|
|
title += ' - ';
|
2014-02-21 08:42:19 +00:00
|
|
|
} else {
|
2014-02-20 13:56:28 +00:00
|
|
|
title = '';
|
|
|
|
}
|
2014-02-20 14:16:45 +00:00
|
|
|
title += FileList.appName;
|
2014-02-11 23:54:35 +00:00
|
|
|
// Sets the page title with the " - ownCloud" suffix as in templates
|
2014-02-13 09:48:01 +00:00
|
|
|
window.document.title = title + ' - ' + oc_defaults.title;
|
2014-02-20 14:36:52 +00:00
|
|
|
|
2014-02-11 23:54:35 +00:00
|
|
|
return true;
|
|
|
|
},
|
2014-01-10 14:02:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the tr element for a given file name
|
2013-10-28 19:22:06 +00:00
|
|
|
* @param fileName file name
|
2014-01-10 14:02:26 +00:00
|
|
|
*/
|
|
|
|
findFileEl: function(fileName){
|
|
|
|
// use filterAttr to avoid escaping issues
|
2013-10-28 19:22:06 +00:00
|
|
|
return this.$fileList.find('tr').filterAttr('data-file', fileName);
|
2014-01-10 14:02:26 +00:00
|
|
|
},
|
2014-02-11 14:57:45 +00:00
|
|
|
|
2014-02-12 13:50:23 +00:00
|
|
|
/**
|
|
|
|
* Returns the file data from a given file element.
|
|
|
|
* @param $el file tr element
|
|
|
|
* @return file data
|
|
|
|
*/
|
|
|
|
elementToFile: function($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),
|
|
|
|
etag: $el.attr('data-etag'),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2014-02-11 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* Appends the next page of files into the table
|
|
|
|
* @param animate true to animate the new elements
|
|
|
|
*/
|
|
|
|
_nextPage: function(animate) {
|
|
|
|
var tr, index, count = this.pageSize,
|
2014-02-12 13:50:23 +00:00
|
|
|
newTrs = [],
|
|
|
|
selected = this.isAllSelected();
|
2014-02-11 14:57:45 +00:00
|
|
|
|
|
|
|
if (this.pageNumber + 1 >= this.totalPages) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pageNumber++;
|
|
|
|
index = this.pageNumber * this.pageSize;
|
|
|
|
|
|
|
|
while (count > 0 && index < this.files.length) {
|
2014-04-04 12:34:07 +00:00
|
|
|
tr = this._renderRow(this.files[index], {updateSummary: false});
|
|
|
|
this.$fileList.append(tr);
|
2014-02-12 13:50:23 +00:00
|
|
|
if (selected) {
|
|
|
|
tr.addClass('selected');
|
|
|
|
tr.find('input:checkbox').prop('checked', true);
|
|
|
|
}
|
2014-02-11 14:57:45 +00:00
|
|
|
if (animate) {
|
|
|
|
tr.addClass('appear transparent'); // TODO
|
|
|
|
newTrs.push(tr);
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animate) {
|
|
|
|
// defer, for animation
|
|
|
|
window.setTimeout(function() {
|
|
|
|
for (var i = 0; i < newTrs.length; i++ ) {
|
|
|
|
newTrs[i].removeClass('transparent');
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Sets the files to be displayed in the list.
|
|
|
|
* This operation will rerender the list and update the summary.
|
|
|
|
* @param filesArray array of file data (map)
|
|
|
|
*/
|
|
|
|
setFiles:function(filesArray) {
|
|
|
|
// detach to make adding multiple rows faster
|
2014-02-11 14:57:45 +00:00
|
|
|
this.files = filesArray;
|
|
|
|
this.pageNumber = -1;
|
|
|
|
this.totalPages = Math.ceil(filesArray.length / this.pageSize);
|
2013-10-28 19:22:06 +00:00
|
|
|
|
2014-02-11 14:57:45 +00:00
|
|
|
this.$fileList.detach();
|
2013-10-28 19:22:06 +00:00
|
|
|
this.$fileList.empty();
|
|
|
|
|
2014-02-12 13:50:23 +00:00
|
|
|
// clear "Select all" checkbox
|
|
|
|
$('#select_all').prop('checked', false);
|
|
|
|
|
2014-02-11 14:57:45 +00:00
|
|
|
this.isEmpty = this.files.length === 0;
|
|
|
|
this._nextPage();
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
this.$el.find('thead').after(this.$fileList);
|
|
|
|
|
|
|
|
this.updateEmptyContent();
|
|
|
|
this.$fileList.trigger(jQuery.Event("fileActionsReady"));
|
2013-08-17 11:07:18 +00:00
|
|
|
// "Files" might not be loaded in extending apps
|
2013-10-22 16:11:03 +00:00
|
|
|
if (window.Files) {
|
2013-08-17 11:07:18 +00:00
|
|
|
Files.setupDragAndDrop();
|
|
|
|
}
|
2014-02-11 15:52:56 +00:00
|
|
|
|
|
|
|
this.fileSummary.calculate(filesArray);
|
|
|
|
|
2014-02-12 13:50:23 +00:00
|
|
|
FileList.updateSelectionSummary();
|
2014-02-04 10:14:00 +00:00
|
|
|
$(window).scrollTop(0);
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
this.$fileList.trigger(jQuery.Event("updated"));
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Creates a new table row element using the given file data.
|
|
|
|
* @param fileData map of file attributes
|
|
|
|
* @param options map of attribute "loading" whether the entry is currently loading
|
|
|
|
* @return new tr element (not appended to the table)
|
|
|
|
*/
|
|
|
|
_createRow: function(fileData, options) {
|
|
|
|
var td, simpleSize, basename, extension, sizeColor,
|
2014-04-04 09:32:07 +00:00
|
|
|
icon = OC.Util.replaceSVGIcon(fileData.icon),
|
2013-10-28 19:22:06 +00:00
|
|
|
name = fileData.name,
|
|
|
|
type = fileData.type || 'file',
|
|
|
|
mtime = parseInt(fileData.mtime, 10) || new Date().getTime(),
|
|
|
|
mime = fileData.mimetype,
|
|
|
|
linkUrl;
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
if (type === 'dir') {
|
|
|
|
mime = mime || 'httpd/unix-directory';
|
|
|
|
}
|
2014-04-17 13:54:45 +00:00
|
|
|
|
|
|
|
// user should always be able to rename a share mount point
|
|
|
|
var allowRename = 0;
|
|
|
|
if (fileData.isShareMountPoint) {
|
|
|
|
allowRename = OC.PERMISSION_UPDATE;
|
|
|
|
}
|
|
|
|
|
2013-02-09 13:42:03 +00:00
|
|
|
//containing tr
|
|
|
|
var tr = $('<tr></tr>').attr({
|
2013-10-28 19:22:06 +00:00
|
|
|
"data-id" : fileData.id,
|
2013-02-09 13:42:03 +00:00
|
|
|
"data-type": type,
|
2013-10-28 19:22:06 +00:00
|
|
|
"data-size": fileData.size,
|
2013-02-09 13:42:03 +00:00
|
|
|
"data-file": name,
|
2013-10-28 19:22:06 +00:00
|
|
|
"data-mime": mime,
|
|
|
|
"data-mtime": mtime,
|
|
|
|
"data-etag": fileData.etag,
|
2014-04-17 13:54:45 +00:00
|
|
|
"data-permissions": fileData.permissions | allowRename || this.getDirectoryPermissions()
|
2013-02-09 13:42:03 +00:00
|
|
|
});
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
if (type === 'dir') {
|
|
|
|
// use default folder icon
|
|
|
|
icon = icon || OC.imagePath('core', 'filetypes/folder');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = icon || OC.imagePath('core', 'filetypes/file');
|
|
|
|
}
|
|
|
|
|
2013-02-09 13:42:03 +00:00
|
|
|
// filename td
|
|
|
|
td = $('<td></td>').attr({
|
2013-10-28 19:22:06 +00:00
|
|
|
"class": "filename",
|
|
|
|
"style": 'background-image:url(' + icon + '); background-size: 32px;'
|
2013-02-09 13:42:03 +00:00
|
|
|
});
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
// linkUrl
|
|
|
|
if (type === 'dir') {
|
|
|
|
linkUrl = FileList.linkTo(FileList.getCurrentDirectory() + '/' + name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
linkUrl = Files.getDownloadUrl(name, FileList.getCurrentDirectory());
|
|
|
|
}
|
|
|
|
td.append('<input id="select-' + fileData.id + '" type="checkbox" /><label for="select-' + fileData.id + '"></label>');
|
2014-04-07 21:45:35 +00:00
|
|
|
var linkElem = $('<a></a>').attr({
|
2013-02-09 13:42:03 +00:00
|
|
|
"class": "name",
|
2013-10-28 19:22:06 +00:00
|
|
|
"href": linkUrl
|
2013-02-09 13:42:03 +00:00
|
|
|
});
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
// from here work on the display name
|
|
|
|
name = fileData.displayName || name;
|
|
|
|
|
|
|
|
// split extension from filename for non dirs
|
2013-10-22 16:11:03 +00:00
|
|
|
if (type !== 'dir' && name.indexOf('.') !== -1) {
|
2013-10-28 19:22:06 +00:00
|
|
|
basename = name.substr(0, name.lastIndexOf('.'));
|
|
|
|
extension = name.substr(name.lastIndexOf('.'));
|
2013-02-09 13:42:03 +00:00
|
|
|
} else {
|
2013-10-28 19:22:06 +00:00
|
|
|
basename = name;
|
|
|
|
extension = false;
|
2011-07-28 21:52:49 +00:00
|
|
|
}
|
2014-04-07 21:45:35 +00:00
|
|
|
var nameSpan=$('<span></span>').addClass('nametext').text(basename);
|
|
|
|
linkElem.append(nameSpan);
|
2013-10-22 16:11:03 +00:00
|
|
|
if (extension) {
|
2014-04-07 21:45:35 +00:00
|
|
|
nameSpan.append($('<span></span>').addClass('extension').text(extension));
|
2013-02-09 13:42:03 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
// dirs can show the number of uploaded files
|
2013-10-22 16:11:03 +00:00
|
|
|
if (type === 'dir') {
|
2014-04-07 21:45:35 +00:00
|
|
|
linkElem.append($('<span></span>').attr({
|
2013-02-09 13:42:03 +00:00
|
|
|
'class': 'uploadtext',
|
|
|
|
'currentUploads': 0
|
|
|
|
}));
|
2011-07-28 21:52:49 +00:00
|
|
|
}
|
2014-04-07 21:45:35 +00:00
|
|
|
td.append(linkElem);
|
2013-02-09 13:42:03 +00:00
|
|
|
tr.append(td);
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
// size column
|
|
|
|
if (typeof(fileData.size) !== 'undefined' && fileData.size >= 0) {
|
|
|
|
simpleSize = humanFileSize(parseInt(fileData.size, 10));
|
|
|
|
sizeColor = Math.round(160-Math.pow((fileData.size/(1024*1024)),2));
|
2013-10-22 16:11:03 +00:00
|
|
|
} else {
|
2013-10-28 19:22:06 +00:00
|
|
|
simpleSize = t('files', 'Pending');
|
2011-07-28 21:52:49 +00:00
|
|
|
}
|
2014-04-07 21:45:35 +00:00
|
|
|
|
2013-02-09 13:42:03 +00:00
|
|
|
td = $('<td></td>').attr({
|
|
|
|
"class": "filesize",
|
2013-10-28 19:22:06 +00:00
|
|
|
"style": 'color:rgb(' + sizeColor + ',' + sizeColor + ',' + sizeColor + ')'
|
2013-02-09 13:42:03 +00:00
|
|
|
}).text(simpleSize);
|
|
|
|
tr.append(td);
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-02-09 13:42:03 +00:00
|
|
|
// date column
|
2013-10-28 19:22:06 +00:00
|
|
|
var modifiedColor = Math.round((Math.round((new Date()).getTime() / 1000) - mtime)/60/60/24*5);
|
2013-02-09 13:42:03 +00:00
|
|
|
td = $('<td></td>').attr({ "class": "date" });
|
|
|
|
td.append($('<span></span>').attr({
|
|
|
|
"class": "modified",
|
2013-10-28 19:22:06 +00:00
|
|
|
"title": formatDate(mtime),
|
2013-02-09 13:42:03 +00:00
|
|
|
"style": 'color:rgb('+modifiedColor+','+modifiedColor+','+modifiedColor+')'
|
2013-10-28 19:22:06 +00:00
|
|
|
}).text( relative_modified_date(mtime / 1000) ));
|
|
|
|
tr.find('.filesize').text(simpleSize);
|
2013-02-09 13:42:03 +00:00
|
|
|
tr.append(td);
|
|
|
|
return tr;
|
|
|
|
},
|
2014-04-04 12:34:07 +00:00
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
2014-04-04 12:34:07 +00:00
|
|
|
* Adds an entry to the files array and also into the DOM
|
|
|
|
*
|
2013-10-28 19:22:06 +00:00
|
|
|
* @param fileData map of file attributes
|
|
|
|
* @param options map of attributes:
|
|
|
|
* - "insert" true to insert in a sorted manner, false to append (default)
|
|
|
|
* - "updateSummary" true to update the summary after adding (default), false otherwise
|
|
|
|
* @return new tr element (not appended to the table)
|
|
|
|
*/
|
|
|
|
add: function(fileData, options) {
|
2014-04-04 12:34:07 +00:00
|
|
|
var index = -1;
|
|
|
|
var $tr = this._renderRow(fileData, options);
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
this.isEmpty = false;
|
|
|
|
|
|
|
|
if (options.insert) {
|
|
|
|
index = this._findInsertionIndex(fileData);
|
|
|
|
if (index < this.files.length) {
|
|
|
|
this.files.splice(index, 0, fileData);
|
|
|
|
this.$fileList.children().eq(index).before($tr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.files.push(fileData);
|
|
|
|
this.$fileList.append($tr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.files.push(fileData);
|
|
|
|
this.$fileList.append($tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// defaults to true if not defined
|
|
|
|
if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) {
|
|
|
|
this.fileSummary.add(fileData, true);
|
|
|
|
this.updateEmptyContent();
|
|
|
|
}
|
|
|
|
return $tr;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new row element based on the given attributes
|
|
|
|
* and returns it.
|
|
|
|
*
|
|
|
|
* @param fileData map of file attributes
|
|
|
|
* @param options map of attributes:
|
|
|
|
* - "index" optional index at which to insert the element
|
|
|
|
* - "updateSummary" true to update the summary after adding (default), false otherwise
|
|
|
|
* @return new tr element (not appended to the table)
|
|
|
|
*/
|
|
|
|
_renderRow: function(fileData, options) {
|
2013-10-28 19:22:06 +00:00
|
|
|
options = options || {};
|
|
|
|
var type = fileData.type || 'file',
|
|
|
|
mime = fileData.mimetype,
|
|
|
|
permissions = parseInt(fileData.permissions, 10) || 0;
|
2013-06-25 10:24:14 +00:00
|
|
|
|
2014-04-17 13:54:45 +00:00
|
|
|
if (fileData.isShareMountPoint) {
|
|
|
|
permissions = permissions | OC.PERMISSION_UPDATE;
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
if (type === 'dir') {
|
|
|
|
mime = mime || 'httpd/unix-directory';
|
2013-06-25 10:24:14 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
var tr = this._createRow(
|
|
|
|
fileData,
|
|
|
|
options
|
|
|
|
);
|
|
|
|
var filenameTd = tr.find('td.filename');
|
2013-06-25 10:24:14 +00:00
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
// TODO: move dragging to FileActions ?
|
|
|
|
// enable drag only for deletable files
|
|
|
|
if (permissions & OC.PERMISSION_DELETE) {
|
|
|
|
filenameTd.draggable(dragOptions);
|
|
|
|
}
|
|
|
|
// allow dropping on folders
|
|
|
|
if (fileData.type === 'dir') {
|
|
|
|
filenameTd.droppable(folderDropOptions);
|
|
|
|
}
|
2013-02-22 16:21:57 +00:00
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
if (options.hidden) {
|
|
|
|
tr.addClass('hidden');
|
2011-07-19 18:57:40 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
// display actions
|
|
|
|
FileActions.display(filenameTd, false);
|
|
|
|
|
|
|
|
if (fileData.isPreviewAvailable) {
|
|
|
|
// lazy load / newly inserted td ?
|
|
|
|
if (!fileData.icon) {
|
|
|
|
Files.lazyLoadPreview(getPathForPreview(fileData.name), mime, function(url) {
|
|
|
|
filenameTd.css('background-image', 'url(' + url + ')');
|
|
|
|
}, null, null, fileData.etag);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// set the preview URL directly
|
|
|
|
var urlSpec = {
|
|
|
|
file: FileList.getCurrentDirectory() + '/' + fileData.name,
|
|
|
|
c: fileData.etag
|
|
|
|
};
|
|
|
|
var previewUrl = Files.generatePreviewUrl(urlSpec);
|
|
|
|
previewUrl = previewUrl.replace('(', '%28').replace(')', '%29');
|
|
|
|
filenameTd.css('background-image', 'url(' + previewUrl + ')');
|
|
|
|
}
|
2012-09-05 04:12:11 +00:00
|
|
|
}
|
2013-03-13 16:26:37 +00:00
|
|
|
return tr;
|
2011-06-04 16:44:14 +00:00
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the current directory
|
|
|
|
* @return current directory
|
|
|
|
*/
|
2013-11-06 09:55:19 +00:00
|
|
|
getCurrentDirectory: function(){
|
|
|
|
return $('#dir').val() || '/';
|
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the directory permissions
|
|
|
|
* @return permission value as integer
|
|
|
|
*/
|
|
|
|
getDirectoryPermissions: function() {
|
|
|
|
return parseInt($('#permissions').val(), 10);
|
|
|
|
},
|
2013-08-17 11:07:18 +00:00
|
|
|
/**
|
|
|
|
* @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)
|
2013-10-22 16:11:03 +00:00
|
|
|
* @param {boolean} force set to true to force changing directory
|
2013-08-17 11:07:18 +00:00
|
|
|
*/
|
2013-10-22 16:11:03 +00:00
|
|
|
changeDirectory: function(targetDir, changeUrl, force) {
|
2013-08-17 11:07:18 +00:00
|
|
|
var $dir = $('#dir'),
|
|
|
|
url,
|
2014-02-20 14:16:45 +00:00
|
|
|
currentDir = $dir.val() || '/';
|
2013-08-17 11:07:18 +00:00
|
|
|
targetDir = targetDir || '/';
|
2013-10-22 16:11:03 +00:00
|
|
|
if (!force && currentDir === targetDir) {
|
2013-08-17 11:07:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
FileList._setCurrentDir(targetDir, changeUrl);
|
2013-11-08 12:15:48 +00:00
|
|
|
$('#fileList').trigger(
|
|
|
|
jQuery.Event('changeDirectory', {
|
|
|
|
dir: targetDir,
|
|
|
|
previousDir: currentDir
|
|
|
|
}
|
|
|
|
));
|
2013-08-17 11:07:18 +00:00
|
|
|
FileList.reload();
|
|
|
|
},
|
2013-10-22 16:11:03 +00:00
|
|
|
linkTo: function(dir) {
|
2013-08-29 19:56:14 +00:00
|
|
|
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
|
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-02-20 14:16:45 +00:00
|
|
|
var url,
|
|
|
|
baseDir = OC.basename(targetDir);
|
|
|
|
|
|
|
|
if (baseDir !== '') {
|
|
|
|
FileList.setPageTitle(baseDir);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
FileList.setPageTitle();
|
|
|
|
}
|
|
|
|
|
2013-08-17 11:07:18 +00:00
|
|
|
$('#dir').val(targetDir);
|
2013-10-22 16:11:03 +00:00
|
|
|
if (changeUrl !== false) {
|
|
|
|
if (window.history.pushState && changeUrl !== false) {
|
2013-08-29 19:56:14 +00:00
|
|
|
url = FileList.linkTo(targetDir);
|
|
|
|
window.history.pushState({dir: targetDir}, '', url);
|
|
|
|
}
|
|
|
|
// use URL hash for IE8
|
|
|
|
else{
|
|
|
|
window.location.hash = '?dir='+ encodeURIComponent(targetDir).replace(/%2F/g, '/');
|
|
|
|
}
|
2013-08-17 11:07:18 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
this.breadcrumb.setDirectory(this.getCurrentDirectory());
|
2013-08-17 11:07:18 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @brief Reloads the file list using ajax call
|
|
|
|
*/
|
2013-10-22 16:11:03 +00:00
|
|
|
reload: function() {
|
2013-08-17 11:07:18 +00:00
|
|
|
FileList.showMask();
|
2013-10-22 16:11:03 +00:00
|
|
|
if (FileList._reloadCall) {
|
2013-08-17 11:07:18 +00:00
|
|
|
FileList._reloadCall.abort();
|
|
|
|
}
|
|
|
|
FileList._reloadCall = $.ajax({
|
2013-10-28 19:22:06 +00:00
|
|
|
url: Files.getAjaxUrl('list'),
|
2013-08-17 11:07:18 +00:00
|
|
|
data: {
|
2013-10-28 19:22:06 +00:00
|
|
|
dir : $('#dir').val()
|
2013-08-17 11:07:18 +00:00
|
|
|
},
|
2013-10-22 16:11:03 +00:00
|
|
|
error: function(result) {
|
2013-08-17 11:07:18 +00:00
|
|
|
FileList.reloadCallback(result);
|
|
|
|
},
|
|
|
|
success: function(result) {
|
|
|
|
FileList.reloadCallback(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2013-10-22 16:11:03 +00:00
|
|
|
reloadCallback: function(result) {
|
2013-10-28 19:22:06 +00:00
|
|
|
delete this._reloadCall;
|
|
|
|
this.hideMask();
|
2013-08-17 11:07:18 +00:00
|
|
|
|
|
|
|
if (!result || result.status === 'error') {
|
|
|
|
OC.Notification.show(result.data.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
if (result.status === 404) {
|
2013-08-17 11:07:18 +00:00
|
|
|
// go back home
|
2013-10-28 19:22:06 +00:00
|
|
|
this.changeDirectory('/');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// aborted ?
|
|
|
|
if (result.status === 0){
|
2013-08-17 11:07:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-06 09:55:19 +00:00
|
|
|
// TODO: should rather return upload file size through
|
|
|
|
// the files list ajax call
|
|
|
|
Files.updateStorageStatistics(true);
|
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
if (result.data.permissions) {
|
2013-10-28 19:22:06 +00:00
|
|
|
this.setDirectoryPermissions(result.data.permissions);
|
2011-06-04 16:44:14 +00:00
|
|
|
}
|
2013-08-27 09:18:59 +00:00
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
this.setFiles(result.data.files);
|
2011-06-04 16:44:14 +00:00
|
|
|
},
|
2013-10-22 16:11:03 +00:00
|
|
|
setDirectoryPermissions: function(permissions) {
|
2013-08-29 21:45:02 +00:00
|
|
|
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
|
|
|
$('#permissions').val(permissions);
|
|
|
|
$('.creatable').toggleClass('hidden', !isCreatable);
|
|
|
|
$('.notCreatable').toggleClass('hidden', isCreatable);
|
2011-06-04 16:44:14 +00:00
|
|
|
},
|
2013-10-15 15:59:59 +00:00
|
|
|
/**
|
|
|
|
* Shows/hides action buttons
|
|
|
|
*
|
|
|
|
* @param show true for enabling, false for disabling
|
|
|
|
*/
|
|
|
|
showActions: function(show){
|
|
|
|
$('.actions,#file_action_panel').toggleClass('hidden', !show);
|
|
|
|
if (show){
|
|
|
|
// make sure to display according to permissions
|
2013-10-28 19:22:06 +00:00
|
|
|
var permissions = this.getDirectoryPermissions();
|
2013-10-15 15:59:59 +00:00
|
|
|
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
|
|
|
$('.creatable').toggleClass('hidden', !isCreatable);
|
|
|
|
$('.notCreatable').toggleClass('hidden', isCreatable);
|
2013-10-28 19:22:06 +00:00
|
|
|
// remove old style breadcrumbs (some apps might create them)
|
|
|
|
$('#controls .crumb').remove();
|
|
|
|
// refresh breadcrumbs in case it was replaced by an app
|
|
|
|
this.breadcrumb.render();
|
2013-10-15 15:59:59 +00:00
|
|
|
}
|
2013-10-31 11:31:40 +00:00
|
|
|
else{
|
|
|
|
$('.creatable, .notCreatable').addClass('hidden');
|
|
|
|
}
|
2013-10-15 15:59:59 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
$('#filestable').toggleClass('hidden', show);
|
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Removes a file entry from the list
|
|
|
|
* @param name name of the file to remove
|
|
|
|
* @param options optional options as map:
|
|
|
|
* "updateSummary": true to update the summary (default), false otherwise
|
2014-02-12 13:50:23 +00:00
|
|
|
* @return deleted element
|
2013-10-28 19:22:06 +00:00
|
|
|
*/
|
2014-04-04 12:34:07 +00:00
|
|
|
remove: function(name, options){
|
2013-10-28 19:22:06 +00:00
|
|
|
options = options || {};
|
2014-01-10 14:02:26 +00:00
|
|
|
var fileEl = FileList.findFileEl(name);
|
2014-04-04 12:34:07 +00:00
|
|
|
var index = fileEl.index();
|
2014-02-12 13:50:23 +00:00
|
|
|
if (!fileEl.length) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-12-09 15:03:23 +00:00
|
|
|
if (fileEl.data('permissions') & OC.PERMISSION_DELETE) {
|
|
|
|
// file is only draggable when delete permissions are set
|
|
|
|
fileEl.find('td.filename').draggable('destroy');
|
|
|
|
}
|
2014-04-04 12:34:07 +00:00
|
|
|
this.files.splice(index, 1);
|
2014-01-10 14:02:26 +00:00
|
|
|
fileEl.remove();
|
2013-10-28 19:22:06 +00:00
|
|
|
// TODO: improve performance on batch update
|
2014-04-04 12:34:07 +00:00
|
|
|
FileList.isEmpty = !this.files.length;
|
2013-10-28 19:22:06 +00:00
|
|
|
if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) {
|
|
|
|
FileList.updateEmptyContent();
|
2014-02-11 15:52:56 +00:00
|
|
|
this.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')}, true);
|
2011-07-30 12:42:58 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
return fileEl;
|
2011-06-04 16:44:14 +00:00
|
|
|
},
|
2014-04-04 12:34:07 +00:00
|
|
|
/**
|
|
|
|
* Finds the index of the row before which the given
|
|
|
|
* fileData should be inserted, considering the current
|
|
|
|
* sorting
|
|
|
|
*/
|
|
|
|
_findInsertionIndex: function(fileData) {
|
|
|
|
var index = 0;
|
|
|
|
while (index < this.files.length && this._fileInfoCompare(fileData, this.files[index]) > 0) {
|
|
|
|
index++;
|
2011-07-04 19:46:20 +00:00
|
|
|
}
|
2014-04-04 12:34:07 +00:00
|
|
|
return index;
|
2011-07-19 18:57:40 +00:00
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
rename: function(oldname) {
|
2012-09-23 01:16:52 +00:00
|
|
|
var tr, td, input, form;
|
2014-01-10 14:02:26 +00:00
|
|
|
tr = FileList.findFileEl(oldname);
|
2014-04-04 12:34:07 +00:00
|
|
|
var oldFileInfo = this.files[tr.index()];
|
2011-07-29 00:26:20 +00:00
|
|
|
tr.data('renaming',true);
|
2013-10-22 16:11:03 +00:00
|
|
|
td = tr.children('td.filename');
|
|
|
|
input = $('<input type="text" class="filename"/>').val(oldname);
|
|
|
|
form = $('<form></form>');
|
2011-07-28 21:04:34 +00:00
|
|
|
form.append(input);
|
2012-10-18 12:16:59 +00:00
|
|
|
td.children('a.name').hide();
|
|
|
|
td.append(form);
|
2011-07-28 21:04:34 +00:00
|
|
|
input.focus();
|
2013-05-13 13:54:45 +00:00
|
|
|
//preselect input
|
|
|
|
var len = input.val().lastIndexOf('.');
|
2014-04-21 08:35:15 +00:00
|
|
|
if ( len === -1 ||
|
|
|
|
tr.data('type') === 'dir' ) {
|
2013-05-13 13:54:45 +00:00
|
|
|
len = input.val().length;
|
|
|
|
}
|
2013-10-22 16:11:03 +00:00
|
|
|
input.selectRange(0, len);
|
|
|
|
var checkInput = function () {
|
|
|
|
var filename = input.val();
|
|
|
|
if (filename !== oldname) {
|
2014-03-04 15:42:40 +00:00
|
|
|
// Files.isFileNameValid(filename) throws an exception itself
|
2014-04-08 15:17:48 +00:00
|
|
|
Files.isFileNameValid(filename);
|
2014-03-04 15:42:40 +00:00
|
|
|
if (FileList.inList(filename)) {
|
2013-10-22 16:11:03 +00:00
|
|
|
throw t('files', '{new_name} already exists', {new_name: filename});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2014-02-04 10:14:00 +00:00
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
form.submit(function(event) {
|
2011-07-28 21:04:34 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
2013-10-22 16:11:03 +00:00
|
|
|
try {
|
|
|
|
var newname = input.val();
|
2013-10-28 19:22:06 +00:00
|
|
|
var directory = FileList.getCurrentDirectory();
|
2013-10-22 16:11:03 +00:00
|
|
|
if (newname !== oldname) {
|
|
|
|
checkInput();
|
2013-05-02 22:15:28 +00:00
|
|
|
// save background image, because it's replaced by a spinner while async request
|
|
|
|
var oldBackgroundImage = td.css('background-image');
|
|
|
|
// mark as loading
|
|
|
|
td.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
|
|
|
|
$.ajax({
|
|
|
|
url: OC.filePath('files','ajax','rename.php'),
|
|
|
|
data: {
|
|
|
|
dir : $('#dir').val(),
|
|
|
|
newname: newname,
|
2013-10-22 16:11:03 +00:00
|
|
|
file: oldname
|
2013-05-02 22:15:28 +00:00
|
|
|
},
|
|
|
|
success: function(result) {
|
2014-04-04 12:34:07 +00:00
|
|
|
var fileInfo;
|
2013-05-02 22:15:28 +00:00
|
|
|
if (!result || result.status === 'error') {
|
2013-10-22 16:11:03 +00:00
|
|
|
OC.dialogs.alert(result.data.message, t('core', 'Could not rename file'));
|
2014-04-04 12:34:07 +00:00
|
|
|
fileInfo = oldFileInfo;
|
2013-11-27 20:34:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-04-04 12:34:07 +00:00
|
|
|
fileInfo = result.data;
|
2013-05-02 22:15:28 +00:00
|
|
|
}
|
2013-10-22 16:11:03 +00:00
|
|
|
// reinsert row
|
2014-04-04 12:34:07 +00:00
|
|
|
FileList.files.splice(tr.index(), 1);
|
|
|
|
tr.remove();
|
|
|
|
FileList.add(fileInfo, {insert: true});
|
2012-07-30 16:21:58 +00:00
|
|
|
}
|
|
|
|
});
|
2012-09-19 12:05:09 +00:00
|
|
|
}
|
2013-10-22 16:11:03 +00:00
|
|
|
input.tipsy('hide');
|
|
|
|
tr.data('renaming',false);
|
|
|
|
tr.attr('data-file', newname);
|
|
|
|
var path = td.children('a.name').attr('href');
|
|
|
|
// FIXME this will fail if the path contains the filename.
|
|
|
|
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
|
|
|
|
var basename = newname;
|
|
|
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
|
|
|
basename = newname.substr(0, newname.lastIndexOf('.'));
|
2014-02-04 10:14:00 +00:00
|
|
|
}
|
2013-10-22 16:11:03 +00:00
|
|
|
td.find('a.name span.nametext').text(basename);
|
|
|
|
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
|
|
|
|
if ( ! td.find('a.name span.extension').exists() ) {
|
|
|
|
td.find('a.name span.nametext').append('<span class="extension"></span>');
|
|
|
|
}
|
|
|
|
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
|
2012-10-18 12:16:59 +00:00
|
|
|
}
|
2013-10-22 16:11:03 +00:00
|
|
|
form.remove();
|
2013-10-02 19:09:03 +00:00
|
|
|
FileActions.display( tr.find('td.filename'), true);
|
2013-10-22 16:11:03 +00:00
|
|
|
td.children('a.name').show();
|
|
|
|
} catch (error) {
|
|
|
|
input.attr('title', error);
|
|
|
|
input.tipsy({gravity: 'w', trigger: 'manual'});
|
|
|
|
input.tipsy('show');
|
|
|
|
input.addClass('error');
|
2012-07-30 16:21:58 +00:00
|
|
|
}
|
2011-12-05 22:51:44 +00:00
|
|
|
return false;
|
2011-07-28 21:04:34 +00:00
|
|
|
});
|
2013-10-22 16:11:03 +00:00
|
|
|
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) {
|
|
|
|
input.tipsy('hide');
|
2012-12-18 15:39:01 +00:00
|
|
|
tr.data('renaming',false);
|
|
|
|
form.remove();
|
|
|
|
td.children('a.name').show();
|
|
|
|
}
|
|
|
|
});
|
2013-10-22 16:11:03 +00:00
|
|
|
input.click(function(event) {
|
2011-07-28 21:04:34 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2013-10-22 16:11:03 +00:00
|
|
|
input.blur(function() {
|
2011-07-29 15:51:17 +00:00
|
|
|
form.trigger('submit');
|
2011-07-28 21:04:34 +00:00
|
|
|
});
|
2011-08-03 22:22:44 +00:00
|
|
|
},
|
2014-01-10 14:02:26 +00:00
|
|
|
inList:function(file) {
|
|
|
|
return FileList.findFileEl(file).length;
|
2012-09-05 04:12:11 +00:00
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2014-02-13 19:20:00 +00:00
|
|
|
do_delete:function(files, dir) {
|
|
|
|
var params;
|
|
|
|
if (files && files.substr) {
|
2013-01-30 13:32:20 +00:00
|
|
|
files=[files];
|
2013-02-20 20:57:50 +00:00
|
|
|
}
|
2014-02-13 19:20:00 +00:00
|
|
|
if (files) {
|
|
|
|
for (var i=0; i<files.length; i++) {
|
|
|
|
var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
|
|
|
|
deleteAction.removeClass('delete-icon').addClass('progress-icon');
|
|
|
|
}
|
2013-01-30 13:32:20 +00:00
|
|
|
}
|
2012-07-30 16:21:58 +00:00
|
|
|
// Finish any existing actions
|
2012-09-19 09:56:31 +00:00
|
|
|
if (FileList.lastAction) {
|
2012-07-30 16:21:58 +00:00
|
|
|
FileList.lastAction();
|
2011-08-03 22:22:44 +00:00
|
|
|
}
|
2012-10-14 19:04:08 +00:00
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
params = {
|
2014-02-13 19:20:00 +00:00
|
|
|
dir: dir || FileList.getCurrentDirectory()
|
|
|
|
};
|
|
|
|
if (files) {
|
|
|
|
params.files = JSON.stringify(files);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// no files passed, delete all in current dir
|
|
|
|
params.allfiles = true;
|
|
|
|
}
|
|
|
|
|
2013-01-22 16:43:46 +00:00
|
|
|
$.post(OC.filePath('files', 'ajax', 'delete.php'),
|
2014-02-13 19:20:00 +00:00
|
|
|
params,
|
2013-10-22 16:11:03 +00:00
|
|
|
function(result) {
|
|
|
|
if (result.status === 'success') {
|
2014-02-13 19:20:00 +00:00
|
|
|
if (params.allfiles) {
|
2014-02-12 13:50:23 +00:00
|
|
|
FileList.setFiles([]);
|
2014-02-13 19:20:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$.each(files,function(index,file) {
|
2013-10-28 19:22:06 +00:00
|
|
|
var fileEl = FileList.remove(file, {updateSummary: false});
|
2014-02-12 13:50:23 +00:00
|
|
|
// FIXME: not sure why we need this after the
|
|
|
|
// element isn't even in the DOM any more
|
2013-10-28 19:22:06 +00:00
|
|
|
fileEl.find('input[type="checkbox"]').prop('checked', false);
|
|
|
|
fileEl.removeClass('selected');
|
2014-02-11 15:52:56 +00:00
|
|
|
FileList.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')});
|
2014-02-13 19:20:00 +00:00
|
|
|
});
|
|
|
|
}
|
2013-07-26 09:13:43 +00:00
|
|
|
checkTrashStatus();
|
2013-10-20 20:47:44 +00:00
|
|
|
FileList.updateEmptyContent();
|
2014-02-11 15:52:56 +00:00
|
|
|
FileList.fileSummary.update();
|
2014-02-12 13:50:23 +00:00
|
|
|
FileList.updateSelectionSummary();
|
2013-11-06 09:15:05 +00:00
|
|
|
Files.updateStorageStatistics();
|
2013-01-30 13:32:20 +00:00
|
|
|
} else {
|
2013-11-14 15:48:04 +00:00
|
|
|
if (result.status === 'error' && result.data.message) {
|
|
|
|
OC.Notification.show(result.data.message);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
OC.Notification.show(t('files', 'Error deleting file.'));
|
|
|
|
}
|
|
|
|
// hide notification after 10 sec
|
|
|
|
setTimeout(function() {
|
|
|
|
OC.Notification.hide();
|
|
|
|
}, 10000);
|
2014-02-13 19:20:00 +00:00
|
|
|
if (params.allfiles) {
|
|
|
|
// reload the page as we don't know what files were deleted
|
|
|
|
// and which ones remain
|
|
|
|
FileList.reload();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$.each(files,function(index,file) {
|
|
|
|
var deleteAction = FileList.findFileEl(file).find('.action.delete');
|
|
|
|
deleteAction.removeClass('progress-icon').addClass('delete-icon');
|
|
|
|
});
|
|
|
|
}
|
2013-02-22 16:21:57 +00:00
|
|
|
}
|
2013-01-22 16:43:46 +00:00
|
|
|
});
|
2013-07-03 17:50:03 +00:00
|
|
|
},
|
2014-02-11 15:52:56 +00:00
|
|
|
/**
|
|
|
|
* Creates the file summary section
|
|
|
|
*/
|
|
|
|
_createSummary: function() {
|
|
|
|
var $tr = $('<tr class="summary"></tr>');
|
|
|
|
this.$el.find('tfoot').append($tr);
|
2013-07-03 17:50:03 +00:00
|
|
|
|
2014-02-11 15:52:56 +00:00
|
|
|
return new FileSummary($tr);
|
2013-08-17 11:07:18 +00:00
|
|
|
},
|
2013-10-23 10:02:06 +00:00
|
|
|
updateEmptyContent: function() {
|
2013-10-20 20:47:44 +00:00
|
|
|
var permissions = $('#permissions').val();
|
|
|
|
var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0;
|
2013-10-28 19:22:06 +00:00
|
|
|
$('#emptycontent').toggleClass('hidden', !isCreatable || !FileList.isEmpty);
|
|
|
|
$('#filestable thead th').toggleClass('hidden', FileList.isEmpty);
|
2013-10-20 20:47:44 +00:00
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Shows the loading mask.
|
|
|
|
*
|
|
|
|
* @see #hideMask
|
|
|
|
*/
|
2013-10-22 16:11:03 +00:00
|
|
|
showMask: function() {
|
2013-08-17 11:07:18 +00:00
|
|
|
// in case one was shown before
|
|
|
|
var $mask = $('#content .mask');
|
2013-10-22 16:11:03 +00:00
|
|
|
if ($mask.exists()) {
|
2013-08-17 11:07:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
this.$el.addClass('hidden');
|
|
|
|
|
2013-08-17 11:07:18 +00:00
|
|
|
$mask = $('<div class="mask transparent"></div>');
|
|
|
|
|
|
|
|
$mask.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')');
|
2013-08-27 08:29:28 +00:00
|
|
|
$mask.css('background-repeat', 'no-repeat');
|
2013-08-17 11:07:18 +00:00
|
|
|
$('#content').append($mask);
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
$mask.removeClass('transparent');
|
2013-08-17 11:07:18 +00:00
|
|
|
},
|
2013-10-28 19:22:06 +00:00
|
|
|
/**
|
|
|
|
* Hide the loading mask.
|
|
|
|
* @see #showMask
|
|
|
|
*/
|
2013-10-22 16:11:03 +00:00
|
|
|
hideMask: function() {
|
2013-10-28 19:22:06 +00:00
|
|
|
$('#content .mask').remove();
|
|
|
|
this.$el.removeClass('hidden');
|
2013-07-31 20:24:52 +00:00
|
|
|
},
|
|
|
|
scrollTo:function(file) {
|
|
|
|
//scroll to and highlight preselected file
|
2014-04-07 21:45:35 +00:00
|
|
|
var $scrollToRow = FileList.findFileEl(file);
|
|
|
|
if ($scrollToRow.exists()) {
|
|
|
|
$scrollToRow.addClass('searchresult');
|
|
|
|
$(window).scrollTop($scrollToRow.position().top);
|
2013-07-31 20:24:52 +00:00
|
|
|
//remove highlight when hovered over
|
2014-04-07 21:45:35 +00:00
|
|
|
$scrollToRow.one('hover', function() {
|
|
|
|
$scrollToRow.removeClass('searchresult');
|
2013-07-31 20:24:52 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2013-10-22 16:11:03 +00:00
|
|
|
filter:function(query) {
|
2014-02-11 15:52:56 +00:00
|
|
|
$('#fileList tr').each(function(i,e) {
|
2013-11-18 16:18:31 +00:00
|
|
|
if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) !== -1) {
|
2013-07-31 20:24:52 +00:00
|
|
|
$(e).addClass("searchresult");
|
|
|
|
} else {
|
|
|
|
$(e).removeClass("searchresult");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//do not use scrollto to prevent removing searchresult css class
|
|
|
|
var first = $('#fileList tr.searchresult').first();
|
2013-10-22 16:11:03 +00:00
|
|
|
if (first.exists()) {
|
2013-07-31 20:24:52 +00:00
|
|
|
$(window).scrollTop(first.position().top);
|
|
|
|
}
|
|
|
|
},
|
2013-10-22 16:11:03 +00:00
|
|
|
unfilter:function() {
|
|
|
|
$('#fileList tr.searchresult').each(function(i,e) {
|
2013-07-31 20:24:52 +00:00
|
|
|
$(e).removeClass("searchresult");
|
|
|
|
});
|
2014-01-24 12:32:31 +00:00
|
|
|
},
|
2014-02-12 13:50:23 +00:00
|
|
|
/**
|
|
|
|
* Update UI based on the current selection
|
|
|
|
*/
|
|
|
|
updateSelectionSummary: function() {
|
|
|
|
var allSelected = this.isAllSelected();
|
|
|
|
var selected;
|
|
|
|
var summary = {
|
|
|
|
totalFiles: 0,
|
|
|
|
totalDirs: 0,
|
|
|
|
totalSize: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
if (allSelected) {
|
|
|
|
summary = this.fileSummary.summary;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selected = this.getSelectedFiles();
|
|
|
|
for (var i = 0; i < selected.length; i++ ){
|
|
|
|
if (selected[i].type === 'dir') {
|
|
|
|
summary.totalDirs++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
summary.totalFiles++;
|
|
|
|
}
|
|
|
|
summary.totalSize += parseInt(selected[i].size, 10) || 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (summary.totalFiles === 0 && summary.totalDirs === 0) {
|
|
|
|
$('#headerName span.name').text(t('files','Name'));
|
|
|
|
$('#headerSize').text(t('files','Size'));
|
|
|
|
$('#modified').text(t('files','Modified'));
|
|
|
|
$('table').removeClass('multiselect');
|
|
|
|
$('.selectedActions').addClass('hidden');
|
|
|
|
$('#select_all').removeAttr('checked');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('.selectedActions').removeClass('hidden');
|
|
|
|
$('#headerSize').text(humanFileSize(summary.totalSize));
|
|
|
|
var selection = '';
|
|
|
|
if (summary.totalDirs > 0) {
|
|
|
|
selection += n('files', '%n folder', '%n folders', summary.totalDirs);
|
|
|
|
if (summary.totalFiles > 0) {
|
|
|
|
selection += ' & ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (summary.totalFiles > 0) {
|
|
|
|
selection += n('files', '%n file', '%n files', summary.totalFiles);
|
|
|
|
}
|
|
|
|
$('#headerName span.name').text(selection);
|
|
|
|
$('#modified').text('');
|
|
|
|
$('table').addClass('multiselect');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-13 19:20:00 +00:00
|
|
|
/**
|
|
|
|
* Returns whether all files are selected
|
|
|
|
* @return true if all files are selected, false otherwise
|
|
|
|
*/
|
|
|
|
isAllSelected: function() {
|
2014-02-12 13:50:23 +00:00
|
|
|
return this.$el.find('#select_all').prop('checked');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief get a list of selected files
|
|
|
|
* @param {string} property (option) the property of the file requested
|
|
|
|
* @return {array}
|
|
|
|
*
|
|
|
|
* possible values for property: name, mime, size and type
|
|
|
|
* if property is set, an array with that property for each file is returnd
|
|
|
|
* if it's ommited an array of objects with all properties is returned
|
|
|
|
*/
|
|
|
|
getSelectedFiles: function(property) {
|
|
|
|
var elements=$('td.filename input:checkbox:checked').parent().parent();
|
|
|
|
var files=[];
|
|
|
|
elements.each(function(i,element) {
|
|
|
|
// TODO: make the json format the same as in FileList.add()
|
|
|
|
var file = FileList.elementToFile($(element));
|
|
|
|
// FIXME: legacy attributes
|
|
|
|
file.origin = file.id;
|
|
|
|
file.mime = file.mimetype;
|
|
|
|
if (property) {
|
|
|
|
files.push(file[property]);
|
|
|
|
} else {
|
|
|
|
files.push(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return files;
|
2011-06-04 16:44:14 +00:00
|
|
|
}
|
2014-02-12 13:50:23 +00:00
|
|
|
}
|
2011-08-03 22:22:44 +00:00
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
$(document).ready(function() {
|
2013-10-28 19:22:06 +00:00
|
|
|
FileList.initialize();
|
2013-03-13 16:26:37 +00:00
|
|
|
|
|
|
|
// handle upload events
|
2014-04-07 21:45:35 +00:00
|
|
|
var fileUploadStart = $('#file_upload_start');
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2014-04-07 21:45:35 +00:00
|
|
|
fileUploadStart.on('fileuploaddrop', function(e, data) {
|
2013-09-18 12:39:39 +00:00
|
|
|
OC.Upload.log('filelist handle fileuploaddrop', e, data);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-10-15 14:14:23 +00:00
|
|
|
var dropTarget = $(e.originalEvent.target).closest('tr, .crumb');
|
2013-10-22 16:11:03 +00:00
|
|
|
if (dropTarget && (dropTarget.data('type') === 'dir' || dropTarget.hasClass('crumb'))) { // drag&drop upload to folder
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-09-06 20:40:10 +00:00
|
|
|
// remember as context
|
|
|
|
data.context = dropTarget;
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-09-06 16:51:27 +00:00
|
|
|
var dir = dropTarget.data('file');
|
2013-10-15 14:14:23 +00:00
|
|
|
// if from file list, need to prepend parent dir
|
2013-10-22 16:11:03 +00:00
|
|
|
if (dir) {
|
2013-10-15 14:14:23 +00:00
|
|
|
var parentDir = $('#dir').val() || '/';
|
2013-10-22 16:11:03 +00:00
|
|
|
if (parentDir[parentDir.length - 1] !== '/') {
|
2013-10-15 14:14:23 +00:00
|
|
|
parentDir += '/';
|
|
|
|
}
|
|
|
|
dir = parentDir + dir;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
// read full path from crumb
|
|
|
|
dir = dropTarget.data('dir') || '/';
|
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
// update folder in form
|
|
|
|
data.formData = function(form) {
|
2013-10-15 14:14:23 +00:00
|
|
|
return [
|
|
|
|
{name: 'dir', value: dir},
|
2014-02-19 21:23:39 +00:00
|
|
|
{name: 'requesttoken', value: oc_requesttoken},
|
2014-04-07 21:45:35 +00:00
|
|
|
{name: 'file_directory', value: data.files[0].relativePath}
|
2013-10-15 14:14:23 +00:00
|
|
|
];
|
2013-08-16 09:40:55 +00:00
|
|
|
};
|
2013-10-28 19:22:06 +00:00
|
|
|
} else {
|
|
|
|
// cancel uploads to current dir if no permission
|
|
|
|
var isCreatable = (FileList.getDirectoryPermissions() & OC.PERMISSION_CREATE) !== 0;
|
|
|
|
if (!isCreatable) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-30 09:41:04 +00:00
|
|
|
}
|
2013-03-13 16:26:37 +00:00
|
|
|
});
|
2014-04-07 21:45:35 +00:00
|
|
|
fileUploadStart.on('fileuploadadd', function(e, data) {
|
2013-09-18 12:39:39 +00:00
|
|
|
OC.Upload.log('filelist handle fileuploadadd', e, data);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-09-08 08:41:20 +00:00
|
|
|
//finish delete if we are uploading a deleted file
|
2013-10-22 16:11:03 +00:00
|
|
|
if (FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1) {
|
2013-08-16 09:40:55 +00:00
|
|
|
FileList.finishDelete(null, true); //delete file before continuing
|
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
// add ui visualization to existing folder
|
2013-10-22 16:11:03 +00:00
|
|
|
if (data.context && data.context.data('type') === 'dir') {
|
2013-08-16 09:40:55 +00:00
|
|
|
// add to existing folder
|
|
|
|
|
|
|
|
// update upload counter ui
|
2014-04-07 21:45:35 +00:00
|
|
|
var uploadText = data.context.find('.uploadtext');
|
|
|
|
var currentUploads = parseInt(uploadText.attr('currentUploads'), 10);
|
2013-08-16 09:40:55 +00:00
|
|
|
currentUploads += 1;
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.attr('currentUploads', currentUploads);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-09-04 13:24:25 +00:00
|
|
|
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
2013-10-22 16:11:03 +00:00
|
|
|
if (currentUploads === 1) {
|
2013-08-16 09:40:55 +00:00
|
|
|
var img = OC.imagePath('core', 'loading.gif');
|
|
|
|
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.text(translatedText);
|
|
|
|
uploadText.show();
|
2013-08-16 09:40:55 +00:00
|
|
|
} else {
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.text(translatedText);
|
2013-03-13 16:26:37 +00:00
|
|
|
}
|
2013-08-16 09:40:55 +00:00
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
});
|
2013-09-08 08:41:20 +00:00
|
|
|
/*
|
|
|
|
* when file upload done successfully add row to filelist
|
|
|
|
* update counter when uploading to sub folder
|
|
|
|
*/
|
2014-04-07 21:45:35 +00:00
|
|
|
fileUploadStart.on('fileuploaddone', function(e, data) {
|
2013-09-18 12:39:39 +00:00
|
|
|
OC.Upload.log('filelist handle fileuploaddone', e, data);
|
2014-02-04 10:14:00 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
var response;
|
|
|
|
if (typeof data.result === 'string') {
|
|
|
|
response = data.result;
|
|
|
|
} else {
|
|
|
|
// fetch response from iframe
|
|
|
|
response = data.result[0].body.innerText;
|
|
|
|
}
|
|
|
|
var result=$.parseJSON(response);
|
2013-03-13 16:26:37 +00:00
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
if (typeof result[0] !== 'undefined' && result[0].status === 'success') {
|
2013-08-16 09:40:55 +00:00
|
|
|
var file = result[0];
|
2014-04-07 21:45:35 +00:00
|
|
|
var size = 0;
|
2013-03-13 16:26:37 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
if (data.context && data.context.data('type') === 'dir') {
|
2013-03-13 16:26:37 +00:00
|
|
|
|
|
|
|
// update upload counter ui
|
2014-04-07 21:45:35 +00:00
|
|
|
var uploadText = data.context.find('.uploadtext');
|
|
|
|
var currentUploads = parseInt(uploadText.attr('currentUploads'), 10);
|
2013-08-16 09:40:55 +00:00
|
|
|
currentUploads -= 1;
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.attr('currentUploads', currentUploads);
|
2013-08-14 04:29:19 +00:00
|
|
|
var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads);
|
2013-10-22 16:11:03 +00:00
|
|
|
if (currentUploads === 0) {
|
2014-02-19 13:47:29 +00:00
|
|
|
var img = OC.imagePath('core', 'filetypes/folder');
|
2013-03-13 16:26:37 +00:00
|
|
|
data.context.find('td.filename').attr('style','background-image:url('+img+')');
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.text(translatedText);
|
|
|
|
uploadText.hide();
|
2013-03-13 16:26:37 +00:00
|
|
|
} else {
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.text(translatedText);
|
2013-03-13 16:26:37 +00:00
|
|
|
}
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
// update folder size
|
2014-04-07 21:45:35 +00:00
|
|
|
size = parseInt(data.context.data('size'), 10);
|
|
|
|
size += parseInt(file.size, 10);
|
2013-08-16 09:40:55 +00:00
|
|
|
data.context.attr('data-size', size);
|
|
|
|
data.context.find('td.filesize').text(humanFileSize(size));
|
2014-04-07 21:04:08 +00:00
|
|
|
} else {
|
2014-02-07 11:53:42 +00:00
|
|
|
// only append new file if uploaded into the current folder
|
2014-04-07 21:04:08 +00:00
|
|
|
if (file.directory !== '/' && file.directory !== FileList.getCurrentDirectory()) {
|
2014-02-19 21:28:32 +00:00
|
|
|
|
2014-04-07 21:04:08 +00:00
|
|
|
var fileDirectory = file.directory.replace('/','').replace(/\/$/, "").split('/');
|
2014-02-19 21:28:32 +00:00
|
|
|
|
2014-04-07 21:04:08 +00:00
|
|
|
if (fileDirectory.length === 1) {
|
|
|
|
fileDirectory = fileDirectory[0];
|
2014-02-19 21:28:32 +00:00
|
|
|
|
2014-02-19 21:23:39 +00:00
|
|
|
// Get the directory
|
2014-04-09 20:16:41 +00:00
|
|
|
var fd = FileList.findFileEl(fileDirectory);
|
|
|
|
if (fd.length === 0) {
|
2014-04-07 21:04:08 +00:00
|
|
|
var dir = {
|
|
|
|
name: fileDirectory,
|
|
|
|
type: 'dir',
|
|
|
|
mimetype: 'httpd/unix-directory',
|
|
|
|
permissions: file.permissions,
|
|
|
|
size: 0,
|
|
|
|
id: file.parentId
|
|
|
|
};
|
|
|
|
FileList.add(dir, {insert: true});
|
2014-02-19 21:23:39 +00:00
|
|
|
}
|
2014-04-07 21:04:08 +00:00
|
|
|
} else {
|
|
|
|
fileDirectory = fileDirectory[0];
|
2014-02-19 21:23:39 +00:00
|
|
|
}
|
2014-02-20 20:18:27 +00:00
|
|
|
|
2014-04-07 21:04:08 +00:00
|
|
|
fileDirectory = FileList.findFileEl(fileDirectory);
|
2014-02-19 21:28:32 +00:00
|
|
|
|
2014-02-19 21:23:39 +00:00
|
|
|
// update folder size
|
2014-04-07 21:45:35 +00:00
|
|
|
size = parseInt(fileDirectory.attr('data-size'), 10);
|
|
|
|
size += parseInt(file.size, 10);
|
2014-04-07 21:04:08 +00:00
|
|
|
fileDirectory.attr('data-size', size);
|
|
|
|
fileDirectory.find('td.filesize').text(humanFileSize(size));
|
2014-02-19 21:28:32 +00:00
|
|
|
|
2013-10-15 14:14:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-03-13 16:26:37 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
// add as stand-alone row to filelist
|
2014-04-07 21:45:35 +00:00
|
|
|
size = t('files', 'Pending');
|
2013-10-22 16:11:03 +00:00
|
|
|
if (data.files[0].size>=0) {
|
2013-08-16 09:40:55 +00:00
|
|
|
size=data.files[0].size;
|
|
|
|
}
|
|
|
|
//should the file exist in the list remove it
|
|
|
|
FileList.remove(file.name);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-08-16 09:40:55 +00:00
|
|
|
// create new file context
|
2013-10-28 19:22:06 +00:00
|
|
|
data.context = FileList.add(file, {insert: true});
|
2013-03-13 16:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-04-07 21:45:35 +00:00
|
|
|
fileUploadStart.on('fileuploadstop', function(e, data) {
|
2013-09-18 12:39:39 +00:00
|
|
|
OC.Upload.log('filelist handle fileuploadstop', e, data);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-08-21 12:58:28 +00:00
|
|
|
//if user pressed cancel hide upload chrome
|
2013-09-06 20:40:10 +00:00
|
|
|
if (data.errorThrown === 'abort') {
|
2013-08-21 12:58:28 +00:00
|
|
|
//cleanup uploading to a dir
|
2014-04-07 21:45:35 +00:00
|
|
|
var uploadText = $('tr .uploadtext');
|
2014-02-19 13:47:29 +00:00
|
|
|
var img = OC.imagePath('core', 'filetypes/folder');
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.parents('td.filename').attr('style','background-image:url('+img+')');
|
|
|
|
uploadText.fadeOut();
|
|
|
|
uploadText.attr('currentUploads', 0);
|
2013-08-21 12:58:28 +00:00
|
|
|
}
|
2013-08-16 09:40:55 +00:00
|
|
|
});
|
2014-04-07 21:45:35 +00:00
|
|
|
fileUploadStart.on('fileuploadfail', function(e, data) {
|
2013-09-18 12:39:39 +00:00
|
|
|
OC.Upload.log('filelist handle fileuploadfail', e, data);
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2013-08-21 12:58:28 +00:00
|
|
|
//if user pressed cancel hide upload chrome
|
|
|
|
if (data.errorThrown === 'abort') {
|
|
|
|
//cleanup uploading to a dir
|
2014-04-07 21:45:35 +00:00
|
|
|
var uploadText = $('tr .uploadtext');
|
2014-02-19 13:47:29 +00:00
|
|
|
var img = OC.imagePath('core', 'filetypes/folder');
|
2014-04-07 21:45:35 +00:00
|
|
|
uploadText.parents('td.filename').attr('style','background-image:url('+img+')');
|
|
|
|
uploadText.fadeOut();
|
|
|
|
uploadText.attr('currentUploads', 0);
|
2013-08-21 12:58:28 +00:00
|
|
|
}
|
2013-08-16 09:40:55 +00:00
|
|
|
});
|
2013-09-08 15:29:43 +00:00
|
|
|
|
2011-08-05 05:37:08 +00:00
|
|
|
$('#notification').hide();
|
2013-02-09 16:20:08 +00:00
|
|
|
$('#notification:first-child').on('click', '.replace', function() {
|
2013-07-31 20:24:52 +00:00
|
|
|
OC.Notification.hide(function() {
|
2014-04-07 21:45:35 +00:00
|
|
|
FileList.replace(
|
|
|
|
$('#notification > span').attr('data-oldName'),
|
|
|
|
$('#notification > span').attr('data-newName'),
|
|
|
|
$('#notification > span').attr('data-isNewFile'));
|
2013-07-31 20:24:52 +00:00
|
|
|
});
|
2012-07-30 16:21:58 +00:00
|
|
|
});
|
2013-02-09 16:20:08 +00:00
|
|
|
$('#notification:first-child').on('click', '.suggest', function() {
|
2014-01-10 14:02:26 +00:00
|
|
|
var file = $('#notification > span').attr('data-oldName');
|
2013-10-28 19:22:06 +00:00
|
|
|
FileList.findFileEl(file).removeClass('hidden');
|
2013-07-31 20:24:52 +00:00
|
|
|
OC.Notification.hide();
|
2012-09-05 04:12:11 +00:00
|
|
|
});
|
2013-02-09 16:20:08 +00:00
|
|
|
$('#notification:first-child').on('click', '.cancel', function() {
|
|
|
|
if ($('#notification > span').attr('data-isNewFile')) {
|
2012-09-05 04:12:11 +00:00
|
|
|
FileList.deleteCanceled = false;
|
2013-02-09 16:20:08 +00:00
|
|
|
FileList.deleteFiles = [$('#notification > span').attr('data-oldName')];
|
2012-09-05 04:12:11 +00:00
|
|
|
}
|
2012-07-30 16:21:58 +00:00
|
|
|
});
|
2012-09-23 01:16:52 +00:00
|
|
|
FileList.useUndo=(window.onbeforeunload)?true:false;
|
2013-10-22 16:11:03 +00:00
|
|
|
$(window).bind('beforeunload', function () {
|
2012-07-30 16:21:58 +00:00
|
|
|
if (FileList.lastAction) {
|
|
|
|
FileList.lastAction();
|
|
|
|
}
|
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
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
function decodeQuery(query) {
|
2013-09-20 19:52:40 +00:00
|
|
|
return query.replace(/\+/g, ' ');
|
|
|
|
}
|
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
function parseHashQuery() {
|
2013-08-29 19:56:14 +00:00
|
|
|
var hash = window.location.hash,
|
2014-04-07 21:45:35 +00:00
|
|
|
pos = hash.indexOf('?');
|
2013-10-22 16:11:03 +00:00
|
|
|
if (pos >= 0) {
|
2013-08-29 19:56:14 +00:00
|
|
|
return hash.substr(pos + 1);
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2013-10-22 16:11:03 +00:00
|
|
|
function parseCurrentDirFromUrl() {
|
2013-08-29 19:56:14 +00:00
|
|
|
var query = parseHashQuery(),
|
2014-04-07 21:45:35 +00:00
|
|
|
params;
|
2013-08-29 19:56:14 +00:00
|
|
|
// try and parse from URL hash first
|
2013-10-22 16:11:03 +00:00
|
|
|
if (query) {
|
2013-09-20 19:52:40 +00:00
|
|
|
params = OC.parseQueryString(decodeQuery(query));
|
2013-08-29 19:56:14 +00:00
|
|
|
}
|
|
|
|
// else read from query attributes
|
2013-10-22 16:11:03 +00:00
|
|
|
if (!params) {
|
2013-09-20 19:52:40 +00:00
|
|
|
params = OC.parseQueryString(decodeQuery(location.search));
|
2013-08-29 19:56:14 +00:00
|
|
|
}
|
|
|
|
return (params && params.dir) || '/';
|
|
|
|
}
|
|
|
|
|
2013-10-14 15:47:38 +00:00
|
|
|
// disable ajax/history API for public app (TODO: until it gets ported)
|
2013-10-28 19:22:06 +00:00
|
|
|
// fallback to hashchange when no history support
|
|
|
|
if (!window.history.pushState) {
|
|
|
|
$(window).on('hashchange', function() {
|
|
|
|
FileList.changeDirectory(parseCurrentDirFromUrl(), false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
window.onpopstate = function(e) {
|
|
|
|
var targetDir;
|
|
|
|
if (e.state && e.state.dir) {
|
|
|
|
targetDir = e.state.dir;
|
2013-08-17 11:07:18 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
else{
|
|
|
|
// read from URL
|
|
|
|
targetDir = parseCurrentDirFromUrl();
|
|
|
|
}
|
|
|
|
if (targetDir) {
|
|
|
|
FileList.changeDirectory(targetDir, false);
|
2013-10-14 15:47:38 +00:00
|
|
|
}
|
2013-10-28 19:22:06 +00:00
|
|
|
};
|
2014-02-20 14:16:45 +00:00
|
|
|
|
2014-02-11 14:57:45 +00:00
|
|
|
$(window).scroll(function(e) {FileList._onScroll(e);});
|
|
|
|
|
2013-10-28 19:22:06 +00:00
|
|
|
var dir = parseCurrentDirFromUrl();
|
|
|
|
// trigger ajax load, deferred to let sub-apps do their overrides first
|
|
|
|
setTimeout(function() {
|
|
|
|
FileList.changeDirectory(dir, false, true);
|
|
|
|
}, 0);
|
2011-08-03 22:22:44 +00:00
|
|
|
});
|
2013-10-28 19:22:06 +00:00
|
|
|
|