2014-05-04 17:26:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-05-18 23:24:04 +00:00
|
|
|
oml.ui.statusIcon = function(user, index) {
|
2014-05-04 17:26:43 +00:00
|
|
|
|
2014-05-18 23:24:04 +00:00
|
|
|
var status = getStatus(user),
|
2014-05-04 17:26:43 +00:00
|
|
|
that = Ox.Element({
|
|
|
|
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) {
|
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
|
|
|
};
|