layouts.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. BlazeLayout.setRoot('body');
  2. const i18nTagToT9n = (i18nTag) => {
  3. // t9n/i18n tags are same now, see: https://github.com/softwarerero/meteor-accounts-t9n/pull/129
  4. // but we keep this conversion function here, to be aware that that they are different system.
  5. return i18nTag;
  6. };
  7. Template.userFormsLayout.onRendered(() => {
  8. const i18nTag = navigator.language;
  9. if (i18nTag) {
  10. T9n.setLanguage(i18nTagToT9n(i18nTag));
  11. }
  12. EscapeActions.executeAll();
  13. });
  14. Template.userFormsLayout.helpers({
  15. languages() {
  16. return _.map(TAPi18n.getLanguages(), (lang, code) => {
  17. const tag = code;
  18. let name = lang.name;
  19. if (lang.name === 'br') {
  20. name = 'Brezhoneg';
  21. } else if (lang.name === 'ig') {
  22. name = 'Igbo';
  23. }
  24. return { tag, name };
  25. }).sort(function(a, b) {
  26. if (a.name === b.name) {
  27. return 0;
  28. } else {
  29. return a.name > b.name ? 1 : -1;
  30. }
  31. });
  32. },
  33. isCurrentLanguage() {
  34. const t9nTag = i18nTagToT9n(this.tag);
  35. const curLang = T9n.getLanguage() || 'en';
  36. return t9nTag === curLang;
  37. },
  38. /*
  39. isCas() {
  40. return Meteor.settings.public &&
  41. Meteor.settings.public.cas &&
  42. Meteor.settings.public.cas.loginUrl;
  43. },
  44. casSignInLabel() {
  45. return TAPi18n.__('casSignIn', {}, T9n.getLanguage() || 'en');
  46. },
  47. */
  48. });
  49. Template.userFormsLayout.events({
  50. 'change .js-userform-set-language'(evt) {
  51. const i18nTag = $(evt.currentTarget).val();
  52. T9n.setLanguage(i18nTagToT9n(i18nTag));
  53. evt.preventDefault();
  54. },
  55. 'click button#cas'() {
  56. Meteor.loginWithCas(function() {
  57. if (FlowRouter.getRouteName() === 'atSignIn') {
  58. FlowRouter.go('/');
  59. }
  60. });
  61. },
  62. 'submit form'(event) {
  63. const connectionMethod = $('.select-connection').val();
  64. // Local account
  65. if (connectionMethod === 'default') {
  66. return;
  67. }
  68. // TODO : find a way to block "submit #at-pwd-form" of the at_pwd_form.js
  69. const inputs = event.target.getElementsByTagName('input');
  70. const email = inputs.namedItem('at-field-username_and_email').value;
  71. const password = inputs.namedItem('at-field-password').value;
  72. // Ldap account
  73. if (connectionMethod === 'ldap') {
  74. // Check if the user can use the ldap connection
  75. Meteor.subscribe('user-connection-method', email, {
  76. onReady() {
  77. const ldap = Users.findOne();
  78. if (ldap) {
  79. // Use the ldap connection package
  80. Meteor.loginWithLDAP(email, password, function(error) {
  81. if (!error) {
  82. // Connection
  83. return FlowRouter.go('/');
  84. } else {
  85. return error;
  86. }
  87. });
  88. }
  89. return this.stop();
  90. },
  91. });
  92. }
  93. },
  94. });
  95. Template.defaultLayout.events({
  96. 'click .js-close-modal': () => {
  97. Modal.close();
  98. },
  99. });