From 581df74e830032f949afc86c4c521d62a1855bda Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 17 Oct 2018 11:47:39 +0200 Subject: [PATCH] Use Chwala's autocomplete service --- plugins/kolab_files/kolab_files.js | 69 +++++++++++-------- .../kolab_files/lib/kolab_files_engine.php | 2 + .../skins/elastic/include/kolab_files.less | 2 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js index 6fef427c..195b8479 100644 --- a/plugins/kolab_files/kolab_files.js +++ b/plugins/kolab_files/kolab_files.js @@ -1336,34 +1336,7 @@ function kolab_files_share_form_init() $('button.submit', row).on('click', function() { file_api.sharing_submit(rcmail.env.folder, row, mode); }); $('input[data-autocomplete]').each(function() { var input = $(this), req_name = 'filesac-' + mode; - - rcmail.init_address_input_events(input, {action: req_name}); - - // "Redirect" autocomplete requests to Chwala API - rcmail.addEventListener('request' + req_name, function(post) { - var params = {search: post._search, mode: input.data('autocomplete'), folder: rcmail.env.folder}, - callback = function(response) { - var result = response.result || []; - $.each(result, function() { - // add fake email to skip Roundcube's group expanding code - if (this.type == 'group' && !this.email) - this.email = 1; - }); - - rcmail.ksearch_query_results(result, post._search, post._reqid); - }, - error_callback = function(o, status, err, data) { - file_api.http_error(o, status, err, data); - rcmail.ksearch_query_results([], post._search, post._reqid); - }; - return file_api.get('autocomplete', params, callback, error_callback); - }); - - // Update hidden fields on selection - rcmail.addEventListener('autocomplete_insert', function(e) { - if (e.field == input[0]) { - input.val(e.insert.replace(/[, ]+$/, '')); - } + kolab_files_autocomplete(input, req_name, function(e) { $(row).find('input[type=hidden]').each(function() { $(this).val(e.data[this.name] || ''); }); @@ -1383,6 +1356,43 @@ function kolab_files_share_form_init() }); }; +function kolab_files_autocomplete(input, action, insert_callback) +{ + rcmail.init_address_input_events(input, {action: action}); + + // "Redirect" autocomplete requests to Chwala API + if (rcmail.env.files_api_version > 3) { + rcmail.addEventListener('request' + action, function(post) { + var params = {search: post._search, mode: input.data('autocomplete') || 'user', folder: rcmail.env.folder}, + callback = function(response) { + var result = response.result || []; + $.each(result, function() { + // add fake email to skip Roundcube's group expanding code + if (this.type == 'group' && !this.email) + this.email = 1; + }); + + rcmail.ksearch_query_results(result, post._search, post._reqid); + }, + error_callback = function(o, status, err, data) { + file_api.http_error(o, status, err, data); + rcmail.ksearch_query_results([], post._search, post._reqid); + }; + + return file_api.get('autocomplete', params, callback, error_callback); + }); + } + + // Update hidden fields on selection + rcmail.addEventListener('autocomplete_insert', function(e) { + if (e.field == input[0]) { + input.val(e.insert.replace(/[, ]+$/, '')); + } + if (insert_callback) + insert_callback(e); + }); +}; + /**********************************************************/ /********* document editor functionality **********/ @@ -1479,9 +1489,8 @@ function kolab_files_editors_dialog(session) if (!rcmail.env.editors_dialog) { rcmail.env.editors_dialog = dialog; - rcmail.init_address_input_events($('#invitation-editor-name'), {action: 'files/autocomplete'}); - rcmail.addEventListener('autocomplete_insert', function(e) { + kolab_files_autocomplete($('#invitation-editor-name'), 'files/autocomplete', function(e) { var success = false; if (e.field.name == 'participant') { // e.data && e.data.type == 'group' ? 'GROUP' : 'INDIVIDUAL' diff --git a/plugins/kolab_files/lib/kolab_files_engine.php b/plugins/kolab_files/lib/kolab_files_engine.php index 18fd4a82..a9594dfd 100644 --- a/plugins/kolab_files/lib/kolab_files_engine.php +++ b/plugins/kolab_files/lib/kolab_files_engine.php @@ -484,6 +484,8 @@ class kolab_files_engine $out .= html::tag('fieldset', $mode, html::tag('legend', null, rcube::Q($tab['title'])) . $table->show()) . "\n"; } + $this->rc->autocomplete_init(); + $this->rc->output->set_env('folder', $folder); $this->rc->output->set_env('form_info', $info['form']); $this->rc->output->add_gui_object('shareform', $attrib['id']); diff --git a/plugins/libkolab/skins/elastic/include/kolab_files.less b/plugins/libkolab/skins/elastic/include/kolab_files.less index 5cfc7da9..34b89205 100644 --- a/plugins/libkolab/skins/elastic/include/kolab_files.less +++ b/plugins/libkolab/skins/elastic/include/kolab_files.less @@ -514,7 +514,7 @@ button.participant.add:before { } button { - padding: .175rem .75rem; + padding: .185rem .75rem; width: 100%; } }