From aa850d24fcc8a6f5620f11d72de392b53b82f74d Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 28 Feb 2014 16:52:42 +0000 Subject: [PATCH] implemented account_type: (accounts|groups|both) option for taglist-account as available in select-account widget --- .../class.etemplate_widget_taglist.inc.php | 5 ++-- etemplate/js/et2_widget_taglist.js | 18 +++++++++++++ phpgwapi/inc/class.accounts.inc.php | 25 ++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_taglist.inc.php b/etemplate/inc/class.etemplate_widget_taglist.inc.php index 5acb742ba7..cc7f125f4e 100644 --- a/etemplate/inc/class.etemplate_widget_taglist.inc.php +++ b/etemplate/inc/class.etemplate_widget_taglist.inc.php @@ -45,6 +45,7 @@ class etemplate_widget_taglist extends etemplate_widget $options = array(); if ($type == "account") { + $options['account_type'] = $_REQUEST['account_type']; $links = accounts::link_query($query, $options); } else @@ -116,8 +117,8 @@ class etemplate_widget_taglist extends etemplate_widget self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),''); } $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)); } } -} \ No newline at end of file +} diff --git a/etemplate/js/et2_widget_taglist.js b/etemplate/js/et2_widget_taglist.js index 8befc6994b..1eeade1aac 100644 --- a/etemplate/js/et2_widget_taglist.js +++ b/etemplate/js/et2_widget_taglist.js @@ -347,6 +347,12 @@ var et2_taglist_account = et2_taglist.extend( allowFreeEntries: { "default": 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: { @@ -360,6 +366,18 @@ var et2_taglist_account = et2_taglist.extend( 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]+$/, /** diff --git a/phpgwapi/inc/class.accounts.inc.php b/phpgwapi/inc/class.accounts.inc.php index 980fef49a5..e1a49acba2 100644 --- a/phpgwapi/inc/class.accounts.inc.php +++ b/phpgwapi/inc/class.accounts.inc.php @@ -346,6 +346,8 @@ class accounts * * @param string|array $pattern * @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 */ public static function link_query($pattern, array &$options = array()) @@ -368,11 +370,28 @@ class accounts $order = 'account_lid'; 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(); - $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( - 'type' => $options['filter']['group'] ? $options['filter']['group'] : $type, + 'type' => $options['filter']['group'] < 0 ? $options['filter']['group'] : $type, 'query' => $pattern, 'query_type' => 'all', 'order' => $order,