From aa2fd307752a704033bde229628c73bfa00ad217 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Oct 2017 18:07:26 +0200 Subject: [PATCH] autocomplete on demand Signed-off-by: Arthur Schiwon --- apps/comments/js/commentstabview.js | 32 +++++++++++++++++------------ 1 file 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: "
  • ${label}
  • ", insertTpl: '' + '' @@ -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) {