Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

1.2 KB
Raw Blame
import { Controller } from '@hotwired/stimulus';

export default class UsersController extends Controller {
  static targets = [
    'passwordFields',
    'authSourceFields',
  ];

  static values = {
    passwordAuthSelected: Boolean,
  };

  declare passwordAuthSelectedValue:boolean;

  declare readonly passwordFieldsTarget:HTMLElement;

  declare readonly hasPasswordFieldsTarget:boolean;

  declare readonly authSourceFieldsTarget:HTMLElement;

  declare readonly hasAuthSourceFieldsTarget:boolean;

  toggleAuthenticationFields(evt:{ target:HTMLSelectElement }):void {
    this.passwordAuthSelectedValue = evt.target.value === '';
  }

  private passwordAuthSelectedValueChanged() {
    if (this.hasPasswordFieldsTarget) {
      this.toggleHiddenAndDisabled(this.passwordFieldsTarget, !this.passwordAuthSelectedValue);
    }
    if (this.hasAuthSourceFieldsTarget) {
      this.toggleHiddenAndDisabled(this.authSourceFieldsTarget, this.passwordAuthSelectedValue);
    }
  }

  private toggleHiddenAndDisabled(target:HTMLElement, hiddenAndDisabled:boolean) {
    target.hidden = hiddenAndDisabled;
    target.querySelectorAll('input')
      .forEach((el:HTMLInputElement) => {
        el.disabled = hiddenAndDisabled;
      });
  }
}