Fixed changing users sometimes not working
This commit is contained in:
parent
7fc0cd7631
commit
651fc4919f
1 changed files with 32 additions and 26 deletions
|
@ -19,21 +19,26 @@ App.Presenters.UserPresenter = function(
|
||||||
var $messages = $el;
|
var $messages = $el;
|
||||||
var templates = {};
|
var templates = {};
|
||||||
var user;
|
var user;
|
||||||
var userName;
|
var userName = null;
|
||||||
var activeTab;
|
var activeTab;
|
||||||
|
|
||||||
function init(args, loaded) {
|
function init(args, loaded) {
|
||||||
|
promise.wait(util.promiseTemplate('user'))
|
||||||
|
.then(function(template, response) {
|
||||||
|
$messages = $el.find('.messages');
|
||||||
|
templates.user = template;
|
||||||
|
reinit(args, loaded);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reinit(args, loaded) {
|
||||||
|
if (args.userName !== userName) {
|
||||||
userName = args.userName;
|
userName = args.userName;
|
||||||
topNavigationPresenter.select(auth.isLoggedIn(userName) ? 'my-account' : 'users');
|
topNavigationPresenter.select(auth.isLoggedIn(userName) ? 'my-account' : 'users');
|
||||||
topNavigationPresenter.changeTitle(userName);
|
topNavigationPresenter.changeTitle(userName);
|
||||||
|
|
||||||
promise.wait(
|
promise.wait(api.get('/users/' + userName))
|
||||||
util.promiseTemplate('user'),
|
.then(function(response) {
|
||||||
api.get('/users/' + userName))
|
|
||||||
.then(function(template, response) {
|
|
||||||
$messages = $el.find('.messages');
|
|
||||||
templates.user = template;
|
|
||||||
|
|
||||||
user = response.json;
|
user = response.json;
|
||||||
var extendedContext = _.extend(args, {user: user});
|
var extendedContext = _.extend(args, {user: user});
|
||||||
|
|
||||||
|
@ -42,7 +47,8 @@ App.Presenters.UserPresenter = function(
|
||||||
[userAccountSettingsPresenter, _.extend({}, extendedContext, {target: '#account-settings-target'})],
|
[userAccountSettingsPresenter, _.extend({}, extendedContext, {target: '#account-settings-target'})],
|
||||||
[userAccountRemovalPresenter, _.extend({}, extendedContext, {target: '#account-removal-target'})]],
|
[userAccountRemovalPresenter, _.extend({}, extendedContext, {target: '#account-removal-target'})]],
|
||||||
function() {
|
function() {
|
||||||
reinit(args, loaded);
|
initTabs(args);
|
||||||
|
loaded();
|
||||||
});
|
});
|
||||||
|
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
|
@ -50,12 +56,12 @@ App.Presenters.UserPresenter = function(
|
||||||
messagePresenter.showError($messages, response.json && response.json.error || response);
|
messagePresenter.showError($messages, response.json && response.json.error || response);
|
||||||
loaded();
|
loaded();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function reinit(args, loaded) {
|
} else {
|
||||||
initTabs(args);
|
initTabs(args);
|
||||||
loaded();
|
loaded();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function initTabs(args) {
|
function initTabs(args) {
|
||||||
activeTab = args.tab || 'basic-info';
|
activeTab = args.tab || 'basic-info';
|
||||||
|
|
Loading…
Reference in a new issue