layouts.js 2.9 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. 'click #at-btn'(event) {
  63. /* All authentication method can be managed/called here.
  64. !! DON'T FORGET to correctly fill the fields of the user during its creation if necessary authenticationMethod : String !!
  65. */
  66. if (FlowRouter.getRouteName() !== 'atSignIn') {
  67. return;
  68. }
  69. const email = $('#at-field-username_and_email').val();
  70. Meteor.subscribe('user-authenticationMethod', email, {
  71. onReady() {
  72. const user = Users.findOne();
  73. if (user && user.authenticationMethod === 'password') {
  74. return this.stop();
  75. }
  76. // Stop submit #at-pwd-form
  77. event.preventDefault();
  78. event.stopImmediatePropagation();
  79. const password = $('#at-field-password').val();
  80. if (user === undefined || user.authenticationMethod === 'ldap') {
  81. // Use the ldap connection package
  82. Meteor.loginWithLDAP(email, password, function(error) {
  83. if (!error) {
  84. // Connection
  85. return FlowRouter.go('/');
  86. }
  87. return error;
  88. });
  89. }
  90. return this.stop();
  91. },
  92. });
  93. },
  94. });
  95. Template.defaultLayout.events({
  96. 'click .js-close-modal': () => {
  97. Modal.close();
  98. },
  99. });