Mach eine neue Typescript Funktion asyncConfirm . In die Datei asyncConfirm.ts schreibst du dies:
module TcHmi {
export module Functions {
export function asyncConfirm(ctx: TcHmi.Context<boolean>, message: any) {
const okButton = document.createElement('button');
okButton.textContent = 'Ok';
const okFnc = () => {
TcHmi.TopMostLayer.removeEx($(questionDiv));
ctx.success?.(true);
};
okButton.addEventListener('click', okFnc);
const cancelButton = document.createElement('button');
cancelButton.textContent = 'Cancel';
const cancelFnc = () => {
TcHmi.TopMostLayer.removeEx($(questionDiv));
ctx.success?.(false);
};
cancelButton.addEventListener('click', cancelFnc);
const questionDiv = document.createElement('div');
questionDiv.style.cssText = 'background-color: white;padding:20px; margin:20px;'
questionDiv.append(
message,
document.createElement('br'),
okButton,
' ',
cancelButton
);
TcHmi.TopMostLayer.addEx($(questionDiv), {
centerHorizontal: true,
centerVertical: true,
removeCb: (data) => {
if (data.canceled) {
cancelFnc();
}
}
});
}
registerFunctionEx('asyncConfirm', 'TcHmi.Functions', asyncConfirm);
}
}
asyncConfirm.funtion.json dies:
{
"function": {
"name": "asyncConfirm",
"namespace": "TcHmi.Functions",
"displayName": "asyncConfirm",
"description": "",
"waitMode": "Asynchronous",
"category": "",
"returnValue": {
"type": "tchmi:general#/definitions/Boolean"
},
"visible": true,
"injectContextObject": true,
"arguments": [
{
"name": "ctx",
"displayName": "ctx",
"type": "tchmi:framework#/definitions/ContextReference",
"description": "Context Reference",
"defaultValue": "",
"required": true,
"bindable": false,
"restParameter": false,
"asReference": false,
"allowControlAttributeBindingOptions": false
},
{
"name": "message",
"displayName": "message",
"type": "tchmi:general#/definitions/String",
"description": "Message to show",
"defaultValue": "",
"required": true,
"bindable": true,
"restParameter": false,
"asReference": false,
"allowControlAttributeBindingOptions": false
}
]
},
"$schema": "./../Packages/Beckhoff.TwinCAT.HMI.Framework.12.750.1/runtimes/native1.12-tchmi/Schema/FunctionDescription.Schema.json",
"apiVersion": 1,
"version": {
"full": "0.0.0.0",
"major": 0,
"minor": 0,
"revision": 0,
"build": 0
},
"dependencyFiles": [
{
"name": "asyncConfirm.js",
"type": "JavaScript",
"description": ""
}
]
}
Dann kannst du im Actions und condition Fenster eine neue condition reinziehen.
In das Feld rechts kommt true rein (ohne Anführungszeichen).
links schreibst du:
TcHmi.Functions.asyncConfirm('Ask whatever you like')
Achtung, per Drag und drop kommt da manchmal noch ein <ctx> mit rein, dass muss weg.
Damit führt ein die Sachen bei "Then" aus, wenn du OK drückst, und die Sachen bei "Else", wenn du Cancel drückst.