fix an error on login, logout, or load with empty find string

This commit is contained in:
rolux 2011-08-24 16:42:55 +00:00
parent ba209d082e
commit 2ae3edb488
3 changed files with 19 additions and 4 deletions

View file

@ -93,7 +93,7 @@ pandora.Query = (function() {
index, indices, index, indices,
ret = { ret = {
find: {index: -1, key: '', value: ''}, find: {index: -1, key: '', value: ''},
groups: [], groups: [], // {index, query, selected}
list: '', list: '',
query: {conditions: [], operator: ''} query: {conditions: [], operator: ''}
}, },
@ -131,7 +131,6 @@ pandora.Query = (function() {
ret.list = ret.query.conditions[index].value; ret.list = ret.query.conditions[index].value;
} }
} }
ret.groups = getGroupsData(ret.query);
// find is populated if exactly one condition in an & query // find is populated if exactly one condition in an & query
// has a findKey as key and "" as operator // has a findKey as key and "" as operator
// (and all other conditions are either list or groups) // (and all other conditions are either list or groups)
@ -145,11 +144,13 @@ pandora.Query = (function() {
} }
}); });
} else { } else {
// number of conditions that are not list or groups
conditions = ret.query.conditions.length conditions = ret.query.conditions.length
- (ret.list != '') - (ret.list != '')
- ret.groups.filter(function(group) { - ret.groups.filter(function(group) {
return group.index > -1; return group.index > -1;
}).length; }).length;
// indices of non-advanced find queries
indices = Ox.map(pandora.site.findKeys, function(findKey) { indices = Ox.map(pandora.site.findKeys, function(findKey) {
var key = findKey.id == 'all' ? '' : findKey.id, var key = findKey.id == 'all' ? '' : findKey.id,
index = oneCondition(ret.query.conditions, key, ''); index = oneCondition(ret.query.conditions, key, '');
@ -167,6 +168,7 @@ pandora.Query = (function() {
} }
} }
} }
ret.groups = getGroupsData(ret.query);
return ret; return ret;
} }
@ -222,6 +224,7 @@ pandora.Query = (function() {
pandora.UI.set({list: data.list}); pandora.UI.set({list: data.list});
pandora.user.ui.find = data.find; pandora.user.ui.find = data.find;
pandora.user.ui.groupsData = data.groups; pandora.user.ui.groupsData = data.groups;
Ox.print("PUUGD", pandora.user.ui.groupsData);
pandora.user.ui.query = data.query; pandora.user.ui.query = data.query;
} }
if ('sort' in query) { if ('sort' in query) {

View file

@ -104,12 +104,14 @@ pandora.getVideoPartsAndPoints = function(durations, points) {
pandora.login = function(data) { pandora.login = function(data) {
pandora.user = data.user; pandora.user = data.user;
pandora.Query.updateGroups();
Ox.Theme(pandora.user.ui.theme); Ox.Theme(pandora.user.ui.theme);
pandora.$ui.appPanel.reload(); pandora.$ui.appPanel.reload();
}; };
pandora.logout = function(data) { pandora.logout = function(data) {
pandora.user = data.user; pandora.user = data.user;
pandora.Query.updateGroups();
Ox.Theme(pandora.site.user.ui.theme); Ox.Theme(pandora.site.user.ui.theme);
pandora.$ui.appPanel.reload(); pandora.$ui.appPanel.reload();
}; };

View file

@ -58,15 +58,25 @@ pandora.ui.group = function(id) {
}), }),
index = pandora.user.ui.groupsData[i].index; index = pandora.user.ui.groupsData[i].index;
if (Ox.isArray(index)) { if (Ox.isArray(index)) {
// this group had multiple selections and the | query
// was on the top level, i.e. not bracketed
pandora.user.ui.query = { pandora.user.ui.query = {
conditions: conditions, conditions: conditions,
operator: conditions.length > 1 ? '|' : '' operator: conditions.length > 1 ? '|' : ''
} }
} else { } else {
if (index == -1) { if (index == -1) {
// this group had no selection, i.e. no query
index = pandora.user.ui.query.conditions.length; index = pandora.user.ui.query.conditions.length;
if (pandora.user.ui.query.operator == '|') {
pandora.user.ui.query = {
conditions: [pandora.user.ui.query],
operator: '&'
};
index = 1;
} else {
pandora.user.ui.query.operator = index ? '&' : ''; pandora.user.ui.query.operator = index ? '&' : '';
Ox.print('$$$$$$$$$$$$$$$$$$$', index, pandora.user.ui.query.operator) }
} }
if (conditions.length == 0) { if (conditions.length == 0) {
pandora.user.ui.query.conditions.splice(index, 1); pandora.user.ui.query.conditions.splice(index, 1);