improve statusbar
This commit is contained in:
parent
ca1a23f856
commit
9b95bb067e
1 changed files with 48 additions and 49 deletions
|
@ -4,66 +4,65 @@ oml.ui.statusbar = function() {
|
|||
|
||||
var ui = oml.user.ui,
|
||||
|
||||
$text = {
|
||||
titleTotal: Ox.Element('<span>').html(Ox._('Total: ')),
|
||||
total: Ox.Element('<span>'),
|
||||
titleSelected: Ox.Element('<span>').html(' — ' + Ox._('Selected: ')),
|
||||
selected: Ox.Element('<span>'),
|
||||
loading: Ox.Element('<span>').html(Ox._('Loading...'))
|
||||
data = {
|
||||
loading: true,
|
||||
selected: {items: 0, size: 0},
|
||||
total: {items: 0, size: 0},
|
||||
},
|
||||
|
||||
that = Ox.Bar({size: 16})
|
||||
.css({textAlign: 'center'})
|
||||
.append(
|
||||
Ox.Element()
|
||||
$status = 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)
|
||||
)
|
||||
}),
|
||||
|
||||
that = Ox.Bar({size: 16})
|
||||
.css({textAlign: 'center'})
|
||||
.append($status)
|
||||
.bindEvent({
|
||||
oml_find: function(data) {
|
||||
that.set('loading', true);
|
||||
},
|
||||
oml_listselection: function(data) {
|
||||
// ...
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
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});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
that.set('loading');
|
||||
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') : ''
|
||||
)));
|
||||
};
|
||||
|
||||
return that;
|
||||
|
||||
|
|
Loading…
Reference in a new issue