openmedialibrary/static/js/peersButton.js

69 lines
1.5 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
var that = Ox.Element({
2016-01-13 10:19:49 +05:30
tooltip: Ox._('No peering requests')
2014-05-04 19:26:43 +02:00
})
.css({
2016-01-13 10:19:49 +05:30
marginRight: '6px'
2014-05-04 19:26:43 +02:00
})
.bindEvent({
2016-01-13 12:55:15 +05:30
click: open
}),
count,
requests = 0;
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({
click: open
})
2014-05-04 19:26:43 +02:00
.appendTo(that);
2016-01-13 12:55:15 +05:30
count = Ox.Element()
2014-05-04 19:26:43 +02:00
.addClass('OxLight')
.css({
float: 'left',
2016-01-13 12:55:15 +05:30
marginTop: '3px',
2014-05-04 19:26:43 +02:00
fontSize: '9px'
})
.html('0')
.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 open() {
2016-01-13 15:22:25 +05:30
oml.UI.set({page: 'peers'});
2016-01-13 12:55:15 +05:30
}
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) {
return user.pending=="received";
}).length;
count.html(requests);
that.options({
tooltip: Ox._(requests
? Ox.formatCount(requests, 'peering request')
: 'No peering requests')
});
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
};