diff --git a/ui/core/app/components/form/account/index.hbs b/ui/core/app/components/form/account/index.hbs deleted file mode 100644 index b7f418d63..000000000 --- a/ui/core/app/components/form/account/index.hbs +++ /dev/null @@ -1,70 +0,0 @@ - - - - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - - - - {{#if @model.errors.description}} - - {{#each @model.errors.description as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - - - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - - - - \ No newline at end of file diff --git a/ui/core/app/components/form/account/password/index.hbs b/ui/core/app/components/form/account/password/index.hbs index 4f167188f..facd43c2f 100644 --- a/ui/core/app/components/form/account/password/index.hbs +++ b/ui/core/app/components/form/account/password/index.hbs @@ -1,5 +1,5 @@ - - {{#if @model.errors.name}} - - {{#each @model.errors.name as |error|}} - {{error.message}} - {{/each}} - - {{/if}} - + {{#if @model.isNew}} + + {{#if @model.errors.name}} + + {{#each @model.errors.name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + {{/if}} - \ No newline at end of file + + diff --git a/ui/core/app/components/form/account/password/index.js b/ui/core/app/components/form/account/password/index.js new file mode 100644 index 000000000..e80e48c95 --- /dev/null +++ b/ui/core/app/components/form/account/password/index.js @@ -0,0 +1,37 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { action } from '@ember/object'; + +export default class FormAccountPasswordIndexComponent extends Component { + + // =properties + + /** + * Account password property + * @type {string} + */ + @tracked password; + + // =methods + + /** + * Unsets the password field. + */ + resetPassword() { + this.password = null; + } + + // =actions + + /** + * Submit with password value when it is allowed. + * Callback with no arguments otherwise. + * @param {function} fn + */ + @action + submit(fn) { + const password = this.password; + this.resetPassword(); + this.args.model.isNew ? fn(password) : fn(); + } +} diff --git a/ui/core/app/components/form/account/password/set-password.hbs b/ui/core/app/components/form/account/password/set-password/index.hbs similarity index 81% rename from ui/core/app/components/form/account/password/set-password.hbs rename to ui/core/app/components/form/account/password/set-password/index.hbs index 3d48a1933..7d88d57eb 100644 --- a/ui/core/app/components/form/account/password/set-password.hbs +++ b/ui/core/app/components/form/account/password/set-password/index.hbs @@ -1,6 +1,6 @@ diff --git a/ui/core/app/components/form/account/password/set-password/index.js b/ui/core/app/components/form/account/password/set-password/index.js new file mode 100644 index 000000000..477c14cee --- /dev/null +++ b/ui/core/app/components/form/account/password/set-password/index.js @@ -0,0 +1,57 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { computed } from '@ember/object'; +import { action } from '@ember/object'; + +export default class FormAccountPasswordSetPasswordIndexComponent extends Component { + + // =properties + + /** + * New password property + * @type {string} + */ + @tracked password; + + /** + * @type {boolean} + */ + @computed('password') + get cannotSave() { + return !(this.password?.length > 0); + } + + // =methods + + /** + * Unsets the password field. + */ + resetPassword() { + this.password = null; + } + + // =actions + + /** + * Submit with password value when it is allowed. + * Callback with no arguments otherwise. + * @param {function} fn + */ + @action + submit(fn) { + const password = this.password; + this.resetPassword(); + fn(password); + } + + /** + * Unset password value before callback. + * @param {function} fn + */ + @action + cancel(fn) { + this.resetPassword(); + fn(); + } + +} diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js index b301d9a09..a5a5efa5f 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts.js @@ -39,12 +39,14 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route * @param {AccountModel} account */ @action - async save(account) { + async save(account, password) { const { isNew } = account; + const adapterOptions = {}; + if(isNew) { adapterOptions.password = password; } try { - await account.save(); - await this.refresh(); + await account.save({ adapterOptions }); await this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account); + this.refresh(); this.notify.success( this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success') ); diff --git a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js index 07f416dcf..1728382b6 100644 --- a/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js +++ b/ui/core/app/routes/scopes/scope/auth-methods/auth-method/accounts/account/settings.js @@ -14,6 +14,7 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout /** * Set password for current account. * @param {AccountModel} account + * @param {string} password */ @action async setPassword(account) { @@ -34,6 +35,6 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountSettingsRout */ @action cancel() { - this.replaceWith('scopes.scope.auth-methods.auth-method.accounts.account'); + this.replaceWith('scopes.scope.auth-methods.auth-method.accounts.account.settings'); } } diff --git a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs index 07b4e30bc..41e9ca5c6 100644 --- a/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs +++ b/ui/core/app/templates/scopes/scope/auth-methods/auth-method/accounts/account/index.hbs @@ -1,4 +1,4 @@ -