Announcement

Collapse
No announcement yet.

Extend Views Setup Handlers add (entity-manager/record/edit)

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

  • Extend Views Setup Handlers add (entity-manager/record/edit)

    Currently using https://docs.espocrm.com/development...anager-params/ is very useful, however there is no way to extend the entity-manager/record/edit view so that one can show/hide extended parameters in the entity manager edit view based on certain conditions. e.g i have two params to add to the entity manager (bool: Archived) and (varchar: source)
    Now i need to show the source params only if the archived is true. this is a basic example but what i am working on has more conditions and sometimes even need to check state of existing parameters e.g stars / kanbanViewMode etc

    Is there any change to add this to the View Setup Handlers framework so we could control the behavior of those params.

    Thanks
    Rabii
    Web Dev | Freelancer

  • #2
    Chance is very low. We may end up with view setup handler for all views. In fact, view-setup-handlers do not differ much from monkey patching.

    Comment


    • #3
      I am just trying to avoid monkey patching and wanted to stick to official way to do things

      I hope there will be an official way in the future

      Thanks yuri
      Rabii
      Web Dev | Freelancer

      Comment


      • #4
        Technically, monkey patching is almost the same as view-setup-handler. The main difference is that I know that there're view-setup-handlers supported in a particular view and I'm more reluctant to change internals of the view. It's a burden for me when a view supports view-setup-handlers. Do not expect them to be applied anywhere. It's more of a hack. Adding view setup handlers anywhere would be a big mistake for the product. Either customizations will constantly break after upgrade or we do not touch code to prevent "official-way" customizations from breaking.

        I have already written about this issue before.
        Last edited by yuri; 09-27-2024, 12:17 PM.

        Comment


        • #5
          If you monkey patch a "setup" method and access only 'public' members of the view, that would be an equivalent of a using view-setup-handler.
          Last edited by yuri; 09-27-2024, 12:39 PM.

          Comment


          • #6
            I understand, Thanks for your time and explanation, so based on this conversation here https://github.com/espocrm/espocrm/i...ent-1801495815 and also https://forum.espocrm.com/forum/deve...522#post100522 i am trying this code below to monkey patch but didn't succeed. is there any related article/conversation about how to get it up working properly. Thanks

            PHP Code:
            require(['views/admin/entity-manager/record/edit'], View => {

                const 
            defaultSetup View.prototype.setup;

                
            View.prototype.setup = function () {
                    
            defaultSetup.call(this);
                    
                    
            console.log('custom setup'this.name);
                };
            });
            ​ 

            Because i am using es6 i also tried below

            PHP Code:
            import EntityManagerRecordEditView from 'views/admin/entity-manager/record/edit';

            const 
            defaultSetup EntityManagerRecordEditView.prototype.setup;

            EntityManagerRecordEditView.prototype.setup = function () {
                
            // Call the original setup method
                
            defaultSetup.call(this);

                
            // Your custom logic
                
            console.log('Custom setup for Entity Manager Index View:'this.name);
            };

            export default EntityManagerRecordEditView;​ 
            This was added in a script in my extension but when running node build --copy and go to edit record in entity manager nothing in the console.

            Any help would be appreciated and i know how much busy you are
            Last edited by rabii; 09-27-2024, 12:44 PM.
            Rabii
            Web Dev | Freelancer

            Comment


            • #7
              Is the file called? Try the console.log outside the method.

              Comment


              • rabii
                rabii commented
                Editing a comment
                tried still nothing in the console

            • #8
              Added to both scriptList and developerModeScriptList ?

              Comment


              • rabii
                rabii commented
                Editing a comment
                already did that

            • #9
              by the way iam using ext-template / es6 enabled transpil
              Rabii
              Web Dev | Freelancer

              Comment


              • #10
                Developer mode enabled? I tried, it worked for me in the developer mode. Clearing cache required.

                Code:
                {
                    "developerModeScriptList": [
                        "__APPEND__",
                        "client/custom/src/test.js"
                    ]
                }
                ​

                Comment


                • #11
                  Yes,

                  It is enabled (i did clear cache both from UI and also through CLI)

                  here is my app > client.json
                  PHP Code:
                  {
                      
                  "scriptList": [
                          
                  "__APPEND__",
                          
                  "client/custom/modules/{@nameHyphen}/lib/init.js",
                          
                  "client/custom/modules/plus-extension/src/plus-script.js"
                      
                  ],
                      
                  "developerModeScriptList": [
                          
                  "__APPEND__",
                          
                  "client/custom/modules/plus-extension/src/plus-script.js"
                      
                  ]
                  }
                  ​ 

                  and my plus-script.js under src folder in my files / client/custom/modules/plus-extension/src/plus-script.js

                  PHP Code:
                  require(['views/admin/entity-manager/record/index'], View => {

                      const 
                  defaultSetup View.prototype.setup;

                      
                  View.prototype.setup = function () {
                          
                  defaultSetup.call(this);
                          
                          
                  console.log('custom setup'this.name);
                      };
                  });
                  ​ 

                  That is weird still not working, even if i console log outside the method nothing shows in the console.
                  Rabii
                  Web Dev | Freelancer

                  Comment


                  • Kharg
                    Kharg commented
                    Editing a comment
                    Maybe try updating the app timestamp from CLI?

                  • rabii
                    rabii commented
                    Editing a comment
                    It was just cache, had to clear it twice using cli and also cleared cache from browser and it start to work.

                  • yuri
                    yuri commented
                    Editing a comment
                    App timestamp updating busts the cache timestamp. So it also works.

                • #12
                  You should be able to see your script in the html source. Ctrl + U in the browser.

                  Comment


                  • #13
                    If the JS file is cached by the browser, open it in a tab and Ctrl + F5.

                    Comment


                    • #14
                      Got it to work now, cleared cache from UI and cache of browser and it worked

                      Thanks Yuri appreciate your time
                      Rabii
                      Web Dev | Freelancer

                      Comment

                      Working...
                      X