PDA

View Full Version : [ENH] RowEditor should follow StartEdit with either CancelEdit or AfterEdit



Curt Arnold
19 Jun 2009, 11:19 AM
I've been using RowEditor in the milestones and had to do a very hacky extension of RowEditor to get notification that the user has closed the row editor when they either pressed Cancel or pressed Save with no changes. I've looked at the code in M3 and the situation does not look changed.

In my app, I have a button to add a new record with default values to the grid and calls RowEditor.startEditing to invoke the editor. If the user does not make any changes or presses the Cancel button, I need to remove the new record from the grid.

p.s. stopEditing(true) can trigger a call to stopEditing(false), so you have to be careful to only send CancelEdit when the RowEditor is visible.

I did my hack as an extension, but something like the following changes would address the issue in the base implementation:


/grid
$ diff -c4 RowEditor.java RowEditor.hack
*** RowEditor.java Thu Jun 11 17:58:58 2009
--- RowEditor.hack Fri Jun 19 14:14:08 2009
***************
*** 240,247 ****
--- 240,248 ----
return;
}
if (!saveChanges || !isValid()) {
hide();
+ fireEvent(Events.CancelEdit, new RowEditorEvent(this, rowIndex));
return;
}

Map<String, Object> data = new FastMap<Object>();
***************
*** 274,281 ****
--- 275,284 ----
record.endEdit();
ree.setRecord(record);
fireEvent(Events.AfterEdit, ree);

+ } else {
+ fireEvent(Events.CancelEdit, ree);
}
hide();
}

Curt Arnold
19 Jun 2009, 11:30 AM
Okay, that is probably a start, but there are other issues.

In my case, I wanted to discard the temporary record if the user made no changes or pressed cancel. Other case would be if you wanted to save the record to the database when the user pressed save. In the current case, the user would have to make at least one modification or you would not get notified that they completed editing.

It would be helpful if there was a configuration option to disable the Save button until there were changes. If my first case, you would set that to true, in the second case to false (likely the default).

Also, it would be nice to have an extension point to add buttons in addition to Save and Cancel. Currently, those are added in onRender and no available extension point.

Curt Arnold
19 Jun 2009, 11:57 AM
Actually, RowEditor in M2 only sends BeforeEdit, doesn't send StartEdit.