[TASK] Factorize similar code in dashboard.js

Change-Id: Ibc90dea92af2c4cde5c578391863084aa9eafb74
Related: #57445
Reviewed-on: https://review.typo3.org/29029
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers