openmedialibrary/static/js/peersButton.js

72 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
2016-01-13 07:04:35 +00:00
oml.ui.peersButton = function() {
2014-05-04 17:26:43 +00:00
2016-01-17 07:43:33 +00:00
var requests = 0,
that = Ox.Element({
tooltip: Ox._('No peering requests')
})
.css({
marginRight: '6px'
}),
$count;
2014-05-04 17:26:43 +00:00
Ox.Button({
style: 'symbol',
2016-01-13 04:49:49 +00:00
title: 'user',
2014-05-04 17:26:43 +00:00
type: 'image'
})
.css({
float: 'left',
borderRadius: 0
})
2016-01-13 07:25:15 +00:00
.bindEvent({
2016-01-16 15:32:40 +00:00
click: function() {
oml.UI.set({page: 'peers'});
}
2016-01-13 07:25:15 +00:00
})
2014-05-04 17:26:43 +00:00
.appendTo(that);
2016-01-17 07:43:33 +00:00
$count = Ox.Element()
2014-05-04 17:26:43 +00:00
.addClass('OxLight')
.css({
float: 'left',
2016-01-13 07:25:15 +00:00
marginTop: '3px',
2014-05-04 17:26:43 +00:00
fontSize: '9px'
})
.html('0')
2016-01-16 15:32:40 +00:00
.bindEvent({
anyclick: function() {
oml.UI.set({page: 'peers'});
}
})
2014-05-04 17:26:43 +00:00
.appendTo(that);
2016-01-13 07:25:15 +00:00
oml.bindEvent({
2016-01-13 09:52:25 +00:00
peering: update
2016-01-13 07:25:15 +00:00
});
update();
function update() {
2016-01-13 09:52:25 +00:00
// wait for clearCache in folder.js
setTimeout(function() {
oml.api.getUsers(function(result) {
requests = result.data.users.filter(function(user) {
2016-01-17 07:43:33 +00:00
return user.pending == 'received';
2016-01-13 09:52:25 +00:00
}).length;
2016-01-17 07:43:33 +00:00
$count.html(requests);
2016-01-13 09:52:25 +00:00
that.options({
2016-01-17 07:43:33 +00:00
tooltip: requests
? Ox.formatCount(requests, '{0} peering request')
: Ox._('No peering requests')
2016-01-13 09:52:25 +00:00
});
2016-01-13 07:25:15 +00:00
});
});
}
2014-05-04 17:26:43 +00:00
return that;
2016-01-13 07:25:15 +00:00
};