send correct requests when unchecking show users

This commit is contained in:
rolux 2011-11-12 11:02:54 +00:00
parent 2f115f2dfc
commit 77ba1ca955

View file

@ -13,7 +13,10 @@ pandora.ui.usersDialog = function() {
checked: true, checked: true,
title: 'Show Guests' title: 'Show Guests'
}) })
.css({float: 'left', margin: '4px'}), .css({float: 'left', margin: '4px'})
.bindEvent({
change: updateList
}),
$findSelect = Ox.Select({ $findSelect = Ox.Select({
items: [ items: [
@ -26,9 +29,7 @@ pandora.ui.usersDialog = function() {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
var key = data.selected[0].id, $findInput.value() && updateList();
value = $findInput.value();
value && updateList(key, value);
$findInput.options({ $findInput.options({
placeholder: data.selected[0].title placeholder: data.selected[0].title
}); });
@ -42,11 +43,7 @@ pandora.ui.usersDialog = function() {
width: 192 width: 192
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: updateList
var key = $findSelect.value(),
value = data.value;
updateList(key, value);
}
}), }),
$findElement = Ox.FormElementGroup({ $findElement = Ox.FormElementGroup({
@ -213,9 +210,14 @@ pandora.ui.usersDialog = function() {
$status.html( $status.html(
Ox.formatNumber(data.items) Ox.formatNumber(data.items)
+ ' user' + (data.items == 1 ? '' : 's') + ' user' + (data.items == 1 ? '' : 's')
+ ' (' + Ox.formatNumber(data.users) + ' registered, ' + (
+ Ox.formatNumber(data.guests) + ' guest' + (data.guests == 1 ? '' : 's') $guestsCheckbox.value()
? ' (' + Ox.formatNumber(data.users) + ' registered, '
+ Ox.formatNumber(data.guests) + ' guest'
+ (data.guests == 1 ? '' : 's')
+ ')' + ')'
: ''
)
); );
}, },
select: function(data) { select: function(data) {
@ -451,14 +453,20 @@ pandora.ui.usersDialog = function() {
}); });
} }
function updateList(key, value) { function updateList() {
var query = { var guests = $guestsCheckbox.value(),
conditions: Ox.merge( key = $findSelect.value(),
value = $findInput.value(),
query = {
conditions: value
? Ox.merge(
key != 'email' ? [{key: 'username', value: value, operator: '='}] : [], key != 'email' ? [{key: 'username', value: value, operator: '='}] : [],
key != 'username' ? [{key: 'email', value: value, operator: '='}] : [] key != 'username' ? [{key: 'email', value: value, operator: '='}] : []
), )
operator: key == 'all' ? '|' : '&' : !guests ? [{key: 'level', value: 'guest', operator: '!='}] : [],
operator: key == 'all' && value ? '|' : '&'
}; };
Ox.print('CONDITIONS', query.conditions)
$list.options({ $list.options({
items: function(data, callback) { items: function(data, callback) {
return pandora.api.findUsers(Ox.extend(data, { return pandora.api.findUsers(Ox.extend(data, {