mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-24 06:34:13 +00:00
Cleanup, fix UserPanel
This commit is contained in:
@@ -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
|
||||
|
||||
12
js/id/ui.js
12
js/id/ui.js
@@ -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')
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user