Make adding pic to gallery async
Fine tune relationship between gallery and pic

First, only display images NOT in galleries. In this situation, an image can only be related to one gallery, so adjust the relationship. It appears you can delete a pic's Gallery and yet it remains part of the gallery's collection. Not sure if that a JPA misconfiguration, but the javascript isn't responsible for that.

After this is working, may want to explore generating the tables purely using REST calls, i.e. dynamically.