openmedialibrary/static/js/peersButton.js

73 lines
1.6 KiB
JavaScript
Raw Normal View History

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