Editor ReadOnly Mode

I have been looking for this feature for a while now. Something similar to the Readonly role.
In my application I have a lot of entities that cannot be modified after they reached a certain “status”.
In CUBA 6 I just disabled the the fieldgroups, and all the detail(nested) table actions, which is a lot of work, because you also have disable the detail table edit screens.

Here is one simple universal solution for CUBA7:

Screen XML with standard window actions and one additional button: closeNoCommitBtn

...
<hbox id="editActions" spacing="true">
	<button id="windowCommitAndCloseBtn" action="windowCommitAndClose"/>
	<button id="windowCommitBtn" action="windowCommit"/>
	<button id="windowCloseBtn" action="windowClose"/>
	<button id="closeNoCommitBtn" caption="Close" icon="font-icon:CLOSE" invoke="onCloseNoCommitBtnClick"/>
</hbox>
...

Controller

...
@Inject
private Button windowCommitBtn, windowCloseBtn, windowCommitAndCloseBtn, closeNoCommitBtn;

@Subscribe
private void onBeforeShow(BeforeShowEvent event) {
	this.disableEdit(this.isUpdateAllowed());
}

/**
 * Close the window without changes
 */
@Subscribe
public void onCloseNoCommitBtnClick() {
	closeWithDiscard();
}

/**
 * Override preventUnsavedChanges. This prevents the framweork from asking to save changes.
 * This is necessary because, if the user uses the close X of the tab, the framework asks to save changes.
 * @param event
 */
@Override
protected void preventUnsavedChanges(BeforeCloseEvent event) {
	if (this.isUpdateAllowed()) { // Some function to check entity fields if update is allowed
		super.preventUnsavedChanges(event); // Call super method to work like normal
	}
	// else do nothing
}

/**
 * Enable disable edit based on the status
 */
private void disableEdit(boolean updateAllowed) {
	if (!updateAllowed) {
		// Hide the standard window buttons
		windowCommitAndCloseBtn.setVisible(false);
		windowCommitBtn.setVisible(false);
		windowCloseBtn.setVisible(false);
		// Disable the actions to prevent user from using shortcut CTRL+ENTER to save.
		this.getWindow().getAction(WINDOW_COMMIT_AND_CLOSE).setEnabled(false);
		this.getWindow().getAction(WINDOW_COMMIT).setEnabled(false);
	}
	// Disable/enable close without commit button
	closeNoCommitBtn.setVisible(!updateAllowed); // Only show this button when update is not allowed
}

I was looking into the code of preventUnsavedChanges and it calls a function isCheckForUnsavedChanges(). It would be nice if this was a setting you could turn on/off in the editor screen.
It would be even nicer if ReadOnly was a standard feature you could turn on for Editor Screens.

The reason I can’t do this wit security constraints, is there are still some actions you can do with the entity that are invoked through a button that does make ‘controlled’ changes to the entity.

Anyone have any other ideas?

Renato

1 Like

I agree, that having ReadOnly mode for editor screen out-of-the-box would be a good thing.

Comparing to your solution, I would like to have not only actions hidden and disabled, but also controls (fields, etc…) disabled.

Seems like an approach in MasterDetailScreen can be reused. I’ll try and post here later

Hi,

apparently this is on the roadmap for CUBA 7.2 as documented in this issue: https://github.com/cuba-platform/cuba/issues/2270

Implementation seems to be in progress / done already, so there is a chance this is covered in the next minor version.

Bye
Mario

1 Like

Looking forward to this feature !