How to Change rowaction button based on condition in Subpanel ??

Hi Friends 

Contact -> RecordView

Cases -> Subpanel under contact record.

i want to change to rowaction button when case status is Closed in subpanel

for example ..

if case status closed then i want preview button else i want delete button as a rowaction.

i have made changes in 2 files ..but not working for me .. Please Help Ajay Kumar Ramana Raju Santhana

custom/modules/Cases/clients/base/views/subpanel-for-contacts-cases/subpanel-for-contacts-cases.php

$viewdefs['Cases']['base']['view']['subpanel-for-contacts-cases'] = array (
'panels' =>
array (
0 =>
array (
'name' => 'panel_header',
'label' => 'LBL_PANEL_1',
'fields' =>
array (
0 =>
array (
'label' => 'LBL_LIST_SUBJECT',
'enabled' => true,
'default' => true,
'name' => 'name',
'link' => true,
),
1 =>
array (
'label' => 'LBL_LIST_STATUS',
'enabled' => true,
'default' => true,
'name' => 'status',
),
2 =>
array (
'target_record_key' => 'account_id',
'target_module' => 'Accounts',
'label' => 'LBL_LIST_ACCOUNT_NAME',
'enabled' => true,
'default' => true,
'name' => 'account_name',
),
3 =>
array (
'name' => 'case_number',
'label' => 'LBL_NUMBER',
'enabled' => true,
'readonly' => true,
'default' => true,
),
4 =>
array (
'label' => 'LBL_LIST_DATE_CREATED',
'enabled' => true,
'default' => true,
'name' => 'date_entered',
),
5 =>
array (
'name' => 'assigned_user_name',
'target_record_key' => 'assigned_user_id',
'target_module' => 'Employees',
'label' => 'LBL_LIST_ASSIGNED_TO_NAME',
'enabled' => true,
'default' => true,
),
),
),
),
'rowactions' =>
array (
'actions' =>
array (
0 =>
array(
'type' => 'rowaction',
'tooltip' => 'LBL_PREVIEW',
'label' => 'LBL_PREVIEW',
'event' => 'list:preview:fire',
'icon' => 'fa-eye',
'acl_action' => 'view',
'allow_bwc' => false,
),
1 =>
array (
'type' => 'rowaction',
'name' => 'edit_button',
'icon' => 'fa-pencil',
'label' => 'LBL_EDIT_BUTTON',
'event' => 'list:editrow:fire',
'acl_action' => 'edit',
'allow_bwc' => true,
),
2 =>
array (
'type' => 'unlink-action',
'icon' => 'fa-chain-broken',
'label' => 'LBL_UNLINK_BUTTON',
),
),
),
'type' => 'subpanel-list',
);

custom/modules/Cases/clients/base/views/subpanel-list/subpanel-list.js

({ 
//subpanel-list.js
extendsFrom:'SubpanelListView',
initialize:function(options){
this._super('initialize',[options]);
this.on('render',this._disableActions,this);
},
_disableActions:function() {

console.log(this.context.attributes.collection.models);

//console.log(this.meta.rowactions.actions);
var self = this;

_.each(this.context.attributes.collection.models, function(case_model){
// console.log(case_model.get('status'));
if(_.isEqual(case_model.get('status'),'Closed'))
{
_.each(self.meta.rowactions.actions, function(action){
if(_.isEqual(action['icon'],"fa-eye")){ // for preview button
delete action['event'];
action['icon'] = 'fa-trash-o';
action['event'] = 'list:deleterow:fire';
action['name'] = 'delete_button';
action['acl_action'] = 'edit';
}
console.log(action);
});
}
});

}
})
Parents
  • Hi Mehul  Bhandari

    Dont add any conditions or any custom code in your subpanel list file and add your code for Preview & Delete Buttons.

    Now check whether Preview & Delete Buttons are displaying under rowactions or not.

    If it is displaying then now in your subpanel list js file tweak your code like:

    Remove _disableActions function and Put your code 

    _disableActions{ // All this code  }

    Inside _renderHtml function as:

    _renderHtml: function(){  

       // Place your code here
       var self = this;
    _.each(this.context.attributes.collection.models, function(case_model){
         if(_.isEqual(case_model.get('status'),'Closed'))
        {
            _.each(self.meta.rowactions.actions, function(action)
            {
                if(_.isEqual(action['icon'],"fa-eye")){
                        // Code for disable preview button on each record
                        delete action['event'];
                        action['css_class'] = 'disabled btn';
                   }
              });
         }
    });
    this._super('_renderHtml');
    },
    _dispose: function(){
       this._super('_dispose');
    }

    Hope this Helps..!!

    Best Regards

    S Ramana Raju

Reply
  • Hi Mehul  Bhandari

    Dont add any conditions or any custom code in your subpanel list file and add your code for Preview & Delete Buttons.

    Now check whether Preview & Delete Buttons are displaying under rowactions or not.

    If it is displaying then now in your subpanel list js file tweak your code like:

    Remove _disableActions function and Put your code 

    _disableActions{ // All this code  }

    Inside _renderHtml function as:

    _renderHtml: function(){  

       // Place your code here
       var self = this;
    _.each(this.context.attributes.collection.models, function(case_model){
         if(_.isEqual(case_model.get('status'),'Closed'))
        {
            _.each(self.meta.rowactions.actions, function(action)
            {
                if(_.isEqual(action['icon'],"fa-eye")){
                        // Code for disable preview button on each record
                        delete action['event'];
                        action['css_class'] = 'disabled btn';
                   }
              });
         }
    });
    this._super('_renderHtml');
    },
    _dispose: function(){
       this._super('_dispose');
    }

    Hope this Helps..!!

    Best Regards

    S Ramana Raju

Children
  • Hi Ramana Raju Santhana

    Thanks bhai for reply ..

    i have changed the code in  custom/modules/Cases/clients/base/views/subpanel-list/subpanel-list.js

    then all records not showing in subpanel

     

    ({ 
    //subpanel-list.js
    extendsFrom:'SubpanelListView',
    initialize:function(options){
    this._super('initialize',[options]);
    this.on('render',this._renderHtml,this);
    },
    _renderHtml: function(){
    // Place your code here
    var self = this;
    _.each(this.context.attributes.collection.models, function(case_model){
    if(_.isEqual(case_model.get('status'),'Closed'))
    {
    _.each(self.meta.rowactions.actions, function(action)
    {
    if(_.isEqual(action['icon'],"fa-eye")){
    // Code for disable preview button on each record
    delete action['event'];
    action['css_class'] = 'disabled btn';
    }
    });
    }
    });
    this._super('_renderHtml');
    },
    _dispose: function(){
    this._super('_dispose');
    }
    })
  • I got this working sort of like this

    ({
        extendsFrom:'SubpanelListView',
        initialize:function(options){
            this._super('initialize',[options]);
            this.on('render',this._disableActions2,this);
        },_disableActions2: function(){
            var self = this;
            _.each(this.context.attributes.collection.models, function(pam_model)
            {
                //debugger;
                var cid = pam_model.get('id');
                if(pam_model.get('assigned_user_id') != SUGAR.App.user.get('id'))
                {
                    this.$('tr[name="PAM_Account_Members_'+cid+'"] td span div.fieldset-field a[data-original-title=Actions]').removeClass('rowaction btn');
                    this.$('tr[name="PAM_Account_Members_'+cid+'"] td span div.fieldset-field a[data-original-title=Actions]').addClass('disabled btn');
                }
            });
        },
    })

    But if you have to click on the 'more record' link to see more than 5, none of those records are affected by this code.  The control is not disabled as it should be.