Is there a way to customize the AlertView Controller?

Hello folks,

does someone know a way to extend the alert view controller?

There is already a registered bug regarding this issue: https://portal.sugarondemand.com/index.php#supp_Bugs/bf747ba0-04db-11e7-9c6a-d4bed9b70c64
Taking a look at the code (Sugar 10.0.2), the problematic point seems to be the init function in sidecar/src/view/alert.js. There it does look up a series of properties in the ViewManager to find the controller class. One example:

ViewManager.views[Utils.capitalize(SUGAR.App.config.platform) + 'AlertView'];

So unfortunately it does not additionally check for ... + 'CustomAlertView' which would probably solve the issue (quick test via js debugger).

Also i don't see a way to modify/extend/hookup the sidecar/src/view/alert.js or sidecar/src/view/alert-view.js

Best regards

Parents
  • You can write your own javascript in custom/include/javascript and augment the alert, by providing your own code for the functions that you want to override:

    app.augment('alert',{
    /**
    * Override your own functions here
    */
    });

    Once done, include the new file in jsgroups and rebuild the js grouping files in Admin->Repair.

  • Hi ,

    thanks for the answer. I did not know about app.augment before and it seemed like a good start. But to me it looked like it overrides the whole app.alert feature with what i pass which i do not want. I wanted to add another alert-level and a new template (hbs) file to allow for other alerts like one with more than two buttons. 

    The main problem was that i could not register the custom controller under custom/clients/base/views/alert/alert.js the usual way as i described earlier.

    After some try and error, i could set the view class of the alert feature like this with a jsgroups file and use the normal controller style like for every other extension under custom/clients/base/.

    (function (app) {
        app.events.on('app:init', function () {
            app.alert.klass = app.utils.extendClass(
                app.view.views,
                app.view.views.BaseAlertView,
                'BaseCustomAlertView', {
                    // Custom Controller
                    initialize: function(options) {
                        this._super('initialize', [options])
    
                        this.LEVEL = _.extend(this.LEVEL, {
                            CUSTOM_LEVEL: 'custom_level', // add custom/
                        });
                    },
                    _getAlertProps: function (options) {
                        var alertProps = this._super('_getAlertProps', [options]);
                        
                        // add handle for custom level
                    }
                }
            )
        })
    })(SUGAR.App);
    

Reply
  • Hi ,

    thanks for the answer. I did not know about app.augment before and it seemed like a good start. But to me it looked like it overrides the whole app.alert feature with what i pass which i do not want. I wanted to add another alert-level and a new template (hbs) file to allow for other alerts like one with more than two buttons. 

    The main problem was that i could not register the custom controller under custom/clients/base/views/alert/alert.js the usual way as i described earlier.

    After some try and error, i could set the view class of the alert feature like this with a jsgroups file and use the normal controller style like for every other extension under custom/clients/base/.

    (function (app) {
        app.events.on('app:init', function () {
            app.alert.klass = app.utils.extendClass(
                app.view.views,
                app.view.views.BaseAlertView,
                'BaseCustomAlertView', {
                    // Custom Controller
                    initialize: function(options) {
                        this._super('initialize', [options])
    
                        this.LEVEL = _.extend(this.LEVEL, {
                            CUSTOM_LEVEL: 'custom_level', // add custom/
                        });
                    },
                    _getAlertProps: function (options) {
                        var alertProps = this._super('_getAlertProps', [options]);
                        
                        // add handle for custom level
                    }
                }
            )
        })
    })(SUGAR.App);
    

Children
No Data