openmedialibrary/static/js/peersButton.js
2016-01-16 21:02:40 +05:30

72 lines
1.6 KiB
JavaScript

'use strict';
oml.ui.peersButton = function() {
var that = Ox.Element({
tooltip: Ox._('No peering requests')
})
.css({
marginRight: '6px'
}),
count,
requests = 0;
Ox.Button({
style: 'symbol',
title: 'user',
type: 'image'
})
.css({
float: 'left',
borderRadius: 0
})
.bindEvent({
click: function() {
oml.UI.set({page: 'peers'});
}
})
.appendTo(that);
count = Ox.Element()
.addClass('OxLight')
.css({
float: 'left',
marginTop: '3px',
fontSize: '9px'
})
.html('0')
.bindEvent({
anyclick: function() {
oml.UI.set({page: 'peers'});
}
})
.appendTo(that);
oml.bindEvent({
peering: update
});
update();
function open() {
}
function update() {
// wait for clearCache in folder.js
setTimeout(function() {
oml.api.getUsers(function(result) {
requests = result.data.users.filter(function(user) {
return user.pending=="received";
}).length;
count.html(requests);
that.options({
tooltip: Ox._(requests
? Ox.formatCount(requests, 'peering request')
: 'No peering requests')
});
});
});
}
return that;
};