Target lists - Targets subpanel

The target list has targets as subpanel where we have added records. On the right side we have Edit and in dropdown remove option.

Is there a way to add duplicate option in that dropdown, so we can duplicate target and edit info? :thinking:

If I remember correctly, in v7 there is no direct way of adding buttons there but you can do it with more elaborate techniques like JS injection, or overriding the classes that output the views.

I don’t have any bookmarked tutorial for you, unfortunately, but maybe you can try searching…

can we do this?

1: Create subpaneldefs.php

custom/modules/ProspectLists/metadata/subpaneldefs.php

  'prospects' => array(
      'order' => 10,
      'sort_by' => 'last_name',
      'sort_order' => 'asc',
      'module' => 'Prospects',
      'subpanel_name' => 'default',
      'get_subpanel_data' => 'prospects',
      'title_key' => 'LBL_PROSPECTS_SUBPANEL_TITLE',
      'top_buttons' => array(
          array('widget_class' => 'SubPanelTopButtonQuickCreate'),
          array('widget_class' => 'SubPanelTopSelectButton', 'mode' => 'MultiSelect'),
          array(
              'widget_class' => 'SubPanelButtonDuplicate',  
              'label' => 'LBL_DUPLICATE',              
              'acl_action' => 'edit',                       
          ),
      ),
  ),

2: Create duplicate.js

({
    extendsFrom: 'SubpanelListView',

    initialize: function(options) {
        this._super('initialize', [options]);
    },

 
    duplicateRecord: function(model) {
        var prospectId = model.id;  
        var prospect = app.data.createBean('Prospects', {id: prospectId});

     
        prospect.fetch({
            success: function(record) {
                var duplicate = app.data.createBean('Prospects');
                
                duplicate.set(record.attributes);
                delete duplicate.attributes.id; 
                delete duplicate.attributes.date_entered;

              
                duplicate.save()
                    .then(function(response) {
                        app.alert.show('duplicate-success', {
                            level: 'success',
                            messages: 'Prospect successfully duplicated.',
                            autoClose: true
                        });

                   
                        this.render();
                    }.bind(this))
                    .catch(function(error) {
                        app.alert.show('duplicate-error', {
                            level: 'error',
                            messages: 'Error duplicating the Prospect.',
                            autoClose: true
                        });
                    });
            },
            error: function() {
                app.alert.show('duplicate-error', {
                    level: 'error',
                    messages: 'Error fetching the Prospect record.',
                    autoClose: true
                });
            }
        });
    },


    addRowAction: function(row) {
        var duplicateBtn = $('<button class="duplicate-btn">Duplicate</button>');
        duplicateBtn.on('click', function() {
            this.duplicateRecord(row.model);  
        }.bind(this));

        row.$el.find('.action_buttons').append(duplicateBtn);  
    },
});

custom/modules/ProspectLists/JS/duplicate.js