textlist improvements (keep selection after sort, make left/right arrows scroll left/right)
This commit is contained in:
parent
32b2da184a
commit
187adae7e2
3 changed files with 64 additions and 17 deletions
|
@ -123,7 +123,7 @@ Ox.Form = function(options, self) {
|
||||||
} else {
|
} else {
|
||||||
Ox.forEach(arguments[0], function(value, key) {
|
Ox.forEach(arguments[0], function(value, key) {
|
||||||
var index = getItemIndexById(key);
|
var index = getItemIndexById(key);
|
||||||
index > -1 && Ox.print(':::::::', key, value)
|
//index > -1 && Ox.print(':::::::', key, value)
|
||||||
index > -1 && self.options.items[index].options({value: value});
|
index > -1 && self.options.items[index].options({value: value});
|
||||||
});
|
});
|
||||||
return that;
|
return that;
|
||||||
|
|
|
@ -556,7 +556,7 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPositions(ids) {
|
function getPositions(ids) {
|
||||||
Ox.print('getPositions', ids)
|
// Ox.print('getPositions', ids)
|
||||||
ids = ids || getSelectedIds();
|
ids = ids || getSelectedIds();
|
||||||
Ox.print('getPositions', ids)
|
Ox.print('getPositions', ids)
|
||||||
// fixme: optimize: send non-selected ids if more than half of the items are selected
|
// fixme: optimize: send non-selected ids if more than half of the items are selected
|
||||||
|
@ -628,7 +628,7 @@ Ox.List = function(options, self) {
|
||||||
function getSelectedIds() {
|
function getSelectedIds() {
|
||||||
//Ox.print('gSI', self.selected, self.$items)
|
//Ox.print('gSI', self.selected, self.$items)
|
||||||
return $.map(self.selected, function(pos) {
|
return $.map(self.selected, function(pos) {
|
||||||
Ox.print('....', pos, self.options.unique, self.$items[pos].options('data')[self.options.unique])
|
//Ox.print('....', pos, self.options.unique, self.$items[pos].options('data')[self.options.unique])
|
||||||
//Ox.print('2222', self.$items, pos)
|
//Ox.print('2222', self.$items, pos)
|
||||||
return self.$items[pos].options('data')[self.options.unique];
|
return self.$items[pos].options('data')[self.options.unique];
|
||||||
});
|
});
|
||||||
|
@ -662,6 +662,7 @@ Ox.List = function(options, self) {
|
||||||
isSelected(pos) && self.$items[pos].addClass('OxSelected');
|
isSelected(pos) && self.$items[pos].addClass('OxSelected');
|
||||||
self.$items[pos].appendTo(that.$content);
|
self.$items[pos].appendTo(that.$content);
|
||||||
});
|
});
|
||||||
|
self.selected.length && scrollToPosition(self.selected[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPageLength(page) {
|
function getPageLength(page) {
|
||||||
|
@ -1230,14 +1231,16 @@ Ox.List = function(options, self) {
|
||||||
function updateSort() {
|
function updateSort() {
|
||||||
Ox.print('start sort')
|
Ox.print('start sort')
|
||||||
var key = self.options.sort[0].key,
|
var key = self.options.sort[0].key,
|
||||||
operator = self.options.sort[0].operator,
|
|
||||||
map = self.options.sort[0].map,
|
map = self.options.sort[0].map,
|
||||||
|
operator = self.options.sort[0].operator,
|
||||||
|
selectedIds,
|
||||||
sort = {};
|
sort = {};
|
||||||
self.options.items.forEach(function(item) {
|
|
||||||
sort[item.id] = map ? map(item[key]) : item[key];
|
|
||||||
});
|
|
||||||
if (self.listLength > 1) {
|
if (self.listLength > 1) {
|
||||||
if (Ox.isArray(self.options.items)) {
|
if (Ox.isArray(self.options.items)) {
|
||||||
|
selectedIds = getSelectedIds();
|
||||||
|
self.options.items.forEach(function(item) {
|
||||||
|
sort[item.id] = map ? map(item[key]) : item[key];
|
||||||
|
});
|
||||||
self.options.items.sort(function(a, b) {
|
self.options.items.sort(function(a, b) {
|
||||||
var aValue = sort[a.id],
|
var aValue = sort[a.id],
|
||||||
bValue = sort[b.id],
|
bValue = sort[b.id],
|
||||||
|
@ -1249,6 +1252,14 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
if (selectedIds.length) {
|
||||||
|
self.selected = [];
|
||||||
|
self.options.items.forEach(function(item, i) {
|
||||||
|
if (selectedIds.indexOf(item.id) > -1) {
|
||||||
|
self.selected.push(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
loadItems();
|
loadItems();
|
||||||
} else {
|
} else {
|
||||||
clear(); // fixme: bad function name
|
clear(); // fixme: bad function name
|
||||||
|
|
|
@ -58,7 +58,17 @@ Ox.TextList = function(options, self) {
|
||||||
sort: []
|
sort: []
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {})
|
||||||
.addClass('OxTextList');
|
.addClass('OxTextList')
|
||||||
|
.bindEvent({
|
||||||
|
key_left: function() {
|
||||||
|
var $element = that.$body.$element;
|
||||||
|
$element[0].scrollLeft = $element[0].scrollLeft - $element.width();
|
||||||
|
},
|
||||||
|
key_right: function() {
|
||||||
|
var $element = that.$body.$element;
|
||||||
|
$element[0].scrollLeft = $element[0].scrollLeft + $element.width();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
self.options.columns.forEach(function(v) { // fixme: can this go into a generic ox.js function?
|
self.options.columns.forEach(function(v) { // fixme: can this go into a generic ox.js function?
|
||||||
// fixme: and can't these just remain undefined?
|
// fixme: and can't these just remain undefined?
|
||||||
|
@ -254,15 +264,19 @@ Ox.TextList = function(options, self) {
|
||||||
Ox.print('clickColumn', id);
|
Ox.print('clickColumn', id);
|
||||||
var i = getColumnIndexById(id),
|
var i = getColumnIndexById(id),
|
||||||
isSelected = self.options.sort[0].key == self.options.columns[i].id;
|
isSelected = self.options.sort[0].key == self.options.columns[i].id;
|
||||||
that.$body.options({
|
self.options.sort = [{
|
||||||
sort: [{
|
key: self.options.columns[i].id,
|
||||||
key: self.options.columns[i].id,
|
operator: isSelected ?
|
||||||
operator: isSelected ?
|
(self.options.sort[0].operator == '+' ? '-' : '+') :
|
||||||
(self.options.sort[0].operator == '+' ? '-' : '+') :
|
self.options.columns[i].operator,
|
||||||
self.options.columns[i].operator,
|
map: self.options.columns[i].map
|
||||||
map: self.options.columns[i].map
|
}]
|
||||||
}]
|
updateColumn();
|
||||||
});
|
// fixme: strangely, sorting the list blocks updating the column,
|
||||||
|
// so we use a timeout for now
|
||||||
|
setTimeout(function() {
|
||||||
|
that.$body.options({sort: self.options.sort});
|
||||||
|
}, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
function constructHead() {
|
function constructHead() {
|
||||||
|
@ -622,6 +636,20 @@ Ox.TextList = function(options, self) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateColumn() {
|
||||||
|
var columnId = self.options.columns[self.selectedColumn].id
|
||||||
|
isSelected = columnId == self.options.sort[0].key;
|
||||||
|
if (self.options.columnsVisible) {
|
||||||
|
if (isSelected) {
|
||||||
|
updateOrder(columnId);
|
||||||
|
} else {
|
||||||
|
toggleSelected(columnId);
|
||||||
|
self.selectedColumn = getColumnIndexById(self.options.sort[0].key);
|
||||||
|
toggleSelected(self.options.columns[self.selectedColumn].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function updateOrder(id) {
|
function updateOrder(id) {
|
||||||
var pos = getColumnPositionById(id);
|
var pos = getColumnPositionById(id);
|
||||||
//Ox.print(id, pos)
|
//Ox.print(id, pos)
|
||||||
|
@ -638,6 +666,9 @@ Ox.TextList = function(options, self) {
|
||||||
that.$body.options(key, value);
|
that.$body.options(key, value);
|
||||||
} else if (key == 'selected') {
|
} else if (key == 'selected') {
|
||||||
that.$body.options(key, value);
|
that.$body.options(key, value);
|
||||||
|
} else if (key == 'sort') {
|
||||||
|
updateColumn();
|
||||||
|
that.$body.options(key, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -731,7 +762,9 @@ Ox.TextList = function(options, self) {
|
||||||
that.$body.size();
|
that.$body.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fixme: deprecated
|
||||||
that.sortList = function(key, operator) {
|
that.sortList = function(key, operator) {
|
||||||
|
Ox.print('$$$$ DEPRECATED $$$$')
|
||||||
var isSelected = key == self.options.sort[0].key;
|
var isSelected = key == self.options.sort[0].key;
|
||||||
self.options.sort = [{
|
self.options.sort = [{
|
||||||
key: key,
|
key: key,
|
||||||
|
@ -750,11 +783,14 @@ Ox.TextList = function(options, self) {
|
||||||
// fixme: strangely, sorting the list blocks toggling the selection,
|
// fixme: strangely, sorting the list blocks toggling the selection,
|
||||||
// so we use a timeout for now
|
// so we use a timeout for now
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
that.$body.options({sort: self.options.sort});
|
||||||
|
/*
|
||||||
that.$body.sortList(
|
that.$body.sortList(
|
||||||
self.options.sort[0].key,
|
self.options.sort[0].key,
|
||||||
self.options.sort[0].operator,
|
self.options.sort[0].operator,
|
||||||
self.options.sort[0].map
|
self.options.sort[0].map
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}, 10);
|
}, 10);
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue