Announcement

Collapse
No announcement yet.

Custom JS in Module or in Custom?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom JS in Module or in Custom?

    I want to modify the Record's detail.js. I've done this before in custom, but can I do it in my own module? I would like for it to affect all detail views.

  • #2
    Custom is the only namespace that takes priority over everything else.

    Espo looks at the clientDefs files to determine which view to use for rendering the entity or collection.

    If you write your own detail.js view inside a module (namespace), you will need to modify all the entities clientDefs json files where you want to call your custom detail.js view.

    For example, if you create a view client/modules/my-module/src/views/record/detail.js and you want the entity "Lead" to be rendered in detail display, using this view, you would have to create a custom clientDefs json file for "Lead" at application/Espo/Modules/MyModule/Resources/metadata/clientDefs/Lead.json and specify there:
    Code:
    {    
        "recordViews" : {
            "detail": "my-module:views/record/detail"
        }
    }

    Comment


    • #3
      OK, thank you, this makes sense. Next question... If I am planning an Extension, can I use a combination of a Module and Custom? Much of what I am using I want to apply to new Entities as they get created, so I would need to put that in Custom path.

      Comment


      • #4
        Yes you can have Modules and Custom.

        I prefer to use Modules in our application because it makes it a lot easier to debug or improve features and I use Custom only for development while testing a new feature and also because everything that you customize using the Admin GUI will be done under the Custom namespace.

        A good example of using a Module to segment by functionality is the free Real Estate extension, you can download it and study the code for guidance.

        In regards of applying a "custom" or "module" view for rendering an Entity you will always have to specify such custom / module view in a new target entity clientDefs created under the Custom or Module namespace, otherwise Espo will always apply the default view in the core code.

        I don't know of any way to make a specific view the default for all entities other than modifying the core code but that would force you to re-code after any updates.
        Last edited by telecastg; 02-04-2021, 06:41 PM.

        Comment


        • #5
          Excellent advice. Module it is.
          Last edited by planetrocke; 02-05-2021, 01:46 AM.

          Comment


          • telecastg
            telecastg commented
            Editing a comment
            Glad to be able to help you

          • telecastg
            telecastg commented
            Editing a comment
            One added advantage of using modules is that you can package your modules as extensions that can be installed or uninstalled. (like the Real Estate extension)

            What we do here, for example, is to work in a local instance (xammp) and use the GUI to create entities or links in the Custom namespace, then when we are satisfied with the results, we move everything to a "Module", pack it as an extension and install in the Espo production site.

            This way we can make changes to one Module locally and then pack a new version to install in the production site, keeping if we want the previous version in case something goes wrong, and if we ever need to do a whole re-installation (it happens !) all we need to do is to download a fresh instance of Espo and then add all our module/extensions.
        Working...
        X