ESQ Async Client Side

Hello community,

 

I'm using isDetailEnabled method in client side to remove add button in detail based on specific conditions. For users in "System Administrator" role I want to allow the add button for every detail. 

 

 JSCODE:

isDetailEnabled: function(detailName) {
    			var esq =  Ext.create("Terrasoft.EntitySchemaQuery", {
						rootSchemaName: "SysUserInRole"
				});
				esq.addColumn("SysRole");
				// add filter for current user
				esq.filters.add("UserFilter", Terrasoft.createColumnFilterWithParameter(
					Terrasoft.ComparisonType.EQUAL, "SysUser", Terrasoft.SysValue.CURRENT_USER.value
				));
				// add filter for role name, joining to SysRole (which is where the name is stored)
				esq.filters.add("RoleFilter", Terrasoft.createColumnFilterWithParameter(
					Terrasoft.ComparisonType.EQUAL, "SysRole.Id", "83a43ebc-f36b-1410-298d-001e8c82bcad" 
				));
               esq.getEntityCollection(function(result) {
                        if (result.success && result.collection.getItems().length > 0) {
                              return true;
                        }
                       return false;
               });
                return this.callParent(arguments);
}

 

Like 0

Like

1 comments

Since EntitySchemaQuery is asynchronous, it doesn't wait for the results to return before the isDetailEnabled function returns. You'll need to pre-fetch if the user is in the role (maybe in the init, or elsewhere) and save that result in an attribute or something, then just check the attribute from the isDetailEnabled function. Does that make sense?

Ryan

Show all comments