Refactor js

**Resolves issues #777 and #780.**

---

Rewriting our js to be more readable and less hacky.



I may be slightly wrong about this. The jQuery docs are thorough but I find their explanations confusing, and the poor method names they've chosen make it somewhat difficult to reason about them.

The point is that I removed the `$.when()` around the `ajax_form_submit()` call and things seemed to work fine.