Fixes for relate widget, moved JS to separate file