connectionMethod.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. Template.connectionMethod.onCreated(function() {
  2. this.authenticationMethods = new ReactiveVar([]);
  3. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  4. if (result) {
  5. // TODO : add a management of different languages
  6. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  7. this.authenticationMethods.set([
  8. { value: 'password' },
  9. // Gets only the authentication methods availables
  10. ...Object.entries(result)
  11. .filter(e => e[1])
  12. .map(e => ({ value: e[0] })),
  13. ]);
  14. }
  15. // If only the default authentication available, hides the select boxe
  16. const content = $('.at-form-authentication');
  17. if (!(this.authenticationMethods.get().length > 1)) {
  18. content.hide();
  19. } else {
  20. content.show();
  21. }
  22. });
  23. });
  24. Template.connectionMethod.onRendered(() => {
  25. // Moves the select boxe in the first place of the at-pwd-form div
  26. $('.at-form-authentication')
  27. .detach()
  28. .prependTo('.at-pwd-form');
  29. });
  30. Template.connectionMethod.helpers({
  31. authentications() {
  32. return Template.instance().authenticationMethods.get();
  33. },
  34. isSelected(match) {
  35. return Template.instance().data.authenticationMethod === match;
  36. },
  37. });