From a878bd9923f68ce35146357fe089749f62ab0e27 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 9 Apr 2013 13:31:12 +0200 Subject: fix allowed rename of folder in root directory to reserved name "Shared" refs #2159 --- apps/files/ajax/rename.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index 9fd2ce3ad4b..d9b59c6e487 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -13,7 +13,7 @@ $newname = stripslashes($_GET["newname"]); $l = OC_L10N::get('files'); -if ( $newname !== '.' and ($dir != '' || $file != 'Shared') and $newname !== '.') { +if ( $newname !== '.' and ($dir != '' || $file != 'Shared') and $newname !== 'Shared' ) { $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname); $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file); if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) { @@ -21,6 +21,8 @@ if ( $newname !== '.' and ($dir != '' || $file != 'Shared') and $newname !== '.' } else { OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") ))); } -}else{ +} elseif( $newname === 'Shared' ) { + OCP\JSON::error(array("data" => array( "message" => $l->t("Invalid folder name. Usage of 'Shared' is reserved by Owncloud") ))); +} else { OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") ))); } -- cgit v1.2.3 From b393c91a96aeb1346add8e0cb5a62747b07379f0 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 9 Apr 2013 13:44:54 +0200 Subject: wrong root dir name --- apps/files/ajax/rename.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index d9b59c6e487..50bbe54bd25 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -13,7 +13,7 @@ $newname = stripslashes($_GET["newname"]); $l = OC_L10N::get('files'); -if ( $newname !== '.' and ($dir != '' || $file != 'Shared') and $newname !== 'Shared' ) { +if ( $newname !== '.' and ($dir != '/' || $file != 'Shared') and ($dir !== '/' || $newname !== 'Shared') ) { $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname); $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file); if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) { @@ -21,7 +21,7 @@ if ( $newname !== '.' and ($dir != '' || $file != 'Shared') and $newname !== 'Sh } else { OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") ))); } -} elseif( $newname === 'Shared' ) { +} elseif( $dir === '/' and $newname === 'Shared' ) { OCP\JSON::error(array("data" => array( "message" => $l->t("Invalid folder name. Usage of 'Shared' is reserved by Owncloud") ))); } else { OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") ))); -- cgit v1.2.3 From 33b31931bddb6932c35f2ab9ec6bce9ea723509a Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 9 Apr 2013 13:54:01 +0200 Subject: string comparision --- apps/files/ajax/rename.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index 50bbe54bd25..a0785f52df2 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -13,7 +13,7 @@ $newname = stripslashes($_GET["newname"]); $l = OC_L10N::get('files'); -if ( $newname !== '.' and ($dir != '/' || $file != 'Shared') and ($dir !== '/' || $newname !== 'Shared') ) { +if ( $newname !== '.' and ($dir !== '/' || $file !== 'Shared') and ($dir !== '/' || $newname !== 'Shared') ) { $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname); $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file); if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) { -- cgit v1.2.3 From 1020d5c16c452145b25725b71bc3269dceddbe6e Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 6 May 2013 20:45:04 +0200 Subject: [files] refactoring --- apps/files/ajax/rename.php | 50 ++++++++++++++++++----------- apps/files/lib/files.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 apps/files/lib/files.php (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index a0785f52df2..641655a9ea5 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -1,28 +1,40 @@ . + * + */ +require_once realpath( dirname(__FILE__).'/../lib/files.php' ); OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); -// Get data -$dir = stripslashes($_GET["dir"]); -$file = stripslashes($_GET["file"]); -$newname = stripslashes($_GET["newname"]); +$files = new \OCA\Files\Files(); +$result = $files->rename( + stripslashes($_GET["dir"]), + stripslashes($_GET["file"]), + stripslashes($_GET["newname"]) +); -$l = OC_L10N::get('files'); - -if ( $newname !== '.' and ($dir !== '/' || $file !== 'Shared') and ($dir !== '/' || $newname !== 'Shared') ) { - $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname); - $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file); - if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) { - OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname ))); - } else { - OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") ))); - } -} elseif( $dir === '/' and $newname === 'Shared' ) { - OCP\JSON::error(array("data" => array( "message" => $l->t("Invalid folder name. Usage of 'Shared' is reserved by Owncloud") ))); +if($result['success'] === true){ + OCP\JSON::success(array('data' => $result['data'])); } else { - OCP\JSON::error(array("data" => array( "message" => $l->t("Unable to rename file") ))); -} + OCP\JSON::error(array('data' => $result['data'])); +} \ No newline at end of file diff --git a/apps/files/lib/files.php b/apps/files/lib/files.php new file mode 100644 index 00000000000..3cbeb384794 --- /dev/null +++ b/apps/files/lib/files.php @@ -0,0 +1,80 @@ +. + * + */ + + +namespace OCA\Files; + +class Files { + private $l10n; + + public function __construct() { + $this->l10n = \OC_L10n::get('files'); + } + + /** + * rename a file + * + * @param string $dir + * @param string $oldname + * @param string $newname + * @return array + */ + public function rename($dir, $oldname, $newname) { + $result = array( + 'success' => false, + 'data' => NULL + ); + + // rename to "Shared" in root directory denied + if( $dir === '/' and $newname === 'Shared' ) { + $result['data'] = array( + 'message' => $this->t("Invalid folder name. Usage of 'Shared' is reserved by Owncloud") + ); + } elseif( + // rename to "." is denied + $newname !== '.' and + // rename to "Shared" inside the root directory is denied + !($dir === '/' and $file === 'Shared') and + // THEN try to rename + \OC\Files\Filesystem::rename( + \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname), + \OC\Files\Filesystem::normalizePath($dir . '/' . $newname) + ) + ) { + // successful rename + $result['success'] = true; + $result['data'] = array( + 'dir' => $dir, + 'file' => $oldname, + 'newname' => $newname + ); + } else { + // rename failed + $result['data'] = array( + 'message' => $this->t('Unable to rename file') + ); + } + return $result; + } + +} \ No newline at end of file -- cgit v1.2.3 From 324c423548a708720a6f4247bb10be2f1314bd37 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 6 May 2013 20:59:26 +0200 Subject: [files] kill stripslashes --- apps/files/ajax/rename.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index 641655a9ea5..cb7a178852d 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -28,9 +28,9 @@ OCP\JSON::callCheck(); $files = new \OCA\Files\Files(); $result = $files->rename( - stripslashes($_GET["dir"]), - stripslashes($_GET["file"]), - stripslashes($_GET["newname"]) + $_GET["dir"], + $_GET["file"], + $_GET["newname"] ); if($result['success'] === true){ -- cgit v1.2.3 From b9f426b1d70b1818aab9d54630b8d858a7e5a4dd Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 7 May 2013 13:36:29 +0200 Subject: [files] remove normalizePath on rename and dependency injection --- apps/files/ajax/rename.php | 5 ++++- apps/files/lib/files.php | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index cb7a178852d..f01932a73c3 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -26,7 +26,10 @@ require_once realpath( dirname(__FILE__).'/../lib/files.php' ); OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); -$files = new \OCA\Files\Files(); +$files = new \OCA\Files\Files( + \OC\Files\Filesystem::getView(), + \OC_L10n::get('files') +); $result = $files->rename( $_GET["dir"], $_GET["file"], diff --git a/apps/files/lib/files.php b/apps/files/lib/files.php index 02582eff20a..d5fdc8dde78 100644 --- a/apps/files/lib/files.php +++ b/apps/files/lib/files.php @@ -27,8 +27,9 @@ namespace OCA\Files; class Files { private $l10n; - public function __construct() { - $this->l10n = \OC_L10n::get('files'); + public function __construct($view, $l10n) { + $this->view = $view; + $this->l10n = $l10n; } /** @@ -56,10 +57,7 @@ class Files { // rename of "/Shared" is denied !($dir === '/' and $oldname === 'Shared') and // THEN try to rename - \OC\Files\Filesystem::rename( - \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname), - \OC\Files\Filesystem::normalizePath($dir . '/' . $newname) - ) + $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname) ) { // successful rename $result['success'] = true; -- cgit v1.2.3 From b777c0fd7501c59f0389c34303e98867e94cd20b Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 8 May 2013 11:56:59 +0200 Subject: [files] rename lib to "App" --- apps/files/ajax/rename.php | 4 +-- apps/files/lib/app.php | 78 ++++++++++++++++++++++++++++++++++++++++ apps/files/lib/files.php | 78 ---------------------------------------- apps/files/tests/ajax_rename.php | 8 ++--- 4 files changed, 84 insertions(+), 84 deletions(-) create mode 100644 apps/files/lib/app.php delete mode 100644 apps/files/lib/files.php (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index f01932a73c3..d9ba68428ee 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -21,12 +21,12 @@ * */ -require_once realpath( dirname(__FILE__).'/../lib/files.php' ); +require_once realpath( dirname(__FILE__).'/../lib/app.php' ); OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); -$files = new \OCA\Files\Files( +$files = new \OCA\Files\App( \OC\Files\Filesystem::getView(), \OC_L10n::get('files') ); diff --git a/apps/files/lib/app.php b/apps/files/lib/app.php new file mode 100644 index 00000000000..7cd6143e6c1 --- /dev/null +++ b/apps/files/lib/app.php @@ -0,0 +1,78 @@ +. + * + */ + + +namespace OCA\Files; + +class App { + private $l10n; + + public function __construct($view, $l10n) { + $this->view = $view; + $this->l10n = $l10n; + } + + /** + * rename a file + * + * @param string $dir + * @param string $oldname + * @param string $newname + * @return array + */ + public function rename($dir, $oldname, $newname) { + $result = array( + 'success' => false, + 'data' => NULL + ); + + // rename to "/Shared" is denied + if( $dir === '/' and $newname === 'Shared' ) { + $result['data'] = array( + 'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved by ownCloud") + ); + } elseif( + // rename to "." is denied + $newname !== '.' and + // rename of "/Shared" is denied + !($dir === '/' and $oldname === 'Shared') and + // THEN try to rename + $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname) + ) { + // successful rename + $result['success'] = true; + $result['data'] = array( + 'dir' => $dir, + 'file' => $oldname, + 'newname' => $newname + ); + } else { + // rename failed + $result['data'] = array( + 'message' => $this->l10n->t('Unable to rename file') + ); + } + return $result; + } + +} \ No newline at end of file diff --git a/apps/files/lib/files.php b/apps/files/lib/files.php deleted file mode 100644 index 2d47fcf4ad3..00000000000 --- a/apps/files/lib/files.php +++ /dev/null @@ -1,78 +0,0 @@ -. - * - */ - - -namespace OCA\Files; - -class Files { - private $l10n; - - public function __construct($view, $l10n) { - $this->view = $view; - $this->l10n = $l10n; - } - - /** - * rename a file - * - * @param string $dir - * @param string $oldname - * @param string $newname - * @return array - */ - public function rename($dir, $oldname, $newname) { - $result = array( - 'success' => false, - 'data' => NULL - ); - - // rename to "/Shared" is denied - if( $dir === '/' and $newname === 'Shared' ) { - $result['data'] = array( - 'message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved by ownCloud") - ); - } elseif( - // rename to "." is denied - $newname !== '.' and - // rename of "/Shared" is denied - !($dir === '/' and $oldname === 'Shared') and - // THEN try to rename - $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname) - ) { - // successful rename - $result['success'] = true; - $result['data'] = array( - 'dir' => $dir, - 'file' => $oldname, - 'newname' => $newname - ); - } else { - // rename failed - $result['data'] = array( - 'message' => $this->l10n->t('Unable to rename file') - ); - } - return $result; - } - -} \ No newline at end of file diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index dee956dc8c8..6dc7c120b3b 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -22,9 +22,9 @@ */ -require_once dirname(__FILE__).'/../lib/files.php'; +require_once dirname(__FILE__).'/../lib/app.php'; -class Test_OC_Files_Files_Rename extends \PHPUnit_Framework_TestCase { +class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { function setUp() { // mock OC_L10n @@ -39,7 +39,7 @@ class Test_OC_Files_Files_Rename extends \PHPUnit_Framework_TestCase { $viewMock->expects($this->any()) ->method('rename') ->will($this->returnValue(true)); - $this->files = new \OCA\Files\Files($viewMock, $l10nMock); + $this->files = new \OCA\Files\App($viewMock, $l10nMock); } /** @@ -91,7 +91,7 @@ class Test_OC_Files_Files_Rename extends \PHPUnit_Framework_TestCase { $result = $this->files->rename($dir, $oldname, $newname); $expected = array( 'success' => false, - 'data' => array('message' => "Invalid folder name. Usage of 'Shared' is reserved by Owncloud") + 'data' => array('message' => "Invalid folder name. Usage of 'Shared' is reserved by ownCloud") ); $this->assertEquals($expected, $result); -- cgit v1.2.3 From e2bd32323d30cb5da7b2e1433d09effd33ef987d Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Sun, 12 May 2013 13:02:01 +0200 Subject: [files] fix mock creation and remove hardcoded 'require' statement --- apps/files/ajax/rename.php | 2 -- apps/files/tests/ajax_rename.php | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rename.php b/apps/files/ajax/rename.php index d9ba68428ee..f4551858283 100644 --- a/apps/files/ajax/rename.php +++ b/apps/files/ajax/rename.php @@ -21,8 +21,6 @@ * */ -require_once realpath( dirname(__FILE__).'/../lib/app.php' ); - OCP\JSON::checkLoggedIn(); OCP\JSON::callCheck(); diff --git a/apps/files/tests/ajax_rename.php b/apps/files/tests/ajax_rename.php index 6dc7c120b3b..23e5761ddda 100644 --- a/apps/files/tests/ajax_rename.php +++ b/apps/files/tests/ajax_rename.php @@ -21,18 +21,15 @@ * */ - -require_once dirname(__FILE__).'/../lib/app.php'; - class Test_OC_Files_App_Rename extends \PHPUnit_Framework_TestCase { function setUp() { // mock OC_L10n - $l10nMock = $this->getMock('\OC_L10N', array('t')); + $l10nMock = $this->getMock('\OC_L10N', array('t'), array(), '', false); $l10nMock->expects($this->any()) ->method('t') ->will($this->returnArgument(0)); - $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath')); + $viewMock = $this->getMock('\OC\Files\View', array('rename', 'normalizePath'), array(), '', false); $viewMock->expects($this->any()) ->method('normalizePath') ->will($this->returnArgument(0)); -- cgit v1.2.3 From 152e275c8a780c220c5022ef059dd7b12adc7cf1 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Fri, 17 May 2013 04:54:08 +0200 Subject: Various cleanups in OC.dialogs --- apps/files/ajax/rawlist.php | 8 ++ core/css/styles.css | 15 +-- core/js/oc-dialogs.js | 235 +++++++++++++++++------------------------ core/templates/filepicker.html | 8 +- 4 files changed, 118 insertions(+), 148 deletions(-) (limited to 'apps/files/ajax') diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 1cd2944483c..f568afad4da 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -15,6 +15,14 @@ $mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : ''; // make filelist $files = array(); +// If a type other than directory is requested first load them. +if($mimetype && strpos($mimetype, 'httpd/unix-directory') === false) { + foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $i ) { + $i["date"] = OCP\Util::formatDate($i["mtime"] ); + $i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']); + $files[] = $i; + } +} foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $i ) { $i["date"] = OCP\Util::formatDate($i["mtime"] ); $i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']); diff --git a/core/css/styles.css b/core/css/styles.css index ee00196d669..2038417685c 100644 --- a/core/css/styles.css +++ b/core/css/styles.css @@ -382,13 +382,14 @@ a.bookmarklet { background-color:#ddd; border:1px solid #ccc; padding:5px;paddin .ui-datepicker-prev,.ui-datepicker-next{ border:1px solid #ddd; background:#fff; } /* ---- DIALOGS ---- */ -#dirup {width:4%;} -#dirtree {width:92%;} -#filelist {height:270px; overflow-y:auto; background-color:white; width:100%;} -#filelist img { margin: 2px 1em 0 4px; } -#filelist .date { float:right;margin-right:1em; } -.filepicker_element_selected { background-color:lightblue;} -.filepicker_loader {height:170px; width:100%; background-color:#333; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; filter:alpha(opacity=30); opacity:.3; visibility:visible; position:absolute; top:0; left:0; text-align:center; padding-top:150px;} +#oc-dialog-filepicker-content .dirup {width:4%; font-weight: bold;} +#oc-dialog-filepicker-content .dirtree {width:92%; overflow:hidden; font-weight: bold; } +#oc-dialog-filepicker-content .dirtree span { cursor: pointer; } +#oc-dialog-filepicker-content .dirtree span:not(last-child)::after { content: '>'; padding: 3px;} +#oc-dialog-filepicker-content .filelist {height:270px; overflow-y:auto; background-color:white; width:100%;} +#oc-dialog-filepicker-content .filelist img { margin: 2px 1em 0 4px; } +#oc-dialog-filepicker-content .filelist .date { float:right;margin-right:1em; } +#oc-dialog-filepicker-content .filepicker_element_selected { background-color:lightblue;} .ui-dialog {position:fixed !important;} span.ui-icon {float: left; margin: 3px 7px 30px 0;} .loading { background: url('../img/loading.gif') no-repeat center; cursor: wait; } diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 89897382878..4da9623c0a7 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -133,7 +133,7 @@ var OCdialogs = { var self = this; $.get(OC.filePath('core', 'templates', 'filepicker.html'), function(tmpl) { self.$filePickerTemplate = $(tmpl); - self.$listTmpl = self.$filePickerTemplate.find('#filelist li:first-child').detach(); + self.$listTmpl = self.$filePickerTemplate.find('.filelist li:first-child').detach(); defer.resolve(self.$filePickerTemplate); }) .fail(function() { @@ -160,6 +160,12 @@ var OCdialogs = { } return defer.promise(); }, + _getFileList: function(dir, mimeType) { + return $.getJSON( + OC.filePath('files', 'ajax', 'rawlist.php'), + {dir: dir, mimetype: mimeType} + ); + }, /** * show a file picker to pick a file from * @param title dialog title @@ -169,35 +175,35 @@ var OCdialogs = { * @param modal make the dialog modal */ filepicker:function(title, callback, multiselect, mimetype_filter, modal) { + var self = this; $.when(this._getFilePickerTemplate()).then(function($tmpl) { - var dialog_name = 'oc-dialog-' + OCdialogs.dialogs_counter + '-content'; + var dialog_name = 'oc-dialog-filepicker-content'; var dialog_id = '#' + dialog_name; - var $dlg = $tmpl.octemplate({ + if(self.$filePicker) { + self.$filePicker.dialog('close'); + } + self.$filePicker = $tmpl.octemplate({ dialog_name: dialog_name, title: title - }).data('path', '/'); + }).data('path', ''); if (modal === undefined) { modal = false }; if (multiselect === undefined) { multiselect = false }; if (mimetype_filter === undefined) { mimetype_filter = '' }; - $('body').append($dlg); + $('body').append(self.$filePicker); - $dlg.find('#dirtree').focus().change( {dcid: dialog_id}, OCdialogs.handleTreeListSelect ); - $dlg.find('#dirup').click( {dcid: dialog_id}, OCdialogs.filepickerDirUp ); - $dlg.find('#filelist').empty().addClass('loading'); - $dlg.ready(function(){ - $.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), - {mimetype: mimetype_filter}, - function(response) { - OCdialogs.fillFilePicker(response, dialog_id); - }); - $.getJSON(OC.filePath('files', 'ajax', 'rawlist.php'), - {mimetype: 'httpd/unix-directory'}, - function(response) { - OCdialogs.fillTreeList(response, dialog_id); + self.$filePicker.ready(function() { + self.$filelist = self.$filePicker.find('.filelist'); + self.$dirUp = self.$filePicker.find('.dirup'); + self.$dirTree = self.$filePicker.find('.dirtree'); + self.$dirTree.on('click', 'span', self, self.handleTreeListSelect); + self.$dirUp.click(self, self.filepickerDirUp); + self.$filelist.on('click', 'li', function(event) { + self.handlePickerClick(event, $(this)); }); + self.fillFilePicker(''); }).data('multiselect', multiselect).data('mimetype',mimetype_filter); // build buttons @@ -206,15 +212,15 @@ var OCdialogs = { var datapath; if (multiselect === true) { datapath = []; - $(dialog_id + ' .filepicker_element_selected .filename').each(function(index, element) { - datapath.push( $(dialog_id).data('path') + $(element).text() ); + self.$filelist.find('.filepicker_element_selected .filename').each(function(index, element) { + datapath.push(self.$filePicker.data('path') + '/' + $(element).text()); }); } else { - var datapath = $(dialog_id).data('path'); - datapath += $(dialog_id+' .filepicker_element_selected .filename').text(); + var datapath = self.$filePicker.data('path'); + datapath += '/' + self.$filelist.find('.filepicker_element_selected .filename').text(); } callback(datapath); - $(dialog_id).dialog('close'); + self.$filePicker.dialog('close'); } }; var buttonlist = [{ @@ -223,16 +229,19 @@ var OCdialogs = { }, { text: t('core', 'Cancel'), - click: function(){$(dialog_id).dialog('close'); } + click: function(){self.$filePicker.dialog('close'); } }]; - $(dialog_id).dialog({ + self.$filePicker.dialog({ width: (4/9)*$(document).width(), height: 420, modal: modal, - buttons: buttonlist + buttons: buttonlist, + close: function(event, ui) { + self.$filePicker.dialog('destroy').remove(); + self.$filePicker = null; + } }); - OCdialogs.dialogs_counter++; }) .fail(function() { alert(t('core', 'Error loading file picker template')); @@ -340,146 +349,98 @@ var OCdialogs = { /** * fills the filepicker with files */ - fillFilePicker:function(request, dialog_content_id) { - var $filelist = $(dialog_content_id + ' #filelist').empty(); - var files = ''; + fillFilePicker:function(dir) { var dirs = []; var others = []; - $.each(request.data, function(index, file) { - if (file.type === 'dir') { - dirs.push(file); - } else { - others.push(file); - } - }); - - var sorted = dirs.concat(others); - var self = this; - $.each(sorted, function(idx, entry) { - $li = self.$listTmpl.octemplate({ - type: entry.type, - dcid: dialog_content_id, - imgsrc: entry.mimetype_icon, - filename: entry.name, - date: OC.mtime2date(entry.mtime) + this.$filelist.empty().addClass('loading'); + this.$filePicker.data('path', dir); + $.when(this._getFileList(dir, this.$filePicker.data('mimetype'))).then(function(response) { + $.each(response.data, function(index, file) { + if (file.type === 'dir') { + dirs.push(file); + } else { + others.push(file); + } }); - $filelist.append($li); - }); - $filelist.removeClass('loading'); + self.fillTreeList(); + var sorted = dirs.concat(others); - $filelist.on('click', 'li', function() { - OCdialogs.handlePickerClick($(this), $(this).data('entryname'), dialog_content_id); - }); + $.each(sorted, function(idx, entry) { + $li = self.$listTmpl.octemplate({ + type: entry.type, + dir: dir, + imgsrc: entry.mimetype_icon, + filename: entry.name, + date: OC.mtime2date(entry.mtime) + }); + self.$filelist.append($li); + }); - $(dialog_content_id + ' .filepicker_loader').css('visibility', 'hidden'); + self.$filelist.removeClass('loading'); + }); }, /** * fills the tree list with directories */ - fillTreeList: function(request, dialog_id) { - var $dirtree = $(dialog_id + ' #dirtree').empty(); - var $template = $(''); - $dirtree.append($template.octemplate({ - count: 0, - name: $(dialog_id).data('path') - })); - $.each(request.data, function(index, file) { - $dirtree.append($template.octemplate({ - count: index, - name: file.name + fillTreeList: function() { + this.$dirTree.empty(); + var self = this + var path = this.$filePicker.data('path'); + if(!path) { + return; + } + var $template = $('{name}'); + var paths = path.split('/'); + paths.pop(); + $.each(paths, function(index, dir) { + var dir = paths.pop(); + if(dir === '') { + return false; + } + self.$dirTree.prepend($template.octemplate({ + dir: paths.join('/') + '/' + dir, + name: dir })); }); + self.$dirTree.prepend($template.octemplate({ + dir: '', + name: '/' + })); }, /** * handle selection made in the tree list */ handleTreeListSelect:function(event) { - // if there's a slash in the selected path, don't append it - if ($('option:selected', this).html().indexOf('/') !== -1) { - $(event.data.dcid).data('path', $('option:selected', this).html()); - } else { - $(event.data.dcid).data('path', $(event.data.dcid).data('path') + $('option:selected', this).html() + '/'); - } - $(event.data.dcid).find('#filelist').addClass('loading'); - $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - { - dir: $(event.data.dcid).data('path'), - mimetype: $(event.data.dcid).data('mimetype') - }, - function(request) { OCdialogs.fillFilePicker(request, event.data.dcid) } - ); - $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - { - dir: $(event.data.dcid).data('path'), - mimetype: 'httpd/unix-directory' - }, - function(request) { OCdialogs.fillTreeList(request, event.data.dcid) } - ); + var self = event.data; + var dir = $(event.target).data('dir'); + self.fillFilePicker(dir); }, /** * go one directory up */ filepickerDirUp:function(event) { - var old_path = $(event.data.dcid).data('path'); - if ( old_path !== '/') { - var splitted_path = old_path.split("/"); - var new_path = "" - for (var i = 0; i < splitted_path.length - 2; i++) { - new_path += splitted_path[i] + '/' - } - $(event.data.dcid).data('path', new_path).find('#filelist').empty().addClass('loading');; - $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - { - dir: $(event.data.dcid).data('path'), - mimetype: $(event.data.dcid).data('mimetype') - }, - function(request) { OCdialogs.fillFilePicker(request, event.data.dcid) } - ); - $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - { - dir: $(event.data.dcid).data('path'), - mimetype: 'httpd/unix-directory' - }, - function(request) { OCdialogs.fillTreeList(request, event.data.dcid) } - ); + var self = event.data; + var old_path = self.$filePicker.data('path'); + if (old_path !== '') { + var splitted_path = old_path.split('/'); + splitted_path.pop(); + self.fillFilePicker(splitted_path.join('/')); } }, /** * handle clicks made in the filepicker */ - handlePickerClick:function(element, name, dialog_content_id) { - if ( $(element).data('type') === 'file' ){ - if ( $(dialog_content_id).data('multiselect') !== true) { - $(dialog_content_id + ' .filepicker_element_selected').removeClass('filepicker_element_selected'); + handlePickerClick:function(event, $element) { + if ($element.data('type') === 'file') { + if (this.$filePicker.data('multiselect') !== true || !event.ctrlKey) { + this.$filelist.find('.filepicker_element_selected').removeClass('filepicker_element_selected'); } - $(element).toggleClass('filepicker_element_selected'); + $element.toggleClass('filepicker_element_selected'); return; - } else if ( $(element).data('type') === 'dir' ) { - var datapath = escapeHTML( $(dialog_content_id).data('path') + name + '/' ); - $(dialog_content_id).data('path', datapath); - $(dialog_content_id).find('#filelist').empty().addClass('loading'); - $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - { - dir: datapath, - mimetype: $(dialog_content_id).data('mimetype') - }, - function(request){ OCdialogs.fillFilePicker(request, dialog_content_id) } - ); - $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - { - dir: datapath, - mimetype: 'httpd/unix-directory' - }, - function(request) { OCdialogs.fillTreeList(request, dialog_content_id) } - ); + } else if ( $element.data('type') === 'dir' ) { + this.fillFilePicker(this.$filePicker.data('path') + '/' + $element.data('entryname')) } } }; diff --git a/core/templates/filepicker.html b/core/templates/filepicker.html index f29de390ef8..e7aa77a732a 100644 --- a/core/templates/filepicker.html +++ b/core/templates/filepicker.html @@ -1,8 +1,8 @@
- - -
    -
  • + + +
      +
    • {filename} {date} -- cgit v1.2.3