loleaflet: User count in user list

Change-Id: Idde4e1bdf1b33590c3b9a8265e059c01943f4777
This commit is contained in:
Pranav Kant 2016-09-01 11:25:08 +05:30
parent 958c0e3534
commit 04064b2e23

View file

@ -468,7 +468,7 @@ $(function () {
{type: 'html', id: 'right'},
{type: 'html', id: 'modifiedstatuslabel', html: '<div id="modifiedstatuslabel" class="loleaflet-font"></div>'},
{type: 'break'},
{type: 'menu', id: 'userlist', caption: _('Users'), items: [
{type: 'menu', id: 'userlist', caption: _('1 user'), items: [
{ id: '-1', text: _('You'), disabled: true },
]},
{type: 'break'},
@ -1357,7 +1357,20 @@ function getUserListItem(viewId, userName) {
var userListItem = { id: viewId, text: userName, disabled: true };
return userListItem;
}
var nUsers = _('%n users');
function updateUserListCount(userlist) {
var count = userlist.items.length;
if (count > 1) {
userlist.caption = nUsers.replace('%n', count);
} else if (count === 1) {
userlist.caption = '1 user';
}
}
map.on('addview', function(e) {
if (!e.viewId || !e.username)
return;
$('#tb_toolbar-down_item_userlist')
.w2overlay({
class: 'loleaflet-font',
@ -1374,10 +1387,14 @@ map.on('addview', function(e) {
var userlist = w2ui['toolbar-down'].get('userlist');
userlist.items.push(getUserListItem(e.viewId, e.username));
updateUserListCount(userlist);
w2ui['toolbar-down'].refresh();
});
map.on('removeview', function(e) {
if (!e.viewId || !e.username)
return;
$('#tb_toolbar-down_item_userlist')
.w2overlay({
class: 'loleaflet-font',
@ -1395,9 +1412,11 @@ map.on('removeview', function(e) {
for (var idx in userlist.items) {
if (userlist.items[idx].id == e.viewId) {
userlist.items.splice(idx, 1);
break;
}
}
updateUserListCount(userlist);
w2ui['toolbar-down'].refresh();
});