Question

Confused | ESQ and Attribute

Why is this not working? I am genuinely confuse.



Setting visibility using ESQ is not working. Am I missing something?

 

define("OpportunitySectionV2", ["ConfigurationConstants"], function(ConfigurationConstants) {
	return {
		entitySchemaName: "Opportunity",
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		attributes: {
			"isSysAdmin": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
				value: false
			}
		},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "DataGridActiveRowDeleteAction",
				"values": {
					"visible": {
						"bindTo": "isSysAdmin"
					}
				}
			}
		]/**SCHEMA_DIFF*/,
		methods: {
			onGridDataLoaded: function() {
				this.callParent(arguments);
				this.getUserRights();
			},
			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);
						debugger;
						scope.set("isSysAdmin", isSysAdmin);
					}
				}, this);
			},
		}
	};
});

Thank you.

Solem A.

Like 1

Like

5 comments
Best reply

Solem Khan Abdusalam,

It's been a bit since I last tried this, but I've tried binding visible (and caption) of buttons in ActiveRowActions and they never seem to work. 

I do this instead: Check and store in the attribute if the user has the needed role. Then, in the method that adds the delete action, do something like this: 

getDeleteRecordMenuItem: function() {
    if (this.get("isSysAdmin")) {
        return this.callParent(arguments);
    }
}

This way, the delete button is never added since when the method is called, it only calls the parent if the user has the role. 

Note, you have to pre-fetch the user's role earlier, before the getDeleteRecordMenuItem is called. Since the ESQ is asynchronous you can't call it in within that method.

Ryan

hi Solem Khan Abdusalam,

 

Please call the getUserRights() method inside init : function() as below

init: function() {
    this.callParent(arguments);
    this.getUserRights();
},

Also, Object permission can be used to achieve the functionality (though the button is visible the operation to add, delete can't be performed).

 

 

BR,

Bhoobalan Palanivelu.

Bhoobalan Palanivelu,



Yes I disabled the role to delete but I need the button to disappear.

Will it work in init? It's ESQ. I tried doing this.set() in without the ESQ and it is not working. Is attribute binding not working anymore?



I am trying to remove the delete button in ListView at Section.

 

//

 

I tried removing methods just to test if attributes works, and it didn't

		attributes: {
			"isSysAdmin": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
				value: true
			}
		},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "DataGridActiveRowDeleteAction",
				"values": {
					"visible": {
						"bindTo": "isSysAdmin"
					}
				}
			}
		]/**SCHEMA_DIFF*/,

 

Solem Khan Abdusalam,

It's been a bit since I last tried this, but I've tried binding visible (and caption) of buttons in ActiveRowActions and they never seem to work. 

I do this instead: Check and store in the attribute if the user has the needed role. Then, in the method that adds the delete action, do something like this: 

getDeleteRecordMenuItem: function() {
    if (this.get("isSysAdmin")) {
        return this.callParent(arguments);
    }
}

This way, the delete button is never added since when the method is called, it only calls the parent if the user has the role. 

Note, you have to pre-fetch the user's role earlier, before the getDeleteRecordMenuItem is called. Since the ESQ is asynchronous you can't call it in within that method.

Ryan

Ryan Farley,



Would this work on Section?

For a section you can override checkCanDelete to return a boolean indicating if the user can delete or not.  Sadly it won't remove the delete button, will instead just give them a message that they can't delete (which is how it works out of the box).

Ryan

Show all comments