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
  • Hello,

    I can point you on the direction. As a start point you may refer this post

    It may help you!

    Thanks & Regards,

    Team Urdhva Tech

    Web: http://www.urdhva-tech.com

  • 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!.

Reply
  • 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!.

Children
  • Hi Ajay,

    I tried like this with subpanel-list.js and its working. But not sure whether its the optimal solution.

    ({
        extendsFrom: 'SubpanelListView',
        initialize: function (options) {
            this._super('initialize',[options]);
            this.on('render',this.hidePanelIfClosed,this); 
        },
        hidePanelIfClosed: function(){
          //get Parent Information
          var ctx = this.context.parent,
              parentModelId = ctx.get("modelId"),
              parentModule = ctx.get("module");
              console.log(parentModelId+ " "+parentModule);
          if(parentModule == 'module'){
             var  parentBean = app.data.createBean(parentModule, {id:parentModelId}),
                  request = parentBean.fetch();
             //when it is done fetching the parent info
             request.xhr.done(function(){
                var parentStatus = parentBean.get("status");
                console.log(parentStatus);
                if(parentStatus == 'closed'){
                   $('.subpanel-header').has('.label-panel-module').find('[class="actions btn-group pull-right panel-top"]').addClass('hidden');
                   $('.flex-list-view-content').find('[class="btn dropdown-toggle"]').addClass('hidden');
                }
             });
          }
        },
    })
    
  • This code does not disable the "+" Create button but it allows you to display a message if certain conditions are true.

    In this case, the code gets triggered when the user clicks on Create button for Revenue Line Items subpanel.

     

    custom/modules/RevenueLineItems/clients/base/views/panel-top/panel-top.js

    ({
       extendsFrom: "PanelTopView",

       createRelatedClicked: function(event) {
          var self = this;
          var oppStatus = self.context.attributes.parentModel.attributes.status_oppty_c;

          app.alert.dismiss('opp-rli-create');

          if (oppStatus == 'In Progress'){
             this._super("createRelatedClicked", [event]); //open create drawer
          }else{
             app.alert.show('disableCreate', {
                level: 'warning',
                messages: 'your message here',
                autoClose: true,
                autoCloseDelay : 10000,

             });
          }
       }
    })

    Hope this helps.

    Regards, 

    Angel M.