openmedialibrary/static/js/sortElement.js

77 lines
2 KiB
JavaScript
Raw Normal View History

2014-05-04 17:26:43 +00:00
'use strict';
oml.ui.sortElement = function() {
var ui = oml.user.ui,
$sortSelect = Ox.Select({
items: oml.config.sortKeys.map(function(key) {
return Ox.extend({}, key, {
title: Ox._('Sort by {0}', [Ox._(key.title)])
});
}),
style: 'squared',
value: ui.listSort[0].key,
width: 160
})
.bindEvent({
change: function(data) {
var key = data.value;
oml.UI.set({
2014-05-17 11:45:57 +00:00
listSort: [{key: key, operator: oml.getSortOperator(key)}]
2014-05-04 17:26:43 +00:00
});
}
}),
$orderButton = Ox.Button({
overlap: 'left',
style: 'squared',
title: getButtonTitle(),
tooltip: getButtonTooltip(),
type: 'image'
})
.bindEvent({
click: function() {
oml.UI.set({
listSort: [{
key: ui.listSort[0].key,
operator: ui.listSort[0].operator == '+' ? '-' : '+'
}]
});
}
}),
that = Ox.FormElementGroup({
elements: [$sortSelect, $orderButton],
float: 'right'
})
.css({
float: 'left',
margin: '4px 2px'
})
.bindEvent({
oml_listsort: function() {
2014-05-17 11:45:57 +00:00
that.updateElement();
2014-05-04 17:26:43 +00:00
}
});
function getButtonTitle() {
return ui.listSort[0].operator == '+' ? 'up' : 'down';
}
function getButtonTooltip() {
return Ox._(ui.listSort[0].operator == '+' ? 'Ascending' : 'Descending');
}
2014-05-17 11:45:57 +00:00
that.updateElement = function() {
2014-05-04 17:26:43 +00:00
$sortSelect.value(ui.listSort[0].key);
$orderButton.options({
title: getButtonTitle(),
tooltip: getButtonTooltip()
});
return that;
};
2014-05-17 11:45:57 +00:00
return that.updateElement();
2014-05-04 17:26:43 +00:00
};