Refactor dashboard js

Been a while since I've found time to contribute but thought I'd dip in! Just shrunk these dashboard functions a little and added a more generic one for future use if required.