auth-changed-message.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function (Misago) {
  2. 'use strict';
  3. function persistent(el, isInit, context) {
  4. context.retain = true;
  5. }
  6. var authChanged = {
  7. refresh: function() {
  8. window.location.reload();
  9. },
  10. view: function(ctrl, _) {
  11. var message = '';
  12. var options = {
  13. config: persistent,
  14. class: (_.auth.isDesynced ? 'show' : null)
  15. };
  16. if (_.auth.isDesynced) {
  17. if (_.auth.newUser && _.auth.newUser.isAuthenticated) {
  18. message = gettext("You have signed in as %(username)s. Please refresh this page before continuing.");
  19. message = interpolate(message, {username: _.auth.newUser.username}, true);
  20. } else {
  21. message = gettext("%(username)s, you have been signed out. Please refresh this page before continuing.");
  22. message = interpolate(message, {username: _.user.username}, true);
  23. }
  24. }
  25. return m('.auth-changed-message', options,
  26. m('',
  27. m('.container', [
  28. m('p',
  29. message
  30. ),
  31. m('p', [
  32. m('button.btn.btn-default[type="button"]', {onclick: this.refresh},
  33. gettext("Reload page")
  34. ),
  35. m('span.hidden-xs.hidden-sm.text-muted',
  36. gettext("or press F5 key.")
  37. )
  38. ])
  39. ])
  40. )
  41. );
  42. }
  43. };
  44. Misago.addService('component:auth-changed-message', function(_) {
  45. _.component('auth-changed-message', authChanged);
  46. },
  47. {
  48. after: 'components'
  49. });
  50. }(Misago.prototype));