pandora/static/js/statusbar.js

89 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2011-11-05 17:04:10 +00:00
'use strict';
2011-05-25 19:42:45 +00:00
pandora.ui.statusbar = function() {
var $text = {
2013-05-09 10:13:58 +00:00
titleTotal: Ox.Element('<span>').html(Ox._('Total: ')),
total: Ox.Element('<span>'),
2013-05-09 10:13:58 +00:00
titleSelected: Ox.Element('<span>').html(' &mdash; ' + Ox._('Selected: ')),
selected: Ox.Element('<span>'),
2013-05-09 10:13:58 +00:00
loading: Ox.Element('<span>').html(Ox._('Loading...'))
},
that = Ox.Bar({size: 16})
2014-01-07 11:37:39 +00:00
.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)
);
function setTotal() {
pandora.api.find({
query: pandora.user.ui.find,
sort: pandora.user.ui.listSort
}, function(result) {
that.set('selected', {items: 0});
that.set('total', result.data);
});
}
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();
2013-03-09 05:27:07 +00:00
$text.selected.html(pandora.getStatusText(data)).show();
}
} else {
2013-03-09 05:27:07 +00:00
$text.total.html(pandora.getStatusText(data)).show();
}
}
};
that.bindEvent({
pandora_find: function() {
that.set('loading');
if (['map', 'calendar'].indexOf(pandora.user.ui.listView) > -1) {
setTotal();
}
},
pandora_listview: function(data) {
var isNavigationView = ['map', 'calendar'].indexOf(data.value) > -1,
wasNavigationView = ['map', 'calendar'].indexOf(data.previousValue) > -1;
that.set('loading');
if (isNavigationView && !wasNavigationView) {
setTotal();
}
}
});
that.set('loading');
if (['map', 'calendar'].indexOf(pandora.user.ui.listView) > -1) {
setTotal();
}
2011-05-25 19:42:45 +00:00
return that;
2011-05-25 19:42:45 +00:00
};