Create custom code on page load

I have Data source with name of Module. it has Module Title and details.

one or more Module assigned to Each client.

in App, I want to generate Module Screen in which need to display all the Modules from Module data source. Module may be display in button component. On Module screen page load I want to generate custom code with below points.

  1. Java script on page load (Module screen page) , javascript function should run the loop (until Module Data source have data) which generate buttons and add that buttons on screen.
  2. in that loop I require one “if” condition which will check that logged in User has assign the modules, if yes the the button should be enabled and else button should be disabled.
  3. click on enable button it should open Document screen, it display only that document which is assigned to clicked module. (for example I have Document Data source, which has multiple document and one or more document assigned to one module, document 1, document 2 which i have assigned to module 1 at a time of creating document. , so click on module 1 button on module screen, it opens document screen which will only display document1 and document 2)
  4. on disabled button click Just need to display only popup message.

I know disabled button do not have click even to I preferred to do Gary colour to it.