From 9d189c55dae28a4510e6d1afc58a421029a59ac9 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 1 Dec 2013 14:55:37 +0100 Subject: [PATCH] Ox.IconList: make value method accept (id, {key: value}) --- source/Ox.UI/js/List/IconList.js | 37 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/source/Ox.UI/js/List/IconList.js b/source/Ox.UI/js/List/IconList.js index e0080fdc..9b1a25fe 100644 --- a/source/Ox.UI/js/List/IconList.js +++ b/source/Ox.UI/js/List/IconList.js @@ -251,25 +251,32 @@ Ox.IconList = function(options, self) { (id) -> get all data for item (id, key) -> get value of key of item with id (id, key, value) -> set value, returns IconList + (id, {key: value, ...}) -> set values, returns IconList @*/ - that.value = function(id, key, value) { - // fixme: make this accept id, {k: v, ...} + that.value = function() { + var args = Ox.slice(arguments), + id = args.shift(), + sort = false; if (arguments.length == 1) { return that.$element.value(id); - } else if (arguments.length == 2) { - return that.$element.value(id, key); + } else if (arguments.length == 2 && Ox.isString(arguments[1])) { + return that.$element.value(id, arguments[1]); } else { - that.$element.value(id, key, value); - if (key == self.unique) { - // unique id has changed - self.options.selected = self.options.selected.map(function(id_) { - return id_ == id ? value : id_ - }); - } - if (key == self.options.sort[0].key) { - // sort key has changed - that.$element.sort(); - } + Ox.forEach(Ox.makeObject(args), function(value, key) { + that.$element.value(id, key, value); + if (key == self.unique) { + // unique id has changed + self.options.selected = self.options.selected.map(function(id_) { + return id_ == id ? value : id_ + }); + id = value; + } + if (key == self.options.sort[0].key) { + // sort key has changed + sort = true; + } + }); + sort && that.$element.sort(); return that; } };