|
8 | 8 | /// <reference path="C:\TwinCAT\Functions\TE2000-HMI-Engineering\Infrastructure\TcHmiFramework\Latest\TcHmi.js" />
|
9 | 9 |
|
10 | 10 | (function (TcHmi) {
|
11 |
| - // If you want to unregister an event outside the event code you need to use the return value of the method register() |
12 |
| - var destroyOnInitialized = TcHmi.EventProvider.register('onInitialized', function (e, data) { |
13 |
| - // This event will be raised only once, so we can free resources. |
14 |
| - // It's best practice to use destroy function of the event object within the callback function to avoid conflicts. |
15 |
| - e.destroy(); |
| 11 | + // If you want to unregister an event outside the event code you need to use the return value of the method register() |
| 12 | + var destroyOnInitialized = TcHmi.EventProvider.register( |
| 13 | + "onInitialized", |
| 14 | + function (e, data) { |
| 15 | + // This event will be raised only once, so we can free resources. |
| 16 | + // It's best practice to use destroy function of the event object within the callback function to avoid conflicts. |
| 17 | + e.destroy(); |
16 | 18 |
|
17 |
| - function composeHtmlPopUpElement(event) { |
18 |
| - return $( |
19 |
| - '<div style="background:white;padding:10px;max-width:400px;">' |
20 |
| - + event.text + '<br><br>' |
21 |
| - + '<button type="button" onclick = ' |
22 |
| - + '"var topLayer=document.getElementsByClassName(\'tchmi-in-topmostlayer\');' |
23 |
| - + 'var currentTop=topLayer[topLayer.length - 1];' |
24 |
| - + 'TcHmi.TopMostLayer.removeEx($(currentTop));"> OK' |
25 |
| - + '</button> ' |
26 |
| - + '</div>'); |
27 |
| - } |
28 |
| - |
29 |
| - function showPopUp(event) { |
30 |
| - var newPopUp = composeHtmlPopUpElement(event) |
31 |
| - TcHmi.TopMostLayer.addEx(newPopUp, { |
32 |
| - centerHorizontal: true, |
33 |
| - centerVertical: true, |
34 |
| - removecb: (data) => { |
35 |
| - if (data.canceled) { |
36 |
| - // user clicked on the background |
37 |
| - TcHmi.TopMostLayer.removeEx(newPopUp); |
38 |
| - } |
39 |
| - } |
40 |
| - }); |
41 |
| - } |
| 19 | + function composeHtmlPopUpElement(event) { |
| 20 | + return $( |
| 21 | + '<div style="background:white;padding:10px;max-width:400px;">' + |
| 22 | + event.text + |
| 23 | + "<br><br>" + |
| 24 | + '<button type="button" onclick = ' + |
| 25 | + "\"var topLayer=document.getElementsByClassName('tchmi-in-topmostlayer');" + |
| 26 | + "var currentTop=topLayer[topLayer.length - 1];" + |
| 27 | + 'TcHmi.TopMostLayer.removeEx($(currentTop));"> OK' + |
| 28 | + "</button> " + |
| 29 | + "</div>" |
| 30 | + ); |
| 31 | + } |
42 | 32 |
|
43 |
| - // subscripton that is called if an event inside the list changes his state |
44 |
| - function subscriptionCallback(data) { |
45 |
| - // check if the callback object is valid |
46 |
| - if (data.error === TcHmi.Errors.NONE) { |
47 |
| - // check if the alarm type is raised |
48 |
| - if (data.changeType === TcHmi.Server.Events.ChangeType.AlarmRaised) { |
49 |
| - showPopUp(data.event); |
50 |
| - } |
| 33 | + function showPopUp(event) { |
| 34 | + var newPopUp = composeHtmlPopUpElement(event); |
| 35 | + TcHmi.TopMostLayer.addEx(newPopUp, { |
| 36 | + centerHorizontal: true, |
| 37 | + centerVertical: true, |
| 38 | + removecb: (data) => { |
| 39 | + if (data.canceled) { |
| 40 | + // user clicked on the background |
| 41 | + TcHmi.TopMostLayer.removeEx(newPopUp); |
51 | 42 | }
|
| 43 | + }, |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + // subscripton that is called if an event inside the list changes his state |
| 48 | + function subscriptionCallback(data) { |
| 49 | + // check if the callback object is valid |
| 50 | + if (data.error === TcHmi.Errors.NONE) { |
| 51 | + // check if the alarm type is raised |
| 52 | + if (data.changeType === TcHmi.Server.Events.ChangeType.AlarmRaised) { |
| 53 | + showPopUp(data.event); |
| 54 | + } |
52 | 55 | }
|
| 56 | + } |
53 | 57 |
|
54 |
| - let allActiveAlarmsFilter = [ |
55 |
| - { |
56 |
| - path: 'type', |
57 |
| - comparator: '==', |
58 |
| - value: TcHmi.Server.Events.Type.Alarm |
59 |
| - }, |
60 |
| - { |
61 |
| - logic: 'AND' |
62 |
| - }, |
63 |
| - { |
64 |
| - path: 'timeConfirmed', |
65 |
| - comparator: '==', |
66 |
| - value: new Date(null) |
67 |
| - } |
68 |
| - ]; |
| 58 | + let allActiveAlarmsFilter = [ |
| 59 | + { |
| 60 | + path: "type", |
| 61 | + comparator: "==", |
| 62 | + value: TcHmi.Server.Events.Type.Alarm, |
| 63 | + }, |
| 64 | + { |
| 65 | + logic: "AND", |
| 66 | + }, |
| 67 | + { |
| 68 | + path: "timeConfirmed", |
| 69 | + comparator: "==", |
| 70 | + value: new Date(null), |
| 71 | + }, |
| 72 | + ]; |
69 | 73 |
|
70 |
| - // register an event consumer with the Server Event API with a filter |
71 |
| - // See HMI manual section 15.1.1.16.21.2 registerConsumer |
72 |
| - TcHmi.Server.Events.registerConsumer( |
73 |
| - allActiveAlarmsFilter, |
74 |
| - { |
75 |
| - subscription: subscriptionCallback |
76 |
| - } |
77 |
| - ); |
78 |
| - }); |
| 74 | + // register an event consumer with the Server Event API with a filter |
| 75 | + // See HMI manual section 15.1.1.16.21.2 registerConsumer |
| 76 | + TcHmi.Server.Events.registerConsumer(allActiveAlarmsFilter, { |
| 77 | + subscription: subscriptionCallback, |
| 78 | + }); |
| 79 | + } |
| 80 | + ); |
79 | 81 | })(TcHmi);
|
0 commit comments