client/views: move notifications to controllers
This commit is contained in:
parent
0ceaa8da42
commit
5bd7f1fa6c
7 changed files with 44 additions and 40 deletions
|
@ -33,7 +33,10 @@ class AuthController {
|
||||||
resolve();
|
resolve();
|
||||||
page('/');
|
page('/');
|
||||||
events.notify(events.Success, 'Logged in');
|
events.notify(events.Success, 'Logged in');
|
||||||
}).catch(errorMessage => { reject(errorMessage); });
|
}).catch(errorMessage => {
|
||||||
|
reject(errorMessage);
|
||||||
|
events.notify(events.Error, errorMessage);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
@ -47,13 +50,8 @@ class AuthController {
|
||||||
passwordResetRoute() {
|
passwordResetRoute() {
|
||||||
topNavController.activate('login');
|
topNavController.activate('login');
|
||||||
this.passwordResetView.render({
|
this.passwordResetView.render({
|
||||||
proceed: nameOrEmail => {
|
proceed: (...args) => {
|
||||||
api.logout();
|
return this._passwordReset(...args);
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
api.get('/password-reset/' + nameOrEmail)
|
|
||||||
.then(() => { resolve(); })
|
|
||||||
.catch(errorMessage => { reject(errorMessage); });
|
|
||||||
});
|
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +74,23 @@ class AuthController {
|
||||||
events.notify(events.Error, response.description);
|
events.notify(events.Error, response.description);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_passwordReset(nameOrEmail) {
|
||||||
|
api.logout();
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
api.get('/password-reset/' + nameOrEmail)
|
||||||
|
.then(() => {
|
||||||
|
resolve();
|
||||||
|
events.notify(
|
||||||
|
events.Success,
|
||||||
|
'E-mail has been sent. To finish the procedure, ' +
|
||||||
|
'please click the link it contains.');
|
||||||
|
}).catch(response => {
|
||||||
|
reject();
|
||||||
|
events.notify(events.Error, response.description);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new AuthController();
|
module.exports = new AuthController();
|
||||||
|
|
|
@ -72,11 +72,13 @@ class UsersController {
|
||||||
resolve();
|
resolve();
|
||||||
page('/');
|
page('/');
|
||||||
events.notify(events.Success, 'Welcome aboard!');
|
events.notify(events.Success, 'Welcome aboard!');
|
||||||
}).catch(response => {
|
}).catch(errorMessage => {
|
||||||
reject(response.description);
|
reject();
|
||||||
|
events.notify(events.Error, errorMessage);
|
||||||
});
|
});
|
||||||
}).catch(response => {
|
}).catch(response => {
|
||||||
reject(response.description);
|
reject();
|
||||||
|
events.notify(events.Error, response.description);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -103,10 +105,9 @@ class UsersController {
|
||||||
newPassword || api.userPassword,
|
newPassword || api.userPassword,
|
||||||
false)
|
false)
|
||||||
.then(next)
|
.then(next)
|
||||||
.catch(response => {
|
.catch(errorMessage => {
|
||||||
reject();
|
reject();
|
||||||
events.notify(
|
events.notify(events.Error, errorMessage);
|
||||||
events.Error, response.description);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
|
|
|
@ -27,3 +27,13 @@ if (!Object.entries) {
|
||||||
|
|
||||||
// fix iterating over NodeList in Chrome and Opera
|
// fix iterating over NodeList in Chrome and Opera
|
||||||
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
|
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
|
||||||
|
|
||||||
|
// non standard
|
||||||
|
Promise.prototype.always = function(onResolveOrReject) {
|
||||||
|
return this.then(
|
||||||
|
onResolveOrReject,
|
||||||
|
reason => {
|
||||||
|
onResolveOrReject(reason);
|
||||||
|
throw reason;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
@ -31,13 +31,7 @@ class LoginView extends BaseView {
|
||||||
userNameField.value,
|
userNameField.value,
|
||||||
passwordField.value,
|
passwordField.value,
|
||||||
rememberUserField.checked)
|
rememberUserField.checked)
|
||||||
.then(() => {
|
.always(() => { this.enableForm(form); });
|
||||||
this.enableForm(form);
|
|
||||||
})
|
|
||||||
.catch(errorMessage => {
|
|
||||||
this.enableForm(form);
|
|
||||||
events.notify(events.Error, errorMessage);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.showView(target, source);
|
this.showView(target, source);
|
||||||
|
|
|
@ -23,16 +23,7 @@ class PasswordResetView extends BaseView {
|
||||||
this.clearMessages();
|
this.clearMessages();
|
||||||
this.disableForm(form);
|
this.disableForm(form);
|
||||||
ctx.proceed(userNameOrEmailField.value)
|
ctx.proceed(userNameOrEmailField.value)
|
||||||
.then(() => {
|
.catch(() => { this.enableForm(form); });
|
||||||
events.notify(
|
|
||||||
events.Success,
|
|
||||||
'E-mail has been sent. To finish the procedure, ' +
|
|
||||||
'please click the link it contains.');
|
|
||||||
})
|
|
||||||
.catch(errorMessage => {
|
|
||||||
this.enableForm(form);
|
|
||||||
events.notify(events.Error, errorMessage);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.showView(target, source);
|
this.showView(target, source);
|
||||||
|
|
|
@ -31,13 +31,7 @@ class RegistrationView extends BaseView {
|
||||||
userNameField.value,
|
userNameField.value,
|
||||||
passwordField.value,
|
passwordField.value,
|
||||||
emailField.value)
|
emailField.value)
|
||||||
.then(() => {
|
.always(() => { this.enableForm(form); });
|
||||||
this.enableForm(form);
|
|
||||||
})
|
|
||||||
.catch(errorMessage => {
|
|
||||||
this.enableForm(form);
|
|
||||||
events.notify(events.Error, errorMessage);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.showView(target, source);
|
this.showView(target, source);
|
||||||
|
|
|
@ -48,8 +48,7 @@ class UserEditView extends BaseView {
|
||||||
passwordField.value,
|
passwordField.value,
|
||||||
emailField.value,
|
emailField.value,
|
||||||
rankField.value)
|
rankField.value)
|
||||||
.then(user => { this.enableForm(form); })
|
.always(() => { this.enableForm(form); });
|
||||||
.catch(() => { this.enableForm(form); });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.showView(target, source);
|
this.showView(target, source);
|
||||||
|
|
Loading…
Reference in a new issue