12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import Ember from 'ember';
- export default Ember.ObjectController.extend({
- rpcUrl: 'activation/send-link',
- isLoading: false,
- email: '',
- router: function() {
- return this.container.lookup('router:main');
- }.property(),
- success: function(requestingUser) {
- this.send('showSentPage', requestingUser);
- this.set('email', '');
- },
- error: function(jqXHR) {
- if (jqXHR.status === 400){
- var rejection = jqXHR.responseJSON;
- if (rejection.code === 'banned') {
- this.get('router').intermediateTransitionTo('error-banned', rejection.detail);
- this.set('email', '');
- } else {
- this.toast.error(rejection.detail);
- }
- } else {
- this.toast.apiError(jqXHR);
- }
- },
- actions: {
- submit: function() {
- if (this.get('isLoading')) {
- return;
- }
- var email = Ember.$.trim(this.get('email'));
- if (email === "") {
- this.toast.warning(gettext("Enter e-mail address."));
- return;
- }
- this.set('isLoading', true);
- var self = this;
- this.rpc.ajax(this.get('rpcUrl'), {
- email: email
- }).then(function(requestingUser) {
- self.success(requestingUser);
- }, function(jqXHR) {
- self.error(jqXHR);
- }).finally(function() {
- self.set('isLoading', false);
- });
- }
- }
- });
|