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*/
};
});