From 06c4b2db2345b37f541644062f50b736a0883c77 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 25 Apr 2016 15:57:38 +0000 Subject: [PATCH] use new et2 site config --- .../inc/class.addressbook_hooks.inc.php | 77 +++++++- addressbook/inc/hook_config.inc.php | 171 ----------------- addressbook/setup/setup.inc.php | 2 +- addressbook/templates/default/config.tpl | 178 ------------------ addressbook/templates/default/config.xet | 149 +++++++++++++++ api/js/etemplate/et2_widget_selectbox.js | 11 ++ 6 files changed, 233 insertions(+), 355 deletions(-) delete mode 100644 addressbook/inc/hook_config.inc.php delete mode 100644 addressbook/templates/default/config.tpl create mode 100644 addressbook/templates/default/config.xet diff --git a/addressbook/inc/class.addressbook_hooks.inc.php b/addressbook/inc/class.addressbook_hooks.inc.php index 4de0cc94a6..b1d791c394 100644 --- a/addressbook/inc/class.addressbook_hooks.inc.php +++ b/addressbook/inc/class.addressbook_hooks.inc.php @@ -10,6 +10,8 @@ * @version $Id$ */ +use EGroupware\Api; + /** * Class containing admin, preferences and sidebox-menus and other hooks */ @@ -452,15 +454,80 @@ class addressbook_hooks } /** - * Hook returning options for deny_acl groups + * Called before displaying site configuration * * @param array $config + * @return array with additional config to merge and "sel_options" values */ - public static function allow_account_edit($config) + public static function config(array $config) { - $accountsel = new uiaccountsel(); + $bocontacts = new Api\Contacts(); - return ''. - $accountsel->selection('newsettings[allow_account_edit]', 'allow_account_edit', $config['allow_account_edit'], 'groups', 4); + // get the list of account fields + $own_account_acl = array(); + foreach($bocontacts->contact_fields as $field => $label) + { + // some fields the user should never be allowed to edit or are covert by an other attribute (n_fn for all n_*) + if (!in_array($field,array('id','tid','owner','created','creator','modified','modifier','private','n_prefix','n_given','n_middle','n_family','n_suffix'))) + { + $own_account_acl[$field] = $label; + } + } + $own_account_acl['link_to'] = 'Links'; + if ($config['account_repository'] != 'ldap') // no custom-fields in ldap + { + foreach(Api\Storage\Customfields::get('addressbook') as $name => $data) + { + $own_account_acl['#'.$name] = $data['label']; + } + } + + $org_fields = $own_account_acl; + unset($org_fields['n_fn'], $org_fields['account_id']); + // Remove country codes as an option, it will be added by BO constructor + unset($org_fields['adr_one_countrycode'], $org_fields['adr_two_countrycode']); + + $supported_fields = $bocontacts->get_fields('supported',null,0); // fields supported by the backend (ldap schemas!) + // get the list of account fields + $copy_fields = array(); + foreach($bocontacts->contact_fields as $field => $label) + { + // some fields the user should never be allowed to copy or are coverted by an other attribute (n_fn for all n_*) + if (!in_array($field,array('id','tid','created','creator','modified','modifier','account_id','uid','etag','n_fn'))) + { + $copy_fields[$field] = $label; + } + } + if ($config['contact_repository'] != 'ldap') // no custom-fields in ldap + { + foreach(Api\Storage\Customfields::get('addressbook') as $name => $data) + { + $copy_fields['#'.$name] = $data['label']; + } + } + // Remove country codes as an option, it will be added by UI constructor + if(in_array('adr_one_countrycode', $supported_fields)) + { + unset($copy_fields['adr_one_countrycode'], $copy_fields['adr_two_countrycode']); + } + + $repositories = array('sql' => 'SQL'); + // check account-repository, contact-repository LDAP is only availible for account-repository == ldap + if ($config['account_repository'] == 'ldap' || !$config['account_repository'] && $config['auth_type'] == 'ldap') + { + $repositories['ldap'] = 'LDAP'; + $repositories['sql-ldap'] = 'SQL --> LDAP ('.lang('read only').')'; + } + + $ret = array( + 'sel_options' => array( + 'own_account_acl' => $own_account_acl, + 'org_fileds_to_update' => $org_fields, // typo has to stay, as it was there allways and we would loose existing config :( + 'copy_fields' => $copy_fields, + 'fileas' => $bocontacts->fileas_options(), + 'contact_repository' => $repositories, + ), + ); + return $ret; } } diff --git a/addressbook/inc/hook_config.inc.php b/addressbook/inc/hook_config.inc.php deleted file mode 100644 index e54f4bb743..0000000000 --- a/addressbook/inc/hook_config.inc.php +++ /dev/null @@ -1,171 +0,0 @@ - - * @package addressbook - * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License - * @version $Id$ - */ - -/** - * Hook to query available contact repositories for addressbook config - * - * @param array $config - * @return string with options - */ -function contact_repositories($config) -{ - $repositories = array('sql' => 'SQL'); - // check account-repository, contact-repository LDAP is only availible for account-repository == ldap - if ($config['account_repository'] == 'ldap' || !$config['account_repository'] && $config['auth_type'] == 'ldap') - { - $repositories['ldap'] = 'LDAP'; - $repositories['sql-ldap'] = 'SQL --> LDAP ('.lang('read only').')'; - } - $options = ''; - foreach($repositories as $repo => $label) - { - $options .= '\n"; - } - return $options; -} - -/** - * Hook to get available fileas types selectbox for addressbook config - * - * @param array $config - * @return string html - */ -function select_fileas($config) -{ - $bocontacts = new addressbook_bo(); - - return html::select('fileas','',array('' => lang('Set only full name'))+$bocontacts->fileas_options(),true); -} - - -/** - * Hook to get a multiselect box with all fieleds of onw-account-acl for addressbook config - * - * @param array $config - * @return string html - */ -function own_account_acl($config) -{ - $bocontacts = new addressbook_bo(); - $supported_fields = $bocontacts->get_fields('supported',null,0); // fields supported by the backend (ldap schemas!) - // get the list of account fields - $fields = array(); - foreach($bocontacts->contact_fields as $field => $label) - { - // some fields the user should never be allowed to edit or are covert by an other attribute (n_fn for all n_*) - if (!in_array($field,array('id','tid','owner','created','creator','modified','modifier','private','n_prefix','n_given','n_middle','n_family','n_suffix'))) - { - $fields[$field] = $label; - } - } - $fields['link_to'] = 'Links'; - - if ($config['account_repository'] != 'ldap') // no custom-fields in ldap - { - foreach(config::get_customfields('addressbook') as $name => $data) - { - $fields['#'.$name] = $data['label']; - } - } - return html::checkbox_multiselect('newsettings[own_account_acl]',$config['own_account_acl'],$fields,true,'',4); -} - -/** - * Hook to get a multiselect box with all fields of org-fields-to-update for addressbook config - * - * @param array $config - * @return string html - */ -function org_fileds_to_update($config) -{ - $bocontacts = new addressbook_bo(); - $supported_fields = $bocontacts->get_fields('supported',null,0); // fields supported by the backend (ldap schemas!) - // get the list of account fields - $fields = array(); - foreach($bocontacts->contact_fields as $field => $label) - { - // some fields never making sense for an organisation - if (!in_array($field,array('id','tid','owner','created','creator','modified','modifier','private','n_prefix','n_given','n_middle','n_family','n_suffix','n_fn','account_id'))) - { - $fields[$field] = $label; - } - } - - if ($config['contact_repository'] != 'ldap') // no custom-fields in ldap - { - foreach(config::get_customfields('addressbook') as $name => $data) - { - $fields['#'.$name] = $data['label']; - } - } - - // Remove country codes as an option, it will be added by BO constructor - unset($fields['adr_one_countrycode']); - unset($fields['adr_two_countrycode']); - - return html::table(array(array( - html::checkbox_multiselect('newsettings[org_fileds_to_update]', - $config['org_fileds_to_update'] ? $config['org_fileds_to_update'] : $bocontacts->org_fields,$fields,true,'',6, - true,'',false - ), - html::submit_button( - '','',"var boxen = \$j('[name^=\'newsettings\[org_fileds_to_update\]\']'); boxen.prop('checked', !boxen.prop('checked')); return false;", - true,'style="float:left;"','check','phpgwapi','button' - ) - ))); -} - -/** - * Hook to get a multiselect box with all fieleds of fields used for copying for addressbook config - * - * @param array $config - * @return string html - */ -function copy_fields($config) -{ - $bocontacts = new addressbook_bo(); - $supported_fields = $bocontacts->get_fields('supported',null,0); // fields supported by the backend (ldap schemas!) - // get the list of account fields - $fields = array(); - foreach($bocontacts->contact_fields as $field => $label) - { - // some fields the user should never be allowed to copy or are coverted by an other attribute (n_fn for all n_*) - if (!in_array($field,array('id','tid','created','creator','modified','modifier','account_id','uid','etag','n_fn'))) - { - $fields[$field] = $label; - } - } - if ($config['contact_repository'] != 'ldap') // no custom-fields in ldap - { - foreach(config::get_customfields('addressbook') as $name => $data) - { - $fields['#'.$name] = $data['label']; - } - } - // Remove country codes as an option, it will be added by UI constructor - if(in_array('adr_one_countrycode', $supported_fields)) - { - unset($fields['adr_one_countrycode']); - unset($fields['adr_two_countrycode']); - } - - return html::table(array(array( - html::checkbox_multiselect('newsettings[copy_fields]', - $config['copy_fields'] ? $config['copy_fields'] : addressbook_ui::$copy_fields, - $fields,true,'',6,true,'',false - ), - html::submit_button( - '','',"var boxen = \$j('[name^=\'newsettings\[copy_fields\]\']'); boxen.prop('checked', !boxen.prop('checked')); return false;", - true,'style="float:left;"','check','phpgwapi','button' - ) - ))); -} diff --git a/addressbook/setup/setup.inc.php b/addressbook/setup/setup.inc.php index dda66a0a7f..8387e73a90 100755 --- a/addressbook/setup/setup.inc.php +++ b/addressbook/setup/setup.inc.php @@ -41,7 +41,7 @@ $setup_info['addressbook']['hooks']['deletegroup'] = 'addressbook.addressbook_bo $setup_info['addressbook']['hooks']['delete_category'] = 'addressbook.addressbook_bo.delete_category'; $setup_info['addressbook']['hooks']['search_link'] = 'addressbook_hooks::search_link'; $setup_info['addressbook']['hooks']['calendar_resources'] = 'addressbook_hooks::calendar_resources'; -$setup_info['addressbook']['hooks'][] = 'config'; +$setup_info['addressbook']['hooks']['config'] = 'addressbook_hooks::config'; $setup_info['addressbook']['hooks']['group_acl'] = 'addressbook_hooks::group_acl'; $setup_info['addressbook']['hooks']['not_enum_group_acls'] = 'addressbook_hooks::not_enum_group_acls'; $setup_info['addressbook']['hooks']['export_limit'] = 'addressbook_hooks::getAppExportLimit'; diff --git a/addressbook/templates/default/config.tpl b/addressbook/templates/default/config.tpl deleted file mode 100644 index 0353992417..0000000000 --- a/addressbook/templates/default/config.tpl +++ /dev/null @@ -1,178 +0,0 @@ - - -
-{hidden_vars} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 {title}
 {error}
 {lang_Telephony_integration}
 {lang_URL_to_link_telephone_numbers_to_(use_%1_=_number_to_call,_%u_=_account_name,_%t_=_account_phone)}:
 {lang_Size_of_popup_(WxH,_eg.400x300,_if_a_popup_should_be_used)}:
-  {lang_Allow_users_to_maintain_their_own_account-data} -
 {lang_Fields_the_user_is_allowed_to_edit_himself} - {hook_own_account_acl} -
-  {lang_General} -
 {lang_Use_a_category_tree?} - -
 {lang_Update_Fields_by_edited_organisations?} - {hook_org_fileds_to_update} -
 {lang_Fields_to_copy_when_copying_an_address?} - {hook_copy_fields} -
 {lang_Use_an_extra_tab_for_private_custom_fields?} - -
-  {lang_Security} -
 {lang_How_many_contacts_should_non-admins_be_able_to_export} - {lang_(empty_=_use_global_limit,_no_=_no_export_at_all)}:
 {lang_Allow_members_of_following_groups_to_edit_contact-data_of_accounts}:{call_addressbook_hooks::allow_account_edit}
 {lang_History_logging}
 {lang_Prevent_deleting_of_contacts} - -
 {lang_Contact_maintenance}
 {lang_Set_full_name_and_file_as_field_in_contacts_of_all_users_(either_all_or_only_empty_values)}: - {hook_select_fileas} - - -
 {lang_Cleanup_addressbook_fields_(apply_if_synchronization_creates_duplicates)}: - -
 {lang_Contact_repository}
 {lang_Select_where_you_want_to_store_/_retrieve_contacts}: - -
 {lang_You_can_only_use_LDAP_as_contact_repository_if_the_accounts_are_stored_in_LDAP_too!}
 {lang_Account_repository}: - - ({lang_Can_be_changed_via_Setup_>>_Configuration}) -
 {lang_LDAP_settings_for_contacts}
 {lang_LDAP_host_for_contacts}:
 {lang_LDAP_context_for_contacts}:
-  {lang_Additional_information_about_using_LDAP_as_contact_repository}: - README -
 {lang_Migration_to_LDAP} - - -
- - -
-
- diff --git a/addressbook/templates/default/config.xet b/addressbook/templates/default/config.xet new file mode 100644 index 0000000000..0412ba728e --- /dev/null +++ b/addressbook/templates/default/config.xet @@ -0,0 +1,149 @@ + + + + + + diff --git a/api/js/etemplate/et2_widget_selectbox.js b/api/js/etemplate/et2_widget_selectbox.js index 8c296cad50..1a942024a1 100644 --- a/api/js/etemplate/et2_widget_selectbox.js +++ b/api/js/etemplate/et2_widget_selectbox.js @@ -609,6 +609,17 @@ var et2_selectbox = (function(){ "use strict"; return et2_inputWidget.extend( this.value = _value; }, + /** + * Method to check all options of a multi-select, if not all are selected, or none if all where selected + * + * @todo: add an attribute to automatic add a button calling this method + */ + select_all_toggle: function() + { + var all = jQuery("input",this.multiOptions); + all.prop("checked", jQuery("input:checked",this.multiOptions).length == all.length ? false : true); + }, + /** * Add a button to toggle between single select and multi select. *