From d332b1d4a2e9382aaa8e8a11b6200efaadb18768 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 2 Jul 2013 11:13:22 +0200 Subject: implement preview loading after upload --- apps/files/js/files.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index a79d34c9b23..224167b99c1 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -513,8 +513,9 @@ $(document).ready(function() { var tr=$('tr').filterAttr('data-file',name); tr.attr('data-mime',result.data.mime); tr.attr('data-id', result.data.id); - getMimeIcon(result.data.mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); + var path = $('#dir').val()+'/'+name; + getPreviewIcon(path, function(previewpath){ + tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } else { OC.dialogs.alert(result.data.message, t('core', 'Error')); @@ -577,8 +578,9 @@ $(document).ready(function() { var tr=$('tr').filterAttr('data-file',localName); tr.data('mime',mime).data('id',id); tr.attr('data-id', id); - getMimeIcon(mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); + var path = $('#dir').val()+'/'+localName; + getPreviewIcon(path, function(previewpath){ + tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); }); eventSource.listen('error',function(error){ @@ -769,8 +771,9 @@ var createDragShadow = function(event){ if (elem.type === 'dir') { newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { - getMimeIcon(elem.mime,function(path){ - newtr.find('td.filename').attr('style','background-image:url('+path+')'); + var path = $('#dir').val()+'/'+elem.name; + getPreviewIcon(path, function(previewpath){ + newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } }); @@ -956,6 +959,10 @@ function getMimeIcon(mime, ready){ } getMimeIcon.cache={}; +function getPreviewIcon(path, ready){ + ready(OC.Router.generate('core_ajax_preview', {file:path, x:44, y:44})); +} + function getUniqueName(name){ if($('tr').filterAttr('data-file',name).length>0){ var parts=name.split('.'); -- cgit v1.2.3 From cf449d42e87b21dff0de35c394031c5fa28b56aa Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 10 Jul 2013 11:25:28 +0200 Subject: properly encode path --- apps/files/js/files.js | 2 +- apps/files_trashbin/lib/trash.php | 2 +- lib/helper.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 224167b99c1..06d193bf8f3 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -960,7 +960,7 @@ function getMimeIcon(mime, ready){ getMimeIcon.cache={}; function getPreviewIcon(path, ready){ - ready(OC.Router.generate('core_ajax_preview', {file:path, x:44, y:44})); + ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:44, y:44})); } function getUniqueName(name){ diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php index e82a597c61e..fb99fca5b3f 100644 --- a/apps/files_trashbin/lib/trash.php +++ b/apps/files_trashbin/lib/trash.php @@ -852,6 +852,6 @@ class Trashbin { } public static function preview_icon($path) { - return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => $path)); + return \OC_Helper::linkToRoute( 'core_ajax_trashbin_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) )); } } diff --git a/lib/helper.php b/lib/helper.php index 0a8962a5312..326f2567f99 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -231,7 +231,7 @@ class OC_Helper { * Returns the path to the preview of the file. */ public static function previewIcon($path) { - return self::linkToRoute( 'core_ajax_preview', array('x' => 44, 'y' => 44, 'file' => $path)); + return self::linkToRoute( 'core_ajax_preview', array('x' => 44, 'y' => 44, 'file' => urlencode($path) )); } /** -- cgit v1.2.3 From ac6a3133eca86b853da838ae310534b76e9fb662 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Tue, 30 Jul 2013 12:29:12 +0200 Subject: style fixes --- apps/files/js/files.js | 2 +- apps/files/templates/part.list.php | 2 +- apps/files_sharing/public.php | 2 +- core/ajax/preview.php | 42 +++++ core/ajax/publicpreview.php | 92 +++++++++++ core/ajax/trashbinpreview.php | 46 ++++++ core/routes.php | 6 +- lib/helper.php | 2 +- lib/preview.php | 308 ++++++++----------------------------- lib/preview/images.php | 7 +- lib/preview/libreoffice-cl.php | 24 +-- lib/preview/movies.php | 22 +-- lib/preview/mp3.php | 22 +-- lib/preview/msoffice.php | 24 +-- lib/preview/office.php | 7 +- lib/preview/pdf.php | 8 +- lib/preview/txt.php | 15 +- lib/preview/unknown.php | 8 +- lib/template.php | 3 + lib/template/functions.php | 16 ++ 20 files changed, 349 insertions(+), 309 deletions(-) create mode 100644 core/ajax/preview.php create mode 100644 core/ajax/publicpreview.php create mode 100644 core/ajax/trashbinpreview.php (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 53c6de09dd0..8b66ed6747b 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -825,7 +825,7 @@ function getMimeIcon(mime, ready){ getMimeIcon.cache={}; function getPreviewIcon(path, ready){ - ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:44, y:44})); + ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:36, y:36})); } function getUniqueName(name){ diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index a957a94f332..ab1b91167db 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -3,7 +3,7 @@ $totaldirs = 0; $totalsize = 0; ?> 6 $totalsize += $file['size']; if ($file['type'] === 'dir') { $totaldirs++; diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 284b7a30208..650fa6a7c27 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -196,7 +196,7 @@ if (isset($path)) { OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path='); $list->assign('isPublic', true); $list->assign('sharingtoken', $token); - $list->assign('sharingroot', ($path)); + $list->assign('sharingroot', $basePath); $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); $breadcrumbNav->assign('breadcrumb', $breadcrumb); $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path='); diff --git a/core/ajax/preview.php b/core/ajax/preview.php new file mode 100644 index 00000000000..a9d127ffcc4 --- /dev/null +++ b/core/ajax/preview.php @@ -0,0 +1,42 @@ +setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->show(); +}catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + \OC\Preview::showErrorPreview(); + exit; +} \ No newline at end of file diff --git a/core/ajax/publicpreview.php b/core/ajax/publicpreview.php new file mode 100644 index 00000000000..aace24caa21 --- /dev/null +++ b/core/ajax/publicpreview.php @@ -0,0 +1,92 @@ +setFile($sharedFile); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->show(); +}catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + \OC\Preview::showErrorPreview(); + exit; +} \ No newline at end of file diff --git a/core/ajax/trashbinpreview.php b/core/ajax/trashbinpreview.php new file mode 100644 index 00000000000..d018a57d37b --- /dev/null +++ b/core/ajax/trashbinpreview.php @@ -0,0 +1,46 @@ +setFile($file); + $preview->setMaxX($maxX); + $preview->setMaxY($maxY); + $preview->setScalingUp($scalingUp); + + $preview->showPreview(); +}catch(\Exception $e) { + \OC_Response::setStatus(500); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + \OC\Preview::showErrorPreview(); + exit; +} \ No newline at end of file diff --git a/core/routes.php b/core/routes.php index 41e82f8a73d..75cc4d511c0 100644 --- a/core/routes.php +++ b/core/routes.php @@ -43,11 +43,11 @@ $this->create('js_config', '/core/js/config.js') $this->create('core_ajax_routes', '/core/routes.json') ->action('OC_Router', 'JSRoutes'); $this->create('core_ajax_preview', '/core/preview.png') - ->action('OC\Preview', 'previewRouter'); + ->actionInclude('core/ajax/preview.php'); $this->create('core_ajax_trashbin_preview', '/core/trashbinpreview.png') - ->action('OC\Preview', 'trashbinPreviewRouter'); + ->actionInclude('core/ajax/trashbinpreview.php'); $this->create('core_ajax_public_preview', '/core/publicpreview.png') - ->action('OC\Preview', 'publicPreviewRouter'); + ->actionInclude('core/ajax/publicpreview.php'); OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php'; $this->create('core_lostpassword_index', '/lostpassword/') ->get() diff --git a/lib/helper.php b/lib/helper.php index 460e5679b02..b74e4c4512e 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -233,7 +233,7 @@ class OC_Helper { return self::linkToRoute( 'core_ajax_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) )); } - public static function publicPreview_icon( $path, $token ) { + public static function publicPreviewIcon( $path, $token ) { return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path), 't' => $token)); } diff --git a/lib/preview.php b/lib/preview.php index 245ad64014e..9f4d20b4650 100755 --- a/lib/preview.php +++ b/lib/preview.php @@ -55,12 +55,12 @@ class Preview { * @param string $file The path to the file where you want a thumbnail from * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image - * @param bool $scalingup Disable/Enable upscaling of previews + * @param bool $scalingUp Disable/Enable upscaling of previews * @return mixed (bool / string) * false if thumbnail does not exist * path to thumbnail if thumbnail exists */ - public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingup=true) { + public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingUp=true) { //set config $this->configMaxX = \OC_Config::getValue('preview_max_x', null); $this->configMaxY = \OC_Config::getValue('preview_max_y', null); @@ -70,11 +70,11 @@ class Preview { $this->setFile($file); $this->setMaxX($maxX); $this->setMaxY($maxY); - $this->setScalingUp($scalingup); + $this->setScalingUp($scalingUp); //init fileviews if($user === ''){ - $user = OC_User::getUser(); + $user = \OC_User::getUser(); } $this->fileview = new \OC\Files\View('/' . $user . '/' . $root); $this->userview = new \OC\Files\View('/' . $user); @@ -120,7 +120,7 @@ class Preview { * @brief returns whether or not scalingup is enabled * @return bool */ - public function getScalingup() { + public function getScalingUp() { return $this->scalingup; } @@ -172,8 +172,8 @@ class Preview { * @return $this */ public function setMaxX($maxX=1) { - if($maxX === 0) { - throw new \Exception('Cannot set width of 0!'); + if($maxX <= 0) { + throw new \Exception('Cannot set width of 0 or smaller!'); } $configMaxX = $this->getConfigMaxX(); if(!is_null($configMaxX)) { @@ -192,8 +192,8 @@ class Preview { * @return $this */ public function setMaxY($maxY=1) { - if($maxY === 0) { - throw new \Exception('Cannot set height of 0!'); + if($maxY <= 0) { + throw new \Exception('Cannot set height of 0 or smaller!'); } $configMaxY = $this->getConfigMaxY(); if(!is_null($configMaxY)) { @@ -208,14 +208,14 @@ class Preview { /** * @brief set whether or not scalingup is enabled - * @param bool $scalingup + * @param bool $scalingUp * @return $this */ - public function setScalingup($scalingup) { + public function setScalingup($scalingUp) { if($this->getMaxScaleFactor() === 1) { - $scalingup = false; + $scalingUp = false; } - $this->scalingup = $scalingup; + $this->scalingup = $scalingUp; return $this; } @@ -245,12 +245,12 @@ class Preview { public function deletePreview() { $file = $this->getFile(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; - $this->userview->unlink($previewpath); - return !$this->userview->file_exists($previewpath); + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; + $this->userview->unlink($previewPath); + return !$this->userview->file_exists($previewPath); } /** @@ -260,13 +260,13 @@ class Preview { public function deleteAllPreviews() { $file = $this->getFile(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; - $this->userview->deleteAll($previewpath); - $this->userview->rmdir($previewpath); - return !$this->userview->is_dir($previewpath); + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + $this->userview->deleteAll($previewPath); + $this->userview->rmdir($previewPath); + return !$this->userview->is_dir($previewPath); } /** @@ -279,45 +279,45 @@ class Preview { $file = $this->getFile(); $maxX = $this->getMaxX(); $maxY = $this->getMaxY(); - $scalingup = $this->getScalingup(); + $scalingUp = $this->getScalingUp(); $maxscalefactor = $this->getMaxScaleFactor(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; - if(is_null($fileid)) { + if(is_null($fileId)) { return false; } - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; - if(!$this->userview->is_dir($previewpath)) { + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + if(!$this->userview->is_dir($previewPath)) { return false; } //does a preview with the wanted height and width already exist? - if($this->userview->file_exists($previewpath . $maxX . '-' . $maxY . '.png')) { - return $previewpath . $maxX . '-' . $maxY . '.png'; + if($this->userview->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) { + return $previewPath . $maxX . '-' . $maxY . '.png'; } - $wantedaspectratio = (float) ($maxX / $maxY); + $wantedAspectRatio = (float) ($maxX / $maxY); //array for usable cached thumbnails - $possiblethumbnails = array(); + $possibleThumbnails = array(); - $allthumbnails = $this->userview->getDirectoryContent($previewpath); - foreach($allthumbnails as $thumbnail) { + $allThumbnails = $this->userview->getDirectoryContent($previewPath); + foreach($allThumbnails as $thumbnail) { $name = rtrim($thumbnail['name'], '.png'); $size = explode('-', $name); $x = (int) $size[0]; $y = (int) $size[1]; - $aspectratio = (float) ($x / $y); - if($aspectratio !== $wantedaspectratio) { + $aspectRatio = (float) ($x / $y); + if($aspectRatio !== $wantedAspectRatio) { continue; } if($x < $maxX || $y < $maxY) { - if($scalingup) { + if($scalingUp) { $scalefactor = $maxX / $x; if($scalefactor > $maxscalefactor) { continue; @@ -326,28 +326,28 @@ class Preview { continue; } } - $possiblethumbnails[$x] = $thumbnail['path']; + $possibleThumbnails[$x] = $thumbnail['path']; } - if(count($possiblethumbnails) === 0) { + if(count($possibleThumbnails) === 0) { return false; } - if(count($possiblethumbnails) === 1) { - return current($possiblethumbnails); + if(count($possibleThumbnails) === 1) { + return current($possibleThumbnails); } - ksort($possiblethumbnails); + ksort($possibleThumbnails); - if(key(reset($possiblethumbnails)) > $maxX) { - return current(reset($possiblethumbnails)); + if(key(reset($possibleThumbnails)) > $maxX) { + return current(reset($possibleThumbnails)); } - if(key(end($possiblethumbnails)) < $maxX) { - return current(end($possiblethumbnails)); + if(key(end($possibleThumbnails)) < $maxX) { + return current(end($possibleThumbnails)); } - foreach($possiblethumbnails as $width => $path) { + foreach($possibleThumbnails as $width => $path) { if($width < $maxX) { continue; }else{ @@ -358,7 +358,7 @@ class Preview { /** * @brief return a preview of a file - * @return image + * @return \OC_Image */ public function getPreview() { if(!is_null($this->preview) && $this->preview->valid()){ @@ -369,10 +369,10 @@ class Preview { $file = $this->getFile(); $maxX = $this->getMaxX(); $maxY = $this->getMaxY(); - $scalingup = $this->getScalingup(); + $scalingUp = $this->getScalingUp(); - $fileinfo = $this->fileview->getFileInfo($file); - $fileid = $fileinfo['fileid']; + $fileInfo = $this->fileview->getFileInfo($file); + $fileId = $fileInfo['fileid']; $cached = $this->isCached(); @@ -386,12 +386,12 @@ class Preview { $mimetype = $this->fileview->getMimeType($file); $preview = null; - foreach(self::$providers as $supportedmimetype => $provider) { - if(!preg_match($supportedmimetype, $mimetype)) { + foreach(self::$providers as $supportedMimetype => $provider) { + if(!preg_match($supportedMimetype, $mimetype)) { continue; } - $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingup, $this->fileview); + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileview); if(!($preview instanceof \OC_Image)) { continue; @@ -400,18 +400,18 @@ class Preview { $this->preview = $preview; $this->resizeAndCrop(); - $previewpath = $this->getThumbnailsFolder() . '/' . $fileid . '/'; - $cachepath = $previewpath . $maxX . '-' . $maxY . '.png'; + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + $cachePath = $previewPath . $maxX . '-' . $maxY . '.png'; if($this->userview->is_dir($this->getThumbnailsFolder() . '/') === false) { $this->userview->mkdir($this->getThumbnailsFolder() . '/'); } - if($this->userview->is_dir($previewpath) === false) { - $this->userview->mkdir($previewpath); + if($this->userview->is_dir($previewPath) === false) { + $this->userview->mkdir($previewPath); } - $this->userview->file_put_contents($cachepath, $preview->data()); + $this->userview->file_put_contents($cachePath, $preview->data()); break; } @@ -447,13 +447,13 @@ class Preview { /** * @brief resize, crop and fix orientation - * @return image + * @return void */ private function resizeAndCrop() { $image = $this->preview; $x = $this->getMaxX(); $y = $this->getMaxY(); - $scalingup = $this->getScalingup(); + $scalingUp = $this->getScalingUp(); $maxscalefactor = $this->getMaxScaleFactor(); if(!($image instanceof \OC_Image)) { @@ -480,7 +480,7 @@ class Preview { $factor = $factorY; } - if($scalingup === false) { + if($scalingUp === false) { if($factor > 1) { $factor = 1; } @@ -583,182 +583,6 @@ class Preview { array_multisort($keys, SORT_DESC, self::$providers); } - /** - * @brief method that handles preview requests from users that are logged in - * @return void - */ - public static function previewRouter() { - \OC_Util::checkLoggedIn(); - - $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; - $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; - - if($file === '') { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - try{ - $preview = new Preview(\OC_User::getUser(), 'files'); - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingup); - - $preview->show(); - }catch(\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - self::showErrorPreview(); - exit; - } - } - - /** - * @brief method that handles preview requests from users that are not logged in / view shared folders that are public - * @return void - */ - public static function publicPreviewRouter() { - if(!\OC_App::isEnabled('files_sharing')){ - exit; - } - - $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '36'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '36'; - $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; - $token = array_key_exists('t', $_GET) ? (string) $_GET['t'] : ''; - - if($token === ''){ - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'No token parameter was passed', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - $linkedItem = \OCP\Share::getShareByToken($token); - if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) { - \OC_Response::setStatus(404); - \OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - if(!isset($linkedItem['uid_owner']) || !isset($linkedItem['file_source'])) { - \OC_Response::setStatus(500); - \OC_Log::write('core-preview', 'Passed token seems to be valid, but it does not contain all necessary information . ("' . $token . '")'); - self::showErrorPreview(); - exit; - } - - $userid = $linkedItem['uid_owner']; - \OC_Util::setupFS($userid); - - $pathid = $linkedItem['file_source']; - $path = \OC\Files\Filesystem::getPath($pathid); - $pathinfo = \OC\Files\Filesystem::getFileInfo($path); - $sharedfile = null; - - if($linkedItem['item_type'] === 'folder') { - $isvalid = \OC\Files\Filesystem::isValidPath($file); - if(!$isvalid) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'Passed filename is not valid, might be malicious (file:"' . $file . '";ip:"' . $_SERVER['REMOTE_ADDR'] . '")', \OC_Log::WARN); - self::showErrorPreview(); - exit; - } - $sharedfile = \OC\Files\Filesystem::normalizePath($file); - } - - if($linkedItem['item_type'] === 'file') { - $parent = $pathinfo['parent']; - $path = \OC\Files\Filesystem::getPath($parent); - $sharedfile = $pathinfo['name']; - } - - $path = \OC\Files\Filesystem::normalizePath($path, false); - if(substr($path, 0, 1) === '/') { - $path = substr($path, 1); - } - - if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - $root = 'files/' . $path; - - try{ - $preview = new Preview($userid, $root); - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingup); - - $preview->show(); - }catch(\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - self::showErrorPreview(); - exit; - } - } - - public static function trashbinPreviewRouter() { - \OC_Util::checkLoggedIn(); - - if(!\OC_App::isEnabled('files_trashbin')){ - exit; - } - - $file = array_key_exists('file', $_GET) ? (string) urldecode($_GET['file']) : ''; - $maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '44'; - $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '44'; - $scalingup = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; - - if($file === '') { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - if($maxX === 0 || $maxY === 0) { - \OC_Response::setStatus(400); //400 Bad Request - \OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG); - self::showErrorPreview(); - exit; - } - - try{ - $preview = new Preview(\OC_User::getUser(), 'files_trashbin/files'); - $preview->setFile($file); - $preview->setMaxX($maxX); - $preview->setMaxY($maxY); - $preview->setScalingUp($scalingup); - - $preview->showPreview(); - }catch(\Exception $e) { - \OC_Response::setStatus(500); - \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); - self::showErrorPreview(); - exit; - } - } - public static function post_write($args) { self::post_delete($args); } @@ -780,8 +604,8 @@ class Preview { //remove last element because it has the mimetype * $providers = array_slice(self::$providers, 0, -1); - foreach($providers as $supportedmimetype => $provider) { - if(preg_match($supportedmimetype, $mimetype)) { + foreach($providers as $supportedMimetype => $provider) { + if(preg_match($supportedMimetype, $mimetype)) { return true; } } diff --git a/lib/preview/images.php b/lib/preview/images.php index 987aa9aef0a..9aec967282d 100644 --- a/lib/preview/images.php +++ b/lib/preview/images.php @@ -16,10 +16,13 @@ class Image extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { //get fileinfo - $fileinfo = $fileview->getFileInfo($path); + $fileInfo = $fileview->getFileInfo($path); + if(!$fileInfo) { + return false; + } //check if file is encrypted - if($fileinfo['encrypted'] === true) { + if($fileInfo['encrypted'] === true) { $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r'))); }else{ $image = new \OC_Image(); diff --git a/lib/preview/libreoffice-cl.php b/lib/preview/libreoffice-cl.php index 2749c4867e9..0f4ec3d0348 100644 --- a/lib/preview/libreoffice-cl.php +++ b/lib/preview/libreoffice-cl.php @@ -22,28 +22,30 @@ class Office extends Provider { return false; } - $abspath = $fileview->toTmpFile($path); + $absPath = $fileview->toTmpFile($path); - $tmpdir = get_temp_dir(); + $tmpDir = get_temp_dir(); - $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpdir) . ' ' . escapeshellarg($abspath); - $export = 'export HOME=/' . $tmpdir; + $exec = $this->cmd . ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir ' . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); + $export = 'export HOME=/' . $tmpDir; shell_exec($export . "\n" . $exec); //create imagick object from pdf try{ - $pdf = new \imagick($abspath . '.pdf' . '[0]'); + $pdf = new \imagick($absPath . '.pdf' . '[0]'); $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ + }catch (\Exception $e) { + unlink($absPath); + unlink($absPath . '.pdf'); \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } $image = new \OC_Image($pdf); - unlink($abspath); - unlink($abspath . '.pdf'); + unlink($absPath); + unlink($absPath . '.pdf'); return $image->valid() ? $image : false; } @@ -55,11 +57,13 @@ class Office extends Provider { $cmd = \OC_Config::getValue('preview_libreoffice_path', null); } - if($cmd === '' && shell_exec('libreoffice --headless --version')) { + $whichLibreOffice = shell_exec('which libreoffice'); + if($cmd === '' && !empty($whichLibreOffice)) { $cmd = 'libreoffice'; } - if($cmd === '' && shell_exec('openoffice --headless --version')) { + $whichOpenOffice = shell_exec('which openoffice'); + if($cmd === '' && !empty($whichOpenOffice)) { $cmd = 'openoffice'; } diff --git a/lib/preview/movies.php b/lib/preview/movies.php index 8531050d112..e2a1b8edddc 100644 --- a/lib/preview/movies.php +++ b/lib/preview/movies.php @@ -8,7 +8,11 @@ */ namespace OC\Preview; -if(!is_null(shell_exec('ffmpeg -version'))) { +$isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); +$whichFFMPEG = shell_exec('which ffmpeg'); +$isFFMPEGAvailable = !empty($whichFFMPEG); + +if($isShellExecEnabled && $isFFMPEGAvailable) { class Movie extends Provider { @@ -17,23 +21,23 @@ if(!is_null(shell_exec('ffmpeg -version'))) { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $abspath = \OC_Helper::tmpFile(); - $tmppath = \OC_Helper::tmpFile(); + $absPath = \OC_Helper::tmpFile(); + $tmpPath = \OC_Helper::tmpFile(); $handle = $fileview->fopen($path, 'rb'); $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576 - file_put_contents($abspath, $firstmb); + file_put_contents($absPath, $firstmb); - //$cmd = 'ffmpeg -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmppath; - $cmd = 'ffmpeg -an -y -i ' . escapeshellarg($abspath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmppath); + //$cmd = 'ffmpeg -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath; + $cmd = 'ffmpeg -an -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmpPath); shell_exec($cmd); - $image = new \OC_Image($tmppath); + $image = new \OC_Image($tmpPath); - unlink($abspath); - unlink($tmppath); + unlink($absPath); + unlink($tmpPath); return $image->valid() ? $image : false; } diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php index 835ff529000..1eed566315c 100644 --- a/lib/preview/mp3.php +++ b/lib/preview/mp3.php @@ -18,19 +18,21 @@ class MP3 extends Provider { $getID3 = new \getID3(); - $tmppath = $fileview->toTmpFile($path); - - $tags = $getID3->analyze($tmppath); - \getid3_lib::CopyTagsToComments($tags); - $picture = @$tags['id3v2']['APIC'][0]['data']; - - unlink($tmppath); + $tmpPath = $fileview->toTmpFile($path); + + $tags = $getID3->analyze($tmpPath); + \getid3_lib::CopyTagsToComments($tags); + if(isset($tags['id3v2']['APIC'][0]['data'])) { + $picture = @$tags['id3v2']['APIC'][0]['data']; + unlink($tmpPath); + $image = new \OC_Image($picture); + return $image->valid() ? $image : $this->getNoCoverThumbnail(); + } - $image = new \OC_Image($picture); - return $image->valid() ? $image : $this->getNoCoverThumbnail($maxX, $maxY); + return $this->getNoCoverThumbnail(); } - public function getNoCoverThumbnail($maxX, $maxY) { + private function getNoCoverThumbnail() { $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png'; if(!file_exists($icon)) { diff --git a/lib/preview/msoffice.php b/lib/preview/msoffice.php index ccf1d674c7a..e69ab0ab8cb 100644 --- a/lib/preview/msoffice.php +++ b/lib/preview/msoffice.php @@ -32,16 +32,16 @@ class DOCX extends Provider { public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { require_once('phpdocx/classes/TransformDoc.inc'); - $tmpdoc = $fileview->toTmpFile($path); + $tmpDoc = $fileview->toTmpFile($path); $transformdoc = new \TransformDoc(); - $transformdoc->setStrFile($tmpdoc); - $transformdoc->generatePDF($tmpdoc); + $transformdoc->setStrFile($tmpDoc); + $transformdoc->generatePDF($tmpDoc); - $pdf = new \imagick($tmpdoc . '[0]'); + $pdf = new \imagick($tmpDoc . '[0]'); $pdf->setImageFormat('jpg'); - unlink($tmpdoc); + unlink($tmpDoc); $image = new \OC_Image($pdf); @@ -62,23 +62,23 @@ class MSOfficeExcel extends Provider { require_once('PHPExcel/Classes/PHPExcel.php'); require_once('PHPExcel/Classes/PHPExcel/IOFactory.php'); - $abspath = $fileview->toTmpFile($path); - $tmppath = \OC_Helper::tmpFile(); + $absPath = $fileview->toTmpFile($path); + $tmpPath = \OC_Helper::tmpFile(); $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf'; \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath); - $phpexcel = new \PHPExcel($abspath); + $phpexcel = new \PHPExcel($absPath); $excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF'); - $excel->save($tmppath); + $excel->save($tmpPath); - $pdf = new \imagick($tmppath . '[0]'); + $pdf = new \imagick($tmpPath . '[0]'); $pdf->setImageFormat('jpg'); - unlink($abspath); - unlink($tmppath); + unlink($absPath); + unlink($tmpPath); $image = new \OC_Image($pdf); diff --git a/lib/preview/office.php b/lib/preview/office.php index b6783bc5798..b93e1e57c8b 100644 --- a/lib/preview/office.php +++ b/lib/preview/office.php @@ -7,8 +7,13 @@ */ //both, libreoffice backend and php fallback, need imagick if (extension_loaded('imagick')) { + $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); + $whichLibreOffice = shell_exec('which libreoffice'); + $isLibreOfficeAvailable = !empty($whichLibreOffice); + $whichOpenOffice = shell_exec('which libreoffice'); + $isOpenOfficeAvailable = !empty($whichOpenOffice); //let's see if there is libreoffice or openoffice on this machine - if(shell_exec('libreoffice --headless --version') || shell_exec('openoffice --headless --version') || is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) { require_once('libreoffice-cl.php'); }else{ //in case there isn't, use our fallback diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php index 3eabd201156..723dc1d80d2 100644 --- a/lib/preview/pdf.php +++ b/lib/preview/pdf.php @@ -16,18 +16,18 @@ if (extension_loaded('imagick')) { } public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $tmppath = $fileview->toTmpFile($path); + $tmpPath = $fileview->toTmpFile($path); //create imagick object from pdf try{ - $pdf = new \imagick($tmppath . '[0]'); + $pdf = new \imagick($tmpPath . '[0]'); $pdf->setImageFormat('jpg'); - }catch(\Exception $e){ + }catch (\Exception $e) { \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); return false; } - unlink($tmppath); + unlink($tmpPath); //new image object $image = new \OC_Image($pdf); diff --git a/lib/preview/txt.php b/lib/preview/txt.php index c7b8fabc6b0..89927fd580a 100644 --- a/lib/preview/txt.php +++ b/lib/preview/txt.php @@ -18,24 +18,23 @@ class TXT extends Provider { $content = stream_get_contents($content); $lines = preg_split("/\r\n|\n|\r/", $content); - $numoflines = count($lines); - $fontsize = 5; //5px - $linesize = ceil($fontsize * 1.25); + $fontSize = 5; //5px + $lineSize = ceil($fontSize * 1.25); $image = imagecreate($maxX, $maxY); - $imagecolor = imagecolorallocate($image, 255, 255, 255); - $textcolor = imagecolorallocate($image, 0, 0, 0); + imagecolorallocate($image, 255, 255, 255); + $textColor = imagecolorallocate($image, 0, 0, 0); foreach($lines as $index => $line) { $index = $index + 1; $x = (int) 1; - $y = (int) ($index * $linesize) - $fontsize; + $y = (int) ($index * $lineSize) - $fontSize; - imagestring($image, 1, $x, $y, $line, $textcolor); + imagestring($image, 1, $x, $y, $line, $textColor); - if(($index * $linesize) >= $maxY) { + if(($index * $lineSize) >= $maxY) { break; } } diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php index a31b365722e..ba13ca35d66 100644 --- a/lib/preview/unknown.php +++ b/lib/preview/unknown.php @@ -20,7 +20,7 @@ class Unknown extends Provider { list($type, $subtype) = explode('/', $mimetype); } - $iconsroot = \OC::$SERVERROOT . '/core/img/filetypes/'; + $iconsRoot = \OC::$SERVERROOT . '/core/img/filetypes/'; if(isset($type)){ $icons = array($mimetype, $type, 'text'); @@ -30,10 +30,10 @@ class Unknown extends Provider { foreach($icons as $icon) { $icon = str_replace('/', '-', $icon); - $iconpath = $iconsroot . $icon . '.png'; + $iconPath = $iconsRoot . $icon . '.png'; - if(file_exists($iconpath)) { - return new \OC_Image($iconpath); + if(file_exists($iconPath)) { + return new \OC_Image($iconPath); } } return false; diff --git a/lib/template.php b/lib/template.php index caa1e667c61..9b2c1211e61 100644 --- a/lib/template.php +++ b/lib/template.php @@ -23,6 +23,9 @@ require_once __DIR__.'/template/functions.php'; +/** + * This class provides the templates for ownCloud. + */ class OC_Template extends \OC\Template\Base { private $renderas; // Create a full page? private $path; // The path to the template diff --git a/lib/template/functions.php b/lib/template/functions.php index a864614c9a1..842f28c90e0 100644 --- a/lib/template/functions.php +++ b/lib/template/functions.php @@ -47,6 +47,22 @@ function image_path( $app, $image ) { return OC_Helper::imagePath( $app, $image ); } +/** + * @brief make preview_icon available as a simple function + * Returns the path to the preview of the image. + * @param $path path of file + * @returns link to the preview + * + * For further information have a look at OC_Helper::previewIcon + */ +function preview_icon( $path ) { + return OC_Helper::previewIcon( $path ); +} + +function publicPreview_icon ( $path, $token ) { + return OC_Helper::publicPreviewIcon( $path, $token ); +} + /** * @brief make OC_Helper::mimetypeIcon available as a simple function * @param string $mimetype mimetype -- cgit v1.2.3 From 9549bd3e68aa32bb9fa1a9a54bda84fa5070966f Mon Sep 17 00:00:00 2001 From: kondou Date: Fri, 9 Aug 2013 20:37:18 +0200 Subject: Use plural translations --- apps/files/js/filelist.js | 5 +++-- apps/files/js/files.js | 14 +++----------- apps/files_trashbin/js/trash.js | 12 ++---------- core/js/js.js | 10 ++++------ lib/template/functions.php | 10 ++++------ 5 files changed, 16 insertions(+), 35 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index b858e2580ee..e0c72295702 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -452,13 +452,14 @@ $(document).ready(function(){ var currentUploads = parseInt(uploadtext.attr('currentUploads')); currentUploads += 1; uploadtext.attr('currentUploads', currentUploads); + var translatedText = n('files', '%n file uploading', '%n files uploading', currentUploads); if(currentUploads === 1) { var img = OC.imagePath('core', 'loading.gif'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.text(t('files', '1 file uploading')); + uploadtext.text(translatedText); uploadtext.show(); } else { - uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); + uploadtext.text(translatedText); } } else { // add as stand-alone row to filelist diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 3fad3fae7d3..53fc25f41b0 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -759,21 +759,13 @@ function procesSelection(){ $('#headerSize').text(humanFileSize(totalSize)); var selection=''; if(selectedFolders.length>0){ - if(selectedFolders.length==1){ - selection+=t('files','1 folder'); - }else{ - selection+=t('files','{count} folders',{count: selectedFolders.length}); - } + selection += n('files', '%n folder', '%n folders', selectedFolders.length); if(selectedFiles.length>0){ selection+=' & '; } } if(selectedFiles.length>0){ - if(selectedFiles.length==1){ - selection+=t('files','1 file'); - }else{ - selection+=t('files','{count} files',{count: selectedFiles.length}); - } + selection += n('files', '%n file', '%n files', selectedFiles.length); } $('#headerName>span.name').text(selection); $('#modified').text(''); @@ -852,4 +844,4 @@ function checkTrashStatus() { $("input[type=button][id=trash]").removeAttr("disabled"); } }); -} \ No newline at end of file +} diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index c3c958b07a7..b14a7240cbe 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -188,21 +188,13 @@ function processSelection(){ $('.selectedActions').show(); var selection=''; if(selectedFolders.length>0){ - if(selectedFolders.length === 1){ - selection+=t('files','1 folder'); - }else{ - selection+=t('files','{count} folders',{count: selectedFolders.length}); - } + selection += n('files', '%n folder', '%n folders', selectedFolders.length); if(selectedFiles.length>0){ selection+=' & '; } } if(selectedFiles.length>0){ - if(selectedFiles.length === 1){ - selection+=t('files','1 file'); - }else{ - selection+=t('files','{count} files',{count: selectedFiles.length}); - } + selection += n('files', '%n file', '%n files', selectedFiles.length); } $('#headerName>span.name').text(selection); $('#modified').text(''); diff --git a/core/js/js.js b/core/js/js.js index 1d1711383f7..0fc4bab80a7 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -812,15 +812,13 @@ function relative_modified_date(timestamp) { var diffdays = Math.round(diffhours/24); var diffmonths = Math.round(diffdays/31); if(timediff < 60) { return t('core','seconds ago'); } - else if(timediff < 120) { return t('core','1 minute ago'); } - else if(timediff < 3600) { return t('core','{minutes} minutes ago',{minutes: diffminutes}); } - else if(timediff < 7200) { return t('core','1 hour ago'); } - else if(timediff < 86400) { return t('core','{hours} hours ago',{hours: diffhours}); } + else if(timediff < 3600) { return n('core','%n minute ago', '%n minutes ago', diffminutes); } + else if(timediff < 86400) { return n('core', '%n hour ago', '%n hours ago', diffhours); } else if(timediff < 86400) { return t('core','today'); } else if(timediff < 172800) { return t('core','yesterday'); } - else if(timediff < 2678400) { return t('core','{days} days ago',{days: diffdays}); } + else if(timediff < 2678400) { return n('core', '%n day ago', '%n days ago', diffdays); } else if(timediff < 5184000) { return t('core','last month'); } - else if(timediff < 31556926) { return t('core','{months} months ago',{months: diffmonths}); } + else if(timediff < 31556926) { return n('core', '%n month ago', '%n months ago', diffmonths); } //else if(timediff < 31556926) { return t('core','months ago'); } else if(timediff < 63113852) { return t('core','last year'); } else { return t('core','years ago'); } diff --git a/lib/template/functions.php b/lib/template/functions.php index 2d43cae1c0c..717e197c1cb 100644 --- a/lib/template/functions.php +++ b/lib/template/functions.php @@ -78,15 +78,13 @@ function relative_modified_date($timestamp) { $diffmonths = round($diffdays/31); if($timediff < 60) { return $l->t('seconds ago'); } - else if($timediff < 120) { return $l->t('1 minute ago'); } - else if($timediff < 3600) { return $l->t('%d minutes ago', $diffminutes); } - else if($timediff < 7200) { return $l->t('1 hour ago'); } - else if($timediff < 86400) { return $l->t('%d hours ago', $diffhours); } + else if($timediff < 3600) { return $l->n('%n minute ago', '%n minutes ago', $diffminutes); } + else if($timediff < 86400) { return $l->n('%n hour ago', '%n hours ago', $diffhours); } else if((date('G')-$diffhours) > 0) { return $l->t('today'); } else if((date('G')-$diffhours) > -24) { return $l->t('yesterday'); } - else if($timediff < 2678400) { return $l->t('%d days ago', $diffdays); } + else if($timediff < 2678400) { return $l->n('%n day go', '%n days ago', $diffdays); } else if($timediff < 5184000) { return $l->t('last month'); } - else if((date('n')-$diffmonths) > 0) { return $l->t('%d months ago', $diffmonths); } + else if((date('n')-$diffmonths) > 0) { return $l->n('%n month ago', '%n months ago', $diffmonths); } else if($timediff < 63113852) { return $l->t('last year'); } else { return $l->t('years ago'); } } -- cgit v1.2.3 From 53bb89824deaf97095acf6bcc2997aa7141dd573 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 12 Aug 2013 17:25:27 +0200 Subject: check if some encrypted files are left after the app was disabled and warn the user --- apps/files/index.php | 1 + apps/files/js/files.js | 14 ++++++++++++++ apps/files/templates/index.php | 1 + lib/public/util.php | 8 ++++++++ lib/util.php | 17 +++++++++++++++++ settings/personal.php | 8 +------- 6 files changed, 42 insertions(+), 7 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/index.php b/apps/files/index.php index 2f005391509..57171ac3b5a 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -143,5 +143,6 @@ if ($needUpgrade) { $tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']); $tmpl->assign('isPublic', false); $tmpl->assign('publicUploadEnabled', $publicUploadEnabled); + $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles()); $tmpl->printPage(); } diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 98fc53b71a9..d6886fc17e4 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -81,9 +81,23 @@ Files={ if (usedSpacePercent > 90) { OC.Notification.show(t('files', 'Your storage is almost full ({usedSpacePercent}%)', {usedSpacePercent: usedSpacePercent})); } + }, + + displayEncryptionWarning: function() { + + if (!OC.Notification.isHidden()) { + return; + } + + var encryptedFiles = $('#encryptedFiles').val(); + if (encryptedFiles === '1') { + OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.', "www.schiessle.org")); + return; + } } }; $(document).ready(function() { + Files.displayEncryptionWarning(); Files.bindKeyboardShortcuts(document, jQuery); $('#fileList tr').each(function(){ //little hack to set unescape filenames in attribute diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index e0731609368..72bc1e937cc 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -121,3 +121,4 @@ + diff --git a/lib/public/util.php b/lib/public/util.php index 693805946ea..b33f07b55e6 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -122,6 +122,14 @@ class Util { return(\OC_Util::formatDate( $timestamp, $dateOnly )); } + /** + * @brief check if some encrypted files are stored + * @return bool + */ + public static function encryptedFiles() { + return \OC_Util::encryptedFiles(); + } + /** * @brief Creates an absolute url * @param string $app app diff --git a/lib/util.php b/lib/util.php index 2586ad28320..cc432af62af 100755 --- a/lib/util.php +++ b/lib/util.php @@ -312,6 +312,23 @@ class OC_Util { return $errors; } + /** + * @brief check if there are still some encrypted files stored + * @return boolean + */ + public static function encryptedFiles() { + //check if encryption was enabled in the past + $encryptedFiles = false; + if (OC_App::isEnabled('files_encryption') === false) { + $view = new OC\Files\View('/' . OCP\User::getUser()); + if ($view->file_exists('/files_encryption/keyfiles')) { + $encryptedFiles = true; + } + } + + return $encryptedFiles; + } + /** * Check for correct file permissions of data directory * @return array arrays with error messages and hints diff --git a/settings/personal.php b/settings/personal.php index bad19ba03ce..e69898f6f8f 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -25,13 +25,7 @@ $userLang=OC_Preferences::getValue( OC_User::getUser(), 'core', 'lang', OC_L10N: $languageCodes=OC_L10N::findAvailableLanguages(); //check if encryption was enabled in the past -$enableDecryptAll = false; -if (OC_App::isEnabled('files_encryption') === false) { - $view = new OC\Files\View('/'.OCP\User::getUser()); - if($view->file_exists('/files_encryption/keyfiles')) { - $enableDecryptAll = true; - } -} +$enableDecryptAll = OC_Util::encryptedFiles(); // array of common languages $commonlangcodes = array( -- cgit v1.2.3 From 3cbbe395eba76be37c16dcb00ac93760e965975e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 11:38:52 +0200 Subject: don't use hardcoded size for preview --- apps/files/js/files.js | 4 +++- apps/files/templates/index.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8b66ed6747b..180c23cbfa4 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -825,7 +825,9 @@ function getMimeIcon(mime, ready){ getMimeIcon.cache={}; function getPreviewIcon(path, ready){ - ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:36, y:36})); + var x = $('#filestable').data('preview-x'); + var y = $('#filestable').data('preview-y'); + ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y})); } function getUniqueName(name){ diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index e4348904671..311ada70dfd 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -59,7 +59,7 @@
t('Nothing in here. Upload something!'))?>
- +
-- cgit v1.2.3 From 4f525c864df7eb6caf1bc945c3c9e48b20bcce5e Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Wed, 14 Aug 2013 13:25:07 +0200 Subject: lazy load preview icons --- apps/files/js/filelist.js | 2 +- apps/files/js/files.js | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 288648693be..138329940b4 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -186,7 +186,7 @@ var FileList={ tr.attr('data-id', id); } var path = $('#dir').val()+'/'+name; - getPreviewIcon(path, function(previewpath){ + lazyLoadPreview(path, mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); tr.find('td.filename').draggable(dragOptions); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 180c23cbfa4..7b01a5202da 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -366,8 +366,8 @@ $(document).ready(function() { var tr=$('tr').filterAttr('data-file',name); tr.attr('data-mime',result.data.mime); tr.attr('data-id', result.data.id); - var path = $('#dir').val()+'/'+name; - getPreviewIcon(path, function(previewpath){ + var path = $('#dir').val() + '/' + name; + lazyLoadPreview(path, result.data.mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } else { @@ -432,7 +432,7 @@ $(document).ready(function() { tr.data('mime',mime).data('id',id); tr.attr('data-id', id); var path = $('#dir').val()+'/'+localName; - getPreviewIcon(path, function(previewpath){ + lazyLoadPreview(path, mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); }); @@ -639,7 +639,7 @@ var createDragShadow = function(event){ newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { var path = $('#dir').val()+'/'+elem.name; - getPreviewIcon(path, function(previewpath){ + lazyLoadPreview(path, elem.mime, function(previewpath){ newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } @@ -824,10 +824,18 @@ function getMimeIcon(mime, ready){ } getMimeIcon.cache={}; -function getPreviewIcon(path, ready){ +function lazyLoadPreview(path, mime, ready) { + getMimeIcon(mime,ready); var x = $('#filestable').data('preview-x'); var y = $('#filestable').data('preview-y'); - ready(OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y})); + var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y}); + $.ajax({ + url: previewURL, + type: 'GET', + success: function() { + ready(previewURL); + } + }); } function getUniqueName(name){ -- cgit v1.2.3 From 7adfc27cafa6f94962a33c158af9c45e71e012c5 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 15 Aug 2013 13:13:16 +0200 Subject: remove whitespaces and some leftover code from testing --- apps/files/js/files.js | 2 +- apps/files_encryption/lib/crypt.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index d6886fc17e4..f5db0207966 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -91,7 +91,7 @@ Files={ var encryptedFiles = $('#encryptedFiles').val(); if (encryptedFiles === '1') { - OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.', "www.schiessle.org")); + OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.')); return; } } diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 759e14b40b2..6543a0de5f3 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -662,5 +662,5 @@ class Crypt { return rtrim($result, "\0"); } } - + } \ No newline at end of file -- cgit v1.2.3 From 57f7ff2dbdbef977483c0078048181ea1b7630f2 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 16 Aug 2013 00:31:27 +0200 Subject: communicate size of newly created file back and update UI --- apps/files/ajax/newfile.php | 2 + apps/files/js/file-upload.js | 622 ++++++++++++++++++++++--------------------- apps/files/js/files.js | 2 + 3 files changed, 316 insertions(+), 310 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 8f5b1d98c3e..d224e79d01b 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -93,9 +93,11 @@ if($source) { $meta = \OC\Files\Filesystem::getFileInfo($target); $id = $meta['fileid']; $mime = $meta['mimetype']; + $size = $meta['size']; OCP\JSON::success(array('data' => array( 'id' => $id, 'mime' => $mime, + 'size' => $size, 'content' => $content, ))); exit(); diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 942a07dfccc..0eddd7e9cd7 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -1,343 +1,345 @@ $(document).ready(function() { - file_upload_param = { - dropZone: $('#content'), // restrict dropZone to content div - //singleFileUploads is on by default, so the data.files array will always have length 1 - add: function(e, data) { + file_upload_param = { + dropZone: $('#content'), // restrict dropZone to content div + //singleFileUploads is on by default, so the data.files array will always have length 1 + add: function(e, data) { - if(data.files[0].type === '' && data.files[0].size == 4096) - { - data.textStatus = 'dirorzero'; - data.errorThrown = t('files','Unable to upload your file as it is a directory or has 0 bytes'); - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - fu._trigger('fail', e, data); - return true; //don't upload this file but go on with next in queue - } + if(data.files[0].type === '' && data.files[0].size == 4096) + { + data.textStatus = 'dirorzero'; + data.errorThrown = t('files','Unable to upload your file as it is a directory or has 0 bytes'); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + fu._trigger('fail', e, data); + return true; //don't upload this file but go on with next in queue + } - var totalSize=0; - $.each(data.originalFiles, function(i,file){ - totalSize+=file.size; - }); + var totalSize=0; + $.each(data.originalFiles, function(i,file){ + totalSize+=file.size; + }); - if(totalSize>$('#max_upload').val()){ - data.textStatus = 'notenoughspace'; - data.errorThrown = t('files','Not enough space available'); - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - fu._trigger('fail', e, data); - return false; //don't upload anything - } + if(totalSize>$('#max_upload').val()){ + data.textStatus = 'notenoughspace'; + data.errorThrown = t('files','Not enough space available'); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + fu._trigger('fail', e, data); + return false; //don't upload anything + } - // start the actual file upload - var jqXHR = data.submit(); + // start the actual file upload + var jqXHR = data.submit(); - // remember jqXHR to show warning to user when he navigates away but an upload is still in progress - if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { - var dirName = data.context.data('file'); - if(typeof uploadingFiles[dirName] === 'undefined') { - uploadingFiles[dirName] = {}; - } - uploadingFiles[dirName][data.files[0].name] = jqXHR; - } else { - uploadingFiles[data.files[0].name] = jqXHR; - } + // remember jqXHR to show warning to user when he navigates away but an upload is still in progress + if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { + var dirName = data.context.data('file'); + if(typeof uploadingFiles[dirName] === 'undefined') { + uploadingFiles[dirName] = {}; + } + uploadingFiles[dirName][data.files[0].name] = jqXHR; + } else { + uploadingFiles[data.files[0].name] = jqXHR; + } - //show cancel button - if($('html.lte9').length === 0 && data.dataType !== 'iframe') { - $('#uploadprogresswrapper input.stop').show(); - } - }, - /** - * called after the first add, does NOT have the data param - * @param e - */ - start: function(e) { - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); - }, - fail: function(e, data) { - if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) { - if (data.textStatus === 'abort') { - $('#notification').text(t('files', 'Upload cancelled.')); - } else { - // HTTP connection problem - $('#notification').text(data.errorThrown); - } - $('#notification').fadeIn(); - //hide notification after 5 sec - setTimeout(function() { - $('#notification').fadeOut(); - }, 5000); - } - delete uploadingFiles[data.files[0].name]; - }, - progress: function(e, data) { - // TODO: show nice progress bar in file row - }, - progressall: function(e, data) { - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } - var progress = (data.loaded/data.total)*100; - $('#uploadprogressbar').progressbar('value',progress); - }, - /** - * called for every successful upload - * @param e - * @param data - */ - done:function(e, data) { - // handle different responses (json or body from iframe for ie) - 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); + //show cancel button + if($('html.lte9').length === 0 && data.dataType !== 'iframe') { + $('#uploadprogresswrapper input.stop').show(); + } + }, + /** + * called after the first add, does NOT have the data param + * @param e + */ + start: function(e) { + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + return; + } + $('#uploadprogressbar').progressbar({value:0}); + $('#uploadprogressbar').fadeIn(); + }, + fail: function(e, data) { + if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) { + if (data.textStatus === 'abort') { + $('#notification').text(t('files', 'Upload cancelled.')); + } else { + // HTTP connection problem + $('#notification').text(data.errorThrown); + } + $('#notification').fadeIn(); + //hide notification after 5 sec + setTimeout(function() { + $('#notification').fadeOut(); + }, 5000); + } + delete uploadingFiles[data.files[0].name]; + }, + progress: function(e, data) { + // TODO: show nice progress bar in file row + }, + progressall: function(e, data) { + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + return; + } + var progress = (data.loaded/data.total)*100; + $('#uploadprogressbar').progressbar('value',progress); + }, + /** + * called for every successful upload + * @param e + * @param data + */ + done:function(e, data) { + // handle different responses (json or body from iframe for ie) + 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); - if(typeof result[0] !== 'undefined' && result[0].status === 'success') { - var file = result[0]; - } else { - data.textStatus = 'servererror'; - data.errorThrown = t('files', result.data.message); - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - fu._trigger('fail', e, data); - } + if(typeof result[0] !== 'undefined' && result[0].status === 'success') { + var file = result[0]; + } else { + data.textStatus = 'servererror'; + data.errorThrown = t('files', result.data.message); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + fu._trigger('fail', e, data); + } - var filename = result[0].originalname; + var filename = result[0].originalname; - // delete jqXHR reference - if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { - var dirName = data.context.data('file'); - delete uploadingFiles[dirName][filename]; - if ($.assocArraySize(uploadingFiles[dirName]) == 0) { - delete uploadingFiles[dirName]; - } - } else { - delete uploadingFiles[filename]; - } + // delete jqXHR reference + if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { + var dirName = data.context.data('file'); + delete uploadingFiles[dirName][filename]; + if ($.assocArraySize(uploadingFiles[dirName]) == 0) { + delete uploadingFiles[dirName]; + } + } else { + delete uploadingFiles[filename]; + } - }, - /** - * called after last upload - * @param e - * @param data - */ - stop: function(e, data) { - if(data.dataType !== 'iframe') { - $('#uploadprogresswrapper input.stop').hide(); - } + }, + /** + * called after last upload + * @param e + * @param data + */ + stop: function(e, data) { + if(data.dataType !== 'iframe') { + $('#uploadprogresswrapper input.stop').hide(); + } - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + return; + } - $('#uploadprogressbar').progressbar('value',100); - $('#uploadprogressbar').fadeOut(); + $('#uploadprogressbar').progressbar('value',100); + $('#uploadprogressbar').fadeOut(); + } } - } - var file_upload_handler = function() { - $('#file_upload_start').fileupload(file_upload_param); - }; + var file_upload_handler = function() { + $('#file_upload_start').fileupload(file_upload_param); + }; - if ( document.getElementById('data-upload-form') ) { - $(file_upload_handler); - } - $.assocArraySize = function(obj) { - // http://stackoverflow.com/a/6700/11236 - var size = 0, key; - for (key in obj) { - if (obj.hasOwnProperty(key)) size++; + if ( document.getElementById('data-upload-form') ) { + $(file_upload_handler); } - return size; - }; - - // warn user not to leave the page while upload is in progress - $(window).bind('beforeunload', function(e) { - if ($.assocArraySize(uploadingFiles) > 0) - return t('files','File upload is in progress. Leaving the page now will cancel the upload.'); - }); + $.assocArraySize = function(obj) { + // http://stackoverflow.com/a/6700/11236 + var size = 0, key; + for (key in obj) { + if (obj.hasOwnProperty(key)) size++; + } + return size; + }; - //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) - if(navigator.userAgent.search(/konqueror/i)==-1){ - $('#file_upload_start').attr('multiple','multiple') - } + // warn user not to leave the page while upload is in progress + $(window).bind('beforeunload', function(e) { + if ($.assocArraySize(uploadingFiles) > 0) + return t('files','File upload is in progress. Leaving the page now will cancel the upload.'); + }); - //if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder - var crumb=$('div.crumb').first(); - while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){ - crumb.children('a').text('...'); - crumb=crumb.next('div.crumb'); - } - //if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent - var crumb=$('div.crumb').first(); - var next=crumb.next('div.crumb'); - while($('div.controls').height()>40 && next.next('div.crumb').length>0){ - crumb.remove(); - crumb=next; - next=crumb.next('div.crumb'); - } - //still not enough, start shorting down the current folder name - var crumb=$('div.crumb>a').last(); - while($('div.controls').height()>40 && crumb.text().length>6){ - var text=crumb.text() - text=text.substr(0,text.length-6)+'...'; - crumb.text(text); - } + //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) + if(navigator.userAgent.search(/konqueror/i)==-1){ + $('#file_upload_start').attr('multiple','multiple') + } - $(document).click(function(){ - $('#new>ul').hide(); - $('#new').removeClass('active'); - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ - $(element).children('form').remove(); - $(element).append('

'+$(element).data('text')+'

'); - } - }); - }); - $('#new li').click(function(){ - if($(this).children('p').length==0){ - return; + //if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder + var crumb=$('div.crumb').first(); + while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){ + crumb.children('a').text('...'); + crumb=crumb.next('div.crumb'); + } + //if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent + var crumb=$('div.crumb').first(); + var next=crumb.next('div.crumb'); + while($('div.controls').height()>40 && next.next('div.crumb').length>0){ + crumb.remove(); + crumb=next; + next=crumb.next('div.crumb'); + } + //still not enough, start shorting down the current folder name + var crumb=$('div.crumb>a').last(); + while($('div.controls').height()>40 && crumb.text().length>6){ + var text=crumb.text() + text=text.substr(0,text.length-6)+'...'; + crumb.text(text); } - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ - $(element).children('form').remove(); - $(element).append('

'+$(element).data('text')+'

'); - } + $(document).click(function(){ + $('#new>ul').hide(); + $('#new').removeClass('active'); + $('#new li').each(function(i,element){ + if($(element).children('p').length==0){ + $(element).children('form').remove(); + $(element).append('

'+$(element).data('text')+'

'); + } + }); }); + $('#new li').click(function(){ + if($(this).children('p').length==0){ + return; + } - var type=$(this).data('type'); - var text=$(this).children('p').text(); - $(this).data('text',text); - $(this).children('p').remove(); - var form=$('
'); - var input=$(''); - form.append(input); - $(this).append(form); - input.focus(); - form.submit(function(event){ - event.stopPropagation(); - event.preventDefault(); - var newname=input.val(); - if(type == 'web' && newname.length == 0) { - OC.Notification.show(t('files', 'URL cannot be empty.')); - return false; - } else if (type != 'web' && !Files.isFileNameValid(newname)) { - return false; - } else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') { - OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by ownCloud')); - return false; - } - if (FileList.lastAction) { - FileList.lastAction(); - } - var name = getUniqueName(newname); - if (newname != name) { - FileList.checkName(name, newname, true); - var hidden = true; - } else { - var hidden = false; - } - switch(type){ - case 'file': - $.post( - OC.filePath('files','ajax','newfile.php'), - {dir:$('#dir').val(),filename:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - FileList.addFile(name,0,date,false,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.attr('data-mime',result.data.mime); - tr.attr('data-id', result.data.id); - getMimeIcon(result.data.mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); - }); - } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); + $('#new li').each(function(i,element){ + if($(element).children('p').length==0){ + $(element).children('form').remove(); + $(element).append('

'+$(element).data('text')+'

'); + } + }); + + var type=$(this).data('type'); + var text=$(this).children('p').text(); + $(this).data('text',text); + $(this).children('p').remove(); + var form=$('
'); + var input=$(''); + form.append(input); + $(this).append(form); + input.focus(); + form.submit(function(event){ + event.stopPropagation(); + event.preventDefault(); + var newname=input.val(); + if(type == 'web' && newname.length == 0) { + OC.Notification.show(t('files', 'URL cannot be empty.')); + return false; + } else if (type != 'web' && !Files.isFileNameValid(newname)) { + return false; + } else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') { + OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by ownCloud')); + return false; + } + if (FileList.lastAction) { + FileList.lastAction(); } - } - ); - break; - case 'folder': - $.post( - OC.filePath('files','ajax','newfolder.php'), - {dir:$('#dir').val(),foldername:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - FileList.addDir(name,0,date,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.attr('data-id', result.data.id); + var name = getUniqueName(newname); + if (newname != name) { + FileList.checkName(name, newname, true); + var hidden = true; } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); + var hidden = false; } - } - ); - break; - case 'web': - if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){ - name='http://'+name; - } - var localName=name; - if(localName.substr(localName.length-1,1)=='/'){//strip / - localName=localName.substr(0,localName.length-1) - } - if(localName.indexOf('/')){//use last part of url - localName=localName.split('/').pop(); - } else { //or the domain - localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.',''); - } - localName = getUniqueName(localName); - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - } else { - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); - } + switch(type){ + case 'file': + $.post( + OC.filePath('files','ajax','newfile.php'), + {dir:$('#dir').val(),filename:name}, + function(result){ + if (result.status == 'success') { + var date=new Date(); + FileList.addFile(name,0,date,false,hidden); + var tr=$('tr').filterAttr('data-file',name); + tr.attr('data-size',result.data.size); + tr.attr('data-mime',result.data.mime); + tr.attr('data-id', result.data.id); + tr.find('.filesize').text(humanFileSize(result.data.size)); + getMimeIcon(result.data.mime,function(path){ + tr.find('td.filename').attr('style','background-image:url('+path+')'); + }); + } else { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } + } + ); + break; + case 'folder': + $.post( + OC.filePath('files','ajax','newfolder.php'), + {dir:$('#dir').val(),foldername:name}, + function(result){ + if (result.status == 'success') { + var date=new Date(); + FileList.addDir(name,0,date,hidden); + var tr=$('tr').filterAttr('data-file',name); + tr.attr('data-id', result.data.id); + } else { + OC.dialogs.alert(result.data.message, t('core', 'Error')); + } + } + ); + break; + case 'web': + if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){ + name='http://'+name; + } + var localName=name; + if(localName.substr(localName.length-1,1)=='/'){//strip / + localName=localName.substr(0,localName.length-1) + } + if(localName.indexOf('/')){//use last part of url + localName=localName.split('/').pop(); + } else { //or the domain + localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.',''); + } + localName = getUniqueName(localName); + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + } else { + $('#uploadprogressbar').progressbar({value:0}); + $('#uploadprogressbar').fadeIn(); + } - var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName}); - eventSource.listen('progress',function(progress){ - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - } else { - $('#uploadprogressbar').progressbar('value',progress); - } - }); - eventSource.listen('success',function(data){ - var mime=data.mime; - var size=data.size; - var id=data.id; - $('#uploadprogressbar').fadeOut(); - var date=new Date(); - FileList.addFile(localName,size,date,false,hidden); - var tr=$('tr').filterAttr('data-file',localName); - tr.data('mime',mime).data('id',id); - tr.attr('data-id', id); - getMimeIcon(mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); - }); - }); - eventSource.listen('error',function(error){ - $('#uploadprogressbar').fadeOut(); - alert(error); + var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName}); + eventSource.listen('progress',function(progress){ + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + } else { + $('#uploadprogressbar').progressbar('value',progress); + } + }); + eventSource.listen('success',function(data){ + var mime=data.mime; + var size=data.size; + var id=data.id; + $('#uploadprogressbar').fadeOut(); + var date=new Date(); + FileList.addFile(localName,size,date,false,hidden); + var tr=$('tr').filterAttr('data-file',localName); + tr.data('mime',mime).data('id',id); + tr.attr('data-id', id); + getMimeIcon(mime,function(path){ + tr.find('td.filename').attr('style','background-image:url('+path+')'); + }); + }); + eventSource.listen('error',function(error){ + $('#uploadprogressbar').fadeOut(); + alert(error); + }); + break; + } + var li=form.parent(); + form.remove(); + li.append('

'+li.data('text')+'

'); + $('#new>a').click(); }); - break; - } - var li=form.parent(); - form.remove(); - li.append('

'+li.data('text')+'

'); - $('#new>a').click(); }); - }); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 53fc25f41b0..e1c53184dd1 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -365,7 +365,9 @@ $(document).ready(function() { FileList.addFile(name,0,date,false,hidden); var tr=$('tr').filterAttr('data-file',name); tr.attr('data-mime',result.data.mime); + tr.attr('data-size',result.data.size); tr.attr('data-id', result.data.id); + tr.find('.filesize').text(humanFileSize(result.data.size)); getMimeIcon(result.data.mime,function(path){ tr.find('td.filename').attr('style','background-image:url('+path+')'); }); -- cgit v1.2.3 From f94e6036980644bdd6312e75a8973f2633cf5ff2 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 16 Aug 2013 11:40:55 +0200 Subject: progress fixes --- apps/files/ajax/upload.php | 9 +- apps/files/css/files.css | 23 +++- apps/files/js/file-upload.js | 263 ++++++++++++++++++++++++++------------- apps/files/js/fileactions.js | 2 +- apps/files/js/filelist.js | 265 ++++++++++++++++++++++++---------------- apps/files/js/files.js | 29 +---- apps/files_sharing/js/public.js | 7 +- core/js/oc-dialogs.js | 215 ++++++++++++++++++-------------- 8 files changed, 503 insertions(+), 310 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 8d183bd1f9c..619b5f6a04b 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -99,8 +99,8 @@ if (strpos($dir, '..') === false) { $fileCount = count($files['name']); for ($i = 0; $i < $fileCount; $i++) { // $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder - if (isset($_POST['new_name'])) { - $newName = $_POST['new_name']; + if (isset($_POST['newname'])) { + $newName = $_POST['newname']; } else { $newName = $files['name'][$i]; } @@ -109,11 +109,12 @@ if (strpos($dir, '..') === false) { } else { $replace = false; } - $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).$newName); + $target = \OC\Files\Filesystem::normalizePath(stripslashes($dir).'/'.$newName); if ( ! $replace && \OC\Files\Filesystem::file_exists($target)) { $meta = \OC\Files\Filesystem::getFileInfo($target); $result[] = array('status' => 'existserror', - 'mime' => $meta['mimetype'], + 'type' => $meta['mimetype'], + 'mtime' => $meta['mtime'], 'size' => $meta['size'], 'id' => $meta['fileid'], 'name' => basename($target), diff --git a/apps/files/css/files.css b/apps/files/css/files.css index acee8471aff..0ff25a24d76 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -190,6 +190,9 @@ table.dragshadow td.size { margin-left: -200px; } +.oc-dialog .fileexists table { + width: 100%; +} .oc-dialog .fileexists .original .icon { width: 64px; height: 64px; @@ -201,6 +204,7 @@ table.dragshadow td.size { .oc-dialog .fileexists .replacement { margin-top: 20px; + margin-bottom: 20px; } .oc-dialog .fileexists .replacement .icon { @@ -213,10 +217,23 @@ table.dragshadow td.size { clear: both; } -.oc-dialog .fileexists label[for="new-name"] { - margin-top: 20px; - display: block; +.oc-dialog .fileexists .toggle { + background-image: url('%webroot%/core/img/actions/triangle-e.png'); + width: 16px; + height: 16px; +} +.oc-dialog .fileexists #allfileslabel { + float:right; } +.oc-dialog .fileexists #allfiles { + vertical-align: bottom; + position: relative; + top: -3px; +} +.oc-dialog .fileexists #allfiles + span{ + vertical-align: bottom; +} + .oc-dialog .fileexists h3 { font-weight: bold; } diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index bd9757b5ffc..f8899cb07e6 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -1,4 +1,30 @@ /** + * 1. tracking which file to upload next -> upload queue with data elements added whenever add is called + * 2. tracking progress for each folder individually -> track progress in a progress[dirname] object + * - every new selection increases the total size and number of files for a directory + * - add increases, successful done decreases, skip decreases, cancel decreases + * 3. track selections -> the general skip / overwrite decision is selection based and can change + * - server might send already exists error -> show dialog & remember decision for selection again + * - server sends error, how do we find collection? + * 4. track jqXHR object to prevent browser from navigationg away -> track in a uploads[dirname][filename] object [x] + * + * selections can progress in parrallel but each selection progresses sequentially + * + * -> store everything in context? + * context.folder + * context.element? + * context.progressui? + * context.jqXHR + * context.selection + * context.selection.onExistsAction? + * + * context available in what events? + * build in drop() add dir + * latest in add() add file? add selection! + * progress? -> update progress? + * onsubmit -> context.jqXHR? + * fail() -> + * done() * * when versioning app is active -> always overwrite * @@ -22,24 +48,74 @@ * dialoge: * -> skip, replace, choose (or abort) () * -> choose left or right (with skip) (when only one file in list also show rename option and remember for all option) + * + * progress always based on filesize + * number of files as text, bytes as bar + * */ -OC.upload = { + +//TODO clean uploads when all progress has completed +OC.Upload = { + /** + * map to lookup the selections for a given directory. + * @type Array + */ + _selections: {}, + /* + * queue which progress tracker to use for the next upload + * @type Array + */ + _queue: [], + queueUpload:function(data) { + // add to queue + this._queue.push(data); //remember what to upload next + if ( ! this.isProcessing() ) { + this.startUpload(); + } + }, + getSelection:function(originalFiles) { + if (!originalFiles.selectionKey) { + originalFiles.selectionKey = 'selection-' + $.assocArraySize(this._selections); + this._selections[originalFiles.selectionKey] = { + selectionKey:originalFiles.selectionKey, + files:{}, + totalBytes:0, + loadedBytes:0, + currentFile:0, + uploads:{}, + checked:false + }; + } + return this._selections[originalFiles.selectionKey]; + }, + cancelUpload:function(dir, filename) { + var deleted = false; + jQuery.each(this._selections, function(i, selection) { + if (selection.dir === dir && selection.uploads[filename]) { + delete selection.uploads[filename]; + deleted = true; + return false; // end searching through selections + } + }); + return deleted; + }, + cancelUploads:function() { + jQuery.each(this._selections,function(i,selection){ + jQuery.each(selection.uploads, function (j, jqXHR) { + delete jqXHR; + }); + }); + this._queue = []; + this._isProcessing = false; + }, _isProcessing:false, isProcessing:function(){ return this._isProcessing; }, - _uploadQueue:[], - addUpload:function(data){ - this._uploadQueue.push(data); - - if ( ! OC.upload.isProcessing() ) { - OC.upload.startUpload(); - } - }, startUpload:function(){ - if (this._uploadQueue.length > 0) { + if (this._queue.length > 0) { this._isProcessing = true; this.nextUpload(); return true; @@ -48,32 +124,50 @@ OC.upload = { } }, nextUpload:function(){ - if (this._uploadQueue.length > 0) { - var data = this._uploadQueue.pop(); - var jqXHR = data.submit(); - - // remember jqXHR to show warning to user when he navigates away but an upload is still in progress - if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { - var dirName = data.context.data('file'); - if(typeof uploadingFiles[dirName] === 'undefined') { - uploadingFiles[dirName] = {}; - } - uploadingFiles[dirName][data.files[0].name] = jqXHR; - } else { - uploadingFiles[data.files[0].name] = jqXHR; - } + if (this._queue.length > 0) { + var data = this._queue.pop(); + var selection = this.getSelection(data.originalFiles); + selection.uploads[data.files[0]] = data.submit(); + } else { //queue is empty, we are done this._isProcessing = false; + //TODO free data } + }, + progressBytes: function() { + var total = 0; + var loaded = 0; + jQuery.each(this._selections, function (i, selection) { + total += selection.totalBytes; + loaded += selection.loadedBytes; + }); + return (loaded/total)*100; + }, + loadedBytes: function() { + var loaded = 0; + jQuery.each(this._selections, function (i, selection) { + loaded += selection.loadedBytes; + }); + return loaded; + }, + totalBytes: function() { + var total = 0; + jQuery.each(this._selections, function (i, selection) { + total += selection.totalBytes; + }); + return total; + }, + handleExists:function(data) { + }, onCancel:function(data){ //TODO cancel all uploads - Files.cancelUploads(); - this._uploadQueue = []; - this._isProcessing = false; + OC.Upload.cancelUploads(); }, onSkip:function(data){ + var selection = this.getSelection(data.originalFiles); + selection.loadedBytes += data.loaded; this.nextUpload(); }, onReplace:function(data){ @@ -83,8 +177,14 @@ OC.upload = { }, onRename:function(data, newName){ //TODO rename file in filelist, stop spinner - data.data.append('new_name', newName); + data.data.append('newname', newName); data.submit(); + }, + setAction:function(data, action) { + + }, + setDefaultAction:function(action) { + } }; @@ -92,15 +192,23 @@ $(document).ready(function() { var file_upload_param = { dropZone: $('#content'), // restrict dropZone to content div + //singleFileUploads is on by default, so the data.files array will always have length 1 add: function(e, data) { var that = $(this); - - if (typeof data.originalFiles.checked === 'undefined') { + + // lookup selection for dir + var selection = OC.Upload.getSelection(data.originalFiles); + + if (!selection.dir) { + selection.dir = $('#dir').val(); + } + + if ( ! selection.checked ) { - var totalSize = 0; + selection.totalBytes = 0; $.each(data.originalFiles, function(i, file) { - totalSize += file.size; + selection.totalBytes += file.size; if (file.type === '' && file.size === 4096) { data.textStatus = 'dirorzero'; @@ -111,11 +219,10 @@ $(document).ready(function() { } }); - if (totalSize > $('#max_upload').val()) { + if (selection.totalBytes > $('#max_upload').val()) { data.textStatus = 'notenoughspace'; data.errorThrown = t('files', 'Not enough space available'); } - if (data.errorThrown) { //don't upload anything var fu = that.data('blueimp-fileupload') || that.data('fileupload'); @@ -123,9 +230,22 @@ $(document).ready(function() { return false; } - data.originalFiles.checked = true; // this will skip the checks on subsequent adds + //TODO refactor away: + //show cancel button + if($('html.lte9').length === 0 && data.dataType !== 'iframe') { + $('#uploadprogresswrapper input.stop').show(); + } } + //all subsequent add calls for this selection can be ignored + //allow navigating to the selection from a context + //context.selection = data.originalFiles.selection; + + //allow navigating to contexts / files of a selection + selection.files[data.files[0].name] = data; + + OC.Upload.queueUpload(data); + //TODO check filename already exists /* if ($('tr[data-file="'+data.files[0].name+'"][data-id]').length > 0) { @@ -140,14 +260,6 @@ $(document).ready(function() { } */ - //add files to queue - OC.upload.addUpload(data); - - //TODO refactor away: - //show cancel button - if($('html.lte9').length === 0 && data.dataType !== 'iframe') { - $('#uploadprogresswrapper input.stop').show(); - } return true; }, /** @@ -176,7 +288,8 @@ $(document).ready(function() { $('#notification').fadeOut(); }, 5000); } - delete uploadingFiles[data.files[0].name]; + var selection = OC.Upload.getSelection(data.originalFiles); + delete selection.uploads[data.files[0]]; }, progress: function(e, data) { // TODO: show nice progress bar in file row @@ -186,7 +299,8 @@ $(document).ready(function() { if($('html.lte9').length > 0) { return; } - var progress = (data.loaded/data.total)*100; + //var progress = (data.loaded/data.total)*100; + var progress = OC.Upload.progressBytes(); $('#uploadprogressbar').progressbar('value', progress); }, /** @@ -204,27 +318,22 @@ $(document).ready(function() { response = data.result[0].body.innerText; } var result=$.parseJSON(response); + var selection = OC.Upload.getSelection(data.originalFiles); - if(typeof result[0] !== 'undefined' && result[0].status === 'success') { - OC.upload.nextUpload(); + if(typeof result[0] !== 'undefined' + && result[0].status === 'success' + ) { + selection.loadedBytes+=data.loaded; + OC.Upload.nextUpload(); } else { if (result[0].status === 'existserror') { - //TODO open dialog and retry with other name? - // get jqXHR reference - if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { - var dirName = data.context.data('file'); - var jqXHR = uploadingFiles[dirName][filename]; - } else { - var jqXHR = uploadingFiles[filename]; - } - //filenames can only be changed on the server side - //TODO show "file already exists" dialog - //options: abort | skip | replace / rename - //TODO reset all-files flag? when done with selection? + //show "file already exists" dialog var original = result[0]; var replacement = data.files[0]; - OC.dialogs.fileexists(data, original, replacement, OC.upload); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + OC.dialogs.fileexists(data, original, replacement, OC.Upload, fu); } else { + delete selection.uploads[data.files[0]]; data.textStatus = 'servererror'; data.errorThrown = t('files', result.data.message); var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); @@ -232,19 +341,6 @@ $(document).ready(function() { } } - var filename = result[0].originalname; - - // delete jqXHR reference - if (typeof data.context !== 'undefined' && data.context.data('type') === 'dir') { - var dirName = data.context.data('file'); - delete uploadingFiles[dirName][filename]; - if ($.assocArraySize(uploadingFiles[dirName]) === 0) { - delete uploadingFiles[dirName]; - } - } else { - delete uploadingFiles[filename]; - } - }, /** * called after last upload @@ -252,17 +348,20 @@ $(document).ready(function() { * @param data */ stop: function(e, data) { - if(data.dataType !== 'iframe') { - $('#uploadprogresswrapper input.stop').hide(); - } + if(OC.Upload.progressBytes()>=100) { - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } + if(data.dataType !== 'iframe') { + $('#uploadprogresswrapper input.stop').hide(); + } - $('#uploadprogressbar').progressbar('value', 100); - $('#uploadprogressbar').fadeOut(); + //IE < 10 does not fire the necessary events for the progress bar. + if($('html.lte9').length > 0) { + return; + } + + $('#uploadprogressbar').progressbar('value', 100); + $('#uploadprogressbar').fadeOut(); + } } }; diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index aa66a57a7b5..277abcfdb15 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -174,7 +174,7 @@ $(document).ready(function () { FileActions.register('all', 'Delete', OC.PERMISSION_DELETE, function () { return OC.imagePath('core', 'actions/delete'); }, function (filename) { - if (Files.cancelUpload(filename)) { + if (OC.Upload.cancelUpload($('#dir').val(), filename)) { if (filename.substr) { filename = [filename]; } diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index f4863837ce7..335f81e04b9 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -407,151 +407,212 @@ $(document).ready(function(){ // handle upload events var file_upload_start = $('#file_upload_start'); + file_upload_start.on('fileuploaddrop', function(e, data) { - // only handle drop to dir if fileList exists - if ($('#fileList').length > 0) { - var dropTarget = $(e.originalEvent.target).closest('tr'); - if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder - data.context = dropTarget; - var dirName = dropTarget.data('file'); - // 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 - var parentDir = formArray[2]['value']; - if (parentDir === '/') { - formArray[2]['value'] += dirName; - } else { - formArray[2]['value'] += '/'+dirName; - } - return formArray; - }; + console.log('fileuploaddrop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + + var dropTarget = $(e.originalEvent.target).closest('tr'); + if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder + + // lookup selection for dir + var selection = OC.Upload.getSelection(data.files); + + // remember drop target + selection.dropTarget = dropTarget; + + selection.dir = dropTarget.data('file'); + if (selection.dir !== '/') { + if ($('#dir').val() === '/') { + selection.dir = '/' + selection.dir; + } else { + selection.dir = $('#dir').val() + '/' + selection.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 + var parentDir = formArray[2]['value']; + if (parentDir === '/') { + formArray[2]['value'] += selection.dir; + } else { + formArray[2]['value'] += '/' + selection.dir; + } + + return formArray; + }; + } + }); file_upload_start.on('fileuploadadd', function(e, data) { - // only add to fileList if it exists - if ($('#fileList').length > 0) { + console.log('fileuploadadd ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + + // lookup selection for dir + var selection = OC.Upload.getSelection(data.originalFiles); + + if(FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1){//finish delete if we are uploading a deleted file + FileList.finishDelete(null, true); //delete file before continuing + } + + // add ui visualization to existing folder + if(selection.dropTarget && selection.dropTarget.data('type') === 'dir') { + // add to existing folder + var dirName = selection.dropTarget.data('file'); + + // set dir context + data.context = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName); - if(FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1){//finish delete if we are uploading a deleted file - FileList.finishDelete(null, true); //delete file before continuing + // update upload counter ui + var uploadtext = data.context.find('.uploadtext'); + var currentUploads = parseInt(uploadtext.attr('currentUploads')); + currentUploads += 1; + uploadtext.attr('currentUploads', currentUploads); + + if(currentUploads === 1) { + var img = OC.imagePath('core', 'loading.gif'); + data.context.find('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.text(t('files', '1 file uploading')); + uploadtext.show(); + } else { + uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); } + } + + }); + file_upload_start.on('fileuploaddone', function(e, data) { + console.log('fileuploaddone ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + + 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); - // add ui visualization to existing folder - var dropTarget = $(e.originalEvent.target).closest('tr'); - if(dropTarget && dropTarget.data('type') === 'dir') { - // add to existing folder - var dirName = dropTarget.data('file'); + if(typeof result[0] !== 'undefined' && result[0].status === 'success') { + var file = result[0]; - // set dir context - data.context = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName); + if (data.context && data.context.data('type') === 'dir') { // update upload counter ui var uploadtext = data.context.find('.uploadtext'); var currentUploads = parseInt(uploadtext.attr('currentUploads')); - currentUploads += 1; + currentUploads -= 1; uploadtext.attr('currentUploads', currentUploads); - if(currentUploads === 1) { - var img = OC.imagePath('core', 'loading.gif'); + if(currentUploads === 0) { + var img = OC.imagePath('core', 'filetypes/folder.png'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.text(t('files', '1 file uploading')); - uploadtext.show(); + uploadtext.text(''); + uploadtext.hide(); } else { uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); } - } - } - }); - file_upload_start.on('fileuploaddone', function(e, data) { - // only update the fileList if it exists - if ($('#fileList').length > 0) { - var response; - if (typeof data.result === 'string') { - response = data.result; + + // update folder size + var size = parseInt(data.context.data('size')); + size += parseInt(file.size); + data.context.attr('data-size', size); + data.context.find('td.filesize').text(humanFileSize(size)); + } else { - // fetch response from iframe - response = data.result[0].body.innerText; - } - var result=$.parseJSON(response); - - if(typeof result[0] !== 'undefined' && result[0].status === 'success') { - var file = result[0]; - - if (data.context && data.context.data('type') === 'dir') { - - // update upload counter ui - var uploadtext = data.context.find('.uploadtext'); - var currentUploads = parseInt(uploadtext.attr('currentUploads')); - currentUploads -= 1; - uploadtext.attr('currentUploads', currentUploads); - if(currentUploads === 0) { - var img = OC.imagePath('core', 'filetypes/folder.png'); - data.context.find('td.filename').attr('style','background-image:url('+img+')'); - uploadtext.text(''); - uploadtext.hide(); - } else { - uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); - } - // update folder size - var size = parseInt(data.context.data('size')); - size += parseInt(file.size) ; - data.context.attr('data-size', size); - data.context.find('td.filesize').text(humanFileSize(size)); + // add as stand-alone row to filelist + var size=t('files','Pending'); + if (data.files[0].size>=0){ + size=data.files[0].size; + } + var date=new Date(); + var param = {}; + if ($('#publicUploadRequestToken').length) { + param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name; + } + //should the file exist in the list remove it + FileList.remove(file.name); + + // create new file context + data.context = FileList.addFile(file.name, file.size, date, false, false, param); - } else { - - // add as stand-alone row to filelist - var uniqueName = getUniqueName(data.files[0].name); - var size=t('files','Pending'); - if (data.files[0].size>=0){ - size=data.files[0].size; - } - var date=new Date(); - var param = {}; - if ($('#publicUploadRequestToken').length) { - param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + uniqueName; - } - - //should the file exist in the list remove it - FileList.remove(file.name); + // update file data + data.context.attr('data-mime',file.mime).attr('data-id',file.id); - // create new file context - data.context = FileList.addFile(file.name, file.size, date, false, false, param); - - // update file data - data.context.attr('data-mime',file.mime).attr('data-id',file.id); - - getMimeIcon(file.mime, function(path){ - data.context.find('td.filename').attr('style','background-image:url('+path+')'); - }); - } + getMimeIcon(file.mime, function(path){ + data.context.find('td.filename').attr('style','background-image:url('+path+')'); + }); } } }); + + file_upload_start.on('fileuploadalways', function(e, data) { + console.log('fileuploadalways ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + }); + file_upload_start.on('fileuploadsend', function(e, data) { + console.log('fileuploadsend ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + + // TODOD add vis + //data.context.element = + }); + file_upload_start.on('fileuploadprogress', function(e, data) { + console.log('fileuploadprogress ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + }); + file_upload_start.on('fileuploadprogressall', function(e, data) { + console.log('fileuploadprogressall ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + }); + file_upload_start.on('fileuploadstop', function(e, data) { + console.log('fileuploadstop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + }); + file_upload_start.on('fileuploadfail', function(e, data) { + console.log('fileuploadfail ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + }); + /* file_upload_start.on('fileuploadfail', function(e, data) { - // only update the fileList if it exists + console.log('fileuploadfail'+((data.files&&data.files.length>0)?' '+data.files[0].name:'')); + + // if we are uploading to a subdirectory + if (data.context && data.context.data('type') === 'dir') { + + // update upload counter ui + var uploadtext = data.context.find('.uploadtext'); + var currentUploads = parseInt(uploadtext.attr('currentUploads')); + currentUploads -= 1; + uploadtext.attr('currentUploads', currentUploads); + if(currentUploads === 0) { + var img = OC.imagePath('core', 'filetypes/folder.png'); + data.context.find('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.text(''); + uploadtext.hide(); + } else { + uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); + } + + } + // cleanup files, error notification has been shown by fileupload code var tr = data.context; if (typeof tr === 'undefined') { tr = $('tr').filterAttr('data-file', data.files[0].name); } if (tr.attr('data-type') === 'dir') { + //cleanup uploading to a dir var uploadtext = tr.find('.uploadtext'); var img = OC.imagePath('core', 'filetypes/folder.png'); tr.find('td.filename').attr('style','background-image:url('+img+')'); uploadtext.text(''); uploadtext.hide(); //TODO really hide already + } else { + //TODO add row when sending file //remove file tr.fadeOut(); tr.remove(); } }); - +*/ $('#notification').hide(); $('#notification').on('click', '.undo', function(){ if (FileList.deleteFiles) { diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 3fad3fae7d3..a907aeab1fc 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -1,31 +1,5 @@ var uploadingFiles = {}; Files={ - cancelUpload:function(filename) { - if(uploadingFiles[filename]) { - uploadingFiles[filename].abort(); - delete uploadingFiles[filename]; - return true; - } - return false; - }, - cancelUploads:function() { - $.each(uploadingFiles,function(index,file) { - if(typeof file['abort'] === 'function') { - file.abort(); - var filename = $('tr').filterAttr('data-file',index); - filename.hide(); - filename.find('input[type="checkbox"]').removeAttr('checked'); - filename.removeClass('selected'); - } else { - $.each(file,function(i,f) { - f.abort(); - delete file[i]; - }); - } - delete uploadingFiles[index]; - }); - procesSelection(); - }, updateMaxUploadFilesize:function(response) { if(response == undefined) { return; @@ -117,7 +91,8 @@ $(document).ready(function() { // Trigger cancelling of file upload $('#uploadprogresswrapper .stop').on('click', function() { - Files.cancelUploads(); + OC.Upload.cancelUploads(); + procesSelection(); }); // Show trash bin diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 294223aa094..a20b4ae636f 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -62,7 +62,10 @@ $(document).ready(function() { // Add Uploadprogress Wrapper to controls bar $('#controls').append($('#additional_controls div#uploadprogresswrapper')); - // Cancel upload trigger - $('#cancel_upload_button').click(Files.cancelUploads); + // Cancel upload trigger + $('#cancel_upload_button').click(function() { + OC.Upload.cancelUploads(); + procesSelection(); + }); }); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 88a3f6628cb..ea03ef21455 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -207,105 +207,142 @@ var OCdialogs = { * @param {object} controller a controller with onCancel, onSkip, onReplace and onRename methods */ fileexists:function(data, original, replacement, controller) { - if (typeof controller !== 'object') { - controller = {}; - } - var self = this; - $.when(this._getFileExistsTemplate()).then(function($tmpl) { - var dialog_name = 'oc-dialog-fileexists-' + OCdialogs.dialogs_counter + '-content'; - var dialog_id = '#' + dialog_name; - var title = t('files','Replace »{filename}«?',{filename: original.name}); - var $dlg = $tmpl.octemplate({ - dialog_name: dialog_name, - title: title, - type: 'fileexists', - - why: t('files','Another file with the same name already exists in "{dir}".',{dir:'somedir'}), - what: t('files','Replacing it will overwrite it\'s contents.'), - original_heading: t('files','Original file'), - original_size: t('files','Size: {size}',{size: original.size}), - original_mtime: t('files','Last changed: {mtime}',{mtime: original.mtime}), + var selection = controller.getSelection(data.originalFiles); + if (selection.defaultAction) { + controller[selection.defaultAction](data); + } else { + $.when(this._getFileExistsTemplate()).then(function($tmpl) { + var dialog_name = 'oc-dialog-fileexists-' + OCdialogs.dialogs_counter + '-content'; + var dialog_id = '#' + dialog_name; + var title = t('files','Replace »{filename}«?',{filename: original.name}); + var original_size= t('files','Size: {size}',{size: original.size}); + var original_mtime = t('files','Last changed: {mtime}',{mtime: original.mtime}); + var replacement_size= t('files','Size: {size}',{size: replacement.size}); + var replacement_mtime = t('files','Last changed: {mtime}',{mtime: replacement.mtime}); + var $dlg = $tmpl.octemplate({ + dialog_name: dialog_name, + title: title, + type: 'fileexists', - replacement_heading: t('files','Replace with'), - replacement_size: t('files','Size: {size}',{size: replacement.size}), - replacement_mtime: t('files','Last changed: {mtime}',{mtime: replacement.mtime}), + why: t('files','Another file with the same name already exists in "{dir}".',{dir:'somedir'}), + what: t('files','Replacing it will overwrite it\'s contents.'), + original_heading: t('files','Original file'), + original_size: original_size, + original_mtime: original_mtime, - new_name_label: t('files','Choose a new name for the target.'), - all_files_label: t('files','Use this action for all files.') - }); - $('body').append($dlg); - - $(dialog_id + ' .original .icon').css('background-image','url('+OC.imagePath('core', 'filetypes/file.png')+')'); - $(dialog_id + ' .replacement .icon').css('background-image','url('+OC.imagePath('core', 'filetypes/file.png')+')'); - $(dialog_id + ' #new-name').val(original.name); - - - $(dialog_id + ' #new-name').on('keyup', function(e){ - if ($(dialog_id + ' #new-name').val() === original.name) { - - $(dialog_id + ' + div .rename').removeClass('primary').hide(); - $(dialog_id + ' + div .replace').addClass('primary').show(); - } else { - $(dialog_id + ' + div .rename').addClass('primary').show(); - $(dialog_id + ' + div .replace').removeClass('primary').hide(); - } - }); + replacement_heading: t('files','Replace with'), + replacement_size: replacement_size, + replacement_mtime: replacement_mtime, - buttonlist = [{ - text: t('core', 'Cancel'), - classes: 'cancel', - click: function(){ - if ( typeof controller.onCancel !== 'undefined') { - controller.onCancel(data); - } - $(dialog_id).ocdialog('close'); + new_name_label: t('files','Choose a new name for the target.'), + all_files_label: t('files','Use this action for all files.') + }); + $('body').append($dlg); + + getMimeIcon(original.type,function(path){ + $(dialog_id + ' .original .icon').css('background-image','url('+path+')'); + }); + getMimeIcon(replacement.type,function(path){ + $(dialog_id + ' .replacement .icon').css('background-image','url('+path+')'); + }); + $(dialog_id + ' #newname').val(original.name); + + + $(dialog_id + ' #newname').on('keyup', function(e){ + if ($(dialog_id + ' #newname').val() === original.name) { + $(dialog_id + ' + div .rename').removeClass('primary').hide(); + $(dialog_id + ' + div .replace').addClass('primary').show(); + } else { + $(dialog_id + ' + div .rename').addClass('primary').show(); + $(dialog_id + ' + div .replace').removeClass('primary').hide(); } - }, - { - text: t('core', 'Skip'), - classes: 'skip', - click: function(){ - if ( typeof controller.onSkip !== 'undefined') { - controller.onSkip(data); + }); + + buttonlist = [{ + text: t('core', 'Cancel'), + classes: 'cancel', + click: function(){ + if ( typeof controller.onCancel !== 'undefined') { + controller.onCancel(data); + } + $(dialog_id).ocdialog('close'); } - $(dialog_id).ocdialog('close'); - } - }, - { - text: t('core', 'Replace'), - classes: 'replace', - click: function(){ - if ( typeof controller.onReplace !== 'undefined') { - controller.onReplace(data); + }, + { + text: t('core', 'Skip'), + classes: 'skip', + click: function(){ + if ( typeof controller.onSkip !== 'undefined') { + if($(dialog_id + ' #allfiles').prop('checked')){ + selection.defaultAction = 'onSkip'; + /*selection.defaultAction = function(){ + controller.onSkip(data); + };*/ + } + controller.onSkip(data); + } + // trigger fileupload done with status skip + //data.result[0].status = 'skip'; + //fileupload._trigger('done', data.e, data); + $(dialog_id).ocdialog('close'); } - $(dialog_id).ocdialog('close'); }, - defaultButton: true - }, - { - text: t('core', 'Rename'), - classes: 'rename', - click: function(){ - if ( typeof controller.onRename !== 'undefined') { - controller.onRename(data, $(dialog_id + ' #new-name').val()); + { + text: t('core', 'Replace'), + classes: 'replace', + click: function(){ + if ( typeof controller.onReplace !== 'undefined') { + if($(dialog_id + ' #allfiles').prop('checked')){ + selection.defaultAction = 'onReplace'; + /*selection.defaultAction = function(){ + controller.onReplace(data); + };*/ + } + controller.onReplace(data); + } + $(dialog_id).ocdialog('close'); + }, + defaultButton: true + }, + { + text: t('core', 'Rename'), + classes: 'rename', + click: function(){ + if ( typeof controller.onRename !== 'undefined') { + //TODO use autorename when repeat is checked + controller.onRename(data, $(dialog_id + ' #newname').val()); + } + $(dialog_id).ocdialog('close'); } - $(dialog_id).ocdialog('close'); - } - }]; + }]; - $(dialog_id).ocdialog({ - closeOnEscape: true, - modal: true, - buttons: buttonlist, - closeButton: null + $(dialog_id).ocdialog({ + width: 500, + closeOnEscape: true, + modal: true, + buttons: buttonlist, + closeButton: null + }); + OCdialogs.dialogs_counter++; + + $(dialog_id + ' + div .rename').hide(); + $(dialog_id + ' #newname').hide(); + + $(dialog_id + ' #newnamecb').on('change', function(){ + if ($(dialog_id + ' #newnamecb').prop('checked')) { + $(dialog_id + ' #newname').fadeIn(); + } else { + $(dialog_id + ' #newname').fadeOut(); + $(dialog_id + ' #newname').val(original.name); + } + }); + + + }) + .fail(function() { + alert(t('core', 'Error loading file exists template')); }); - OCdialogs.dialogs_counter++; - - $(dialog_id + ' + div .rename').hide(); - }) - .fail(function() { - alert(t('core', 'Error loading file exists template')); - }); + } }, _getFilePickerTemplate: function() { var defer = $.Deferred(); -- cgit v1.2.3 From 164502477d8eac293ea002d39378be846bcc733c Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 16 Aug 2013 17:24:45 +0200 Subject: use jQuery.get instead of jQuery.ajax --- apps/files/js/files.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 3178ff65af8..fd18cf21ee8 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -821,12 +821,8 @@ function lazyLoadPreview(path, mime, ready) { var x = $('#filestable').data('preview-x'); var y = $('#filestable').data('preview-y'); var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y}); - $.ajax({ - url: previewURL, - type: 'GET', - success: function() { - ready(previewURL); - } + $.get(previewURL, function() { + ready(previewURL); }); } -- cgit v1.2.3 From bf04daff82758fe9913c706eef07aed30c9b35ea Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 21 Aug 2013 14:58:28 +0200 Subject: architecture too complex --- 3rdparty | 2 +- apps/files/js/file-upload.js | 109 +++- apps/files/js/filelist.js | 51 +- apps/files/js/files.js | 7 - apps/files/js/jquery.fileupload.js | 1023 ++++++++++++++++++++++-------- apps/files/js/jquery.iframe-transport.js | 70 +- apps/files/templates/part.list.php | 11 +- 7 files changed, 934 insertions(+), 339 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/3rdparty b/3rdparty index 2f3ae9f56a9..75a05d76ab8 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 2f3ae9f56a9838b45254393e13c14f8a8c380d6b +Subproject commit 75a05d76ab86ba7454b4312fd0ff2ca5bd5828cf diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index f8899cb07e6..c620942170c 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -1,4 +1,7 @@ /** + * + * use put t ocacnel upload before it starts? use chunked uploads? + * * 1. tracking which file to upload next -> upload queue with data elements added whenever add is called * 2. tracking progress for each folder individually -> track progress in a progress[dirname] object * - every new selection increases the total size and number of files for a directory @@ -63,6 +66,7 @@ OC.Upload = { * @type Array */ _selections: {}, + _selectionCount: 0, /* * queue which progress tracker to use for the next upload * @type Array @@ -77,7 +81,7 @@ OC.Upload = { }, getSelection:function(originalFiles) { if (!originalFiles.selectionKey) { - originalFiles.selectionKey = 'selection-' + $.assocArraySize(this._selections); + originalFiles.selectionKey = 'selection-' + this._selectionCount++; this._selections[originalFiles.selectionKey] = { selectionKey:originalFiles.selectionKey, files:{}, @@ -90,22 +94,41 @@ OC.Upload = { } return this._selections[originalFiles.selectionKey]; }, + deleteSelection:function(selectionKey) { + if (this._selections[selectionKey]) { + jQuery.each(this._selections[selectionKey].uploads, function(i, upload) { + upload.abort(); + }); + delete this._selections[selectionKey]; + } else { + console.log('OC.Upload: selection ' + selectionKey + ' does not exist'); + } + }, + deleteSelectionUpload:function(selection, filename) { + if(selection.uploads[filename]) { + selection.uploads[filename].abort(); + return true; + } else { + console.log('OC.Upload: selection ' + selection.selectionKey + ' does not contain upload for ' + filename); + } + return false; + }, cancelUpload:function(dir, filename) { + var self = this; var deleted = false; jQuery.each(this._selections, function(i, selection) { if (selection.dir === dir && selection.uploads[filename]) { - delete selection.uploads[filename]; - deleted = true; + deleted = self.deleteSelectionUpload(selection, filename); return false; // end searching through selections } }); return deleted; }, cancelUploads:function() { - jQuery.each(this._selections,function(i,selection){ - jQuery.each(selection.uploads, function (j, jqXHR) { - delete jqXHR; - }); + console.log('canceling uploads'); + var self = this; + jQuery.each(this._selections,function(i, selection){ + self.deleteSelection(selection.selectionKey); }); this._queue = []; this._isProcessing = false; @@ -132,7 +155,7 @@ OC.Upload = { } else { //queue is empty, we are done this._isProcessing = false; - //TODO free data + OC.Upload.cancelUploads(); } }, progressBytes: function() { @@ -157,13 +180,13 @@ OC.Upload = { total += selection.totalBytes; }); return total; - }, - handleExists:function(data) { - }, onCancel:function(data){ - //TODO cancel all uploads - OC.Upload.cancelUploads(); + //TODO cancel all uploads of this selection + + var selection = this.getSelection(data.originalFiles); + OC.Upload.deleteSelection(selection.selectionKey); + //FIXME hide progressbar }, onSkip:function(data){ var selection = this.getSelection(data.originalFiles); @@ -171,20 +194,19 @@ OC.Upload = { this.nextUpload(); }, onReplace:function(data){ - //TODO overwrite file data.data.append('replace', true); data.submit(); }, onRename:function(data, newName){ - //TODO rename file in filelist, stop spinner data.data.append('newname', newName); data.submit(); }, - setAction:function(data, action) { - - }, - setDefaultAction:function(action) { - + logStatus:function(caption, e, data) { + console.log(caption+' ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + if (data) { + console.log(data); + } + console.log(e); } }; @@ -195,6 +217,7 @@ $(document).ready(function() { //singleFileUploads is on by default, so the data.files array will always have length 1 add: function(e, data) { + OC.Upload.logStatus('add', e, data); var that = $(this); // lookup selection for dir @@ -267,14 +290,17 @@ $(document).ready(function() { * @param e */ start: function(e) { + OC.Upload.logStatus('start', e, null); //IE < 10 does not fire the necessary events for the progress bar. if($('html.lte9').length > 0) { return true; } + $('#uploadprogresswrapper input.stop').show(); $('#uploadprogressbar').progressbar({value:0}); $('#uploadprogressbar').fadeIn(); }, fail: function(e, data) { + OC.Upload.logStatus('fail', e, data); if (typeof data.textStatus !== 'undefined' && data.textStatus !== 'success' ) { if (data.textStatus === 'abort') { $('#notification').text(t('files', 'Upload cancelled.')); @@ -289,12 +315,26 @@ $(document).ready(function() { }, 5000); } var selection = OC.Upload.getSelection(data.originalFiles); - delete selection.uploads[data.files[0]]; + OC.Upload.deleteSelectionUpload(selection, data.files[0].name); + + //if user pressed cancel hide upload progress bar and cancel button + if (data.errorThrown === 'abort') { + $('#uploadprogresswrapper input.stop').fadeOut(); + $('#uploadprogressbar').fadeOut(); + } }, progress: function(e, data) { + OC.Upload.logStatus('progress', e, data); // TODO: show nice progress bar in file row }, + /** + * + * @param {type} e + * @param {type} data (only has loaded, total and lengthComputable) + * @returns {unresolved} + */ progressall: function(e, data) { + OC.Upload.logStatus('progressall', e, data); //IE < 10 does not fire the necessary events for the progress bar. if($('html.lte9').length > 0) { return; @@ -309,6 +349,7 @@ $(document).ready(function() { * @param data */ done:function(e, data) { + OC.Upload.logStatus('done', e, data); // handle different responses (json or body from iframe for ie) var response; if (typeof data.result === 'string') { @@ -323,7 +364,9 @@ $(document).ready(function() { if(typeof result[0] !== 'undefined' && result[0].status === 'success' ) { - selection.loadedBytes+=data.loaded; + if (selection) { + selection.loadedBytes+=data.loaded; + } OC.Upload.nextUpload(); } else { if (result[0].status === 'existserror') { @@ -333,13 +376,19 @@ $(document).ready(function() { var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); OC.dialogs.fileexists(data, original, replacement, OC.Upload, fu); } else { - delete selection.uploads[data.files[0]]; + OC.Upload.deleteSelectionUpload(selection, data.files[0].name); data.textStatus = 'servererror'; data.errorThrown = t('files', result.data.message); var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); fu._trigger('fail', e, data); } } + + //if user pressed cancel hide upload chrome + if (! OC.Upload.isProcessing()) { + $('#uploadprogresswrapper input.stop').fadeOut(); + $('#uploadprogressbar').fadeOut(); + } }, /** @@ -348,7 +397,10 @@ $(document).ready(function() { * @param data */ stop: function(e, data) { - if(OC.Upload.progressBytes()>=100) { + OC.Upload.logStatus('stop', e, data); + if(OC.Upload.progressBytes()>=100) { //only hide controls when all selections have ended uploading + + OC.Upload.cancelUploads(); //cleanup if(data.dataType !== 'iframe') { $('#uploadprogresswrapper input.stop').hide(); @@ -362,6 +414,11 @@ $(document).ready(function() { $('#uploadprogressbar').progressbar('value', 100); $('#uploadprogressbar').fadeOut(); } + //if user pressed cancel hide upload chrome + if (! OC.Upload.isProcessing()) { + $('#uploadprogresswrapper input.stop').fadeOut(); + $('#uploadprogressbar').fadeOut(); + } } }; @@ -384,8 +441,8 @@ $(document).ready(function() { }; // warn user not to leave the page while upload is in progress - $(window).bind('beforeunload', function(e) { - if ($.assocArraySize(uploadingFiles) > 0) { + $(window).on('beforeunload', function(e) { + if (OC.Upload.isProcessing()) { return t('files', 'File upload is in progress. Leaving the page now will cancel the upload.'); } }); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 335f81e04b9..eb57672e464 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -409,7 +409,7 @@ $(document).ready(function(){ var file_upload_start = $('#file_upload_start'); file_upload_start.on('fileuploaddrop', function(e, data) { - console.log('fileuploaddrop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploaddrop', e, data); var dropTarget = $(e.originalEvent.target).closest('tr'); if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder @@ -448,7 +448,7 @@ $(document).ready(function(){ }); file_upload_start.on('fileuploadadd', function(e, data) { - console.log('fileuploadadd ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploadadd', e, data); // lookup selection for dir var selection = OC.Upload.getSelection(data.originalFiles); @@ -482,8 +482,11 @@ $(document).ready(function(){ } }); + file_upload_start.on('fileuploadstart', function(e, data) { + OC.Upload.logStatus('fileuploadstart', e, data); + }); file_upload_start.on('fileuploaddone', function(e, data) { - console.log('fileuploaddone ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploaddone', e, data); var response; if (typeof data.result === 'string') { @@ -545,28 +548,58 @@ $(document).ready(function(){ }); } } + + //if user pressed cancel hide upload chrome + if (! OC.Upload.isProcessing()) { + //cleanup uploading to a dir + var uploadtext = $('tr .uploadtext'); + var img = OC.imagePath('core', 'filetypes/folder.png'); + uploadtext.parents('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.fadeOut(); + uploadtext.attr('currentUploads', 0); + } }); file_upload_start.on('fileuploadalways', function(e, data) { - console.log('fileuploadalways ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploadalways', e, data); }); file_upload_start.on('fileuploadsend', function(e, data) { - console.log('fileuploadsend ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploadsend', e, data); // TODOD add vis //data.context.element = }); file_upload_start.on('fileuploadprogress', function(e, data) { - console.log('fileuploadprogress ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploadprogress', e, data); }); file_upload_start.on('fileuploadprogressall', function(e, data) { - console.log('fileuploadprogressall ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploadprogressall', e, data); }); file_upload_start.on('fileuploadstop', function(e, data) { - console.log('fileuploadstop ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploadstop', e, data); + + //if user pressed cancel hide upload chrome + if (! OC.Upload.isProcessing()) { + //cleanup uploading to a dir + var uploadtext = $('tr .uploadtext'); + var img = OC.imagePath('core', 'filetypes/folder.png'); + uploadtext.parents('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.fadeOut(); + uploadtext.attr('currentUploads', 0); + } }); file_upload_start.on('fileuploadfail', function(e, data) { - console.log('fileuploadfail ' +OC.Upload.loadedBytes()+' / '+OC.Upload.totalBytes()); + OC.Upload.logStatus('fileuploadfail', e, data); + + //if user pressed cancel hide upload chrome + if (data.errorThrown === 'abort') { + //cleanup uploading to a dir + var uploadtext = $('tr .uploadtext'); + var img = OC.imagePath('core', 'filetypes/folder.png'); + uploadtext.parents('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.fadeOut(); + uploadtext.attr('currentUploads', 0); + } }); /* file_upload_start.on('fileuploadfail', function(e, data) { diff --git a/apps/files/js/files.js b/apps/files/js/files.js index a907aeab1fc..53405c7fe7e 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -1,4 +1,3 @@ -var uploadingFiles = {}; Files={ updateMaxUploadFilesize:function(response) { if(response == undefined) { @@ -235,12 +234,6 @@ $(document).ready(function() { return size; }; - // warn user not to leave the page while upload is in progress - $(window).bind('beforeunload', function(e) { - if ($.assocArraySize(uploadingFiles) > 0) - return t('files','File upload is in progress. Leaving the page now will cancel the upload.'); - }); - //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) if(navigator.userAgent.search(/konqueror/i)==-1){ $('#file_upload_start').attr('multiple','multiple') diff --git a/apps/files/js/jquery.fileupload.js b/apps/files/js/jquery.fileupload.js index a89e9dc2c44..f9f6cc3a382 100644 --- a/apps/files/js/jquery.fileupload.js +++ b/apps/files/js/jquery.fileupload.js @@ -1,5 +1,5 @@ /* - * jQuery File Upload Plugin 5.9 + * jQuery File Upload Plugin 5.32.2 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2010, Sebastian Tschan @@ -10,7 +10,7 @@ */ /*jslint nomen: true, unparam: true, regexp: true */ -/*global define, window, document, Blob, FormData, location */ +/*global define, window, document, location, File, Blob, FormData */ (function (factory) { 'use strict'; @@ -27,12 +27,28 @@ }(function ($) { 'use strict'; + // Detect file input support, based on + // http://viljamis.com/blog/2012/file-upload-support-on-mobile/ + $.support.fileInput = !(new RegExp( + // Handle devices which give false positives for the feature detection: + '(Android (1\\.[0156]|2\\.[01]))' + + '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' + + '|(w(eb)?OSBrowser)|(webOS)' + + '|(Kindle/(1\\.0|2\\.[05]|3\\.0))' + ).test(window.navigator.userAgent) || + // Feature detection for all other devices: + $('').prop('disabled')); + // The FileReader API is not actually used, but works as feature detection, // as e.g. Safari supports XHR file uploads via the FormData API, // but not non-multipart XHR file uploads: $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader); $.support.xhrFormDataFileUpload = !!window.FormData; + // Detect support for Blob slicing (required for chunked uploads): + $.support.blobSlice = window.Blob && (Blob.prototype.slice || + Blob.prototype.webkitSlice || Blob.prototype.mozSlice); + // The fileupload widget listens for change events on file input fields defined // via fileInput setting and paste or drop events of the given dropZone. // In addition to the default jQuery Widget methods, the fileupload widget @@ -44,17 +60,16 @@ $.widget('blueimp.fileupload', { options: { - // The namespace used for event handler binding on the dropZone and - // fileInput collections. - // If not set, the name of the widget ("fileupload") is used. - namespace: undefined, - // The drop target collection, by the default the complete document. - // Set to null or an empty collection to disable drag & drop support: + // The drop target element(s), by the default the complete document. + // Set to null to disable drag & drop support: dropZone: $(document), - // The file input field collection, that is listened for change events. + // The paste target element(s), by the default the complete document. + // Set to null to disable paste support: + pasteZone: $(document), + // The file input field(s), that are listened to for change events. // If undefined, it is set to the file input fields inside // of the widget element on plugin initialization. - // Set to null or an empty collection to disable the change listener. + // Set to null to disable the change listener. fileInput: undefined, // By default, the file input field is replaced with a clone after // each input field change event. This is required for iframe transport @@ -63,7 +78,8 @@ replaceFileInput: true, // The parameter name for the file form data (the request argument name). // If undefined or empty, the name property of the file input field is - // used, or "files[]" if the file input name property is also empty: + // used, or "files[]" if the file input name property is also empty, + // can be a string or an array of strings: paramName: undefined, // By default, each file of a selection is uploaded using an individual // request for XHR type uploads. Set to false to upload file @@ -108,6 +124,29 @@ // global progress calculation. Set the following option to false to // prevent recalculating the global progress data: recalculateProgress: true, + // Interval in milliseconds to calculate and trigger progress events: + progressInterval: 100, + // Interval in milliseconds to calculate progress bitrate: + bitrateInterval: 500, + // By default, uploads are started automatically when adding files: + autoUpload: true, + + // Error and info messages: + messages: { + uploadedBytes: 'Uploaded bytes exceed file size' + }, + + // Translation function, gets the message key to be translated + // and an object with context specific data as arguments: + i18n: function (message, context) { + message = this.messages[message] || message.toString(); + if (context) { + $.each(context, function (key, value) { + message = message.replace('{' + key + '}', value); + }); + } + return message; + }, // Additional form data to be sent along with the file uploads can be set // using this option, which accepts an array of objects with name and @@ -121,48 +160,81 @@ // The add callback is invoked as soon as files are added to the fileupload // widget (via file input selection, drag & drop, paste or add API call). // If the singleFileUploads option is enabled, this callback will be - // called once for each file in the selection for XHR file uplaods, else + // called once for each file in the selection for XHR file uploads, else // once for each file selection. + // // The upload starts when the submit method is invoked on the data parameter. // The data object contains a files property holding the added files - // and allows to override plugin options as well as define ajax settings. + // and allows you to override plugin options as well as define ajax settings. + // // Listeners for this callback can also be bound the following way: // .bind('fileuploadadd', func); + // // data.submit() returns a Promise object and allows to attach additional // handlers using jQuery's Deferred callbacks: // data.submit().done(func).fail(func).always(func); add: function (e, data) { - data.submit(); + if (data.autoUpload || (data.autoUpload !== false && + $(this).fileupload('option', 'autoUpload'))) { + data.process().done(function () { + data.submit(); + }); + } }, // Other callbacks: + // Callback for the submit event of each file upload: // submit: function (e, data) {}, // .bind('fileuploadsubmit', func); + // Callback for the start of each file upload request: // send: function (e, data) {}, // .bind('fileuploadsend', func); + // Callback for successful uploads: // done: function (e, data) {}, // .bind('fileuploaddone', func); + // Callback for failed (abort or error) uploads: // fail: function (e, data) {}, // .bind('fileuploadfail', func); + // Callback for completed (success, abort or error) requests: // always: function (e, data) {}, // .bind('fileuploadalways', func); + // Callback for upload progress events: // progress: function (e, data) {}, // .bind('fileuploadprogress', func); + // Callback for global upload progress events: // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func); + // Callback for uploads start, equivalent to the global ajaxStart event: // start: function (e) {}, // .bind('fileuploadstart', func); + // Callback for uploads stop, equivalent to the global ajaxStop event: // stop: function (e) {}, // .bind('fileuploadstop', func); - // Callback for change events of the fileInput collection: + + // Callback for change events of the fileInput(s): // change: function (e, data) {}, // .bind('fileuploadchange', func); - // Callback for paste events to the dropZone collection: + + // Callback for paste events to the pasteZone(s): // paste: function (e, data) {}, // .bind('fileuploadpaste', func); - // Callback for drop events of the dropZone collection: + + // Callback for drop events of the dropZone(s): // drop: function (e, data) {}, // .bind('fileuploaddrop', func); - // Callback for dragover events of the dropZone collection: + + // Callback for dragover events of the dropZone(s): // dragover: function (e) {}, // .bind('fileuploaddragover', func); + // Callback for the start of each chunk upload request: + // chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func); + + // Callback for successful chunk uploads: + // chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func); + + // Callback for failed (abort or error) chunk uploads: + // chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func); + + // Callback for completed (success, abort or error) chunk upload requests: + // chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func); + // The plugin options are used as settings object for the ajax calls. // The following are jQuery ajax settings required for the file uploads: processData: false, @@ -170,15 +242,36 @@ cache: false }, - // A list of options that require a refresh after assigning a new value: - _refreshOptionsList: [ - 'namespace', - 'dropZone', + // A list of options that require reinitializing event listeners and/or + // special initialization code: + _specialOptions: [ 'fileInput', + 'dropZone', + 'pasteZone', 'multipart', 'forceIframeTransport' ], + _blobSlice: $.support.blobSlice && function () { + var slice = this.slice || this.webkitSlice || this.mozSlice; + return slice.apply(this, arguments); + }, + + _BitrateTimer: function () { + this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime()); + this.loaded = 0; + this.bitrate = 0; + this.getBitrate = function (now, loaded, interval) { + var timeDiff = now - this.timestamp; + if (!this.bitrate || !interval || timeDiff > interval) { + this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8; + this.loaded = loaded; + this.timestamp = now; + } + return this.bitrate; + }; + }, + _isXHRUpload: function (options) { return !options.forceIframeTransport && ((!options.multipart && $.support.xhrFileUpload) || @@ -189,9 +282,11 @@ var formData; if (typeof options.formData === 'function') { return options.formData(options.form); - } else if ($.isArray(options.formData)) { + } + if ($.isArray(options.formData)) { return options.formData; - } else if (options.formData) { + } + if ($.type(options.formData) === 'object') { formData = []; $.each(options.formData, function (name, value) { formData.push({name: name, value: value}); @@ -209,28 +304,66 @@ return total; }, + _initProgressObject: function (obj) { + var progress = { + loaded: 0, + total: 0, + bitrate: 0 + }; + if (obj._progress) { + $.extend(obj._progress, progress); + } else { + obj._progress = progress; + } + }, + + _initResponseObject: function (obj) { + var prop; + if (obj._response) { + for (prop in obj._response) { + if (obj._response.hasOwnProperty(prop)) { + delete obj._response[prop]; + } + } + } else { + obj._response = {}; + } + }, + _onProgress: function (e, data) { if (e.lengthComputable) { - var total = data.total || this._getTotal(data.files), - loaded = parseInt( - e.loaded / e.total * (data.chunkSize || total), - 10 - ) + (data.uploadedBytes || 0); - this._loaded += loaded - (data.loaded || data.uploadedBytes || 0); - data.lengthComputable = true; - data.loaded = loaded; - data.total = total; + var now = ((Date.now) ? Date.now() : (new Date()).getTime()), + loaded; + if (data._time && data.progressInterval && + (now - data._time < data.progressInterval) && + e.loaded !== e.total) { + return; + } + data._time = now; + loaded = Math.floor( + e.loaded / e.total * (data.chunkSize || data._progress.total) + ) + (data.uploadedBytes || 0); + // Add the difference from the previously loaded state + // to the global loaded counter: + this._progress.loaded += (loaded - data._progress.loaded); + this._progress.bitrate = this._bitrateTimer.getBitrate( + now, + this._progress.loaded, + data.bitrateInterval + ); + data._progress.loaded = data.loaded = loaded; + data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate( + now, + loaded, + data.bitrateInterval + ); // Trigger a custom progress event with a total data property set // to the file size(s) of the current upload and a loaded data // property calculated accordingly: this._trigger('progress', e, data); // Trigger a global progress event for all current file uploads, // including ajax calls queued for sequential file uploads: - this._trigger('progressall', e, { - lengthComputable: true, - loaded: this._loaded, - total: this._total - }); + this._trigger('progressall', e, this._progress); } }, @@ -254,34 +387,30 @@ } }, + _isInstanceOf: function (type, obj) { + // Cross-frame instanceof check + return Object.prototype.toString.call(obj) === '[object ' + type + ']'; + }, + _initXHRData: function (options) { - var formData, + var that = this, + formData, file = options.files[0], // Ignore non-multipart setting if not supported: - multipart = options.multipart || !$.support.xhrFileUpload; - if (!multipart || options.blob) { - // For non-multipart uploads and chunked uploads, - // file meta data is not part of the request body, - // so we transmit this data as part of the HTTP headers. - // For cross domain requests, these headers must be allowed - // via Access-Control-Allow-Headers or removed using - // the beforeSend callback: - options.headers = $.extend(options.headers, { - 'X-File-Name': file.name, - 'X-File-Type': file.type, - 'X-File-Size': file.size - }); - if (!options.blob) { - // Non-chunked non-multipart upload: - options.contentType = file.type; - options.data = file; - } else if (!multipart) { - // Chunked non-multipart upload: - options.contentType = 'application/octet-stream'; - options.data = options.blob; - } + multipart = options.multipart || !$.support.xhrFileUpload, + paramName = options.paramName[0]; + options.headers = options.headers || {}; + if (options.contentRange) { + options.headers['Content-Range'] = options.contentRange; + } + if (!multipart || options.blob || !this._isInstanceOf('File', file)) { + options.headers['Content-Disposition'] = 'attachment; filename="' + + encodeURI(file.name) + '"'; } - if (multipart && $.support.xhrFormDataFileUpload) { + if (!multipart) { + options.contentType = file.type; + options.data = options.blob || file; + } else if ($.support.xhrFormDataFileUpload) { if (options.postMessage) { // window.postMessage does not allow sending FormData // objects, so we just add the File/Blob objects to @@ -290,19 +419,19 @@ formData = this._getFormData(options); if (options.blob) { formData.push({ - name: options.paramName, + name: paramName, value: options.blob }); } else { $.each(options.files, function (index, file) { formData.push({ - name: options.paramName, + name: options.paramName[index] || paramName, value: file }); }); } } else { - if (options.formData instanceof FormData) { + if (that._isInstanceOf('FormData', options.formData)) { formData = options.formData; } else { formData = new FormData(); @@ -311,14 +440,18 @@ }); } if (options.blob) { - formData.append(options.paramName, options.blob, file.name); + formData.append(paramName, options.blob, file.name); } else { $.each(options.files, function (index, file) { - // File objects are also Blob instances. // This check allows the tests to run with // dummy objects: - if (file instanceof Blob) { - formData.append(options.paramName, file, file.name); + if (that._isInstanceOf('File', file) || + that._isInstanceOf('Blob', file)) { + formData.append( + options.paramName[index] || paramName, + file, + file.name + ); } }); } @@ -330,13 +463,13 @@ }, _initIframeSettings: function (options) { + var targetHost = $('').prop('href', options.url).prop('host'); // Setting the dataType to iframe enables the iframe transport: options.dataType = 'iframe ' + (options.dataType || ''); // The iframe transport accepts a serialized array as form data: options.formData = this._getFormData(options); // Add redirect url to form data on cross-domain uploads: - if (options.redirect && $('').prop('href', options.url) - .prop('host') !== location.host) { + if (options.redirect && targetHost && targetHost !== location.host) { options.formData.push({ name: options.redirectParamName || 'redirect', value: options.redirect @@ -358,29 +491,58 @@ options.dataType = 'postmessage ' + (options.dataType || ''); } } else { - this._initIframeSettings(options, 'iframe'); + this._initIframeSettings(options); } }, + _getParamName: function (options) { + var fileInput = $(options.fileInput), + paramName = options.paramName; + if (!paramName) { + paramName = []; + fileInput.each(function () { + var input = $(this), + name = input.prop('name') || 'files[]', + i = (input.prop('files') || [1]).length; + while (i) { + paramName.push(name); + i -= 1; + } + }); + if (!paramName.length) { + paramName = [fileInput.prop('name') || 'files[]']; + } + } else if (!$.isArray(paramName)) { + paramName = [paramName]; + } + return paramName; + }, + _initFormSettings: function (options) { // Retrieve missing options from the input field and the // associated form, if available: if (!options.form || !options.form.length) { options.form = $(options.fileInput.prop('form')); + // If the given file input doesn't have an associated form, + // use the default widget file input's form: + if (!options.form.length) { + options.form = $(this.options.fileInput.prop('form')); + } } - if (!options.paramName) { - options.paramName = options.fileInput.prop('name') || - 'files[]'; - } + options.paramName = this._getParamName(options); if (!options.url) { options.url = options.form.prop('action') || location.href; } // The HTTP request method must be "POST" or "PUT": options.type = (options.type || options.form.prop('method') || '') .toUpperCase(); - if (options.type !== 'POST' && options.type !== 'PUT') { + if (options.type !== 'POST' && options.type !== 'PUT' && + options.type !== 'PATCH') { options.type = 'POST'; } + if (!options.formAcceptCharset) { + options.formAcceptCharset = options.form.attr('accept-charset'); + } }, _getAJAXSettings: function (data) { @@ -390,6 +552,21 @@ return options; }, + // jQuery 1.6 doesn't provide .state(), + // while jQuery 1.8+ removed .isRejected() and .isResolved(): + _getDeferredState: function (deferred) { + if (deferred.state) { + return deferred.state(); + } + if (deferred.isResolved()) { + return 'resolved'; + } + if (deferred.isRejected()) { + return 'rejected'; + } + return 'pending'; + }, + // Maps jqXHR callbacks to the equivalent // methods of the given Promise object: _enhancePromise: function (promise) { @@ -414,24 +591,77 @@ return this._enhancePromise(promise); }, + // Adds convenience methods to the data callback argument: + _addConvenienceMethods: function (e, data) { + var that = this, + getPromise = function (data) { + return $.Deferred().resolveWith(that, [data]).promise(); + }; + data.process = function (resolveFunc, rejectFunc) { + if (resolveFunc || rejectFunc) { + data._processQueue = this._processQueue = + (this._processQueue || getPromise(this)) + .pipe(resolveFunc, rejectFunc); + } + return this._processQueue || getPromise(this); + }; + data.submit = function () { + if (this.state() !== 'pending') { + data.jqXHR = this.jqXHR = + (that._trigger('submit', e, this) !== false) && + that._onSend(e, this); + } + return this.jqXHR || that._getXHRPromise(); + }; + data.abort = function () { + if (this.jqXHR) { + return this.jqXHR.abort(); + } + return that._getXHRPromise(); + }; + data.state = function () { + if (this.jqXHR) { + return that._getDeferredState(this.jqXHR); + } + if (this._processQueue) { + return that._getDeferredState(this._processQueue); + } + }; + data.progress = function () { + return this._progress; + }; + data.response = function () { + return this._response; + }; + }, + + // Parses the Range header from the server response + // and returns the uploaded bytes: + _getUploadedBytes: function (jqXHR) { + var range = jqXHR.getResponseHeader('Range'), + parts = range && range.split('-'), + upperBytesPos = parts && parts.length > 1 && + parseInt(parts[1], 10); + return upperBytesPos && upperBytesPos + 1; + }, + // Uploads a file in multiple, sequential requests // by splitting the file up in multiple blob chunks. // If the second parameter is true, only tests if the file // should be uploaded in chunks, but does not invoke any // upload requests: _chunkedUpload: function (options, testOnly) { + options.uploadedBytes = options.uploadedBytes || 0; var that = this, file = options.files[0], fs = file.size, - ub = options.uploadedBytes = options.uploadedBytes || 0, + ub = options.uploadedBytes, mcs = options.maxChunkSize || fs, - // Use the Blob methods with the slice implementation - // according to the W3C Blob API specification: - slice = file.webkitSlice || file.mozSlice || file.slice, - upload, - n, + slice = this._blobSlice, + dfd = $.Deferred(), + promise = dfd.promise(), jqXHR, - pipe; + upload; if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) || options.data) { return false; @@ -440,62 +670,84 @@ return true; } if (ub >= fs) { - file.error = 'uploadedBytes'; + file.error = options.i18n('uploadedBytes'); return this._getXHRPromise( false, options.context, [null, 'error', file.error] ); } - // n is the number of blobs to upload, - // calculated via filesize, uploaded bytes and max chunk size: - n = Math.ceil((fs - ub) / mcs); - // The chunk upload method accepting the chunk number as parameter: - upload = function (i) { - if (!i) { - return that._getXHRPromise(true, options.context); - } - // Upload the blobs in sequential order: - return upload(i -= 1).pipe(function () { - // Clone the options object for each chunk upload: - var o = $.extend({}, options); - o.blob = slice.call( - file, - ub + i * mcs, - ub + (i + 1) * mcs - ); - // Store the current chunk size, as the blob itself - // will be dereferenced after data processing: - o.chunkSize = o.blob.size; - // Process the upload data (the blob and potential form data): - that._initXHRData(o); - // Add progress listeners for this chunk upload: - that._initProgressListener(o); - jqXHR = ($.ajax(o) || that._getXHRPromise(false, o.context)) - .done(function () { - // Create a progress event if upload is done and - // no progress event has been invoked for this chunk: - if (!o.loaded) { - that._onProgress($.Event('progress', { - lengthComputable: true, - loaded: o.chunkSize, - total: o.chunkSize - }), o); - } - options.uploadedBytes = o.uploadedBytes += - o.chunkSize; - }); - return jqXHR; - }); + // The chunk upload method: + upload = function () { + // Clone the options object for each chunk upload: + var o = $.extend({}, options), + currentLoaded = o._progress.loaded; + o.blob = slice.call( + file, + ub, + ub + mcs, + file.type + ); + // Store the current chunk size, as the blob itself + // will be dereferenced after data processing: + o.chunkSize = o.blob.size; + // Expose the chunk bytes position range: + o.contentRange = 'bytes ' + ub + '-' + + (ub + o.chunkSize - 1) + '/' + fs; + // Process the upload data (the blob and potential form data): + that._initXHRData(o); + // Add progress listeners for this chunk upload: + that._initProgressListener(o); + jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) || + that._getXHRPromise(false, o.context)) + .done(function (result, textStatus, jqXHR) { + ub = that._getUploadedBytes(jqXHR) || + (ub + o.chunkSize); + // Create a progress event if no final progress event + // with loaded equaling total has been triggered + // for this chunk: + if (currentLoaded + o.chunkSize - o._progress.loaded) { + that._onProgress($.Event('progress', { + lengthComputable: true, + loaded: ub - o.uploadedBytes, + total: ub - o.uploadedBytes + }), o); + } + options.uploadedBytes = o.uploadedBytes = ub; + o.result = result; + o.textStatus = textStatus; + o.jqXHR = jqXHR; + that._trigger('chunkdone', null, o); + that._trigger('chunkalways', null, o); + if (ub < fs) { + // File upload not yet complete, + // continue with the next chunk: + upload(); + } else { + dfd.resolveWith( + o.context, + [result, textStatus, jqXHR] + ); + } + }) + .fail(function (jqXHR, textStatus, errorThrown) { + o.jqXHR = jqXHR; + o.textStatus = textStatus; + o.errorThrown = errorThrown; + that._trigger('chunkfail', null, o); + that._trigger('chunkalways', null, o); + dfd.rejectWith( + o.context, + [jqXHR, textStatus, errorThrown] + ); + }); }; - // Return the piped Promise object, enhanced with an abort method, - // which is delegated to the jqXHR object of the current upload, - // and jqXHR callbacks mapped to the equivalent Promise methods: - pipe = upload(n); - pipe.abort = function () { + this._enhancePromise(promise); + promise.abort = function () { return jqXHR.abort(); }; - return this._enhancePromise(pipe); + upload(); + return promise; }, _beforeSend: function (e, data) { @@ -504,99 +756,113 @@ // and no other uploads are currently running, // equivalent to the global ajaxStart event: this._trigger('start'); + // Set timer for global bitrate progress calculation: + this._bitrateTimer = new this._BitrateTimer(); + // Reset the global progress values: + this._progress.loaded = this._progress.total = 0; + this._progress.bitrate = 0; } + // Make sure the container objects for the .response() and + // .progress() methods on the data object are available + // and reset to their initial state: + this._initResponseObject(data); + this._initProgressObject(data); + data._progress.loaded = data.loaded = data.uploadedBytes || 0; + data._progress.total = data.total = this._getTotal(data.files) || 1; + data._progress.bitrate = data.bitrate = 0; this._active += 1; // Initialize the global progress values: - this._loaded += data.uploadedBytes || 0; - this._total += this._getTotal(data.files); + this._progress.loaded += data.loaded; + this._progress.total += data.total; }, _onDone: function (result, textStatus, jqXHR, options) { - if (!this._isXHRUpload(options)) { - // Create a progress event for each iframe load: + var total = options._progress.total, + response = options._response; + if (options._progress.loaded < total) { + // Create a progress event if no final progress event + // with loaded equaling total has been triggered: this._onProgress($.Event('progress', { lengthComputable: true, - loaded: 1, - total: 1 + loaded: total, + total: total }), options); } - options.result = result; - options.textStatus = textStatus; - options.jqXHR = jqXHR; + response.result = options.result = result; + response.textStatus = options.textStatus = textStatus; + response.jqXHR = options.jqXHR = jqXHR; this._trigger('done', null, options); }, _onFail: function (jqXHR, textStatus, errorThrown, options) { - options.jqXHR = jqXHR; - options.textStatus = textStatus; - options.errorThrown = errorThrown; - this._trigger('fail', null, options); + var response = options._response; if (options.recalculateProgress) { // Remove the failed (error or abort) file upload from // the global progress calculation: - this._loaded -= options.loaded || options.uploadedBytes || 0; - this._total -= options.total || this._getTotal(options.files); + this._progress.loaded -= options._progress.loaded; + this._progress.total -= options._progress.total; } + response.jqXHR = options.jqXHR = jqXHR; + response.textStatus = options.textStatus = textStatus; + response.errorThrown = options.errorThrown = errorThrown; + this._trigger('fail', null, options); }, _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) { - this._active -= 1; - options.textStatus = textStatus; - if (jqXHRorError && jqXHRorError.always) { - options.jqXHR = jqXHRorError; - options.result = jqXHRorResult; - } else { - options.jqXHR = jqXHRorResult; - options.errorThrown = jqXHRorError; - } + // jqXHRorResult, textStatus and jqXHRorError are added to the + // options object via done and fail callbacks this._trigger('always', null, options); - if (this._active === 0) { - // The stop callback is triggered when all uploads have - // been completed, equivalent to the global ajaxStop event: - this._trigger('stop'); - // Reset the global progress values: - this._loaded = this._total = 0; - } }, _onSend: function (e, data) { + if (!data.submit) { + this._addConvenienceMethods(e, data); + } var that = this, jqXHR, + aborted, slot, pipe, options = that._getAJAXSettings(data), - send = function (resolve, args) { + send = function () { that._sending += 1; + // Set timer for bitrate progress calculation: + options._bitrateTimer = new that._BitrateTimer(); jqXHR = jqXHR || ( - (resolve !== false && - that._trigger('send', e, options) !== false && - (that._chunkedUpload(options) || $.ajax(options))) || - that._getXHRPromise(false, options.context, args) + ((aborted || that._trigger('send', e, options) === false) && + that._getXHRPromise(false, options.context, aborted)) || + that._chunkedUpload(options) || $.ajax(options) ).done(function (result, textStatus, jqXHR) { that._onDone(result, textStatus, jqXHR, options); }).fail(function (jqXHR, textStatus, errorThrown) { that._onFail(jqXHR, textStatus, errorThrown, options); }).always(function (jqXHRorResult, textStatus, jqXHRorError) { - that._sending -= 1; that._onAlways( jqXHRorResult, textStatus, jqXHRorError, options ); + that._sending -= 1; + that._active -= 1; if (options.limitConcurrentUploads && options.limitConcurrentUploads > that._sending) { // Start the next queued upload, // that has not been aborted: var nextSlot = that._slots.shift(); while (nextSlot) { - if (!nextSlot.isRejected()) { + if (that._getDeferredState(nextSlot) === 'pending') { nextSlot.resolve(); break; } nextSlot = that._slots.shift(); } } + if (that._active === 0) { + // The stop callback is triggered when all uploads have + // been completed, equivalent to the global ajaxStop event: + that._trigger('stop'); + } }); return jqXHR; }; @@ -609,18 +875,19 @@ this._slots.push(slot); pipe = slot.pipe(send); } else { - pipe = (this._sequence = this._sequence.pipe(send, send)); + this._sequence = this._sequence.pipe(send, send); + pipe = this._sequence; } // Return the piped Promise object, enhanced with an abort method, // which is delegated to the jqXHR object of the current upload, // and jqXHR callbacks mapped to the equivalent Promise methods: pipe.abort = function () { - var args = [undefined, 'abort', 'abort']; + aborted = [undefined, 'abort', 'abort']; if (!jqXHR) { if (slot) { - slot.rejectWith(args); + slot.rejectWith(options.context, aborted); } - return send(false, args); + return send(); } return jqXHR.abort(); }; @@ -634,40 +901,43 @@ result = true, options = $.extend({}, this.options, data), limit = options.limitMultiFileUploads, + paramName = this._getParamName(options), + paramNameSet, + paramNameSlice, fileSet, i; if (!(options.singleFileUploads || limit) || !this._isXHRUpload(options)) { fileSet = [data.files]; + paramNameSet = [paramName]; } else if (!options.singleFileUploads && limit) { fileSet = []; + paramNameSet = []; for (i = 0; i < data.files.length; i += limit) { fileSet.push(data.files.slice(i, i + limit)); + paramNameSlice = paramName.slice(i, i + limit); + if (!paramNameSlice.length) { + paramNameSlice = paramName; + } + paramNameSet.push(paramNameSlice); } + } else { + paramNameSet = paramName; } data.originalFiles = data.files; $.each(fileSet || data.files, function (index, element) { - var files = fileSet ? element : [element], - newData = $.extend({}, data, {files: files}); - newData.submit = function () { - newData.jqXHR = this.jqXHR = - (that._trigger('submit', e, this) !== false) && - that._onSend(e, this); - return this.jqXHR; - }; - return (result = that._trigger('add', e, newData)); + var newData = $.extend({}, data); + newData.files = fileSet ? element : [element]; + newData.paramName = paramNameSet[index]; + that._initResponseObject(newData); + that._initProgressObject(newData); + that._addConvenienceMethods(e, newData); + result = that._trigger('add', e, newData); + return result; }); return result; }, - // File Normalization for Gecko 1.9.1 (Firefox 3.5) support: - _normalizeFile: function (index, file) { - if (file.name === undefined && file.size === undefined) { - file.name = file.fileName; - file.size = file.fileSize; - } - }, - _replaceFileInput: function (input) { var inputClone = input.clone(true); $('
').append(inputClone)[0].reset(); @@ -677,7 +947,7 @@ // Avoid memory leaks with the detached file input: $.cleanData(input.unbind('remove')); // Replace the original file input element in the fileInput - // collection with the clone, which has been copied including + // elements set with the clone, which has been copied including // event handlers: this.options.fileInput = this.options.fileInput.map(function (i, el) { if (el === input[0]) { @@ -692,102 +962,229 @@ } }, - _onChange: function (e) { - var that = e.data.fileupload, - data = { - files: $.each($.makeArray(e.target.files), that._normalizeFile), - fileInput: $(e.target), - form: $(e.target.form) - }; - if (!data.files.length) { + _handleFileTreeEntry: function (entry, path) { + var that = this, + dfd = $.Deferred(), + errorHandler = function (e) { + if (e && !e.entry) { + e.entry = entry; + } + // Since $.when returns immediately if one + // Deferred is rejected, we use resolve instead. + // This allows valid files and invalid items + // to be returned together in one set: + dfd.resolve([e]); + }, + dirReader; + path = path || ''; + if (entry.isFile) { + if (entry._file) { + // Workaround for Chrome bug #149735 + entry._file.relativePath = path; + dfd.resolve(entry._file); + } else { + entry.file(function (file) { + file.relativePath = path; + dfd.resolve(file); + }, errorHandler); + } + } else if (entry.isDirectory) { + dirReader = entry.createReader(); + dirReader.readEntries(function (entries) { + that._handleFileTreeEntries( + entries, + path + entry.name + '/' + ).done(function (files) { + dfd.resolve(files); + }).fail(errorHandler); + }, errorHandler); + } else { + // Return an empy list for file system items + // other than files or directories: + dfd.resolve([]); + } + return dfd.promise(); + }, + + _handleFileTreeEntries: function (entries, path) { + var that = this; + return $.when.apply( + $, + $.map(entries, function (entry) { + return that._handleFileTreeEntry(entry, path); + }) + ).pipe(function () { + return Array.prototype.concat.apply( + [], + arguments + ); + }); + }, + + _getDroppedFiles: function (dataTransfer) { + dataTransfer = dataTransfer || {}; + var items = dataTransfer.items; + if (items && items.length && (items[0].webkitGetAsEntry || + items[0].getAsEntry)) { + return this._handleFileTreeEntries( + $.map(items, function (item) { + var entry; + if (item.webkitGetAsEntry) { + entry = item.webkitGetAsEntry(); + if (entry) { + // Workaround for Chrome bug #149735: + entry._file = item.getAsFile(); + } + return entry; + } + return item.getAsEntry(); + }) + ); + } + return $.Deferred().resolve( + $.makeArray(dataTransfer.files) + ).promise(); + }, + + _getSingleFileInputFiles: function (fileInput) { + fileInput = $(fileInput); + var entries = fileInput.prop('webkitEntries') || + fileInput.prop('entries'), + files, + value; + if (entries && entries.length) { + return this._handleFileTreeEntries(entries); + } + files = $.makeArray(fileInput.prop('files')); + if (!files.length) { + value = fileInput.prop('value'); + if (!value) { + return $.Deferred().resolve([]).promise(); + } // If the files property is not available, the browser does not // support the File API and we add a pseudo File object with // the input value as name with path information removed: - data.files = [{name: e.target.value.replace(/^.*\\/, '')}]; - } - if (that.options.replaceFileInput) { - that._replaceFileInput(data.fileInput); + files = [{name: value.replace(/^.*\\/, '')}]; + } else if (files[0].name === undefined && files[0].fileName) { + // File normalization for Safari 4 and Firefox 3: + $.each(files, function (index, file) { + file.name = file.fileName; + file.size = file.fileSize; + }); } - if (that._trigger('change', e, data) === false || - that._onAdd(e, data) === false) { - return false; + return $.Deferred().resolve(files).promise(); + }, + + _getFileInputFiles: function (fileInput) { + if (!(fileInput instanceof $) || fileInput.length === 1) { + return this._getSingleFileInputFiles(fileInput); } + return $.when.apply( + $, + $.map(fileInput, this._getSingleFileInputFiles) + ).pipe(function () { + return Array.prototype.concat.apply( + [], + arguments + ); + }); + }, + + _onChange: function (e) { + var that = this, + data = { + fileInput: $(e.target), + form: $(e.target.form) + }; + this._getFileInputFiles(data.fileInput).always(function (files) { + data.files = files; + if (that.options.replaceFileInput) { + that._replaceFileInput(data.fileInput); + } + if (that._trigger('change', e, data) !== false) { + that._onAdd(e, data); + } + }); }, _onPaste: function (e) { - var that = e.data.fileupload, - cbd = e.originalEvent.clipboardData, - items = (cbd && cbd.items) || [], + var items = e.originalEvent && e.originalEvent.clipboardData && + e.originalEvent.clipboardData.items, data = {files: []}; - $.each(items, function (index, item) { - var file = item.getAsFile && item.getAsFile(); - if (file) { - data.files.push(file); + if (items && items.length) { + $.each(items, function (index, item) { + var file = item.getAsFile && item.getAsFile(); + if (file) { + data.files.push(file); + } + }); + if (this._trigger('paste', e, data) === false || + this._onAdd(e, data) === false) { + return false; } - }); - if (that._trigger('paste', e, data) === false || - that._onAdd(e, data) === false) { - return false; } }, _onDrop: function (e) { - var that = e.data.fileupload, - dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer, - data = { - files: $.each( - $.makeArray(dataTransfer && dataTransfer.files), - that._normalizeFile - ) - }; - if (that._trigger('drop', e, data) === false || - that._onAdd(e, data) === false) { - return false; + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; + var that = this, + dataTransfer = e.dataTransfer, + data = {}; + if (dataTransfer && dataTransfer.files && dataTransfer.files.length) { + e.preventDefault(); + this._getDroppedFiles(dataTransfer).always(function (files) { + data.files = files; + if (that._trigger('drop', e, data) !== false) { + that._onAdd(e, data); + } + }); } - e.preventDefault(); }, _onDragOver: function (e) { - var that = e.data.fileupload, - dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer; - if (that._trigger('dragover', e) === false) { - return false; - } + e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; + var dataTransfer = e.dataTransfer; if (dataTransfer) { - dataTransfer.dropEffect = dataTransfer.effectAllowed = 'copy'; + if (this._trigger('dragover', e) === false) { + return false; + } + if ($.inArray('Files', dataTransfer.types) !== -1) { + dataTransfer.dropEffect = 'copy'; + e.preventDefault(); + } } - e.preventDefault(); }, _initEventHandlers: function () { - var ns = this.options.namespace; if (this._isXHRUpload(this.options)) { - this.options.dropZone - .bind('dragover.' + ns, {fileupload: this}, this._onDragOver) - .bind('drop.' + ns, {fileupload: this}, this._onDrop) - .bind('paste.' + ns, {fileupload: this}, this._onPaste); + this._on(this.options.dropZone, { + dragover: this._onDragOver, + drop: this._onDrop + }); + this._on(this.options.pasteZone, { + paste: this._onPaste + }); + } + if ($.support.fileInput) { + this._on(this.options.fileInput, { + change: this._onChange + }); } - this.options.fileInput - .bind('change.' + ns, {fileupload: this}, this._onChange); }, _destroyEventHandlers: function () { - var ns = this.options.namespace; - this.options.dropZone - .unbind('dragover.' + ns, this._onDragOver) - .unbind('drop.' + ns, this._onDrop) - .unbind('paste.' + ns, this._onPaste); - this.options.fileInput - .unbind('change.' + ns, this._onChange); + this._off(this.options.dropZone, 'dragover drop'); + this._off(this.options.pasteZone, 'paste'); + this._off(this.options.fileInput, 'change'); }, _setOption: function (key, value) { - var refresh = $.inArray(key, this._refreshOptionsList) !== -1; - if (refresh) { + var reinit = $.inArray(key, this._specialOptions) !== -1; + if (reinit) { this._destroyEventHandlers(); } - $.Widget.prototype._setOption.call(this, key, value); - if (refresh) { + this._super(key, value); + if (reinit) { this._initSpecialOptions(); this._initEventHandlers(); } @@ -796,42 +1193,68 @@ _initSpecialOptions: function () { var options = this.options; if (options.fileInput === undefined) { - options.fileInput = this.element.is('input:file') ? - this.element : this.element.find('input:file'); + options.fileInput = this.element.is('input[type="file"]') ? + this.element : this.element.find('input[type="file"]'); } else if (!(options.fileInput instanceof $)) { options.fileInput = $(options.fileInput); } if (!(options.dropZone instanceof $)) { options.dropZone = $(options.dropZone); } + if (!(options.pasteZone instanceof $)) { + options.pasteZone = $(options.pasteZone); + } + }, + + _getRegExp: function (str) { + var parts = str.split('/'), + modifiers = parts.pop(); + parts.shift(); + return new RegExp(parts.join('/'), modifiers); + }, + + _isRegExpOption: function (key, value) { + return key !== 'url' && $.type(value) === 'string' && + /^\/.*\/[igm]{0,3}$/.test(value); + }, + + _initDataAttributes: function () { + var that = this, + options = this.options; + // Initialize options set via HTML5 data-attributes: + $.each( + $(this.element[0].cloneNode(false)).data(), + function (key, value) { + if (that._isRegExpOption(key, value)) { + value = that._getRegExp(value); + } + options[key] = value; + } + ); }, _create: function () { - var options = this.options, - dataOpts = $.extend({}, this.element.data()); - dataOpts[this.widgetName] = undefined; - $.extend(options, dataOpts); - options.namespace = options.namespace || this.widgetName; + this._initDataAttributes(); this._initSpecialOptions(); this._slots = []; this._sequence = this._getXHRPromise(true); - this._sending = this._active = this._loaded = this._total = 0; + this._sending = this._active = 0; + this._initProgressObject(this); this._initEventHandlers(); }, - destroy: function () { - this._destroyEventHandlers(); - $.Widget.prototype.destroy.call(this); - }, - - enable: function () { - $.Widget.prototype.enable.call(this); - this._initEventHandlers(); + // This method is exposed to the widget API and allows to query + // the number of active uploads: + active: function () { + return this._active; }, - disable: function () { - this._destroyEventHandlers(); - $.Widget.prototype.disable.call(this); + // This method is exposed to the widget API and allows to query + // the widget upload progress. + // It returns an object with loaded, total and bitrate properties + // for the running uploads: + progress: function () { + return this._progress; }, // This method is exposed to the widget API and allows adding files @@ -839,21 +1262,65 @@ // must have a files property and can contain additional options: // .fileupload('add', {files: filesList}); add: function (data) { + var that = this; if (!data || this.options.disabled) { return; } - data.files = $.each($.makeArray(data.files), this._normalizeFile); - this._onAdd(null, data); + if (data.fileInput && !data.files) { + this._getFileInputFiles(data.fileInput).always(function (files) { + data.files = files; + that._onAdd(null, data); + }); + } else { + data.files = $.makeArray(data.files); + this._onAdd(null, data); + } }, // This method is exposed to the widget API and allows sending files // using the fileupload API. The data parameter accepts an object which - // must have a files property and can contain additional options: + // must have a files or fileInput property and can contain additional options: // .fileupload('send', {files: filesList}); // The method returns a Promise object for the file upload call. send: function (data) { if (data && !this.options.disabled) { - data.files = $.each($.makeArray(data.files), this._normalizeFile); + if (data.fileInput && !data.files) { + var that = this, + dfd = $.Deferred(), + promise = dfd.promise(), + jqXHR, + aborted; + promise.abort = function () { + aborted = true; + if (jqXHR) { + return jqXHR.abort(); + } + dfd.reject(null, 'abort', 'abort'); + return promise; + }; + this._getFileInputFiles(data.fileInput).always( + function (files) { + if (aborted) { + return; + } + if (!files.length) { + dfd.reject(); + return; + } + data.files = files; + jqXHR = that._onSend(null, data).then( + function (result, textStatus, jqXHR) { + dfd.resolve(result, textStatus, jqXHR); + }, + function (jqXHR, textStatus, errorThrown) { + dfd.reject(jqXHR, textStatus, errorThrown); + } + ); + } + ); + return this._enhancePromise(promise); + } + data.files = $.makeArray(data.files); if (data.files.length) { return this._onSend(null, data); } @@ -863,4 +1330,4 @@ }); -})); +})); \ No newline at end of file diff --git a/apps/files/js/jquery.iframe-transport.js b/apps/files/js/jquery.iframe-transport.js index d85c0c11297..5c9df77976b 100644 --- a/apps/files/js/jquery.iframe-transport.js +++ b/apps/files/js/jquery.iframe-transport.js @@ -1,5 +1,5 @@ /* - * jQuery Iframe Transport Plugin 1.3 + * jQuery Iframe Transport Plugin 1.7 * https://github.com/blueimp/jQuery-File-Upload * * Copyright 2011, Sebastian Tschan @@ -30,27 +30,45 @@ // The iframe transport accepts three additional options: // options.fileInput: a jQuery collection of file input fields // options.paramName: the parameter name for the file form data, - // overrides the name property of the file input field(s) + // overrides the name property of the file input field(s), + // can be a string or an array of strings. // options.formData: an array of objects with name and value properties, // equivalent to the return data of .serializeArray(), e.g.: // [{name: 'a', value: 1}, {name: 'b', value: 2}] $.ajaxTransport('iframe', function (options) { - if (options.async && (options.type === 'POST' || options.type === 'GET')) { + if (options.async) { var form, - iframe; + iframe, + addParamChar; return { send: function (_, completeCallback) { form = $('
'); + form.attr('accept-charset', options.formAcceptCharset); + addParamChar = /\?/.test(options.url) ? '&' : '?'; + // XDomainRequest only supports GET and POST: + if (options.type === 'DELETE') { + options.url = options.url + addParamChar + '_method=DELETE'; + options.type = 'POST'; + } else if (options.type === 'PUT') { + options.url = options.url + addParamChar + '_method=PUT'; + options.type = 'POST'; + } else if (options.type === 'PATCH') { + options.url = options.url + addParamChar + '_method=PATCH'; + options.type = 'POST'; + } // javascript:false as initial iframe src // prevents warning popups on HTTPS in IE6. // IE versions below IE8 cannot set the name property of // elements that have already been added to the DOM, // so we set the name along with the iframe HTML markup: + counter += 1; iframe = $( '' + counter + '">' ).bind('load', function () { - var fileInputClones; + var fileInputClones, + paramNames = $.isArray(options.paramName) ? + options.paramName : [options.paramName]; iframe .unbind('load') .bind('load', function () { @@ -79,7 +97,12 @@ // (happens on form submits to iframe targets): $('') .appendTo(form); - form.remove(); + window.setTimeout(function () { + // Removing the form in a setTimeout call + // allows Chrome's developer tools to display + // the response result + form.remove(); + }, 0); }); form .prop('target', iframe.prop('name')) @@ -101,8 +124,11 @@ return fileInputClones[index]; }); if (options.paramName) { - options.fileInput.each(function () { - $(this).prop('name', options.paramName); + options.fileInput.each(function (index) { + $(this).prop( + 'name', + paramNames[index] || options.paramName + ); }); } // Appending the file input fields to the hidden form @@ -144,22 +170,36 @@ }); // The iframe transport returns the iframe content document as response. - // The following adds converters from iframe to text, json, html, and script: + // The following adds converters from iframe to text, json, html, xml + // and script. + // Please note that the Content-Type for JSON responses has to be text/plain + // or text/html, if the browser doesn't include application/json in the + // Accept header, else IE will show a download dialog. + // The Content-Type for XML responses on the other hand has to be always + // application/xml or text/xml, so IE properly parses the XML response. + // See also + // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation $.ajaxSetup({ converters: { 'iframe text': function (iframe) { - return $(iframe[0].body).text(); + return iframe && $(iframe[0].body).text(); }, 'iframe json': function (iframe) { - return $.parseJSON($(iframe[0].body).text()); + return iframe && $.parseJSON($(iframe[0].body).text()); }, 'iframe html': function (iframe) { - return $(iframe[0].body).html(); + return iframe && $(iframe[0].body).html(); + }, + 'iframe xml': function (iframe) { + var xmlDoc = iframe && iframe[0]; + return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc : + $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) || + $(xmlDoc.body).html()); }, 'iframe script': function (iframe) { - return $.globalEval($(iframe[0].body).text()); + return iframe && $.globalEval($(iframe[0].body).text()); } } }); -})); +})); \ No newline at end of file diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 0c7d6936697..39f5ac471e5 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -1,7 +1,8 @@ +$totalsize = 0; +$pc = 0; ?> $relative_date_color = round((time()-$file['mtime'])/60/60/24*14); if($relative_date_color>160) $relative_date_color = 160; $name = \OCP\Util::encodePath($file['name']); - $directory = \OCP\Util::encodePath($file['directory']); ?> + $directory = \OCP\Util::encodePath($file['directory']); + ?> +
+ + )"> -- cgit v1.2.3 From 101cfa23590c3430b05debc60a2335ad597f7d23 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 22 Aug 2013 00:09:43 +0200 Subject: remove duplicate code --- apps/files/js/file-upload.js | 7 ++ apps/files/js/files.js | 198 ------------------------------------------- 2 files changed, 7 insertions(+), 198 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 49e464b810a..f262f11f065 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -205,6 +205,13 @@ $(document).ready(function() { } }); }); + $('#new').click(function(event){ + event.stopPropagation(); + }); + $('#new>a').click(function(){ + $('#new>ul').toggle(); + $('#new').toggleClass('active'); + }); $('#new li').click(function(){ if($(this).children('p').length==0){ return; diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 4eb949c2eef..87311237e36 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -265,204 +265,6 @@ $(document).ready(function() { e.preventDefault(); // prevent browser from doing anything, if file isn't dropped in dropZone }); - $.assocArraySize = function(obj) { - // http://stackoverflow.com/a/6700/11236 - var size = 0, key; - for (key in obj) { - if (obj.hasOwnProperty(key)) size++; - } - return size; - }; - - // warn user not to leave the page while upload is in progress - $(window).bind('beforeunload', function(e) { - if ($.assocArraySize(uploadingFiles) > 0) - return t('files','File upload is in progress. Leaving the page now will cancel the upload.'); - }); - - //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) - if(navigator.userAgent.search(/konqueror/i)==-1){ - $('#file_upload_start').attr('multiple','multiple') - } - - //if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder - var crumb=$('div.crumb').first(); - while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){ - crumb.children('a').text('...'); - crumb=crumb.next('div.crumb'); - } - //if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent - var crumb=$('div.crumb').first(); - var next=crumb.next('div.crumb'); - while($('div.controls').height()>40 && next.next('div.crumb').length>0){ - crumb.remove(); - crumb=next; - next=crumb.next('div.crumb'); - } - //still not enough, start shorting down the current folder name - var crumb=$('div.crumb>a').last(); - while($('div.controls').height()>40 && crumb.text().length>6){ - var text=crumb.text() - text=text.substr(0,text.length-6)+'...'; - crumb.text(text); - } - - $(document).click(function(){ - $('#new>ul').hide(); - $('#new').removeClass('active'); - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ - $(element).children('form').remove(); - $(element).append('

'+$(element).data('text')+'

'); - } - }); - }); - $('#new').click(function(event){ - event.stopPropagation(); - }); - $('#new>a').click(function(){ - $('#new>ul').toggle(); - $('#new').toggleClass('active'); - }); - $('#new li').click(function(){ - if($(this).children('p').length==0){ - return; - } - - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ - $(element).children('form').remove(); - $(element).append('

'+$(element).data('text')+'

'); - } - }); - - var type=$(this).data('type'); - var text=$(this).children('p').text(); - $(this).data('text',text); - $(this).children('p').remove(); - var form=$('
'); - var input=$(''); - form.append(input); - $(this).append(form); - input.focus(); - form.submit(function(event){ - event.stopPropagation(); - event.preventDefault(); - var newname=input.val(); - if(type == 'web' && newname.length == 0) { - OC.Notification.show(t('files', 'URL cannot be empty.')); - return false; - } else if (type != 'web' && !Files.isFileNameValid(newname)) { - return false; - } else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') { - OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by Owncloud')); - return false; - } - if (FileList.lastAction) { - FileList.lastAction(); - } - var name = getUniqueName(newname); - if (newname != name) { - FileList.checkName(name, newname, true); - var hidden = true; - } else { - var hidden = false; - } - switch(type){ - case 'file': - $.post( - OC.filePath('files','ajax','newfile.php'), - {dir:$('#dir').val(),filename:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - FileList.addFile(name,0,date,false,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.attr('data-mime',result.data.mime); - tr.attr('data-size',result.data.size); - tr.attr('data-id', result.data.id); - tr.find('.filesize').text(humanFileSize(result.data.size)); - getMimeIcon(result.data.mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); - }); - } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); - } - } - ); - break; - case 'folder': - $.post( - OC.filePath('files','ajax','newfolder.php'), - {dir:$('#dir').val(),foldername:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - FileList.addDir(name,0,date,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.attr('data-id', result.data.id); - } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); - } - } - ); - break; - case 'web': - if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){ - name='http://'+name; - } - var localName=name; - if(localName.substr(localName.length-1,1)=='/'){//strip / - localName=localName.substr(0,localName.length-1) - } - if(localName.indexOf('/')){//use last part of url - localName=localName.split('/').pop(); - }else{//or the domain - localName=(localName.match(/:\/\/(.[^/]+)/)[1]).replace('www.',''); - } - localName = getUniqueName(localName); - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - } else { - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); - } - - var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName}); - eventSource.listen('progress',function(progress){ - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - } else { - $('#uploadprogressbar').progressbar('value',progress); - } - }); - eventSource.listen('success',function(data){ - var mime=data.mime; - var size=data.size; - var id=data.id; - $('#uploadprogressbar').fadeOut(); - var date=new Date(); - FileList.addFile(localName,size,date,false,hidden); - var tr=$('tr').filterAttr('data-file',localName); - tr.data('mime',mime).data('id',id); - tr.attr('data-id', id); - getMimeIcon(mime,function(path){ - tr.find('td.filename').attr('style','background-image:url('+path+')'); - }); - }); - eventSource.listen('error',function(error){ - $('#uploadprogressbar').fadeOut(); - alert(error); - }); - break; - } - var li=form.parent(); - form.remove(); - li.append('

'+li.data('text')+'

'); - $('#new>a').click(); - }); - }); - //do a background scan if needed scanFiles(); -- cgit v1.2.3 From 13e34649bfb1a7d15833c209d629e3540d3366ef Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Fri, 23 Aug 2013 23:19:21 +0200 Subject: move path generation for previews to dedicated function --- apps/files/js/filelist.js | 2 +- apps/files/js/files.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 41245c00ba6..e3e985af38b 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -185,7 +185,7 @@ var FileList={ if (id != null) { tr.attr('data-id', id); } - var path = $('#dir').val()+'/'+name; + var path = getPathForPreview(name); lazyLoadPreview(path, mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index f88ecd961b1..79fa01aa0aa 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -382,7 +382,7 @@ $(document).ready(function() { tr.attr('data-size',result.data.size); tr.attr('data-id', result.data.id); tr.find('.filesize').text(humanFileSize(result.data.size)); - var path = $('#dir').val() + '/' + name; + var path = getPathForPreview(name); lazyLoadPreview(path, result.data.mime, function(previewpath){ tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); @@ -654,7 +654,7 @@ var createDragShadow = function(event){ if (elem.type === 'dir') { newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { - var path = $('#dir').val()+'/'+elem.name; + var path = getPathForPreview(elem.name); lazyLoadPreview(path, elem.mime, function(previewpath){ newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); @@ -832,6 +832,11 @@ function getMimeIcon(mime, ready){ } getMimeIcon.cache={}; +function getPathForPreview(name) { + var path = $('#dir').val() + '/' + name; + return path; +} + function lazyLoadPreview(path, mime, ready) { getMimeIcon(mime,ready); var x = $('#filestable').data('preview-x'); -- cgit v1.2.3 From 46cbd7cd3b37e073ebb497f34d54ab67e4761969 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 26 Aug 2013 12:16:51 +0200 Subject: fix preview issue when uploading a file with parentheses --- apps/files/js/files.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 79fa01aa0aa..a890da843bb 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -843,7 +843,9 @@ function lazyLoadPreview(path, mime, ready) { var y = $('#filestable').data('preview-y'); var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y}); $.get(previewURL, function() { - ready(previewURL); + previewURL = previewURL.replace('(','%28'); + previewURL = previewURL.replace(')','%29'); + ready(previewURL + '&reload=true'); }); } -- cgit v1.2.3 From bbf8acb383bdcb1dcb53f4b9d5a8d894b17401df Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 5 Sep 2013 10:19:54 +0200 Subject: separate uploading code from progress code, add progress capability detection --- apps/files/js/file-upload.js | 193 +++++++++++++++++++++++-------------------- apps/files/js/filelist.js | 20 ++--- apps/files/js/files.js | 32 +++---- core/js/oc-dialogs.js | 13 ++- 4 files changed, 136 insertions(+), 122 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index be3d7e08aff..bd0ae4db00b 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -14,6 +14,7 @@ * - when only existing -> remember as single skip action * - when only new -> remember as single replace action * - when both -> remember as single autorename action + * - continue -> apply marks, when nothing is marked continue == skip all * - start uploading selection * * on send @@ -96,7 +97,30 @@ * */ +// from https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html +// also see article at http://blog.new-bamboo.co.uk/2012/01/10/ridiculously-simple-ajax-uploads-with-formdata +// Function that will allow us to know if Ajax uploads are supported +function supportAjaxUploadWithProgress() { + return supportFileAPI() && supportAjaxUploadProgressEvents() && supportFormData(); + // Is the File API supported? + function supportFileAPI() { + var fi = document.createElement('INPUT'); + fi.type = 'file'; + return 'files' in fi; + }; + + // Are progress events supported? + function supportAjaxUploadProgressEvents() { + var xhr = new XMLHttpRequest(); + return !! (xhr && ('upload' in xhr) && ('onprogress' in xhr.upload)); + }; + + // Is FormData supported? + function supportFormData() { + return !! window.FormData; + } +} //TODO clean uploads when all progress has completed OC.Upload = { @@ -245,6 +269,7 @@ OC.Upload = { console.log(data); }, checkExistingFiles: function (selection, callbacks){ + // FIXME check filelist before uploading callbacks.onNoConflicts(selection); } }; @@ -327,7 +352,7 @@ $(document).ready(function() { return false; //don't upload anything } - // check existing files whan all is collected + // check existing files when all is collected if ( selection.uploads.length >= selection.filesToUpload ) { //remove our selection hack: @@ -358,11 +383,6 @@ $(document).ready(function() { OC.Upload.checkExistingFiles(selection, callbacks); - //TODO refactor away: - //show cancel button - if($('html.lte9').length === 0 && data.dataType !== 'iframe') { - $('#uploadprogresswrapper input.stop').show(); - } } @@ -389,13 +409,6 @@ $(document).ready(function() { */ start: function(e) { OC.Upload.logStatus('start', e, null); - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return true; - } - $('#uploadprogresswrapper input.stop').show(); - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); }, fail: function(e, data) { OC.Upload.logStatus('fail', e, data); @@ -414,32 +427,6 @@ $(document).ready(function() { } //var selection = OC.Upload.getSelection(data.originalFiles); //OC.Upload.deleteSelectionUpload(selection, data.files[0].name); - - //if user pressed cancel hide upload progress bar and cancel button - if (data.errorThrown === 'abort') { - $('#uploadprogresswrapper input.stop').fadeOut(); - $('#uploadprogressbar').fadeOut(); - } - }, - progress: function(e, data) { - OC.Upload.logStatus('progress', e, data); - // TODO: show nice progress bar in file row - }, - /** - * - * @param {type} e - * @param {type} data (only has loaded, total and lengthComputable) - * @returns {unresolved} - */ - progressall: function(e, data) { - OC.Upload.logStatus('progressall', e, data); - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } - var progress = (data.loaded/data.total)*100; - //var progress = OC.Upload.progressBytes(); - $('#uploadprogressbar').progressbar('value', progress); }, /** * called for every successful upload @@ -460,33 +447,21 @@ $(document).ready(function() { //var selection = OC.Upload.getSelection(data.originalFiles); if(typeof result[0] !== 'undefined' - && result[0].status === 'success' + && result[0].status === 'existserror' ) { - //if (selection) { - // selection.loadedBytes+=data.loaded; - //} - //OC.Upload.nextUpload(); + //show "file already exists" dialog + var original = result[0]; + var replacement = data.files[0]; + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + OC.dialogs.fileexists(data, original, replacement, OC.Upload, fu); } else { - if (result[0].status === 'existserror') { - //show "file already exists" dialog - var original = result[0]; - var replacement = data.files[0]; - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - OC.dialogs.fileexists(data, original, replacement, OC.Upload, fu); - } else { - OC.Upload.deleteSelectionUpload(selection, data.files[0].name); - data.textStatus = 'servererror'; - data.errorThrown = t('files', result.data.message); - var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); - fu._trigger('fail', e, data); - } + OC.Upload.deleteSelectionUpload(selection, data.files[0].name); + data.textStatus = 'servererror'; + data.errorThrown = t('files', result.data.message); + var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); + fu._trigger('fail', e, data); } - //if user pressed cancel hide upload chrome - //if (! OC.Upload.isProcessing()) { - // $('#uploadprogresswrapper input.stop').fadeOut(); - // $('#uploadprogressbar').fadeOut(); - //} }, /** @@ -496,36 +471,78 @@ $(document).ready(function() { */ stop: function(e, data) { OC.Upload.logStatus('stop', e, data); - //if(OC.Upload.progressBytes()>=100) { //only hide controls when all selections have ended uploading - - //OC.Upload.cancelUploads(); //cleanup - - // if(data.dataType !== 'iframe') { - // $('#uploadprogresswrapper input.stop').hide(); - // } - - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length > 0) { - return; - } - - // $('#uploadprogressbar').progressbar('value', 100); - // $('#uploadprogressbar').fadeOut(); - //} - //if user pressed cancel hide upload chrome - //if (! OC.Upload.isProcessing()) { - // $('#uploadprogresswrapper input.stop').fadeOut(); - // $('#uploadprogressbar').fadeOut(); - //} } }; - - var file_upload_handler = function() { - $('#file_upload_start').fileupload(file_upload_param); - }; if ( document.getElementById('data-upload-form') ) { - $(file_upload_handler); + // initialize jquery fileupload (blueimp) + var fileupload = $('#file_upload_start').fileupload(file_upload_param); + + if(supportAjaxUploadWithProgress()) { + + // add progress handlers + fileupload.on('fileuploadadd', function(e, data) { + OC.Upload.logStatus('progress handle fileuploadadd', e, data); + //show cancel button + //if(data.dataType !== 'iframe') { //FIXME when is iframe used? only for ie? + // $('#uploadprogresswrapper input.stop').show(); + //} + }); + // add progress handlers + fileupload.on('fileuploadstart', function(e, data) { + OC.Upload.logStatus('progress handle fileuploadstart', e, data); + $('#uploadprogresswrapper input.stop').show(); + $('#uploadprogressbar').progressbar({value:0}); + $('#uploadprogressbar').fadeIn(); + }); + fileupload.on('fileuploadprogress', function(e, data) { + OC.Upload.logStatus('progress handle fileuploadprogress', e, data); + //TODO progressbar in row + }); + fileupload.on('fileuploadprogressall', function(e, data) { + OC.Upload.logStatus('progress handle fileuploadprogressall', e, data); + var progress = (data.loaded / data.total) * 100; + $('#uploadprogressbar').progressbar('value', progress); + }); + fileupload.on('fileuploaddone', function(e, data) { + OC.Upload.logStatus('progress handle fileuploaddone', e, data); + //if user pressed cancel hide upload chrome + //if (! OC.Upload.isProcessing()) { + // $('#uploadprogresswrapper input.stop').fadeOut(); + // $('#uploadprogressbar').fadeOut(); + //} + }); + fileupload.on('fileuploadstop', function(e, data) { + OC.Upload.logStatus('progress handle fileuploadstop', e, data); + //if(OC.Upload.progressBytes()>=100) { //only hide controls when all selections have ended uploading + + //OC.Upload.cancelUploads(); //cleanup + + // if(data.dataType !== 'iframe') { + // $('#uploadprogresswrapper input.stop').hide(); + // } + + // $('#uploadprogressbar').progressbar('value', 100); + // $('#uploadprogressbar').fadeOut(); + //} + //if user pressed cancel hide upload chrome + //if (! OC.Upload.isProcessing()) { + // $('#uploadprogresswrapper input.stop').fadeOut(); + // $('#uploadprogressbar').fadeOut(); + //} + }); + fileupload.on('fileuploadfail', function(e, data) { + OC.Upload.logStatus('progress handle fileuploadfail', e, data); + //if user pressed cancel hide upload progress bar and cancel button + if (data.errorThrown === 'abort') { + $('#uploadprogresswrapper input.stop').fadeOut(); + $('#uploadprogressbar').fadeOut(); + } + }); + + } else { + console.log('skipping file progress because your browser is broken'); + } } $.assocArraySize = function(obj) { // http://stackoverflow.com/a/6700/11236 diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 31e2a8300e2..4f20d1940aa 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -517,7 +517,7 @@ $(document).ready(function(){ var file_upload_start = $('#file_upload_start'); file_upload_start.on('fileuploaddrop', function(e, data) { - OC.Upload.logStatus('fileuploaddrop', e, data); + OC.Upload.logStatus('filelist handle fileuploaddrop', e, data); var dropTarget = $(e.originalEvent.target).closest('tr'); if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder @@ -556,7 +556,7 @@ $(document).ready(function(){ }); file_upload_start.on('fileuploadadd', function(e, data) { - OC.Upload.logStatus('fileuploadadd', e, data); + OC.Upload.logStatus('filelist handle fileuploadadd', e, data); // lookup selection for dir var selection = OC.Upload.getSelection(data.originalFiles); @@ -592,10 +592,10 @@ $(document).ready(function(){ }); file_upload_start.on('fileuploadstart', function(e, data) { - OC.Upload.logStatus('fileuploadstart', e, data); + OC.Upload.logStatus('filelist handle fileuploadstart', e, data); }); file_upload_start.on('fileuploaddone', function(e, data) { - OC.Upload.logStatus('fileuploaddone', e, data); + OC.Upload.logStatus('filelist handle fileuploaddone', e, data); var response; if (typeof data.result === 'string') { @@ -672,22 +672,22 @@ $(document).ready(function(){ }); file_upload_start.on('fileuploadalways', function(e, data) { - OC.Upload.logStatus('fileuploadalways', e, data); + OC.Upload.logStatus('filelist handle fileuploadalways', e, data); }); file_upload_start.on('fileuploadsend', function(e, data) { - OC.Upload.logStatus('fileuploadsend', e, data); + OC.Upload.logStatus('filelist handle fileuploadsend', e, data); // TODOD add vis //data.context.element = }); file_upload_start.on('fileuploadprogress', function(e, data) { - OC.Upload.logStatus('fileuploadprogress', e, data); + OC.Upload.logStatus('filelist handle fileuploadprogress', e, data); }); file_upload_start.on('fileuploadprogressall', function(e, data) { - OC.Upload.logStatus('fileuploadprogressall', e, data); + OC.Upload.logStatus('filelist handle fileuploadprogressall', e, data); }); file_upload_start.on('fileuploadstop', function(e, data) { - OC.Upload.logStatus('fileuploadstop', e, data); + OC.Upload.logStatus('filelist handle fileuploadstop', e, data); //if user pressed cancel hide upload chrome if (! OC.Upload.isProcessing()) { @@ -700,7 +700,7 @@ $(document).ready(function(){ } }); file_upload_start.on('fileuploadfail', function(e, data) { - OC.Upload.logStatus('fileuploadfail', e, data); + OC.Upload.logStatus('filelist handle fileuploadfail', e, data); //if user pressed cancel hide upload chrome if (data.errorThrown === 'abort') { diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 9a725fc2077..4a6c9c78900 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -1,6 +1,6 @@ Files={ updateMaxUploadFilesize:function(response) { - if(response == undefined) { + if(response === undefined) { return; } if(response.data !== undefined && response.data.uploadMaxFilesize !== undefined) { @@ -9,7 +9,7 @@ Files={ $('#usedSpacePercent').val(response.data.usedSpacePercent); Files.displayStorageWarnings(); } - if(response[0] == undefined) { + if(response[0] === undefined) { return; } if(response[0].uploadMaxFilesize !== undefined) { @@ -25,7 +25,7 @@ Files={ OC.Notification.show(t('files', '\'.\' is an invalid file name.')); return false; } - if (name.length == 0) { + if (name.length === 0) { OC.Notification.show(t('files', 'File name cannot be empty.')); return false; } @@ -33,7 +33,7 @@ Files={ // check for invalid characters var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*']; for (var i = 0; i < invalid_characters.length; i++) { - if (name.indexOf(invalid_characters[i]) != -1) { + if (name.indexOf(invalid_characters[i]) !== -1) { OC.Notification.show(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.")); return false; } @@ -127,7 +127,7 @@ $(document).ready(function() { var rows = $(this).parent().parent().parent().children('tr'); for (var i = start; i < end; i++) { $(rows).each(function(index) { - if (index == i) { + if (index === i) { var checkbox = $(this).children().children('input:checkbox'); $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().addClass('selected'); @@ -145,7 +145,7 @@ $(document).ready(function() { $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().toggleClass('selected'); var selectedCount=$('td.filename input:checkbox:checked').length; - if (selectedCount == $('td.filename input:checkbox').length) { + if (selectedCount === $('td.filename input:checkbox').length) { $('#select_all').attr('checked', 'checked'); } } @@ -192,7 +192,7 @@ $(document).ready(function() { var rows = $(this).parent().parent().parent().children('tr'); for (var i = start; i < end; i++) { $(rows).each(function(index) { - if (index == i) { + if (index === i) { var checkbox = $(this).children().children('input:checkbox'); $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().addClass('selected'); @@ -205,7 +205,7 @@ $(document).ready(function() { if(!$(this).attr('checked')){ $('#select_all').attr('checked',false); }else{ - if(selectedCount==$('td.filename input:checkbox').length){ + if(selectedCount === $('td.filename input:checkbox').length){ $('#select_all').attr('checked',true); } } @@ -262,9 +262,9 @@ $(document).ready(function() { function resizeBreadcrumbs(firstRun) { var width = $(this).width(); - if (width != lastWidth) { + if (width !== lastWidth) { if ((width < lastWidth || firstRun) && width < breadcrumbsWidth) { - if (hiddenBreadcrumbs == 0) { + if (hiddenBreadcrumbs === 0) { breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth; $(breadcrumbs[1]).find('a').hide(); $(breadcrumbs[1]).append('...'); @@ -276,12 +276,12 @@ $(document).ready(function() { breadcrumbsWidth -= $(breadcrumbs[i]).get(0).offsetWidth; $(breadcrumbs[i]).hide(); hiddenBreadcrumbs = i; - i++ + i++; } } else if (width > lastWidth && hiddenBreadcrumbs > 0) { var i = hiddenBreadcrumbs; while (width > breadcrumbsWidth && i > 0) { - if (hiddenBreadcrumbs == 1) { + if (hiddenBreadcrumbs === 1) { breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth; $(breadcrumbs[1]).find('span').remove(); $(breadcrumbs[1]).find('a').show(); @@ -382,7 +382,7 @@ scanFiles.scanning=false; function boolOperationFinished(data, callback) { result = jQuery.parseJSON(data.responseText); Files.updateMaxUploadFilesize(result); - if(result.status == 'success'){ + if(result.status === 'success'){ callback.call(); } else { alert(result.data.message); @@ -436,7 +436,7 @@ var createDragShadow = function(event){ }); return dragshadow; -} +}; //options for file drag/drop var dragOptions={ @@ -446,7 +446,7 @@ var dragOptions={ stop: function(event, ui) { $('#fileList tr td.filename').addClass('ui-draggable'); } -} +}; // sane browsers support using the distance option if ( $('html.ie').length === 0) { dragOptions['distance'] = 20; @@ -489,7 +489,7 @@ var folderDropOptions={ }); }, tolerance: 'pointer' -} +}; var crumbDropOptions={ drop: function( event, ui ) { diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 5ed24417264..08afbfd42f2 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -257,13 +257,7 @@ var OCdialogs = { //TODO add to same size collection? } - //add checkbox toggling actions - conflict.find('.replacement,.original').on('click', function(){ - var checkbox = $(this).find('input[type="checkbox"]'); - checkbox.prop('checkbox', !checkbox.prop('checkbox')); - }).find('input[type="checkbox"]').prop('checkbox',false); - - //TODO show skip action for files with same size and mtime + //TODO show skip action for files with same size and mtime in bottom row }; var selection = controller.getSelection(data.originalFiles); @@ -345,11 +339,14 @@ var OCdialogs = { var checkboxes = $(dialog_id).find('.conflict:not(.template) .original input[type="checkbox"]'); checkboxes.prop('checked', $(this).prop('checked')); }); - $(dialog_id).find('.conflicts').on('click', '.replacement,.original', function() { var checkbox = $(this).find('input[type="checkbox"]'); checkbox.prop('checked', !checkbox.prop('checked')); }); + $(dialog_id).find('.conflicts').on('click', 'input[type="checkbox"]', function() { + var checkbox = $(this); + checkbox.prop('checked', !checkbox.prop('checked')); + }); //update counters $(dialog_id).on('click', '.replacement,.allnewfiles', function() { -- cgit v1.2.3 From fb462e83ccde5c46565c23545c5eb894acbd6fd3 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 6 Sep 2013 12:27:40 +0200 Subject: no longer enforce log out, but provide useful errors/warnings instead --- apps/files/index.php | 7 +++++- apps/files/js/files.js | 9 ++++++++ apps/files/templates/index.php | 1 + .../ajax/updatePrivateKeyPassword.php | 1 + apps/files_encryption/appinfo/app.php | 17 -------------- apps/files_encryption/hooks/hooks.php | 2 +- apps/files_encryption/lib/helper.php | 27 ++++++---------------- apps/files_encryption/lib/session.php | 15 ++++++++---- apps/files_encryption/lib/stream.php | 2 +- apps/files_encryption/lib/util.php | 3 ++- .../templates/invalid_private_key.php | 6 +++-- 11 files changed, 42 insertions(+), 48 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/index.php b/apps/files/index.php index f1e120c872c..b81ba2bdde9 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -124,8 +124,12 @@ if ($needUpgrade) { $storageInfo=OC_Helper::getStorageInfo($dir); $maxUploadFilesize=OCP\Util::maxUploadFilesize($dir); $publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes'); + // if the encryption app is disabled, than everything is fine + $encryptionInitStatus = \OCA\Encryption\Session::INIT_SUCCESSFUL; if (OC_App::isEnabled('files_encryption')) { $publicUploadEnabled = 'no'; + $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); + $encryptionInitStatus = $session->getInitialized(); } $trashEnabled = \OCP\App::isEnabled('files_trashbin'); @@ -133,7 +137,7 @@ if ($needUpgrade) { if ($trashEnabled) { $trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user); } - + OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); OCP\Util::addscript('files', 'keyboardshortcuts'); @@ -153,5 +157,6 @@ if ($needUpgrade) { $tmpl->assign('isPublic', false); $tmpl->assign('publicUploadEnabled', $publicUploadEnabled); $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles()); + $tmpl->assign("encryptionInitStatus", $encryptionInitStatus); $tmpl->printPage(); } diff --git a/apps/files/js/files.js b/apps/files/js/files.js index d729077ea72..63c3544b53d 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -90,6 +90,15 @@ Files={ } var encryptedFiles = $('#encryptedFiles').val(); + var initStatus = $('#encryptionInitStatus').val(); + if (initStatus === '0') { // enc not initialized, but should be + OC.Notification.show(t('files_encryption', 'Encryption App is enabled but your keys are not initialized, please log-out and log-in again')); + return; + } + if (initStatus === '1') { // encryption tried to init but failed + OC.Notification.show(t('files_encryption', 'Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.')); + return; + } if (encryptedFiles === '1') { OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.')); return; diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 24cb8c2fe58..e17273e47b1 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -123,3 +123,4 @@ + \ No newline at end of file diff --git a/apps/files_encryption/ajax/updatePrivateKeyPassword.php b/apps/files_encryption/ajax/updatePrivateKeyPassword.php index 1e6644da576..29c72952ae9 100644 --- a/apps/files_encryption/ajax/updatePrivateKeyPassword.php +++ b/apps/files_encryption/ajax/updatePrivateKeyPassword.php @@ -48,6 +48,7 @@ if ($decryptedKey) { // success or failure if ($return) { + $session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL); \OCP\JSON::success(array('data' => array('message' => $l->t('Private key password successfully updated.')))); } else { \OCP\JSON::error(array('data' => array('message' => $l->t('Could not update the private key password. Maybe the old password was not correct.')))); diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 90a9984e27f..cd26cd10cd9 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -41,23 +41,6 @@ if (!OC_Config::getValue('maintenance', false)) { if($sessionReady) { $session = new \OCA\Encryption\Session($view); } - - $user = \OCP\USER::getUser(); - // check if user has a private key - if ($sessionReady === false - || (!$view->file_exists('/' . $user . '/files_encryption/' . $user . '.private.key') - && OCA\Encryption\Crypt::mode() === 'server') - ) { - - // Force the user to log-in again if the encryption key isn't unlocked - // (happens when a user is logged in before the encryption app is - // enabled) - OCP\User::logout(); - - header("Location: " . OC::$WEBROOT . '/'); - - exit(); - } } } else { // logout user if we are in maintenance to force re-login diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 4c6122b7c2b..c945deeea0c 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -547,7 +547,7 @@ class Hooks { $setMigrationStatus->execute(); $session = new \OCA\Encryption\Session(new \OC\Files\View('/')); - $session->setInitialized(false); + $session->setInitialized(\OCA\Encryption\Session::NOT_INITIALIZED); } } diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php index 7d466b88523..048473ce846 100755 --- a/apps/files_encryption/lib/helper.php +++ b/apps/files_encryption/lib/helper.php @@ -237,28 +237,15 @@ class Helper { */ public static function redirectToErrorPage($session) { - $l = \OC_L10N::get('files_encryption'); - - if ($session->getInitialized() === false) { - $errorMsg = $l->t('Encryption app not initialized! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app.'); - } else { - $errorMsg = $l->t('Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.'); - } + $init = $session->getInitialized(); + $location = \OC_Helper::linkToAbsolute('apps/files_encryption/files', 'error.php'); + $post = 0; if(count($_POST) > 0) { - header('HTTP/1.0 404 ' . $errorMsg); - } - - // check if ajax request - if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { - \OCP\JSON::error(array('data' => array('message' => $errorMsg))); - } else { - header('HTTP/1.0 404 ' . $errorMsg); - $tmpl = new OC_Template('files_encryption', 'invalid_private_key', 'guest'); - $tmpl->printPage(); - } - - exit; + $post = 1; + } + header('Location: ' . $location . '?p=' . $post . '&i=' . $init); + exit(); } /** diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index 648e6e9ab07..25f2198181f 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -30,6 +30,11 @@ class Session { private $view; + const NOT_INITIALIZED = '0'; + const INIT_EXECUTED = '1'; + const INIT_SUCCESSFUL = '2'; + + /** * @brief if session is started, check if ownCloud key pair is set up, if not create it * @param \OC_FilesystemView $view @@ -113,10 +118,10 @@ class Session { } /** - * @brief Sets status if we tried to initialize the encyption app - * @param bool $privateKey true=initialized false=not initialized + * @brief Sets status of encryption app + * @param string $init INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INOITIALIZED * @return bool - * + * * @note this doesn not indicate of the init was successful, we just remeber the try! */ public function setInitialized($init) { @@ -130,7 +135,7 @@ class Session { /** * @brief Gets status if we already tried to initialize the encryption app - * @returns bool + * @returns init status INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INOITIALIZED * * @note this doesn not indicate of the init was successful, we just remeber the try! */ @@ -138,7 +143,7 @@ class Session { if (!is_null(\OC::$session->get('encryptionInitialized'))) { return \OC::$session->get('encryptionInitialized'); } else { - return false; + return self::NOT_INITIALIZED; } } diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 9215352aa78..c6db10ce40d 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -128,7 +128,7 @@ class Stream { $this->unencryptedSize = 0; } else { - +\OCA\Encryption\Helper::redirectToErrorPage($this->session); if($this->privateKey === false) { // if private key is not valid redirect user to a error page \OCA\Encryption\Helper::redirectToErrorPage($this->session); diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 17096a787f2..7a19f954643 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1724,7 +1724,7 @@ class Util { $session = new \OCA\Encryption\Session($this->view); // we tried to initialize the encryption app for this session - $session->setInitialized(true); + $session->setInitialized(\OCA\Encryption\Session::INIT_EXECUTED); $encryptedKey = Keymanager::getPrivateKey($this->view, $params['uid']); @@ -1737,6 +1737,7 @@ class Util { } $session->setPrivateKey($privateKey); + $session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL); return $session; } diff --git a/apps/files_encryption/templates/invalid_private_key.php b/apps/files_encryption/templates/invalid_private_key.php index 5c086d6514c..9af65f831b4 100644 --- a/apps/files_encryption/templates/invalid_private_key.php +++ b/apps/files_encryption/templates/invalid_private_key.php @@ -2,9 +2,11 @@
  • - t('Your private key is not valid! Maybe the your password was changed from outside.')); ?> +
    - t('You can unlock your private key in your ')); ?> t('personal settings')); ?>. + + p($l->t('Go directly to your ')); ?> t('personal settings')); ?>. +
  • -- cgit v1.2.3 From 1304b511e9533dee4cf1125e625568c8a74719a1 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Sat, 17 Aug 2013 13:07:18 +0200 Subject: Ajax calls for "files" and "files_trashbin" apps Frontend: - The files app list now uses ajax calls to refresh the list. - Added support the browser back button (history API). - Added mask + spinner while loading file list Backend: - Added utility function in core JS for parsing query strings. - Moved file list + breadcrumb template data code to helper functions - Fixed some file paths in trashbin app to be similar to the files app --- apps/files/ajax/list.php | 38 +++--- apps/files/css/files.css | 22 ++++ apps/files/index.php | 42 +------ apps/files/js/fileactions.js | 5 +- apps/files/js/filelist.js | 137 ++++++++++++++++++++-- apps/files/js/files.js | 48 +++++--- apps/files/lib/helper.php | 65 ++++++++++ apps/files/templates/index.php | 10 +- apps/files/templates/part.list.php | 4 +- apps/files_sharing/js/share.js | 2 +- apps/files_sharing/public.php | 2 +- apps/files_trashbin/ajax/list.php | 51 ++++++++ apps/files_trashbin/index.php | 91 ++------------ apps/files_trashbin/js/filelist.js | 29 +++++ apps/files_trashbin/js/trash.js | 14 ++- apps/files_trashbin/lib/helper.php | 97 +++++++++++++++ apps/files_trashbin/templates/index.php | 3 + apps/files_trashbin/templates/part.breadcrumb.php | 4 +- apps/files_trashbin/templates/part.list.php | 3 +- core/js/js.js | 32 +++++ 20 files changed, 518 insertions(+), 181 deletions(-) create mode 100644 apps/files_trashbin/ajax/list.php create mode 100644 apps/files_trashbin/js/filelist.js create mode 100644 apps/files_trashbin/lib/helper.php (limited to 'apps/files/js/files.js') diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php index 14ed43cbb3a..035ffc0e393 100644 --- a/apps/files/ajax/list.php +++ b/apps/files/ajax/list.php @@ -10,36 +10,34 @@ OCP\JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; + +if (!\OC\Files\Filesystem::is_dir($dir . '/')) { + header("HTTP/1.0 404 Not Found"); + exit(); +} + $doBreadcrumb = isset($_GET['breadcrumb']); $data = array(); +$baseUrl = OCP\Util::linkTo('files', 'index.php') . '?dir='; // Make breadcrumb if($doBreadcrumb) { - $breadcrumb = array(); - $pathtohere = "/"; - foreach( explode( "/", $dir ) as $i ) { - if( $i != "" ) { - $pathtohere .= "$i/"; - $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i ); - } - } - - $breadcrumbNav = new OCP\Template( "files", "part.breadcrumb", "" ); - $breadcrumbNav->assign( "breadcrumb", $breadcrumb, false ); + $breadcrumb = \OCA\files\lib\Helper::makeBreadcrumb($dir); + + $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); + $breadcrumbNav->assign('breadcrumb', $breadcrumb, false); + $breadcrumbNav->assign('baseURL', $baseUrl); $data['breadcrumb'] = $breadcrumbNav->fetchPage(); } // make filelist -$files = array(); -foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) { - $i["date"] = OCP\Util::formatDate($i["mtime"] ); - $i['icon'] = \OCA\files\lib\Helper::determineIcon($i); - $files[] = $i; -} +$files = \OCA\files\lib\Helper::getFiles($dir); -$list = new OCP\Template( "files", "part.list", "" ); -$list->assign( "files", $files, false ); -$data = array('files' => $list->fetchPage()); +$list = new OCP\Template("files", "part.list", ""); +$list->assign('files', $files, false); +$list->assign('baseURL', $baseUrl, false); +$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/'))); +$data['files'] = $list->fetchPage(); OCP\JSON::success(array('data' => $data)); diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 8053649bd55..f506a379477 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -336,3 +336,25 @@ table.dragshadow td.size { text-align: center; margin-left: -200px; } +.mask { + z-index: 50; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: white; + background-repeat: no-repeat no-repeat; + background-position: 50%; + opacity: 0.7; + filter: alpha(opacity=70); + transition: opacity 100ms; + -moz-transition: opacity 100ms; + -o-transition: opacity 100ms; + -ms-transition: opacity 100ms; + -webkit-transition: opacity 100ms; +} +.mask.transparent{ + opacity: 0; +} + diff --git a/apps/files/index.php b/apps/files/index.php index 4443bf5fde0..ec824f895b6 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -41,62 +41,25 @@ if (!\OC\Files\Filesystem::is_dir($dir . '/')) { exit(); } -function fileCmp($a, $b) { - if ($a['type'] == 'dir' and $b['type'] != 'dir') { - return -1; - } elseif ($a['type'] != 'dir' and $b['type'] == 'dir') { - return 1; - } else { - return strnatcasecmp($a['name'], $b['name']); - } -} - $files = array(); $user = OC_User::getUser(); if (\OC\Files\Cache\Upgrade::needUpgrade($user)) { //dont load anything if we need to upgrade the cache - $content = array(); $needUpgrade = true; $freeSpace = 0; } else { - $content = \OC\Files\Filesystem::getDirectoryContent($dir); + $files = \OCA\files\lib\Helper::getFiles($dir); $freeSpace = \OC\Files\Filesystem::free_space($dir); $needUpgrade = false; } -foreach ($content as $i) { - $i['date'] = OCP\Util::formatDate($i['mtime']); - if ($i['type'] == 'file') { - $fileinfo = pathinfo($i['name']); - $i['basename'] = $fileinfo['filename']; - if (!empty($fileinfo['extension'])) { - $i['extension'] = '.' . $fileinfo['extension']; - } else { - $i['extension'] = ''; - } - } - $i['directory'] = $dir; - $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($i['mimetype']); - $i['icon'] = \OCA\files\lib\Helper::determineIcon($i); - $files[] = $i; -} - -usort($files, "fileCmp"); // Make breadcrumb -$breadcrumb = array(); -$pathtohere = ''; -foreach (explode('/', $dir) as $i) { - if ($i != '') { - $pathtohere .= '/' . $i; - $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i); - } -} +$breadcrumb = \OCA\files\lib\Helper::makeBreadcrumb($dir); // make breadcrumb und filelist markup $list = new OCP\Template('files', 'part.list', ''); $list->assign('files', $files); $list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '?dir='); $list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/'))); -$list->assign('disableSharing', false); $list->assign('isPublic', false); $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); $breadcrumbNav->assign('breadcrumb', $breadcrumb); @@ -154,5 +117,6 @@ if ($needUpgrade) { $tmpl->assign('isPublic', false); $tmpl->assign('publicUploadEnabled', $publicUploadEnabled); $tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles()); + $tmpl->assign('disableSharing', false); $tmpl->printPage(); } diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index 097fe521aa6..330fe86f6b3 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -196,13 +196,12 @@ FileActions.register('all', 'Rename', OC.PERMISSION_UPDATE, function () { FileList.rename(filename); }); - FileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename) { - var dir = $('#dir').val(); + var dir = $('#dir').val() || '/'; if (dir !== '/') { dir = dir + '/'; } - window.location = OC.linkTo('files', 'index.php') + '?dir=' + encodeURIComponent(dir + filename); + FileList.changeDirectory(dir + filename); }); FileActions.setDefault('dir', 'Open'); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 29be5e0d362..c205ae32aa9 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1,7 +1,25 @@ var FileList={ useUndo:true, + postProcessList: function(){ + $('#fileList tr').each(function(){ + //little hack to set unescape filenames in attribute + $(this).attr('data-file',decodeURIComponent($(this).attr('data-file'))); + }); + }, update:function(fileListHtml) { - $('#fileList').empty().html(fileListHtml); + var $fileList = $('#fileList'); + $fileList.empty().html(fileListHtml); + $('#emptycontent').toggleClass('hidden', $fileList.find('tr').length > 0); + $fileList.find('tr').each(function () { + FileActions.display($(this).children('td.filename')); + }); + $fileList.trigger(jQuery.Event("fileActionsReady")); + FileList.postProcessList(); + // "Files" might not be loaded in extending apps + if (window.Files){ + Files.setupDragAndDrop(); + } + $fileList.trigger(jQuery.Event("updated")); }, createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions){ var td, simpleSize, basename, extension; @@ -134,20 +152,83 @@ var FileList={ FileActions.display(tr.find('td.filename')); return tr; }, - refresh:function(data) { - var result = jQuery.parseJSON(data.responseText); + /** + * @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) + */ + changeDirectory: function(targetDir, changeUrl){ + var $dir = $('#dir'), + url, + currentDir = $dir.val() || '/'; + targetDir = targetDir || '/'; + if (currentDir === targetDir){ + return; + } + FileList.setCurrentDir(targetDir, changeUrl); + FileList.reload(); + }, + setCurrentDir: function(targetDir, changeUrl){ + $('#dir').val(targetDir); + // Note: IE8 handling ignored for now + if (window.history.pushState && changeUrl !== false){ + url = OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(targetDir).replace(/%2F/g, '/'), + window.history.pushState({dir: targetDir}, '', url); + } + }, + /** + * @brief Reloads the file list using ajax call + */ + reload: function(){ + FileList.showMask(); + if (FileList._reloadCall){ + FileList._reloadCall.abort(); + } + FileList._reloadCall = $.ajax({ + url: OC.filePath('files','ajax','list.php'), + data: { + dir : $('#dir').val(), + breadcrumb: true + }, + error: function(result){ + FileList.reloadCallback(result); + }, + success: function(result) { + FileList.reloadCallback(result); + } + }); + }, + reloadCallback: function(result){ + var $controls = $('#controls'); + + delete FileList._reloadCall; + FileList.hideMask(); + + if (!result || result.status === 'error') { + OC.Notification.show(result.data.message); + return; + } + + if (result.status === 404){ + // go back home + FileList.changeDirectory('/'); + return; + } + if(typeof(result.data.breadcrumb) != 'undefined'){ - updateBreadcrumb(result.data.breadcrumb); + $controls.find('.crumb').remove(); + $controls.prepend(result.data.breadcrumb); + // TODO: might need refactor breadcrumb code into a new file + //resizeBreadcrumbs(true); } FileList.update(result.data.files); - resetFileActionPanel(); }, remove:function(name){ $('tr').filterAttr('data-file',name).find('td.filename').draggable('destroy'); $('tr').filterAttr('data-file',name).remove(); FileList.updateFileSummary(); if($('tr[data-file]').length==0){ - $('#emptycontent').show(); + $('#emptycontent').removeClass('hidden'); } }, insertElement:function(name,type,element){ @@ -177,7 +258,7 @@ var FileList={ }else{ $('#fileList').append(element); } - $('#emptycontent').hide(); + $('#emptycontent').addClass('hidden'); FileList.updateFileSummary(); }, loadingDone:function(name, id){ @@ -508,6 +589,30 @@ var FileList={ $connector.show(); } } + }, + showMask: function(){ + // in case one was shown before + var $mask = $('#content .mask'); + if ($mask.length){ + return; + } + + $mask = $('
    '); + + $mask.css('background-image', 'url('+ OC.imagePath('core', 'loading.gif') + ')'); + $('#content').append($mask); + + // block UI, but only make visible in case loading takes longer + FileList._maskTimeout = window.setTimeout(function(){ + // reset opacity + $mask.removeClass('transparent'); + }, 250); + }, + hideMask: function(){ + var $mask = $('#content .mask').remove(); + if (FileList._maskTimeout){ + window.clearTimeout(FileList._maskTimeout); + } } }; @@ -629,8 +734,8 @@ $(document).ready(function(){ } // update folder size - var size = parseInt(data.context.data('size')); - size += parseInt(file.size) ; + var size = parseInt(data.context.data('size')); + size += parseInt(file.size); data.context.attr('data-size', size); data.context.find('td.filesize').text(humanFileSize(size)); @@ -710,5 +815,19 @@ $(document).ready(function(){ $(window).trigger('beforeunload'); }); + window.onpopstate = function(e){ + var targetDir; + if (e.state && e.state.dir){ + targetDir = e.state.dir; + } + else{ + // read from URL + targetDir = (OC.parseQueryString(location.search) || {dir: '/'}).dir || '/'; + } + if (targetDir){ + FileList.changeDirectory(targetDir, false); + } + } + FileList.createFileSummary(); }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index d729077ea72..ce72c7bcb5a 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -94,29 +94,34 @@ Files={ OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.')); return; } + }, + + setupDragAndDrop: function(){ + var $fileList = $('#fileList'); + + //drag/drop of files + $fileList.find('tr td.filename').each(function(i,e){ + if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) { + $(e).draggable(dragOptions); + } + }); + + $fileList.find('tr[data-type="dir"] td.filename').each(function(i,e){ + if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){ + $(e).droppable(folderDropOptions); + } + }); } }; $(document).ready(function() { Files.displayEncryptionWarning(); Files.bindKeyboardShortcuts(document, jQuery); - $('#fileList tr').each(function(){ - //little hack to set unescape filenames in attribute - $(this).attr('data-file',decodeURIComponent($(this).attr('data-file'))); - }); + + FileList.postProcessList(); + Files.setupDragAndDrop(); $('#file_action_panel').attr('activeAction', false); - //drag/drop of files - $('#fileList tr td.filename').each(function(i,e){ - if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) { - $(e).draggable(dragOptions); - } - }); - $('#fileList tr[data-type="dir"] td.filename').each(function(i,e){ - if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){ - $(e).droppable(folderDropOptions); - } - }); $('div.crumb:not(.last)').droppable(crumbDropOptions); $('ul#apps>li:first-child').data('dir',''); if($('div.crumb').length){ @@ -335,6 +340,9 @@ $(document).ready(function() { resizeBreadcrumbs(true); + // event handlers for breadcrumb items + $('#controls').delegate('.crumb a', 'click', onClickBreadcrumb); + // display storage warnings setTimeout ( "Files.displayStorageWarnings()", 100 ); OC.Notification.setDefault(Files.displayStorageWarnings); @@ -415,10 +423,6 @@ function boolOperationFinished(data, callback) { } } -function updateBreadcrumb(breadcrumbHtml) { - $('p.nav').empty().html(breadcrumbHtml); -} - var createDragShadow = function(event){ //select dragged file var isDragSelected = $(event.target).parents('tr').find('td input:first').prop('checked'); @@ -681,3 +685,9 @@ function checkTrashStatus() { } }); } + +function onClickBreadcrumb(e){ + var $el = $(e.target).closest('.crumb'); + e.preventDefault(); + FileList.changeDirectory(decodeURIComponent($el.data('dir'))); +} diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index 9170c6e3fc0..282f0678a9a 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -45,5 +45,70 @@ class Helper return \OC_Helper::mimetypeIcon($file['mimetype']); } + /** + * Comparator function to sort files alphabetically and have + * the directories appear first + * @param array $a file + * @param array $b file + * @return -1 if $a must come before $b, 1 otherwise + */ + public static function fileCmp($a, $b) { + if ($a['type'] === 'dir' and $b['type'] !== 'dir') { + return -1; + } elseif ($a['type'] !== 'dir' and $b['type'] === 'dir') { + return 1; + } else { + return strnatcasecmp($a['name'], $b['name']); + } + } + + /** + * Retrieves the contents of the given directory and + * returns it as a sorted array. + * @param string $dir path to the directory + * @return array of files + */ + public static function getFiles($dir) { + $content = \OC\Files\Filesystem::getDirectoryContent($dir); + $files = array(); + + foreach ($content as $i) { + $i['date'] = \OCP\Util::formatDate($i['mtime']); + if ($i['type'] === 'file') { + $fileinfo = pathinfo($i['name']); + $i['basename'] = $fileinfo['filename']; + if (!empty($fileinfo['extension'])) { + $i['extension'] = '.' . $fileinfo['extension']; + } else { + $i['extension'] = ''; + } + } + $i['directory'] = $dir; + $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($i['mimetype']); + $i['icon'] = \OCA\files\lib\Helper::determineIcon($i); + $files[] = $i; + } + usort($files, array('\OCA\files\lib\Helper', 'fileCmp')); + + return $files; + } + + /** + * Splits the given path into a breadcrumb structure. + * @param string $dir path to process + * @return array where each entry is a hash of the absolute + * directory path and its name + */ + public static function makeBreadcrumb($dir){ + $breadcrumb = array(); + $pathtohere = ''; + foreach (explode('/', $dir) as $i) { + if ($i !== '') { + $pathtohere .= '/' . $i; + $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i); + } + } + return $breadcrumb; + } } diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 29cb457cd5a..85e21380c6d 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -2,7 +2,7 @@
    -
    +
    t('New'));?>
      @@ -55,9 +55,9 @@
    - -
    t('Nothing in here. Upload something!'))?>
    - +
    0):?>class="hidden">t('Nothing in here. Upload something!'))?>
    + + @@ -82,7 +82,7 @@ ').attr({ @@ -45,7 +45,7 @@ var FileList={ "href": linktarget }); //split extension from filename for non dirs - if (type != 'dir' && name.indexOf('.')!=-1) { + if (type !== 'dir' && name.indexOf('.') !== -1) { basename=name.substr(0,name.lastIndexOf('.')); extension=name.substr(name.lastIndexOf('.')); } else { @@ -54,11 +54,11 @@ var FileList={ } var name_span=$('').addClass('nametext').text(basename); link_elem.append(name_span); - if(extension){ + if (extension) { name_span.append($('').addClass('extension').text(extension)); } //dirs can show the number of uploaded files - if (type == 'dir') { + if (type === 'dir') { link_elem.append($('').attr({ 'class': 'uploadtext', 'currentUploads': 0 @@ -68,9 +68,9 @@ var FileList={ tr.append(td); //size column - if(size!=t('files', 'Pending')){ + if (size !== t('files', 'Pending')) { simpleSize = humanFileSize(size); - }else{ + } else { simpleSize=t('files', 'Pending'); } var sizeColor = Math.round(160-Math.pow((size/(1024*1024)),2)); @@ -92,7 +92,7 @@ var FileList={ tr.append(td); return tr; }, - addFile:function(name,size,lastModified,loading,hidden,param){ + addFile:function(name, size, lastModified, loading, hidden, param) { var imgurl; if (!param) { @@ -122,9 +122,9 @@ var FileList={ ); FileList.insertElement(name, 'file', tr); - if(loading){ - tr.data('loading',true); - }else{ + if (loading) { + tr.data('loading', true); + } else { tr.find('td.filename').draggable(dragOptions); } if (hidden) { @@ -132,7 +132,7 @@ var FileList={ } return tr; }, - addDir:function(name,size,lastModified,hidden){ + addDir:function(name, size, lastModified, hidden) { var tr = this.createRow( 'dir', @@ -144,7 +144,7 @@ var FileList={ $('#permissions').val() ); - FileList.insertElement(name,'dir',tr); + FileList.insertElement(name, 'dir', tr); var td = tr.find('td.filename'); td.draggable(dragOptions); td.droppable(folderDropOptions); @@ -158,25 +158,26 @@ var FileList={ * @brief Changes the current directory and reload the file list. * @param targetDir target directory (non URL encoded) * @param changeUrl false if the URL must not be changed (defaults to true) + * @param {boolean} force set to true to force changing directory */ - changeDirectory: function(targetDir, changeUrl, force){ + changeDirectory: function(targetDir, changeUrl, force) { var $dir = $('#dir'), url, currentDir = $dir.val() || '/'; targetDir = targetDir || '/'; - if (!force && currentDir === targetDir){ + if (!force && currentDir === targetDir) { return; } FileList.setCurrentDir(targetDir, changeUrl); FileList.reload(); }, - linkTo: function(dir){ + linkTo: function(dir) { return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/'); }, - setCurrentDir: function(targetDir, changeUrl){ + setCurrentDir: function(targetDir, changeUrl) { $('#dir').val(targetDir); - if (changeUrl !== false){ - if (window.history.pushState && changeUrl !== false){ + if (changeUrl !== false) { + if (window.history.pushState && changeUrl !== false) { url = FileList.linkTo(targetDir); window.history.pushState({dir: targetDir}, '', url); } @@ -189,9 +190,9 @@ var FileList={ /** * @brief Reloads the file list using ajax call */ - reload: function(){ + reload: function() { FileList.showMask(); - if (FileList._reloadCall){ + if (FileList._reloadCall) { FileList._reloadCall.abort(); } FileList._reloadCall = $.ajax({ @@ -200,7 +201,7 @@ var FileList={ dir : $('#dir').val(), breadcrumb: true }, - error: function(result){ + error: function(result) { FileList.reloadCallback(result); }, success: function(result) { @@ -208,7 +209,7 @@ var FileList={ } }); }, - reloadCallback: function(result){ + reloadCallback: function(result) { var $controls = $('#controls'); delete FileList._reloadCall; @@ -219,17 +220,17 @@ var FileList={ return; } - if (result.status === 404){ + if (result.status === 404) { // go back home FileList.changeDirectory('/'); return; } - if (result.data.permissions){ + if (result.data.permissions) { FileList.setDirectoryPermissions(result.data.permissions); } - if(typeof(result.data.breadcrumb) != 'undefined'){ + if (typeof(result.data.breadcrumb) !== 'undefined') { $controls.find('.crumb').remove(); $controls.prepend(result.data.breadcrumb); @@ -238,81 +239,83 @@ var FileList={ Files.resizeBreadcrumbs(width, true); // in case svg is not supported by the browser we need to execute the fallback mechanism - if(!SVGSupport()) { + if (!SVGSupport()) { replaceSVG(); } } FileList.update(result.data.files); }, - setDirectoryPermissions: function(permissions){ + setDirectoryPermissions: function(permissions) { var isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0; $('#permissions').val(permissions); $('.creatable').toggleClass('hidden', !isCreatable); $('.notCreatable').toggleClass('hidden', isCreatable); }, - remove:function(name){ - $('tr').filterAttr('data-file',name).find('td.filename').draggable('destroy'); - $('tr').filterAttr('data-file',name).remove(); + remove:function(name) { + $('tr[data-file="'+name+'"]').find('td.filename').draggable('destroy'); + $('tr[data-file="'+name+'"]').remove(); FileList.updateFileSummary(); - if($('tr[data-file]').length==0){ + if ( ! $('tr[data-file]').exists() ) { $('#emptycontent').removeClass('hidden'); } }, - insertElement:function(name,type,element){ + insertElement:function(name, type, element) { //find the correct spot to insert the file or folder var pos, fileElements=$('tr[data-file][data-type="'+type+'"]:visible'); - if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){ - pos=-1; - }else if(name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file'))>0){ - pos=fileElements.length-1; - }else{ - for(pos=0;pos0 && name.localeCompare($(fileElements[pos+1]).attr('data-file'))<0){ + if (name.localeCompare($(fileElements[0]).attr('data-file')) < 0) { + pos = -1; + } else if (name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file')) > 0) { + pos = fileElements.length - 1; + } else { + for(pos = 0; pos 0 + && name.localeCompare($(fileElements[pos+1]).attr('data-file')) < 0) + { break; } } } - if(fileElements.length){ - if(pos==-1){ + if (fileElements.exists()) { + if (pos === -1) { $(fileElements[0]).before(element); - }else{ + } else { $(fileElements[pos]).after(element); } - }else if(type=='dir' && $('tr[data-file]').length>0){ + } else if (type === 'dir' && $('tr[data-file]').exists()) { $('tr[data-file]').first().before(element); - } else if(type=='file' && $('tr[data-file]').length>0) { + } else if (type === 'file' && $('tr[data-file]').exists()) { $('tr[data-file]').last().before(element); - }else{ + } else { $('#fileList').append(element); } $('#emptycontent').addClass('hidden'); FileList.updateFileSummary(); }, - loadingDone:function(name, id){ - var mime, tr=$('tr').filterAttr('data-file',name); - tr.data('loading',false); - mime=tr.data('mime'); - tr.attr('data-mime',mime); - if (id != null) { + loadingDone:function(name, id) { + var mime, tr = $('tr[data-file="'+name+'"]'); + tr.data('loading', false); + mime = tr.data('mime'); + tr.attr('data-mime', mime); + if (id) { tr.attr('data-id', id); } var path = getPathForPreview(name); - lazyLoadPreview(path, mime, function(previewpath){ + lazyLoadPreview(path, mime, function(previewpath) { tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); tr.find('td.filename').draggable(dragOptions); }, - isLoading:function(name){ - return $('tr').filterAttr('data-file',name).data('loading'); + isLoading:function(name) { + return $('tr[data-file="'+name+'"]').data('loading'); }, - rename:function(name){ + rename:function(oldname) { var tr, td, input, form; - tr=$('tr').filterAttr('data-file',name); + tr = $('tr[data-file="'+oldname+'"]'); tr.data('renaming',true); - td=tr.children('td.filename'); - input=$('').val(name); - form=$('
    '); + td = tr.children('td.filename'); + input = $('').val(oldname); + form = $('
    '); form.append(input); td.children('a.name').hide(); td.append(form); @@ -322,18 +325,29 @@ var FileList={ if (len === -1) { len = input.val().length; } - input.selectRange(0,len); - - form.submit(function(event){ + input.selectRange(0, len); + + var checkInput = function () { + var filename = input.val(); + if (filename !== oldname) { + if (!Files.isFileNameValid(filename)) { + // Files.isFileNameValid(filename) throws an exception itself + } else if($('#dir').val() === '/' && filename === 'Shared') { + throw t('files','Invalid name. Usage of \'Shared\' is reserved by ownCloud'); + } else if (FileList.inList(filename)) { + throw t('files', '{new_name} already exists', {new_name: filename}); + } + } + return true; + }; + + form.submit(function(event) { event.stopPropagation(); event.preventDefault(); - var newname=input.val(); - if (!Files.isFileNameValid(newname)) { - return false; - } else if (newname != name) { - if (FileList.checkName(name, newname, false)) { - newname = name; - } else { + try { + var newname = input.val(); + if (newname !== oldname) { + checkInput(); // save background image, because it's replaced by a spinner while async request var oldBackgroundImage = td.css('background-image'); // mark as loading @@ -343,16 +357,16 @@ var FileList={ data: { dir : $('#dir').val(), newname: newname, - file: name + file: oldname }, success: function(result) { if (!result || result.status === 'error') { - OC.Notification.show(result.data.message); - newname = name; + OC.dialogs.alert(result.data.message, t('core', 'Could not rename file')); // revert changes + newname = oldname; tr.attr('data-file', newname); var path = td.children('a.name').attr('href'); - td.children('a.name').attr('href', path.replace(encodeURIComponent(name), encodeURIComponent(newname))); + td.children('a.name').attr('href', path.replace(encodeURIComponent(oldname), encodeURIComponent(newname))); if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') { var basename=newname.substr(0,newname.lastIndexOf('.')); } else { @@ -360,7 +374,7 @@ var FileList={ } td.find('a.name span.nametext').text(basename); if (newname.indexOf('.') > 0 && tr.data('type') !== 'dir') { - if (td.find('a.name span.extension').length === 0 ) { + if ( ! td.find('a.name span.extension').exists() ) { td.find('a.name span.nametext').append(''); } td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.'))); @@ -368,70 +382,76 @@ var FileList={ tr.find('.fileactions').effect('highlight', {}, 5000); tr.effect('highlight', {}, 5000); } + // reinsert row + tr.detach(); + FileList.insertElement( tr.attr('data-file'), tr.attr('data-type'),tr ); // remove loading mark and recover old image td.css('background-image', oldBackgroundImage); } }); } - } - tr.data('renaming',false); - tr.attr('data-file', newname); - var path = td.children('a.name').attr('href'); - td.children('a.name').attr('href', path.replace(encodeURIComponent(name), encodeURIComponent(newname))); - if (newname.indexOf('.') > 0 && tr.data('type') != 'dir') { - var basename=newname.substr(0,newname.lastIndexOf('.')); - } else { - var basename=newname; - } - td.find('a.name span.nametext').text(basename); - if (newname.indexOf('.') > 0 && tr.data('type') != 'dir') { - if (td.find('a.name span.extension').length == 0 ) { - td.find('a.name span.nametext').append(''); + 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('.')); + } + 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(''); + } + td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.'))); } - td.find('a.name span.extension').text(newname.substr(newname.lastIndexOf('.'))); + form.remove(); + td.children('a.name').show(); + } catch (error) { + input.attr('title', error); + input.tipsy({gravity: 'w', trigger: 'manual'}); + input.tipsy('show'); + input.addClass('error'); } - form.remove(); - td.children('a.name').show(); return false; }); - input.keyup(function(event){ - if (event.keyCode == 27) { + 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'); tr.data('renaming',false); form.remove(); td.children('a.name').show(); } }); - input.click(function(event){ + input.click(function(event) { event.stopPropagation(); event.preventDefault(); }); - input.blur(function(){ + input.blur(function() { form.trigger('submit'); }); }, - checkName:function(oldName, newName, isNewFile) { - if (isNewFile || $('tr').filterAttr('data-file', newName).length > 0) { - var html; - if(isNewFile){ - html = t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+''+t('files', 'replace')+''+t('files', 'suggest name')+' '+t('files', 'cancel')+''; - }else{ - html = t('files', '{new_name} already exists', {new_name: escapeHTML(newName)})+''+t('files', 'replace')+''+t('files', 'cancel')+''; - } - html = $('' + html + ''); - html.attr('data-oldName', oldName); - html.attr('data-newName', newName); - html.attr('data-isNewFile', isNewFile); - OC.Notification.showHtml(html); - return true; - } else { - return false; - } + inList:function(filename) { + return $('#fileList tr[data-file="'+filename+'"]').length; }, replace:function(oldName, newName, isNewFile) { // Finish any existing actions - $('tr').filterAttr('data-file', oldName).hide(); - $('tr').filterAttr('data-file', newName).hide(); - var tr = $('tr').filterAttr('data-file', oldName).clone(); + $('tr[data-file="'+oldName+'"]').hide(); + $('tr[data-file="'+newName+'"]').hide(); + var tr = $('tr[data-file="'+oldName+'"]').clone(); tr.attr('data-replace', 'true'); tr.attr('data-file', newName); var td = tr.children('td.filename'); @@ -460,14 +480,14 @@ var FileList={ FileList.finishReplace(); }; if (!isNewFile) { - OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+''+t('files', 'undo')+''); + OC.Notification.showHtml(t('files', 'replaced {new_name} with {old_name}', {new_name: newName}, {old_name: oldName})+''+t('files', 'undo')+''); } }, finishReplace:function() { if (!FileList.replaceCanceled && FileList.replaceOldName && FileList.replaceNewName) { $.ajax({url: OC.filePath('files', 'ajax', 'rename.php'), async: false, data: { dir: $('#dir').val(), newname: FileList.replaceNewName, file: FileList.replaceOldName }, success: function(result) { - if (result && result.status == 'success') { - $('tr').filterAttr('data-replace', 'true').removeAttr('data-replace'); + if (result && result.status === 'success') { + $('tr[data-replace="true"').removeAttr('data-replace'); } else { OC.dialogs.alert(result.data.message, 'Error moving file'); } @@ -478,12 +498,12 @@ var FileList={ }}); } }, - do_delete:function(files){ - if(files.substr){ + do_delete:function(files) { + if (files.substr) { files=[files]; } for (var i=0; i 0 ) { + if ( $('#fileList tr').exists() ) { var totalDirs = 0; var totalFiles = 0; var totalSize = 0; @@ -536,7 +556,7 @@ var FileList={ var infoVars = { dirs: ''+directoryInfo+'', files: ''+fileInfo+'' - } + }; var info = t('files', '{dirs} and {files}', infoVars); @@ -618,10 +638,10 @@ var FileList={ } } }, - showMask: function(){ + showMask: function() { // in case one was shown before var $mask = $('#content .mask'); - if ($mask.length){ + if ($mask.exists()) { return; } @@ -632,31 +652,31 @@ var FileList={ $('#content').append($mask); // block UI, but only make visible in case loading takes longer - FileList._maskTimeout = window.setTimeout(function(){ + FileList._maskTimeout = window.setTimeout(function() { // reset opacity $mask.removeClass('transparent'); }, 250); }, - hideMask: function(){ + hideMask: function() { var $mask = $('#content .mask').remove(); - if (FileList._maskTimeout){ + if (FileList._maskTimeout) { window.clearTimeout(FileList._maskTimeout); } }, scrollTo:function(file) { //scroll to and highlight preselected file - var scrolltorow = $('tr[data-file="'+file+'"]'); - if (scrolltorow.length > 0) { - scrolltorow.addClass('searchresult'); - $(window).scrollTop(scrolltorow.position().top); + var $scrolltorow = $('tr[data-file="'+file+'"]'); + if ($scrolltorow.exists()) { + $scrolltorow.addClass('searchresult'); + $(window).scrollTop($scrolltorow.position().top); //remove highlight when hovered over - scrolltorow.one('hover', function(){ - scrolltorow.removeClass('searchresult'); + $scrolltorow.one('hover', function() { + $scrolltorow.removeClass('searchresult'); }); } }, - filter:function(query){ - $('#fileList tr:not(.summary)').each(function(i,e){ + filter:function(query) { + $('#fileList tr:not(.summary)').each(function(i,e) { if ($(e).data('file').toLowerCase().indexOf(query.toLowerCase()) !== -1) { $(e).addClass("searchresult"); } else { @@ -665,18 +685,18 @@ var FileList={ }); //do not use scrollto to prevent removing searchresult css class var first = $('#fileList tr.searchresult').first(); - if (first.length !== 0) { + if (first.exists()) { $(window).scrollTop(first.position().top); } }, - unfilter:function(){ - $('#fileList tr.searchresult').each(function(i,e){ + unfilter:function() { + $('#fileList tr.searchresult').each(function(i,e) { $(e).removeClass("searchresult"); }); } }; -$(document).ready(function(){ +$(document).ready(function() { var isPublic = !!$('#isPublic').val(); // handle upload events @@ -686,16 +706,16 @@ $(document).ready(function(){ OC.Upload.log('filelist handle fileuploaddrop', e, data); var dropTarget = $(e.originalEvent.target).closest('tr, .crumb'); - if(dropTarget && (dropTarget.data('type') === 'dir' || dropTarget.hasClass('crumb'))) { // drag&drop upload to folder + 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){ + if (dir) { var parentDir = $('#dir').val() || '/'; - if (parentDir[parentDir.length - 1] != '/'){ + if (parentDir[parentDir.length - 1] !== '/') { parentDir += '/'; } dir = parentDir + dir; @@ -719,12 +739,12 @@ $(document).ready(function(){ OC.Upload.log('filelist handle fileuploadadd', e, data); //finish delete if we are uploading a deleted file - if(FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1){ + if (FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!==-1) { FileList.finishDelete(null, true); //delete file before continuing } // add ui visualization to existing folder - if(data.context && data.context.data('type') === 'dir') { + if (data.context && data.context.data('type') === 'dir') { // add to existing folder // update upload counter ui @@ -734,7 +754,7 @@ $(document).ready(function(){ uploadtext.attr('currentUploads', currentUploads); var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads); - if(currentUploads === 1) { + if (currentUploads === 1) { var img = OC.imagePath('core', 'loading.gif'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); uploadtext.text(translatedText); @@ -761,7 +781,7 @@ $(document).ready(function(){ } var result=$.parseJSON(response); - if(typeof result[0] !== 'undefined' && result[0].status === 'success') { + if (typeof result[0] !== 'undefined' && result[0].status === 'success') { var file = result[0]; if (data.context && data.context.data('type') === 'dir') { @@ -772,7 +792,7 @@ $(document).ready(function(){ currentUploads -= 1; uploadtext.attr('currentUploads', currentUploads); var translatedText = n('files', 'Uploading %n file', 'Uploading %n files', currentUploads); - if(currentUploads === 0) { + if (currentUploads === 0) { var img = OC.imagePath('core', 'filetypes/folder.png'); data.context.find('td.filename').attr('style','background-image:url('+img+')'); uploadtext.text(translatedText); @@ -789,18 +809,18 @@ $(document).ready(function(){ } else { // only append new file if dragged onto current dir's crumb (last) - if (data.context && data.context.hasClass('crumb') && !data.context.hasClass('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'); - if (data.files[0].size>=0){ + if (data.files[0].size>=0) { size=data.files[0].size; } var date=new Date(); var param = {}; - if ($('#publicUploadRequestToken').length) { + if ($('#publicUploadRequestToken').exists()) { param.download_url = document.location.href + '&download&path=/' + $('#dir').val() + '/' + file.name; } //should the file exist in the list remove it @@ -813,14 +833,14 @@ $(document).ready(function(){ data.context.attr('data-mime',file.mime).attr('data-id',file.id); var permissions = data.context.data('permissions'); - if(permissions !== file.permissions) { + if (permissions !== file.permissions) { data.context.attr('data-permissions', file.permissions); data.context.data('permissions', file.permissions); } FileActions.display(data.context.find('td.filename'), true); var path = getPathForPreview(file.name); - lazyLoadPreview(path, file.mime, function(previewpath){ + lazyLoadPreview(path, file.mime, function(previewpath) { data.context.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } @@ -854,10 +874,10 @@ $(document).ready(function(){ }); $('#notification').hide(); - $('#notification').on('click', '.undo', function(){ + $('#notification').on('click', '.undo', function() { if (FileList.deleteFiles) { - $.each(FileList.deleteFiles,function(index,file){ - $('tr').filterAttr('data-file',file).show(); + $.each(FileList.deleteFiles,function(index,file) { + $('tr[data-file="'+file+'"]').show(); }); FileList.deleteCanceled=true; FileList.deleteFiles=null; @@ -867,10 +887,10 @@ $(document).ready(function(){ FileList.deleteCanceled = false; FileList.deleteFiles = [FileList.replaceOldName]; } else { - $('tr').filterAttr('data-file', FileList.replaceOldName).show(); + $('tr[data-file="'+FileList.replaceOldName+'"]').show(); } - $('tr').filterAttr('data-replace', 'true').remove(); - $('tr').filterAttr('data-file', FileList.replaceNewName).show(); + $('tr[data-replace="true"').remove(); + $('tr[data-file="'+FileList.replaceNewName+'"]').show(); FileList.replaceCanceled = true; FileList.replaceOldName = null; FileList.replaceNewName = null; @@ -885,7 +905,7 @@ $(document).ready(function(){ }); }); $('#notification:first-child').on('click', '.suggest', function() { - $('tr').filterAttr('data-file', $('#notification > span').attr('data-oldName')).show(); + $('tr[data-file="'+$('#notification > span').attr('data-oldName')+'"]').show(); OC.Notification.hide(); }); $('#notification:first-child').on('click', '.cancel', function() { @@ -895,67 +915,67 @@ $(document).ready(function(){ } }); FileList.useUndo=(window.onbeforeunload)?true:false; - $(window).bind('beforeunload', function (){ + $(window).bind('beforeunload', function () { if (FileList.lastAction) { FileList.lastAction(); } }); - $(window).unload(function (){ + $(window).unload(function () { $(window).trigger('beforeunload'); }); - function decodeQuery(query){ + function decodeQuery(query) { return query.replace(/\+/g, ' '); } - function parseHashQuery(){ + function parseHashQuery() { var hash = window.location.hash, pos = hash.indexOf('?'), query; - if (pos >= 0){ + if (pos >= 0) { return hash.substr(pos + 1); } return ''; } - function parseCurrentDirFromUrl(){ + function parseCurrentDirFromUrl() { var query = parseHashQuery(), params, dir = '/'; // try and parse from URL hash first - if (query){ + if (query) { params = OC.parseQueryString(decodeQuery(query)); } // else read from query attributes - if (!params){ + if (!params) { params = OC.parseQueryString(decodeQuery(location.search)); } return (params && params.dir) || '/'; } // disable ajax/history API for public app (TODO: until it gets ported) - if (!isPublic){ + if (!isPublic) { // fallback to hashchange when no history support - if (!window.history.pushState){ - $(window).on('hashchange', function(){ + if (!window.history.pushState) { + $(window).on('hashchange', function() { FileList.changeDirectory(parseCurrentDirFromUrl(), false); }); } - window.onpopstate = function(e){ + window.onpopstate = function(e) { var targetDir; - if (e.state && e.state.dir){ + if (e.state && e.state.dir) { targetDir = e.state.dir; } else{ // read from URL targetDir = parseCurrentDirFromUrl(); } - if (targetDir){ + if (targetDir) { FileList.changeDirectory(targetDir, false); } - } + }; - if (parseInt($('#ajaxLoad').val(), 10) === 1){ + if (parseInt($('#ajaxLoad').val(), 10) === 1) { // need to initially switch the dir to the one from the hash (IE8) FileList.changeDirectory(parseCurrentDirFromUrl(), false, true); } diff --git a/apps/files/js/files.js b/apps/files/js/files.js index c3a8d81b50d..3567904f2f2 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -1,18 +1,18 @@ Files={ updateMaxUploadFilesize:function(response) { - if(response == undefined) { + if (response === undefined) { return; } - if(response.data !== undefined && response.data.uploadMaxFilesize !== undefined) { + if (response.data !== undefined && response.data.uploadMaxFilesize !== undefined) { $('#max_upload').val(response.data.uploadMaxFilesize); $('#upload.button').attr('original-title', response.data.maxHumanFilesize); $('#usedSpacePercent').val(response.data.usedSpacePercent); Files.displayStorageWarnings(); } - if(response[0] == undefined) { + if (response[0] === undefined) { return; } - if(response[0].uploadMaxFilesize !== undefined) { + if (response[0].uploadMaxFilesize !== undefined) { $('#max_upload').val(response[0].uploadMaxFilesize); $('#upload.button').attr('original-title', response[0].maxHumanFilesize); $('#usedSpacePercent').val(response[0].usedSpacePercent); @@ -22,23 +22,18 @@ Files={ }, isFileNameValid:function (name) { if (name === '.') { - OC.Notification.show(t('files', '\'.\' is an invalid file name.')); - return false; - } - if (name.length == 0) { - OC.Notification.show(t('files', 'File name cannot be empty.')); - return false; + throw t('files', '\'.\' is an invalid file name.'); + } else if (name.length === 0) { + throw t('files', 'File name cannot be empty.'); } // check for invalid characters var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*']; for (var i = 0; i < invalid_characters.length; i++) { - if (name.indexOf(invalid_characters[i]) != -1) { - OC.Notification.show(t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.")); - return false; + if (name.indexOf(invalid_characters[i]) !== -1) { + throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed."); } } - OC.Notification.hide(); return true; }, displayStorageWarnings: function() { @@ -78,18 +73,18 @@ Files={ } }, - setupDragAndDrop: function(){ + setupDragAndDrop: function() { var $fileList = $('#fileList'); //drag/drop of files - $fileList.find('tr td.filename').each(function(i,e){ + $fileList.find('tr td.filename').each(function(i,e) { if ($(e).parent().data('permissions') & OC.PERMISSION_DELETE) { $(e).draggable(dragOptions); } }); - $fileList.find('tr[data-type="dir"] td.filename').each(function(i,e){ - if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE){ + $fileList.find('tr[data-type="dir"] td.filename').each(function(i,e) { + if ($(e).parent().data('permissions') & OC.PERMISSION_CREATE) { $(e).droppable(folderDropOptions); } }); @@ -127,9 +122,9 @@ Files={ }, resizeBreadcrumbs: function (width, firstRun) { - if (width != Files.lastWidth) { + if (width !== Files.lastWidth) { if ((width < Files.lastWidth || firstRun) && width < Files.breadcrumbsWidth) { - if (Files.hiddenBreadcrumbs == 0) { + if (Files.hiddenBreadcrumbs === 0) { Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth; $(Files.breadcrumbs[1]).find('a').hide(); $(Files.breadcrumbs[1]).append('...'); @@ -141,12 +136,12 @@ Files={ Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth; $(Files.breadcrumbs[i]).hide(); Files.hiddenBreadcrumbs = i; - i++ + i++; } } else if (width > Files.lastWidth && Files.hiddenBreadcrumbs > 0) { var i = Files.hiddenBreadcrumbs; while (width > Files.breadcrumbsWidth && i > 0) { - if (Files.hiddenBreadcrumbs == 1) { + if (Files.hiddenBreadcrumbs === 1) { Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth; $(Files.breadcrumbs[1]).find('span').remove(); $(Files.breadcrumbs[1]).find('a').show(); @@ -170,7 +165,7 @@ Files={ }; $(document).ready(function() { // FIXME: workaround for trashbin app - if (window.trashBinApp){ + if (window.trashBinApp) { return; } Files.displayEncryptionWarning(); @@ -215,7 +210,7 @@ $(document).ready(function() { var rows = $(this).parent().parent().parent().children('tr'); for (var i = start; i < end; i++) { $(rows).each(function(index) { - if (index == i) { + if (index === i) { var checkbox = $(this).children().children('input:checkbox'); $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().addClass('selected'); @@ -232,23 +227,23 @@ $(document).ready(function() { } 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) { + var selectedCount = $('td.filename input:checkbox:checked').length; + if (selectedCount === $('td.filename input:checkbox').length) { $('#select_all').attr('checked', 'checked'); } } procesSelection(); } else { var filename=$(this).parent().parent().attr('data-file'); - var tr=$('tr').filterAttr('data-file',filename); + var tr=$('tr[data-file="'+filename+'"]'); var renaming=tr.data('renaming'); - if(!renaming && !FileList.isLoading(filename)){ + if (!renaming && !FileList.isLoading(filename)) { 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){ + if (action) { event.preventDefault(); action(filename); } @@ -259,11 +254,11 @@ $(document).ready(function() { // Sets the select_all checkbox behaviour : $('#select_all').click(function() { - if($(this).attr('checked')){ + if ($(this).attr('checked')) { // Check all $('td.filename input:checkbox').attr('checked', true); $('td.filename input:checkbox').parent().parent().addClass('selected'); - }else{ + } else { // Uncheck all $('td.filename input:checkbox').attr('checked', false); $('td.filename input:checkbox').parent().parent().removeClass('selected'); @@ -280,7 +275,7 @@ $(document).ready(function() { var rows = $(this).parent().parent().parent().children('tr'); for (var i = start; i < end; i++) { $(rows).each(function(index) { - if (index == i) { + if (index === i) { var checkbox = $(this).children().children('input:checkbox'); $(checkbox).attr('checked', 'checked'); $(checkbox).parent().parent().addClass('selected'); @@ -290,10 +285,10 @@ $(document).ready(function() { } var selectedCount=$('td.filename input:checkbox:checked').length; $(this).parent().parent().toggleClass('selected'); - if(!$(this).attr('checked')){ + if (!$(this).attr('checked')) { $('#select_all').attr('checked',false); - }else{ - if(selectedCount==$('td.filename input:checkbox').length){ + } else { + if (selectedCount===$('td.filename input:checkbox').length) { $('#select_all').attr('checked',true); } } @@ -306,10 +301,11 @@ $(document).ready(function() { var dir=$('#dir').val()||'/'; OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.')); // use special download URL if provided, e.g. for public shared files - if ( (downloadURL = document.getElementById("downloadURL")) ) { - window.location=downloadURL.value+"&download&files="+encodeURIComponent(fileslist); + var downloadURL = document.getElementById("downloadURL"); + if ( downloadURL ) { + window.location = downloadURL.value+"&download&files=" + encodeURIComponent(fileslist); } else { - window.location=OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist }); + window.location = OC.filePath('files', 'ajax', 'download.php') + '?'+ $.param({ dir: dir, files: fileslist }); } return false; }); @@ -376,12 +372,12 @@ $(document).ready(function() { } }); -function scanFiles(force, dir, users){ +function scanFiles(force, dir, users) { if (!OC.currentUser) { return; } - if(!dir){ + if (!dir) { dir = ''; } force = !!force; //cast to bool @@ -399,17 +395,17 @@ function scanFiles(force, dir, users){ scannerEventSource = new OC.EventSource(OC.filePath('files','ajax','scan.php'),{force: force,dir: dir}); } scanFiles.cancel = scannerEventSource.close.bind(scannerEventSource); - scannerEventSource.listen('count',function(count){ - console.log(count + ' files scanned') + scannerEventSource.listen('count',function(count) { + console.log(count + ' files scanned'); }); - scannerEventSource.listen('folder',function(path){ - console.log('now scanning ' + path) + scannerEventSource.listen('folder',function(path) { + console.log('now scanning ' + path); }); - scannerEventSource.listen('done',function(count){ + scannerEventSource.listen('done',function(count) { scanFiles.scanning=false; console.log('done after ' + count + ' files'); }); - scannerEventSource.listen('user',function(user){ + scannerEventSource.listen('user',function(user) { console.log('scanning files for ' + user); }); } @@ -418,14 +414,14 @@ scanFiles.scanning=false; function boolOperationFinished(data, callback) { result = jQuery.parseJSON(data.responseText); Files.updateMaxUploadFilesize(result); - if(result.status == 'success'){ + if (result.status === 'success') { callback.call(); } else { alert(result.data.message); } } -var createDragShadow = function(event){ +var createDragShadow = function(event) { //select dragged file var isDragSelected = $(event.target).parents('tr').find('td input:first').prop('checked'); if (!isDragSelected) { @@ -435,7 +431,7 @@ var createDragShadow = function(event){ var selectedFiles = getSelectedFilesTrash(); - if (!isDragSelected && selectedFiles.length == 1) { + if (!isDragSelected && selectedFiles.length === 1) { //revert the selection $(event.target).parents('tr').find('td input:first').prop('checked',false); } @@ -452,7 +448,7 @@ var createDragShadow = function(event){ var dir=$('#dir').val(); - $(selectedFiles).each(function(i,elem){ + $(selectedFiles).each(function(i,elem) { var newtr = $('
    ').attr('data-dir', dir).attr('data-filename', elem.name); newtr.append($('
    t( 'Modified' )); ?> - + t('Unshare'))?> diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index 9e1750faddf..1e4d4d11c98 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -1,4 +1,6 @@ - + assign('mimetype', \OC\Files\Filesystem::getMimeType($path)); $tmpl->assign('fileTarget', basename($linkItem['file_target'])); $tmpl->assign('dirToken', $linkItem['token']); + $tmpl->assign('disableSharing', true); $allowPublicUploadEnabled = (bool) ($linkItem['permissions'] & OCP\PERMISSION_CREATE); if (\OCP\App::isEnabled('files_encryption')) { $allowPublicUploadEnabled = false; @@ -206,7 +207,6 @@ if (isset($path)) { } $list = new OCP\Template('files', 'part.list', ''); $list->assign('files', $files); - $list->assign('disableSharing', true); $list->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path='); $list->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path='); diff --git a/apps/files_trashbin/ajax/list.php b/apps/files_trashbin/ajax/list.php new file mode 100644 index 00000000000..e72e67b01d7 --- /dev/null +++ b/apps/files_trashbin/ajax/list.php @@ -0,0 +1,51 @@ +assign('breadcrumb', $breadcrumb, false); + $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir='); + $breadcrumbNav->assign('home', OCP\Util::linkTo('files', 'index.php')); + + $data['breadcrumb'] = $breadcrumbNav->fetchPage(); +} + +// make filelist +$files = \OCA\files_trashbin\lib\Helper::getTrashFiles($dir); + +if ($files === null){ + header("HTTP/1.0 404 Not Found"); + exit(); +} + +$dirlisting = false; +if ($dir && $dir !== '/') { + $dirlisting = true; +} + +$encodedDir = \OCP\Util::encodePath($dir); +$list = new OCP\Template('files_trashbin', 'part.list', ''); +$list->assign('files', $files, false); +$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$encodedDir); +$list->assign('downloadURL', OCP\Util::linkToRoute('download', array('file' => '/'))); +$list->assign('dirlisting', $dirlisting); +$list->assign('disableDownloadActions', true); +$data['files'] = $list->fetchPage(); + +OCP\JSON::success(array('data' => $data)); + diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/index.php index b7d0ef012f4..c28a88d541a 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/index.php @@ -10,92 +10,27 @@ OCP\Util::addScript('files_trashbin', 'disableDefaultActions'); OCP\Util::addScript('files', 'fileactions'); $tmpl = new OCP\Template('files_trashbin', 'index', 'user'); -$user = \OCP\User::getUser(); -$view = new OC_Filesystemview('/'.$user.'/files_trashbin/files'); - OCP\Util::addStyle('files', 'files'); OCP\Util::addScript('files', 'filelist'); +// filelist overrides +OCP\Util::addScript('files_trashbin', 'filelist'); $dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : ''; -$result = array(); -if ($dir) { - $dirlisting = true; - $dirContent = $view->opendir($dir); - $i = 0; - if(is_resource($dirContent)) { - while(($entryName = readdir($dirContent)) !== false) { - if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) { - $pos = strpos($dir.'/', '/', 1); - $tmp = substr($dir, 0, $pos); - $pos = strrpos($tmp, '.d'); - $timestamp = substr($tmp, $pos+2); - $result[] = array( - 'id' => $entryName, - 'timestamp' => $timestamp, - 'mime' => $view->getMimeType($dir.'/'.$entryName), - 'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file', - 'location' => $dir, - ); - } - } - closedir($dirContent); - } -} else { - $dirlisting = false; - $query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?'); - $result = $query->execute(array($user))->fetchAll(); -} +$files = \OCA\files_trashbin\lib\Helper::getTrashFiles($dir); -$files = array(); -foreach ($result as $r) { - $i = array(); - $i['name'] = $r['id']; - $i['date'] = OCP\Util::formatDate($r['timestamp']); - $i['timestamp'] = $r['timestamp']; - $i['mimetype'] = $r['mime']; - $i['type'] = $r['type']; - if ($i['type'] === 'file') { - $fileinfo = pathinfo($r['id']); - $i['basename'] = $fileinfo['filename']; - $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : ''; - } - $i['directory'] = $r['location']; - if ($i['directory'] === '/') { - $i['directory'] = ''; - } - $i['permissions'] = OCP\PERMISSION_READ; - $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($r['mime']); - $i['icon'] = \OCA\files\lib\Helper::determineIcon($i); - $files[] = $i; +// Redirect if directory does not exist +if ($files === null){ + header('Location: ' . OCP\Util::linkTo('files_trashbin', 'index.php')); + exit(); } -function fileCmp($a, $b) { - if ($a['type'] === 'dir' and $b['type'] !== 'dir') { - return -1; - } elseif ($a['type'] !== 'dir' and $b['type'] === 'dir') { - return 1; - } else { - return strnatcasecmp($a['name'], $b['name']); - } +$dirlisting = false; +if ($dir && $dir !== '/') { + $dirlisting = true; } -usort($files, "fileCmp"); - -// Make breadcrumb -$pathtohere = ''; -$breadcrumb = array(); -foreach (explode('/', $dir) as $i) { - if ($i !== '') { - if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) { - $name = $match[1]; - } else { - $name = $i; - } - $pathtohere .= '/' . $i; - $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name); - } -} +$breadcrumb = \OCA\files_trashbin\lib\Helper::makeBreadcrumb($dir); $breadcrumbNav = new OCP\Template('files_trashbin', 'part.breadcrumb', ''); $breadcrumbNav->assign('breadcrumb', $breadcrumb); @@ -108,7 +43,6 @@ $list->assign('files', $files); $encodedDir = \OCP\Util::encodePath($dir); $list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$encodedDir); $list->assign('downloadURL', OCP\Util::linkTo('files_trashbin', 'download.php') . '?file='.$encodedDir); -$list->assign('disableSharing', true); $list->assign('dirlisting', $dirlisting); $list->assign('disableDownloadActions', true); @@ -116,6 +50,7 @@ $tmpl->assign('dirlisting', $dirlisting); $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage()); $tmpl->assign('fileList', $list->fetchPage()); $tmpl->assign('files', $files); -$tmpl->assign('dir', \OC\Files\Filesystem::normalizePath($view->getAbsolutePath())); +$tmpl->assign('dir', $dir); +$tmpl->assign('disableSharing', true); $tmpl->printPage(); diff --git a/apps/files_trashbin/js/filelist.js b/apps/files_trashbin/js/filelist.js new file mode 100644 index 00000000000..ff3a846d860 --- /dev/null +++ b/apps/files_trashbin/js/filelist.js @@ -0,0 +1,29 @@ +// override reload with own ajax call +FileList.reload = function(){ + FileList.showMask(); + if (FileList._reloadCall){ + FileList._reloadCall.abort(); + } + $.ajax({ + url: OC.filePath('files_trashbin','ajax','list.php'), + data: { + dir : $('#dir').val(), + breadcrumb: true + }, + error: function(result) { + FileList.reloadCallback(result); + }, + success: function(result) { + FileList.reloadCallback(result); + } + }); +} + +FileList.setCurrentDir = function(targetDir, changeUrl){ + $('#dir').val(targetDir); + // Note: IE8 handling ignored for now + if (window.history.pushState && changeUrl !== false){ + url = OC.linkTo('files_trashbin', 'index.php')+"?dir="+ encodeURIComponent(targetDir).replace(/%2F/g, '/'), + window.history.pushState({dir: targetDir}, '', url); + } +} diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js index 40c0bdb3829..d73eadb6011 100644 --- a/apps/files_trashbin/js/trash.js +++ b/apps/files_trashbin/js/trash.js @@ -171,9 +171,15 @@ $(document).ready(function() { action(filename); } } + + // event handlers for breadcrumb items + $('#controls').delegate('.crumb:not(.home) a', 'click', onClickBreadcrumb); }); - FileActions.actions.dir = {}; + FileActions.actions.dir = { + // only keep 'Open' action for navigation + 'Open': FileActions.actions.dir.Open + }; }); function processSelection(){ @@ -246,3 +252,9 @@ function disableActions() { $(".action").css("display", "none"); $(":input:checkbox").css("display", "none"); } +function onClickBreadcrumb(e){ + var $el = $(e.target).closest('.crumb'); + e.preventDefault(); + FileList.changeDirectory(decodeURIComponent($el.data('dir'))); +} + diff --git a/apps/files_trashbin/lib/helper.php b/apps/files_trashbin/lib/helper.php new file mode 100644 index 00000000000..098fc0b54b7 --- /dev/null +++ b/apps/files_trashbin/lib/helper.php @@ -0,0 +1,97 @@ +opendir($dir); + if ($dirContent === false){ + return null; + } + if(is_resource($dirContent)){ + while(($entryName = readdir($dirContent)) !== false) { + if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) { + $pos = strpos($dir.'/', '/', 1); + $tmp = substr($dir, 0, $pos); + $pos = strrpos($tmp, '.d'); + $timestamp = substr($tmp, $pos+2); + $result[] = array( + 'id' => $entryName, + 'timestamp' => $timestamp, + 'mime' => $view->getMimeType($dir.'/'.$entryName), + 'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file', + 'location' => $dir, + ); + } + } + closedir($dirContent); + } + } else { + $query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?'); + $result = $query->execute(array($user))->fetchAll(); + } + + $files = array(); + foreach ($result as $r) { + $i = array(); + $i['name'] = $r['id']; + $i['date'] = \OCP\Util::formatDate($r['timestamp']); + $i['timestamp'] = $r['timestamp']; + $i['mimetype'] = $r['mime']; + $i['type'] = $r['type']; + if ($i['type'] === 'file') { + $fileinfo = pathinfo($r['id']); + $i['basename'] = $fileinfo['filename']; + $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : ''; + } + $i['directory'] = $r['location']; + if ($i['directory'] === '/') { + $i['directory'] = ''; + } + $i['permissions'] = \OCP\PERMISSION_READ; + $i['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($r['mime']); + $i['icon'] = \OCA\files\lib\Helper::determineIcon($i); + $files[] = $i; + } + + usort($files, array('\OCA\files\lib\Helper', 'fileCmp')); + + return $files; + } + + /** + * Splits the given path into a breadcrumb structure. + * @param string $dir path to process + * @return array where each entry is a hash of the absolute + * directory path and its name + */ + public static function makeBreadcrumb($dir){ + // Make breadcrumb + $pathtohere = ''; + $breadcrumb = array(); + foreach (explode('/', $dir) as $i) { + if ($i !== '') { + if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) { + $name = $match[1]; + } else { + $name = $i; + } + $pathtohere .= '/' . $i; + $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name); + } + } + return $breadcrumb; + } +} diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index 88c32b1f3eb..daae7753aeb 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -9,6 +9,9 @@
    t('Nothing in here. Your trash bin is empty!'))?>
    + + + diff --git a/apps/files_trashbin/templates/part.breadcrumb.php b/apps/files_trashbin/templates/part.breadcrumb.php index 8ecab58e5c8..4acc298adbe 100644 --- a/apps/files_trashbin/templates/part.breadcrumb.php +++ b/apps/files_trashbin/templates/part.breadcrumb.php @@ -1,11 +1,11 @@ -
    +
    '> + data-dir='/'> t("Deleted Files")); ?>
    diff --git a/apps/files_trashbin/templates/part.list.php b/apps/files_trashbin/templates/part.list.php index f7cc6b01bbb..78709d986ae 100644 --- a/apps/files_trashbin/templates/part.list.php +++ b/apps/files_trashbin/templates/part.list.php @@ -1,4 +1,3 @@ - ' id="" - data-file="" + data-file="" data-timestamp='' data-dirlisting=1 diff --git a/core/js/js.js b/core/js/js.js index 1999ff73d23..c09f80369f9 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -321,6 +321,38 @@ var OC={ var date = new Date(1000*mtime); return date.getDate()+'.'+(date.getMonth()+1)+'.'+date.getFullYear()+', '+date.getHours()+':'+date.getMinutes(); }, + /** + * Parses a URL query string into a JS map + * @param queryString query string in the format param1=1234¶m2=abcde¶m3=xyz + * @return map containing key/values matching the URL parameters + */ + parseQueryString:function(queryString){ + var parts, + components, + result = {}, + key, + value; + if (!queryString){ + return null; + } + if (queryString[0] === '?'){ + queryString = queryString.substr(1); + } + parts = queryString.split('&'); + for (var i = 0; i < parts.length; i++){ + components = parts[i].split('='); + if (!components.length){ + continue; + } + key = decodeURIComponent(components[0]); + if (!key){ + continue; + } + value = components[1]; + result[key] = value && decodeURIComponent(value); + } + return result; + }, /** * Opens a popup with the setting for an app. * @param appid String. The ID of the app e.g. 'calendar', 'contacts' or 'files'. -- cgit v1.2.3 From 4e751cbb473b416f693473ae69e7c55e013e854b Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 27 Aug 2013 13:13:00 +0200 Subject: fixing breadcrumbs on ajax loading of files --- apps/files/js/filelist.js | 6 +- apps/files/js/files.js | 133 ++++++++++++++++++++++------------------- apps/files/templates/index.php | 4 +- 3 files changed, 78 insertions(+), 65 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 21f713b4a80..b3955b3d22e 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -218,8 +218,10 @@ var FileList={ if(typeof(result.data.breadcrumb) != 'undefined'){ $controls.find('.crumb').remove(); $controls.prepend(result.data.breadcrumb); - // TODO: might need refactor breadcrumb code into a new file - //resizeBreadcrumbs(true); + + var width = $(window).width(); + Files.initBreadCrumbs(); + Files.resizeBreadcrumbs(width, true); // in case svg is not supported by the browser we need to execute the fallback mechanism if(!SVGSupport()) { diff --git a/apps/files/js/files.js b/apps/files/js/files.js index ce72c7bcb5a..1ea2f5fbcc2 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -111,6 +111,72 @@ Files={ $(e).droppable(folderDropOptions); } }); + }, + + lastWidth: 0, + + initBreadCrumbs: function () { + Files.lastWidth = 0; + Files.breadcrumbs = []; + + // initialize with some extra space + Files.breadcrumbsWidth = 64; + if ( document.getElementById("navigation") ) { + Files.breadcrumbsWidth += $('#navigation').get(0).offsetWidth; + } + Files.hiddenBreadcrumbs = 0; + + $.each($('.crumb'), function(index, breadcrumb) { + Files.breadcrumbs[index] = breadcrumb; + Files.breadcrumbsWidth += $(breadcrumb).get(0).offsetWidth; + }); + + + $.each($('#controls .actions>div'), function(index, action) { + Files.breadcrumbsWidth += $(action).get(0).offsetWidth; + }); + }, + + resizeBreadcrumbs: function (width, firstRun) { + if (width != Files.lastWidth) { + if ((width < Files.lastWidth || firstRun) && width < Files.breadcrumbsWidth) { + if (Files.hiddenBreadcrumbs == 0) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth; + $(Files.breadcrumbs[1]).find('a').hide(); + $(Files.breadcrumbs[1]).append('...'); + Files.breadcrumbsWidth += $(Files.breadcrumbs[1]).get(0).offsetWidth; + Files.hiddenBreadcrumbs = 2; + } + var i = Files.hiddenBreadcrumbs; + while (width < Files.breadcrumbsWidth && i > 1 && i < Files.breadcrumbs.length - 1) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth; + $(Files.breadcrumbs[i]).hide(); + Files.hiddenBreadcrumbs = i; + i++ + } + } else if (width > Files.lastWidth && Files.hiddenBreadcrumbs > 0) { + var i = Files.hiddenBreadcrumbs; + while (width > Files.breadcrumbsWidth && i > 0) { + if (Files.hiddenBreadcrumbs == 1) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[1]).get(0).offsetWidth; + $(Files.breadcrumbs[1]).find('span').remove(); + $(Files.breadcrumbs[1]).find('a').show(); + Files.breadcrumbsWidth += $(Files.breadcrumbs[1]).get(0).offsetWidth; + } else { + $(Files.breadcrumbs[i]).show(); + Files.breadcrumbsWidth += $(Files.breadcrumbs[i]).get(0).offsetWidth; + if (Files.breadcrumbsWidth > width) { + Files.breadcrumbsWidth -= $(Files.breadcrumbs[i]).get(0).offsetWidth; + $(Files.breadcrumbs[i]).hide(); + break; + } + } + i--; + Files.hiddenBreadcrumbs = i; + } + } + Files.lastWidth = width; + } } }; $(document).ready(function() { @@ -273,72 +339,15 @@ $(document).ready(function() { //do a background scan if needed scanFiles(); - var lastWidth = 0; - var breadcrumbs = []; - var breadcrumbsWidth = 0; - if ( document.getElementById("navigation") ) { - breadcrumbsWidth = $('#navigation').get(0).offsetWidth; - } - var hiddenBreadcrumbs = 0; - - $.each($('.crumb'), function(index, breadcrumb) { - breadcrumbs[index] = breadcrumb; - breadcrumbsWidth += $(breadcrumb).get(0).offsetWidth; - }); - - - $.each($('#controls .actions>div'), function(index, action) { - breadcrumbsWidth += $(action).get(0).offsetWidth; - }); - - function resizeBreadcrumbs(firstRun) { - var width = $(this).width(); - if (width != lastWidth) { - if ((width < lastWidth || firstRun) && width < breadcrumbsWidth) { - if (hiddenBreadcrumbs == 0) { - breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth; - $(breadcrumbs[1]).find('a').hide(); - $(breadcrumbs[1]).append('...'); - breadcrumbsWidth += $(breadcrumbs[1]).get(0).offsetWidth; - hiddenBreadcrumbs = 2; - } - var i = hiddenBreadcrumbs; - while (width < breadcrumbsWidth && i > 1 && i < breadcrumbs.length - 1) { - breadcrumbsWidth -= $(breadcrumbs[i]).get(0).offsetWidth; - $(breadcrumbs[i]).hide(); - hiddenBreadcrumbs = i; - i++ - } - } else if (width > lastWidth && hiddenBreadcrumbs > 0) { - var i = hiddenBreadcrumbs; - while (width > breadcrumbsWidth && i > 0) { - if (hiddenBreadcrumbs == 1) { - breadcrumbsWidth -= $(breadcrumbs[1]).get(0).offsetWidth; - $(breadcrumbs[1]).find('span').remove(); - $(breadcrumbs[1]).find('a').show(); - breadcrumbsWidth += $(breadcrumbs[1]).get(0).offsetWidth; - } else { - $(breadcrumbs[i]).show(); - breadcrumbsWidth += $(breadcrumbs[i]).get(0).offsetWidth; - if (breadcrumbsWidth > width) { - breadcrumbsWidth -= $(breadcrumbs[i]).get(0).offsetWidth; - $(breadcrumbs[i]).hide(); - break; - } - } - i--; - hiddenBreadcrumbs = i; - } - } - lastWidth = width; - } - } + Files.initBreadCrumbs(); $(window).resize(function() { - resizeBreadcrumbs(false); + var width = $(this).width(); + Files.resizeBreadcrumbs(width, false); }); - resizeBreadcrumbs(true); + var width = $(this).width(); + Files.resizeBreadcrumbs(width, true); // event handlers for breadcrumb items $('#controls').delegate('.crumb a', 'click', onClickBreadcrumb); diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 85e21380c6d..9ca115f7711 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -38,7 +38,9 @@
    - > +
    -- cgit v1.2.3 From 3cf0820d3507349fa2d518c24579d8605db7cd2e Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Sun, 1 Sep 2013 14:24:01 +0200 Subject: Changed breadcrumb event handling to not use delegate Using delegate might break apps that embed themselves in the files container. When an app embeds itself and the user clicks a breadcrumb, it will simply reload the whole browser page. --- apps/files/js/files.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 1ea2f5fbcc2..7aef8ea1d11 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -131,10 +131,12 @@ Files={ Files.breadcrumbsWidth += $(breadcrumb).get(0).offsetWidth; }); - $.each($('#controls .actions>div'), function(index, action) { Files.breadcrumbsWidth += $(action).get(0).offsetWidth; }); + + // event handlers for breadcrumb items + $('#controls .crumb a').on('click', onClickBreadcrumb); }, resizeBreadcrumbs: function (width, firstRun) { @@ -349,9 +351,6 @@ $(document).ready(function() { var width = $(this).width(); Files.resizeBreadcrumbs(width, true); - // event handlers for breadcrumb items - $('#controls').delegate('.crumb a', 'click', onClickBreadcrumb); - // display storage warnings setTimeout ( "Files.displayStorageWarnings()", 100 ); OC.Notification.setDefault(Files.displayStorageWarnings); -- cgit v1.2.3 From 611075bf206555cf011b5fb70e117c93040e9027 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Sun, 1 Sep 2013 14:36:33 +0200 Subject: Fixed JS error in trashbin app --- apps/files/js/files.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 7aef8ea1d11..c2418cfa751 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -182,6 +182,10 @@ Files={ } }; $(document).ready(function() { + // FIXME: workaround for trashbin app + if (window.trashBinApp){ + return; + } Files.displayEncryptionWarning(); Files.bindKeyboardShortcuts(document, jQuery); -- cgit v1.2.3 From b40925ae1747ae44a52fb1f8dcf7645d022c6f13 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Jul 2013 22:24:52 +0200 Subject: initial scrollto implementation: use places/folder icon, move link construction to JS, only show icon on hover, use 'searchresult' as css class name, add filter/unfilter methods, highlight searched files in current filelist only filter when correct FileList is present --- apps/files/css/files.css | 3 +++ apps/files/js/filelist.js | 41 ++++++++++++++++++++++++++++++++++----- apps/files/js/files.js | 5 +++++ core/js/js.js | 13 +++++++++++++ lib/search/provider/file.php | 3 ++- lib/search/result.php | 4 +++- search/css/results.css | 22 +++++++++++++++++++-- search/js/result.js | 38 ++++++++++++++++++++++++++++++------ search/templates/part.results.php | 3 ++- 9 files changed, 116 insertions(+), 16 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 41d9808c56b..0acb3c5d829 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -76,6 +76,9 @@ #filestable tbody tr.selected { background-color: rgb(230,230,230); } +#filestable tbody tr.searchresult { + background-color: rgb(240,240,240); +} tbody a { color:#000; } span.extension, span.uploading, td.date { color:#999; } span.extension { text-transform:lowercase; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; filter:alpha(opacity=70); opacity:.7; -webkit-transition:opacity 300ms; -moz-transition:opacity 300ms; -o-transition:opacity 300ms; transition:opacity 300ms; } diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index b50d46c98d3..9a2d39c3652 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -643,6 +643,37 @@ var FileList={ if (FileList._maskTimeout){ window.clearTimeout(FileList._maskTimeout); } + }, + scrollTo:function(file) { + //scroll to and highlight preselected file + var scrolltorow = $('tr[data-file="'+file+'"]'); + if (scrolltorow.length > 0) { + scrolltorow.addClass('searchresult'); + $(window).scrollTop(scrolltorow.position().top); + //remove highlight when hovered over + scrolltorow.one('hover', function(){ + scrolltorow.removeClass('searchresult'); + }); + } + }, + filter:function(query){ + $('#fileList tr:not(.summary)').each(function(i,e){ + if ($(e).data('file').toLowerCase().indexOf(query.toLowerCase()) !== -1) { + $(e).addClass("searchresult"); + } else { + $(e).removeClass("searchresult"); + } + }); + //do not use scrollto to prevent removing searchresult css class + var first = $('#fileList tr.searchresult').first(); + if (first.length !== 0) { + $(window).scrollTop(first.position().top); + } + }, + unfilter:function(){ + $('#fileList tr.searchresult').each(function(i,e){ + $(e).removeClass("searchresult"); + }); } }; @@ -818,16 +849,16 @@ $(document).ready(function(){ FileList.replaceIsNewFile = null; } FileList.lastAction = null; - OC.Notification.hide(); + OC.Notification.hide(); }); $('#notification:first-child').on('click', '.replace', function() { - OC.Notification.hide(function() { - FileList.replace($('#notification > span').attr('data-oldName'), $('#notification > span').attr('data-newName'), $('#notification > span').attr('data-isNewFile')); - }); + OC.Notification.hide(function() { + FileList.replace($('#notification > span').attr('data-oldName'), $('#notification > span').attr('data-newName'), $('#notification > span').attr('data-isNewFile')); + }); }); $('#notification:first-child').on('click', '.suggest', function() { $('tr').filterAttr('data-file', $('#notification > span').attr('data-oldName')).show(); - OC.Notification.hide(); + OC.Notification.hide(); }); $('#notification:first-child').on('click', '.cancel', function() { if ($('#notification > span').attr('data-isNewFile')) { diff --git a/apps/files/js/files.js b/apps/files/js/files.js index c2418cfa751..a4fdf383339 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -384,6 +384,11 @@ $(document).ready(function() { } }); } + + //scroll to and highlight preselected file + if (getURLParameter('scrollto')) { + FileList.scrollTo(getURLParameter('scrollto')); + } }); function scanFiles(force, dir, users){ diff --git a/core/js/js.js b/core/js/js.js index c09f80369f9..c23cf9eebd9 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -723,11 +723,17 @@ $(document).ready(function(){ } }else if(event.keyCode===27){//esc OC.search.hide(); + if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system + FileList.unfilter(); + } }else{ var query=$('#searchbox').val(); if(OC.search.lastQuery!==query){ OC.search.lastQuery=query; OC.search.currentResult=-1; + if (FileList && typeof FileList.filter === 'function') { //TODO add hook system + FileList.filter(query); + } if(query.length>2){ OC.search(query); }else{ @@ -840,6 +846,13 @@ function formatDate(date){ return $.datepicker.formatDate(datepickerFormatDate, date)+' '+date.getHours()+':'+((date.getMinutes()<10)?'0':'')+date.getMinutes(); } +// taken from http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery +function getURLParameter(name) { + return decodeURI( + (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1] + ); +} + /** * takes an absolute timestamp and return a string with a human-friendly relative date * @param int a Unix timestamp diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php index 4d88c2a87f1..9bd50931517 100644 --- a/lib/search/provider/file.php +++ b/lib/search/provider/file.php @@ -10,6 +10,7 @@ class OC_Search_Provider_File extends OC_Search_Provider{ $mime = $fileData['mimetype']; $name = basename($path); + $container = dirname($path); $text = ''; $skip = false; if($mime=='httpd/unix-directory') { @@ -37,7 +38,7 @@ class OC_Search_Provider_File extends OC_Search_Provider{ } } if(!$skip) { - $results[] = new OC_Search_Result($name, $text, $link, $type); + $results[] = new OC_Search_Result($name, $text, $link, $type, $container); } } return $results; diff --git a/lib/search/result.php b/lib/search/result.php index 08beaea151c..42275c2df11 100644 --- a/lib/search/result.php +++ b/lib/search/result.php @@ -7,6 +7,7 @@ class OC_Search_Result{ public $text; public $link; public $type; + public $container; /** * create a new search result @@ -15,10 +16,11 @@ class OC_Search_Result{ * @param string $link link for the result * @param string $type the type of result as human readable string ('File', 'Music', etc) */ - public function __construct($name, $text, $link, $type) { + public function __construct($name, $text, $link, $type, $container) { $this->name=$name; $this->text=$text; $this->link=$link; $this->type=$type; + $this->container=$container; } } diff --git a/search/css/results.css b/search/css/results.css index 4ae7d67afb3..8a32b0b995d 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -14,7 +14,7 @@ position:fixed; right:0; text-overflow:ellipsis; - top:20px; + top:45px; width:380px; z-index:75; } @@ -43,10 +43,16 @@ } #searchresults td { - vertical-align:top; padding:0 .3em; + height: 32px; +} +#searchresults tr.template { + display: none; } +#searchresults td.result { + width:250px; +} #searchresults td.result div.text { padding-left:1em; white-space:nowrap; @@ -56,6 +62,18 @@ cursor:pointer; } +#searchresults td.container { + width:20px; +} + +#searchresults td.container img { + vertical-align: middle; + display:none; +} +#searchresults tr:hover td.container img { + display:inline; +} + #searchresults td.type { border-bottom:none; border-right:1px solid #aaa; diff --git a/search/js/result.js b/search/js/result.js index 78fa8efc8e9..78d9149f220 100644 --- a/search/js/result.js +++ b/search/js/result.js @@ -8,15 +8,23 @@ OC.search.catagorizeResults=function(results){ types[type].push(results[i]); } return types; -} +}; OC.search.hide=function(){ $('#searchresults').hide(); if($('#searchbox').val().length>2){ $('#searchbox').val(''); + if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system + FileList.unfilter(); + } }; -} + if ($('#searchbox').val().length === 0) { + if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system + FileList.unfilter(); + } + } +}; OC.search.showResults=function(results){ - if(results.length==0){ + if(results.length === 0){ return; } if(!OC.search.showResults.loaded){ @@ -30,6 +38,9 @@ OC.search.showResults=function(results){ }); $(document).click(function(event){ OC.search.hide(); + if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system + FileList.unfilter(); + } }); OC.search.lastResults=results; OC.search.showResults(results); @@ -46,12 +57,27 @@ OC.search.showResults=function(results){ var row=$('#searchresults tr.template').clone(); row.removeClass('template'); row.addClass('result'); - if (i == 0){ + if (i === 0){ row.children('td.type').text(name); } row.find('td.result a').attr('href',type[i].link); row.find('td.result div.name').text(type[i].name); row.find('td.result div.text').text(type[i].text); + if (type[i].container) { + var td = row.find('td.container'); + td.append(''); + td.find('img').attr('src',OC.imagePath('core','places/folder')); + var containerName = OC.basename(type[i].container); + if (containerName === '') { + containerName = '/'; + } + var containerLink = OC.linkTo('files','index.php') + +'?dir='+encodeURIComponent(type[i].container) + +'&scrollto='+encodeURIComponent(type[i].name); + row.find('td.container a') + .attr('href',containerLink) + .attr('title',t('core','Show in {folder}',{folder: containerName})); + } row.data('index',index); index++; if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here @@ -62,7 +88,7 @@ OC.search.showResults=function(results){ } } } -} +}; OC.search.showResults.loaded=false; OC.search.renderCurrent=function(){ @@ -71,4 +97,4 @@ OC.search.renderCurrent=function(){ $('#searchresults tr.result').removeClass('current'); $(result).addClass('current'); } -} +}; diff --git a/search/templates/part.results.php b/search/templates/part.results.php index 9e39a1c2c8b..1469e3468d3 100644 --- a/search/templates/part.results.php +++ b/search/templates/part.results.php @@ -1,7 +1,7 @@
    - + +
    @@ -9,6 +9,7 @@
    -- cgit v1.2.3 From 0d81a53e12bed66e5ec9684424519913283110a5 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 19 Sep 2013 10:00:42 +0200 Subject: use 96x96 as 64x64 thumbnails in conflicts dialog, 64x64 looks very blocky ... maybe something is wrong there --- apps/files/js/files.js | 12 ++++++++---- core/js/oc-dialogs.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index afbb14c5e00..76f19b87cbc 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -627,11 +627,15 @@ function getPathForPreview(name) { return path; } -function lazyLoadPreview(path, mime, ready) { +function lazyLoadPreview(path, mime, ready, width, height) { getMimeIcon(mime,ready); - var x = $('#filestable').data('preview-x'); - var y = $('#filestable').data('preview-y'); - var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:x, y:y}); + if (!width) { + width = $('#filestable').data('preview-x'); + } + if (!height) { + height = $('#filestable').data('preview-y'); + } + var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height}); $.get(previewURL, function() { previewURL = previewURL.replace('(','%28'); previewURL = previewURL.replace(')','%29'); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 7ca94dcbaa4..d661a871a5f 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -296,7 +296,7 @@ var OCdialogs = { var path = getPathForPreview(original.name); lazyLoadPreview(path, original.type, function(previewpath){ conflict.find('.original .icon').css('background-image','url('+previewpath+')'); - }); + }, 96, 96); getCroppedPreview(replacement).then( function(path){ conflict.find('.replacement .icon').css('background-image','url(' + path + ')'); -- cgit v1.2.3 From c30c153ea517403ee479be739a503bd91bab272e Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 19 Sep 2013 11:13:11 +0200 Subject: fixing typos and l10n --- apps/files/js/file-upload.js | 2 +- apps/files/js/files.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 8e9bcb885f6..2c42f29445f 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -169,7 +169,7 @@ OC.Upload = { }, /** * TODO checks the list of existing files prior to uploading and shows a simple dialog to choose - * skip all, replace all or choosw which files to keep + * skip all, replace all or choose which files to keep * @param array selection of files to upload * @param callbacks to call: * onNoConflicts, diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 76f19b87cbc..ccb40e7216f 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -499,7 +499,7 @@ var folderDropOptions={ $('#notification').fadeIn(); } } else { - OC.dialogs.alert(t('Error moving file'), t('core', 'Error')); + OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error')); } }); }); @@ -537,7 +537,7 @@ var crumbDropOptions={ $('#notification').fadeIn(); } } else { - OC.dialogs.alert(t('Error moving file'), t('core', 'Error')); + OC.dialogs.alert(t('files', 'Error moving file'), t('files', 'Error')); } }); }); -- cgit v1.2.3 From 98ff8478301676c99ffefd5756ad22466dfb6acf Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 19 Sep 2013 14:46:33 +0200 Subject: fix race condition in lazy preview loading --- apps/files/js/files.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index ccb40e7216f..5ec65d87457 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -628,18 +628,24 @@ function getPathForPreview(name) { } function lazyLoadPreview(path, mime, ready, width, height) { - getMimeIcon(mime,ready); - if (!width) { - width = $('#filestable').data('preview-x'); - } - if (!height) { - height = $('#filestable').data('preview-y'); - } - var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height}); - $.get(previewURL, function() { - previewURL = previewURL.replace('(','%28'); - previewURL = previewURL.replace(')','%29'); - ready(previewURL + '&reload=true'); + // get mime icon url + getMimeIcon(mime, function(iconURL) { + ready(iconURL); // set mimeicon URL + + // now try getting a preview thumbnail URL + if ( ! width ) { + width = $('#filestable').data('preview-x'); + } + if ( ! height ) { + height = $('#filestable').data('preview-y'); + } + var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height}); + $.get(previewURL, function() { + previewURL = previewURL.replace('(', '%28'); + previewURL = previewURL.replace(')', '%29'); + //set preview thumbnail URL + ready(previewURL + '&reload=true'); + }); }); } -- cgit v1.2.3 From 8a1618bce56a32e311626cd9f0e322dd7cf330c4 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 23 Sep 2013 12:27:05 +0200 Subject: implement previews for public upload --- apps/files/js/files.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 8ccb448abfb..ec688eaf63e 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -644,7 +644,11 @@ function lazyLoadPreview(path, mime, ready, width, height) { if ( ! height ) { height = $('#filestable').data('preview-y'); } - var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height}); + if( $('#publicUploadButtonMock').length ) { + var previewURL = OC.Router.generate('core_ajax_public_preview', {file: encodeURIComponent(path), x:width, y:height, t:$('#dirToken').val()}); + } else { + var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height}); + } $.get(previewURL, function() { previewURL = previewURL.replace('(', '%28'); previewURL = previewURL.replace(')', '%29'); -- cgit v1.2.3 From 9d2595a7c59048fc6ed3777a888e03d43a8f03f9 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 4 Oct 2013 11:11:24 +0200 Subject: Shortened notification message that was too long The message for invalid private key was too long and didn't fit in the notification box. This fix reduces the message to fit properly by removing the extra information. --- apps/files/js/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 55ee89e17a2..899bc6469e5 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -69,7 +69,7 @@ Files={ return; } if (initStatus === '1') { // encryption tried to init but failed - OC.Notification.show(t('files_encryption', 'Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.')); + OC.Notification.showHtml(t('files_encryption', 'Invalid private key for Encryption App. Please update your private key password in your personal settings to recover access to your encrypted files.')); return; } if (encryptedFiles === '1') { -- cgit v1.2.3 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/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 6a4563f203d8decb07bee3a82e111d876255e516 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 7 Oct 2013 11:07:33 +0200 Subject: Fix breadcrumb to reinit dnd after ajax nav #5064 Now correctly reinitializing the breadcrumb drop zone after ajax navigation. This also fixes dropping onto the "files" app icon. --- apps/files/js/files.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 899bc6469e5..53858d65c65 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -98,6 +98,8 @@ Files={ lastWidth: 0, initBreadCrumbs: function () { + var $controls = $('#controls'); + Files.lastWidth = 0; Files.breadcrumbs = []; @@ -118,7 +120,10 @@ Files={ }); // event handlers for breadcrumb items - $('#controls .crumb a').on('click', onClickBreadcrumb); + $controls.find('.crumb a').on('click', onClickBreadcrumb); + + // setup drag and drop + $controls.find('.crumb:not(.last)').droppable(crumbDropOptions); }, resizeBreadcrumbs: function (width, firstRun) { @@ -176,11 +181,8 @@ $(document).ready(function() { $('#file_action_panel').attr('activeAction', false); - $('div.crumb:not(.last)').droppable(crumbDropOptions); - $('ul#apps>li:first-child').data('dir',''); - if($('div.crumb').length){ - $('ul#apps>li:first-child').droppable(crumbDropOptions); - } + // allow dropping on the "files" app icon + $('ul#apps li:first-child').data('dir','').droppable(crumbDropOptions); // Triggers invisible file input $('#upload a').on('click', function() { -- cgit v1.2.3 From 4ccbace68df0150cdadaa8e680a7cb2639e8c628 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 20 Sep 2013 14:59:17 +0200 Subject: remove double uri encoding --- apps/files/js/files.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 899bc6469e5..bffb354fce6 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -367,7 +367,7 @@ $(document).ready(function() { } }); } - + //scroll to and highlight preselected file if (getURLParameter('scrollto')) { FileList.scrollTo(getURLParameter('scrollto')); @@ -645,7 +645,7 @@ function lazyLoadPreview(path, mime, ready, width, height) { // get mime icon url getMimeIcon(mime, function(iconURL) { ready(iconURL); // set mimeicon URL - + // now try getting a preview thumbnail URL if ( ! width ) { width = $('#filestable').data('preview-x'); @@ -654,9 +654,9 @@ function lazyLoadPreview(path, mime, ready, width, height) { height = $('#filestable').data('preview-y'); } if( $('#publicUploadButtonMock').length ) { - var previewURL = OC.Router.generate('core_ajax_public_preview', {file: encodeURIComponent(path), x:width, y:height, t:$('#dirToken').val()}); + var previewURL = OC.Router.generate('core_ajax_public_preview', {file: path, x:width, y:height, t:$('#dirToken').val()}); } else { - var previewURL = OC.Router.generate('core_ajax_preview', {file: encodeURIComponent(path), x:width, y:height}); + var previewURL = OC.Router.generate('core_ajax_preview', {file: path, x:width, y:height}); } $.get(previewURL, function() { previewURL = previewURL.replace('(', '%28'); -- 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/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 1c611a3dfb16c67a940ad74625bda54e4b593a09 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 18 Oct 2013 10:57:10 +0200 Subject: give getSelectedFilesTrash() a unique name for the trash.js to avoid confusions with the same function in files.js --- apps/files/js/files.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index a35ed4add8c..c3a8d81b50d 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -301,7 +301,7 @@ $(document).ready(function() { }); $('.download').click('click',function(event) { - var files=getSelectedFiles('name'); + var files=getSelectedFilesTrash('name'); var fileslist = JSON.stringify(files); var dir=$('#dir').val()||'/'; OC.Notification.show(t('files','Your download is being prepared. This might take some time if the files are big.')); @@ -315,7 +315,7 @@ $(document).ready(function() { }); $('.delete-selected').click(function(event) { - var files=getSelectedFiles('name'); + var files=getSelectedFilesTrash('name'); event.preventDefault(); FileList.do_delete(files); return false; @@ -433,7 +433,7 @@ var createDragShadow = function(event){ $(event.target).parents('tr').find('td input:first').prop('checked',true); } - var selectedFiles = getSelectedFiles(); + var selectedFiles = getSelectedFilesTrash(); if (!isDragSelected && selectedFiles.length == 1) { //revert the selection @@ -562,7 +562,7 @@ var crumbDropOptions={ } function procesSelection(){ - var selected=getSelectedFiles(); + var selected=getSelectedFilesTrash(); var selectedFiles=selected.filter(function(el){return el.type=='file'}); var selectedFolders=selected.filter(function(el){return el.type=='dir'}); if(selectedFiles.length==0 && selectedFolders.length==0) { @@ -607,7 +607,7 @@ function procesSelection(){ * 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 */ -function getSelectedFiles(property){ +function getSelectedFilesTrash(property){ var elements=$('td.filename input:checkbox:checked').parent().parent(); var files=[]; elements.each(function(i,element){ -- cgit v1.2.3 From 3bb7cf939ec56f97a5fb01c16282ed7d831e338f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 22 Oct 2013 12:08:05 +0200 Subject: Fixed ugly white space while loading file thumbnail Preview images are now pre-loaded before being set on the file element. This fixes #5135 and prevents a white space to be displayed while the thumbnails is being loaded. --- apps/files/js/files.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index c3a8d81b50d..ec2dc7c62ea 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -663,8 +663,16 @@ function lazyLoadPreview(path, mime, ready, width, height) { $.get(previewURL, function() { previewURL = previewURL.replace('(', '%28'); previewURL = previewURL.replace(')', '%29'); - //set preview thumbnail URL - ready(previewURL + '&reload=true'); + previewURL += '&reload=true'; + + // preload image to prevent delay + // this will make the browser cache the image + var img = new Image(); + img.onload = function(){ + //set preview thumbnail URL + ready(previewURL); + } + img.src = previewURL; }); }); } -- cgit v1.2.3 From 45e6d9670266884806431f35a4cedb80c0ceb229 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 22 Oct 2013 18:11:03 +0200 Subject: prevent user from creating or renaming sth. to an existing filename - show tooltip when violating naming constraints while typing - when target filename exists on server fallback to dialog to interrupt the users flow because something unexpected went wrong - fixes #5062 - also fixes some whitespace and codestyle issues in files js - uses css selector over filterAttr in touched js files --- apps/files/ajax/newfile.php | 15 ++ apps/files/css/files.css | 8 +- apps/files/js/file-upload.js | 337 ++++++++++++++++++++----------------- apps/files/js/filelist.js | 390 +++++++++++++++++++++++-------------------- apps/files/js/files.js | 198 +++++++++++----------- apps/files/lib/app.php | 10 +- core/js/js.js | 2 +- 7 files changed, 524 insertions(+), 436 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index 76c03c87a51..8f483aa5cb6 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -56,6 +56,21 @@ function progress($notification_code, $severity, $message, $message_code, $bytes $target = $dir.'/'.$filename; +$l10n = \OC_L10n::get('files'); + +if (\OC\Files\Filesystem::file_exists($target)) { + $result = array( + 'success' => false, + 'data' => array( + 'message' => $l10n->t( + "The name %s is already used in the folder %s. Please choose a different name.", + array($newname, $dir)) + ) + ); + OCP\JSON::error($result); + exit(); +} + if($source) { if(substr($source, 0, 8)!='https://' and substr($source, 0, 7)!='http://') { OCP\JSON::error(array("data" => array( "message" => "Not a valid source" ))); diff --git a/apps/files/css/files.css b/apps/files/css/files.css index ac2a243f2b4..af8597192f3 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -49,7 +49,13 @@ background-repeat:no-repeat; cursor:pointer; } #new>ul>li>p { cursor:pointer; padding-top: 7px; padding-bottom: 7px;} - +#new .error, #fileList .error { + color: #e9322d; + border-color: #e9322d; + -webkit-box-shadow: 0 0 6px #f8b9b7; + -moz-box-shadow: 0 0 6px #f8b9b7; + box-shadow: 0 0 6px #f8b9b7; +} /* FILE TABLE */ diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index fefb06a8ac5..936487cad3c 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -53,12 +53,12 @@ OC.Upload = { */ cancelUploads:function() { this.log('canceling uploads'); - jQuery.each(this._uploads,function(i, jqXHR){ + jQuery.each(this._uploads,function(i, jqXHR) { jqXHR.abort(); }); this._uploads = []; }, - rememberUpload:function(jqXHR){ + rememberUpload:function(jqXHR) { if (jqXHR) { this._uploads.push(jqXHR); } @@ -68,10 +68,10 @@ OC.Upload = { * returns true if any hxr has the state 'pending' * @returns {boolean} */ - isProcessing:function(){ + isProcessing:function() { var count = 0; - jQuery.each(this._uploads,function(i, data){ + jQuery.each(this._uploads,function(i, data) { if (data.state() === 'pending') { count++; } @@ -114,7 +114,7 @@ OC.Upload = { * handle skipping an upload * @param {object} data */ - onSkip:function(data){ + onSkip:function(data) { this.log('skip', null, data); this.deleteUpload(data); }, @@ -122,12 +122,12 @@ OC.Upload = { * handle replacing a file on the server with an uploaded file * @param {object} data */ - onReplace:function(data){ + onReplace:function(data) { this.log('replace', null, data); - if (data.data){ + if (data.data) { data.data.append('resolution', 'replace'); } else { - data.formData.push({name:'resolution',value:'replace'}); //hack for ie8 + data.formData.push({name:'resolution', value:'replace'}); //hack for ie8 } data.submit(); }, @@ -135,12 +135,12 @@ OC.Upload = { * handle uploading a file and letting the server decide a new name * @param {object} data */ - onAutorename:function(data){ + onAutorename:function(data) { this.log('autorename', null, data); if (data.data) { data.data.append('resolution', 'autorename'); } else { - data.formData.push({name:'resolution',value:'autorename'}); //hack for ie8 + data.formData.push({name:'resolution', value:'autorename'}); //hack for ie8 } data.submit(); }, @@ -162,7 +162,7 @@ OC.Upload = { * @param {function} callbacks.onChooseConflicts * @param {function} callbacks.onCancel */ - checkExistingFiles: function (selection, callbacks){ + checkExistingFiles: function (selection, callbacks) { // TODO check filelist before uploading and show dialog on conflicts, use callbacks callbacks.onNoConflicts(selection); } @@ -215,7 +215,7 @@ $(document).ready(function() { var selection = data.originalFiles.selection; // add uploads - if ( selection.uploads.length < selection.filesToUpload ){ + if ( selection.uploads.length < selection.filesToUpload ) { // remember upload selection.uploads.push(data); } @@ -335,7 +335,7 @@ $(document).ready(function() { delete data.jqXHR; - if(typeof result[0] === 'undefined') { + if (typeof result[0] === 'undefined') { data.textStatus = 'servererror'; data.errorThrown = t('files', 'Could not get result from server.'); var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload'); @@ -368,13 +368,13 @@ $(document).ready(function() { var fileupload = $('#file_upload_start').fileupload(file_upload_param); window.file_upload_param = fileupload; - if(supportAjaxUploadWithProgress()) { + if (supportAjaxUploadWithProgress()) { // add progress handlers fileupload.on('fileuploadadd', function(e, data) { OC.Upload.log('progress handle fileuploadadd', e, data); //show cancel button - //if(data.dataType !== 'iframe') { //FIXME when is iframe used? only for ie? + //if (data.dataType !== 'iframe') { //FIXME when is iframe used? only for ie? // $('#uploadprogresswrapper input.stop').show(); //} }); @@ -419,7 +419,9 @@ $(document).ready(function() { // http://stackoverflow.com/a/6700/11236 var size = 0, key; for (key in obj) { - if (obj.hasOwnProperty(key)) size++; + if (obj.hasOwnProperty(key)) { + size++; + } } return size; }; @@ -432,56 +434,61 @@ $(document).ready(function() { }); //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) - if(navigator.userAgent.search(/konqueror/i)==-1){ - $('#file_upload_start').attr('multiple','multiple'); + if (navigator.userAgent.search(/konqueror/i) === -1) { + $('#file_upload_start').attr('multiple', 'multiple'); } //if the breadcrumb is to long, start by replacing foldernames with '...' except for the current folder var crumb=$('div.crumb').first(); - while($('div.controls').height()>40 && crumb.next('div.crumb').length>0){ + while($('div.controls').height() > 40 && crumb.next('div.crumb').length > 0) { crumb.children('a').text('...'); - crumb=crumb.next('div.crumb'); + crumb = crumb.next('div.crumb'); } //if that isn't enough, start removing items from the breacrumb except for the current folder and it's parent - var crumb=$('div.crumb').first(); - var next=crumb.next('div.crumb'); - while($('div.controls').height()>40 && next.next('div.crumb').length>0){ + var crumb = $('div.crumb').first(); + var next = crumb.next('div.crumb'); + while($('div.controls').height()>40 && next.next('div.crumb').length > 0) { crumb.remove(); - crumb=next; - next=crumb.next('div.crumb'); + crumb = next; + next = crumb.next('div.crumb'); } //still not enough, start shorting down the current folder name var crumb=$('div.crumb>a').last(); - while($('div.controls').height()>40 && crumb.text().length>6){ - var text=crumb.text() - text=text.substr(0,text.length-6)+'...'; + while($('div.controls').height() > 40 && crumb.text().length > 6) { + var text=crumb.text(); + text = text.substr(0,text.length-6)+'...'; crumb.text(text); } - $(document).click(function(){ + $(document).click(function() { $('#new>ul').hide(); $('#new').removeClass('active'); - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ + if ($('#new .error').length > 0) { + $('#new .error').tipsy('hide'); + } + $('#new li').each(function(i,element) { + if ($(element).children('p').length === 0) { $(element).children('form').remove(); $(element).append('

    '+$(element).data('text')+'

    '); } }); }); - $('#new').click(function(event){ + $('#new').click(function(event) { event.stopPropagation(); }); - $('#new>a').click(function(){ + $('#new>a').click(function() { $('#new>ul').toggle(); $('#new').toggleClass('active'); }); - $('#new li').click(function(){ - if($(this).children('p').length==0){ + $('#new li').click(function() { + if ($(this).children('p').length === 0) { return; } + + $('#new .error').tipsy('hide'); - $('#new li').each(function(i,element){ - if($(element).children('p').length==0){ + $('#new li').each(function(i,element) { + if ($(element).children('p').length === 0) { $(element).children('form').remove(); $(element).append('

    '+$(element).data('text')+'

    '); } @@ -491,132 +498,164 @@ $(document).ready(function() { var text=$(this).children('p').text(); $(this).data('text',text); $(this).children('p').remove(); + + // add input field var form=$('
    '); var input=$(''); form.append(input); $(this).append(form); + + var checkInput = function () { + var filename = input.val(); + if (type === 'web' && filename.length === 0) { + throw t('files', 'URL cannot be empty.'); + } else if (type !== 'web' && !Files.isFileNameValid(filename)) { + // Files.isFileNameValid(filename) throws an exception itself + } else if ($('#dir').val() === '/' && filename === 'Shared') { + throw t('files','Invalid name. Usage of \'Shared\' is reserved by ownCloud'); + } else if (FileList.inList(filename)) { + throw t('files', '{new_name} already exists', {new_name: filename}); + } else { + return true; + } + }; + + // verify filename on typing + input.keyup(function(event) { + 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'); + } + }); + input.focus(); - form.submit(function(event){ + form.submit(function(event) { event.stopPropagation(); event.preventDefault(); - var newname=input.val(); - if(type == 'web' && newname.length == 0) { - OC.Notification.show(t('files', 'URL cannot be empty.')); - return false; - } else if (type != 'web' && !Files.isFileNameValid(newname)) { - return false; - } else if( type == 'folder' && $('#dir').val() == '/' && newname == 'Shared') { - OC.Notification.show(t('files','Invalid folder name. Usage of \'Shared\' is reserved by ownCloud')); - return false; - } - if (FileList.lastAction) { - FileList.lastAction(); - } - var name = getUniqueName(newname); - if (newname != name) { - FileList.checkName(name, newname, true); - var hidden = true; - } else { - var hidden = false; - } - switch(type){ - case 'file': - $.post( - OC.filePath('files','ajax','newfile.php'), - {dir:$('#dir').val(),filename:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - // 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); - tr.find('.filesize').text(humanFileSize(result.data.size)); - var path = getPathForPreview(name); - lazyLoadPreview(path, result.data.mime, function(previewpath){ - tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); - }); - FileActions.display(tr.find('td.filename'), true); - } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); + try { + checkInput(); + var newname = input.val(); + if (FileList.lastAction) { + FileList.lastAction(); + } + var name = getUniqueName(newname); + if (newname !== name) { + FileList.checkName(name, newname, true); + var hidden = true; + } else { + var hidden = false; + } + switch(type) { + case 'file': + $.post( + OC.filePath('files', 'ajax', 'newfile.php'), + {dir:$('#dir').val(), filename:name}, + function(result) { + if (result.status === 'success') { + var date = new Date(); + // 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); + tr.find('.filesize').text(humanFileSize(result.data.size)); + var path = getPathForPreview(name); + lazyLoadPreview(path, result.data.mime, function(previewpath) { + tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); + }); + FileActions.display(tr.find('td.filename'), true); + } else { + OC.dialogs.alert(result.data.message, t('core', 'Could not create file')); + } } - } - ); - break; - case 'folder': - $.post( - OC.filePath('files','ajax','newfolder.php'), - {dir:$('#dir').val(),foldername:name}, - function(result){ - if (result.status == 'success') { - var date=new Date(); - FileList.addDir(name,0,date,hidden); - var tr=$('tr').filterAttr('data-file',name); - tr.attr('data-id', result.data.id); - } else { - OC.dialogs.alert(result.data.message, t('core', 'Error')); + ); + break; + case 'folder': + $.post( + OC.filePath('files','ajax','newfolder.php'), + {dir:$('#dir').val(), foldername:name}, + function(result) { + if (result.status === 'success') { + var date=new Date(); + FileList.addDir(name, 0, date, hidden); + var tr=$('tr[data-file="'+name+'"]'); + tr.attr('data-id', result.data.id); + } else { + OC.dialogs.alert(result.data.message, t('core', 'Could not create folder')); + } } + ); + break; + case 'web': + if (name.substr(0,8) !== 'https://' && name.substr(0,7) !== 'http://') { + name = 'http://' + name; } - ); - break; - case 'web': - if(name.substr(0,8)!='https://' && name.substr(0,7)!='http://'){ - name='http://'+name; - } - var localName=name; - if(localName.substr(localName.length-1,1)=='/'){//strip / - localName=localName.substr(0,localName.length-1) - } - if(localName.indexOf('/')){//use last part of url - localName=localName.split('/').pop(); - } else { //or the domain - localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.',''); - } - localName = getUniqueName(localName); - //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length === 0) { - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); - } - - var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName}); - eventSource.listen('progress',function(progress){ + var localName=name; + if (localName.substr(localName.length-1,1)==='/') {//strip / + localName=localName.substr(0,localName.length-1); + } + if (localName.indexOf('/')) {//use last part of url + localName=localName.split('/').pop(); + } else { //or the domain + localName=(localName.match(/:\/\/(.[^\/]+)/)[1]).replace('www.',''); + } + localName = getUniqueName(localName); //IE < 10 does not fire the necessary events for the progress bar. - if($('html.lte9').length === 0) { - $('#uploadprogressbar').progressbar('value',progress); + if ($('html.lte9').length === 0) { + $('#uploadprogressbar').progressbar({value:0}); + $('#uploadprogressbar').fadeIn(); } - }); - eventSource.listen('success',function(data){ - var mime=data.mime; - var size=data.size; - var id=data.id; - $('#uploadprogressbar').fadeOut(); - var date=new Date(); - FileList.addFile(localName,size,date,false,hidden); - var tr=$('tr').filterAttr('data-file',localName); - tr.data('mime',mime).data('id',id); - tr.attr('data-id', id); - var path = $('#dir').val()+'/'+localName; - lazyLoadPreview(path, mime, function(previewpath){ - tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); + + var eventSource=new OC.EventSource(OC.filePath('files','ajax','newfile.php'),{dir:$('#dir').val(),source:name,filename:localName}); + eventSource.listen('progress',function(progress) { + //IE < 10 does not fire the necessary events for the progress bar. + if ($('html.lte9').length === 0) { + $('#uploadprogressbar').progressbar('value',progress); + } }); - }); - eventSource.listen('error',function(error){ - $('#uploadprogressbar').fadeOut(); - alert(error); - }); - break; + eventSource.listen('success',function(data) { + var mime = data.mime; + var size = data.size; + var id = data.id; + $('#uploadprogressbar').fadeOut(); + var date = new Date(); + FileList.addFile(localName, size, date, false, hidden); + var tr = $('tr[data-file="'+localName+'"]'); + tr.data('mime', mime).data('id', id); + tr.attr('data-id', id); + var path = $('#dir').val()+'/'+localName; + lazyLoadPreview(path, mime, function(previewpath) { + tr.find('td.filename').attr('style', 'background-image:url('+previewpath+')'); + }); + FileActions.display(tr.find('td.filename'), true); + }); + eventSource.listen('error',function(error) { + $('#uploadprogressbar').fadeOut(); + alert(error); + }); + break; + } + var li=form.parent(); + form.remove(); + /* workaround for IE 9&10 click event trap, 2 lines: */ + $('input').first().focus(); + $('#content').focus(); + li.append('

    '+li.data('text')+'

    '); + $('#new>a').click(); + } catch (error) { + input.attr('title', error); + input.tipsy({gravity: 'w', trigger: 'manual'}); + input.tipsy('show'); + input.addClass('error'); } - var li=form.parent(); - form.remove(); - /* workaround for IE 9&10 click event trap, 2 lines: */ - $('input').first().focus(); - $('#content').focus(); - li.append('

    '+li.data('text')+'

    '); - $('#new>a').click(); }); }); window.file_upload_param = file_upload_param; diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 84ff1093253..694ddb0c803 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1,7 +1,7 @@ var FileList={ useUndo:true, - postProcessList: function(){ - $('#fileList tr').each(function(){ + postProcessList: function() { + $('#fileList tr').each(function() { //little hack to set unescape filenames in attribute $(this).attr('data-file',decodeURIComponent($(this).attr('data-file'))); }); @@ -11,20 +11,20 @@ var FileList={ permissions = $('#permissions').val(), isCreatable = (permissions & OC.PERMISSION_CREATE) !== 0; $fileList.empty().html(fileListHtml); - $('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').length > 0); + $('#emptycontent').toggleClass('hidden', !isCreatable || $fileList.find('tr').exists()); $fileList.find('tr').each(function () { FileActions.display($(this).children('td.filename')); }); $fileList.trigger(jQuery.Event("fileActionsReady")); FileList.postProcessList(); // "Files" might not be loaded in extending apps - if (window.Files){ + if (window.Files) { Files.setupDragAndDrop(); } FileList.updateFileSummary(); $fileList.trigger(jQuery.Event("updated")); }, - createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions){ + createRow:function(type, name, iconurl, linktarget, size, lastModified, permissions) { var td, simpleSize, basename, extension; //containing tr var tr = $('
    ').addClass('filename').text(elem.name)); newtr.append($('').addClass('size').text(humanFileSize(elem.size))); @@ -461,14 +457,14 @@ var createDragShadow = function(event){ newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { var path = getPathForPreview(elem.name); - lazyLoadPreview(path, elem.mime, function(previewpath){ + lazyLoadPreview(path, elem.mime, function(previewpath) { newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); }); } }); return dragshadow; -} +}; //options for file drag/drop var dragOptions={ @@ -478,7 +474,7 @@ var dragOptions={ stop: function(event, ui) { $('#fileList tr td.filename').addClass('ui-draggable'); } -} +}; // sane browsers support using the distance option if ( $('html.ie').length === 0) { dragOptions['distance'] = 20; @@ -491,20 +487,20 @@ var folderDropOptions={ return false; } - var target=$.trim($(this).find('.nametext').text()); + var target = $.trim($(this).find('.nametext').text()); var files = ui.helper.find('tr'); - $(files).each(function(i,row){ + $(files).each(function(i,row) { var dir = $(row).data('dir'); var file = $(row).data('filename'); $.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: dir+'/'+target }, function(result) { if (result) { if (result.status === 'success') { //recalculate folder size - var oldSize = $('#fileList tr').filterAttr('data-file',target).data('size'); - var newSize = oldSize + $('#fileList tr').filterAttr('data-file',file).data('size'); - $('#fileList tr').filterAttr('data-file',target).data('size', newSize); - $('#fileList tr').filterAttr('data-file',target).find('td.filesize').text(humanFileSize(newSize)); + var oldSize = $('#fileList tr[data-file="'+target+'"]').data('size'); + var newSize = oldSize + $('#fileList tr[data-file="'+file+'"]').data('size'); + $('#fileList tr[data-file="'+target+'"]').data('size', newSize); + $('#fileList tr[data-file="'+target+'"]').find('td.filesize').text(humanFileSize(newSize)); FileList.remove(file); procesSelection(); @@ -521,24 +517,24 @@ var folderDropOptions={ }); }, tolerance: 'pointer' -} +}; var crumbDropOptions={ drop: function( event, ui ) { var target=$(this).data('dir'); - var dir=$('#dir').val(); - while(dir.substr(0,1)=='/'){//remove extra leading /'s + var dir = $('#dir').val(); + while(dir.substr(0,1) === '/') {//remove extra leading /'s dir=dir.substr(1); } - dir='/'+dir; - if(dir.substr(-1,1)!='/'){ - dir=dir+'/'; + dir = '/' + dir; + if (dir.substr(-1,1) !== '/') { + dir = dir + '/'; } - if(target==dir || target+'/'==dir){ + if (target === dir || target+'/' === dir) { return; } var files = ui.helper.find('tr'); - $(files).each(function(i,row){ + $(files).each(function(i,row) { var dir = $(row).data('dir'); var file = $(row).data('filename'); $.post(OC.filePath('files', 'ajax', 'move.php'), { dir: dir, file: file, target: target }, function(result) { @@ -559,13 +555,17 @@ var crumbDropOptions={ }); }, tolerance: 'pointer' -} +}; -function procesSelection(){ - var selected=getSelectedFilesTrash(); - var selectedFiles=selected.filter(function(el){return el.type=='file'}); - var selectedFolders=selected.filter(function(el){return el.type=='dir'}); - if(selectedFiles.length==0 && selectedFolders.length==0) { +function procesSelection() { + var selected = getSelectedFilesTrash(); + var selectedFiles = selected.filter(function(el) { + return el.type==='file'; + }); + var selectedFolders = selected.filter(function(el) { + return el.type==='dir'; + }); + if (selectedFiles.length === 0 && selectedFolders.length === 0) { $('#headerName>span.name').text(t('files','Name')); $('#headerSize').text(t('files','Size')); $('#modified').text(t('files','Modified')); @@ -574,22 +574,22 @@ function procesSelection(){ } else { $('.selectedActions').show(); - var totalSize=0; - for(var i=0;i0){ + var selection = ''; + if (selectedFolders.length > 0) { selection += n('files', '%n folder', '%n folders', selectedFolders.length); - if(selectedFiles.length>0){ - selection+=' & '; + if (selectedFiles.length > 0) { + selection += ' & '; } } - if(selectedFiles.length>0){ + if (selectedFiles.length>0) { selection += n('files', '%n file', '%n files', selectedFiles.length); } $('#headerName>span.name').text(selection); @@ -600,37 +600,37 @@ function procesSelection(){ /** * @brief get a list of selected files - * @param string property (option) the property of the file requested - * @return array + * @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 */ -function getSelectedFilesTrash(property){ +function getSelectedFilesTrash(property) { var elements=$('td.filename input:checkbox:checked').parent().parent(); var files=[]; - elements.each(function(i,element){ + elements.each(function(i,element) { var file={ name:$(element).attr('data-file'), mime:$(element).data('mime'), type:$(element).data('type'), size:$(element).data('size') }; - if(property){ + if (property) { files.push(file[property]); - }else{ + } else { files.push(file); } }); return files; } -function getMimeIcon(mime, ready){ - if(getMimeIcon.cache[mime]){ +function getMimeIcon(mime, ready) { + if (getMimeIcon.cache[mime]) { ready(getMimeIcon.cache[mime]); - }else{ - $.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path){ + } else { + $.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path) { getMimeIcon.cache[mime]=path; ready(getMimeIcon.cache[mime]); }); @@ -655,7 +655,7 @@ function lazyLoadPreview(path, mime, ready, width, height) { if ( ! height ) { height = $('#filestable').data('preview-y'); } - if( $('#publicUploadButtonMock').length ) { + if ( $('#publicUploadButtonMock').length ) { var previewURL = OC.Router.generate('core_ajax_public_preview', {file: path, x:width, y:height, t:$('#dirToken').val()}); } else { var previewURL = OC.Router.generate('core_ajax_preview', {file: path, x:width, y:height}); @@ -669,8 +669,8 @@ function lazyLoadPreview(path, mime, ready, width, height) { }); } -function getUniqueName(name){ - if($('tr').filterAttr('data-file',name).length>0){ +function getUniqueName(name) { + if ($('tr[data-file="'+name+'"]').exists()) { var parts=name.split('.'); var extension = ""; if (parts.length > 1) { @@ -679,9 +679,9 @@ function getUniqueName(name){ var base=parts.join('.'); numMatch=base.match(/\((\d+)\)/); var num=2; - if(numMatch && numMatch.length>0){ + if (numMatch && numMatch.length>0) { num=parseInt(numMatch[numMatch.length-1])+1; - base=base.split('(') + base=base.split('('); base.pop(); base=$.trim(base.join('(')); } @@ -695,19 +695,19 @@ function getUniqueName(name){ } function checkTrashStatus() { - $.post(OC.filePath('files_trashbin', 'ajax', 'isEmpty.php'), function(result){ + $.post(OC.filePath('files_trashbin', 'ajax', 'isEmpty.php'), function(result) { if (result.data.isEmpty === false) { $("input[type=button][id=trash]").removeAttr("disabled"); } }); } -function onClickBreadcrumb(e){ +function onClickBreadcrumb(e) { var $el = $(e.target).closest('.crumb'), $targetDir = $el.data('dir'); isPublic = !!$('#isPublic').val(); - if ($targetDir !== undefined && !isPublic){ + if ($targetDir !== undefined && !isPublic) { e.preventDefault(); FileList.changeDirectory(decodeURIComponent($targetDir)); } diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php index 579e8676cfc..ccf629ae3cb 100644 --- a/apps/files/lib/app.php +++ b/apps/files/lib/app.php @@ -52,7 +52,15 @@ class App { $result['data'] = array( 'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved by ownCloud") ); - } elseif( + // rename to existing file is denied + } else if ($this->view->file_exists($dir . '/' . $newname)) { + + $result['data'] = array( + 'message' => $this->l10n->t( + "The name %s is already used in the folder %s. Please choose a different name.", + array($newname, $dir)) + ); + } else if ( // rename to "." is denied $newname !== '.' and // rename of "/Shared" is denied diff --git a/core/js/js.js b/core/js/js.js index c17e3fa2959..f5991cfc9dd 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -933,7 +933,7 @@ jQuery.fn.selectRange = function(start, end) { */ jQuery.fn.exists = function(){ return this.length > 0; -} +}; /** * Calls the server periodically every 15 mins to ensure that session doesnt -- cgit v1.2.3 From e62ca4ea4fc235d7ec767034a80889b2fa331e97 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 28 Oct 2013 11:22:34 +0100 Subject: Append file etag to preview URLs Fixes #5534 --- apps/files/ajax/newfile.php | 3 +- apps/files/ajax/upload.php | 2 + apps/files/js/file-upload.js | 9 +++-- apps/files/js/filelist.js | 10 ++--- apps/files/js/files.js | 80 +++++++++++++++++++++++++------------- apps/files/lib/helper.php | 2 +- apps/files/templates/part.list.php | 1 + apps/files_sharing/public.php | 2 +- core/js/oc-dialogs.js | 6 +-- lib/private/helper.php | 4 +- 10 files changed, 75 insertions(+), 44 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/ajax/newfile.php b/apps/files/ajax/newfile.php index eed0047fc81..9d9a81ae3dc 100644 --- a/apps/files/ajax/newfile.php +++ b/apps/files/ajax/newfile.php @@ -89,7 +89,7 @@ if($source) { $meta = \OC\Files\Filesystem::getFileInfo($target); $mime=$meta['mimetype']; $id = $meta['fileid']; - $eventSource->send('success', array('mime'=>$mime, 'size'=>\OC\Files\Filesystem::filesize($target), 'id' => $id)); + $eventSource->send('success', array('mime'=>$mime, 'size'=>\OC\Files\Filesystem::filesize($target), 'id' => $id, 'etag' => $meta['etag'])); } else { $eventSource->send('error', $l10n->t('Error while downloading %s to %s', array($source, $target))); } @@ -119,6 +119,7 @@ if($source) { 'mime' => $mime, 'size' => $size, 'content' => $content, + 'etag' => $meta['etag'] ))); exit(); } diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 38c2a053a9e..0e905f993ac 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -132,6 +132,7 @@ if (strpos($dir, '..') === false) { 'size' => $meta['size'], 'id' => $meta['fileid'], 'name' => basename($target), + 'etag' => $meta['etag'], 'originalname' => $files['tmp_name'][$i], 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, @@ -158,6 +159,7 @@ if (strpos($dir, '..') === false) { 'size' => $meta['size'], 'id' => $meta['fileid'], 'name' => basename($target), + 'etag' => $meta['etag'], 'originalname' => $files['tmp_name'][$i], 'uploadMaxFilesize' => $maxUploadFileSize, 'maxHumanFilesize' => $maxHumanFileSize, diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 5bf4f5c0981..af67a0e2002 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -566,11 +566,12 @@ $(document).ready(function() { tr.attr('data-size', result.data.size); tr.attr('data-mime', result.data.mime); tr.attr('data-id', result.data.id); + tr.attr('data-etag', result.data.etag); tr.find('.filesize').text(humanFileSize(result.data.size)); var path = getPathForPreview(name); - lazyLoadPreview(path, result.data.mime, function(previewpath) { + Files.lazyLoadPreview(path, result.data.mime, function(previewpath) { tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); - }); + }, null, null, result.data.etag); FileActions.display(tr.find('td.filename'), true); } else { OC.dialogs.alert(result.data.message, t('core', 'Could not create file')); @@ -632,9 +633,9 @@ $(document).ready(function() { tr.data('mime', mime).data('id', id); tr.attr('data-id', id); var path = $('#dir').val()+'/'+localName; - lazyLoadPreview(path, mime, function(previewpath) { + Files.lazyLoadPreview(path, mime, function(previewpath) { tr.find('td.filename').attr('style', 'background-image:url('+previewpath+')'); - }); + }, null, null, data.etag); FileActions.display(tr.find('td.filename'), true); }); eventSource.listen('error',function(error) { diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index c33a06bbdc3..b05f42a79a8 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -326,9 +326,9 @@ var FileList={ tr.attr('data-id', id); } var path = getPathForPreview(name); - lazyLoadPreview(path, mime, function(previewpath) { + Files.lazyLoadPreview(path, mime, function(previewpath) { tr.find('td.filename').attr('style','background-image:url('+previewpath+')'); - }); + }, null, null, tr.attr('data-etag')); tr.find('td.filename').draggable(dragOptions); }, isLoading:function(name) { @@ -863,7 +863,7 @@ $(document).ready(function() { data.context = FileList.addFile(file.name, file.size, date, false, false, param); // update file data - data.context.attr('data-mime',file.mime).attr('data-id',file.id); + data.context.attr('data-mime',file.mime).attr('data-id',file.id).attr('data-etag', file.etag); var permissions = data.context.data('permissions'); if (permissions !== file.permissions) { @@ -873,9 +873,9 @@ $(document).ready(function() { FileActions.display(data.context.find('td.filename'), true); var path = getPathForPreview(file.name); - lazyLoadPreview(path, file.mime, function(previewpath) { + Files.lazyLoadPreview(path, file.mime, function(previewpath) { data.context.find('td.filename').attr('style','background-image:url('+previewpath+')'); - }); + }, null, null, file.etag); } } }); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 389bf1bf197..ee0fdcb43a9 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -20,6 +20,17 @@ Files={ } }, + + /** + * Fix path name by removing double slash at the beginning, if any + */ + fixPath: function(fileName) { + if (fileName.substr(0, 2) == '//') { + return fileName.substr(1); + } + return fileName; + }, + isFileNameValid:function (name) { if (name === '.') { throw t('files', '\'.\' is an invalid file name.'); @@ -457,9 +468,9 @@ var createDragShadow = function(event) { newtr.find('td.filename').attr('style','background-image:url('+OC.imagePath('core', 'filetypes/folder.png')+')'); } else { var path = getPathForPreview(elem.name); - lazyLoadPreview(path, elem.mime, function(previewpath) { + Files.lazyLoadPreview(path, elem.mime, function(previewpath) { newtr.find('td.filename').attr('style','background-image:url('+previewpath+')'); - }); + }, null, null, elem.etag); } }); @@ -626,26 +637,28 @@ function getSelectedFilesTrash(property) { return files; } -function getMimeIcon(mime, ready) { - if (getMimeIcon.cache[mime]) { - ready(getMimeIcon.cache[mime]); +Files.getMimeIcon = function(mime, ready) { + if (Files.getMimeIcon.cache[mime]) { + ready(Files.getMimeIcon.cache[mime]); } else { $.get( OC.filePath('files','ajax','mimeicon.php'), {mime: mime}, function(path) { - getMimeIcon.cache[mime]=path; - ready(getMimeIcon.cache[mime]); + Files.getMimeIcon.cache[mime]=path; + ready(Files.getMimeIcon.cache[mime]); }); } } -getMimeIcon.cache={}; +Files.getMimeIcon.cache={}; function getPathForPreview(name) { var path = $('#dir').val() + '/' + name; return path; } -function lazyLoadPreview(path, mime, ready, width, height) { +Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) { // get mime icon url - getMimeIcon(mime, function(iconURL) { + Files.getMimeIcon(mime, function(iconURL) { + var urlSpec = {}; + var previewURL; ready(iconURL); // set mimeicon URL // now try getting a preview thumbnail URL @@ -655,25 +668,38 @@ function lazyLoadPreview(path, mime, ready, width, height) { if ( ! height ) { height = $('#filestable').data('preview-y'); } + // note: the order of arguments must match the one + // from the server's template so that the browser + // knows it's the same file for caching + urlSpec.x = width; + urlSpec.y = height; + urlSpec.file = Files.fixPath(path); + + if (etag){ + // use etag as cache buster + urlSpec.c = etag; + } + else { + console.warn('Files.lazyLoadPreview(): missing etag argument'); + } + if ( $('#publicUploadButtonMock').length ) { - var previewURL = OC.Router.generate('core_ajax_public_preview', {file: path, x:width, y:height, t:$('#dirToken').val()}); + urlSpec.t = $('#dirToken').val(); + previewURL = OC.Router.generate('core_ajax_public_preview', urlSpec); } else { - var previewURL = OC.Router.generate('core_ajax_preview', {file: path, x:width, y:height}); - } - $.get(previewURL, function() { - previewURL = previewURL.replace('(', '%28'); - previewURL = previewURL.replace(')', '%29'); - previewURL += '&reload=true'; - - // preload image to prevent delay - // this will make the browser cache the image - var img = new Image(); - img.onload = function(){ - //set preview thumbnail URL - ready(previewURL); - } - img.src = previewURL; - }); + previewURL = OC.Router.generate('core_ajax_preview', urlSpec); + } + previewURL = previewURL.replace('(', '%28'); + previewURL = previewURL.replace(')', '%29'); + + // preload image to prevent delay + // this will make the browser cache the image + var img = new Image(); + img.onload = function(){ + //set preview thumbnail URL + ready(previewURL); + } + img.src = previewURL; }); } diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php index 709d78a4d45..7692dd67574 100644 --- a/apps/files/lib/helper.php +++ b/apps/files/lib/helper.php @@ -40,7 +40,7 @@ class Helper if($file['isPreviewAvailable']) { $pathForPreview = $file['directory'] . '/' . $file['name']; - return \OC_Helper::previewIcon($pathForPreview); + return \OC_Helper::previewIcon($pathForPreview) . '&c=' . $file['etag']; } return \OC_Helper::mimetypeIcon($file['mimetype']); } diff --git a/apps/files/templates/part.list.php b/apps/files/templates/part.list.php index a6d2e44f34f..2f630e1f014 100644 --- a/apps/files/templates/part.list.php +++ b/apps/files/templates/part.list.php @@ -16,6 +16,7 @@ $totalsize = 0; ?> data-type="" data-mime="" data-size="" + data-etag="" data-permissions=""> 36, 'y' => 36, 'file' => urlencode($path) )); + return self::linkToRoute( 'core_ajax_preview', array('x' => 36, 'y' => 36, 'file' => $path )); } public static function publicPreviewIcon( $path, $token ) { - return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path), 't' => $token)); + return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => $path, 't' => $token)); } /** -- cgit v1.2.3 From efbd79198b3fed8480566c81397f530dea7e7b5c Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 28 Oct 2013 15:41:52 +0100 Subject: Fixed preview URL + size while dragging an existing file --- apps/files/css/files.css | 3 ++- apps/files/js/files.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/css/files.css b/apps/files/css/files.css index af8597192f3..b9bf8cb87c1 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -320,8 +320,9 @@ table.dragshadow { width:auto; } table.dragshadow td.filename { - padding-left:36px; + padding-left:60px; padding-right:16px; + height: 36px; } table.dragshadow td.size { padding-right:8px; diff --git a/apps/files/js/files.js b/apps/files/js/files.js index ee0fdcb43a9..c0acfb4fc2b 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -480,7 +480,7 @@ var createDragShadow = function(event) { //options for file drag/drop var dragOptions={ revert: 'invalid', revertDuration: 300, - opacity: 0.7, zIndex: 100, appendTo: 'body', cursorAt: { left: -5, top: -5 }, + 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'); @@ -626,7 +626,8 @@ function getSelectedFilesTrash(property) { name:$(element).attr('data-file'), mime:$(element).data('mime'), type:$(element).data('type'), - size:$(element).data('size') + size:$(element).data('size'), + etag:$(element).data('etag') }; if (property) { files.push(file[property]); -- cgit v1.2.3 From a4be1ebeb8e596a1f44eae546dbe872544a219f0 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 31 Oct 2013 14:31:57 +0100 Subject: use data-file to retrieve filename forward port of https://github.com/owncloud/core/pull/5647#discussion-diff-7341163 trust me, I know what I'm doing --- apps/files/js/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 389bf1bf197..950dae2f925 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -487,7 +487,7 @@ var folderDropOptions={ return false; } - var target = $.trim($(this).find('.nametext').text()); + var target = $(this).parent('tr').data('file'); var files = ui.helper.find('tr'); $(files).each(function(i,row) { -- cgit v1.2.3 From adb5de4a888c01863b58cd50bd21ab2d4d17cace Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 31 Oct 2013 15:56:02 +0100 Subject: prefer closest over parent closest will search up the tree --- apps/files/js/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 950dae2f925..0b10fa8c63a 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -487,7 +487,7 @@ var folderDropOptions={ return false; } - var target = $(this).parent('tr').data('file'); + var target = $(this).closest('tr').data('file'); var files = ui.helper.find('tr'); $(files).each(function(i,row) { -- cgit v1.2.3 From b869fb2a0961e5cb5a6233626721b14f5e1cfdd8 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 5 Nov 2013 12:18:25 +0100 Subject: calling getstoragestats.php only if a user is logged in because this call requires a user to be logged in --- apps/files/js/files.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 5fa2b128153..eb30ddfda0f 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -357,24 +357,26 @@ $(document).ready(function() { Files.updateMaxUploadFilesize(response); }); } - - // start on load - we ask the server every 5 minutes - var update_storage_statistics_interval = 5*60*1000; - var update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval); - - // Use jquery-visibility to de-/re-activate file stats sync - if ($.support.pageVisibility) { - $(document).on({ - 'show.visibility': function() { - if (!update_storage_statistics_interval_id) { - update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval); + // only possible at the moment if user is logged in + if (OC.currentUser) { + // start on load - we ask the server every 5 minutes + var update_storage_statistics_interval = 5*60*1000; + var update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval); + + // Use jquery-visibility to de-/re-activate file stats sync + if ($.support.pageVisibility) { + $(document).on({ + 'show.visibility': function() { + if (!update_storage_statistics_interval_id) { + update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval); + } + }, + 'hide.visibility': function() { + clearInterval(update_storage_statistics_interval_id); + update_storage_statistics_interval_id = 0; } - }, - 'hide.visibility': function() { - clearInterval(update_storage_statistics_interval_id); - update_storage_statistics_interval_id = 0; - } - }); + }); + } } //scroll to and highlight preselected file -- cgit v1.2.3 From 5d9ab6e7ac161a2431d9baca59281c03015b4ff5 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 6 Nov 2013 10:15:05 +0100 Subject: Update quota value in client after scan and upload After uploading, the quota value wasn't refreshed. This fix refreshes the quota value after files have been scanned or uploaded. --- apps/files/js/file-upload.js | 2 +- apps/files/js/filelist.js | 1 + apps/files/js/files.js | 43 +++++++++++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 13 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 94290895ebd..553ca036360 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -404,7 +404,7 @@ $(document).ready(function() { $('#uploadprogresswrapper input.stop').fadeOut(); $('#uploadprogressbar').fadeOut(); - + Files.updateStorageStatistics(); }); fileupload.on('fileuploadfail', function(e, data) { OC.Upload.log('progress handle fileuploadfail', e, data); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 3ef3c2c1766..66b4a006f88 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -554,6 +554,7 @@ var FileList={ checkTrashStatus(); FileList.updateFileSummary(); FileList.updateEmptyContent(); + Files.updateStorageStatistics(); } else { $.each(files,function(index,file) { var deleteAction = $('tr[data-file="'+files[i]+'"]').children("td.date").children(".action.delete"); diff --git a/apps/files/js/files.js b/apps/files/js/files.js index eb30ddfda0f..a7aea0957bd 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -1,4 +1,28 @@ Files={ + // file space size sync + _updateStorageStatistics: function() { + Files._updateStorageStatisticsTimeout = null; + if (Files.updateStorageStatistics.running){ + return; + } + Files.updateStorageStatistics.running = true; + $.getJSON(OC.filePath('files','ajax','getstoragestats.php'),function(response) { + Files.updateStorageStatistics.running = false; + Files.updateMaxUploadFilesize(response); + }); + }, + updateStorageStatistics: function() { + if (!OC.currentUser) { + return; + } + + // debounce to prevent calling too often + if (Files._updateStorageStatisticsTimeout) { + clearTimeout(Files._updateStorageStatisticsTimeout); + } + Files._updateStorageStatisticsTimeout = setTimeout(Files._updateStorageStatistics, 1000); + }, + updateMaxUploadFilesize:function(response) { if (response === undefined) { return; @@ -351,29 +375,23 @@ $(document).ready(function() { setTimeout ( "Files.displayStorageWarnings()", 100 ); OC.Notification.setDefault(Files.displayStorageWarnings); - // file space size sync - function update_storage_statistics() { - $.getJSON(OC.filePath('files','ajax','getstoragestats.php'),function(response) { - Files.updateMaxUploadFilesize(response); - }); - } // only possible at the moment if user is logged in if (OC.currentUser) { // start on load - we ask the server every 5 minutes - var update_storage_statistics_interval = 5*60*1000; - var update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval); + var updateStorageStatisticsInterval = 5*60*1000; + var updateStorageStatisticsIntervalId = setInterval(Files.updateStorageStatistics, updateStorageStatisticsInterval); // Use jquery-visibility to de-/re-activate file stats sync if ($.support.pageVisibility) { $(document).on({ 'show.visibility': function() { - if (!update_storage_statistics_interval_id) { - update_storage_statistics_interval_id = setInterval(update_storage_statistics, update_storage_statistics_interval); + if (!updateStorageStatisticsIntervalId) { + updateStorageStatisticsIntervalId = setInterval(Files.updateStorageStatistics, updateStorageStatisticsInterval); } }, 'hide.visibility': function() { - clearInterval(update_storage_statistics_interval_id); - update_storage_statistics_interval_id = 0; + clearInterval(updateStorageStatisticsIntervalId); + updateStorageStatisticsIntervalId = 0; } }); } @@ -417,6 +435,7 @@ function scanFiles(force, dir, users) { scannerEventSource.listen('done',function(count) { scanFiles.scanning=false; console.log('done after ' + count + ' files'); + Files.updateStorageStatistics(); }); scannerEventSource.listen('user',function(user) { console.log('scanning files for ' + user); -- cgit v1.2.3 From 31181e4348b9af2625cf4d6ad38cf4cd81db3c1f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 6 Nov 2013 10:55:19 +0100 Subject: Fixed storage stats to be based on current directory Previously, the storage statistics were always for the root dir. This means that the upload button would always show the limit for the root dir, even when uploading to a shared dir or external storage. This fix adds a "dir" argument to getstoragestats.php. --- apps/files/ajax/getstoragestats.php | 8 +++++++- apps/files/js/filelist.js | 7 +++++++ apps/files/js/files.js | 26 +++++++++++++++++++------- 3 files changed, 33 insertions(+), 8 deletions(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/ajax/getstoragestats.php b/apps/files/ajax/getstoragestats.php index 32a77bff6c3..dd7c7dc5571 100644 --- a/apps/files/ajax/getstoragestats.php +++ b/apps/files/ajax/getstoragestats.php @@ -3,7 +3,13 @@ // only need filesystem apps $RUNTIME_APPTYPES = array('filesystem'); +$dir = '/'; + +if (isset($_GET['dir'])) { + $dir = $_GET['dir']; +} + OCP\JSON::checkLoggedIn(); // send back json -OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics('/'))); +OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir))); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 66b4a006f88..006bd1f4966 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -152,6 +152,9 @@ var FileList={ FileActions.display(tr.find('td.filename'), true); return tr; }, + getCurrentDirectory: function(){ + return $('#dir').val() || '/'; + }, /** * @brief Changes the current directory and reload the file list. * @param targetDir target directory (non URL encoded) @@ -224,6 +227,10 @@ var FileList={ return; } + // TODO: should rather return upload file size through + // the files list ajax call + Files.updateStorageStatistics(true); + if (result.data.permissions) { FileList.setDirectoryPermissions(result.data.permissions); } diff --git a/apps/files/js/files.js b/apps/files/js/files.js index a7aea0957bd..2947512ece5 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -2,16 +2,23 @@ Files={ // file space size sync _updateStorageStatistics: function() { Files._updateStorageStatisticsTimeout = null; - if (Files.updateStorageStatistics.running){ - return; + var currentDir = FileList.getCurrentDirectory(), + state = Files.updateStorageStatistics; + if (state.dir){ + if (state.dir === currentDir) { + return; + } + // cancel previous call, as it was for another dir + state.call.abort(); } - Files.updateStorageStatistics.running = true; - $.getJSON(OC.filePath('files','ajax','getstoragestats.php'),function(response) { - Files.updateStorageStatistics.running = false; + state.dir = currentDir; + state.call = $.getJSON(OC.filePath('files','ajax','getstoragestats.php') + '?dir=' + encodeURIComponent(currentDir),function(response) { + state.dir = null; + state.call = null; Files.updateMaxUploadFilesize(response); }); }, - updateStorageStatistics: function() { + updateStorageStatistics: function(force) { if (!OC.currentUser) { return; } @@ -20,7 +27,12 @@ Files={ if (Files._updateStorageStatisticsTimeout) { clearTimeout(Files._updateStorageStatisticsTimeout); } - Files._updateStorageStatisticsTimeout = setTimeout(Files._updateStorageStatistics, 1000); + if (force) { + Files._updateStorageStatistics(); + } + else { + Files._updateStorageStatisticsTimeout = setTimeout(Files._updateStorageStatistics, 250); + } }, updateMaxUploadFilesize:function(response) { -- cgit v1.2.3 From e285e84e18aa622fd97cde0c9ae41185c06d78df Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 11 Nov 2013 17:14:40 +0100 Subject: Selection summary is now displayed properly Fixes #5775 --- apps/files/js/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files/js/files.js') diff --git a/apps/files/js/files.js b/apps/files/js/files.js index 2947512ece5..fdaa3aa3342 100644 --- a/apps/files/js/files.js +++ b/apps/files/js/files.js @@ -636,7 +636,7 @@ function procesSelection() { if (selectedFiles.length>0) { selection += n('files', '%n file', '%n files', selectedFiles.length); } - $('#headerName>span.name').text(selection); + $('#headerName span.name').text(selection); $('#modified').text(''); $('table').addClass('multiselect'); } -- cgit v1.2.3