Hey Community,

 

I have two details on my custom "Order" entity. Depends on order status i need to show/hide add button and the possibility to edit this details.

Is there any best practices for this scenario?



Thanks for help,

Oleksiis

Like 1

Like

6 comments
Best reply

Hello, 

Here is an example of how to hide the Add button in detail based on the condition:

define("UsrSchemaaae5d57eDetail", ["ConfigurationGrid", "ConfigurationGridGenerator",
	"ConfigurationGridUtilitiesV2"], function() {
	return {
		entitySchemaName: "UsrForHideTest",
		attributes: {
                -------------
			"IsAddEnabled": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				value: true
			}
		},
                -------------
		methods: {
                --------------
			init: function() {
				this.callParent(arguments);
				this.isAddEnabled();
			},
			isAddEnabled: function() {
				var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                        rootSchemaName: "Contact"
                    });
                    esq.addColumn("Type");
                     esq.getEntity(this.values.MasterRecordId, function(result) {
                        if (result.success && result.entity.values.Type.displayValue == 'Customer') {
                            this.set("IsAddEnabled", false);
                        }
                    }, this);
			}
		},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "AddRecordButton",
				"values": {
					"visible": {"bindTo": "IsAddEnabled"}
				}
			},

Here we are hiding the button if the Type of the Contact = 'Customer'.

Regarding the editing of the detail, if I`m not mistaken, you cannot change it dynamically. 

Upd

I found the code snippet to hide Add button and added it to page - 

 

			isDetailEnabled: function(detailName) {
      		var productionStage = this.get("RdtStatus").displayValue;   
			if (detailName === "RdtSchemad16d4a3eDetail") {
			if(productionStage === "Planned"){
                    return true;       //Disable the "+" button
                }
                else{
                    return false;        //Enable the "+" button
                }
	}
			if (detailName === "RdtSchema670160a3Detail") {
			if(productionStage === "Planned"){
                    return true;       //Disable the "+" button
                }
                else{
                    return false;        //Enable the "+" button
                }
	}
			return this.callParent(arguments);
}

But now i have issue with clicking on data on editable grid



Hello,

not sure about best practices but for me isDetailEnabled also caused issues like that. I implemented this logic with replacing method in Detail code like this:

getAddRecordButtonEnabled: function() {
				var instance = this;
				var isEditable = instance.get("IsProductDetailEditable");
				return isEditable && this._isAddRecordButtonEnabled();
			},

adding attribute IsProductDetailEditable and settiging its value in onGridDataLoaded method override with an esq check of the parent page Status or any other condition you would need. This would cover add button, for the changes of existing rows you could add buisness rules for each field to block them for certain conditions, in my case implemented an esq check on save logic, with replacing method saveRowChanges from ConfigurationGridUtilities, check result would notify the user unability to save changes for that condition or proceed as normal.

Hello, 

Here is an example of how to hide the Add button in detail based on the condition:

define("UsrSchemaaae5d57eDetail", ["ConfigurationGrid", "ConfigurationGridGenerator",
	"ConfigurationGridUtilitiesV2"], function() {
	return {
		entitySchemaName: "UsrForHideTest",
		attributes: {
                -------------
			"IsAddEnabled": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				value: true
			}
		},
                -------------
		methods: {
                --------------
			init: function() {
				this.callParent(arguments);
				this.isAddEnabled();
			},
			isAddEnabled: function() {
				var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                        rootSchemaName: "Contact"
                    });
                    esq.addColumn("Type");
                     esq.getEntity(this.values.MasterRecordId, function(result) {
                        if (result.success && result.entity.values.Type.displayValue == 'Customer') {
                            this.set("IsAddEnabled", false);
                        }
                    }, this);
			}
		},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "AddRecordButton",
				"values": {
					"visible": {"bindTo": "IsAddEnabled"}
				}
			},

Here we are hiding the button if the Type of the Contact = 'Customer'.

Regarding the editing of the detail, if I`m not mistaken, you cannot change it dynamically. 

Dmytro Vovchenko writes:

Hello, 

