From 4508a121881d5aef31479a96a11cab4783ac48ee Mon Sep 17 00:00:00 2001 From: Daniel Calviño Sánchez Date: Thu, 30 Aug 2018 10:25:09 +0200 Subject: Prevent default action from being executed when the button is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When "enter" is pressed in the file picker a "click" event is triggered on the primary action button. However, in some cases, like when the file picker is in "Choose" mode and the current directory in the file picker is the root folder, the primary action button is disabled. In those cases pressing enter should not trigger a click action on the button and be ignored instead. Signed-off-by: Daniel Calviño Sánchez --- core/js/jquery.ocdialog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/jquery.ocdialog.js b/core/js/jquery.ocdialog.js index f3a54119e78..02bd3069c59 100644 --- a/core/js/jquery.ocdialog.js +++ b/core/js/jquery.ocdialog.js @@ -64,7 +64,7 @@ self.$buttonrow.find($(event.target)).length === 0 ) { var $button = self.$buttonrow.find('button.primary'); - if($button) { + if($button && !$button.prop('disabled')) { $button.trigger('click'); } } else if(self.$buttonrow) { -- cgit v1.2.3 From 66f2b155cecbd6b066fbc6c1efa7317e24f79915 Mon Sep 17 00:00:00 2001 From: Daniel Calviño Sánchez Date: Thu, 30 Aug 2018 14:02:50 +0200 Subject: Fix empty mime type filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the mime type is an empty array no filter should be applied. However, the filter was loosely compared to an empty array, but as arrays are objects then it became an implicit strict equality comparison which always failed due to being different objects. Now the length of the array is compared instead, and also moved outside the loop as it is not needed to check it for each file. Signed-off-by: Daniel Calviño Sánchez --- core/js/oc-dialogs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index d346b5231d1..a9f9426c488 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -841,9 +841,9 @@ var OCdialogs = { filter = [filter]; } self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) { - if (filter) { + if (filter && filter.length > 0) { files = files.filter(function (file) { - return filter == [] || file.type === 'dir' || filter.indexOf(file.mimetype) !== -1; + return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1; }); } files = files.sort(function(a, b) { -- cgit v1.2.3 From f080fa55ac606b498e3e1144a5fb58513e7ad1a3 Mon Sep 17 00:00:00 2001 From: Daniel Calviño Sánchez Date: Thu, 30 Aug 2018 14:23:47 +0200 Subject: Store the mime type filter always as an array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will make easier to check if both directories and files should be pickable. This also removes an unused assignment to the mime type. Signed-off-by: Daniel Calviño Sánchez --- core/js/oc-dialogs.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'core/js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index a9f9426c488..ee1e84033d4 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -206,6 +206,14 @@ var OCdialogs = { if(self.$filePicker) { self.$filePicker.ocdialog('close'); } + + if (mimetypeFilter === undefined || mimetypeFilter === null) { + mimetypeFilter = []; + } + if (typeof(mimetypeFilter) === "string") { + mimetypeFilter = [mimetypeFilter]; + } + self.$filePicker = $tmpl.octemplate({ dialog_name: dialogName, title: title, @@ -218,9 +226,6 @@ var OCdialogs = { if (multiselect === undefined) { multiselect = false; } - if (mimetypeFilter === undefined) { - mimetypeFilter = ''; - } $('body').append(self.$filePicker); @@ -315,7 +320,7 @@ var OCdialogs = { // Hence this is one of the approach to get the choose button. var getOcDialog = self.$filePicker.closest('.oc-dialog'); var buttonEnableDisable = getOcDialog.find('.primary'); - if (self.$filePicker.data('mimetype') === "httpd/unix-directory") { + if (self.$filePicker.data('mimetype').indexOf("httpd/unix-directory") !== -1) { buttonEnableDisable.prop("disabled", false); } else { buttonEnableDisable.prop("disabled", true); @@ -939,7 +944,7 @@ var OCdialogs = { var getOcDialog = (event.target).closest('.oc-dialog'); var buttonEnableDisable = $('.primary', getOcDialog); this._changeButtonsText(type, dir.split(/[/]+/).pop()); - if (this.$filePicker.data('mimetype') === "httpd/unix-directory") { + if (this.$filePicker.data('mimetype').indexOf("httpd/unix-directory") !== -1) { buttonEnableDisable.prop("disabled", false); } else { buttonEnableDisable.prop("disabled", true); @@ -960,7 +965,7 @@ var OCdialogs = { } else if ( $element.data('type') === 'dir' ) { this._fillFilePicker(this.$filePicker.data('path') + '/' + $element.data('entryname')); this._changeButtonsText(type, $element.data('entryname')); - if (this.$filePicker.data('mimetype') === "httpd/unix-directory") { + if (this.$filePicker.data('mimetype').indexOf("httpd/unix-directory") !== -1) { buttonEnableDisable.prop("disabled", false); } else { buttonEnableDisable.prop("disabled", true); -- cgit v1.2.3 From c14c6e5ccf55f1f6170520b161381a415dd8e4d8 Mon Sep 17 00:00:00 2001 From: Daniel Calviño Sánchez Date: Thu, 30 Aug 2018 14:40:12 +0200 Subject: Make possible to pick both files and folders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- core/js/oc-dialogs.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'core/js') diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index ee1e84033d4..7369298b8d5 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -175,6 +175,14 @@ var OCdialogs = { }, /** * show a file picker to pick a file from + * + * In order to pick several types of mime types they need to be passed as an + * array of strings. + * + * When no mime type filter is given only files can be selected. In order to + * be able to select both files and folders "['*', 'httpd/unix-directory']" + * should be used instead. + * * @param title dialog title * @param callback which will be triggered when user presses Choose * @param multiselect whether it should be possible to select multiple files @@ -846,7 +854,7 @@ var OCdialogs = { filter = [filter]; } self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) { - if (filter && filter.length > 0) { + if (filter && filter.length > 0 && filter.indexOf('*') === -1) { files = files.filter(function (file) { return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1; }); -- cgit v1.2.3