implemented account_type: (accounts|groups|both) option for taglist-account as available in select-account widget

This commit is contained in:
Ralf Becker 2014-02-28 16:52:42 +00:00
parent ecc37850f0
commit aa850d24fc
3 changed files with 43 additions and 5 deletions

View File

@ -45,6 +45,7 @@ class etemplate_widget_taglist extends etemplate_widget
$options = array(); $options = array();
if ($type == "account") if ($type == "account")
{ {
$options['account_type'] = $_REQUEST['account_type'];
$links = accounts::link_query($query, $options); $links = accounts::link_query($query, $options);
} }
else else
@ -116,7 +117,7 @@ class etemplate_widget_taglist extends etemplate_widget
self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),''); self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),'');
} }
$valid =& self::get_array($validated, $form_name, true); $valid =& self::get_array($validated, $form_name, true);
$valid = $value; if (true) $valid = $value;
//error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed)); //error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed));
} }
} }

View File

@ -347,6 +347,12 @@ var et2_taglist_account = et2_taglist.extend(
allowFreeEntries: { allowFreeEntries: {
"default": true, "default": true,
ignore: true ignore: true
},
account_type: {
name: 'Account type',
'default': 'accounts',
type: 'string',
description: 'Limit type of accounts. One of {accounts,groups,both,owngroups}.'
} }
}, },
lib_options: { lib_options: {
@ -360,6 +366,18 @@ var et2_taglist_account = et2_taglist.extend(
this.options.autocomplete_params.type = "account"; this.options.autocomplete_params.type = "account";
}, },
/**
* Set if accounts, groups or both are supported
*
* Option get's passed on to autocomplete_params.
*
* @param {string} value "accounts" (default), "groups", "both", "owngroups"
*/
set_account_type: function(value)
{
this.options.autocomplete_params.account_type = this.options.account_type = value;
},
int_reg_exp: /^[0-9]+$/, int_reg_exp: /^[0-9]+$/,
/** /**

View File

@ -346,6 +346,8 @@ class accounts
* *
* @param string|array $pattern * @param string|array $pattern
* @param array $options * @param array $options
* $options['filter']['group'] only return members of that group
* $options['account_type'] "accounts", "groups", "both" or "groupmembers"
* @return array with id - title pairs of the matching entries * @return array with id - title pairs of the matching entries
*/ */
public static function link_query($pattern, array &$options = array()) public static function link_query($pattern, array &$options = array())
@ -368,11 +370,28 @@ class accounts
$order = 'account_lid'; $order = 'account_lid';
break; break;
} }
$only_own = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] === 'groupmembers' &&
!isset($GLOBALS['egw_info']['user']['apps']['admin']);
switch($options['account_type'])
{
case 'accounts':
$type = $only_own ? 'groupmembers' : 'accounts';
break;
case 'groups':
$type = $only_own ? 'memberships' : 'groups';
break;
case 'groupmembers':
case 'memberships':
$type = $options['account_type'];
break;
case 'both':
default:
$type = $only_own ? 'groupmembers+memberships' : 'both';
break;
}
$accounts = array(); $accounts = array();
$type = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
!isset($GLOBALS['egw_info']['user']['apps']['admin']) ? 'groupmembers+memberships' : 'both';
foreach(self::getInstance()->search(array( foreach(self::getInstance()->search(array(
'type' => $options['filter']['group'] ? $options['filter']['group'] : $type, 'type' => $options['filter']['group'] < 0 ? $options['filter']['group'] : $type,
'query' => $pattern, 'query' => $pattern,
'query_type' => 'all', 'query_type' => 'all',
'order' => $order, 'order' => $order,