openmedialibrary/static/js/statusIcon.js

100 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
2014-05-18 23:24:04 +00:00
oml.ui.statusIcon = function(user, index) {
var status = 'unknown';
status = getStatus(user);
var that = Ox.Element({
2014-05-04 17:26:43 +00:00
tooltip: Ox._({
connected: 'Connected',
disconnected: 'Disconnected',
transferring: 'Transferring'
}[status])
})
.css({
width: '10px',
height: '10px',
margin: '3px',
borderRadius: '5px'
})
.append(
$('<div>')
.css({
width: '8px',
height: '8px',
margin: '1px',
borderRadius: '4px'
})
);
2014-05-18 23:24:04 +00:00
render();
if (user) {
var superRemove = that.remove;
that.remove = function() {
oml.unbindEvent({
status: update
})
superRemove();
};
oml.bindEvent({
status: update
});
}
2014-05-04 17:26:43 +00:00
2014-05-18 23:24:04 +00:00
function getStatus(data) {
if (user.id != oml.user.id && data.id == oml.user.id && data.online) {
return status == 'unknown' ? 'disconnected' : status;
}
2016-02-07 08:25:12 +00:00
if (data.local) {
return 'connected';
}
2015-12-02 21:05:23 +00:00
if (!oml.user.online) {
return 'unknown';
}
if (user.id == data.id) {
return data.online ? 'connected' : 'disconnected';
}
return status || 'unknown';
2014-05-18 23:24:04 +00:00
}
function render() {
var color = {
2014-05-19 15:00:33 +00:00
connected: [[64, 255, 64], [0, 192, 0]],
disconnected: [[255, 64, 64], [192, 0, 0]],
transferring: [[64, 255, 255], [0, 192, 192]],
unknown: [[255, 255, 64], [192, 192, 0]]
}[status].map(function(rgb) {
return 'rgb(' + rgb.join(', ') + ')';
}).join(', ');
2014-05-18 23:24:04 +00:00
that.options({
tooltip: Ox._({
connected: 'Connected',
disconnected: 'Disconnected',
transferring: 'Transferring'
}[status])
}).css({
2015-02-22 11:39:33 +00:00
background: '-moz-linear-gradient(bottom, ' + color + ')'
}).css({
background: '-webkit-linear-gradient(bottom, ' + color + ')'
2014-05-18 23:24:04 +00:00
});
that.find('div').css({
2015-02-22 11:39:33 +00:00
background: '-moz-linear-gradient(top, ' + color + ')'
}).css({
background: '-webkit-linear-gradient(top, ' + color + ')'
2014-05-18 23:24:04 +00:00
});
}
function update(data) {
2015-12-02 21:05:23 +00:00
if (data.id == user.id || data.id == oml.user.id) {
2014-05-18 23:24:04 +00:00
var newStatus = getStatus(data);
if (status != newStatus) {
status = newStatus;
render();
}
}
}
return that;
2014-05-19 15:00:33 +00:00
2014-05-18 23:24:04 +00:00
};