Tracking the state of an attribute of another replacement module
Condition:
The button should be available if the current contact is male (corresponding value for the corresponding field on the contact page). The availability of the button takes into account the change of the field.
Implement button state tracking by binding the "enabled" property of the button to an attribute ("attributes" property) of a Boolean type.
The button should work in combined (combined) mode. This mode is enabled when you open any entry in the section in the current browser tab. In fact, the entry opens on the client schema of the section (in the address bar of the browser, you can see that the client schema is now the Section of the section). To open an entry in client-side page schema mode (the address bar will have a Section Page), either open the section entry in a new browser tab, or open the section entry in the current browser tab and refresh the page.
To implement the data exchange to track the state of the button, you need to use Sandbox.
I have a problem, I don't know how to track attribute state in ContactSectionV2 from ContactPageV2 using SandBox? I am unable to control access in ContactSectionV2.
define("ContactPageV2", [], function() { return { entitySchemaName: "Contact", attributes: { "ButtonEnabled": { "dataValueType": Terrasoft.DataValueType.BOOLEAN, "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN, } }, messages: { "MessageOnPageClick": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.SUBSCRIBE }, "MessageIsButtonEnabled": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.SUBSCRIBE } }, methods: { onEntityInitialized: function() { this.callParent(arguments); this.setButtonEnabled(); this.sandbox.subscribe("MessageOnPageClick", function() { return this.onPageClick(); }, this, ["SectionModuleV2_ContactSectionV2"]); this.sandbox.subscribe("MessageIsButtonEnabled", function() { alert(osfeofksepofkpo); return this.setButtonEnabled(); }, this, ["SectionModuleV2_ContactSectionV2"]); }, onSaved: function() { this.callParent(arguments); this.setButtonEnabled(); }, onPageClick: function() { this.showInformationDialog(";;;;;;"); }, setButtonEnabled: function() { var buttonEnabledValue = this.get("ButtonEnabled"); if (this.get("Gender") != null && this.get("Gender").value == "eeac42ee-65b6-df11-831a-001d60e938c6") { this.set("ButtonEnabled", true); this.sandbox.subscribe("MessageIsButtonEnabled", function() { alert(true); return this.set("ButtonEnabled", true); }, this, ["SectionModuleV2_ContactSectionV2"]); } else { this.set("ButtonEnabled", false); this.sandbox.subscribe("MessageIsButtonEnabled", function() { alert(false); return this.set("ButtonEnabled", false); }, this, ["SectionModuleV2_ContactSectionV2"]); } } }, diff: [{ "operation": "insert", "parentName": "LeftContainer", "propertyName": "items", "name": "NewButton", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "caption": { bindTo: "Resources.Strings.CaptionButton" }, "classes": { "textClass": "actions-button-margin-right" }, "style": Terrasoft.controls.ButtonEnums.style.BLUE, "enabled": {bindTo: "ButtonEnabled"}, "click": {bindTo: "onPageClick"} } }] /**SCHEMA_DIFF*/ }; }); define("ContactSectionV2", [], function() { return { entitySchemaName: "Contact", messages: { "MessageOnPageClick": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.PUBLISH }, "MessageIsButtonEnabled": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.PUBLISH } }, methods: { onCardRendered: function() { this.callParent(arguments); this.onSectionButtonEnabled(); }, onSectionClick: function() { this.sandbox.publish("MessageOnPageClick", null, [this.sandbox.id]); }, onSectionButtonEnabled: function(message) { this.sandbox.publish("MessageIsButtonEnabled", null, [this.sandbox.id]); } }, diff: /**SCHEMA_DIFF*/[ { "operation": "insert", "parentName": "CombinedModeActionButtonsCardLeftContainer", "propertyName": "items", "name": "NewButton", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "caption": {bindTo: "Resources.Strings.NewButtonCaption"}, "classes": {"textClass": "actions-button-margin-right"}, "click": {bindTo: "onSectionClick"}, "style": Terrasoft.controls.ButtonEnums.style.RED, "enabled": {bundTo: "ButtonEnabled"} } } ]/**SCHEMA_DIFF*/ }; });
Like
Erlan Ibraev,
It will do the needed action, I've tested this code before providing it. The code is added to be used in the combined mode which means that when you open the contact page from the section then the logic from the ContactSectionV2 will be triggered (your initial question).
To achieve the result:
1) Display the "Gender" column in the section list
2) Replace the code in the ContactSectionV2 with the code attached:
define("ContactSectionV2", [], function() { return { entitySchemaName: "Contact", messages: {}, attributes: { "ButtonEnabled": { "dataValueType": Terrasoft.DataValueType.BOOLEAN, "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN, "value": true } }, methods: { onCardRendered: function() { this.callParent(arguments); var gridData = this.get("GridData"); var activeRow = this.get("ActiveRow"); if (gridData) { if (activeRow) { var activeRowData = gridData.get(activeRow); var activeRowDataGender = activeRowData.get("Gender"); if (activeRowDataGender) { var enableButton = activeRowDataGender.displayValue !== "Female"; this.set("ButtonEnabled", enableButton); } else { this.set("ButtonEnabled", false); } } } }, }, diff: /**SCHEMA_DIFF*/[ { "operation": "insert", "parentName": "CombinedModeActionButtonsCardLeftContainer", "propertyName": "items", "name": "NewButton", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "caption": {bindTo: "Resources.Strings.NewButtonCaption"}, "classes": {"textClass": "actions-button-margin-right"}, "click": {bindTo: "onSectionClick"}, "style": Terrasoft.controls.ButtonEnums.style.RED, "enabled": {bindTo: "ButtonEnabled"} } } ]/**SCHEMA_DIFF*/ }; });
This will make the button to be enabled only in case gender of the current contact is "Male" and will be disabled in case gender of the current contact is "Female" or empty.
Олег Дробина,
But I need Enabled to depend on an attribute which is in ContactPageV2
Erlan Ibraev,
It will do the needed action, I've tested this code before providing it. The code is added to be used in the combined mode which means that when you open the contact page from the section then the logic from the ContactSectionV2 will be triggered (your initial question).