1
0
Fork 0
forked from 0x2620/oxjs

use Ox.api in Ox.List and Ox.Map

This commit is contained in:
rolux 2012-04-04 09:06:55 +02:00
commit 7b7bedb65a
4 changed files with 45 additions and 8 deletions

View file

@ -26,6 +26,7 @@ Ox.List <f:Ox.Element> List Element
selected <a|[]> ids of the selected elements
sort <a|[]> sort order
sortable <b|false> If true, items can be re-ordered
sums <[]|[]> sums to be included in totals
type <s|'text'>
unique <s|''> name of the key that acts as unique id
self <o> shared private variable
@ -68,12 +69,29 @@ Ox.List = function(options, self) {
selected: [],
sort: [],
sortable: false,
sums: [],
type: 'text',
unique: ''
})
.options(options || {})
.scroll(scroll);
self.options.sort = self.options.sort.map(function(sort) {
return Ox.isString(sort) ? {
key: sort.replace(/^[\+\-]/, ''),
operator: sort[0] == '-' ? '-' : '+'
} : sort;
});
if (Ox.isArray(self.options.items)) {
self.options.items = Ox.api(self.options.items, {
cache: true,
sort: self.options.sort,
sums: self.options.sums,
unique: self.options.unique
});
}
that.$content.bindEvent({
mousedown: mousedown,
singleclick: singleclick,
@ -103,7 +121,7 @@ Ox.List = function(options, self) {
$items: [],
$pages: [],
format: {},
isAsync: Ox.isFunction(self.options.items),
isAsync: true,
itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later
keyboardEvents: {
key_control_c: copyItems,
@ -1384,15 +1402,20 @@ Ox.List = function(options, self) {
//Ox.Log('List', 'list setOption', key, value);
var previousSelected;
if (key == 'items') {
// fixme: this could be used to change the list
// from sync to async or vice versa, which wouldn't work
if (Ox.isArray(value)) {
self.options.items = Ox.api(self.options.items, {
cache: true,
sort: self.options.sort,
sums: self.options.sums,
unique: self.options.unique
});
/*
self.listLength = value.length;
updateSelected();
updateSort();
} else {
updateQuery();
*/
}
updateQuery();
} else if (key == 'selected') {
previousSelected = self.selected;
setSelected(value);