Brainstorm: Add related records as "mass update"

I have a complex scenario:

I have a custom subpanel on Leads for Products of Interest.

Each Product of Interest has a series of qualifiers. Which qualifiers apply to which product is determined in a custom Products of Interest Catalog.

When entering a Product of Interest one selects from a product dropdown (generated from the custom catalog) and is presented with checkboxes and other dropdowns for the applicable qualifiers (again, based on the custom catalog).

I want the user to be able to Mass Assign Products of Interest by selecting a number of leads from a filtered list and assigning a product with certain options to each one. All leads would get the same product/options.

I am thinking the solution is to have an Action on the List that would open a  Products of Interest drawer. Here the user would select the Product of Interest to be added and set the options, when saving I would create a Product of Interest record for each item in the collection.

The other option is easier to code but messier to maintain:

Have a panel for each product and put each product and qualifiers for each product on the Lead itself. I don't like this approach because as products and qualifiers change in time we'll end up with abandoned fields and messy re-naming.

Can anyone think of something better/easier?

thanks,
FrancescaS

SugarCRM v7.6.1 Professional

  • Solved extending record list to open the drawer and relate the profucts to the collection selected

    custom/modules/Leads/clients/base/views/recordlist/recordlist.php

    Added to the actions array:

                array(

                    'name' => 'comp_products_button',

                    'type' => 'button',

                    'label' => 'LBL_ADD_COMP_PRODUCTS',

                    'acl_action' => 'edit',

                    'primary' => true,

                    'events' => array(

                        'click' => 'list:addcompproducts:fire',

                    ),

                ),

    custom/modules/Leads/clients/base/views/recordlist/recordlist.js

    ({

       extendsFrom: 'RecordlistView',

       initialize: function(options){

          this._super('initialize', [options]);

          //events

          this.context.on('list:addcompproducts:fire', this.addComplimentaryProducts, this);

       },

       addComplimentaryProducts: function(){

         var ids = _.map(this.context.get('mass_collection').models, function(selected_model){return selected_model.id});

         //open the complimentary product drawer, loop through the ids and create a new product for each lead id

         app.drawer.open({

           layout:'create-actions',

           context:{

             create: true,

             module:'compp_Complimentary_Products',

             parent_ids: ids,

             parent_module: 'Leads',

           }

        });

      },

      _dispose: function() {

        this._super('_dispose');

      },

    })

    and handle the multi add in

    custom/modules/compp_Complimentary_Products/clients/base/views]$ vi create-actions/create-actions.js

    /**

    * @class View.Views.Base.CreateActionsView

    * @alias SUGAR.App.view.views.BaseCreateActionsView

    * @extends View.Views.Base.CreateView

    */

    ({

      extendsFrom: 'BaseCreateActionsView',

      /**

       * An array of the parent IDs from the list view (mass creation of products)

       * @protected

       * @type {Array}

       */

      _parentIDs: [],

      /**

       * The name of the parent module from the list view (mass creation of products)

       * @protected

       * @type {string}

      */

      _parentModule: [],

      initialize: function(options) {

        if(!_.isUndefined(options.context.get('parent_ids')) && !_.isUndefined(options.context.get('parent_module'))){

          this._parentIDs = options.context.get('parent_ids');

          this._parentModule = options.context.get('parent_module');

        }

        this._super('initialize', [options]);

      },

      /**

       * Save and close drawer

       */

        saveAndClose: function () {

            this.initiateSave(_.bind(function () {

                if(app.drawer){

                    app.drawer.close(this.context, this.model);

                }

                var parent_ids = this._parentIDs,

                    parent_module = this._parentModule,

                    copy_id = this.model.get('id');

                if(!_.isEmpty(parent_ids) && !_.isEmpty(parent_module)){

                  this.handleMultiAdd(parent_module, parent_ids, copy_id);

                }

            }, this));

        },

        /**

         * Handle click on save and create another link

         */

        saveAndCreate: function() {

            this.context.lastSaveAction = this.SAVEACTIONS.SAVE_AND_CREATE;

            var parent_ids = this._parentIDs,

                parent_module = this._parentModule;

            this.initiateSave(_.bind(

            function() {

                    var copy_id = this.model.get('id');

                    this.clear();

                    // set the default attributes and the relatedAttributes back

                    // on the model since it's been cleared out

                    this.model.set(_.extend(this.model.getDefault(), this.model.relatedAttributes));

                    this.resetDuplicateState();

                    if (this.hasSubpanelModels) {

                        // loop through subpanels and call resetCollection on create subpanels

                        _.each(this.context.children, function(child) {

                            if (child.get('isCreateSubpanel')) {

                                this.context.trigger('subpanel:resetCollection:' + child.get('link'), true);

                            }

                        }, this);

     

                        // reset the hasSubpanelModels flag

                        this.hasSubpanelModels = false;

                    }

                    if(!_.isEmpty(parent_ids) && !_.isEmpty(parent_module)){

                            this.handleMultiAdd(parent_module, parent_ids, copy_id);

                    }

            }, this));

        },

        handleMultiAdd: function(parent_module, parent_ids, copy_id){

           var url = app.api.buildURL('compp_Complimentary_Products/addMultipleCompProducts/'+parent_module+'/'+parent_ids+'/'+copy_id);

    console.log(url);

           App.api.call('GET', url, '',{

             success: _.bind(function(o){

               console.log("REST easy " + o);

             },this),

             error: _.bind(function(o){

               console.log("No REST for the wicked!" + o);

             }, this),

           });

        },

    })