From e692e54c901f2e96b5e1e70943e41847a5eca842 Mon Sep 17 00:00:00 2001 From: Rolux Date: Mon, 5 Jul 2010 18:52:12 +0200 Subject: [PATCH] temporary fix for parseKeyboard bug --- build/js/ox.js | 24 +++- build/js/ox.ui.js | 7 +- demos/test/list.js | 303 +++++++++++++++++++++++++-------------------- 3 files changed, 198 insertions(+), 136 deletions(-) diff --git a/build/js/ox.js b/build/js/ox.js index b3ae187..de4ba30 100644 --- a/build/js/ox.js +++ b/build/js/ox.js @@ -182,6 +182,28 @@ Ox.filter = function(arr, fn) { 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({"a": 1, "b": 2, "c": 3}) @@ -321,7 +343,7 @@ Ox.shuffle = function(arr) { 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; }) true >>> Ox.some({a: 1, b: 2, c: 3}, function(v) { return v == 1; }) diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 47bfec2..13b2d31 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -212,6 +212,10 @@ requires } return { bind: function(id, event, callback) { + if (arguments.length == 2) { + callback = event; + event = id; + } if (isKeyboardEvent(event)) { keyboardEvents[id] = keyboardEvents[id] || {}; keyboardEvents[id][event] = callback; @@ -2849,7 +2853,7 @@ requires self.$items[pos].appendTo(self.$pages[page]); }); 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); if (result.data.items.length < visibleItems) { self.$pages[page].height(height).css({ @@ -4267,6 +4271,7 @@ requires ); function parseKeyboard(str) { + if (Ox.isObject(str)) return str; // fixme: this should not happen var modifiers = str.split(" "), key = modifiers.pop(); return { diff --git a/demos/test/list.js b/demos/test/list.js index b586150..ce250ec 100644 --- a/demos/test/list.js +++ b/demos/test/list.js @@ -102,129 +102,7 @@ $(function() { orientation: "horizontal" }) - $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: "+" - } - ] - }), - - $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" - }), + $list = constructList("text"); $toolBar = Ox.Bar({ size: 24 @@ -365,9 +243,11 @@ $(function() { id: "statusBar" }), - $totals = new Ox.Element().attr({ - id: "totals" - }).appendTo($statusBar); + $totals = new Ox.Element() + .attr({ + id: "totals" + }) + .appendTo($statusBar), $leftPanel = new Ox.Container(), @@ -470,9 +350,7 @@ $(function() { }); Ox.Event.bind(null, "change_viewSelect", function(event, data) { - if (data.id == "icons") { - $list.replaceWith($iconList); - } + $list.replaceWith(constructList(data.id)); }); Ox.Event.bind(null, "submit_find", function(event, data) { @@ -537,22 +415,33 @@ $(function() { }); Ox.Event.bind(null, "load_list", function(event, data) { + $totals.html(constructStatus({ + "total": data, + "selected": {} + })); var html = [ - data.items + " movie" + (data.items != 1 ? "s" : ""), - Ox.formatDuration(data.runtime, "long"), + Ox.formatNumber(data.items) + " movie" + (data.items != 1 ? "s" : ""), Ox.formatDuration(data.runtime, "medium"), - Ox.formatDuration(data.runtime, 3, "short"), data.files + " file" + (data.files != 1 ? "s" : ""), Ox.formatDuration(data.duration, "short"), Ox.formatValue(data.size, "B"), Ox.formatValue(data.pixels, "px") ]; - $totals.html(html.join(", ")); + $totals.html("Total: " + constructStatus(data) + " — 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, "select_list", function(event, data) { + + }); Ox.Event.bind(null, "click_show_query", function(event, data) { var query = constructQuery(), html = "Conditions

" + $.map(query.conditions, function(v) { @@ -573,6 +462,136 @@ $(function() { .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) { var conditions = $.merge(!Ox.isUndefined(findCondition.key) ? [findCondition] : [], $.map(groups, function(v, i) { 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(" — "); + + } + function getGroupById(id) { // unused $.each(groups, function(i, v) { if (v.id == id) {