request-link.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Ember from 'ember';
  2. export default Ember.ObjectController.extend({
  3. rpcUrl: 'activation/send-link',
  4. isLoading: false,
  5. email: '',
  6. router: function() {
  7. return this.container.lookup('router:main');
  8. }.property(),
  9. success: function(requestingUser) {
  10. this.send('showSentPage', requestingUser);
  11. this.set('email', '');
  12. },
  13. error: function(jqXHR) {
  14. if (jqXHR.status === 400){
  15. var rejection = jqXHR.responseJSON;
  16. if (rejection.code === 'banned') {
  17. this.get('router').intermediateTransitionTo('error-banned', rejection.detail);
  18. this.set('email', '');
  19. } else {
  20. this.toast.error(rejection.detail);
  21. }
  22. } else {
  23. this.toast.apiError(jqXHR);
  24. }
  25. },
  26. actions: {
  27. submit: function() {
  28. if (this.get('isLoading')) {
  29. return;
  30. }
  31. var email = Ember.$.trim(this.get('email'));
  32. if (email === "") {
  33. this.toast.warning(gettext("Enter e-mail address."));
  34. return;
  35. }
  36. this.set('isLoading', true);
  37. var self = this;
  38. this.rpc.ajax(this.get('rpcUrl'), {
  39. email: email
  40. }).then(function(requestingUser) {
  41. self.success(requestingUser);
  42. }, function(jqXHR) {
  43. self.error(jqXHR);
  44. }).finally(function() {
  45. self.set('isLoading', false);
  46. });
  47. }
  48. }
  49. });