[modal] Use AjaxRequestTarget#prependJavaScript() when hiding the modal to do it as early as possible.

This helps in case the modal is repainted with target#add(modal) by the application