Skip to content

Commit

Permalink
feat: add config option to hide "additional" user fields
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel committed Aug 30, 2021
1 parent 5914ee1 commit 574b9fc
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 60 deletions.
24 changes: 19 additions & 5 deletions addon/controllers/users/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export default class UsersEditIndexController extends Controller {
model.firstName = formElements.firstName.value;
model.lastName = formElements.lastName.value;
model.email = formElements.email.value;
model.phone = formElements.phone.value;
model.language = formElements.language.selectedOptions[0].value;
model.address = formElements.address.value;
model.city = formElements.city.value;
model.zip = formElements.zip.value;
model.isActive = formElements.isActive.checked;

// additional fields might not be present
model.phone = formElements.phone?.value;
model.language = formElements.language?.selectedOptions[0].value;
model.address = formElements.address?.value;
model.city = formElements.city?.value;
model.zip = formElements.zip?.value;

model.username = this.emailAsUsername
? formElements.email.value
: formElements.username.value;
Expand All @@ -28,4 +30,16 @@ export default class UsersEditIndexController extends Controller {
get emailAsUsername() {
return this.emeisOptions.emailAsUsername;
}

get additionalUserFields() {
return (
this.emeisOptions.additionalUserFields || [
"phone",
"language",
"address",
"city",
"zip",
]
);
}
}
120 changes: 65 additions & 55 deletions addon/templates/users/edit/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,67 +50,77 @@
/>
</EditForm::Element>

<EditForm::Element @label={{t "emeis.users.headings.phone"}}>
<input
class="uk-input"
type="tel"
name="phone"
placeholder="{{t "emeis.users.headings.phone"}}..."
required
pattern="^[0-9()\-\s]+$"
value={{@model.phone}}
/>
{{#if (includes "phone" this.additionalUserFields)}}
<EditForm::Element @label={{t "emeis.users.headings.phone"}}>
<input
class="uk-input"
type="tel"
name="phone"
placeholder="{{t "emeis.users.headings.phone"}}..."
required
pattern="^[0-9()\-\s]+$"
value={{@model.phone}}
/>

<span class="uk-text-meta">
{{t "emeis.form.phone-hint"}}
</span>
</EditForm::Element>
<span class="uk-text-meta">
{{t "emeis.form.phone-hint"}}
</span>
</EditForm::Element>
{{/if}}

<EditForm::Element @label={{t "emeis.users.headings.language"}}>
<select class="uk-select uk-text-uppercase" required name="language">
<option value="" class="uk-text-capitalize">
{{t "emeis.users.headings.language"}}...
</option>
{{#each this.intl.locales as |language|}}
<option value={{language}} selected={{eq language @model.language}}>
{{language}}
{{#if (includes "language" this.additionalUserFields)}}
<EditForm::Element @label={{t "emeis.users.headings.language"}}>
<select class="uk-select uk-text-uppercase" required name="language">
<option value="" class="uk-text-capitalize">
{{t "emeis.users.headings.language"}}...
</option>
{{/each}}
</select>
</EditForm::Element>
{{#each this.intl.locales as |language|}}
<option value={{language}} selected={{eq language @model.language}}>
{{language}}
</option>
{{/each}}
</select>
</EditForm::Element>
{{/if}}

<EditForm::Element @label={{t "emeis.users.headings.address"}}>
<input
class="uk-input"
type="text"
name="address"
placeholder="{{t "emeis.users.headings.address"}}..."
required
value={{@model.address}}
/>
</EditForm::Element>
{{#if (includes "address" this.additionalUserFields)}}
<EditForm::Element @label={{t "emeis.users.headings.address"}}>
<input
class="uk-input"
type="text"
name="address"
placeholder="{{t "emeis.users.headings.address"}}..."
required
value={{@model.address}}
/>
</EditForm::Element>
{{/if}}

<EditForm::Element @label={{t "emeis.users.headings.city"}}>
<input
class="uk-input"
type="text"
name="city"
placeholder="{{t "emeis.users.headings.city"}}..."
required
value={{@model.city}}
/>
</EditForm::Element>
{{#if (includes "city" this.additionalUserFields)}}
<EditForm::Element @label={{t "emeis.users.headings.city"}}>
<input
class="uk-input"
type="text"
name="city"
placeholder="{{t "emeis.users.headings.city"}}..."
required
value={{@model.city}}
/>
</EditForm::Element>
{{/if}}

<EditForm::Element @label={{t "emeis.users.headings.zip"}}>
<input
class="uk-input"
type="number"
name="zip"
placeholder="{{t "emeis.users.headings.zip"}}..."
required
value={{@model.zip}}
/>
</EditForm::Element>
{{#if (includes "zip" this.additionalUserFields)}}
<EditForm::Element @label={{t "emeis.users.headings.zip"}}>
<input
class="uk-input"
type="number"
name="zip"
placeholder="{{t "emeis.users.headings.zip"}}..."
required
value={{@model.zip}}
/>
</EditForm::Element>
{{/if}}

<EditForm::Element @label={{t "emeis.users.headings.isActive"}}>
<input
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/services/emeis-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import Service from "@ember/service";
export default class EmeisOptionsService extends Service {
emailAsUsername = false;
pageSize = 10;
// additionalUserFields = ["phone", "language"];
}

0 comments on commit 574b9fc

Please sign in to comment.