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