From 5001a47cf8611fad0f7dffb64f365be7efdb0a62 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 1 Dec 2013 14:55:10 +0100 Subject: [PATCH] Ox.TableList: make value method accept (id, {key: value}) --- source/Ox.UI/js/List/TableList.js | 48 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/source/Ox.UI/js/List/TableList.js b/source/Ox.UI/js/List/TableList.js index 38f0895d..7d19f816 100644 --- a/source/Ox.UI/js/List/TableList.js +++ b/source/Ox.UI/js/List/TableList.js @@ -1215,31 +1215,37 @@ Ox.TableList = function(options, self) { (id) -> get values of row id (id, key) -> get value of cell id, key (id, key, value) -> set id, key to value + (id, {key: value, ...}) -> set id, keys to values @*/ - that.value = function(id, key, value) { - // fixme: make this accept id, {k: v, ...} - var $cell; + that.value = function() { + var $cell, + args = Ox.slice(arguments), + id = args.shift(), + sort = false; if (arguments.length == 1) { return that.$body.value(id); - } else if (arguments.length == 2) { - return that.$body.value(id, key); + } else if (arguments.length == 2 && Ox.isString(arguments[1])) { + return that.$body.value(id, arguments[1]); } else { - that.$body.value(id, key, value); - if (key == self.options.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); - if ($cell && !$cell.is('.OxEdit')) { - $cell.html(formatValue(key, value, that.$body.value(id))); - } - if (!self.options.sortable && key == self.options.sort[0].key) { - // sort key has changed - that.$body.sort(); - } + Ox.forEach(Ox.makeObject(args), function(value, key) { + that.$body.value(id, key, value); + if (key == self.options.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); + if ($cell && !$cell.is('.OxEdit')) { + $cell.html(formatValue(key, value, that.$body.value(id))); + } + if (!self.options.sortable && key == self.options.sort[0].key) { + // sort key has changed + sort = true; + } + }); + sort && that.$body.sort(); return that; } };