use Ox.api in Ox.List and Ox.Map
This commit is contained in:
parent
997b704f8b
commit
7b7bedb65a
4 changed files with 45 additions and 8 deletions
|
@ -26,6 +26,7 @@ Ox.List <f:Ox.Element> List Element
|
||||||
selected <a|[]> ids of the selected elements
|
selected <a|[]> ids of the selected elements
|
||||||
sort <a|[]> sort order
|
sort <a|[]> sort order
|
||||||
sortable <b|false> If true, items can be re-ordered
|
sortable <b|false> If true, items can be re-ordered
|
||||||
|
sums <[]|[]> sums to be included in totals
|
||||||
type <s|'text'>
|
type <s|'text'>
|
||||||
unique <s|''> name of the key that acts as unique id
|
unique <s|''> name of the key that acts as unique id
|
||||||
self <o> shared private variable
|
self <o> shared private variable
|
||||||
|
@ -68,12 +69,29 @@ Ox.List = function(options, self) {
|
||||||
selected: [],
|
selected: [],
|
||||||
sort: [],
|
sort: [],
|
||||||
sortable: false,
|
sortable: false,
|
||||||
|
sums: [],
|
||||||
type: 'text',
|
type: 'text',
|
||||||
unique: ''
|
unique: ''
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {})
|
||||||
.scroll(scroll);
|
.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({
|
that.$content.bindEvent({
|
||||||
mousedown: mousedown,
|
mousedown: mousedown,
|
||||||
singleclick: singleclick,
|
singleclick: singleclick,
|
||||||
|
@ -103,7 +121,7 @@ Ox.List = function(options, self) {
|
||||||
$items: [],
|
$items: [],
|
||||||
$pages: [],
|
$pages: [],
|
||||||
format: {},
|
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
|
itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later
|
||||||
keyboardEvents: {
|
keyboardEvents: {
|
||||||
key_control_c: copyItems,
|
key_control_c: copyItems,
|
||||||
|
@ -1384,15 +1402,20 @@ Ox.List = function(options, self) {
|
||||||
//Ox.Log('List', 'list setOption', key, value);
|
//Ox.Log('List', 'list setOption', key, value);
|
||||||
var previousSelected;
|
var previousSelected;
|
||||||
if (key == 'items') {
|
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)) {
|
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;
|
self.listLength = value.length;
|
||||||
updateSelected();
|
updateSelected();
|
||||||
updateSort();
|
updateSort();
|
||||||
} else {
|
*/
|
||||||
updateQuery();
|
|
||||||
}
|
}
|
||||||
|
updateQuery();
|
||||||
} else if (key == 'selected') {
|
} else if (key == 'selected') {
|
||||||
previousSelected = self.selected;
|
previousSelected = self.selected;
|
||||||
setSelected(value);
|
setSelected(value);
|
||||||
|
|
|
@ -37,8 +37,9 @@ Ox.TextList <f:Ox.Element> TextList Object
|
||||||
pageLength <n|100> Number of items per page
|
pageLength <n|100> Number of items per page
|
||||||
scrollbarVisible <b|false> If true, the scrollbar is always visible
|
scrollbarVisible <b|false> If true, the scrollbar is always visible
|
||||||
selected <a|[]>
|
selected <a|[]>
|
||||||
sort <a|[]>
|
sort <[]|[]>
|
||||||
sortable <b|false> If true, elements can be re-ordered
|
sortable <b|false> If true, elements can be re-ordered
|
||||||
|
sums <[]|[]> Sums to be included in totals
|
||||||
self <o> shared private variable
|
self <o> shared private variable
|
||||||
@*/
|
@*/
|
||||||
|
|
||||||
|
@ -68,7 +69,8 @@ Ox.TextList = function(options, self) {
|
||||||
scrollbarVisible: false,
|
scrollbarVisible: false,
|
||||||
selected: [],
|
selected: [],
|
||||||
sort: [],
|
sort: [],
|
||||||
sortable: false
|
sortable: false,
|
||||||
|
sums: []
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {})
|
||||||
.addClass('OxTextList')
|
.addClass('OxTextList')
|
||||||
|
@ -86,6 +88,13 @@ Ox.TextList = function(options, self) {
|
||||||
keys: find
|
keys: find
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.options.sort = self.options.sort.map(function(sort) {
|
||||||
|
return Ox.isString(sort) ? {
|
||||||
|
key: sort.replace(/^[\+\-]/, ''),
|
||||||
|
operator: sort[0] == '-' ? '-' : '+'
|
||||||
|
} : sort;
|
||||||
|
});
|
||||||
|
|
||||||
self.options.columns.forEach(function(column) { // fixme: can this go into a generic ox.js function?
|
self.options.columns.forEach(function(column) { // 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?
|
||||||
if (Ox.isUndefined(column.align)) {
|
if (Ox.isUndefined(column.align)) {
|
||||||
|
@ -208,6 +217,7 @@ Ox.TextList = function(options, self) {
|
||||||
selected: self.options.selected,
|
selected: self.options.selected,
|
||||||
sort: self.options.sort,
|
sort: self.options.sort,
|
||||||
sortable: self.options.sortable,
|
sortable: self.options.sortable,
|
||||||
|
sums: self.options.sums,
|
||||||
type: 'text',
|
type: 'text',
|
||||||
unique: self.unique
|
unique: self.unique
|
||||||
}, Ox.clone(self)) // pass event handler
|
}, Ox.clone(self)) // pass event handler
|
||||||
|
|
|
@ -207,7 +207,10 @@ Ox.Map = function(options, self) {
|
||||||
place.id = Ox.encodeBase32(Ox.uid());
|
place.id = Ox.encodeBase32(Ox.uid());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.options.places = Ox.api(self.options.places, {geo: true});
|
self.options.places = Ox.api(self.options.places, {
|
||||||
|
geo: true,
|
||||||
|
sort: '-area'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self.mapHeight = getMapHeight();
|
self.mapHeight = getMapHeight();
|
||||||
|
|
|
@ -173,6 +173,7 @@ Ox.api = function(items, options) {
|
||||||
data.items = result.data.items.length;
|
data.items = result.data.items.length;
|
||||||
if (api.geo) {
|
if (api.geo) {
|
||||||
/*
|
/*
|
||||||
|
fixme: slow, disabled
|
||||||
data.area = Ox.joinAreas(result.data.items.map(function(item) {
|
data.area = Ox.joinAreas(result.data.items.map(function(item) {
|
||||||
return {
|
return {
|
||||||
sw: {lat: item.south, lng: item.west},
|
sw: {lat: item.south, lng: item.west},
|
||||||
|
|
Loading…
Reference in a new issue