refactor(web): simplify address to single free-form value
Docker Image bauen und veröffentlichen / docker (push) Canceled after 26s
Docker Image bauen und veröffentlichen / docker (push) Canceled after 26s
This commit is contained in:
@@ -311,25 +311,13 @@ func parseContactForm(r *http.Request) (contactFormInput, error) {
|
||||
in.Emails = append(in.Emails, templates.LabeledValue{Type: formValue(emailTypes, i), Value: v})
|
||||
}
|
||||
|
||||
addrTypes := get("address_type")
|
||||
streets := get("address_street")
|
||||
cities := get("address_city")
|
||||
postalCodes := get("address_postal_code")
|
||||
regions := get("address_region")
|
||||
countries := get("address_country")
|
||||
for i := range streets {
|
||||
street := strings.TrimSpace(formValue(streets, i))
|
||||
city := strings.TrimSpace(formValue(cities, i))
|
||||
postalCode := strings.TrimSpace(formValue(postalCodes, i))
|
||||
region := strings.TrimSpace(formValue(regions, i))
|
||||
country := strings.TrimSpace(formValue(countries, i))
|
||||
if street == "" && city == "" && postalCode == "" && region == "" && country == "" {
|
||||
addrTypes, addrValues := get("address_type"), get("address_value")
|
||||
for i, v := range addrValues {
|
||||
v = strings.TrimSpace(v)
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
in.Addresses = append(in.Addresses, templates.AddressValue{
|
||||
Type: formValue(addrTypes, i), Street: street, City: city,
|
||||
Region: region, PostalCode: postalCode, Country: country,
|
||||
})
|
||||
in.Addresses = append(in.Addresses, templates.AddressValue{Type: formValue(addrTypes, i), Value: v})
|
||||
}
|
||||
|
||||
if r.MultipartForm != nil {
|
||||
@@ -456,14 +444,7 @@ func buildCard(uid string, in contactFormInput, existingPhoto string) vcard.Card
|
||||
card.Add(vcard.FieldEmail, f)
|
||||
}
|
||||
for _, a := range in.Addresses {
|
||||
addr := &vcard.Address{
|
||||
Field: &vcard.Field{},
|
||||
StreetAddress: a.Street,
|
||||
Locality: a.City,
|
||||
Region: a.Region,
|
||||
PostalCode: a.PostalCode,
|
||||
Country: a.Country,
|
||||
}
|
||||
addr := &vcard.Address{Field: &vcard.Field{}, StreetAddress: a.Value}
|
||||
if a.Type != "" {
|
||||
addr.Params = vcard.Params{vcard.ParamType: {a.Type}}
|
||||
}
|
||||
@@ -530,10 +511,8 @@ func addressValues(card vcard.Card) []templates.AddressValue {
|
||||
if a.Params != nil {
|
||||
typ = a.Params.Get(vcard.ParamType)
|
||||
}
|
||||
out = append(out, templates.AddressValue{
|
||||
Type: typ, Street: a.StreetAddress, City: a.Locality,
|
||||
Region: a.Region, PostalCode: a.PostalCode, Country: a.Country,
|
||||
})
|
||||
value := strings.Join([]string{a.StreetAddress, a.Locality, a.Region, a.PostalCode, a.Country}, ", ")
|
||||
out = append(out, templates.AddressValue{Type: typ, Value: value})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user