How to safely extend js views in packages?

Hi, I just can't figure out how to do this in a safe way.

Lets say I want to extend accounts recordView - I create a file custom/modules/Accounts/clients/base/views/record/record.js. Easy.

And now I want to install this file using a package - this package will take the file (using copy installdefs) and put it on it's place and everything works...

But does it? What if there already was a different file from a different package? It would be overwritten right? So the previous functionality would be lost? How can I avoid this? And how can I ensure some other package won't overwrite my files?

All that comes to my mind is not to create files in custom/modules/*/clients/base/views/, but rather to extend the class directly in some JSGroupings file. But that's kinda ugly and I would still run to problems if there were methods with same names (at least initialize method...), so i would like like to avoid that...

What is the best practice for this?

Thanks for suggestions

Karel

Parents
  • Karel ÄŒech

    This document would be useful to you.

    Leveraging Backbone Events in Sugar « Sugar Developer Blog – SugarCRM 

    You can use JSgrouping from the above documentation.

    And do whatever you like to code on Recordview at any module.

    app.router.on('route:record', function(module){
    //AND the module is Accounts...
    if(module === 'Accounts') {

  • I think you already know the answer to your question. Which is that when you override a file, there is a risk of conflicts with other customizations. There is no getting around that. This is manageable when you own the Sugar instance and can decide what customizations go where and can even merge conflicting changes manually within a record controller. But when you are expecting your customization to be installed as a package, you have to be more careful.

    When you are building a package, you should use Extensions Framework and avoid overrides at all costs. There are lots of ways to implement changes on a Record view without overriding. This may mean you have to make some compromises between what you want to do and what is safe development practice.

    1. Build dashlets / dashboards for use in this Record view
    2. Add a custom view that you control to the Record layout using a Sidecar extension
    3. Create a custom field type and add that to the system, use an extension to modify viewdefs or vardefs to have modules use this new custom field type
    4. Add code elsewhere that subscribes to Backbone Events that occur on this module
    5. Use a Sidecar extension to add a custom button to Record view that launches into your alternative UI
    6. ...

    App Ecosystem @ SugarCRM

Reply
  • I think you already know the answer to your question. Which is that when you override a file, there is a risk of conflicts with other customizations. There is no getting around that. This is manageable when you own the Sugar instance and can decide what customizations go where and can even merge conflicting changes manually within a record controller. But when you are expecting your customization to be installed as a package, you have to be more careful.

    When you are building a package, you should use Extensions Framework and avoid overrides at all costs. There are lots of ways to implement changes on a Record view without overriding. This may mean you have to make some compromises between what you want to do and what is safe development practice.

    1. Build dashlets / dashboards for use in this Record view
    2. Add a custom view that you control to the Record layout using a Sidecar extension
    3. Create a custom field type and add that to the system, use an extension to modify viewdefs or vardefs to have modules use this new custom field type
    4. Add code elsewhere that subscribes to Backbone Events that occur on this module
    5. Use a Sidecar extension to add a custom button to Record view that launches into your alternative UI
    6. ...

    App Ecosystem @ SugarCRM

Children