From 3965eed1537c737cec710e8c624426451e263e32 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Wed, 28 Sep 2011 17:31:35 +0000 Subject: [PATCH] url controller updates, list bugfixes --- source/Ox.UI/js/Core/Ox.Element.js | 4 +- source/Ox.UI/js/Core/Ox.Event.js | 2 + source/Ox.UI/js/Core/Ox.URL.js | 82 ++++++++++++++++-------- source/Ox.UI/js/Form/Ox.Select.js | 2 +- source/Ox.UI/js/List/Ox.IconItem.js | 1 + source/Ox.UI/js/List/Ox.IconList.js | 6 +- source/Ox.UI/js/List/Ox.List.js | 16 +++-- source/Ox.UI/js/List/Ox.TextList.js | 18 +++--- source/Ox.UI/js/Panel/Ox.SplitPanel.js | 2 + source/Ox.UI/js/Video/Ox.VideoPreview.js | 1 + source/Ox.UI/js/Window/Ox.Dialog.js | 2 + source/Ox.js | 10 ++- 12 files changed, 98 insertions(+), 48 deletions(-) diff --git a/source/Ox.UI/js/Core/Ox.Element.js b/source/Ox.UI/js/Core/Ox.Element.js index efbb516b..a3d8d8f4 100644 --- a/source/Ox.UI/js/Core/Ox.Element.js +++ b/source/Ox.UI/js/Core/Ox.Element.js @@ -348,7 +348,9 @@ Ox.Element = function(options, self) { 'draganddropstart', 'draganddrop', 'draganddropenter', 'draganddropleave', 'draganddropend', 'playing', 'position', 'progress' ].indexOf(event) == -1) { - Ox.print(that.id, self.options.id, 'trigger', event, data); + if (!/^pandora_/.test(event)) { + Ox.print(that.id, self.options.id, 'trigger', event, data); + } } // it is necessary to check if self.$eventHandler exists, // since, for example, when removing the element on click, diff --git a/source/Ox.UI/js/Core/Ox.Event.js b/source/Ox.UI/js/Core/Ox.Event.js index c0cb268c..04a120e7 100644 --- a/source/Ox.UI/js/Core/Ox.Event.js +++ b/source/Ox.UI/js/Core/Ox.Event.js @@ -19,7 +19,9 @@ Ox.Event = (function() { @*/ that.bind = function() { Ox.forEach(Ox.makeObject(arguments), function(callback, event) { + var foo = event; self.$eventHandler.bind('ox_' + event, function(event, data) { + Ox.print('CALLBACK', foo, data.value); callback(data.value); }); }); diff --git a/source/Ox.UI/js/Core/Ox.URL.js b/source/Ox.UI/js/Core/Ox.URL.js index 37b8dad3..9f6a31b8 100644 --- a/source/Ox.UI/js/Core/Ox.URL.js +++ b/source/Ox.UI/js/Core/Ox.URL.js @@ -242,7 +242,7 @@ Ox.URL = function(options) { ].indexOf(state.view) > -1) { parts.push(state.view); } - if (state.span) { + if (state.span && state.span.length) { parts.push(constructSpan(state.span, state)); } if (state.sort && state.sort.length) { @@ -444,7 +444,7 @@ Ox.URL = function(options) { parseBeyondItem(); } else { // test for item id or name - self.options.getItem(parts[0], function(item) { + self.options.getItem(parts[0].replace(/%20/g, ' '), function(item) { state.item = item; if (item) { parts.shift(); @@ -585,10 +585,13 @@ Ox.URL = function(options) { + document.location.search + document.location.hash, callback = arguments[arguments.length - 1]; + /* parseURL(str, function(state) { that.replace(constructURL(state)); callback(state); }); + */ + parseURL(str, callback); return that; } @@ -602,34 +605,61 @@ Ox.URL = function(options) { /*@ push Pushes a new URL - (url, callback) -> URL controller - (state) -> URL controller - url New URL + (state, title, url, callback) -> URL controller + state State for the new URL + title Title for the new URL + url New URL, or state object to construct it from + This state object can be different from the first one + (for example: save full state, create URL from reduced state) callback callback function state New state - state State to construct the new URL from @*/ - that.push = function(url, callback) { - url = callback ? url : constructURL(url); - saveURL(); - Ox.print('PUSH', url); - history.pushState({}, '', url); - callback && parseURL(url, callback); - return that; - }; + that.push = function(state, title, url, callback) { + if (Ox.isString(url)) { + if (state) { + pushState(state, title, url); + } else { + parseURL(url, function(state) { + pushState(state, title, url); + }); + } + } else { + url = constructURL(url); + pushState(state, title, url); + } + function pushState(state, title, url) { + history.pushState(state, title, url); + callback && callback(state); + } + } - that.replace = function(url) { - saveURL(); - history.replaceState({}, '', url); - return that; - }; - - that.update = function(state) { - // pushes a new URL, constructed from state - // state can have type, item, view, span, sort, find - that.push(constructURL(state)); - return that; - }; + /*@ + replace Replaces the URL with a new URL + (state, title, url, callback) -> URL controller + state State for the new URL + title Title for the new URL + url New URL, or state object to construct it from + callback callback function + state New state + @*/ + that.replace = function(state, title, url, callback) { + if (Ox.isString(url)) { + if (state) { + replaceState(state, title, url); + } else { + parseURL(url, function(state) { + replaceState(state, title, url); + }); + } + } else { + url = constructURL(url); + replaceState(state, title, url); + } + function replaceState(state, title, url) { + history.replaceState(state, title, url); + callback && callback(state); + } + } return that; diff --git a/source/Ox.UI/js/Form/Ox.Select.js b/source/Ox.UI/js/Form/Ox.Select.js index 1a51ea66..f9b09fcd 100644 --- a/source/Ox.UI/js/Form/Ox.Select.js +++ b/source/Ox.UI/js/Form/Ox.Select.js @@ -195,7 +195,7 @@ Ox.Select = function(options, self) { id item id @*/ that.selectItem = function(id) { - //Ox.print('selectItem', id, Ox.getObjectById(self.options.items, id).title) + Ox.print('selectItem', id, self.options.items, self.options.items.length, Ox.getObjectById(self.options.items, id)) self.options.type == 'text' && self.$title.html( Ox.getObjectById(self.options.items, id).title ); diff --git a/source/Ox.UI/js/List/Ox.IconItem.js b/source/Ox.UI/js/List/Ox.IconItem.js index 496719d3..f7b56849 100644 --- a/source/Ox.UI/js/List/Ox.IconItem.js +++ b/source/Ox.UI/js/List/Ox.IconItem.js @@ -134,6 +134,7 @@ Ox.IconItem = function(options, self) { ); function formatText(text, maxLines, maxLength) { + text = Ox.isArray(text) ? text.join(', ') : text; var lines = Ox.wordwrap(text, maxLength, '
', true, false).split('
'); return Ox.map(lines, function(line, i) { if (i < maxLines - 1) { diff --git a/source/Ox.UI/js/List/Ox.IconList.js b/source/Ox.UI/js/List/Ox.IconList.js index 76c141eb..1b701cbc 100644 --- a/source/Ox.UI/js/List/Ox.IconList.js +++ b/source/Ox.UI/js/List/Ox.IconList.js @@ -113,9 +113,8 @@ Ox.IconList = function(options, self) { } function updateKeys() { - self.options.keys = Ox.unique(Ox.merge(self.options.keys, [self.options.sort[0].key])); that.$element.options({ - keys: self.options.keys + keys: Ox.unique(Ox.merge(self.options.sort[0].key, self.options.keys)) }); } @@ -129,7 +128,9 @@ Ox.IconList = function(options, self) { } else if (key == 'selected') { that.$element.options(key, value); } else if (key == 'sort') { + updateKeys(); that.$element.options(key, value); + //that.$element.sortList(key, operator); } }; @@ -177,6 +178,7 @@ Ox.IconList = function(options, self) { that.$element.size(); }; + // fixme: deprecate, use options() /*@ sortList sort list (key, operator) -> the list diff --git a/source/Ox.UI/js/List/Ox.List.js b/source/Ox.UI/js/List/Ox.List.js index d4824a3a..70e0731b 100644 --- a/source/Ox.UI/js/List/Ox.List.js +++ b/source/Ox.UI/js/List/Ox.List.js @@ -37,7 +37,7 @@ Ox.List List Element draganddropstart Fires when drag starts copy copy paste paste - movie move item + move move item load list loaded openpreview preview of selected item opened closepreview preview closed @@ -291,7 +291,7 @@ Ox.List = function(options, self) { Ox.Request.cancel(v); }); Ox.extend(self, { - //$items: [], + $items: [], $pages: [], page: 0, requests: [] @@ -677,6 +677,7 @@ Ox.List = function(options, self) { function loadItems() { that.$content.empty(); + self.$items = []; self.options.items.forEach(function(item, pos) { // fixme: duplicated self.$items[pos] = Ox.ListItem({ @@ -1649,17 +1650,20 @@ Ox.List = function(options, self) { value value, can be whatever that property is @*/ that.value = function(id, key, value) { - //Ox.print('that.value', id, getPositionById(id)) var pos = getPositionById(id), $item = self.$items[pos], - data = $item.options('data'), - oldValue; + data = $item.options('data'); if (arguments.length == 1) { return data; } else if (arguments.length == 2) { return data[key]; } else { - oldValue = data[key]; + if (key == self.options.unique) { + // unique id has changed + self.options.selected = self.options.selected.map(function(id_) { + return id_ == data[key] ? value : id_ + }); + } data[key] = value; $item.options({data: data}); return that; diff --git a/source/Ox.UI/js/List/Ox.TextList.js b/source/Ox.UI/js/List/Ox.TextList.js index c6572e4f..b775edbe 100644 --- a/source/Ox.UI/js/List/Ox.TextList.js +++ b/source/Ox.UI/js/List/Ox.TextList.js @@ -196,7 +196,7 @@ Ox.TextList = function(options, self) { sortable: self.options.sortable, type: 'text', unique: self.unique - }, Ox.extend({}, self)) // pass event handler + }, Ox.clone(self)) // pass event handler .addClass('OxBody') .css({ top: (self.options.columnsVisible ? 16 : 0) + 'px', @@ -222,7 +222,6 @@ Ox.TextList = function(options, self) { //that.triggerEvent('init', data); }, select: function() { - Ox.print('SELECT????') self.options.selected = that.$body.options('selected'); } }) @@ -929,18 +928,19 @@ Ox.TextList = function(options, self) { return that.$body.value(id, key); } else { that.$body.value(id, key, value); - //Ox.print('? ? ?', column, column.format) + if (key == self.unique) { + // unique id has changed + self.options.selected = self.options.selected.map(function(id_) { + return id_ == id ? value : id_ + }); + id = value; + } $cell = getCell(id, key); $cell && $cell.html(formatValue(key, value)); if (key == self.options.sort[0].key) { + // sort key has changed that.$body.sort(); } - /* fixme: something like this is needed: - if (column.unique) { - that.$body.setId($item.data('id'), value); - $item.data({id: value}); - } - */ return that; } } diff --git a/source/Ox.UI/js/Panel/Ox.SplitPanel.js b/source/Ox.UI/js/Panel/Ox.SplitPanel.js index 42140413..66632ab5 100644 --- a/source/Ox.UI/js/Panel/Ox.SplitPanel.js +++ b/source/Ox.UI/js/Panel/Ox.SplitPanel.js @@ -196,6 +196,8 @@ Ox.SplitPanel = function(options, self) { that.$elements[pos] = element .css(self.edges[2], (parseInt(element.css(self.edges[2])) || 0) + 'px') .css(self.edges[3], (parseInt(element.css(self.edges[3])) || 0) + 'px'); + // fixme: it would be better to call removeElement here, + // or have a custom replaceElement function that removes event handlers self.options.elements[pos].element.replaceWith(element.$element.$element || element.$element); self.options.elements[pos].element = element; setSizes(); diff --git a/source/Ox.UI/js/Video/Ox.VideoPreview.js b/source/Ox.UI/js/Video/Ox.VideoPreview.js index 526b2c56..aa4c46bf 100644 --- a/source/Ox.UI/js/Video/Ox.VideoPreview.js +++ b/source/Ox.UI/js/Video/Ox.VideoPreview.js @@ -65,6 +65,7 @@ Ox.VideoPreview = function(options, self) { function getFrameCSS() { var css = {}; + // fixme: these are still wrong if (!self.options.scaleToFill) { css.width = self.options.width; css.height = Math.round(css.width / self.options.frameRatio); diff --git a/source/Ox.UI/js/Window/Ox.Dialog.js b/source/Ox.UI/js/Window/Ox.Dialog.js index 9cb7467b..78c9164c 100644 --- a/source/Ox.UI/js/Window/Ox.Dialog.js +++ b/source/Ox.UI/js/Window/Ox.Dialog.js @@ -261,6 +261,7 @@ Ox.Dialog = function(options, self) { function getButtonById(id) { var ret = null; Ox.forEach(self.options.buttons, function(button) { + Ox.print(button.options(), button.options('id')) if (button.options && button.options('id') == id) { ret = button; return false; @@ -271,6 +272,7 @@ Ox.Dialog = function(options, self) { function keypress(key) { var id = self.options.keys[key]; + Ox.print(id, getButtonById(id)); id && getButtonById(id).$element.trigger('click'); } diff --git a/source/Ox.js b/source/Ox.js index 899971bb..474930a9 100644 --- a/source/Ox.js +++ b/source/Ox.js @@ -431,6 +431,8 @@ Ox.clone Returns a (shallow or deep) copy of an object or array 'val' > (function() { a = {key: 'val'}; b = Ox.clone(a); a.key = null; return b.key; }()) 'val' + > Ox.clone(0) + 0 @*/ Ox.clone = function(col, deep) { @@ -442,7 +444,9 @@ Ox.clone = function(col, deep) { ? Ox.clone(val, true) : val; }); } else { - ret = Ox.isArray(col) ? col.slice() : Ox.extend({}, col); + ret = Ox.isArray(col) ? col.slice() + : Ox.isObject(col) ? Ox.extend({}, col) + : col; } return ret; }; @@ -670,10 +674,10 @@ Ox.getset = function(obj, args, callback, context) { var obj_ = Ox.clone(obj), ret; if (args.length == 0) { // getset([]) - ret = obj; + ret = obj_; } else if (args.length == 1 && !Ox.isObject(args[0])) { // getset([key]) - ret = obj[args[0]]; + ret = Ox.clone(obj[args[0]]); } else { // getset([key, val]) or getset([{key: val, ...}]) args = Ox.makeObject(args);