Custom button with permission level is displayed only after page refresh

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vit
    Junior Member
    • Oct 2024
    • 7

    #1

    Custom button with permission level is displayed only after page refresh

    I've added some buttons via extending views/details this way

    Code:
    define(['views/detail'], (DetailView) => {
    return class DetailExtendView extends DetailView{
    setup(){
    super.setup();
    .....
    if (this.getAcl().getPermissionLevel('gw') === 'team'
    || this.getAcl().getPermissionLevel('gw') === 'all'
    ) {
    this.addMenuItem('buttons', {
    name: 'add-gw',
    iconHtml: '<span class="fas fa-suitcase" style="color:#e5e5e5"></span>',
    className: 'btn-success',
    acl: 'edit',
    text: this.translate('Add GW'),
    onClick: () => this.actionAddGw(),
    });
    }

    They are displayed fine for admin users. For users with appropriate permission, their display varies with how you open entity details

    Steps to recreate
    1. Click on an entity in the main menu
    2. Click on an item to enter entity details
    (button is not displayed)
    3. Refresh the page
    (button is displayed)
    4. Click on an entity name (not in the menu)
    5. Click on an item to enter entity details
    (button is not displayed)
    6. Click on another entity in the menu.
    7. Click on the target entity
    8. Click on the entity item
    (button is displayed)

    I believe that it's a matter of caching buttons or rendered views.

    Extending views/record/detail won't work as it has no addMenuItem function in it, and can not be called thus.

    Setting button with adding them in clientDefs is an option though, but I do not know how to check getPermissionLevel globally, not for a particular entity

    Click image for larger version  Name:	image.png Views:	3 Size:	19.9 KB ID:	119177
    Last edited by Vit; Today, 03:15 PM.
  • Vit
    Junior Member
    • Oct 2024
    • 7

    #2
    Moving logic from setup to afterRender function did not help.

    Comment

    • yuri
      Member
      • Mar 2014
      • 9119

      #3
      Use a handler instead. Not the view.

      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • Vit
        Junior Member
        • Oct 2024
        • 7

        #4
        Is this.getAcl().getPermissionLevel() method visible in handlers?

        Comment

        • yuri
          Member
          • Mar 2014
          • 9119

          #5
          Code:
          this.view.getAcl()
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • Vit
            Junior Member
            • Oct 2024
            • 7

            #6
            Thank you so much. It worked

            Comment

            Working...