{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebcalc_class.pls
More file actions
277 lines (266 loc) · 8.27 KB
/
Copy pathwebcalc_class.pls
File metadata and controls
277 lines (266 loc) · 8.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
*---------------------------------------------------------------
.
. Program Name: web_calc_class
. Description: This classmodule will display a sample web calcualtor.
.
. Revision History:
.
. 17 Jul 23 W Keech
. Original code
.
. This program is created using 'CLASSMODULE'.
. In this case, this program can ONLY be accessed using public
. entry points ( FUNCTIONs ) included in this PL/B program.
.
*
. The 'CLASSMODULE' MUST be the first statement in this program
. logic.
.
eStandAlone EQU 0
.
%IF eStandAlone = 0
CLASSMODULE
%ENDIF
INCLUDE plbequ.inc
INCLUDE plbmeth.inc
INCLUDE plbstdlib.inc
*---------------------------------------------------------------
.
. All PL/B variables in this class module are private.
. COMMON variables are NOT ALLOWED in a class module.
. Only public access is through FUNCTIONs.
. CHAIN, TRAP, and Routine are not allowed.
. The class module can not be executed directly.
. LRoutine is allowed.
CalcHtml INIT "<html> ":
"<head> ":
"<!-- Sample of a calculator --> ":
"<style> ":
"##calculator { ":
" border: solid; ":
" background-color: ##0d6efd; ":
" width: 400px; ":
" margin-left: auto; ":
" margin-right: auto; ":
" text-align: center; ":
" padding: 10px; ":
"} ":
"input.calc { ":
" width: 85%; ":
" height: 7%; ":
" text-align: right; ":
" padding: 5px; ":
" border: inset; ":
"} ":
"button.calc { ":
" background-color: ##6ea8fe; ":
" width: 90%; ":
" height: 10%; ":
" border: outset; ":
"} ":
" button.calc:hover { ":
" background-color: ##cfe2ff; ":
"} ":
" button.calc:active { ":
" border: inset; ":
" border-width: thick; ":
" border-color: ##FFFFFF; ":
"} ":
"input.calc, button.calc { ":
" font-family: Arial; ":
" font-size: 20pt; ":
" border-width: thick; ":
" border-color: ##FFFFFF; ":
" margin: 5px; ":
"} ":
".calc [readonly] { ":
" background-color: ##9ec5fe; ":
"} ":
"table.calc { ":
" width: 100%; ":
"} ":
"table.calc td { ":
" width: 25%; ":
"} ":
"</style> ":
"</head> ":
"<body> ":
" <div id='calculator'> ":
" <table class='calc'> ":
" <tr> ":
" <td colspan='4'> ":
" <input class='calc' id='txtResult' type='text' readonly='readonly' data-plbenable='on' /> ":
" </td> ":
" </tr> ":
" <tr> ":
" <td colspan='4'> ":
" <input class='calc' id='txtInput' type='text' data-plbenable='on' /> ":
" </td> ":
" </tr> ":
" <tr> ":
" <td></td> ":
" <td></td> ":
" <td><button class='calc' id='btnClearEntry' data-plbenable='on'>CE</button></td> ":
" <td><button class='calc' id='btnClear' data-plbenable='on'>C</button></td> ":
" </tr> ":
" <tr> ":
" <td><button class='calc' id='btnNumber7' data-plbenable='on'>7</button></td> ":
" <td><button class='calc' id='btnNumber8' data-plbenable='on'>8</button></td> ":
" <td><button class='calc' id='btnNumber9' data-plbenable='on'>9</button></td> ":
" <td><button class='calc' id='btnPlus' data-plbenable='on'>+</button></td> ":
" </tr> ":
" <tr> ":
" <td><button class='calc' id='btnNumber4' data-plbenable='on' >4</button></td> ":
" <td><button class='calc' id='btnNumber5' data-plbenable='on' >5</button></td> ":
" <td><button class='calc' id='btnNumber6' data-plbenable='on'>6</button></td> ":
" <td><button class='calc' id='btnMinus' data-plbenable='on' >-</button></td> ":
" </tr> ":
" <tr> ":
" <td><button class='calc' id='btnNumber1' data-plbenable='on' >1</button></td> ":
" <td><button class='calc' id='btnNumber2' data-plbenable='on' >2</button></td> ":
" <td><button class='calc' id='btnNumber3' data-plbenable='on'>3</button></td> ":
" <td><button class='calc' id='btnEqual' data-plbevent='click' data-plbenable='on' >=</button></td> ":
" <td></td> ":
" </tr> ":
" <tr> ":
" <td></td> ":
" <td><button class='calc' id='btnNumber0' data-plbenable='on'>0</button></td> ":
" <td></td> ":
" <td></td> ":
" </tr> ":
" </table> ":
" </div> ":
"<script type='text/javascript'> ":
"var txtInput; ":
"var txtResult; ":
" for (var i = 0; i < 10; i++) { ":
" document.getElementById('btnNumber'+i).addEventListener('click', numberClick, false); ":
" } ":
" txtInput = document.getElementById('txtInput'); ":
" txtResult = document.getElementById('txtResult'); ":
" document.getElementById('btnPlus').addEventListener('click', plusClick, false); ":
" document.getElementById('btnMinus').addEventListener('click', minusClick, false); ":
" document.getElementById('btnEqual').addEventListener('click', plusClick, false); ":
" document.getElementById('btnClearEntry').addEventListener('click', clearEntry, false); ":
" document.getElementById('btnClear').addEventListener('click', clear, false); ":
" clear(); ":
"function numberClick() { ":
" txtInput.value = txtInput.value == '0' ? this.innerText : txtInput.value + this.innerText; ":
" txtInput.focus(); ":
"} ":
"function plusClick() { ":
" txtResult.value = Number(txtResult.value) + Number(txtInput.value); ":
" clearEntry(); ":
" txtInput.focus(); ":
"} ":
"function minusClick() { ":
" txtResult.value = Number(txtResult.value) - Number(txtInput.value); ":
" clearEntry(); ":
" txtInput.focus(); ":
"} ":
"function clearEntry() { ":
" txtInput.value = '0'; ":
" txtInput.focus(); ":
"} ":
"function clear() { ":
" txtInput.value = '0'; ":
" txtResult.value = '0'; ":
" txtInput.focus(); ":
"} ":
"</script> ":
"</body> ":
"</html>"
CalcContainer HTMLCONTROL
JsonMsg PLBOBJECT
JsonData DIM 200
*................................................................
.
. Class Create
.
ClassCreate FUNCTION
ENTRY
.
. Create the JsonMsg PLBOBJECT to decode the $JQueryEvent event data
.
CREATE JsonMsg,CLASS="jsonmsg_class"
FUNCTIONEND
*................................................................
.
. Class Destroy
.
ClassDestroy FUNCTION
ENTRY
DESTROY CalcContainer
DESTROY JsonMsg
FUNCTIONEND
*................................................................
.
. Properties
.
Get_Value FUNCTION // Get the value of the calculator result
ENTRY
Result FORM 10
Value DIM 10
TEST CalcContainer
IF ZERO
MOVE "0" to Result
ELSE
CalcContainer.GetAttr Giving Value Using "txtResult","val"
MOVE Value to Result
ENDIF
FUNCTIONEND USING Result
.
Set_Value FUNCTION // Set the value of the calculator result
Num FORM 10
ENTRY
Value DIM 10
TEST CalcContainer
IF NOT ZERO
MOVE Num To Value
CalcContainer.SetAttr Using "txtResult","val",Value
ENDIF
FUNCTIONEND
*................................................................
.
. Local event handler
.
CalcEvent LFUNCTION // Handle the CalcContainer $JQueryEvent event
ENTRY
Id DIM 30
Result FORM 10
Value DIM 10
JsonMsg.ChangeMsg Using JsonData
GETPROP JsonMsg;*id=Id
IF (Id == "btnEqual" )
CalcContainer.GetAttr Giving Value Using "txtResult","val"
MOVE Value to Result
.
. Send the event to the associated PLBOBJECT
.
EVENTSEND *CLASS,$CHANGE,RESULT=Result
ENDIF
FUNCTIONEND
*................................................................
.
. Methods
.
CalcBind FUNCTION // Bind the HTML calculator to a provided PANEL object
Container Panel ^
ENTRY
MOVEPTR Container to Container
RETURN IF OVER
TEST Container
RETURN IF ZERO
CREATE Container;CalcContainer=1:1:1:1,Visible=1,dock=$DOCKFULL
CalcContainer.InnerHtml Using CalcHtml,$HTML_HAS_EVENTS
EVENTREG CalcContainer,$JQueryEvent,CalcEvent,ARG1=JsonData
FUNCTIONEND
......
*................................................................
.
. Testing
.
%IF eStandAlone = 1
CALL ClassCreate
%ENDIF
.
You can’t perform that action at this time.
