Tweak dirty-checking in phase 1

Rather than just keeping a dirty bit, keep two states for each class
-- the UI state and the saved state. Classes are dirty if the two
states differ; the saved state is set only when an update succeeds.

This fixes some correctness issues with the old system where it was
possible to leave the page while an ajax call was in progress without
it complaining at you for not having saved.