openmedialibrary/static/js/peersButton.js

68 lines
1.4 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
var that = Ox.Element({
2016-01-13 04:49:49 +00:00
tooltip: Ox._('No peering requests')
2014-05-04 17:26:43 +00:00
})
.css({
2016-01-13 04:49:49 +00:00
marginRight: '6px'
2014-05-04 17:26:43 +00:00
})
.bindEvent({
2016-01-13 07:25:15 +00:00
click: open
}),
count,
requests = 0;
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({
click: open
})
2014-05-04 17:26:43 +00:00
.appendTo(that);
2016-01-13 07:25:15 +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')
.appendTo(that);
2016-01-13 07:25:15 +00:00
oml.bindEvent({
'peering.request': update,
'peering.accept': update,
'peering.reject': update
});
update();
function open() {
oml.UI.set({page: 'users'});
}
function update() {
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')
});
});
}
2014-05-04 17:26:43 +00:00
return that;
2016-01-13 07:25:15 +00:00
};