fix a bug where clicks and changes in a submenu would not fire on the parent menu

This commit is contained in:
rlx 2011-01-11 15:00:32 +00:00
parent e8be24d20e
commit 9da654ad08

View file

@ -6645,7 +6645,8 @@ requires
var $cell, var $cell,
$item = findItem(e), $item = findItem(e),
pos, pos,
editTimeout = false; clickable, editable,
clickTimeout = false;
selectTimeout = false; selectTimeout = false;
that.gainFocus(); that.gainFocus();
if ($item) { if ($item) {
@ -6670,11 +6671,15 @@ requires
selectTimeout = true; selectTimeout = true;
} else if (self.options.type == 'text') { } else if (self.options.type == 'text') {
$cell = findCell(e); $cell = findCell(e);
if ($cell && $cell.hasClass('OxEditable') && !$cell.hasClass('OxEdit')) { if ($cell) {
clickable = $cell.hasClass('OxClickable');
editable = $cell.hasClass('OxEditable') && !$cell.hasClass('OxEdit');
if (clickable || editable) {
if (self.options.sortable) { if (self.options.sortable) {
editTimeout = true; clickTimeout = true;
} else { } else {
triggerEditEvent($item, $cell); triggerCellEvent($item, $cell, clickable ? 'click' : 'edit');
}
} }
} }
} }
@ -6695,8 +6700,8 @@ requires
if (self.dragTimeout) { if (self.dragTimeout) {
clearTimeout(self.dragTimeout); clearTimeout(self.dragTimeout);
self.dragTimeout = 0; self.dragTimeout = 0;
if (editTimeout) { if (clickTimeout) {
triggerEditEvent($item, $cell); triggerCellEvent($item, $cell, clickable ? 'click' : 'edit');
} }
} }
}); });
@ -6932,8 +6937,9 @@ requires
} }
} }
function triggerEditEvent($item, $cell) { function triggerCellEvent($item, $cell, event) {
that.triggerEvent('edit', { // event can be 'click' or 'edit'
that.triggerEvent(event, {
id: $item.data('id'), id: $item.data('id'),
key: $cell.attr('class').split('OxColumn')[1].split(' ')[0].toLowerCase() key: $cell.attr('class').split('OxColumn')[1].split(' ')[0].toLowerCase()
}); });
@ -7051,6 +7057,7 @@ requires
that.closePreview = function() { that.closePreview = function() {
self.preview = false; self.preview = false;
return that;
}; };
that.reload = function() { that.reload = function() {
@ -7065,6 +7072,15 @@ requires
that.scrollToSelection = function() { that.scrollToSelection = function() {
self.selected.length && scrollToPosition(self.selected[0]); self.selected.length && scrollToPosition(self.selected[0]);
return that;
};
that.setId = function(oldId, newId) {
var index = self.ids.indexOf(oldId);
if (index > -1) {
self.ids[index] = newId;
}
return that;
}; };
that.size = function() { // fixme: not a good function name that.size = function() { // fixme: not a good function name
@ -7099,6 +7115,7 @@ requires
emptyFirstPage(); emptyFirstPage();
fillFirstPage(); fillFirstPage();
} }
return that;
} }
that.sortList = function(key, operator) { that.sortList = function(key, operator) {
@ -7113,6 +7130,10 @@ requires
return that; return that;
} }
that.value = function(id, key, value) {
};
return that; return that;
}; };
@ -7150,7 +7171,6 @@ requires
.addClass('OxItem') .addClass('OxItem')
.attr({ .attr({
draggable: self.options.draggable draggable: self.options.draggable
//id: self.options.id.replace(/./g, '_') // fixme: dots are not the only problem
}) })
.data({ .data({
id: self.options.id, id: self.options.id,
@ -7460,6 +7480,7 @@ requires
var $cell = $('<div>') var $cell = $('<div>')
.addClass( .addClass(
'OxCell OxColumn' + Ox.toTitleCase(v.id) + 'OxCell OxColumn' + Ox.toTitleCase(v.id) +
(v.clickable ? ' OxClickable' : '') +
(v.editable ? ' OxEditable' : '') (v.editable ? ' OxEditable' : '')
) )
.css({ .css({
@ -7579,6 +7600,7 @@ requires
} }
function getCell(id, key) { function getCell(id, key) {
Ox.print('getCell', id, key)
var $item = getItem(id); var $item = getItem(id);
return $($item.find('.OxCell.OxColumn' + Ox.toTitleCase(key))[0]); return $($item.find('.OxCell.OxColumn' + Ox.toTitleCase(key))[0]);
} }
@ -7592,6 +7614,7 @@ requires
} }
function getItem(id) { function getItem(id) {
Ox.print('getItem', id)
var $item = null; var $item = null;
$.each(that.find('.OxItem'), function(i, v) { $.each(that.find('.OxItem'), function(i, v) {
$v = $(v); $v = $(v);
@ -7599,7 +7622,7 @@ requires
$item = $v; $item = $v;
return false; return false;
} }
}) });
return $item; return $item;
} }
@ -7766,9 +7789,17 @@ requires
}; };
that.value = function(id, key, value) { that.value = function(id, key, value) {
// fixme: make this accept id, {k: v, ...}
var $item = getItem(id),
$cell = getCell(id, key);
if (Ox.isUndefined(value)) { if (Ox.isUndefined(value)) {
return $cell.html();
} else { } else {
$cell && $cell.html(value);
if (self.options.columns[getColumnIndexById(key)].unique) {
that.$body.setId($item.data('id'), value);
$item.data({id: value});
}
return that; return that;
} }
} }
@ -8608,6 +8639,7 @@ requires
function clickItem(position) { function clickItem(position) {
var item = that.items[position], var item = that.items[position],
menu = self.options.mainmenu || self.options.parent || that,
toggled; toggled;
that.hideMenu(); that.hideMenu();
if (!item.options('items').length) { if (!item.options('items').length) {
@ -8624,7 +8656,7 @@ requires
that.items[pos].toggleChecked(); that.items[pos].toggleChecked();
}); });
Ox.print('--triggering change event--'); Ox.print('--triggering change event--');
(self.options.mainmenu || that).triggerEvent('change', { menu.triggerEvent('change', {
id: item.options('group'), id: item.options('group'),
checked: $.map(self.optionGroups[item.options('group')].checked(), function(v, i) { checked: $.map(self.optionGroups[item.options('group')].checked(), function(v, i) {
return { return {
@ -8636,14 +8668,14 @@ requires
} }
} else { } else {
item.toggleChecked(); item.toggleChecked();
(self.options.mainmenu || that).triggerEvent('change', { menu.triggerEvent('change', {
checked: item.options('checked'), checked: item.options('checked'),
id: item.options('id'), id: item.options('id'),
title: Ox.stripTags(item.options('title')[0]) title: Ox.stripTags(item.options('title')[0])
}); });
} }
} else { } else {
(self.options.mainmenu || that).triggerEvent('click', { menu.triggerEvent('click', {
id: item.options('id'), id: item.options('id'),
title: Ox.stripTags(item.options('title')[0]) title: Ox.stripTags(item.options('title')[0])
}); });