Refactor header JavaScript

The chaining was a bit hard to follow & made it hard to "hook into" a specific
aspect (e.g. manually re-submit header content after an edit conflict)

Meanwhile also added fail() handler to show error if fetching content failed.
Also made outputting the errors use base's showError method.

Change-Id: I75a116f852250ab598bd86a56bfcb84d6f3e0b4f
Merge "Refactor header JavaScript"