aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-03-16 17:19:47 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-03-20 19:09:04 +0100
commitd6062195766fc21b53be1990e6633da7da58d732 (patch)
treed33fbfd92712889f3d59acf31af9aca55822c151
parent3980364b6d95feebd1ac8a4c0c9cb5773c9e5fd0 (diff)
downloadnextcloud-server-d6062195766fc21b53be1990e6633da7da58d732.tar.gz
nextcloud-server-d6062195766fc21b53be1990e6633da7da58d732.zip
Extract code to get suggestions to its own method
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--core/js/sharedialogview.js165
1 files changed, 92 insertions, 73 deletions
diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js
index f8f3efce2c5..fc867e31968 100644
--- a/core/js/sharedialogview.js
+++ b/core/js/sharedialogview.js
@@ -134,53 +134,18 @@
this.$el.find('.shareWithField').autocomplete("search");
},
- autocompleteHandler: function (search, response) {
- var $shareWithField = $('.shareWithField'),
- view = this,
- $loading = this.$el.find('.shareWithLoading'),
- $confirm = this.$el.find('.shareWithConfirm');
-
- var count = oc_config['sharing.minSearchStringLength'];
- if (search.term.trim().length < count) {
- var title = n('core',
- 'At least {count} character is 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');
- $confirm.addClass('hidden');
-
- $shareWithField.removeClass('error')
- .tooltip('hide');
+ _getSuggestions: function(searchTerm, perPage, model) {
+ var deferred = $.Deferred();
- var perPage = 200;
$.get(
OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees',
{
format: 'json',
- search: search.term.trim(),
+ search: searchTerm,
perPage: perPage,
- itemType: view.model.get('itemType')
+ itemType: model.get('itemType')
},
function (result) {
- $loading.addClass('hidden');
- $loading.removeClass('inlineblock');
- $confirm.removeClass('hidden');
if (result.ocs.meta.statuscode === 100) {
var users = result.ocs.data.exact.users.concat(result.ocs.data.users);
var groups = result.ocs.data.exact.groups.concat(result.ocs.data.groups);
@@ -213,17 +178,17 @@
}
// Filter out the owner of the share
- if (view.model.hasReshare()) {
+ if (model.hasReshare()) {
usersLength = users.length;
for (i = 0 ; i < usersLength; i++) {
- if (users[i].value.shareWith === view.model.getReshareOwner()) {
+ if (users[i].value.shareWith === model.getReshareOwner()) {
users.splice(i, 1);
break;
}
}
}
- var shares = view.model.get('shares');
+ var shares = model.get('shares');
var sharesLength = shares.length;
// Now filter out all sharees that are already shared with
@@ -275,43 +240,97 @@
var suggestions = users.concat(groups).concat(remotes).concat(emails).concat(circles).concat(lookup);
- if (suggestions.length > 0) {
- $shareWithField
- .autocomplete("option", "autoFocus", true);
+ deferred.resolve(suggestions);
+ } else {
+ deferred.resolve(null);
+ }
+ }
+ ).fail(function() {
+ deferred.reject();
+ });
- response(suggestions);
+ return deferred.promise();
+ },
- // 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(oc_config['sharing.maxAutocompleteResults'] > 0 &&
- Math.min(perPage, oc_config['sharing.maxAutocompleteResults'])
- <= Math.max(users.length, groups.length, remotes.length, emails.length, lookup.length)) {
+ autocompleteHandler: function (search, response) {
+ var $shareWithField = $('.shareWithField'),
+ view = this,
+ $loading = this.$el.find('.shareWithLoading'),
+ $confirm = this.$el.find('.shareWithConfirm');
- var message = t('core', 'This list is maybe truncated - please refine your search term to see more results.');
- $('.ui-autocomplete').append('<li class="autocomplete-note">' + message + '</li>');
- }
+ var count = oc_config['sharing.minSearchStringLength'];
+ if (search.term.trim().length < count) {
+ var title = n('core',
+ 'At least {count} character is 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;
+ }
- } else {
- 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')
- .attr('data-original-title', title)
- .tooltip('hide')
- .tooltip({
- placement: 'bottom',
- trigger: 'manual'
- })
- .tooltip('fixTitle')
- .tooltip('show');
- response();
- }
- } else {
- response();
+ $loading.removeClass('hidden');
+ $loading.addClass('inlineblock');
+ $confirm.addClass('hidden');
+
+ $shareWithField.removeClass('error')
+ .tooltip('hide');
+
+ var perPage = 200;
+ this._getSuggestions(
+ search.term.trim(),
+ perPage,
+ view.model
+ ).done(function(suggestions) {
+ $loading.addClass('hidden');
+ $loading.removeClass('inlineblock');
+ $confirm.removeClass('hidden');
+
+ if (suggestions && suggestions.length > 0) {
+ $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(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('<li class="autocomplete-note">' + message + '</li>');
}
+
+ } else if (suggestions) {
+ 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')
+ .attr('data-original-title', title)
+ .tooltip('hide')
+ .tooltip({
+ placement: 'bottom',
+ trigger: 'manual'
+ })
+ .tooltip('fixTitle')
+ .tooltip('show');
+ response();
+ } else {
+ response();
}
- ).fail(function() {
+ }).fail(function() {
$loading.addClass('hidden');
$loading.removeClass('inlineblock');
$confirm.removeClass('hidden');
span class="p">,self::getStorageData(),'/some'); $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/')); $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/folder')); $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/')); $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some')); list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder'); $this->assertEquals('folder',$internalPath); } public function testNormalize() { $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/')); $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false)); $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path')); $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path')); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/')); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar')); if (class_exists('Normalizer')) { $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88")); } } public function testHooks() { if(\OC\Files\Filesystem::getView()){ $user = \OC_User::getUser(); }else{ $user=uniqid(); \OC\Files\Filesystem::init('/'.$user.'/files'); } \OC_Hook::clear('OC_Filesystem'); \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/'); $rootView=new \OC\Files\View(''); $rootView->mkdir('/'.$user); $rootView->mkdir('/'.$user.'/files'); \OC\Files\Filesystem::file_put_contents('/foo', 'foo'); \OC\Files\Filesystem::mkdir('/bar'); \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo'); $tmpFile = \OC_Helper::tmpFile(); file_put_contents($tmpFile, 'foo'); $fh = fopen($tmpFile, 'r'); \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh); } public function dummyHook($arguments) { $path = $arguments['path']; $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized } }