Question

Is it possible to make a control disabled/enabled based on if user is member of a department using page business rules?

Is it possible to make a control disabled/enabled based on if user is member of a department using page business rules? I tried setting that up like this, but didn't work (I wasn't really expecting it to since it looks strange)

Is the only way to do this by binding the fields enabled property to a function in the page VM that performs the department check? Or set up as access rights for the column permissions? Or can this be done using the page business rules and I just set it up incorrectly? 

Thanks.

Ryan

Like 0

Like

2 comments

Hello Ryan,



The best way to implement your task is to bind control enabled property to virtual attribute and get it`s value from overrided onEntityInitialized method Here is an example where I created replacing client module for contact edit page with button that is disabled for everyone except sysAdmins.

 

define("ContactPageV2", ["ConfigurationConstants"],

    function(ConfigurationConstants) {

        return {

            entitySchemaName: "Contact",

            details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,

            methods: {

                    getUserRights: function() {

                        var scope = this;

                        

                        var currentUser = Terrasoft.SysValue.CURRENT_USER.value;

                        var sysAdmins = ConfigurationConstants.SysAdminUnit.Id.SysAdministrators;

                        var esq = Ext.create("Terrasoft.EntitySchemaQuery", { rootSchemaName: "SysUserInRole" });

                        esq.addColumn("SysRole");

                        esq.addColumn("SysUser");

                        esq.filters.add("SysUser", Terrasoft.createColumnFilterWithParameter(

                            Terrasoft.ComparisonType.EQUAL, "SysUser", currentUser));

                        esq.filters.add("SysRole", Terrasoft.createColumnFilterWithParameter(

                            Terrasoft.ComparisonType.EQUAL, "SysRole", sysAdmins));

                        esq.getEntityCollection(function(response) {

                            if (response && response.success) {

                                var result = response.collection;

                                var isSysAdmin = (result.collection.length !== 0);

                                scope.set("isAdmin", isSysAdmin);

                        }

                         }, this);

                    },

            

                    onEntityInitialized: function() {

                        this.callParent(arguments);

                        this.getUserRights();

                    }

            },

            attributes: {

                "isAdmin": {

                  "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,

                  "dataValueType": Terrasoft.DataValueType.BOOLEAN,

                  "value": false

                }

            },

            

            diff: /**SCHEMA_DIFF*/[

                

           

                {

                

                    "operation": "insert",

                 

                    "parentName": "LeftContainer",

                   

                    "propertyName": "items",

                    

                    "name": "GetServiceInfoButton",

                   

                    "values": {

                   

                        itemType: Terrasoft.ViewItemType.BUTTON,

                    

                        caption: "12345",

                       

                        enabled: {bindTo: "isAdmin"},

                       

                        "layout": {"column": 1, "row": 6, "colSpan": 2, "rowSpan": 1}

                    }

                }

            ]/**SCHEMA_DIFF*/,

        };

    });



Best wishes,

Alex

Alex_Tim,

That is a great idea. Thank you.

Ryan

Show all comments