fix addressbook edit for new Et2SelectCountry&State:

- using allowFreeEntries for custom country-names and storing, as before, region-name not the -code
- also fix flags to show nothing for custom / free country-names
Not entirely happy about it, but not willing to spend/waste more time on this tiny feature
This commit is contained in:
ralf 2022-06-23 10:06:01 +02:00
parent 9157a37480
commit f2e20eddba
6 changed files with 67 additions and 88 deletions

View File

@ -301,7 +301,6 @@ class addressbook_ui extends addressbook_bo
'cc' => 'Cc',
'bcc' => 'Bcc',
);
$sel_options['adr_one_countrycode']['-custom-'] = lang('No country selected');
// if there is any export limit set, pass it on to the nextmatch, to be evaluated by the export
if (isset($this->config['contact_export_limit']) && (int)$this->config['contact_export_limit']) $content['nm']['export_limit']=$this->config['contact_export_limit'];
@ -2303,9 +2302,20 @@ class addressbook_ui extends addressbook_bo
// Country codes
foreach(array('adr_one', 'adr_two') as $c_prefix)
{
if ($content[$c_prefix.'_countrycode'] == '-custom-')
// we store region-name not code
if (!empty($content[$c_prefix.'_region']))
{
$content[$c_prefix.'_countrycode'] = null;
$states = Api\Country::get_states($content[$c_prefix.'_countrycode']);
if ($states && isset($states[$content[$c_prefix.'_region']]))
{
$content[$c_prefix.'_region'] = $states[$content[$c_prefix.'_region']];
}
}
// handling custom country-name
if (!Api\Country::get_full_name($content[$c_prefix.'_countrycode']))
{
$content[$c_prefix.'_countryname'] = $content[$c_prefix.'_countrycode'];
unset($content[$c_prefix.'_countrycode']);
}
}
$content['msg'] = '';
@ -2639,6 +2649,25 @@ class addressbook_ui extends addressbook_bo
$content['addr_format'] = $this->addr_format_by_country($content['adr_one_countryname']);
$content['addr_format2'] = $this->addr_format_by_country($content['adr_two_countryname']);
// Country codes
foreach(array('adr_one', 'adr_two') as $c_prefix)
{
// handling custom country-name
if (empty($content[$c_prefix.'_countrycode']) && !empty($content[$c_prefix.'_countryname']))
{
$content[$c_prefix.'_countrycode'] = $content[$c_prefix.'_countryname'];
}
// translate from our stored state-/region-name to the code
if (!empty($content[$c_prefix.'_region']) && !empty($content[$c_prefix.'_countrycode']))
{
$states = Api\Country::get_states($content[$c_prefix.'_countrycode']);
if (($key = array_search($content[$c_prefix.'_region'], $states)))
{
$content[$c_prefix.'_region'] = $key;
}
}
}
//_debug_array($content);
$readonlys['button[delete]'] = !$content['owner'] || !$this->check_perms(Acl::DELETE,$content);
$readonlys['button[copy]'] = $readonlys['button[edit]'] = $readonlys['button[vcard]'] = true;
@ -2650,7 +2679,6 @@ class addressbook_ui extends addressbook_bo
}
$sel_options['fileas_type'] = $this->fileas_options($content);
$sel_options['adr_one_countrycode']['-custom-'] = lang('Custom');
$sel_options['owner'] = $this->get_addressbooks(Acl::ADD);
if ($content['owner']) unset($sel_options['owner'][0]); // do not offer to switch to accounts, as we do not support moving contacts to accounts
if ((string) $content['owner'] !== '')

View File

