diff --git a/plugins/kolab_files/kolab_files.js b/plugins/kolab_files/kolab_files.js index 2aa5bcf3..3e10e599 100644 --- a/plugins/kolab_files/kolab_files.js +++ b/plugins/kolab_files/kolab_files.js @@ -1331,6 +1331,41 @@ function kolab_files_share_form_init() $('tbody > tr', this).each(function(i, row) { if (!i) { $('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(/[, ]+$/, '')); + } + $(row).find('input[type=hidden]').each(function() { + $(this).val(e.data[this.name] || ''); + }); + }); + }); } else { $('button.delete', row).on('click', function() { file_api.sharing_delete(rcmail.env.folder, row, mode); }); diff --git a/plugins/kolab_files/lib/kolab_files_engine.php b/plugins/kolab_files/lib/kolab_files_engine.php index 2e0abd46..e798a1d4 100644 --- a/plugins/kolab_files/lib/kolab_files_engine.php +++ b/plugins/kolab_files/lib/kolab_files_engine.php @@ -399,7 +399,10 @@ class kolab_files_engine } } else { - $ff = new html_inputfield(array('name' => $index)); + $ff = new html_inputfield(array( + 'name' => $index, + 'data-autocomplete' => $field['autocomplete'], + )); } $table->add(null, $ff->show());