Ox.TableList: make value method accept (id, {key: value})

This commit is contained in:
rolux 2013-12-01 14:55:10 +01:00
parent a5baff8319
commit 5001a47cf8

View file

@ -1215,15 +1215,19 @@ Ox.TableList = function(options, self) {
(id) -> get values of row id (id) -> get values of row id
(id, key) -> get value of cell id, key (id, key) -> get value of cell id, key
(id, key, value) -> set id, key to value (id, key, value) -> set id, key to value
(id, {key: value, ...}) -> set id, keys to values
@*/ @*/
that.value = function(id, key, value) { that.value = function() {
// fixme: make this accept id, {k: v, ...} var $cell,
var $cell; args = Ox.slice(arguments),
id = args.shift(),
sort = false;
if (arguments.length == 1) { if (arguments.length == 1) {
return that.$body.value(id); return that.$body.value(id);
} else if (arguments.length == 2) { } else if (arguments.length == 2 && Ox.isString(arguments[1])) {
return that.$body.value(id, key); return that.$body.value(id, arguments[1]);
} else { } else {
Ox.forEach(Ox.makeObject(args), function(value, key) {
that.$body.value(id, key, value); that.$body.value(id, key, value);
if (key == self.options.unique) { if (key == self.options.unique) {
// unique id has changed // unique id has changed
@ -1238,8 +1242,10 @@ Ox.TableList = function(options, self) {
} }
if (!self.options.sortable && key == self.options.sort[0].key) { if (!self.options.sortable && key == self.options.sort[0].key) {
// sort key has changed // sort key has changed
that.$body.sort(); sort = true;
} }
});
sort && that.$body.sort();
return that; return that;
} }
}; };