How to disable sub panel row actions conditionally based on parent model?

What is the best practice to conditionally disable edit/add/ un-link actions on sub panel where parent module is assigned to a status.
For example:

If parent status is 'Closed' -> Sub panel records should not be altered.

Message was edited by: Alex Nassi

Parents Reply Children
  • Hi Surabhil,

    Create and link existing record buttons are come from panel-top view.

    Edit and unlink buttons come from subpanel-list view.So there you can loop through buttons and you can make disable action.

    Here i have done similar to your case,like if Accounts module(Record view), industry field value is "Construction" .Then i want to disable button actions for subpanel leads module. So i am placing these files in

    sugar/custom/modules/Leads/clients/base/views/panel-top/panel-top.js

    sugar/custom/modules/Leads/clients/base/views/subpanel-list/subpanel-list.js

    panel-top.js

    ({
      //panel-top.js
      extendsFrom: 'PanelTopView',
      initialize:function(options) {
      this._super('initialize', [options]);
      var industryValue=this.context.parent.get('model').get("industry");
      var parentModule=this.context.parent.get('module');
      if(!_.isEqual(industryValue,'Construction') && _.isEqual(parentModule,"Accounts")){
      _.each(_.first(this.meta.buttons).buttons, function(action){
      action['css_class'] = 'disabled btn';
      });
      }
      },
    })
    
    

    subpanel-list.js

    ({
      //subpanel-list.js
      extendsFrom:'SubpanelListView',
      initialize:function(options){
      this._super('initialize',[options]);
      this.on('render',this._disableActions,this);
      },
      _disableActions:function() {
      var industryValue=this.context.parent.get('model').get("industry");
      var parentModule=this.context.parent.get('module');
      if(!_.isEqual(industryValue,'Construction') && _.isEqual(parentModule,"Accounts")){
      _.each(this.meta.rowactions.actions, function(action){
      if(!_.isEqual(action['icon'],"fa-eye")){ // for preview button
      delete action['event'];
      action['css_class'] = 'disabled btn';
      }
      });
      }
      }  
    })
    

    Place the two files based on your module.

    Hope this helps!.

  • Thanks. I can add a new button,but what I am looking for is the best practice for hiding the existing row-actions with conditions.