Case:
We want to hide print button for some opportunity stages
Algorithm of realization:
- You should create replacing client schema for OpportunityPageV2 and OpportunitySectionV2.
-
Create attributes on both pages:
attributes: { "isPrintButtonVisible": { "dataValueType": Terrasoft.DataValueType.BOOLEAN } }
in addition add on Opportunity page:
"Stage": { "onChange": "onStageChanged" }
-
Create message which will send stage from OpportunityPage to OpportunitySection when we work in combined mode.
Add following code to OpportunitySection:
messages: { "PrintButtonVisibleMessage": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.SUBSCRIBE } },
And to OpportunityPage:
messages: { "PrintButtonVisibleMessage": { mode: Terrasoft.MessageMode.PTP, direction: Terrasoft.MessageDirectionType.PUBLISH } },
-
Create methods which will set button visibility and publish message about it on OpportunityPage:
printButtonVisiblePublishMessage: function() { return this.sandbox.publish("PrintButtonVisibleMessage", this.get("isPrintButtonVisible"), ["key"]); }, onStageChanged: function() { this.setPrintButtonVisibility(); this.printButtonVisiblePublishMessage(); }, setPrintButtonVisibility: function() { var stage = this.get("Stage"); if (stage.value === "423774cb-5ae6-df11-971b-001d60e938c6") { this.set("isPrintButtonVisible", true); } else { this.set("isPrintButtonVisible", false); } }
-
Create methods which will handle stage changing on OpportunitySection if we work in combined mode
init: function() { this.callParent(arguments); this.sandbox.subscribe("PrintButtonVisibleMessage", this.onPrintButtonVisibleMessage, this, ["key"]); }, onPrintButtonVisibleMessage: function(isButtonVisible) { this.set("isPrintButtonVisible", isButtonVisible); }
-
Bind button visibility to isPrintButtonVisible attribute
-
OpportunityPage
{ "operation": "merge", "name": "PrintButton", "values": { "visible": { "bindTo": "isPrintButtonVisible" } } },
-
OpportunitySection
{ "operation": "merge", "name": "CombinedModePrintButton", "values": { "visible": { "bindTo": "isPrintButtonVisible" } } }
-