From 0736bfb43a0ecc81ba1eb38c4b32fea8ed454957 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 4 Oct 2013 17:49:42 +0200 Subject: Do not call changeDirectory() when no dir set on breadcrumb Some apps like the files_trashbin app do not set a directory on its "home" breadcrumb link. This fix makes sure that the click event doesn't do anything in that case and lets the browser open the link. This fixes the "home" icon in the trashbin app which now correctly reopens the files app. --- apps/files/js/files.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'apps/files/js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 899bc6469e5..09f5d6f114c 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -701,7 +701,10 @@ function checkTrashStatus() { } function onClickBreadcrumb(e){ - var $el = $(e.target).closest('.crumb'); - e.preventDefault(); - FileList.changeDirectory(decodeURIComponent($el.data('dir'))); + var $el = $(e.target).closest('.crumb'), + $targetDir = $el.data('dir'); + if ($targetDir !== undefined){ + e.preventDefault(); + FileList.changeDirectory(decodeURIComponent($targetDir)); + } } -- cgit v1.2.3 From 7c6ed6ab33e8487d6de135b5e956a82685bf4463 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 8 Oct 2013 15:03:24 +0200 Subject: catch exceptions while uploading and pass on the error message --- apps/files/ajax/upload.php | 51 ++++++++++++++++++++++++-------------------- apps/files/js/file-upload.js | 2 +- 2 files changed, 29 insertions(+), 24 deletions(-) (limited to 'apps/files/js') diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 0920bf62109..45fb17de94a 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -110,30 +110,35 @@ if (strpos($dir, '..') === false) { || (isset($_POST['resolution']) && $_POST['resolution']==='replace') ) { // upload and overwrite file - if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { - - // updated max file size after upload - $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir); - - $meta = \OC\Files\Filesystem::getFileInfo($target); - if ($meta === false) { - $error = $l->t('Upload failed. Could not get file info.'); + try + { + if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { + + // updated max file size after upload + $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir); + + $meta = \OC\Files\Filesystem::getFileInfo($target); + if ($meta === false) { + $error = $l->t('Upload failed. Could not get file info.'); + } else { + $result[] = array('status' => 'success', + 'mime' => $meta['mimetype'], + 'mtime' => $meta['mtime'], + 'size' => $meta['size'], + 'id' => $meta['fileid'], + 'name' => basename($target), + 'originalname' => $files['tmp_name'][$i], + 'uploadMaxFilesize' => $maxUploadFileSize, + 'maxHumanFilesize' => $maxHumanFileSize, + 'permissions' => $meta['permissions'], + ); + } + } else { - $result[] = array('status' => 'success', - 'mime' => $meta['mimetype'], - 'mtime' => $meta['mtime'], - 'size' => $meta['size'], - 'id' => $meta['fileid'], - 'name' => basename($target), - 'originalname' => $files['tmp_name'][$i], - 'uploadMaxFilesize' => $maxUploadFileSize, - 'maxHumanFilesize' => $maxHumanFileSize, - 'permissions' => $meta['permissions'], - ); + $error = $l->t('Upload failed. Could not find uploaded file'); } - - } else { - $error = $l->t('Upload failed. Could not find uploaded file'); + } catch(Exception $ex) { + $error = $ex->getMessage(); } } else { @@ -164,5 +169,5 @@ if ($error === false) { OCP\JSON::encodedPrint($result); exit(); } else { - OCP\JSON::error(array('data' => array_merge(array('message' => $error), $storageStats))); + OCP\JSON::error(array(array('data' => array_merge(array('message' => $error), $storageStats)))); } diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index b52221ac1fc..88d5a05107f 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -365,7 +365,7 @@ $(document).ready(function() { } else if (result[0].status !== 'success') { //delete data.jqXHR; data.textStatus = 'servererror'; - data.errorThrown = result.data.message; // error message has been translated on server + data.errorThrown = result[0].data.message; // error message has been translated on server var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); fu._trigger('fail', e, data); } -- cgit v1.2.3 From e98ea06890e87a67f2ae501b7daa55882d1d3a03 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 11 Oct 2013 17:06:01 +0200 Subject: File actions are now updated after create/upload file The file actions must explicitly be updated by calling FileActions.display() on the file element after creating or uploading a file. Fixes #4971 and #4993 --- apps/files/js/file-upload.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'apps/files/js') diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index f1ef485fc3d..fbb53b3530a 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -523,8 +523,10 @@ $(document).ready(function() { function(result){ if (result.status == 'success') { var date=new Date(); - FileList.addFile(name,0,date,false,hidden); - var tr=$('tr').filterAttr('data-file',name); + // TODO: ideally addFile should be able to receive + // all attributes and set them automatically, + // and also auto-load the preview + var tr = FileList.addFile(name,0,date,false,hidden); tr.attr('data-size',result.data.size); tr.attr('data-mime',result.data.mime); tr.attr('data-id', result.data.id); @@ -533,6 +535,7 @@ $(document).ready(function() { lazyLoadPreview(path, result.data.mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); + FileActions.display(tr.find('td.filename')); } else { OC.dialogs.alert(result.data.message, t('core', 'Error')); } -- cgit v1.2.3 From fab4102c51e92c5e33725c69ec984b8912a9aee1 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 14 Oct 2013 17:47:38 +0200 Subject: Disabled ajax mode for public files view Ajax loading is not supported yet for public files view. This fix disabled the history API, ajax loading and ajax directory switch in public mode until it is implemented properly. --- apps/files/js/filelist.js | 44 ++++++++++++++++++++++++-------------------- apps/files/js/files.js | 4 +++- 2 files changed, 27 insertions(+), 21 deletions(-) (limited to 'apps/files/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a9297996778..ccc4b1401ad 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -677,6 +677,7 @@ var FileList={ }; $(document).ready(function(){ + var isPublic = !!$('#isPublic').val(); // handle upload events var file_upload_start = $('#file_upload_start'); @@ -924,29 +925,32 @@ $(document).ready(function(){ return (params && params.dir) || '/'; } - // 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; - } - else{ - // read from URL - targetDir = parseCurrentDirFromUrl(); + // disable ajax/history API for public app (TODO: until it gets ported) + if (!isPublic){ + // fallback to hashchange when no history support + if (!window.history.pushState){ + $(window).on('hashchange', function(){ + FileList.changeDirectory(parseCurrentDirFromUrl(), false); + }); } - if (targetDir){ - FileList.changeDirectory(targetDir, false); + window.onpopstate = function(e){ + var targetDir; + if (e.state && e.state.dir){ + targetDir = e.state.dir; + } + else{ + // read from URL + targetDir = parseCurrentDirFromUrl(); + } + if (targetDir){ + FileList.changeDirectory(targetDir, false); + } } - } - if (parseInt($('#ajaxLoad').val(), 10) === 1){ - // need to initially switch the dir to the one from the hash (IE8) - FileList.changeDirectory(parseCurrentDirFromUrl(), false, true); + if (parseInt($('#ajaxLoad').val(), 10) === 1){ + // need to initially switch the dir to the one from the hash (IE8) + FileList.changeDirectory(parseCurrentDirFromUrl(), false, true); + } } FileList.createFileSummary(); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 9e7a2364b18..a35ed4add8c 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -705,7 +705,9 @@ function checkTrashStatus() { function onClickBreadcrumb(e){ var $el = $(e.target).closest('.crumb'), $targetDir = $el.data('dir'); - if ($targetDir !== undefined){ + isPublic = !!$('#isPublic').val(); + + if ($targetDir !== undefined && !isPublic){ e.preventDefault(); FileList.changeDirectory(decodeURIComponent($targetDir)); } -- cgit v1.2.3 From 92e646413a8b2df3c16306b75deab506b6eb4ec2 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 15 Oct 2013 15:54:16 +0200 Subject: Fixed drag and drop onto folders Fixes #5351 --- apps/files/js/filelist.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'apps/files/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index a9297996778..02de2f2415e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -698,11 +698,23 @@ $(document).ready(function(){ // array index 0 contains the max files size // array index 1 contains the request token // array index 2 contains the directory - var parentDir = formArray[2]['value']; - if (parentDir === '/') { - formArray[2]['value'] += dir; - } else { - formArray[2]['value'] += '/' + dir; + if (formArray.length){ + var parentDir = formArray[2]['value']; + if (parentDir === '/') { + formArray[2]['value'] += dir; + } else { + formArray[2]['value'] += '/' + dir; + } + } + else{ + var parentDir = $('#dir').val() || ''; + if (parentDir[parentDir.length - 1] != '/'){ + parentDir += '/'; + } + return [ + {name: 'dir', value: parentDir + dir}, + {name: 'requesttoken', value: oc_requesttoken} + ]; } return formArray; -- cgit v1.2.3 From c6f14001bb2ca1b035760e62c57281b164e55795 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 15 Oct 2013 16:14:23 +0200 Subject: Fixed drag and drop upload to breadcrumb --- apps/files/js/filelist.js | 48 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'apps/files/js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 02de2f2415e..fa26e2bfb7e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -684,40 +684,32 @@ $(document).ready(function(){ file_upload_start.on('fileuploaddrop', function(e, data) { OC.Upload.log('filelist handle fileuploaddrop', e, data); - var dropTarget = $(e.originalEvent.target).closest('tr'); - if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder + var dropTarget = $(e.originalEvent.target).closest('tr, .crumb'); + if(dropTarget && (dropTarget.data('type') === 'dir' || dropTarget.hasClass('crumb'))) { // drag&drop upload to folder // remember as context data.context = dropTarget; var dir = dropTarget.data('file'); + // if from file list, need to prepend parent dir + if (dir){ + var parentDir = $('#dir').val() || '/'; + if (parentDir[parentDir.length - 1] != '/'){ + parentDir += '/'; + } + dir = parentDir + dir; + } + else{ + // read full path from crumb + dir = dropTarget.data('dir') || '/'; + } // update folder in form data.formData = function(form) { - var formArray = form.serializeArray(); - // array index 0 contains the max files size - // array index 1 contains the request token - // array index 2 contains the directory - if (formArray.length){ - var parentDir = formArray[2]['value']; - if (parentDir === '/') { - formArray[2]['value'] += dir; - } else { - formArray[2]['value'] += '/' + dir; - } - } - else{ - var parentDir = $('#dir').val() || ''; - if (parentDir[parentDir.length - 1] != '/'){ - parentDir += '/'; - } - return [ - {name: 'dir', value: parentDir + dir}, - {name: 'requesttoken', value: oc_requesttoken} - ]; - } - - return formArray; + return [ + {name: 'dir', value: dir}, + {name: 'requesttoken', value: oc_requesttoken} + ]; }; } @@ -795,6 +787,10 @@ $(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')){ + return; + } // add as stand-alone row to filelist var size=t('files', 'Pending'); -- cgit v1.2.3