Comments (9)

I think there are two ways we could go with this.
1. We bring up a confirmation box when the user attempts to close the window/tab, go to a different page, press the back arrow, etc. that prompts something along the lines of "Are you sure you want to close this page?" with a OK/Cancel prompt.
2. We could also bring up a prompt along the lines of "Would you like to save before you leave the page?" with a No/Yes prompt. Yes would do the same thing as clicking on the Save Button except leaves the page/closes the tab/etc.

The dialogue should only appear if there are unsaved changes. I frequently open trials in the editor to read the script or check cross-examinations, without editing them. Having to confirm that I don't want to save when I never changed a thing would be a nuisance.

In that light, Option 2 makes far more sense. If unsaved changes trigger the message, than the message should be about unsaved changes.

Currently, the editor has no way of knowing if any change was performed on the trial or not.

This is one of the applications I originally planned for the BufferWrapper object though : if the BufferWrapper implementation is reliable and fast enough, the trial_data variable exposed throughout the editor could be wrapped into a buffer wrapper at load time, and when closing the tab we could quickly check the contents of this buffer's diff. If it has significant changes, then we could show the message about unsaved changes.

Oh, I didn't really pay attention to what I was writing there.
Yes, the warning probably should be displayed for any change - it's the user's responsibility to know whether it's trivial (and should be discarded) or it's significant.

But the problem of being able to detect whether any change occured remains :-)

The != operator will not check that the contents of the objects are the same, it will check if the two variables point to exactly the same object in memory (which would always be false). If we wanted to to a full object content comparison, we would use the objCompare function I've written in objects.js

A comparison of the whole object contents, especially on big trials, could take long, inducing a lag whenever we want to close the tab.

The main feature of the BufferWrapper is to actually store a list of all changes performed to the object, the diff. So the test would rather be to check whether trial_data.__diff contains any change. Something like: