temporary fix for parseKeyboard bug

This commit is contained in:
Rolux 2010-07-05 18:52:12 +02:00
parent 9eb96ea54c
commit 4363c8dac1
3 changed files with 198 additions and 136 deletions

View file

@ -182,6 +182,28 @@ Ox.filter = function(arr, fn) {
return ret; return ret;
}; };
Ox.getObjectById = function(arr, id) {
var ret = null;
Ox.each(arr, function(i, v) {
if (v.id == id) {
ret = v;
return false;
}
});
return ret;
};
Ox.getPositionById = function(arr, id) {
var ret = -1;
Ox.each(arr, function(i, v) {
if (v.id == id) {
ret = i;
return false;
}
});
return ret;
};
Ox.keys = function(obj) { Ox.keys = function(obj) {
/* /*
>>> Ox.keys({"a": 1, "b": 2, "c": 3}) >>> Ox.keys({"a": 1, "b": 2, "c": 3})
@ -321,7 +343,7 @@ Ox.shuffle = function(arr) {
Ox.some = function(obj, fn) { Ox.some = function(obj, fn) {
/* /*
Ox.some() forks for arrays, objects and strings, unlike [].some() Ox.some() works for arrays, objects and strings, unlike [].some()
>>> Ox.some([2, 1, 0], function(i, v) { return i == v; }) >>> Ox.some([2, 1, 0], function(i, v) { return i == v; })
true true
>>> Ox.some({a: 1, b: 2, c: 3}, function(v) { return v == 1; }) >>> Ox.some({a: 1, b: 2, c: 3}, function(v) { return v == 1; })

View file

@ -212,6 +212,10 @@ requires
} }
return { return {
bind: function(id, event, callback) { bind: function(id, event, callback) {
if (arguments.length == 2) {
callback = event;
event = id;
}
if (isKeyboardEvent(event)) { if (isKeyboardEvent(event)) {
keyboardEvents[id] = keyboardEvents[id] || {}; keyboardEvents[id] = keyboardEvents[id] || {};
keyboardEvents[id][event] = callback; keyboardEvents[id][event] = callback;
@ -2849,7 +2853,7 @@ requires
self.$items[pos].appendTo(self.$pages[page]); self.$items[pos].appendTo(self.$pages[page]);
}); });
if (self.options.type == "text" && page == 0) { if (self.options.type == "text" && page == 0) {
var height = that.height(), var height = that.height() - (that.width() < that.$content.width() ? oxui.scrollbarSize : 0),
visibleItems = Math.ceil(height / self.options.itemHeight); visibleItems = Math.ceil(height / self.options.itemHeight);
if (result.data.items.length < visibleItems) { if (result.data.items.length < visibleItems) {
self.$pages[page].height(height).css({ self.$pages[page].height(height).css({
@ -4267,6 +4271,7 @@ requires
); );
function parseKeyboard(str) { function parseKeyboard(str) {
if (Ox.isObject(str)) return str; // fixme: this should not happen
var modifiers = str.split(" "), var modifiers = str.split(" "),
key = modifiers.pop(); key = modifiers.pop();
return { return {

View file

@ -102,129 +102,7 @@ $(function() {
orientation: "horizontal" orientation: "horizontal"
}) })
$list = new Ox.TextList({ $list = constructList("text");
columns: [
{
align: "left",
id: "id",
operator: "+",
title: "ID",
unique: true,
visible: true,
width: 80
},
{
align: "left",
id: "title",
operator: "+",
title: "Title",
visible: true,
width: 160
},
{
align: "left",
id: "director",
operator: "+",
title: "Director",
visible: true,
width: 160
},
{
align: "left",
id: "country",
operator: "+",
title: "Country",
visible: true,
width: 120
},
{
align: "right",
id: "year",
operator: "-",
title: "Year",
visible: true,
width: 60
},
{
align: "left",
id: "language",
operator: "+",
title: "Language",
visible: true,
width: 120
},
{
align: "right",
id: "runtime",
operator: "-",
title: "Runtime",
visible: true,
width: 80
},
{
align: "left",
id: "genre",
operator: "+",
title: "Genre",
visible: true,
width: 120
},
{
align: "right",
id: "rating",
operator: "-",
title: "Rating",
width: 80
},
{
align: "right",
id: "votes",
operator: "-",
title: "Votes",
width: 80
}
],
id: "list",
request: function(options) {
app.request("find", $.extend(options, {
query: constructQuery()
}), options.callback);
},
sort: [
{
key: "director",
operator: "+"
}
]
}),
$iconList = new Ox.IconList({
id: "list",
item: function(data, sort) {
return {
height: data["posterHeight"],
id: data["id"],
info: data[$.inArray(sort[0].key, ["title", "director"]) > -1 ? "year" : sort[0].key],
title: data["title"] + " (" + data["director"] + ")",
url: data["posterURL"],
width: data["posterWidth"]
};
},
keys: ["director", "id", "posterHeight", "posterWidth", "posterURL", "title"],
request: function(options) {
app.request("find", $.extend(options, {
query: constructQuery()
}), options.callback);
},
size: 128,
sort: [
{
key: "director",
operator: "+"
}
],
unique: "id"
}),
$toolBar = Ox.Bar({ $toolBar = Ox.Bar({
size: 24 size: 24
@ -365,9 +243,11 @@ $(function() {
id: "statusBar" id: "statusBar"
}), }),
$totals = new Ox.Element().attr({ $totals = new Ox.Element()
.attr({
id: "totals" id: "totals"
}).appendTo($statusBar); })
.appendTo($statusBar),
$leftPanel = new Ox.Container(), $leftPanel = new Ox.Container(),
@ -470,9 +350,7 @@ $(function() {
}); });
Ox.Event.bind(null, "change_viewSelect", function(event, data) { Ox.Event.bind(null, "change_viewSelect", function(event, data) {
if (data.id == "icons") { $list.replaceWith(constructList(data.id));
$list.replaceWith($iconList);
}
}); });
Ox.Event.bind(null, "submit_find", function(event, data) { Ox.Event.bind(null, "submit_find", function(event, data) {
@ -537,22 +415,33 @@ $(function() {
}); });
Ox.Event.bind(null, "load_list", function(event, data) { Ox.Event.bind(null, "load_list", function(event, data) {
$totals.html(constructStatus({
"total": data,
"selected": {}
}));
var html = [ var html = [
data.items + " movie" + (data.items != 1 ? "s" : ""), Ox.formatNumber(data.items) + " movie" + (data.items != 1 ? "s" : ""),
Ox.formatDuration(data.runtime, "long"),
Ox.formatDuration(data.runtime, "medium"), Ox.formatDuration(data.runtime, "medium"),
Ox.formatDuration(data.runtime, 3, "short"),
data.files + " file" + (data.files != 1 ? "s" : ""), data.files + " file" + (data.files != 1 ? "s" : ""),
Ox.formatDuration(data.duration, "short"), Ox.formatDuration(data.duration, "short"),
Ox.formatValue(data.size, "B"), Ox.formatValue(data.size, "B"),
Ox.formatValue(data.pixels, "px") Ox.formatValue(data.pixels, "px")
]; ];
$totals.html(html.join(", ")); $totals.html("Total: " + constructStatus(data) + " &mdash; Selected: " + constructStatus({
duration: 0,
files: 0,
items: 0,
pixels: 0,
runtime: 0,
size: 0
}));
}); });
Ox.Event.bind(null, "sort_list", function(event, data) { Ox.Event.bind(null, "sort_list", function(event, data) {
}); });
Ox.Event.bind(null, "select_list", function(event, data) {
});
Ox.Event.bind(null, "click_show_query", function(event, data) { Ox.Event.bind(null, "click_show_query", function(event, data) {
var query = constructQuery(), var query = constructQuery(),
html = "Conditions<br/><br/>" + $.map(query.conditions, function(v) { html = "Conditions<br/><br/>" + $.map(query.conditions, function(v) {
@ -573,6 +462,136 @@ $(function() {
.open(); .open();
}); });
function constructList(view) {
var $list;
if (view == "text") {
$list = new Ox.TextList({
columns: [
{
align: "left",
id: "id",
operator: "+",
title: "ID",
unique: true,
visible: true,
width: 80
},
{
align: "left",
id: "title",
operator: "+",
title: "Title",
visible: true,
width: 160
},
{
align: "left",
id: "director",
operator: "+",
title: "Director",
visible: true,
width: 160
},
{
align: "left",
id: "country",
operator: "+",
title: "Country",
visible: true,
width: 120
},
{
align: "right",
id: "year",
operator: "-",
title: "Year",
visible: true,
width: 60
},
{
align: "left",
id: "language",
operator: "+",
title: "Language",
visible: true,
width: 120
},
{
align: "right",
id: "runtime",
operator: "-",
title: "Runtime",
visible: true,
width: 80
},
{
align: "left",
id: "genre",
operator: "+",
title: "Genre",
visible: true,
width: 120
},
{
align: "right",
id: "rating",
operator: "-",
title: "Rating",
width: 80
},
{
align: "right",
id: "votes",
operator: "-",
title: "Votes",
width: 80
}
],
id: "list",
request: function(options) {
app.request("find", $.extend(options, {
query: constructQuery()
}), options.callback);
},
sort: [
{
key: "director",
operator: "+"
}
]
});
} else if (view == "icons") {
$list = new Ox.IconList({
id: "list",
item: function(data, sort, size) {
return {
height: data.posterHeight,
id: data["id"],
info: data[$.inArray(sort[0].key, ["title", "director"]) > -1 ? "year" : sort[0].key],
title: data.title + (data.director ? " (" + data.director + ")" : ""),
url: "http://0xdb.org/" + data.id + "/poster." + size + "." + "jpg",
width: data.posterWidth
};
},
keys: ["director", "id", "posterHeight", "posterWidth", "posterURL", "title"],
request: function(options) {
app.request("find", $.extend(options, {
query: constructQuery()
}), options.callback);
},
size: 128,
sort: [
{
key: "director",
operator: "+"
}
],
unique: "id"
});
}
return $list;
}
function constructQuery(groupId) { function constructQuery(groupId) {
var conditions = $.merge(!Ox.isUndefined(findCondition.key) ? [findCondition] : [], $.map(groups, function(v, i) { var conditions = $.merge(!Ox.isUndefined(findCondition.key) ? [findCondition] : [], $.map(groups, function(v, i) {
if (v.id != groupId) { if (v.id != groupId) {
@ -590,6 +609,22 @@ $(function() {
}; };
} }
function constructStatus(data) {
var html = [];
$.each(data, function(k, v) {
html.push(Ox.toTitleCase(k) + ": " + [
Ox.formatNumber(data.items) + " movie" + (data.items != 1 ? "s" : ""),
Ox.formatDuration(data.runtime, "medium"),
data.files + " file" + (data.files != 1 ? "s" : ""),
Ox.formatDuration(data.duration, "short"),
Ox.formatValue(data.size, "B"),
Ox.formatValue(data.pixels, "px")
].join(", "));
})
return html.join(" &mdash; ");
}
function getGroupById(id) { // unused function getGroupById(id) { // unused
$.each(groups, function(i, v) { $.each(groups, function(i, v) {
if (v.id == id) { if (v.id == id) {