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 {
cancel: function() {
var index;
if (arguments.length == 0) {
requests = {};
} else if (Ox.isFunction(arguments[0])) {
@ -1007,11 +1006,11 @@ requires
*/
if (arguments.length == 1) {
$.each(arguments[0], function(event, fn) {
//Ox.print(that.id, 'bind', event);
// Ox.print(that.id, 'bind', event);
self.$eventHandler.bind('ox_' + event, fn);
});
} else {
//Ox.print(that.id, 'bind', arguments[0]);
// Ox.print(that.id, 'bind', arguments[0]);
self.$eventHandler.bind('ox_' + arguments[0], arguments[1]);
}
return that;
@ -1094,11 +1093,11 @@ requires
*/
if (Ox.isObject(arguments[0])) {
$.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);
});
} 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] || {});
}
return that;
@ -1111,11 +1110,11 @@ requires
*/
if (arguments.length == 1) {
$.each(arguments[0], function(event, fn) {
//Ox.print(that.id, 'unbind', arguments[0]);
// Ox.print(that.id, 'unbind', arguments[0]);
self.$eventHandler.unbind('ox_' + event, fn);
});
} else {
//Ox.print(that.id, 'unbind', arguments[0]);
// Ox.print(that.id, 'unbind', arguments[0]);
self.$eventHandler.unbind('ox_' + arguments[0], arguments[1]);
}
return that;
@ -4339,7 +4338,7 @@ requires
self.options.type == 'image' && self.$menu.addClass('OxRight');
function clickMenu(event, data) {
//Ox.print('%% clickMenu')
that.triggerEvent('click', data);
}
function changeMenu(event, data) {
@ -6107,6 +6106,8 @@ requires
ids: [],
itemMargin: self.options.type == 'text' ? 0 : 8, // 2 x 4 px margin ... fixme: the 2x should be computed later
keyboardEvents: {
key_backspace: deleteItems,
key_delete: deleteItems,
key_end: scrollToFirst,
key_enter: open,
key_home: scrollToLast,
@ -6284,6 +6285,13 @@ requires
return $page;
}
function deleteItems() {
var ids = getSelectedIds();
ids.length && that.triggerEvent('delete', {
ids: ids
});
}
function deselect(pos) {
if (isSelected(pos)) {
self.selected.splice(self.selected.indexOf(pos), 1);
@ -6594,6 +6602,7 @@ requires
self.$pages[page] = new Ox.ListPage().css(getPageCSS(page));
$.each(result.data.items, function(i, v) {
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({
construct: self.options.construct,
data: v,
@ -6602,17 +6611,14 @@ requires
position: pos,
unique: self.options.unique
});
self.ids[pos] = v[self.options.unique]; // fixme: why not use self.$items[pos].options('id')?
if (isSelected(pos)) {
//Ox.print('pos', pos, 'isSelected')
self.$items[pos].addClass('OxSelected');
}
isSelected(pos) && self.$items[pos].addClass('OxSelected');
self.$items[pos].appendTo(self.$pages[page]);
});
self.options.type == 'text' && page == 0 && fillFirstPage();
$emptyPage.remove();
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 {
//Ox.print('loading a page from cache, this should probably not happen -----------')
@ -6927,6 +6933,11 @@ requires
self.$items[pos].removeClass('OxSelected');
}
});
} else {
ids.forEach(function(id, i) {
var pos = getPositionById(id);
select(pos);
});
}
// fixme: implement the rest of this
/*
@ -7004,7 +7015,7 @@ requires
clear();
self.requests.push(self.options.request({}, function(result) {
var keys = {};
that.triggerEvent('load', result.data);
that.triggerEvent('init', result.data);
self.rowLength = getRowLength();
self.pageLength = self.options.orientation == 'both' ?
self.pageLengthByRowLength[self.rowLength] :
@ -7076,7 +7087,12 @@ requires
return that;
};
that.reload = function() {
that.reloadList = function() {
updateQuery();
return that;
}
that.reloadPages = function() {
//Ox.print('---------------- list reload, page', self.page)
var page = self.page;
clear();
@ -7353,7 +7369,7 @@ requires
})
.bindEvent({
edit: function(event, data) {
editCell(data.id, data.key, data.item, data.cell);
that.editCell(data.id, data.key);
},
select: function(event, data) {
self.options.selected = data.ids;
@ -7388,7 +7404,7 @@ requires
return v.id;
})
});
that.$body.reload();
that.$body.reloadPages();
}
function changeColumns(event, data) {
@ -7598,54 +7614,6 @@ requires
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) {
//Ox.print('getCell', id, key)
var $item = getItem(id);
@ -7800,8 +7768,60 @@ requires
}
};
that.closePreview = function() {
that.$body.closePreview();
// fixme: doesn't work, doesn't return that
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) {
@ -9412,7 +9432,6 @@ requires
.dblclick(dblclickTitlebar)
.appendTo(that),
$switch = new Ox.Button({
id: self.options.id + 'Switch',
style: 'symbol',
title: title,
type: 'image',
@ -9425,13 +9444,13 @@ requires
.appendTo($titlebar);
if (self.options.menu.length) {
that.$menu = new Ox.Select({
id: self.options.id + 'Menu',
items: self.options.menu,
max: 0,
min: 0,
selectable: false,
type: 'image'
})
.bindEvent('click', clickMenu)
.bindEvent({click: clickMenu})
.appendTo($titlebar)
}
that.$content = new Ox.Element()
@ -9444,8 +9463,8 @@ requires
marginTop: -that.$content.height() + 'px'
});
}
function clickMenu() {
function clickMenu(event, data) {
that.triggerEvent('click', data);
}
function dblclickTitlebar(e) {
if (!$(e.target).hasClass('OxButton')) {