openmedialibrary/static/js/statusbar.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.ui.statusbar = function() {
var ui = oml.user.ui,
2016-01-14 07:09:51 +00:00
data = {
loading: true,
selected: {items: 0, size: 0},
total: {items: 0, size: 0},
2014-05-04 17:26:43 +00:00
},
2016-01-14 07:09:51 +00:00
$status = Ox.Element()
.css({
margin: '2px 4px',
fontSize: '9px',
overflow: 'hidden',
textOverflow: 'ellipsis'
}),
2014-05-04 17:26:43 +00:00
that = Ox.Bar({size: 16})
.css({textAlign: 'center'})
2016-01-14 07:09:51 +00:00
.append($status)
2014-05-04 17:26:43 +00:00
.bindEvent({
2016-01-14 07:09:51 +00:00
oml_find: function(data) {
that.set('loading', true);
},
2014-05-04 17:26:43 +00:00
oml_listselection: function(data) {
2016-01-14 07:09:51 +00:00
if (ui.listSelection.length) {
oml.api.find({
query: {
conditions: [{
2016-01-14 07:09:51 +00:00
key: 'id',
operator: '&',
value: ui.listSelection
}],
operator: '&'
2016-01-14 07:09:51 +00:00
}
}, function(result) {
that.set('selected', result.data);
});
} else {
that.set('selected', {items: 0, size: 0});
}
2014-05-04 17:26:43 +00:00
}
});
2016-01-14 07:09:51 +00:00
that.set = function(key, value) {
var hasSelection;
data[key] = value;
if (key != 'loading') {
data.loading = false;
2014-05-04 17:26:43 +00:00
}
2016-01-14 07:09:51 +00:00
hasSelection = data.selected.items
&& data.selected.items < data.total.items;
$status.html(data.loading ? Ox._('Loading...') : ((
hasSelection ? Ox.formatNumber(data.selected.items) + ' of ' : ''
) + Ox.toTitleCase(Ox.formatCount(data.total.items, 'book')) + (
data.total.items ? ', ' + (
hasSelection ? Ox.formatValue(data.selected.size, 'B') + ' of ' : ''
) + Ox.formatValue(data.total.size, 'B') : ''
)));
2014-05-04 17:26:43 +00:00
};
return that;
};