register-button.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. (function (Misago) {
  2. 'use strict';
  3. var button = {
  4. controller: function(style, _) {
  5. return {
  6. isBusy: false,
  7. showRegister: function() {
  8. if (_.settings.account_activation === 'closed') {
  9. _.alert.info(gettext("New registrations are currently disabled."));
  10. } else {
  11. m.startComputation();
  12. this.isBusy = true;
  13. m.endComputation();
  14. var self = this;
  15. m.sync([
  16. _.zxcvbn.load(),
  17. _.captcha.load()
  18. ]).then(function() {
  19. _.modal('register');
  20. }, function() {
  21. _.alert.error(gettext('Registation is not available now due to an error.'));
  22. }).then(function() {
  23. m.startComputation();
  24. self.isBusy = false;
  25. m.endComputation();
  26. });
  27. }
  28. }
  29. };
  30. },
  31. view: function(ctrl, style, _) {
  32. return _.component('button', {
  33. class: style,
  34. onclick: ctrl.showRegister.bind(ctrl),
  35. loading: ctrl.isBusy,
  36. label: gettext('Register')
  37. });
  38. }
  39. };
  40. Misago.addService('component:navbar:register-button', function(_) {
  41. _.component('navbar:register-button', button);
  42. },
  43. {
  44. after: 'components'
  45. });
  46. }(Misago.prototype));