account selection currently only need to use server-side search, for pref "Primary group and search"

for all other types the local search is sufficient, as everything is already local!
fix Taglist::ajax_search for accounts to pass the icon to client-side and always set value instead of id
This commit is contained in:
ralf 2022-08-09 10:47:57 +02:00
parent 280bbcb827
commit ea0cbd0441
3 changed files with 33 additions and 28 deletions

View File

@ -32,15 +32,25 @@ export class Et2SelectAccount extends Et2Select
constructor()
{
super();
this.searchUrl = "EGroupware\\Api\\Etemplate\\Widget\\Taglist::ajax_search";
// currently only account_selection "Primary group and search" needs the search,
// all other types have the accounts fully local
if (this.egw().preference('account_selection', 'common') === 'primary_group')
{
this.searchUrl = "EGroupware\\Api\\Etemplate\\Widget\\Taglist::ajax_search";
}
else // always allow local search
{
this.search = true;
}
this.searchOptions = { type: 'account', account_type: 'accounts' };
this.__accountType = 'accounts';
}
set accountType(type : AccountType)
{
this.__accountType = type;
this.searchOptions.account_type = type;
super.select_options = this.select_options;
}

View File

@ -63,38 +63,33 @@ class Taglist extends Etemplate\Widget
* Find entries that match query parameter (from link system) and format them
* as the widget expects, a list of {id: ..., label: ...} objects
*/
public static function ajax_search($search_text, $search_options = [])
public static function ajax_search($search_text=null, array $search_options = [])
{
$app = $_REQUEST['app'];
$type = $_REQUEST['type'];
$query = $_REQUEST['query'];
$options = array();
$links = array();
if($type == "account")
$query = $search_text ?? $_REQUEST['query'];
$options = $search_options;
$results = [];
if (empty($query))
{
// Only search if a query was provided - don't search for all accounts
if($query)
// do NOT search without a query
}
elseif($type === "account")
{
$options['account_type'] = $_REQUEST['account_type'];
$options['tag_list'] = true;
$results = Api\Accounts::link_query($query, $options);
}
else
{
foreach(Api\Link::query($app, $query, $options) as $id => $name)
{
$options['account_type'] = $_REQUEST['account_type'];
$links = Api\Accounts::link_query($query, $options);
$results[] = ['value' => $id, 'label' => $name];
}
}
elseif($query) // Only search if there's a query, avoid searching for all
{
$links = Api\Link::query($app, $query, $options);
}
$results = array();
foreach($links as $id => $name)
{
$results[] = array('id' => $id, 'label' => $name);
}
usort($results, function ($a, $b) use ($query) {
$a_label = is_array($a["label"]) ? $a["label"]["label"] : $a["label"];
$b_label = is_array($b["label"]) ? $b["label"]["label"] : $b["label"];
similar_text($query, $a_label, $percent_a);
similar_text($query, $b_label, $percent_b);
usort($results, static function ($a, $b) use ($query) {
similar_text($query, $a["label"], $percent_a);
similar_text($query, $b["label"], $percent_b);
return $percent_a === $percent_b ? 0 : ($percent_a > $percent_b ? -1 : 1);
});

View File

@ -3689,7 +3689,7 @@ class mail_compose
$completeMailString = call_user_func_array('imap_rfc822_write_address', $args);
if(!empty($email) && in_array($completeMailString ,$results) === false) {
$results[] = array(
'id'=>$completeMailString,
'value' => $completeMailString,
'label' => $completeMailString,
// Add just name for nice display, with title for hover
'name' => $contact['n_fn'],