updating list
This commit is contained in:
parent
6f64ad3512
commit
fcdfb03bea
1 changed files with 23 additions and 43 deletions
|
@ -258,19 +258,16 @@ Ox.List = function(options, self) {
|
||||||
self.selected.push(pos);
|
self.selected.push(pos);
|
||||||
!Ox.isUndefined(self.$items[pos]) &&
|
!Ox.isUndefined(self.$items[pos]) &&
|
||||||
self.$items[pos].addClass('OxSelected');
|
self.$items[pos].addClass('OxSelected');
|
||||||
//Ox.print('addToSelection')
|
|
||||||
triggerSelectEvent();
|
triggerSelectEvent();
|
||||||
} else {
|
} else {
|
||||||
// allow for 'cursor navigation' if orientation == 'both'
|
// allow for 'cursor navigation' if orientation == 'both'
|
||||||
self.selected.splice(self.selected.indexOf(pos), 1);
|
self.selected.splice(self.selected.indexOf(pos), 1);
|
||||||
self.selected.push(pos);
|
self.selected.push(pos);
|
||||||
//Ox.print('self.selected', self.selected)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
self.requests.forEach(function(v) {
|
self.requests.forEach(function(v) {
|
||||||
//Ox.print('Ox.Request.cancel', v);
|
|
||||||
Ox.Request.cancel(v);
|
Ox.Request.cancel(v);
|
||||||
});
|
});
|
||||||
$.extend(self, {
|
$.extend(self, {
|
||||||
|
@ -282,7 +279,6 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function constructEmptyPage(page) {
|
function constructEmptyPage(page) {
|
||||||
//Ox.print('cEP', page)
|
|
||||||
var i, $page = Ox.ListPage().css(getPageCSS(page));
|
var i, $page = Ox.ListPage().css(getPageCSS(page));
|
||||||
for (i = 0; i < getPageLength(page); i++
|
for (i = 0; i < getPageLength(page); i++
|
||||||
) {
|
) {
|
||||||
|
@ -291,7 +287,6 @@ Ox.List = function(options, self) {
|
||||||
construct: self.options.construct
|
construct: self.options.construct
|
||||||
}).appendTo($page);
|
}).appendTo($page);
|
||||||
}
|
}
|
||||||
//Ox.print('cEP done')
|
|
||||||
return $page;
|
return $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,12 +419,10 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function emptyFirstPage() {
|
function emptyFirstPage() {
|
||||||
//Ox.print('emptyFirstPage', self.$pages);
|
|
||||||
self.$pages[0] && self.$pages[0].find('.OxEmpty').remove();
|
self.$pages[0] && self.$pages[0].find('.OxEmpty').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillFirstPage() {
|
function fillFirstPage() {
|
||||||
Ox.print('fillFirstPage')
|
|
||||||
if (self.$pages[0]) {
|
if (self.$pages[0]) {
|
||||||
var height = getHeight(),
|
var height = getHeight(),
|
||||||
lastItemHeight = height % self.options.itemHeight || self.options.itemHeight,
|
lastItemHeight = height % self.options.itemHeight || self.options.itemHeight,
|
||||||
|
@ -461,7 +454,6 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function findItemPosition(e) {
|
function findItemPosition(e) {
|
||||||
//Ox.print('---- findItem', e.target)
|
|
||||||
var $element = $(e.target),
|
var $element = $(e.target),
|
||||||
position = -1;
|
position = -1;
|
||||||
while (!$element.hasClass('OxTarget') && !$element.hasClass('OxPage') && !$element.is('body')) {
|
while (!$element.hasClass('OxTarget') && !$element.hasClass('OxPage') && !$element.is('body')) {
|
||||||
|
@ -572,7 +564,7 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPositions(callback) {
|
function getPositions(callback) {
|
||||||
Ox.print('getPositions', self.options.selected);
|
//Ox.print('getPositions', self.options.selected);
|
||||||
// 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
|
||||||
if (self.options.selected.length /*&& ids.length < self.listLength*/) {
|
if (self.options.selected.length /*&& ids.length < self.listLength*/) {
|
||||||
/*Ox.print('-------- request', {
|
/*Ox.print('-------- request', {
|
||||||
|
@ -591,7 +583,7 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPositionsCallback(result, callback) {
|
function getPositionsCallback(result, callback) {
|
||||||
Ox.print('getPositionsCallback', result);
|
//Ox.print('getPositionsCallback', result);
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
if (result) {
|
if (result) {
|
||||||
$.extend(self, {
|
$.extend(self, {
|
||||||
|
@ -599,7 +591,6 @@ Ox.List = function(options, self) {
|
||||||
selected: []
|
selected: []
|
||||||
});
|
});
|
||||||
Ox.forEach(result.data.positions, function(pos, id) {
|
Ox.forEach(result.data.positions, function(pos, id) {
|
||||||
//Ox.print('id', id, 'pos', pos)
|
|
||||||
self.selected.push(pos);
|
self.selected.push(pos);
|
||||||
});
|
});
|
||||||
pos = Ox.min(self.selected);
|
pos = Ox.min(self.selected);
|
||||||
|
@ -643,13 +634,10 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedIds() {
|
function getSelectedIds() {
|
||||||
//Ox.print('gSI', self.selected, self.$items)
|
|
||||||
if (self.$items.length == 0) {
|
if (self.$items.length == 0) {
|
||||||
return self.options.selected;
|
return self.options.selected;
|
||||||
} else {
|
} else {
|
||||||
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('gsI', pos)
|
|
||||||
return self.$items[pos].options('data')[self.options.unique];
|
return self.$items[pos].options('data')[self.options.unique];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -670,7 +658,6 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadItems() {
|
function loadItems() {
|
||||||
//Ox.print('start loadItems')
|
|
||||||
that.$content.empty();
|
that.$content.empty();
|
||||||
self.options.items.forEach(function(item, pos) {
|
self.options.items.forEach(function(item, pos) {
|
||||||
// fixme: duplicated
|
// fixme: duplicated
|
||||||
|
@ -685,7 +672,6 @@ Ox.List = function(options, self) {
|
||||||
self.$items[pos].appendTo(that.$content);
|
self.$items[pos].appendTo(that.$content);
|
||||||
});
|
});
|
||||||
self.selected.length && scrollToPosition(self.selected[0]);
|
self.selected.length && scrollToPosition(self.selected[0]);
|
||||||
//Ox.print('stop loadItems')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPageLength(page) {
|
function getPageLength(page) {
|
||||||
|
@ -698,7 +684,7 @@ Ox.List = function(options, self) {
|
||||||
!Ox.isUndefined(callback) && callback();
|
!Ox.isUndefined(callback) && callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Ox.print('loadPage', page);
|
Ox.print(that.id, 'loadPage', page);
|
||||||
var keys = $.merge(self.options.keys.indexOf(self.options.unique) == -1 ? [self.options.unique] : [], self.options.keys),
|
var keys = $.merge(self.options.keys.indexOf(self.options.unique) == -1 ? [self.options.unique] : [], self.options.keys),
|
||||||
offset = page * self.pageLength,
|
offset = page * self.pageLength,
|
||||||
range = [offset, offset + getPageLength(page)];
|
range = [offset, offset + getPageLength(page)];
|
||||||
|
@ -716,19 +702,19 @@ Ox.List = function(options, self) {
|
||||||
result.data.items.forEach(function(v, i) {
|
result.data.items.forEach(function(v, i) {
|
||||||
var pos = offset + i;
|
var pos = offset + i;
|
||||||
self.$items[pos] = Ox.ListItem({
|
self.$items[pos] = Ox.ListItem({
|
||||||
construct: self.options.construct,
|
construct: self.options.construct,
|
||||||
data: v,
|
data: v,
|
||||||
draggable: self.options.draggable,
|
draggable: self.options.draggable,
|
||||||
//format: self.options.format,
|
//format: self.options.format,
|
||||||
position: pos,
|
position: pos,
|
||||||
unique: self.options.unique
|
unique: self.options.unique
|
||||||
});
|
});
|
||||||
isSelected(pos) && self.$items[pos].addClass('OxSelected');
|
isSelected(pos) && self.$items[pos].addClass('OxSelected');
|
||||||
self.$items[pos].appendTo(self.$pages[page]);
|
self.$items[pos].appendTo(self.$pages[page]);
|
||||||
});
|
});
|
||||||
self.options.type == 'text' && page == 0 && fillFirstPage();
|
self.options.type == 'text' && page == 0 && fillFirstPage();
|
||||||
// fixme: why does emptyPage sometimes have no methods?
|
// fixme: why does emptyPage sometimes have no methods?
|
||||||
Ox.print('emptyPage', $emptyPage)
|
//Ox.print('emptyPage', $emptyPage)
|
||||||
$emptyPage.removeElement && $emptyPage.removeElement();
|
$emptyPage.removeElement && $emptyPage.removeElement();
|
||||||
self.$pages[page].appendTo(that.$content);
|
self.$pages[page].appendTo(that.$content);
|
||||||
!Ox.isUndefined(callback) && callback(); // fixme: callback necessary? why not bind to event?
|
!Ox.isUndefined(callback) && callback(); // fixme: callback necessary? why not bind to event?
|
||||||
|
@ -922,7 +908,6 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function preview() {
|
function preview() {
|
||||||
Ox.print('preview selected', !self.preview, self.options.selected)
|
|
||||||
if (self.options.selected.length) {
|
if (self.options.selected.length) {
|
||||||
self.preview = !self.preview;
|
self.preview = !self.preview;
|
||||||
if (self.preview) {
|
if (self.preview) {
|
||||||
|
@ -942,9 +927,11 @@ Ox.List = function(options, self) {
|
||||||
self.scrollTimeout = setTimeout(function() {
|
self.scrollTimeout = setTimeout(function() {
|
||||||
self.scrollTimeout = 0;
|
self.scrollTimeout = 0;
|
||||||
self.page = getPage();
|
self.page = getPage();
|
||||||
|
/*
|
||||||
if (self.page != page) {
|
if (self.page != page) {
|
||||||
//Ox.print('page', page, '-->', self.page);
|
Ox.print('page', page, '-->', self.page);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (self.page == page - 1) {
|
if (self.page == page - 1) {
|
||||||
unloadPage(self.page + 2);
|
unloadPage(self.page + 2);
|
||||||
loadPage(self.page - 1);
|
loadPage(self.page - 1);
|
||||||
|
@ -995,6 +982,7 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollToPosition(pos, leftOrTopAlign) {
|
function scrollToPosition(pos, leftOrTopAlign) {
|
||||||
|
//Ox.print('scrollToPosition', pos)
|
||||||
var itemHeight = self.options.itemHeight + self.itemMargin,
|
var itemHeight = self.options.itemHeight + self.itemMargin,
|
||||||
itemWidth = self.options.itemWidth + self.itemMargin,
|
itemWidth = self.options.itemWidth + self.itemMargin,
|
||||||
positions = [],
|
positions = [],
|
||||||
|
@ -1103,7 +1091,6 @@ Ox.List = function(options, self) {
|
||||||
// fixme: no case where callback is set
|
// fixme: no case where callback is set
|
||||||
// fixme: can't use selectNone here,
|
// fixme: can't use selectNone here,
|
||||||
// since it'd trigger a select event
|
// since it'd trigger a select event
|
||||||
Ox.print('setSelected', ids)
|
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
self.$items.forEach(function($item, pos) {
|
self.$items.forEach(function($item, pos) {
|
||||||
if (isSelected(pos)) {
|
if (isSelected(pos)) {
|
||||||
|
@ -1128,7 +1115,6 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
function select(pos, i) {
|
function select(pos, i) {
|
||||||
Ox.print('pushing', pos, 'onto self.selected')
|
|
||||||
self.selected.push(pos);
|
self.selected.push(pos);
|
||||||
!Ox.isUndefined(self.$items[pos]) &&
|
!Ox.isUndefined(self.$items[pos]) &&
|
||||||
self.$items[pos].addClass('OxSelected');
|
self.$items[pos].addClass('OxSelected');
|
||||||
|
@ -1158,7 +1144,7 @@ Ox.List = function(options, self) {
|
||||||
var ids = self.options.selected = getSelectedIds();
|
var ids = self.options.selected = getSelectedIds();
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var ids_ = self.options.selected = getSelectedIds();
|
var ids_ = self.options.selected = getSelectedIds();
|
||||||
Ox.print('ids', ids, 'ids after 100 msec', ids_, Ox.isEqual(ids, ids_))
|
// Ox.print('ids', ids, 'ids after 100 msec', ids_, Ox.isEqual(ids, ids_))
|
||||||
if (Ox.isEqual(ids, ids_)) {
|
if (Ox.isEqual(ids, ids_)) {
|
||||||
that.triggerEvent('select', {
|
that.triggerEvent('select', {
|
||||||
ids: ids
|
ids: ids
|
||||||
|
@ -1167,7 +1153,7 @@ Ox.List = function(options, self) {
|
||||||
ids: ids
|
ids: ids
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Ox.print('select event not triggered after timeout');
|
// Ox.print('select event not triggered after timeout');
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
@ -1226,11 +1212,11 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateQuery(callback) { // fixme: shouldn't this be setQuery?
|
function updateQuery(callback) { // fixme: shouldn't this be setQuery?
|
||||||
Ox.print('updateQuery', self.options)
|
//Ox.print('updateQuery', self.options)
|
||||||
clear(); // fixme: bad function name ... clear what?
|
clear(); // fixme: bad function name ... clear what?
|
||||||
self.requests.push(self.options.items({}, function(result) {
|
self.requests.push(self.options.items({}, function(result) {
|
||||||
var keys = {};
|
var keys = {};
|
||||||
Ox.print('INIT!!!', result.data)
|
//Ox.print('INIT!!!', result.data)
|
||||||
that.triggerEvent('init', result.data);
|
that.triggerEvent('init', result.data);
|
||||||
self.rowLength = getRowLength();
|
self.rowLength = getRowLength();
|
||||||
self.pageLength = self.options.orientation == 'both' ?
|
self.pageLength = self.options.orientation == 'both' ?
|
||||||
|
@ -1257,7 +1243,7 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSelected() {
|
function updateSelected() {
|
||||||
Ox.print('updateSelected')
|
//Ox.print('updateSelected')
|
||||||
var oldSelectedIds = getSelectedIds(),
|
var oldSelectedIds = getSelectedIds(),
|
||||||
newSelectedIds = [];
|
newSelectedIds = [];
|
||||||
Ox.forEach(self.options.items, function(item) {
|
Ox.forEach(self.options.items, function(item) {
|
||||||
|
@ -1281,7 +1267,6 @@ Ox.List = function(options, self) {
|
||||||
self.options.items.forEach(function(item) {
|
self.options.items.forEach(function(item) {
|
||||||
sort[item.id] = map ? map(item[key]) : item[key];
|
sort[item.id] = map ? map(item[key]) : item[key];
|
||||||
});
|
});
|
||||||
Ox.print('start sort')
|
|
||||||
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],
|
||||||
|
@ -1293,7 +1278,6 @@ Ox.List = function(options, self) {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
Ox.print('end sort')
|
|
||||||
if (selectedIds.length) {
|
if (selectedIds.length) {
|
||||||
self.selected = [];
|
self.selected = [];
|
||||||
self.options.items.forEach(function(item, i) {
|
self.options.items.forEach(function(item, i) {
|
||||||
|
@ -1324,13 +1308,13 @@ Ox.List = function(options, self) {
|
||||||
updateQuery();
|
updateQuery();
|
||||||
}
|
}
|
||||||
} else if (key == 'selected') {
|
} else if (key == 'selected') {
|
||||||
Ox.print('setOption selected', value)
|
//Ox.print('setOption selected', value)
|
||||||
setSelected(value);
|
setSelected(value);
|
||||||
// fixme: next line added to make text list find-as-you-type work,
|
// fixme: next line added to make text list find-as-you-type work,
|
||||||
// may break other things
|
// may break other things
|
||||||
!self.isAsync && triggerSelectEvent(value);
|
!self.isAsync && triggerSelectEvent(value);
|
||||||
} else if (key == 'sort') {
|
} else if (key == 'sort') {
|
||||||
Ox.print('---sort---')
|
//Ox.print('---sort---')
|
||||||
updateSort();
|
updateSort();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1382,7 +1366,6 @@ Ox.List = function(options, self) {
|
||||||
() -> <o> the list
|
() -> <o> the list
|
||||||
@*/
|
@*/
|
||||||
that.closePreview = function() {
|
that.closePreview = function() {
|
||||||
Ox.print('-- closePreview --')
|
|
||||||
self.preview = false;
|
self.preview = false;
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
@ -1479,7 +1462,6 @@ Ox.List = function(options, self) {
|
||||||
() -> <o> the list
|
() -> <o> the list
|
||||||
@*/
|
@*/
|
||||||
that.reloadPages = function() {
|
that.reloadPages = function() {
|
||||||
//Ox.print('---------------- list reload, page', self.page)
|
|
||||||
var page = self.page;
|
var page = self.page;
|
||||||
clear();
|
clear();
|
||||||
self.page = page
|
self.page = page
|
||||||
|
@ -1554,11 +1536,9 @@ Ox.List = function(options, self) {
|
||||||
that.$content.css({
|
that.$content.css({
|
||||||
height: self.listSize + 'px'
|
height: self.listSize + 'px'
|
||||||
});
|
});
|
||||||
//Ox.print('scrolling to', scroll)
|
|
||||||
scrollTo(scroll);
|
scrollTo(scroll);
|
||||||
}
|
}
|
||||||
} else if (self.options.type == 'text') {
|
} else if (self.options.type == 'text') {
|
||||||
//Ox.print('that.size, type==text')
|
|
||||||
emptyFirstPage();
|
emptyFirstPage();
|
||||||
fillFirstPage();
|
fillFirstPage();
|
||||||
}
|
}
|
||||||
|
@ -1581,7 +1561,7 @@ Ox.List = function(options, self) {
|
||||||
// fixme: this (and others) should be deprecated,
|
// fixme: this (and others) should be deprecated,
|
||||||
// one should set options instead
|
// one should set options instead
|
||||||
that.sortList = function(key, operator, map) {
|
that.sortList = function(key, operator, map) {
|
||||||
Ox.print('sortList', key, operator, map)
|
// Ox.print('sortList', key, operator, map)
|
||||||
if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) {
|
if (key != self.options.sort[0].key || operator != self.options.sort[0].operator) {
|
||||||
self.options.sort[0] = {key: key, operator: operator, map: map};
|
self.options.sort[0] = {key: key, operator: operator, map: map};
|
||||||
updateSort();
|
updateSort();
|
||||||
|
|
Loading…
Reference in a new issue