summaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/admin.js12
-rw-r--r--apps/files/js/file-upload.js37
-rw-r--r--apps/files/js/fileactions.js53
-rw-r--r--apps/files/js/filelist.js55
-rw-r--r--apps/files/js/files.js92
-rw-r--r--apps/files/js/upgrade.js11
-rw-r--r--apps/files/js/upload.js11
7 files changed, 222 insertions, 49 deletions
diff --git a/apps/files/js/admin.js b/apps/files/js/admin.js
index bfa96670635..f735079fcbe 100644
--- a/apps/files/js/admin.js
+++ b/apps/files/js/admin.js
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
function switchPublicFolder()
{
var publicEnable = $('#publicEnable').is(':checked');
@@ -10,7 +20,7 @@ function switchPublicFolder()
$(document).ready(function(){
switchPublicFolder(); // Execute the function after loading DOM tree
$('#publicEnable').click(function(){
- switchPublicFolder(); // To get rid of onClick()
+ switchPublicFolder(); // To get rid of onClick()
});
$('#allowZipDownload').bind('change', function() {
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 225c3319107..f962a7044a8 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -1,3 +1,13 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
/**
* The file upload code uses several hooks to interact with blueimps jQuery file upload library:
* 1. the core upload handling hooks are added when initializing the plugin,
@@ -8,6 +18,8 @@
* - TODO music upload button
*/
+/* global OC, t, n */
+
/**
* Function that will allow us to know if Ajax uploads are supported
* @link https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html
@@ -241,10 +253,22 @@ $(document).ready(function() {
// add size
selection.totalBytes += file.size;
- //check max upload size
- if (selection.totalBytes > $('#max_upload').val()) {
+ // check PHP upload limit
+ if (selection.totalBytes > $('#upload_limit').val()) {
+ data.textStatus = 'sizeexceedlimit';
+ data.errorThrown = t('files', 'Total file size {size1} exceeds upload limit {size2}', {
+ 'size1': humanFileSize(selection.totalBytes),
+ 'size2': humanFileSize($('#upload_limit').val())
+ });
+ }
+
+ // check free space
+ if (selection.totalBytes > $('#free_space').val()) {
data.textStatus = 'notenoughspace';
- data.errorThrown = t('files', 'Not enough space available');
+ data.errorThrown = t('files', 'Not enough free space, you are uploading {size1} but only {size2} is left', {
+ 'size1': humanFileSize(selection.totalBytes),
+ 'size2': humanFileSize($('#free_space').val())
+ });
}
// end upload for whole selection on error
@@ -315,6 +339,13 @@ $(document).ready(function() {
} else {
// HTTP connection problem
OC.Notification.show(data.errorThrown);
+ if (data.result) {
+ var result = JSON.parse(data.result);
+ if (result && result[0] && result[0].data && result[0].data.code === 'targetnotfound') {
+ // abort upload of next files if any
+ OC.Upload.cancelUploads();
+ }
+ }
}
//hide notification after 10 sec
setTimeout(function() {
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 74bb711ef3d..9a69d7b3688 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -1,3 +1,15 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, FileList */
+/* global trashBinApp */
var FileActions = {
actions: {},
defaults: {},
@@ -45,8 +57,9 @@ var FileActions = {
return filteredActions;
},
getDefault: function (mime, type, permissions) {
+ var mimePart;
if (mime) {
- var mimePart = mime.substr(0, mime.indexOf('/'));
+ mimePart = mime.substr(0, mime.indexOf('/'));
}
var name = false;
if (mime && FileActions.defaults[mime]) {
@@ -71,13 +84,15 @@ var FileActions = {
FileActions.currentFile = parent;
var actions = FileActions.get(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var file = FileActions.getCurrentFile();
+ var nameLinks;
if (FileList.findFileEl(file).data('renaming')) {
return;
}
// recreate fileactions
- parent.children('a.name').find('.fileactions').remove();
- parent.children('a.name').append('<span class="fileactions" />');
+ nameLinks = parent.children('a.name');
+ nameLinks.find('.fileactions, .nametext .action').remove();
+ nameLinks.append('<span class="fileactions" />');
var defaultAction = FileActions.getDefault(FileActions.getCurrentMimeType(), FileActions.getCurrentType(), FileActions.getCurrentPermissions());
var actionHandler = function (event) {
@@ -97,21 +112,30 @@ var FileActions = {
}
if ((name === 'Download' || action !== defaultAction) && name !== 'Delete') {
- var img = FileActions.icons[name];
+ var img = FileActions.icons[name],
+ actionText = t('files', name),
+ actionContainer = 'a.name>span.fileactions';
+
+ if (name === 'Rename') {
+ // rename has only an icon which appears behind
+ // the file name
+ actionText = '';
+ actionContainer = 'a.name span.nametext';
+ }
if (img.call) {
img = img(file);
}
var html = '<a href="#" class="action" data-action="' + name + '">';
if (img) {
- html += '<img class ="svg" src="' + img + '" /> ';
+ html += '<img class ="svg" src="' + img + '" />';
}
- html += t('files', name) + '</a>';
+ html += '<span> ' + actionText + '</span></a>';
var element = $(html);
element.data('action', name);
//alert(element);
element.on('click', {a: null, elem: parent, actionFunc: actions[name]}, actionHandler);
- parent.find('a.name>span.fileactions').append(element);
+ parent.find(actionContainer).append(element);
}
};
@@ -130,13 +154,14 @@ var FileActions = {
parent.parent().children().last().find('.action.delete').remove();
if (actions['Delete']) {
var img = FileActions.icons['Delete'];
+ var html;
if (img.call) {
img = img(file);
}
if (typeof trashBinApp !== 'undefined' && trashBinApp) {
- var html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
+ html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
} else {
- var html = '<a href="#" class="action delete delete-icon" />';
+ html = '<a href="#" class="action delete delete-icon" />';
}
var element = $(html);
element.data('action', actions['Delete']);
@@ -163,17 +188,21 @@ var FileActions = {
};
$(document).ready(function () {
+ var downloadScope;
if ($('#allowZipDownload').val() == 1) {
- var downloadScope = 'all';
+ downloadScope = 'all';
} else {
- var downloadScope = 'file';
+ downloadScope = 'file';
}
if (typeof disableDownloadActions == 'undefined' || !disableDownloadActions) {
FileActions.register(downloadScope, 'Download', OC.PERMISSION_READ, function () {
return OC.imagePath('core', 'actions/download');
}, function (filename) {
- window.location = OC.filePath('files', 'ajax', 'download.php') + '?files=' + encodeURIComponent(filename) + '&dir=' + encodeURIComponent($('#dir').val());
+ var url = FileList.getDownloadUrl(filename);
+ if (url) {
+ OC.redirect(url);
+ }
});
}
$('#fileList tr').each(function () {
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 66968ab54c7..a855d6cbe59 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -1,4 +1,16 @@
-var FileList={
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, t, n, FileList, FileActions, Files */
+/* global procesSelection, dragOptions, SVGSupport, replaceSVG */
+window.FileList={
useUndo:true,
postProcessList: function() {
$('#fileList tr').each(function() {
@@ -28,7 +40,8 @@ var FileList={
}
FileList.updateFileSummary();
procesSelection();
-
+
+ $(window).scrollTop(0);
$fileList.trigger(jQuery.Event("updated"));
},
createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions) {
@@ -191,6 +204,7 @@ var FileList={
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
},
setCurrentDir: function(targetDir, changeUrl) {
+ var url;
$('#dir').val(targetDir);
if (changeUrl !== false) {
if (window.history.pushState && changeUrl !== false) {
@@ -394,7 +408,7 @@ var FileList={
}
return true;
};
-
+
form.submit(function(event) {
event.stopPropagation();
event.preventDefault();
@@ -421,10 +435,9 @@ var FileList={
tr.attr('data-file', newname);
var path = td.children('a.name').attr('href');
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname)));
+ var basename = newname;
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
- var basename=newname.substr(0,newname.lastIndexOf('.'));
- } else {
- var basename=newname;
+ basename = newname.substr(0,newname.lastIndexOf('.'));
}
td.find('a.name span.nametext').text(basename);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
@@ -468,7 +481,7 @@ var FileList={
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);
if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') {
if ( ! td.find('a.name span.extension').exists() ) {
@@ -477,6 +490,7 @@ var FileList={
td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.')));
}
form.remove();
+ FileActions.display( tr.find('td.filename'), true);
td.children('a.name').show();
} catch (error) {
input.attr('title', error);
@@ -529,10 +543,9 @@ var FileList={
td.children('a.name .span').text(newName);
var path = td.children('a.name').attr('href');
td.children('a.name').attr('href', path.replace(encodeURIComponent(oldName), encodeURIComponent(newName)));
+ var basename = newName;
if (newName.indexOf('.') > 0) {
- var basename = newName.substr(0, newName.lastIndexOf('.'));
- } else {
- var basename = newName;
+ basename = newName.substr(0, newName.lastIndexOf('.'));
}
td.children('a.name').empty();
var span = $('<span class="nametext"></span>');
@@ -780,6 +793,20 @@ var FileList={
$('#fileList tr.searchresult').each(function(i,e) {
$(e).removeClass("searchresult");
});
+ },
+
+ /**
+ * Returns the download URL of the given file
+ * @param filename file name of the file
+ * @param dir optional directory in which the file name is, defaults to the current directory
+ */
+ getDownloadUrl: function(filename, dir) {
+ var params = {
+ files: filename,
+ dir: dir || FileList.getCurrentDirectory(),
+ download: null
+ };
+ return OC.filePath('files', 'ajax', 'download.php') + '?' + OC.buildQueryString(params);
}
};
@@ -819,7 +846,7 @@ $(document).ready(function() {
{name: 'requesttoken', value: oc_requesttoken}
];
};
- }
+ }
});
file_upload_start.on('fileuploadadd', function(e, data) {
@@ -858,7 +885,7 @@ $(document).ready(function() {
*/
file_upload_start.on('fileuploaddone', function(e, data) {
OC.Upload.log('filelist handle fileuploaddone', e, data);
-
+
var response;
if (typeof data.result === 'string') {
response = data.result;
@@ -895,8 +922,8 @@ $(document).ready(function() {
data.context.find('td.filesize').text(humanFileSize(size));
} else {
- // only append new file if dragged onto current dir's crumb (last)
- if (data.context && data.context.hasClass('crumb') && !data.context.hasClass('last')) {
+ // only append new file if uploaded into the current folder
+ if (file.directory !== FileList.getCurrentDirectory()) {
return;
}
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index dc7e893340f..1ec4c4ec7ab 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -1,4 +1,16 @@
-Files={
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC, t, n, FileList, FileActions */
+/* global getURLParameter, isPublic */
+var Files = {
// file space size sync
_updateStorageStatistics: function() {
Files._updateStorageStatisticsTimeout = null;
@@ -41,6 +53,7 @@ Files={
}
if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) {
$('#max_upload').val(response.data.uploadMaxFilesize);
+ $('#free_space').val(response.data.freeSpace);
$('#upload.button').attr('original-title', response.data.maxHumanFilesize);
$('#usedSpacePercent').val(response.data.usedSpacePercent);
Files.displayStorageWarnings();
@@ -67,17 +80,25 @@ Files={
return fileName;
},
- isFileNameValid:function (name) {
- if (name === '.') {
- throw t('files', '\'.\' is an invalid file name.');
- } else if (name.length === 0) {
+ /**
+ * Checks whether the given file name is valid.
+ * @param name file name to check
+ * @return true if the file name is valid.
+ * Throws a string exception with an error message if
+ * the file name is not valid
+ */
+ isFileNameValid: function (name) {
+ var trimmedName = name.trim();
+ if (trimmedName === '.' || trimmedName === '..') {
+ throw t('files', '"{name}" is an invalid file name.', {name: name});
+ } else if (trimmedName.length === 0) {
throw t('files', 'File name cannot be empty.');
}
-
// check for invalid characters
- var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
+ var invalid_characters =
+ ['\\', '/', '<', '>', ':', '"', '|', '?', '*', '\n'];
for (var i = 0; i < invalid_characters.length; i++) {
- if (name.indexOf(invalid_characters[i]) !== -1) {
+ if (trimmedName.indexOf(invalid_characters[i]) !== -1) {
throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
}
}
@@ -384,7 +405,7 @@ $(document).ready(function() {
Files.resizeBreadcrumbs(width, true);
// display storage warnings
- setTimeout ( "Files.displayStorageWarnings()", 100 );
+ setTimeout(Files.displayStorageWarnings, 100);
OC.Notification.setDefault(Files.displayStorageWarnings);
// only possible at the moment if user is logged in
@@ -493,7 +514,7 @@ var createDragShadow = function(event) {
var dir=$('#dir').val();
$(selectedFiles).each(function(i,elem) {
- var newtr = $('<tr/>').attr('data-dir', dir).attr('data-filename', elem.name);
+ var newtr = $('<tr/>').attr('data-dir', dir).attr('data-filename', elem.name).attr('data-origin', elem.origin);
newtr.append($('<td/>').addClass('filename').text(elem.name));
newtr.append($('<td/>').addClass('size').text(humanFileSize(elem.size)));
tbody.append(newtr);
@@ -511,13 +532,30 @@ var createDragShadow = function(event) {
};
//options for file drag/drop
+//start&stop handlers needs some cleaning up
var dragOptions={
revert: 'invalid', revertDuration: 300,
opacity: 0.7, zIndex: 100, appendTo: 'body', cursorAt: { left: 24, top: 18 },
helper: createDragShadow, cursor: 'move',
- stop: function(event, ui) {
- $('#fileList tr td.filename').addClass('ui-draggable');
- }
+ start: function(event, ui){
+ var $selectedFiles = $('td.filename input:checkbox:checked');
+ if($selectedFiles.length > 1){
+ $selectedFiles.parents('tr').fadeTo(250, 0.2);
+ }
+ else{
+ $(this).fadeTo(250, 0.2);
+ }
+ },
+ stop: function(event, ui) {
+ var $selectedFiles = $('td.filename input:checkbox:checked');
+ if($selectedFiles.length > 1){
+ $selectedFiles.parents('tr').fadeTo(250, 1);
+ }
+ else{
+ $(this).fadeTo(250, 1);
+ }
+ $('#fileList tr td.filename').addClass('ui-draggable');
+ }
};
// sane browsers support using the distance option
if ( $('html.ie').length === 0) {
@@ -525,6 +563,7 @@ if ( $('html.ie').length === 0) {
}
var folderDropOptions={
+ hoverClass: "canDrop",
drop: function( event, ui ) {
//don't allow moving a file into a selected folder
if ($(event.target).parents('tr').find('td input:first').prop('checked') === true) {
@@ -537,6 +576,11 @@ var folderDropOptions={
$(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: dir+'/'+target }, function(result) {
if (result) {
if (result.status === 'success') {
@@ -559,6 +603,7 @@ var folderDropOptions={
} else {
OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error'));
}
+ td.css('background-image', oldBackgroundImage);
});
});
},
@@ -583,6 +628,11 @@ var crumbDropOptions={
$(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') {
@@ -597,6 +647,7 @@ var crumbDropOptions={
} else {
OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error'));
}
+ td.css('background-image', oldBackgroundImage);
});
});
},
@@ -624,10 +675,10 @@ function procesSelection() {
var totalSize = 0;
for(var i=0; i<selectedFiles.length; i++) {
totalSize+=selectedFiles[i].size;
- };
+ }
for(var i=0; i<selectedFolders.length; i++) {
totalSize+=selectedFolders[i].size;
- };
+ }
$('#headerSize').text(humanFileSize(totalSize));
var selection = '';
if (selectedFolders.length > 0) {
@@ -663,7 +714,8 @@ function getSelectedFilesTrash(property) {
mime:$(element).data('mime'),
type:$(element).data('type'),
size:$(element).data('size'),
- etag:$(element).data('etag')
+ etag:$(element).data('etag'),
+ origin: $(element).data('id')
};
if (property) {
files.push(file[property]);
@@ -720,7 +772,7 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
console.warn('Files.lazyLoadPreview(): missing etag argument');
}
- if ( $('#publicUploadButtonMock').length ) {
+ if ( $('#isPublic').length ) {
urlSpec.t = $('#dirToken').val();
previewURL = OC.Router.generate('core_ajax_public_preview', urlSpec);
} else {
@@ -738,10 +790,11 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
}
img.src = previewURL;
});
-}
+};
function getUniqueName(name) {
if (FileList.findFileEl(name).exists()) {
+ var numMatch;
var parts=name.split('.');
var extension = "";
if (parts.length > 1) {
@@ -775,7 +828,7 @@ function checkTrashStatus() {
function onClickBreadcrumb(e) {
var $el = $(e.target).closest('.crumb'),
- $targetDir = $el.data('dir');
+ $targetDir = $el.data('dir'),
isPublic = !!$('#isPublic').val();
if ($targetDir !== undefined && !isPublic) {
@@ -783,3 +836,4 @@ function onClickBreadcrumb(e) {
FileList.changeDirectory(decodeURIComponent($targetDir));
}
}
+
diff --git a/apps/files/js/upgrade.js b/apps/files/js/upgrade.js
index 02d57fc9e6c..714adf824a1 100644
--- a/apps/files/js/upgrade.js
+++ b/apps/files/js/upgrade.js
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC */
$(document).ready(function () {
var eventSource, total, bar = $('#progressbar');
console.log('start');
diff --git a/apps/files/js/upload.js b/apps/files/js/upload.js
index 9d9f61f600e..617cf4b1c1d 100644
--- a/apps/files/js/upload.js
+++ b/apps/files/js/upload.js
@@ -1,3 +1,14 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+/* global OC */
function Upload(fileSelector) {
if ($.support.xhrFileUpload) {
return new XHRUpload(fileSelector.target.files);