diff --git a/static/js/statusbar.js b/static/js/statusbar.js index 4f5b6a5..cf96974 100644 --- a/static/js/statusbar.js +++ b/static/js/statusbar.js @@ -4,67 +4,66 @@ oml.ui.statusbar = function() { var ui = oml.user.ui, - $text = { - titleTotal: Ox.Element('').html(Ox._('Total: ')), - total: Ox.Element(''), - titleSelected: Ox.Element('').html(' — ' + Ox._('Selected: ')), - selected: Ox.Element(''), - loading: Ox.Element('').html(Ox._('Loading...')) + data = { + loading: true, + selected: {items: 0, size: 0}, + total: {items: 0, size: 0}, }, + $status = Ox.Element() + .css({ + margin: '2px 4px', + fontSize: '9px', + overflow: 'hidden', + textOverflow: 'ellipsis' + }), + that = Ox.Bar({size: 16}) .css({textAlign: 'center'}) - .append( - Ox.Element() - .css({ - margin: '2px 4px', - fontSize: '9px', - overflow: 'hidden', - textOverflow: 'ellipsis' - }) - .append($text.loading) - .append($text.titleTotal) - .append($text.total) - .append($text.titleSelected) - .append($text.selected) - ) + .append($status) .bindEvent({ + oml_find: function(data) { + that.set('loading', true); + }, oml_listselection: function(data) { - // ... + if (ui.listSelection.length) { + oml.api.find({ + query: { + conditions: ui.listSelection.map(function(id) { + return { + key: 'id', + operator: '==', + value: id + }; + }), + operator: '|' + } + }, function(result) { + that.set('selected', result.data); + }); + } else { + that.set('selected', {items: 0, size: 0}); + } } }); - function getText(data) { - return Ox.toTitleCase(Ox.formatCount(data.items, 'book')) + ( - data.items ? ', ' + Ox.formatValue(data.size, 'B') : '' - ); - } - - that.set = function(key, data) { - if (key == 'loading') { - Ox.forEach($text, function($element, key) { - $element[key == 'loading' ? 'show' : 'hide'](); - }); - } else { - $text.loading.hide(); - if (key == 'selected') { - if (data.items == 0) { - $text.titleTotal.hide(); - $text.titleSelected.hide(); - $text.selected.hide(); - } else { - $text.titleTotal.show(); - $text.titleSelected.show(); - $text.selected.html(getText(data)).show(); - } - } else { - $text.total.html(getText(data)).show(); - } + that.set = function(key, value) { + var hasSelection; + data[key] = value; + if (key != 'loading') { + data.loading = false; } + 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') : '' + ))); }; - that.set('loading'); - return that; }; \ No newline at end of file