|
| 1 | +*--------------------------------------------------------------- |
| 2 | +. |
| 3 | +. Program Name: jsonmsg_class |
| 4 | +. Description: This classmodule takes a JSON event message |
| 5 | +. ($JQueryEvent) and provides easy access to |
| 6 | +. the message members. |
| 7 | +. |
| 8 | +. Revision History: |
| 9 | +. |
| 10 | +. 17 Jul 23 W Keech |
| 11 | +. Original code |
| 12 | +. |
| 13 | +. This program is created using 'CLASSMODULE'. |
| 14 | +. In this case, this program can ONLY be accessed using public |
| 15 | +. entry points ( FUNCTIONs ) included in this PL/B program. |
| 16 | +. |
| 17 | +* |
| 18 | +. The 'CLASSMODULE' MUST be the first statement in this program |
| 19 | +. logic. |
| 20 | +. |
| 21 | +eStandAlone EQU 0 |
| 22 | +. |
| 23 | + %IF eStandAlone = 0 |
| 24 | + CLASSMODULE |
| 25 | + %ENDIF |
| 26 | + |
| 27 | + INCLUDE plbequ.inc |
| 28 | + INCLUDE plbmeth.inc |
| 29 | + INCLUDE plbstdlib.inc |
| 30 | + |
| 31 | +*--------------------------------------------------------------- |
| 32 | +. |
| 33 | +. All PL/B variables in this class module are private. |
| 34 | +. COMMON variables are NOT ALLOWED in a class module. |
| 35 | +. Only public access is through FUNCTIONs. |
| 36 | +. CHAIN, TRAP, and Routine are not allowed. |
| 37 | +. The class module can not be executed directly. |
| 38 | +. LRoutine is allowed. |
| 39 | + |
| 40 | +// <program wide variables> |
| 41 | +JsonEvent XDATA |
| 42 | +JsonResult DIM 100 |
| 43 | +JsonFlag BOOLEAN |
| 44 | + |
| 45 | + %IF eStandAlone = 1 |
| 46 | +Data DIM 100 |
| 47 | + %ENDIF |
| 48 | +*................................................................ |
| 49 | +. |
| 50 | +. Class Create |
| 51 | +. |
| 52 | +ClassCreate FUNCTION |
| 53 | + ENTRY |
| 54 | + FUNCTIONEND |
| 55 | + |
| 56 | +*................................................................ |
| 57 | +. |
| 58 | +. Class Destroy |
| 59 | +. |
| 60 | +ClassDestroy FUNCTION |
| 61 | + ENTRY |
| 62 | + JsonEvent.Reset |
| 63 | + FUNCTIONEND |
| 64 | + |
| 65 | +*................................................................ |
| 66 | +. |
| 67 | +. Properties |
| 68 | +. |
| 69 | +Get_type FUNCTION // The text event name |
| 70 | + ENTRY |
| 71 | + CALL FetchJsonStr Using JsonEvent,"type",JsonResult |
| 72 | + FUNCTIONEND USING JsonResult |
| 73 | +. |
| 74 | +Get_id FUNCTION // The 'id' name of the HTML object which generated the event |
| 75 | + ENTRY |
| 76 | + CALL FetchJsonStr Using JsonEvent,"id",JsonResult |
| 77 | + FUNCTIONEND USING JsonResult |
| 78 | + |
| 79 | +Get_pageX FUNCTION // The X relative mouse position |
| 80 | + ENTRY |
| 81 | + CALL FetchJsonStr Using JsonEvent,"pageX",JsonResult |
| 82 | + FUNCTIONEND USING JsonResult |
| 83 | + |
| 84 | +Get_pageY FUNCTION // The Y relative mouse position |
| 85 | + ENTRY |
| 86 | + CALL FetchJsonStr Using JsonEvent,"pageY",JsonResult |
| 87 | + FUNCTIONEND USING JsonResult |
| 88 | + |
| 89 | +Get_metaKey FUNCTION // Flag if meta key state when event occurred |
| 90 | + ENTRY |
| 91 | + CALL FetchJsonStr Using JsonEvent,"metaKey",JsonResult |
| 92 | + IF ( NOCASE JsonResult = "true" ) |
| 93 | + SET JsonFlag |
| 94 | + ELSE |
| 95 | + CLEAR JsonFlag |
| 96 | + ENDIF |
| 97 | + FUNCTIONEND USING JsonFlag |
| 98 | + |
| 99 | +Get_which FUNCTION // The key value or mouse button caused the event |
| 100 | + ENTRY |
| 101 | + CALL FetchJsonStr Using JsonEvent,"which",JsonResult |
| 102 | + FUNCTIONEND USING JsonResult |
| 103 | + |
| 104 | +Get_target FUNCTION // The currentTarget id value that generated the event |
| 105 | + ENTRY |
| 106 | + CALL FetchJsonStr Using JsonEvent,"target",JsonResult |
| 107 | + FUNCTIONEND USING JsonResult |
| 108 | + |
| 109 | +*................................................................ |
| 110 | +. |
| 111 | +. Methods |
| 112 | +. |
| 113 | +ChangeMsg FUNCTION // Change message data to the supplied JSON string |
| 114 | +JsonStr DIM ^ |
| 115 | + ENTRY |
| 116 | +. |
| 117 | + JsonEvent.LoadJson Using JsonStr |
| 118 | +. |
| 119 | + FUNCTIONEND |
| 120 | + |
| 121 | +*................................................................ |
| 122 | +. |
| 123 | +. Testing |
| 124 | +. |
| 125 | + %IF eStandAlone = 1 |
| 126 | + CALL ClassCreate |
| 127 | + CALL ChangeMsg Using "66" |
| 128 | + CALL ChangeMsg Using "{#"type#":#"click#",#"id#":#"sizzle#",#"pageX#":390,#"pageY#":96,#"metaKey#":false,#"which#":1,#"target#":#"sizzle#"}" |
| 129 | + CALL Get_type Giving Data |
| 130 | + CALL Get_id Giving Data |
| 131 | + CALL Get_pageX Giving Data |
| 132 | + CALL Get_pageY Giving Data |
| 133 | + CALL Get_metaKey Giving Data |
| 134 | + CALL Get_which Giving Data |
| 135 | + CALL Get_target Giving Data |
| 136 | + CALL ClassDestroy |
| 137 | + %ENDIF |
| 138 | +. |
| 139 | + |
0 commit comments