how to override create cases button from leads subpanel

If the Leads is in particular status the users are not allow to create Cases from Leads subpanel ( the button '+' in subpanel)

I can't hide the button but i have to show an alert.

I am using SugarCRM pro 7.2

Thank you

Parents Reply
  • i want to show an alert based on a Lead record value but only when the user clicks on create cases from leads subpanel ("+").

    I want to prevent the creation cases and show an alert.

    I tryed to extend SubpanelListView and SubpanelsLayout but i am not able to change the button behavior.

    i wrote this ...

    ({

      /* File: ./custom/modules/Leads/clients/base/views/record/record.js */

        extendsFrom: 'RecordView',

        initialize: function(options) {

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

            this.model.on('data:sync:complete', this.showAlert, this);

        },

        showAlert: function(){

        var currentStatus = this.model.get('caratterizzazione_c');

      

        if (currentStatus === '2')

        {

      app.alert.show("ConvertedLead", {

                    level: 'warning',

                            messages: app.lang.get('EXCEPTION_LEADS_CARATTERIZZAZIONE' , 'Leads'),

                            autoClose: false

            });

        }

        }

    })

Children
  • Ciao Luca,

    You are approaching this from the wrong end, you are trying to work in the Leads record view when you should be working from the Cases perspective on the subpanel's panel-top view.

    As Angel said : "You can manipulate the behavior of the button by extending the panel-top view's controller (panel-top.js) to check the data of the parent record and manipulate the css class on the button and show the alert."


    Panel Top lives here: <your sugarcrm>/jssource/src_files/clients/base/views/panel-top/panel-top.js

    Some modules also have specific ones in modules/<module>/clients/base/views/. but, at least in 7.6, Cases does not have one.

    What you want to do is extend the panel-top controller for Cases by creating:

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

    There you can extend the createRelatedClicked method to check for caratterizzazione_c, alert if your criteria holds, proceed to creating the record if it doesn't.

    Within the createRelatedClicked you should be able to use

    this.context.parent.get('module') to make sure you're in a subpanel on Leads

    and then

    this.context.parent.get('caratterizzazione_c') to get the value you need.

    In bocca al lupo,

    FrancescaS

     

  • Thank you so much,

    FrancescaS and Angel

    I solved my problem. It works.

    I created the file below

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

    /**

    * Header section for Subpanel layouts.

    *

    * @class View.Views.Base.PanelTopView

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

    * @extends View.View

    */

    ({

        /**

         * @inheritDoc

         */

        className: 'subpanel-header',

        /**

         * @inheritDoc

         */

        attributes: {

            'data-sortable-subpanel': 'true'

        },

        /**

         * @inheritDoc

         */

        events: {

            'click': 'togglePanel',

            'click a[name=create_button]:not(".disabled")': 'createRelatedClicked',

        },

        plugins: ['LinkedModel'],

        /**

         * @override

         * @param opts

         */

        initialize: function(opts) {

            app.view.View.prototype.initialize.call(this, opts);

            var context = this.context;

          

            this.parentModule = context.parent.get('module');

            context.parent.on('panel-top:refresh', function(link) {

                if (context.get('link') === link) {

                    context.get('collection').fetch();

                }

            });

        },

        /**

         * Event handler for the create button.

         *

         * @param {Event} event The click event.

         */

        createRelatedClicked: function(event) {

           var fieldCaratt = this.model.link.bean.attributes.caratterizzazione_c;

           if (this.parentModule=='Leads'){

                if (fieldCaratt =='2'){

                     app.alert.show("workflow-status-message", {

                                level: 'warning',

                                messages: app.lang.get('EXCEPTION_CREATE_CASE_FROM_LEAD' , 'Cases'),

                                autoClose: false

                       });

                }else{

                     this.createRelatedRecord(this.module);

                }

           }else{

                this.createRelatedRecord(this.module);

           }

            

        },

        /**

        * Event handler that closes the subpanel layout when the SubpanelHeader is clicked

        * @param e DOM event

        */

        togglePanel: function(e) {

            // Make sure we aren't toggling the panel when the user clicks on a dropdown action.

            var toggleSubpanel = !$(e.target).parents("span.actions").length;

            if (toggleSubpanel) {

                this._toggleSubpanel();

            }

        },

        _toggleSubpanel: function() {

            if(!this.layout.disposed) {

                var isHidden = this.layout.$(".subpanel").hasClass('closed');

                this.layout.trigger('panel:toggle', isHidden);

            }

        },

        /**

         * @override

         */

        bindDataChange: function() {

            if (this.collection) {

                this.listenTo(this.collection, 'reset', this.render);

            }

        }

    })

  • I'm not sure why you are replacing the view instead of extending it but glad you got it working.

    Francesca