Cleanup, fix UserPanel

This commit is contained in:
John Firebaugh
2013-02-12 21:03:34 -08:00
parent 6f6958ad98
commit 4bbed7e943
3 changed files with 52 additions and 59 deletions

View File

@@ -228,7 +228,7 @@ iD.Connection = function(context) {
if (img && img[0].getAttribute('href')) {
image_url = img[0].getAttribute('href');
}
callback(connection.user({
callback(undefined, connection.user({
display_name: u.attributes.display_name.nodeValue,
image_url: image_url,
id: u.attributes.id.nodeValue

View File

@@ -60,15 +60,9 @@ iD.ui = function(context) {
var about = container.append('div')
.attr('class','col12 about-block fillD pad1');
var userContainer = about.append('div')
.attr('class', 'user-container');
userContainer.append('div')
.attr('class', 'hello');
userContainer.call(iD.ui.UserPanel(connection)
.on('logout.editor', connection.logout)
.on('login.editor', connection.authenticate));
about.append('div')
.attr('class', 'user-container')
.call(iD.ui.UserPanel(context));
var linkList = about.append('ul')
.attr('id', 'about')

View File

@@ -1,54 +1,53 @@
iD.ui.UserPanel = function(connection) {
var event = d3.dispatch('logout', 'login');
iD.ui.UserPanel = function(context) {
var connection = context.connection();
function user(selection) {
function update() {
if (connection.authenticated()) {
selection.style('display', 'block');
connection.userDetails(function(err, user_details) {
selection.html('');
if (err) return;
// Link
var userLink = selection.append('a')
.attr('href', connection.url() + '/user/' +
user_details.display_name)
.attr('target', '_blank');
// Add thumbnail or dont
if (user_details.image_url) {
userLink.append('img')
.attr('class', 'icon icon-pre-text user-icon')
.attr('src', user_details.image_url);
} else {
userLink.append('span')
.attr('class','icon avatar icon-pre-text');
}
// Add user name
userLink.append('span')
.attr('class','label')
.text(user_details.display_name);
selection
.append('a')
.attr('class', 'logout')
.attr('href', '#')
.text(t('logout'))
.on('click.logout', function() {
d3.event.preventDefault();
event.logout();
});
});
} else {
selection.html('').style('display', 'none');
}
function update(selection) {
if (!connection.authenticated()) {
selection.html('')
.style('display', 'none');
return;
}
connection.on('auth', update);
update();
selection.style('display', 'block');
connection.userDetails(function(err, details) {
selection.html('');
if (err) return;
// Link
var userLink = selection.append('a')
.attr('href', connection.url() + '/user/' + details.display_name)
.attr('target', '_blank');
// Add thumbnail or dont
if (details.image_url) {
userLink.append('img')
.attr('class', 'icon icon-pre-text user-icon')
.attr('src', details.image_url);
} else {
userLink.append('span')
.attr('class', 'icon avatar icon-pre-text');
}
// Add user name
userLink.append('span')
.attr('class', 'label')
.text(details.display_name);
selection.append('a')
.attr('class', 'logout')
.attr('href', '#')
.text(t('logout'))
.on('click.logout', function() {
d3.event.preventDefault();
connection.logout();
});
});
}
return d3.rebind(user, event, 'on');
return function(selection) {
connection.on('auth', function() { update(selection); });
update(selection);
};
};