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
|
||||
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);
|
||||
|
|
|
@ -37,8 +37,9 @@ Ox.TextList <f:Ox.Element> TextList Object
|
|||
pageLength <n|100> Number of items per page
|
||||
scrollbarVisible <b|false> If true, the scrollbar is always visible
|
||||
selected <a|[]>
|
||||
sort <a|[]>
|
||||
sort <[]|[]>
|
||||
sortable <b|false> If true, elements can be re-ordered
|
||||
sums <[]|[]> Sums to be included in totals
|
||||
self <o> shared private variable
|
||||
@*/
|
||||
|
||||
|
@ -68,7 +69,8 @@ Ox.TextList = function(options, self) {
|
|||
scrollbarVisible: false,
|
||||
selected: [],
|
||||
sort: [],
|
||||
sortable: false
|
||||
sortable: false,
|
||||
sums: []
|
||||
})
|
||||
.options(options || {})
|
||||
.addClass('OxTextList')
|
||||
|
@ -86,6 +88,13 @@ Ox.TextList = function(options, self) {
|
|||
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?
|
||||
// fixme: and can't these just remain undefined?
|
||||
if (Ox.isUndefined(column.align)) {
|
||||
|
@ -208,6 +217,7 @@ Ox.TextList = function(options, self) {
|
|||
selected: self.options.selected,
|
||||
sort: self.options.sort,
|
||||
sortable: self.options.sortable,
|
||||
sums: self.options.sums,
|
||||
type: 'text',
|
||||
unique: self.unique
|
||||
}, Ox.clone(self)) // pass event handler
|
||||
|
|
|
@ -207,7 +207,10 @@ Ox.Map = function(options, self) {
|
|||
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();
|
||||
|
|
|
@ -173,6 +173,7 @@ Ox.api = function(items, options) {
|
|||
data.items = result.data.items.length;
|
||||
if (api.geo) {
|
||||
/*
|
||||
fixme: slow, disabled
|
||||
data.area = Ox.joinAreas(result.data.items.map(function(item) {
|
||||
return {
|
||||
sw: {lat: item.south, lng: item.west},
|
||||
|
|
Loading…
Reference in a new issue