From 53a7f80ac3e5cf07db6ca01b048f2a25a526eb83 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 2 Sep 2013 23:53:45 +0200 Subject: Use provided mimetype on open. Fix #4696 --- core/js/oc-dialogs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/js/oc-dialogs.js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 4092b8d0746..6b768641586 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -77,7 +77,7 @@ var OCdialogs = { self.$filePicker = $tmpl.octemplate({ dialog_name: dialog_name, title: title - }).data('path', ''); + }).data('path', '').data('multiselect', multiselect).data('mimetype', mimetype_filter); if (modal === undefined) { modal = false; @@ -100,7 +100,7 @@ var OCdialogs = { self._handlePickerClick(event, $(this)); }); self._fillFilePicker(''); - }).data('multiselect', multiselect).data('mimetype',mimetype_filter); + }); // build buttons var functionToCall = function() { -- cgit v1.2.3 From d62c5063f420a0ec69d606aea086d40fe027da47 Mon Sep 17 00:00:00 2001 From: kondou Date: Tue, 3 Sep 2013 15:15:20 +0200 Subject: Add previews to OC.dialogs.filepicker(); Fix #4697 --- core/js/oc-dialogs.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'core/js/oc-dialogs.js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 6b768641586..f184a1022bc 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -285,7 +285,11 @@ var OCdialogs = { filename: entry.name, date: OC.mtime2date(entry.mtime) }); - $li.find('img').attr('src', entry.mimetype_icon); + if (entry.mimetype === "httpd/unix-directory") { + $li.find('img').attr('src', OC.imagePath('core', 'filetypes/folder.png')); + } else { + $li.find('img').attr('src', OC.Router.generate('core_ajax_preview', {x:32, y:32, file:escapeHTML(dir+'/'+entry.name)}) ); + } self.$filelist.append($li); }); -- cgit v1.2.3 From 992b59f70bec5dcc6681db14c3a97036b4961403 Mon Sep 17 00:00:00 2001 From: kondou Date: Thu, 5 Sep 2013 16:54:12 +0200 Subject: Make it possible to pass rawlist.php an JSON array, to filter by more than one mimetype --- apps/files/ajax/rawlist.php | 22 +++++++++++++++++----- core/js/oc-dialogs.js | 15 +++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'core/js/oc-dialogs.js') diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index f568afad4da..37fd12f71d0 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -12,21 +12,33 @@ OCP\JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; $mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : ''; +$mimetypeList = isset($_GET['mimetype_list']) ? json_decode($_GET['mimetype_list'], true) : ''; // make filelist $files = array(); // If a type other than directory is requested first load them. -if($mimetype && strpos($mimetype, 'httpd/unix-directory') === false) { +if( ($mimetype || $mimetypeList) && 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']); - $files[] = $i; + +if (is_array($mimetypeList)) { + foreach ($mimetypeList as $mimetype) { + 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']); + $files[] = $i; + } + } +} else { + 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']); + $files[] = $i; + } } OCP\JSON::success(array('data' => $files)); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f184a1022bc..f4c339702e1 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -244,10 +244,17 @@ var OCdialogs = { return defer.promise(); }, _getFileList: function(dir, mimeType) { - return $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - {dir: dir, mimetype: mimeType} - ); + if (typeof(mimeType) === "object") { + return $.getJSON( + OC.filePath('files', 'ajax', 'rawlist.php'), + {dir: dir, "mimetype_list": JSON.stringify(mimeType)} + ); + } else { + return $.getJSON( + OC.filePath('files', 'ajax', 'rawlist.php'), + {dir: dir, mimetype: mimeType} + ); + } }, _determineValue: function(element) { if ( $(element).attr('type') === 'checkbox' ) { -- cgit v1.2.3 From f84fe479a5af35cc51b4bee39492093c75ddc64e Mon Sep 17 00:00:00 2001 From: kondou Date: Thu, 5 Sep 2013 18:40:55 +0200 Subject: Only use mimetype_list and clean up a bit --- apps/files/ajax/rawlist.php | 19 ++++++++++--------- core/js/oc-dialogs.js | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) (limited to 'core/js/oc-dialogs.js') diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 37fd12f71d0..2fd6f67d308 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -11,22 +11,23 @@ OCP\JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; -$mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : ''; -$mimetypeList = isset($_GET['mimetype_list']) ? json_decode($_GET['mimetype_list'], true) : ''; +$mimetypes = isset($_GET['mimetypes']) ? array_unique(json_decode($_GET['mimetypes'], true)) : ''; // make filelist $files = array(); // If a type other than directory is requested first load them. -if( ($mimetype || $mimetypeList) && strpos($mimetype, 'httpd/unix-directory') === false) { +if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) { 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']); + $i['mimetype_icon'] = ($i['type'] == 'dir') + ? \mimetype_icon('dir') + : \mimetype_icon($i['mimetype']); $files[] = $i; } } -if (is_array($mimetypeList)) { - foreach ($mimetypeList as $mimetype) { +if (is_array($mimetypes) && count($mimetypes)) { + foreach ($mimetypes as $mimetype) { 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']); @@ -34,11 +35,11 @@ if (is_array($mimetypeList)) { } } } else { - foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $i ) { - $i["date"] = OCP\Util::formatDate($i["mtime"] ); + foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) { + $i["date"] = OCP\Util::formatDate($i["mtime"]); $i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']); $files[] = $i; } } -OCP\JSON::success(array('data' => $files)); +OC_JSON::success(array('data' => $files)); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f4c339702e1..ed4d7c678e1 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -244,17 +244,19 @@ var OCdialogs = { return defer.promise(); }, _getFileList: function(dir, mimeType) { - if (typeof(mimeType) === "object") { - return $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - {dir: dir, "mimetype_list": JSON.stringify(mimeType)} - ); - } else { - return $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - {dir: dir, mimetype: mimeType} - ); + if (typeof(mimeType) === "string") { + var tmp = mimeType; + mimeType = new Array(); + mimeType[0] = tmp; } + + return $.getJSON( + OC.filePath('files', 'ajax', 'rawlist.php'), + { + dir: dir, + mimetypes: JSON.stringify(mimeType) + } + ); }, _determineValue: function(element) { if ( $(element).attr('type') === 'checkbox' ) { -- cgit v1.2.3 From c6ca9c1e9d8e25f4dad5ca18f2f335b19a4a3c0c Mon Sep 17 00:00:00 2001 From: kondou Date: Fri, 6 Sep 2013 13:33:17 +0200 Subject: Use shorter array-conversion --- core/js/oc-dialogs.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'core/js/oc-dialogs.js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index ed4d7c678e1..61b58d00fa6 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -245,9 +245,7 @@ var OCdialogs = { }, _getFileList: function(dir, mimeType) { if (typeof(mimeType) === "string") { - var tmp = mimeType; - mimeType = new Array(); - mimeType[0] = tmp; + mimeType = [mimeType]; } return $.getJSON( -- cgit v1.2.3 From 799c5c2c9b3fdfd4c4d407e352c9dff494d86cc0 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 11 Sep 2013 16:02:12 +0200 Subject: Don't popup meaningless alerts when dialog called on page leave --- core/js/oc-dialogs.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'core/js/oc-dialogs.js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f184a1022bc..a3516f866d1 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -139,8 +139,14 @@ var OCdialogs = { } }); }) - .fail(function() { - alert(t('core', 'Error loading file picker template')); + .fail(function(status, error) { + // If the method is called while navigating away + // from the page, it is probably not needed ;) + if(status === 0) { + return; + } else { + alert(t('core', 'Error loading file picker template: {error}', {error: error})); + } }); }, /** @@ -206,8 +212,14 @@ var OCdialogs = { }); OCdialogs.dialogs_counter++; }) - .fail(function() { - alert(t('core', 'Error loading file picker template')); + .fail(function(status, error) { + // If the method is called while navigating away from + // the page, we still want to deliver the message. + if(status === 0) { + alert(title + ': ' + content); + } else { + alert(t('core', 'Error loading message template: {error}', {error: error})); + } }); }, _getFilePickerTemplate: function() { @@ -219,8 +231,8 @@ var OCdialogs = { self.$listTmpl = self.$filePickerTemplate.find('.filelist li:first-child').detach(); defer.resolve(self.$filePickerTemplate); }) - .fail(function() { - defer.reject(); + .fail(function(jqXHR, textStatus, errorThrown) { + defer.reject(jqXHR.status, errorThrown); }); } else { defer.resolve(this.$filePickerTemplate); @@ -231,12 +243,12 @@ var OCdialogs = { var defer = $.Deferred(); if(!this.$messageTemplate) { var self = this; - $.get(OC.filePath('core', 'templates', 'message.html'), function(tmpl) { + $.get(OC.filePath('core', 'templates', 'message.htm'), function(tmpl) { self.$messageTemplate = $(tmpl); defer.resolve(self.$messageTemplate); }) - .fail(function() { - defer.reject(); + .fail(function(jqXHR, textStatus, errorThrown) { + defer.reject(jqXHR.status, errorThrown); }); } else { defer.resolve(this.$messageTemplate); -- cgit v1.2.3 From 1f8f0e61d89036e9c51befbd88404cbe9af6e664 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 11 Sep 2013 21:11:35 +0200 Subject: Remove test error :P --- core/js/oc-dialogs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js/oc-dialogs.js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index a3516f866d1..26173ffeb69 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -243,7 +243,7 @@ var OCdialogs = { var defer = $.Deferred(); if(!this.$messageTemplate) { var self = this; - $.get(OC.filePath('core', 'templates', 'message.htm'), function(tmpl) { + $.get(OC.filePath('core', 'templates', 'message.html'), function(tmpl) { self.$messageTemplate = $(tmpl); defer.resolve(self.$messageTemplate); }) -- cgit v1.2.3 From 08225a60c8e7535ae94726189a090679886ea47d Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 11 Sep 2013 21:15:32 +0200 Subject: Save two lines --- core/js/oc-dialogs.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'core/js/oc-dialogs.js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 26173ffeb69..db8cb5d8cf9 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -142,9 +142,7 @@ var OCdialogs = { .fail(function(status, error) { // If the method is called while navigating away // from the page, it is probably not needed ;) - if(status === 0) { - return; - } else { + if(status !== 0) { alert(t('core', 'Error loading file picker template: {error}', {error: error})); } }); -- cgit v1.2.3 From c117e719daf84c087faa0e5913a6fd96668edfcf Mon Sep 17 00:00:00 2001 From: kondou Date: Sat, 14 Sep 2013 14:35:23 +0200 Subject: Use external and shared icons in OC.Dialogs.filepicker() --- apps/files/ajax/rawlist.php | 20 +++++++++----------- core/js/oc-dialogs.js | 6 +----- 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'core/js/oc-dialogs.js') diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index e9ae1f5305f..9ccd4cc299a 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -25,8 +25,10 @@ $files = array(); // If a type other than directory is requested first load them. if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $file ) { + $file['directory'] = $dir; + $file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']); $file["date"] = OCP\Util::formatDate($file["mtime"]); - $file['mimetype_icon'] = \mimetype_icon('dir'); + $file['mimetype_icon'] = \OCA\files\lib\Helper::determineIcon($file); $files[] = $file; } } @@ -34,23 +36,19 @@ if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) { if (is_array($mimetypes) && count($mimetypes)) { foreach ($mimetypes as $mimetype) { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) { + $file['directory'] = $dir; + $file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']); $file["date"] = OCP\Util::formatDate($file["mtime"]); - if ($file['type'] === "dir") { - $file['mimetype_icon'] = \mimetype_icon('dir'); - } else { - $file['mimetype_icon'] = \mimetype_icon($file['mimetype']); - } + $file['mimetype_icon'] = \OCA\files\lib\Helper::determineIcon($file); $files[] = $file; } } } else { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) { + $file['directory'] = $dir; + $file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']); $file["date"] = OCP\Util::formatDate($file["mtime"]); - if ($file['type'] === "dir") { - $file['mimetype_icon'] = \mimetype_icon('dir'); - } else { - $file['mimetype_icon'] = \mimetype_icon($file['mimetype']); - } + $file['mimetype_icon'] = \OCA\files\lib\Helper::determineIcon($file); $files[] = $file; } } diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index 61b58d00fa6..33e3a75fab6 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -292,11 +292,7 @@ var OCdialogs = { filename: entry.name, date: OC.mtime2date(entry.mtime) }); - if (entry.mimetype === "httpd/unix-directory") { - $li.find('img').attr('src', OC.imagePath('core', 'filetypes/folder.png')); - } else { - $li.find('img').attr('src', OC.Router.generate('core_ajax_preview', {x:32, y:32, file:escapeHTML(dir+'/'+entry.name)}) ); - } + $li.find('img').attr('src', entry.mimetype_icon); self.$filelist.append($li); }); -- cgit v1.2.3