cleaner submit routine for find

This commit is contained in:
rolux 2011-01-16 01:06:37 +00:00
parent d39d66c112
commit 663eac45cf
3 changed files with 32 additions and 49 deletions

View file

@ -148,6 +148,7 @@
"preferences": {}, "preferences": {},
"ui": { "ui": {
"annotationsSize": 256, "annotationsSize": 256,
"findKey": "",
"findQuery": {"conditions": [], "operator": ""}, "findQuery": {"conditions": [], "operator": ""},
"groups": ["director", "country", "year", "language", "genre"], "groups": ["director", "country", "year", "language", "genre"],
"groupsQuery": {"conditions": [], "operator": "|"}, "groupsQuery": {"conditions": [], "operator": "|"},

View file

@ -61,9 +61,11 @@ class UserProfile(models.Model):
pos.position = qs.aggregate(Max('position'))['position__max'] + 1 pos.position = qs.aggregate(Max('position'))['position__max'] + 1
pos.save() pos.save()
id = l.get_id() id = l.get_id()
'''
if id not in ui['lists']: if id not in ui['lists']:
ui['lists'][id] = {} ui['lists'][id] = {}
ui['lists'][id].update(ui['lists']['']) ui['lists'][id].update(ui['lists'][''])
'''
ids.append(id) ids.append(id)
return ids return ids

View file

@ -34,7 +34,6 @@ var pandora = new Ox.App({
if (app.user.group == 'guest') { if (app.user.group == 'guest') {
app.user = $.extend({}, app.config.user); app.user = $.extend({}, app.config.user);
$.browser.safari && Ox.theme('modern');
} }
function load() { function load() {
@ -650,6 +649,12 @@ var pandora = new Ox.App({
return that; return that;
}, },
findElement: function() { findElement: function() {
var findKey = '',
findValue = '';
if (app.user.ui.findQuery.conditions.length == 1) {
findKey = app.user.ui.findQuery.conditions[0].key;
findValue = app.user.ui.findQuery.conditions[0].value;
}
var that = new Ox.FormElementGroup({ var that = new Ox.FormElementGroup({
elements: $.merge(app.user.ui.list ? [ elements: $.merge(app.user.ui.list ? [
app.$ui.findListSelect = new Ox.Select({ app.$ui.findListSelect = new Ox.Select({
@ -674,6 +679,7 @@ var pandora = new Ox.App({
items: $.map(app.config.findKeys, function(key, i) { items: $.map(app.config.findKeys, function(key, i) {
return { return {
id: key.id, id: key.id,
checked: key.id == findKey,
title: 'Find: ' + key.title title: 'Find: ' + key.title
}; };
}), }),
@ -683,7 +689,7 @@ var pandora = new Ox.App({
.bindEvent({ .bindEvent({
change: function(event, data) { change: function(event, data) {
var key = data.selected[0].id; var key = data.selected[0].id;
if (!app.user.ui.findQuery.conditions.length) { if (!app.user.ui.findQuery.conditions.length) { // fixme: can this case happen at all?
app.user.ui.findQuery.conditions = [{key: key, value: '', operator: ''}]; app.user.ui.findQuery.conditions = [{key: key, value: '', operator: ''}];
} else { } else {
app.user.ui.findQuery.conditions[0].key = key; app.user.ui.findQuery.conditions[0].key = key;
@ -702,47 +708,26 @@ var pandora = new Ox.App({
autocompleteSelectSubmit: true, autocompleteSelectSubmit: true,
clear: true, clear: true,
id: 'input', id: 'input',
value: findValue,
width: 192 width: 192
}) })
.bindEvent({ .bindEvent({
submit: function(event, data) { submit: function(event, data) {
var key = app.user.ui.findQuery.conditions.length ? var key = app.user.ui.findQuery.conditions.length ?
app.user.ui.findQuery.conditions[0].key : '', app.user.ui.findQuery.conditions[0].key : '';
query; if (app.user.ui.list && that.value()[0].id == 'all') {
if (that.value()[0].id == 'all') { // fixme: ambiguous?
app.$ui.sectionList.forEach(function($list) { app.$ui.sectionList.forEach(function($list) {
$list.options({selected: []}); $list.options({selected: []});
}); // fixme: doesn't cover complex lists });
app.user.ui.list = ''; UI.set({list: ''});
app.user.ui.listQuery = {conditions: [], operator: ''}; app.user.ui.listQuery = {conditions: [], operator: ''};
} }
app.user.ui.findQuery.conditions = [ app.user.ui.findQuery.conditions = [{
{ key: key == 'all' ? '' : key,
key: key == 'all' ? '' : key, value: data.value,
value: data.value, operator: ''
operator: '' }];
} URL.set(Query.toString());
];
$.each(app.ui.groups, function(i, group) {
group.query.conditions = [];
app.$ui.groups[i].options({
request: function(data, callback) {
delete data.keys;
return pandora.api.find($.extend(data, {
group: group.id,
query: Query.toObject(group.id)
}), callback);
}
});
});
app.$ui.list.options({
request: function(data, callback) {
return pandora.api.find($.extend(data, {
query: query = Query.toObject()
}), callback);
}
});
history.pushState({}, '', '/' + Query.toString(query));
} }
}) })
]), ]),
@ -754,17 +739,15 @@ var pandora = new Ox.App({
}); });
function autocompleteFunction() { function autocompleteFunction() {
return app.user.ui.findQuery.conditions.length ? function(value, callback) { return app.user.ui.findQuery.conditions.length ? function(value, callback) {
var key = that.value()[app.user.ui.list ? 1 : 0].id, var elementValue = that.value(),
key = elementValue[app.user.ui.list ? 1 : 0].id,
findKey = Ox.getObjectById(app.config.findKeys, key); findKey = Ox.getObjectById(app.config.findKeys, key);
Ox.print('!!!!', key, findKey, 'autocomplete' in findKey && findKey.autocomplete) Ox.print('!!!!', key, findKey, 'autocomplete' in findKey && findKey.autocomplete)
value === '' && Ox.print('Warning: autocomplete function should never be called with empty value'); value === '' && Ox.print('Warning: autocomplete function should never be called with empty value');
if ('autocomplete' in findKey && findKey.autocomplete) { if ('autocomplete' in findKey && findKey.autocomplete) {
pandora.api.autocomplete({ pandora.api.autocomplete({
key: key, key: key,
query: that.value()[0].id == 'list' ? { query: elementValue[0].id == 'list' ? app.user.ui.listQuery : {conditions: [], operator: ''},
conditions: $.merge($.merge([], app.user.ui.listQuery.conditions), app.user.ui.findQuery.conditions),
operator: '&'
} : app.user.ui.findQuery,
range: [0, 20], range: [0, 20],
sort: [{ sort: [{
key: 'votes', key: 'votes',
@ -2443,7 +2426,7 @@ var pandora = new Ox.App({
}, },
{ {
format: function(value) { format: function(value) {
return value.split('.').join(': '); return value.split('/').join(': ');
}, },
id: 'id', id: 'id',
operator: '+', operator: '+',
@ -2649,10 +2632,10 @@ var pandora = new Ox.App({
app.$ui.sectionList.forEach(function($list, i_) { app.$ui.sectionList.forEach(function($list, i_) {
i != i_ && $list.options('selected', []); i != i_ && $list.options('selected', []);
}); });
UI.set({list: listId}); //UI.set({list: listId});
URL.set('?find=list:' + listId); URL.set('?find=list:' + listId);
} else { } else {
UI.set({list: ''}); //UI.set({list: ''});
URL.set(''); URL.set('');
} }
}, },
@ -3279,15 +3262,13 @@ var pandora = new Ox.App({
if ('find' in query) { if ('find' in query) {
app.user.ui.listQuery = {conditions: [], operator: ''}; // fixme: hackish app.user.ui.listQuery = {conditions: [], operator: ''}; // fixme: hackish
app.user.ui.findQuery = parseFind(query.find); app.user.ui.findQuery = parseFind(query.find);
if (app.user.ui.listsQuery) { if (app.user.ui.listQuery.conditions.length) {
list = app.user.ui.listsQuery.conditions[0].value; list = app.user.ui.listQuery.conditions[0].value;
UI.set({
list: list
});
!app.user.ui.lists[list] && UI.set( !app.user.ui.lists[list] && UI.set(
'lists.' + list, app.config.user.ui.list ['lists', list].join('|'), app.config.user.ui.lists['']
); );
} }
UI.set({list: list});
//Ox.print('user.ui.findQuery', app.user.ui.findQuery) //Ox.print('user.ui.findQuery', app.user.ui.findQuery)
} }
if ('sort' in query) { if ('sort' in query) {
@ -3398,7 +3379,6 @@ var pandora = new Ox.App({
Query.fromString('?find='); // fixme: silly hack Query.fromString('?find='); // fixme: silly hack
UI.set({ UI.set({
section: 'items', section: 'items',
list: '',
item: '' item: ''
}); });
}, },