Attachments as components

This includes:

- Remove duplicated template code from all sections with attachments.
- Remove duplicated resource loading code from all controllers with attachments.
- Minor improvements on tg-check-permissions directive.

NOTE: obviously is preferable some review and test before merge.