usersDialog

This commit is contained in:
j 2014-05-17 01:50:20 +02:00
parent c58a8a5bcb
commit ec83ec052c

View file

@ -62,6 +62,7 @@ oml.ui.usersDialog = function() {
}), }),
users, users,
peerIds = [],
buttons = [ buttons = [
{id: 'send', title: Ox._('Send')}, {id: 'send', title: Ox._('Send')},
@ -284,11 +285,12 @@ oml.ui.usersDialog = function() {
var isOwn = data.value == oml.user.id, var isOwn = data.value == oml.user.id,
isPeer = Ox.contains(peerIds, data.value), isPeer = Ox.contains(peerIds, data.value),
isValid = oml.validatePublicKey(data.value), isValid = oml.validatePublicKey(data.value),
peer = Ox.getObjectById(users, data.value); peer = Ox.getObjectById(users, data.value),
$sendButton.options({ disabled = isOwn || isPeer || !isValid;
disabled: isOwn || isPeer || !isValid $buttons[0].options({
disabled: disabled
}); });
if (data.value && $sendButton.options('disabled')) { if (data.value && disabled) {
$warning.html( $warning.html(
isOwn ? 'That\'s your own public key.' isOwn ? 'That\'s your own public key.'
: isPeer ? 'That\'s ' : isPeer ? 'That\'s '
@ -383,19 +385,31 @@ oml.ui.usersDialog = function() {
}; };
if (id == 'send') { if (id == 'send') {
oml.api.requestPeering(data, function(result) { oml.api.requestPeering(data, function(result) {
Ox.Request.clearCache();
updateUsers(function() {
selectUser(user.id);
});
}); });
} else if (id == 'cancel') { } else if (id == 'cancel') {
oml.api.cancelPeering(data, function(result) { oml.api.cancelPeering(data, function(result) {
Ox.Request.clearCache();
updateUsers(function() {
selectUser(user.id);
});
}); });
} else if (id == 'accept') { } else if (id == 'accept') {
oml.api.acceptPeering(data, function(result) { oml.api.acceptPeering(data, function(result) {
Ox.Request.clearCache();
updateUsers(function() {
selectUser(user.id);
});
}); });
} else if (id == 'reject') { } else if (id == 'reject') {
oml.api.rejectPeering(data, function(result) { oml.api.rejectPeering(data, function(result) {
Ox.Request.clearCache();
updateUsers(function() {
selectUser(user.id);
});
}); });
} else if (id == 'remove') { } else if (id == 'remove') {
oml.ui.confirmDialog({ oml.ui.confirmDialog({
@ -411,7 +425,10 @@ oml.ui.usersDialog = function() {
content: Ox._('Are you sure you want to remove this peer?') content: Ox._('Are you sure you want to remove this peer?')
}, function() { }, function() {
oml.api.removePeering(data, function(result) { oml.api.removePeering(data, function(result) {
// ... Ox.Request.clearCache();
updateUsers(function() {
selectUser(user.id);
});
}); });
}); });
} }
@ -478,6 +495,17 @@ oml.ui.usersDialog = function() {
} }
function selectUser(id) {
$lists.forEach(function($list) {
var item = $list.options('items').filter(function(item) {
return item.id == id;
})[0];
if (item) {
selectItem($list, id);
}
});
}
function selectItem($list, id) { function selectItem($list, id) {
$lists.forEach(function($element) { $lists.forEach(function($element) {
if ($element == $list) { if ($element == $list) {
@ -492,19 +520,15 @@ oml.ui.usersDialog = function() {
} }
} }
function updateUsers() { function updateUsers(callback) {
// ...
}
that.update = function() {
that.options({
content: Ox.LoadingScreen().start()
});
oml.api.getUsers(function(result) { oml.api.getUsers(function(result) {
users = result.data.users; users = result.data.users;
peerIds = users.filter(function(user) {
return user.peered;
}).map(function(user) {
return user.id
});
folders.forEach(function(folder) { folders.forEach(function(folder) {
folder.items = []; folder.items = [];
}); });
@ -519,6 +543,10 @@ oml.ui.usersDialog = function() {
); );
}); });
$lists.splice(1).forEach(function(folder) {
folder.remove();
});
folders.forEach(function(folder, index) { folders.forEach(function(folder, index) {
$lists.push( $lists.push(
( (
@ -549,13 +577,21 @@ oml.ui.usersDialog = function() {
}); });
that.options({content: $panel}); that.options({content: $panel});
callback && callback();
}); });
}
that.update = function() {
that.options({
content: Ox.LoadingScreen().start()
});
updateUsers();
return that; return that;
}; };
return that.update(); return that.update();
}; };