Ox.List: use Ox.contains

This commit is contained in:
rlx 2014-09-26 10:59:06 +02:00
parent cdf8aa8788
commit 4b84424869

View file

@ -219,7 +219,7 @@ Ox.List = function(options, self) {
self.selected = self.options.items.map(function(item, i) {
return Ox.extend(item, {_index: i})
}).filter(function(item) {
return self.options.selected.indexOf(item[self.options.unique]) > -1;
return Ox.contains(self.options.selected, item[self.options.unique]);
}).map(function(item) {
return item['_index'];
});
@ -765,7 +765,7 @@ Ox.List = function(options, self) {
var ids = [], rest = [],
useRest = self.selected.length > self.listLength / 2;
result.data.items.forEach(function(item, i) {
if (self.selected.indexOf(i) > -1) {
if (isSelected(i)) {
ids.push(item[self.options.unique]);
} else if (useRest) {
rest.push(item[self.options.unique]);
@ -787,7 +787,7 @@ Ox.List = function(options, self) {
}
function isSelected(pos) {
return self.selected.indexOf(pos) > -1;
return Ox.contains(self.selected, pos);
}
function isSpecialTarget(e) {
@ -1463,7 +1463,7 @@ Ox.List = function(options, self) {
getSelectedIds(function(oldIds) {
var newIds = [];
Ox.forEach(self.options.items, function(item) {
if (oldIds.indexOf(item.id) > -1) {
if (Ox.contains(oldIds, item.id)) {
newIds.push(item.id);
}
if (newIds.length == oldIds.length) {
@ -1508,7 +1508,7 @@ Ox.List = function(options, self) {
if (selectedIds.length) {
self.selected = [];
self.options.items.forEach(function(item, i) {
if (selectedIds.indexOf(item.id) > -1) {
if (Ox.contains(selectedIds, item.id)) {
self.selected.push(i);
}
});
@ -1681,7 +1681,7 @@ Ox.List = function(options, self) {
});
} else { // remove items from pos to pos+length
Ox.range(pos, pos + length).forEach(function(i) {
self.selected.indexOf(i) > -1 && deselect(i);
isSelected(i) && deselect(i);
self.$items[i].remove();
});
self.options.items.splice(pos, length);
@ -1744,7 +1744,7 @@ Ox.List = function(options, self) {
};
/*@
size <f> fixme: not a good function name
size <f> Update list size
() -> <o> List Object
@*/
that.size = function() { // fixme: not a good function name