even more improvements to lists

This commit is contained in:
rlx 2011-01-13 19:41:10 +00:00
parent 489e72a8af
commit deb35064a1

View file

@ -659,7 +659,6 @@ requires
return { return {
cancel: function() { cancel: function() {
var index;
if (arguments.length == 0) { if (arguments.length == 0) {
requests = {}; requests = {};
} else if (Ox.isFunction(arguments[0])) { } else if (Ox.isFunction(arguments[0])) {
@ -1094,11 +1093,11 @@ requires
*/ */
if (Ox.isObject(arguments[0])) { if (Ox.isObject(arguments[0])) {
$.each(arguments[0], function(event, data) { $.each(arguments[0], function(event, data) {
//Ox.print(that.id, self.options.id, 'trigger', event, data); Ox.print(that.id, self.options.id, 'trigger', event, data);
self.$eventHandler.trigger('ox_' + event, data); self.$eventHandler.trigger('ox_' + event, data);
}); });
} else { } else {
//Ox.print('??', that.id, self.options ? self.options.id : '', 'trigger', arguments[0], arguments[1] || {}); Ox.print(that.id, self.options ? self.options.id : '', 'trigger', arguments[0], arguments[1] || {});
self.$eventHandler.trigger('ox_' + arguments[0], arguments[1] || {}); self.$eventHandler.trigger('ox_' + arguments[0], arguments[1] || {});
} }
return that; return that;
@ -4339,7 +4338,7 @@ requires
self.options.type == 'image' && self.$menu.addClass('OxRight'); self.options.type == 'image' && self.$menu.addClass('OxRight');
function clickMenu(event, data) { function clickMenu(event, data) {
//Ox.print('%% clickMenu') that.triggerEvent('click', data);
} }
function changeMenu(event, data) { function changeMenu(event, data) {
@ -6107,6 +6106,8 @@ requires
ids: [], ids: [],
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_backspace: deleteItems,
key_delete: deleteItems,
key_end: scrollToFirst, key_end: scrollToFirst,
key_enter: open, key_enter: open,
key_home: scrollToLast, key_home: scrollToLast,
@ -6284,6 +6285,13 @@ requires
return $page; return $page;
} }
function deleteItems() {
var ids = getSelectedIds();
ids.length && that.triggerEvent('delete', {
ids: ids
});
}
function deselect(pos) { function deselect(pos) {
if (isSelected(pos)) { if (isSelected(pos)) {
self.selected.splice(self.selected.indexOf(pos), 1); self.selected.splice(self.selected.indexOf(pos), 1);
@ -6594,6 +6602,7 @@ requires
self.$pages[page] = new Ox.ListPage().css(getPageCSS(page)); self.$pages[page] = new Ox.ListPage().css(getPageCSS(page));
$.each(result.data.items, function(i, v) { $.each(result.data.items, function(i, v) {
var pos = offset + i; var pos = offset + i;
self.ids[pos] = v[self.options.unique]; // fixme: why not use self.$items[pos].options('id')?
self.$items[pos] = new Ox.ListItem({ self.$items[pos] = new Ox.ListItem({
construct: self.options.construct, construct: self.options.construct,
data: v, data: v,
@ -6602,17 +6611,14 @@ requires
position: pos, position: pos,
unique: self.options.unique unique: self.options.unique
}); });
self.ids[pos] = v[self.options.unique]; // fixme: why not use self.$items[pos].options('id')? isSelected(pos) && self.$items[pos].addClass('OxSelected');
if (isSelected(pos)) {
//Ox.print('pos', pos, 'isSelected')
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();
$emptyPage.remove(); $emptyPage.remove();
self.$pages[page].appendTo(that.$content); self.$pages[page].appendTo(that.$content);
!Ox.isUndefined(callback) && callback(); !Ox.isUndefined(callback) && callback(); // fixme: callback necessary? why not bind to event?
that.triggerEvent('load');
})); }));
} else { } else {
//Ox.print('loading a page from cache, this should probably not happen -----------') //Ox.print('loading a page from cache, this should probably not happen -----------')
@ -6927,6 +6933,11 @@ requires
self.$items[pos].removeClass('OxSelected'); self.$items[pos].removeClass('OxSelected');
} }
}); });
} else {
ids.forEach(function(id, i) {
var pos = getPositionById(id);
select(pos);
});
} }
// fixme: implement the rest of this // fixme: implement the rest of this
/* /*
@ -7004,7 +7015,7 @@ requires
clear(); clear();
self.requests.push(self.options.request({}, function(result) { self.requests.push(self.options.request({}, function(result) {
var keys = {}; var keys = {};
that.triggerEvent('load', 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' ?
self.pageLengthByRowLength[self.rowLength] : self.pageLengthByRowLength[self.rowLength] :
@ -7076,7 +7087,12 @@ requires
return that; return that;
}; };
that.reload = function() { that.reloadList = function() {
updateQuery();
return that;
}
that.reloadPages = function() {
//Ox.print('---------------- list reload, page', self.page) //Ox.print('---------------- list reload, page', self.page)
var page = self.page; var page = self.page;
clear(); clear();
@ -7353,7 +7369,7 @@ requires
}) })
.bindEvent({ .bindEvent({
edit: function(event, data) { edit: function(event, data) {
editCell(data.id, data.key, data.item, data.cell); that.editCell(data.id, data.key);
}, },
select: function(event, data) { select: function(event, data) {
self.options.selected = data.ids; self.options.selected = data.ids;
@ -7388,7 +7404,7 @@ requires
return v.id; return v.id;
}) })
}); });
that.$body.reload(); that.$body.reloadPages();
} }
function changeColumns(event, data) { function changeColumns(event, data) {
@ -7598,54 +7614,6 @@ requires
that.$body.clearCache(); that.$body.clearCache();
} }
function editCell(id, key) {
//Ox.print('editCell')
var $item = getItem(id),
$cell = getCell(id, key),
$input,
html = $cell.html(),
index = getColumnIndexById(key),
column = self.options.columns[index],
width = column.width;
$cell.empty()
.addClass('OxEdit')
.css({
width: width + 'px'
});
$input = Ox.Input({
autovalidate: column.input.autovalidate,
style: 'square',
value: html,
width: width
})
.bind({
mousedown: function(e) {
// keep mousedown from reaching list
e.stopPropagation();
}
})
.bindEvent({
blur: submit,
})
.appendTo($cell)
.focus();
function submit() {
var value = $input.value();
//$input.loseFocus().remove();
// fixme: leaky, inputs remain in focus stack
$cell.removeClass('OxEdit')
.css({
width: (width - 8) + 'px'
})
.html(value)
that.triggerEvent('submit', {
id: id,
key: key,
value: value
});
}
}
function getCell(id, key) { function getCell(id, key) {
//Ox.print('getCell', id, key) //Ox.print('getCell', id, key)
var $item = getItem(id); var $item = getItem(id);
@ -7800,8 +7768,60 @@ requires
} }
}; };
that.closePreview = function() { // fixme: doesn't work, doesn't return that
that.$body.closePreview(); that.closePreview = that.$body.closePreview;
that.editCell = function(id, key) {
//Ox.print('editCell')
var $item = getItem(id),
$cell = getCell(id, key),
$input,
html = $cell.html(),
index = getColumnIndexById(key),
column = self.options.columns[index],
width = column.width;
$cell.empty()
.addClass('OxEdit')
.css({
width: width + 'px'
});
$input = Ox.Input({
autovalidate: column.input.autovalidate,
style: 'square',
value: html,
width: width
})
.bind({
mousedown: function(e) {
// keep mousedown from reaching list
e.stopPropagation();
}
})
.bindEvent({
blur: submit,
})
.appendTo($cell)
.focus();
function submit() {
var value = $input.value();
//$input.loseFocus().remove();
// fixme: leaky, inputs remain in focus stack
$cell.removeClass('OxEdit')
.css({
width: (width - 8) + 'px'
})
.html(value)
that.triggerEvent('submit', {
id: id,
key: key,
value: value
});
}
}
that.reloadList = function() {
that.$body.reloadList();
return that;
}; };
that.resizeColumn = function(id, width) { that.resizeColumn = function(id, width) {
@ -9412,7 +9432,6 @@ requires
.dblclick(dblclickTitlebar) .dblclick(dblclickTitlebar)
.appendTo(that), .appendTo(that),
$switch = new Ox.Button({ $switch = new Ox.Button({
id: self.options.id + 'Switch',
style: 'symbol', style: 'symbol',
title: title, title: title,
type: 'image', type: 'image',
@ -9425,13 +9444,13 @@ requires
.appendTo($titlebar); .appendTo($titlebar);
if (self.options.menu.length) { if (self.options.menu.length) {
that.$menu = new Ox.Select({ that.$menu = new Ox.Select({
id: self.options.id + 'Menu',
items: self.options.menu, items: self.options.menu,
max: 0, max: 0,
min: 0, min: 0,
selectable: false,
type: 'image' type: 'image'
}) })
.bindEvent('click', clickMenu) .bindEvent({click: clickMenu})
.appendTo($titlebar) .appendTo($titlebar)
} }
that.$content = new Ox.Element() that.$content = new Ox.Element()
@ -9444,8 +9463,8 @@ requires
marginTop: -that.$content.height() + 'px' marginTop: -that.$content.height() + 'px'
}); });
} }
function clickMenu() { function clickMenu(event, data) {
that.triggerEvent('click', data);
} }
function dblclickTitlebar(e) { function dblclickTitlebar(e) {
if (!$(e.target).hasClass('OxButton')) { if (!$(e.target).hasClass('OxButton')) {