Fix removing (delete) a row from nextmatch

- Fix broken destroy callback
- Fix caching & actions to be removed
- Fix always removing the last row also
- Fix indexing so arrow keys work over sparse indexMap
This commit is contained in:
Nathan Gray 2014-01-17 17:57:59 +00:00
parent 0c2d8f87b9
commit 344a63b37c
3 changed files with 39 additions and 6 deletions

View File

@ -568,7 +568,10 @@ var et2_dataview_controller = Class.extend({
// If there's no data, stop
if(typeof _data == "undefined" || _data == null)
{
this._destroyCallback();
this.self._destroyCallback.call(
this,
this.entry.row
);
return;
}
@ -632,6 +635,7 @@ var et2_dataview_controller = Class.extend({
if (this.entry.row)
{
var tr = this.entry.row.getDOMNode();
this.self._selectionMgr._updateState(this.entry.uid, EGW_AO_STATE_NORMAL)
this.self._selectionMgr.unregisterRow(this.entry.uid, tr);
}

View File

@ -152,6 +152,7 @@ var et2_dataview_selectionManager = Class.extend(
if (!_noDelete
&& this._registeredRows[_uid].state === EGW_AO_STATE_NORMAL)
{
delete this._indexMap[this._registeredRows[_uid].idx];
delete this._registeredRows[_uid];
}
@ -326,8 +327,16 @@ var et2_dataview_selectionManager = Class.extend(
}
function getElementRelatively (_step) {
return getIndexAO(Math.max(0,
Math.min(self._total - 1, _entry.idx + _step)));
var count = self._total;
var element = null;
var idx = _entry.idx;
while(element == null && count > 0 && idx <= self._total)
{
count--;
element = getIndexAO(Math.max(0,
Math.min(self._total - 1, idx += _step)));
}
return element;
};
_entry.ao.getPrevious = function (_step) {

View File

@ -456,14 +456,34 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
}
break;
case "delete":
// Record current & next index
var entry = this.controller._selectionMgr._getRegisteredRowsEntry(uid);
var next = entry.ao.getNext(1);
if(next == null || !next.id)
{
// No next, select previous
next = entry.ao.getPrevious(1);
}
// Select next row
if(next && next.id)
{
this.controller._selectionMgr._handleSelect(next.id);
}
// Blank the row
this.egw().dataStoreUID(uid,null);
// Stop caring about this ID
this.egw().dataUnregisterUID(uid);
// Update the count
this.options.settings.total -= 1;
// This triggers an invalidate, which may update the grid in needed
this.dataview.grid.setTotalCount(this.options.settings.total);
// This removes the last row (in addition), doesn't matter if that wasn't the right one,
// then triggers an invalidate, which may update the grid
// this.dataview.grid.setTotalCount(this.options.settings.total);
// Update directly instead
this.dataview.grid._total -= this.options.settings.total;
this.controller._selectionMgr._total = this.options.settings.total;
this.header.count_total.text(this.options.settings.total+"");
break;
case "edit":
case "add":
@ -474,7 +494,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
}
}
// Trigger an event so app code can act on it
$j(this).triggerHandler("refresh",[this]);
$j(this).triggerHandler("refresh",[this,_row_ids,_type]);
},
/**