There are lots of different ways you could approach this (e.g. customising the viewLocator.convertModuleIdToViewId
method comes to mind), but I think what you've got is OK provided you're not repeating too much code between the "same" view/viewModel for each different role.
The only thing I don't like about it is that you'll end up with "hundreds" of files named "index.js" and "index.html" which makes it hard to find if you're using R#.
In order to get around the "harder to maintain as a group" problem, you could fairly easily refactor common code out into an "All" role, and then require it in for specific roles. So something like:
app/roles/all/
- building/
- buildingCore.js
- offices/
- officesCore.js
Then for buildingCore.js
(obviously I'm just making up the methods up here):
define([], function() {
var someCommonBuildingFunction = function() {
// whatever
}
return {
doSomething: someCommonBuildingFunction
}
});
And then in (say) admin/building/building.js
:
define([
"roles/all/buildingCore"
],
function(buildingCore) {
var viewModel = {
activate: function() {
buildingCore.doSomething()
}
}
return viewModel;
});