Question
How can I pass infromation from ModalBox?
Answer
1) Crreate a MoalBox page - "Model schema of the page view" without specifying the parent schema:
define("UsrMyModalPage", ["ModalBox"], function(ModalBox) {
return {
attributes: {
"TestText": {
dataValueType: Terrasoft.DataValueType.TEXT,
type: Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN
}
},
messages: {
"DataFromModal": {
mode: Terrasoft.MessageMode.PTP,
direction: Terrasoft.MessageDirectionType.PUBLISH
}
},
methods: {
init: function(callback, scope) {
this.callParent(arguments);
},
onRender: function() {
},
onCloseButtonClick: function() {
this.sandbox.publish("DataFromModal", { test: this.get("TestText") }, [this.sandbox.id]);
ModalBox.close();
}
},
diff: [
{
"operation": "insert",
"name": "MyContainer",
"propertyName": "items",
"values": {
"itemType": Terrasoft.ViewItemType.CONTAINER,
"items": []
}
},
{
"operation": "insert",
"parentName": "MyContainer",
"propertyName": "items",
"name": "MyGridContainer",
"values": {
"itemType": Terrasoft.ViewItemType.GRID_LAYOUT,
"items": []
}
},
{
"operation": "insert",
"parentName": "MyGridContainer",
"propertyName": "items",
"name": "TestText",
"values": {
"bindTo": "TestText",
"caption": "Test text",
"layout": {"column": 0, "row": 0, "colSpan": 10}
}
},
{
"operation": "insert",
"parentName": "MyGridContainer",
"name": "CloseButton",
"propertyName": "items",
"values": {
"itemType": Terrasoft.ViewItemType.BUTTON,
"style": Terrasoft.controls.ButtonEnums.style.BLUE,
"click": {bindTo: "onCloseButtonClick"},
"markerValue": "CloseButton",
"caption": "OK",
"layout": { "column": 0, "row": 1, "colSpan": 3 }
}
}
]
};
});
2) Create the ModalBox module - "Module" with a single dependancy from the above mentioned page.
define("UsrMyModalModule", ["ModalBox", "BaseSchemaModuleV2"],
function(ModalBox) {
Ext.define("Terrasoft.configuration.UsrMyModalModule", {
extend: "Terrasoft.BaseSchemaModule",
alternateClassName: "Terrasoft.UsrMyModalModule",
/** * @inheritDoc Terrasoft.BaseSchemaModule#generateViewContainerId * @overridden */
generateViewContainerId: false,
/** * @inheritDoc Terrasoft.BaseSchemaModule#initSchemaName * @overridden */
initSchemaName: function() {
this.schemaName = "UsrMyModalPage";
},
/** * @inheritDoc Terrasoft.BaseSchemaModule#initHistoryState * @overridden */
initHistoryState: Terrasoft.emptyFn,
});
return Terrasoft.UsrMyModalModule;
});
3) Create a replacing edit page for adding the created ModalBox:
define("ContactPageV2", ["ContactPageV2Resources", "GeneralDetails", "ModalBox"],
function(resources, GeneralDetails, ModalBox) {
return {
entitySchemaName: "Contact",
messages: {
"DataFromModal": {
mode: Terrasoft.MessageMode.PTP,
direction: Terrasoft.MessageDirectionType.SUBSCRIBE
}
},
details: /**SCHEMA_DETAILS*/{
}/**SCHEMA_DETAILS*/,
methods: {
subscribeSandboxEvents: function() {
this.callParent(arguments);
this.sandbox.subscribe("DataFromModal", function(arg) {
console.log("msg from modal: " + arg.test);
}, this, [this.sandbox.id + "_" + "UsrMyModalModule"]);
},
loadMyModal: function() {
var sandbox = this.sandbox;
var config = {
heightPixels: 420,
widthPixels: 750
};
var moduleName = "UsrMyModalModule";
var moduleId = sandbox.id + "_" + moduleName;
var renderTo = ModalBox.show(config, function() {
sandbox.unloadModule(moduleId, renderTo);
});
sandbox.loadModule(moduleName, {
id: moduleId,
renderTo: renderTo
});
},
onMyClick: function() {
this.loadMyModal();
},
onEntityInitialized: function() {
this.callParent(arguments);
}
},
diff: /**SCHEMA_DIFF*/[
{
"operation": "insert",
"parentName": "CombinedModeActionButtonsCardContainer",
"propertyName": "items",
"name": "MainContactButton",
"values": {
"itemType": Terrasoft.ViewItemType.BUTTON,
"caption": "пыщь-пыщь",
"click": {"bindTo": "onMyClick"}
}
}
]/**SCHEMA_DIFF*/
};
});