delete button on subpanel row: why does this work and is it safe to use?

I wanted to add a delete button on a subpanel row for a custom module.
These are essentially line items on an Opportunity.

I added the rowaction it in the metadata for the subpanel:

             

mysugar/custom/modules/oppp_Opportunity_Products/clients/base/views]$ cd subpanel-for-opportunities/subpanel-for-opportunities.php

$viewdefs['oppp_Opportunity_Products']['base']['view']['subpanel-for-opportunities'] = array (
  'rowactions' => array(
    'actions' => array(
      array(
        'type' => 'rowaction',
        'css_class' => 'btn',
        'tooltip' => 'LBL_PREVIEW',
        'event' => 'list:preview:fire',
        'icon' => 'icon-eye-open',
        'acl_action' => 'view',
        'allow_bwc' => false,
      ),
      array(
        'type' => 'rowaction',
        'name' => 'edit_button',
        'icon' => 'icon-pencil',
        'label' => 'LBL_EDIT_BUTTON',
        'event' => 'list:drawereditrow:fire',
        'acl_action' => 'edit',
        'allow_bwc' => false,
      ),
      array(
        'type' => 'rowaction',
        'name' => 'delete_button',
        'icon' => 'icon-trash',
        'label' => 'LBL_DELETE_BUTTON',
        'event' => 'list:deleterow:fire',
        'acl_action' => 'delete',
        'allow_bwc' => false,
      ),
      array(
         'type' => 'unlink-action',
         'icon' => 'icon-unlink',
         'label' => 'LBL_UNLINK_BUTTON',
      ),
    ),
  ),
  'panels' =>
 <snipped>
                                                                                           

and I added the action in the subpanel-list

mysugar/custom/modules/oppp_Opportunity_Products/clients/base/views/subpanel-list/subpanel-list.js 

I was going to use the API to delete that model.id but it turns out that's unnecessary and actually causes problems.

What is puzzling me is that this works if the delteClicked function is totally empty, I came across it quite by accident... but WHY does it work? What is it doing? There is no deleteClicked in SubpanelListView so where is it getting it from?

Can anyone explain why this works an if it's safe to use?

({
  extendsFrom: 'SubpanelListView',
  initialize: function(options){
     this._super('initialize', [options]);
     this.context.on('list:drawereditrow:fire',this.drawerEditClicked, this);
     this.context.on('list:deleterow:fire',this.deleteClicked, this);
  },
  deleteClicked: function(model) {},
  drawerEditClicked: function(model){
    app.drawer.open({
       layout:'create-actions',
       context:{
         create: true,
         model: model,
         module:'oppp_Opportunity_Products',
       }
    });
  },
  _dispose: function() {
    this._super('_dispose');
  },
});
                                                         


thanks,
FrancescaS

  • Hi FrancescaS,

    if you take a closer look at the subpanel-list.js (core) it extends reocrdlist.js and on that controller there is an event for list:deleterow:fire, this is just a wild guess but maybe its being triggered as well when your event is fired. 

    Hope this helps
  • Thanks EvilPeri,
    I guess that's a good reason for it to work, but I'm not happy with having an empty function for the deleteClicked. So I guess the right question is what is the proper syntax for calling the parent function?

    FrancescaS
  • Hi,

    I guess you already solve it. Just wanted to know if the answer was something like this,

    ({
      extendsFrom: 'SubpanelListView',
      initialize: function(options){
         this._super('initialize', [options]);
         this.context.on('list:drawereditrow:fire',this.drawerEditClicked, this);
         this.context.on('list:deleterow:fire',this.deleteClicked, this);
      },
      deleteClicked: function(model) {
         this._super('deleteModel');
    
      },  
      drawerEditClicked: function(model){
        app.drawer.open({
           layout:'create-actions',
           context:{
             create: true,
             model: model,
             module:'oppp_Opportunity_Products',
           }
        });
      },
      _dispose: function() {
        this._super('_dispose');
      },
    });
    
  • Hello ,

    I'm trying to do the same as you did, for a Sugar Sell V11.1 but the event is not fired, especially this part : 

    deleteClicked: function (model) {
            this._super('deleteModel');
        },

    When I check on the base subpanel-list.js file, there is no deleteModel function, it is located in recordlist.js (base) function.

    Is there anything I'm missing ? 

    Thanks a lot for your answer.

    Best regards,

    Enes

  • Finally I made it working by removing the content of the function deleteClicked ... very strange :/

  • Gosh, it's been a few years since this thread...


    Here is what I have for my subpanel-list on that module today, and it's working appropriately for me on Sugar 11.0.3 Professional.

    Notice the initialize function has the deletedrow:fire event, and I'm not using deleteModel but rather the deleteClicked function uses the original warnDelete(model) which I believe subpanel-list inherits from recordlist.js

    ({
      extendsFrom: 'SubpanelListView',
      initialize: function(options){
         this._super('initialize', [options]);
         this.context.on('list:drawereditrow:fire',this.drawerEditClicked, this);
         this.context.on('list:deleterow:fire',this.deleteClicked, this);
        if(this.layout){
          this.layout.on('list:record:deleted', function() {
            this.refreshCollection();
            this.refreshParentAmount();
          }, this);
        }
      },
      refreshParentAmount: function(){
        var parentmodel = this.context.parent.get('model');
        parentmodel.fetch({
          view: undefined,
          fields: ['amount', 'product_of_interest_c']
        });
      },
      deleteClicked: function(model) {
        var self = this;
        self.warnDelete(model);
      },
      drawerEditClicked: function(model){
        app.drawer.open({
           layout:'create',
           context:{
             create: true,
             model: model,
             module:'oppp_Opportunity_Products',
           }
        });
      },
    });
    

  • Thanks a lot for your feedback Francesca, very nice from you Slight smile

    We will apply this piece of code on monday.

    Have a nice week-end !

    Enes

  • Hi Francesca,

    It's ok on our side, the modification works on Sugar Ent 11.0.2 :-)

    Thanks a lot and have a nice week.

    Enes