diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-10-25 18:07:26 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-10-26 15:25:24 +0200 |
commit | aa2fd307752a704033bde229628c73bfa00ad217 (patch) | |
tree | 6ee02449fb8efc22cc5a1f40eea456cd0aae857f /apps/comments/js | |
parent | dcc4e7d9f64603574c16fe5155e36256bce5f82d (diff) | |
download | nextcloud-server-aa2fd307752a704033bde229628c73bfa00ad217.tar.gz nextcloud-server-aa2fd307752a704033bde229628c73bfa00ad217.zip |
autocomplete on demand
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/comments/js')
-rw-r--r-- | apps/comments/js/commentstabview.js | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js index 2b9db72ac13..125420d7b26 100644 --- a/apps/comments/js/commentstabview.js +++ b/apps/comments/js/commentstabview.js @@ -90,7 +90,7 @@ this._commentMaxThreshold = this._commentMaxLength * 0.9; // TODO: error handling - _.bindAll(this, '_onTypeComment', '_initAutoComplete'); + _.bindAll(this, '_onTypeComment', '_initAutoComplete', '_onAutoComplete'); }, template: function(params) { @@ -175,11 +175,13 @@ autosize(this.$el.find('.newCommentRow .message')) }, - _applyAutoComplete: function($target) { + _initAutoComplete: function($target) { var s = this; $target.atwho({ at: '@', - data: this._autoCompleteData, + callbacks: { + remoteFilter: s._onAutoComplete + }, displayTpl: "<li>${label}</li>", insertTpl: '' + '<span class="avatar-name-wrapper">' @@ -203,27 +205,31 @@ }); }, - _initAutoComplete: function ($target) { - if(!_.isUndefined(this._autoCompleteData)) { - this._applyAutoComplete($target); + _onAutoComplete: function(query, callback) { + if(_.isEmpty(query)) { return; } - var s = this; - _.defer(function () { - $.get( + if(!_.isUndefined(this._autoCompleteRequestTimer)) { + clearTimeout(this._autoCompleteRequestTimer); + } + this._autoCompleteRequestTimer = _.delay(function() { + if(!_.isUndefined(this._autoCompleteRequestCall)) { + this._autoCompleteRequestCall.abort(); + } + this._autoCompleteRequestCall = $.get( OC.generateUrl('/autocomplete/get'), { + search: query, itemType: 'files', itemId: s.model.get('id'), sorter: 'comments|share-recipients' }, function (data) { - s._autoCompleteData = data; - s._applyAutoComplete($target); + callback(data); } - ) - }); + ); + }, 200); }, _formatItem: function(commentModel) { |