Here is an example of how to hide the Add button in detail based on the condition:


 
define("UsrSchemaaae5d57eDetail", ["ConfigurationGrid", "ConfigurationGridGenerator",
	"ConfigurationGridUtilitiesV2"], function() {
	return {
		entitySchemaName: "UsrForHideTest",
		attributes: {
                -------------
			"IsAddEnabled": {
				dataValueType: Terrasoft.DataValueType.BOOLEAN,
				value: true
			}
		},
                -------------
		methods: {
                --------------
			init: function() {
				this.callParent(arguments);
				this.isAddEnabled();
			},
			isAddEnabled: function() {
				var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                        rootSchemaName: "Contact"
                    });
                    esq.addColumn("Type");
                     esq.getEntity(this.values.MasterRecordId, function(result) {
                        if (result.success && result.entity.values.Type.displayValue == 'Customer') {
                            this.set("IsAddEnabled", false);
                        }
                    }, this);
			}
		},
		diff: /**SCHEMA_DIFF*/[
			{
				"operation": "merge",
				"name": "AddRecordButton",
				"values": {
					"visible": {"bindTo": "IsAddEnabled"}
				}
			},

Here we are hiding the button if the Type of the Contact = 'Customer'.

Regarding the editing of the detail, if I`m not mistaken, you cannot change it dynamically. 

 

Thanks so much, will take a look on this.

Dmytro Vovchenko,

I tried your code-snippet for this implementation and seems the code not running with editable details. And code triggered only when opening the edit page of detail. 

So on the main page where details exists the Add button still visible :(

Show all comments

Hi community,

 

I read the article (https://community.creatio.com/questions/add-action-detail) in Creatio community and added a button in the action menu of our order product detail.

But the visibility seems not working. May you help me to adjust the code below? What I

need is to show the button when some detail records are selected, and hide the button otherwise.

 

                     addToolsButtonMenuItems: function(toolsButtonMenu) {

                             this.callParent(arguments);

                             toolsButtonMenu.addItem(this.getButtonMenuSeparator());

                             toolsButtonMenu.addItem(this.getButtonMenuItem({

                               Caption: this.get("Resources.Strings.UsrBtnBatchUpdate"),

                               Click: {"bindTo": "OnButonClick"},

                               Visible: {"bindTo": "IsSelectRecord"}

                             }));

                     },

 

Thanks a lot!

Like 0

Like

2 comments
Best reply

Hi Andrew,

 

Please use the following approach:

methods: {
				addToolsButtonMenuItems: function(toolsButtonMenu) {
					this.callParent(arguments);
					toolsButtonMenu.addItem(this.getButtonMenuSeparator());
					toolsButtonMenu.addItem(this.getButtonMenuItem({
						Caption: {"bindTo": "Resources.Strings.CustomButton"},
						Click: {"bindTo": "onButonClick"},
						Visible: {"bindTo": "getCustomButtonVisible"},
					}));
				},
				getCustomButtonVisible: function() {
					return this.isSingleSelected();
				},
				onButonClick: function() {
					console.log("Clicked!");
				}
			},

there is no IsSelectRecord base attribute that will make the button visible or invisible, thus there are basic methods to make "Edit" or "Copy" buttons enabled\disabled so I've used the logic behind them as an example to make the custom button visible.

Hi Andrew,

 

Please use the following approach:

methods: {
				addToolsButtonMenuItems: function(toolsButtonMenu) {
					this.callParent(arguments);
					toolsButtonMenu.addItem(this.getButtonMenuSeparator());
					toolsButtonMenu.addItem(this.getButtonMenuItem({
						Caption: {"bindTo": "Resources.Strings.CustomButton"},
						Click: {"bindTo": "onButonClick"},
						Visible: {"bindTo": "getCustomButtonVisible"},
					}));
				},
				getCustomButtonVisible: function() {
					return this.isSingleSelected();
				},
				onButonClick: function() {
					console.log("Clicked!");
				}
			},

there is no IsSelectRecord base attribute that will make the button visible or invisible, thus there are basic methods to make "Edit" or "Copy" buttons enabled\disabled so I've used the logic behind them as an example to make the custom button visible.

Oleg Drobina,

Thank you for your guid!. It works for a single detail record selected, like the behavior of "Edit" or "Copy".

What I want is the like the behavior of "Delete", and I found the solution in the academy.

In summary, I just adjusted the code below to approach the behavior like "Delete" action.

 

getCustomButtonVisible: function() {

    var selectedRows = this.get("SelectedRows");

    return selectedRows ? (selectedRows.length > 0) : false;

},

 

Thank you!

Show all comments

Is there a way to hide the button on a detail page when the parent page status has changed upon checking on initialize?

 

I tried to create an attribute that will be set to true when the parent status is 'order processing' and bind it to the visible property of the button but it doesn't work.

 

"className": "Terrasoft.ConfigurationGrid",
"generator": "ConfigurationGridGenerator.generatePartial",
"generateControlsConfig": {"bindTo": "generateActiveRowControlsConfig"},
"changeRow": {"bindTo": "changeRow"},
"unSelectRow": {"bindTo": "unSelectRow"},
"onGridClick": {"bindTo": "onGridClick"},
"activeRowActions": [
	{
		"className": "Terrasoft.Button",
		"style": this.Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
		"tag": "save",
		"markerValue": "save",
		"imageConfig": {"bindTo": "Resources.Images.SaveIcon"},
		"visible": {"bindTo": "IsOrderProcessing"}
	},...
init: function() {
	debugger;
	this.callParent(arguments);
 
	var orderId = this.$MasterRecordId;
	var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
		rootSchemaName: "Order"
	});
 
	esq.addColumn("Status", "Status");
	esq.getEntity(orderId, function (result) {
		debugger;
		if (!result.success) {
			this.showInformationDialog("Data query error");
			return;
		}
		if (result.entity) {
			var orderStatus = result.entity.get("Status");
 
			if (orderStatus.value === "3f7523c5-f066-4bb6-bfd8-b2156fb42f13") { // Order Processing
				this.set("IsOrderProcessing", true);
			}
			else {
				this.set("IsOrderProcessing", false);
			}
		}
 
	}, this);
}

 

Like 0

Like

1 comments

Hi Community, has anybody have an idea on this?

Show all comments