From 3284efd1996854df0252d3e40574759e698b812d Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 21 Feb 2017 17:07:07 -0600 Subject: Improve the UX for sharing settings * shows a info when list is potentially truncated * shows a warning when characters length is not enough Signed-off-by: Morris Jobke --- core/js/sharedialogview.js | 52 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 60cd97fb572..bbc40c9c8d4 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -130,18 +130,46 @@ }, autocompleteHandler: function (search, response) { - var view = this; - var $loading = this.$el.find('.shareWithLoading'); + var $shareWithField = $('.shareWithField'), + view = this, + $loading = this.$el.find('.shareWithLoading'), + $remoteShareInfo = this.$el.find('.shareWithRemoteInfo'); + + var count = oc_config['sharing.minSearchStringLength']; + if (search.term.trim().length < count) { + var title = n('core', + 'At least {count} character are needed for autocompletion', + 'At least {count} characters are needed for autocompletion', + count, + { count: count } + ); + $shareWithField.addClass('error') + .attr('data-original-title', title) + .tooltip('hide') + .tooltip({ + placement: 'bottom', + trigger: 'manual' + }) + .tooltip('fixTitle') + .tooltip('show'); + response(); + return; + } + $loading.removeClass('hidden'); $loading.addClass('inlineblock'); - var $remoteShareInfo = this.$el.find('.shareWithRemoteInfo'); $remoteShareInfo.addClass('hidden'); + + $shareWithField.removeClass('error') + .tooltip('hide'); + + var perPage = 200; $.get( OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees', { format: 'json', search: search.term.trim(), - perPage: 200, + perPage: perPage, itemType: view.model.get('itemType') }, function (result) { @@ -232,16 +260,24 @@ var suggestions = users.concat(groups).concat(remotes).concat(emails).concat(lookup); if (suggestions.length > 0) { - $('.shareWithField').removeClass('error') - .tooltip('hide') + $shareWithField .autocomplete("option", "autoFocus", true); + response(suggestions); + + // show a notice that the list is truncated + // this is the case if one of the search results is at least as long as the max result config option + if(Math.min(perPage, oc_config['sharing.maxAutocompleteResults']) <= Math.max(users.length, groups.length, remotes.length, emails.length, lookup.length)) { + var message = t('core', 'This list is maybe truncated - please refine your search term to see more results.'); + $('.ui-autocomplete').append('
  • ' + message + '
  • '); + } + } else { - var title = t('core', 'No users or groups found for {search}', {search: $('.shareWithField').val()}); + var title = t('core', 'No users or groups found for {search}', {search: $shareWithField.val()}); if (!view.configModel.get('allowGroupSharing')) { title = t('core', 'No users found for {search}', {search: $('.shareWithField').val()}); } - $('.shareWithField').addClass('error') + $shareWithField.addClass('error') .attr('data-original-title', title) .tooltip('hide') .tooltip({ -- cgit v1.2.3 From 8e3d0fecd237a457fe66e00bc293923dae9a5adf Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 21 Feb 2017 17:22:06 -0600 Subject: Use intval() for validation of config options Signed-off-by: Morris Jobke --- apps/files_sharing/lib/Controller/ShareesAPIController.php | 4 ++-- core/js/sharedialogview.js | 5 ++++- lib/private/Template/JSConfigHelper.php | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'core/js/sharedialogview.js') diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php index 171fac4dbd2..73f804faace 100644 --- a/apps/files_sharing/lib/Controller/ShareesAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php @@ -415,13 +415,13 @@ class ShareesAPIController extends OCSController { public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) { // only search for string larger than a given threshold - $threshold = $this->config->getSystemValue('sharing.minSearchStringLength', 0); + $threshold = intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)); if (strlen($search) < $threshold) { return new Http\DataResponse($this->result); } // never return more than the max. number of results configured in the config.php - $maxResults = $this->config->getSystemValue('sharing.maxAutocompleteResults', 0); + $maxResults = intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)); if ($maxResults > 0) { $perPage = min($perPage, $maxResults); } diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index bbc40c9c8d4..6a92c6a8dd5 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -267,7 +267,10 @@ // show a notice that the list is truncated // this is the case if one of the search results is at least as long as the max result config option - if(Math.min(perPage, oc_config['sharing.maxAutocompleteResults']) <= Math.max(users.length, groups.length, remotes.length, emails.length, lookup.length)) { + if(oc_config['sharing.maxAutocompleteResults'] > 0 && + Math.min(perPage, oc_config['sharing.maxAutocompleteResults']) + <= Math.max(users.length, groups.length, remotes.length, emails.length, lookup.length)) { + var message = t('core', 'This list is maybe truncated - please refine your search term to see more results.'); $('.ui-autocomplete').append('
  • ' + message + '
  • '); } diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index 7a4e8415e7d..6bf08dcdada 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -207,8 +207,8 @@ class JSConfigHelper { 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), 'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'), - 'sharing.maxAutocompleteResults' => $this->config->getSystemValue('sharing.maxAutocompleteResults', 0), - 'sharing.minSearchStringLength' => $this->config->getSystemValue('sharing.minSearchStringLength', 0), + 'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)), + 'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)), ]), "oc_appconfig" => json_encode([ 'core' => [ -- cgit v1.2.3 From 11e5a3dcf4767149a3f7e14deb8e684bb6500276 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 22 Feb 2017 16:28:42 +0100 Subject: fix typo Signed-off-by: Bjoern Schiessle --- core/js/sharedialogview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js/sharedialogview.js') diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index 6a92c6a8dd5..a63960da2b8 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -138,7 +138,7 @@ var count = oc_config['sharing.minSearchStringLength']; if (search.term.trim().length < count) { var title = n('core', - 'At least {count} character are needed for autocompletion', + 'At least {count} character is needed for autocompletion', 'At least {count} characters are needed for autocompletion', count, { count: count } -- cgit v1.2.3