TableList: add 'unique' option (until now, the unique id had be specified via columns, even if one had no intention to ever display it as a column)

This commit is contained in:
rolux 2012-06-27 18:19:24 +02:00
parent 27ea70784c
commit 773311d8d7

View file

@ -6,7 +6,6 @@ Ox.TableList <f> TableList Widget
options <o> Options object options <o> Options object
columns <[o]|[]> Columns columns <[o]|[]> Columns
# Fixme: There's probably more... # Fixme: There's probably more...
addable <b> ...
editable <b> ... editable <b> ...
format <f> ... format <f> ...
id <s> ... id <s> ...
@ -16,7 +15,7 @@ Ox.TableList <f> TableList Widget
title <s> ... title <s> ...
titleImage <s> ... titleImage <s> ...
unformat <f> Applied before editing unformat <f> Applied before editing
unique <b> If true, this column acts as unique id unique <b> If true, this column acts as unique id (deprecated)
visible <b> ... visible <b> ...
width <n> ... width <n> ...
columnsMovable <b|false> If true, columns can be re-ordered columnsMovable <b|false> If true, columns can be re-ordered
@ -37,6 +36,9 @@ Ox.TableList <f> TableList Widget
sort <[o]|[s]|[]> ['+foo', ...] or [{key: 'foo', operator: '+'}, ...] sort <[o]|[s]|[]> ['+foo', ...] or [{key: 'foo', operator: '+'}, ...]
sortable <b|false> If true, elements can be re-ordered sortable <b|false> If true, elements can be re-ordered
sums <[s]|[]> Sums to be included in totals sums <[s]|[]> Sums to be included in totals
unique <s|''> Key of the unique id
This has precedence over a unique id specified via columns (which is
deprecated).
columnresize <!> columnresize columnresize <!> columnresize
columnchange <!> columnchange columnchange <!> columnchange
self <o> shared private variable self <o> shared private variable
@ -69,7 +71,8 @@ Ox.TableList = function(options, self) {
selected: [], selected: [],
sort: [], sort: [],
sortable: false, sortable: false,
sums: [] sums: [],
unique: ''
}) })
.options(options || {}) .options(options || {})
.update({ .update({
@ -129,15 +132,15 @@ Ox.TableList = function(options, self) {
if (Ox.isUndefined(column.visible)) { if (Ox.isUndefined(column.visible)) {
column.visible = false; column.visible = false;
} }
if (column.unique) { if (column.unique && !self.options.unique) {
self.unique = column.id; self.options.unique = column.id;
} }
}); });
if (Ox.isEmpty(self.options.sort)) { if (Ox.isEmpty(self.options.sort)) {
self.options.sort = [{ self.options.sort = [{
key: self.unique, key: self.options.unique,
operator: Ox.getObjectById(self.options.columns, self.unique).operator operator: Ox.getObjectById(self.options.columns, self.options.unique).operator
}]; }];
} }
@ -225,9 +228,13 @@ Ox.TableList = function(options, self) {
items: self.options.items, items: self.options.items,
itemWidth: getItemWidth(), itemWidth: getItemWidth(),
format: self.format, // fixme: not needed, happens in TableList format: self.format, // fixme: not needed, happens in TableList
keys: self.visibleColumns.map(function(column) { keys: Ox.unique(
return column.id; self.visibleColumns.map(function(column) {
}).concat(self.options.keys), return column.id;
})
.concat(self.options.unique)
.concat(self.options.keys)
),
max: self.options.max, max: self.options.max,
min: self.options.min, min: self.options.min,
orientation: 'vertical', orientation: 'vertical',
@ -239,7 +246,7 @@ Ox.TableList = function(options, self) {
sortable: self.options.sortable, sortable: self.options.sortable,
sums: self.options.sums, sums: self.options.sums,
type: 'text', type: 'text',
unique: self.unique unique: self.options.unique
}, Ox.extend(Ox.clone(self), {updateCallbacks: []})) // pass event handler }, Ox.extend(Ox.clone(self), {updateCallbacks: []})) // pass event handler
.addClass('OxBody') .addClass('OxBody')
.css({ .css({
@ -458,7 +465,7 @@ Ox.TableList = function(options, self) {
if (v.tooltip) { if (v.tooltip) {
$cell = Ox.Element({ $cell = Ox.Element({
tooltip: function() { tooltip: function() {
return self.options.selected.indexOf(data[self.unique]) > -1 return self.options.selected.indexOf(data[self.options.unique]) > -1
? (Ox.isString(v.tooltip) ? v.tooltip : v.tooltip(data)) : ''; ? (Ox.isString(v.tooltip) ? v.tooltip : v.tooltip(data)) : '';
} }
}); });
@ -594,7 +601,7 @@ Ox.TableList = function(options, self) {
sort.map ? sort.map(item[sort.key]) : item[sort.key] sort.map ? sort.map(item[sort.key]) : item[sort.key]
).toString().toLowerCase(); ).toString().toLowerCase();
if (Ox.startsWith(value, query)) { if (Ox.startsWith(value, query)) {
that.$body.options({selected: [item[self.unique]]}); that.$body.options({selected: [item[self.options.unique]]});
Ox.Log('List', 'QUERY', query, 'VALUE', value) Ox.Log('List', 'QUERY', query, 'VALUE', value)
Ox.Break(); Ox.Break();
} }
@ -1027,7 +1034,7 @@ Ox.TableList = function(options, self) {
return that.$body.value(id, key); return that.$body.value(id, key);
} else { } else {
that.$body.value(id, key, value); that.$body.value(id, key, value);
if (key == self.unique) { if (key == self.options.unique) {
// unique id has changed // unique id has changed
self.options.selected = self.options.selected.map(function(id_) { self.options.selected = self.options.selected.map(function(id_) {
return id_ == id ? value : id_ return id_ == id ? value : id_