some query fixes

This commit is contained in:
rolux 2011-08-24 08:25:08 +00:00
parent 09e9b5af0a
commit 95ac3ee685
4 changed files with 75 additions and 88 deletions

View file

@ -89,7 +89,6 @@ pandora.Query = (function() {
function parseFind(str) {
// takes a find query string, returns useful information about the application's state
// (selected lists, find input key/value (and index of the corresponding condition), query object)
str = str || '';
var conditions,
index, indices,
ret = {
@ -98,6 +97,7 @@ pandora.Query = (function() {
query: {conditions: [], operator: ''}
},
subconditions = str.match(/\[.*?\]/g) || [];
if (str.length) {
// replace subconditions with placeholder,
// so we can later split by main operator
subconditions.forEach(function(subcondition, i) {
@ -147,6 +147,7 @@ pandora.Query = (function() {
index = oneCondition(ret.query.conditions, key, '');
return index > -1 ? index : null;
});
Ox.print('INDICES', indices, indices.length == 1 && !ret.query.conditions[indices[0]].conditions)
if (indices.length) {
ret.find = indices.length == 1 && !ret.query.conditions[indices[0]].conditions ? {
index: indices[0],
@ -154,6 +155,8 @@ pandora.Query = (function() {
value: ret.query.conditions[indices[0]].value
} : {index: -1, key: 'advanced', value: ''}
}
Ox.print('FIND', ret.find)
}
}
return ret;
}
@ -200,7 +203,7 @@ pandora.Query = (function() {
query = Ox.unserialize(str.substr(1)),
sort = []
if ('find' in query) {
data = parseFind(query.find);
data = parseFind(query.find || '');
Ox.print(Ox.repeat('-', 120));
Ox.print('STATE', data);
Ox.print(Ox.repeat('-', 120));

View file

@ -58,8 +58,8 @@ pandora.ui.browser = function() {
};
},
items: function(data, callback) {
pandora.api.find($.extend(data, {
query: pandora.Query.toObject()
pandora.api.find(Ox.extend(data, {
query: pandora.user.ui.query
}), callback);
},
keys: ['director', 'id', 'posterRatio', 'title', 'year'],

View file

@ -46,10 +46,12 @@ pandora.ui.findElement = function() {
var key = data.selected[0].id;
if (key == 'advanced') {
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
pandora.$ui.findInput.options({placeholder: 'Edit...'})
} else {
pandora.$ui.mainMenu.checkItem('findMenu_find_' + key);
pandora.$ui.findInput.options({
autocomplete: autocompleteFunction()
autocomplete: autocompleteFunction(),
placeholder: ''
}).focus();
}
}
@ -67,7 +69,7 @@ pandora.ui.findElement = function() {
})
.bindEvent({
focus: function(data) {
if (findKey == 'advanced') {
if (pandora.$ui.findSelect.value() == 'advanced') {
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
}
},

View file

@ -65,7 +65,8 @@ pandora.ui.group = function(id) {
} else {
if (index == -1) {
index = pandora.user.ui.query.conditions.length;
pandora.user.ui.query.operator = '&'
pandora.user.ui.query.operator = index ? '&' : '';
Ox.print('$$$$$$$$$$$$$$$$$$$', index, pandora.user.ui.query.operator)
}
if (conditions.length == 0) {
pandora.user.ui.query.conditions.splice(index, 1);
@ -82,7 +83,6 @@ pandora.ui.group = function(id) {
}
}
pandora.Query.updateGroups();
Ox.print('---------', pandora.user.ui.query, pandora.user.ui.groupsData)
pandora.URL.push(pandora.Query.toString());
pandora.reloadGroups(i);
}
@ -104,55 +104,37 @@ pandora.ui.group = function(id) {
i_ = pandora.user.ui.groups.indexOf(id_);
if (i_ == -1) {
// new group was not part of old group set
if (pandora.user.queryGroups[i].query.conditions.length) {
if (pandora.user.ui.groupsData[i].selected.length) {
// if group with selection gets replaced, reload
pandora.user.queryGroups[i].query.conditions = [];
pandora.user.ui.query.conditions.splice(pandora.user.ui.groupsData[i].index, 1);
pandora.Query.updateGroups();
pandora.URL.push(pandora.Query.toString());
pandora.reloadGroups(i);
}
pandora.user.queryGroups[i] = getGroupObject(id_);
pandora.user.ui.groups[i] = id_;
pandora.UI.set({groups: pandora.user.ui.groups});
replaceGroup(i, id_);
} else {
// swap two existing groups
var group = $.extend({}, pandora.user.queryGroups[i]);
pandora.user.queryGroups[i] = pandora.user.queryGroups[i_];
pandora.user.queryGroups[i_] = group;
var groupsData = Ox.clone(pandora.user.ui.groupsData[i]);
pandora.user.ui.groupsData[i] = pandora.user.ui.groupsData[i_];
pandora.user.ui.groupsData[i_] = groupsData;
pandora.user.ui.groups[i] = id_;
pandora.user.ui.groups[i_] = id;
pandora.UI.set({groups: pandora.user.ui.groups});
replaceGroup(i, id_, pandora.user.queryGroups[i].query);
replaceGroup(i_, id, pandora.user.queryGroups[i_].query);
replaceGroup(i, id_);
replaceGroup(i_, id);
}
function replaceGroup(i, id, query) {
// if query is passed, selected items will be derived from it
var isOuter = i % 4 == 0;
pandora.$ui[isOuter ? 'browser' : 'groupsInnerPanel'].replaceElement(
isOuter ? i / 2 : i - 1,
pandora.$ui.groups[i] = pandora.ui.group(id, query)
pandora.$ui.groups[i] = pandora.ui.group(id)
);
}
})
.appendTo(that.$bar.$element);
if (!query) {
// if query is set, group object has already been taken care of
pandora.user.queryGroups[i] = getGroupObject(id);
}
function getGroupObject(id) {
var i = pandora.user.ui.groups.indexOf(id),
title = Ox.getObjectById(pandora.site.groups, id).title,
width = pandora.getGroupWidth(i, panelWidth);
return {
id: id,
element: that,
query: {
conditions: [],
operator: '|'
},
size: width.list,
title: title
};
}
return that;
};