1
0
Fork 0
forked from 0x2620/oxjs

some autocomplete

This commit is contained in:
Rolux 2010-07-02 14:33:45 +02:00
commit 3b7b3d8e64
2 changed files with 155 additions and 115 deletions

View file

@ -6,24 +6,30 @@ $(function() {
// requestURL: "http://blackbook.local:8000/api/"
requestURL: "http://lion.oil21.org:8000/api/"
}),
findCondition = {},
groups = [
{
conditions: [],
id: "director",
title: "Director"
},
{
conditions: [],
id: "country",
title: "Country"
},
{
conditions: [],
id: "year",
title: "Year"
},
{
conditions: [],
id: "language",
title: "Language"
},
{
conditions: [],
id: "genre",
title: "Genre"
}
@ -59,16 +65,7 @@ $(function() {
delete options.keys;
app.request("find", $.extend(options, {
group: v.id,
query: {
conditions: [
{
key: "director",
value: "",
operator: ""
}
],
operator: ""
}
query: constructQuery()
}), options.callback);
},
sort: [
@ -190,16 +187,7 @@ $(function() {
id: "list",
request: function(options) {
app.request("find", $.extend(options, {
query: {
conditions: [
{
key: "director",
value: "",
operator: ""
}
],
operator: ""
}
query: constructQuery()
}), options.callback);
},
sort: [
@ -269,67 +257,59 @@ $(function() {
}).width(120).appendTo($toolBar);
$input = new Ox.Input({
autocomplete: {
"Find: All": [],
"Find: Title": [
"A bout de souffle",
"Casino",
"Diaries, Notes and Sketches",
"L'age d'or",
"Far From Heaven",
"In girum imus nocte et consumimur igni",
"It Felt Like a Kiss",
"Mulholland Dr.",
"Querelle",
"Vertigo"
],
"Find: Director": [
"Luis Buñuel",
"Adam Curtis",
"Guy Debord",
"Rainer Werner Fassbinder",
"Jean-Luc Godard",
"Todd Haynes",
"Alfred Hitchcock",
"David Lynch",
"Jonas Mekas",
"Martin Scorsese"
],
"Find: Country": [
"Austria",
"Canada",
"France",
"Germany",
"Italy",
"Japan",
"Spain",
"Switzerland",
"UK",
"USA"
],
"Find: Cinematographer": []
autocomplete: function(key, value, callback) {
Ox.print("autocomplete", key, value);
value === "" && Ox.print("Warning: autocomplete function should never be called with empty value");
if (key == "all") {
callback();
} else {
app.request("find", {
keys: [key],
query: {
conditions: [
{
key: key,
value: value,
operator: "~"
}
],
operator: ""
},
sort: [
{
key: key,
operator: "+"
}
],
range: [0, 10]
}, function(result) {
callback($.map(result.data.items, function(v) {
return v.title;
}))
});
}
},
clear: true,
highlight: false,
id: "find",
label: [
"Find: All",
"Find: Title",
"Find: Director",
"Find: Country",
"Find: Year",
"Find: Language",
"Find: Writer",
"Find: Producer",
"Find: Cinematographer",
"Find: Editor",
"Find: Actor",
"Find: Character",
"Find: Name",
"Find: Genre",
"Find: Keyword",
"Find: Summary",
"Find: Dialog",
{ id: "all", title: "Find: All" },
{ id: "title", title: "Find: Title" },
{ id: "director", title: "Find: Director" },
{ id: "country", title: "Find: Country" },
{ id: "year", title: "Find: Year" },
{ id: "language", title: "Find: Language" },
{ id: "writer", title: "Find: Writer" },
{ id: "producer", title: "Find: Producer" },
{ id: "cinematographer", title: "Find: Cinematographer" },
{ id: "editor", title: "Find: Editor" },
{ id: "actor", title: "Find: Actor" },
{ id: "character", title: "Find: Character" },
{ id: "name", title: "Find: Name" },
{ id: "genre", title: "Find: Genre" },
{ id: "keyword", title: "Find: Keyword" },
{ id: "summary", title: "Find: Summary" },
{ id: "dialog", title: "Find: Dialog" }
],
labelWidth: 85
}).css({
@ -414,6 +394,13 @@ $(function() {
] }
]
},
{
id: "debug",
title: "Debug",
items: [
{ id: "show_query", title: "Show Query" }
]
}
],
size: "medium"
}),
@ -457,17 +444,16 @@ $(function() {
Ox.Event.bind(null, "select_group_" + group.id, function(event, data) {
$list.options({
request: function(options) {
groups[i].conditions = $.map(data.ids, function(v) {
return {
key: group.id,
value: v,
operator: "="
};
});
Ox.print
return app.request("find", $.extend(options, {
query: {
conditions: $.map(data.ids, function(v, j) {
return {
key: group.id,
value: v,
operator: "="
}
}),
operator: "|"
}
query: constructQuery()
}), options.callback);
}
});
@ -478,16 +464,7 @@ $(function() {
delete options.keys;
return app.request("find", $.extend(options, {
group: group_.id,
query: {
conditions: $.map(data.ids, function(v, j) {
return {
key: group.id,
value: v,
operator: "="
}
}),
operator: "|"
}
query: constructQuery(group_.id)
}), options.callback);
}
})
@ -515,4 +492,51 @@ $(function() {
Ox.Event.bind(null, "sort_list", function(event, data) {
});
Ox.Event.bind(null, "click_show_query", function(event, data) {
var query = constructQuery(),
html = "Conditions<br/><br/>" + $.map(query.conditions, function(v) {
return v.key + " " + v.operator + " " + v.value;
}).join("<br/>") + "<br/><br/>Operator: " + query.operator,
$dialog = new Ox.Dialog({
title: "Show Query",
buttons: [
{
value: "Close",
click: function() {
$dialog.close();
}
}
]
})
.append(html)
.open();
});
function constructQuery(groupId) {
var conditions = $.merge(!Ox.isUndefined(findCondition.query) ? [findCondition] : [], $.map(groups, function(v, i) {
if (v.id != groupId) {
return v.conditions;
}
}));
/*
Ox.print("conditions", conditions, "groups conditions", $.map(groups, function(v) {
return v.conditions;
}));
*/
return {
conditions: conditions,
operator: conditions.length ? "," : ""
};
}
function getGroupById(id) { // unused
$.each(groups, function(i, v) {
if (v.id == id) {
return i;
}
});
return -1;
}
});