@ -21,6 +21,8 @@ import {fetchAll, nm_action, nm_compare_field} from "../../api/js/etemplate/et2_
import "./CRM";
import {egw} from "../../api/js/jsapi/egw_global";
import {LitElement} from "@lion/core";
import {Et2SelectState} from "../../api/js/etemplate/Et2Select/Et2Select";
import {Et2SelectCountry} from "../../api/js/etemplate/Et2Select/Et2SelectCountry";
/**
* Object to call app.addressbook.openCRMview with
@ -88,10 +90,7 @@ class AddressbookApp extends EgwApp
var content = this.et2.getArrayMgr('content').data;
if (typeof content.showsearchbuttons == 'undefined' || !content.showsearchbuttons)
{
this.show_custom_country(jQuery('select[id*="adr_one_countrycode"]').get(0));
this.show_custom_country(jQuery('select[id*="adr_two_countrycode"]').get(0));
// Instanciate infolog JS too - wrong app, so it won't be done automatically
// Instantiate infolog JS too - wrong app, so it won't be done automatically
if(typeof window.app.infolog != 'object' && typeof window.app.classes['infolog'] == 'function')
{
window.app.infolog = new window.app.classes.infolog();
@ -107,13 +106,6 @@ class AddressbookApp extends EgwApp
}
break;
}
jQuery('select[id*="adr_one_countrycode"]').each(function() {
if (app.addressbook) app.addressbook.show_custom_country(this);
});
jQuery('select[id*="adr_two_countrycode"]').each(function() {
if (app.addressbook) app.addressbook.show_custom_country(this);
});
}
/**
@ -736,37 +728,15 @@ class AddressbookApp extends EgwApp
egw.json('addressbook.addressbook_ui.ajax_check_values', [values, widget.id, own_id],this._confirmdialog_callback,this,true,this).sendRequest();
}
show_custom_country(selectbox)
/**
* Set country-code of select-state
*
* @param event
* @param country
*/
regionSetCountry(event, country : Et2SelectCountry)
{
if(!selectbox) return;
const custom_field = this.et2.getWidgetById(selectbox.id.replace("countrycode", "countryname"));
let display = "inline";
if(custom_field && selectbox.value == "-custom-") {
display = "inline";
}
else if (custom_field)
{
if((selectbox.value == "" || selectbox.value == null) && custom_field.value != "")
{
selectbox.value = "-custom-";
display = "inline";
}
else
{
display = "none";
}
}
if(custom_field?.attributeStyleMap)
{
custom_field.attributeStyleMap.set("display", display);
}
var region = this.et2.getWidgetById(selectbox.id.replace('countrycode', 'region'));
if(region)
{
region.set_country_code(selectbox.value);
}
(<Et2SelectState><any>this.et2.getWidgetById(country.id.replace('countrycode', 'region')))?.set_country_code(country.value);
}
/**

View File

@ -90,13 +90,8 @@
<radio statustext="select phone number as prefered way of contact" id="tel_prefer"
options="tel_fax,&amp;hearts;"/>
<description for="adr_one_countryname" value="country"/>
<vbox class="city_state_postcode" width="100%">
<select-country width="100%" class="countrySelect" id="adr_one_countrycode" tabindex="15"
onchange="app.addressbook.show_custom_country(this);" empty_label="Select one"
autocomplete="country"/>
<textbox id="adr_one_countryname" class="custom_country"
autocomplete="country-name"/>
</vbox>
<select-country id="adr_one_countrycode" tabindex="15" empty_label="Select one" allowFreeEntries="true" autocomplete="country"
onchange="app.addressbook.regionSetCountry"/>
</row>
<row disabled="@addr_format=city_state_postcode">
<description for="tel_other" value="Other phone"/>
@ -104,7 +99,7 @@
<radio statustext="select phone number as prefered way of contact" id="tel_prefer"
options="tel_other,&amp;hearts;"/>
<description value="Region"/>
<select-state class="city_state_postcode" statustext="State" country_code="$cont[adr_one_countrycode]"
<select-state class="city_state_postcode" statustext="State" country_code="$cont[adr_one_countrycode]" allowFreeEntries="true"
empty_label="Select one" id="adr_one_region" tabindex="16" maxlength="64"/>
</row>
<row disabled="!@addr_format=city_state_postcode">
@ -116,7 +111,7 @@
<hbox>
<textbox statustext="City" id="adr_one_locality" size="30" maxlength="64" tabindex="13"
autocomplete="address-level2"/>
<select-state statustext="State" country_code="$cont[adr_one_countrycode]" id="adr_one_region" tabindex="14"
<select-state statustext="State" country_code="$cont[adr_one_countrycode]" id="adr_one_region" tabindex="14" allowFreeEntries="true"
empty_label="Select one" width="130"/>
<textbox statustext="ZIP Code" id="adr_one_postalcode" size="5" maxlength="64" tabindex="15"
autocomplete="postal-code"/>
@ -128,12 +123,8 @@
<radio statustext="select phone number as prefered way of contact" id="tel_prefer"
options="tel_fax,&amp;hearts;"/>
<description for="adr_one_countryname" value="country"/>
<vbox width="100%" tabindex="16">
<select-country tabindex="16" width="100%" class="countrySelect" id="adr_one_countrycode" onchange="app.addressbook.show_custom_country(this);"
empty_label="Select one" autocomplete="country"/>
<textbox id="adr_one_countryname" class="custom_country" tabindex="16"
autocomplete="country-name"/>
</vbox>
<select-country tabindex="16" id="adr_one_countrycode" allowFreeEntries="true" empty_label="Select one" autocomplete="country"
onchange="app.addressbook.regionSetCountry"/>
</row>
<row disabled="!@addr_format=city_state_postcode">
<description for="tel_other" value="Other Phone"/>
@ -271,21 +262,15 @@
<radio statustext="select phone number as prefered way of contact" id="tel_prefer"
options="tel_pager,&amp;hearts;"/>
<description for="adr_two_countryname" value="country"/>
<vbox width="100%" class="city_state_postcode">
<select-country tabindex="37" width="100%" class="countrySelect" id="adr_two_countrycode"
onchange="app.addressbook.show_custom_country(this);"
empty_label="Select one" autocomplete="section-two country"/>
<textbox id="adr_two_countryname" class="custom_country"
autocomplete="section-two country-name"/>
</vbox>
<description/>
<select-country tabindex="37" id="adr_two_countrycode" empty_label="Select one" allowFreeEntries="true" autocomplete="section-two country"
onchange="app.addressbook.regionSetCountry"/>
</row>
<row disabled="@addr_format=city_state_postcode">
<description for="bday" value="Birthday"/>
<date id="bday" tabindex="31" options="Y-m-d" year_range="c-90:c+2"/>
<description/>
<description value="Region"/>
<select-state statustext="State" country_code="$cont[adr_two_countrycode]" id="adr_two_region" tabindex="38"
<select-state statustext="State" country_code="$cont[adr_two_countrycode]" id="adr_two_region" tabindex="38" allowFreeEntries="true"
empty_label="Select one" maxlength="64" class="city_state_postcode"/>
<description/>
</row>
@ -298,7 +283,7 @@
<hbox>
<textbox statustext="City" id="adr_two_locality" size="30" maxlength="64"
autocomplete="section-two address-level2"/>
<select-state country_code="$cont[adr_one_countrycode]" statustext="State" id="adr_two_region"
<select-state country_code="$cont[adr_one_countrycode]" statustext="State" id="adr_two_region" allowFreeEntries="true"
empty_label="Select one" width="130" autocomplete="section-two address-level1"/>
<textbox statustext="ZIP Code" id="adr_two_postalcode" size="5" maxlength="64"
autocomplete="section-two postal-code"/>
@ -311,14 +296,8 @@
<radio statustext="select phone number as prefered way of contact" id="tel_prefer"
options="tel_pager,&amp;hearts;"/>
<description for="adr_two_countryname" value="country"/>
<vbox width="100%">
<select-country class="countrySelect" width="100%" id="adr_two_countrycode"
onchange="app.addressbook.show_custom_country(this);"
empty_label="Select one" autocomplete="section-two country"/>
<textbox id="adr_two_countryname" class="custom_country"
autocomplete="section-two country-name"/>
</vbox>
<description/>
<select-country id="adr_two_countrycode" allowFreeEntries="true" empty_label="Select one" autocomplete="section-two country"
onchange="app.addressbook.regionSetCountry"/>
</row>
<row disabled="!@addr_format=city_state_postcode">
<description for="bday" value="Birthday"/>

View File

@ -38,6 +38,10 @@ export class Et2SelectCountry extends Et2Select
(<Promise<SelectOption[]>>so.country(this, {}, true)).then(options =>
{
if (this.allowFreeEntries && this.value && !options.filter(option => option.value == this.value).length)
{
options = options.concat(<SelectOption>{value: this.value, label: this.value});
}
this.select_options = options
});
}

View File

@ -171,6 +171,12 @@ class Select extends Etemplate\Widget
// handle empty-label for all widget types
if ((string)$val === '' && in_array('', $allowed)) continue;
// no validation, for allowFreeEntries="true"
if (!empty($this->attrs['allowFreeEntries']) && $this->attrs['allowFreeEntries'] !== 'false')
{
continue;
}
switch ($widget_type)
{
case 'select-account':

View File

@ -1,6 +1,7 @@
et2-select-country sl-menu-item::part(prefix), et2-select-country::part(prefix) {
position: relative;
background-image: none;
background-image: url(../images/flags.png);
background-position: 0 100px; /* to NOT display a flag for every value not explict defined below */
background-repeat: no-repeat;
text-indent: 15px;
height: 10px;
@ -8,20 +9,11 @@ et2-select-country sl-menu-item::part(prefix), et2-select-country::part(prefix)
margin-right: 10px;
}
et2-select-country [value]:not([value=""])::part(prefix), et2-select-country[value]:not([value=""])::part(prefix) {
background-image: url(../images/flags.png);
}
et2-select-country::part(prefix) {
margin-right: 0px;
margin-left: 10px;
}
et2-select-country [value="-CUSTOM-"]::part(prefix) {
background-image: none;
}
et2-select-country[value="BE"]::part(prefix), et2-select-country [value="BE"]::part(prefix) {
width: 18px
}