[Home] [Help]
PACKAGE BODY: APPS.JS
Source
1 package body js as
2 /* $Header: ICXJAVAB.pls 120.1 2005/10/07 13:25:12 gjimenez noship $ */
3
4
5 procedure numeric_characters is
6
7 l_decimal varchar2(30);
8 l_group varchar2(30);
9
10 begin
11
12 l_decimal := substrb(icx_sec.g_numeric_characters,1,1);
13 l_group := substrb(icx_sec.g_numeric_characters,2,1);
14
15 htp.p('var g_group = new Array();');
16 htp.p('var g_integer = new Boolean(true)');
17
18 htp.p('function con(x) {
19 var y = "";
20 var decimal = x.length;
21 var group = 0;
22
23 for (var i = x.length; i >= 0; i--)
24 if (x.charAt(i) == '''||l_decimal||''') {
25 y = "." + y;
26 decimal = i;
27 g_integer = false;
28 }
29 else
30 if (x.charAt(i) != '''||l_group||''')
31 y = x.charAt(i) + y;
32 else
33 if (group++ == g_group.length)
34 g_group[group-1] = decimal - i;
35 return y;
36 }');
37
38 htp.p('function decon(x) {
39 var y = "";
40 var decimal = 0;
41 var group = 0;
42 var count = x.length;
43
44 if (g_integer)
45 decimal = x.length;
46
47 for (var i = x.length; i >= 0; i--) {
48 if (x.charAt(i) == ''.'') {
49 y = "'||l_decimal||'" + y;
50 decimal = i;
51 }
52 else {
53 if (count == decimal - g_group[group]) {
54 y = "'||l_group||'" + y;
55 group++;
56 count--;
57 }
58 y = x.charAt(i) + y;
59 };
60 count--;
61 };
62 g_integer = true;
63
64 return y;
65 }');
66 end;
67
68 /*************function scriptOpen*****************************************/
69 function scriptOpen return varchar2 is
70
71 begin
72 return ('<SCRIPT LANGUAGE="JavaScript">
73
74 <!-- hide the script''s contents from feeble browsers');
75
76 end;
77
78 /*************procedure start_script*****************************************/
79 procedure scriptOpen is
80 begin
81 htp.p(js.scriptOpen);
82 end;
83
84 /*************function end_script *****************************************/
85 function scriptClose return varchar2 is
86 begin
87 return ('<!-- done hiding from old browsers -->
88
89 </SCRIPT>');
90 end;
91
92 /*************procedure end_script *****************************************/
93 procedure scriptClose is
94 begin
95 htp.p(js.scriptClose);
96 end;
97
98 /*************function formOpen *****************************************/
99 function formOpen return varchar2 is
100 begin
101 return('<FORM>');
102 end;
103
104 /*************procedure formOpen *****************************************/
105 procedure formOpen is
106 begin
107 htp.p(js.formOpen);
108 end;
109
110 /*************procedure dynamicButton ************************************/
111 procedure dynamicButton is
112
113 l_DisabledColor varchar2(7) := '#999999';
114 c_browser varchar2(400) := owa_util.get_cgi_env('HTTP_USER_AGENT');
115
116 PROCEDURE doc (P_text varchar2) IS
117 BEGIN
118 htp.p('document.write('||P_text||');');
119 END;
120
121 BEGIN
122
123 htp.p('function dynamicButton(p_text,p_alt,p_over,p_language,p_image,p_url,p_flag) {');
124
125 htp.p('var l_image_path = "/OA_MEDIA/" ');
126
127 doc('"<table border=0 cellpadding=0 cellspacing=0 valign=TOP align=left>"');
128
129 htp.p('if (p_text != "") {');
130 doc('"<tr><td height=28 width=29 rowspan=5>"');
131 htp.p('} else {');
132 doc('"<tr><td height=28 width=5>"');
133 htp.p('}');
134
135 htp.p('if (p_url != "") {');
136 doc('"<a href=" + p_url + " onMouseOver=\"window.status=''" + p_over + "''; return true\">"');
137 doc('"<img src=" + l_image_path + p_image + " align=CENTER height=28 width=29 border=0 alt=" + p_alt + "></a></td>"');
138 htp.p('} else {');
139 doc('"<img src=" + l_image_path + p_image + " align=CENTER height=28 width=29 border=0 alt=" + p_alt + "></td>"');
140 htp.p('}');
141
142 htp.p('if (p_text != "") {');
143 doc('"<td height=1 bgcolor=#CCCCCC><img height=1 width=1 src=" + l_image_path + "FNDDBPXC.gif alt=" + p_alt + "></td>"');
144 doc('"<td height=28 width=29 rowspan=5>"');
145 htp.p('} else {');
146 doc('"<td height=28 width=5>"');
147 htp.p('}');
148
149 htp.p('if (p_url != "") {');
150 doc('"<a href=" + p_url + " onMouseOver=\"window.status=''" + p_over + "''; return true\">"');
151 doc('"<img src=" + l_image_path + "FNDDBEND.gif border=0 height=28 width=7 align=CENTER alt=" + p_alt + "></a></td></tr>"');
152 htp.p('} else {');
153 doc('"<img src=" + l_image_path + "FNDDBEND.gif border=0 height=28 width=7 align=CENTER alt=" + p_alt + "></td></tr>"');
154 htp.p('}');
155
156 htp.p('if (p_text != "") {');
157 doc('"<tr><td height=1 bgcolor=#FFFFFF>"');
158 doc('"<img src=" + l_image_path + "FNDDBPXW.gif width=1 height=1 alt=" + p_alt + "></td></tr>"');
159 doc('"<tr align=CENTER valign=MIDDLE><td height=24 valign=MIDDLE bgcolor=#cccccc nowrap>"');
160 htp.p('if (p_url != "") {');
161 doc('"<a href=" + p_url + " valign=MIDDLE onMouseOver=\"window.status=''" + p_over + "''; return true\">"');
162 htp.p('}');
163
164 htp.p('if (p_flag == "TRUE") {');
165 doc('"<font color='||l_DisabledColor||'>" + p_text + "</font>"');
166 htp.p('if (p_url != "") {');
167 doc('"</a></td></tr>"');
168 htp.p('} else {');
169 doc('"</td></tr>"');
170 htp.p('}');
171 htp.p('} else {');
172 doc('"<font color=#000000>" + p_text + "</font>"');
173 htp.p('if (p_url != "") {');
174 doc('"</a></td></tr>"');
175 htp.p('} else {');
176 doc('"</td></tr>"');
177 htp.p('}');
178 htp.p('}');
179
180 doc('"<tr><td height=1 bgcolor=#999999>"');
181 doc('"<img src=" + l_image_path + "FNDDBPX9.gif width=1 height=1 alt=" + p_alt + "></td></tr>"');
182 doc('"<tr><td height=1 bgcolor=#000000>"');
183 doc('"<img src=" + l_image_path + "FNDDBPXB.gif width=1 height=1 alt=" + p_alt + "></td></tr>"');
184 htp.p('}');
185
186 doc('"</table>"');
187
188 htp.p('}');
189
190 END;
191
192 /*************procedure money_decimal*****************************************/
193 procedure money_decimal(precision number) is
194 begin
195 htp.p('function AddDecimal(number) {
196 var withdecimal = "";
197 var expp = Math.pow(10, ' || precision || ');
198 var num = "" + Math.round(number*expp);
199 if (num.length == 0) {
200 withdecimal += "0";
201 if (' || precision || ' > 0) {
202 withdecimal += ".";
203 for (var i=0; i < ' || precision || '; i++) {
204 withdecimal += "0";
205 }
206 }
207 } else if (num.length <= ' || precision || ') {
208 withdecimal += "0.";
209 for (var k = 0; k < (' || precision || ' - num.length); k++) {
210 withdecimal += "0";
211 }
212 withdecimal += num;
213 } else {
214 if (' || precision || ' > 0) {
215 withdecimal += num.substring(0, num.length - ' || precision || ');
216 withdecimal += "."
217 withdecimal += num.substring(num.length - ' || precision ||
218 ', num.length);
219 } else {
220 withdecimal += "num";
221 }
222 }
223
224 return withdecimal;
225 }
226 ');
227
228 end;
229
230
231 /*************function button *****************************************/
232
233 function button (name varchar2, value varchar2, onClick varchar2)
234 return varchar2 is
235
236 begin
237 if onClick is not null then
238 return('<INPUT TYPE="button" VALUE="' || value || '" NAME="' ||
239 name || '" onClick="' || '">');
240 else
241 return('<INPUT TYPE="button" VALUE="' || value || '" NAME="' ||
242 name || '">');
243 end if;
244 end;
245
246 /*************procedure button *****************************************/
247 procedure button (name varchar2, value varchar2, onClick varchar2) is
248
249 begin
250 htp.p(js.button(name, value, onClick));
251 end;
252
253 /*************function checkbox *****************************************/
254 function checkbox (name varchar2, value varchar2, onClick varchar2,
255 checked boolean) return varchar2 is
256
257 ccheck varchar2(10);
258
259 begin
260 if checked then
261 ccheck := ' CHECKED ';
262 else
263 ccheck := null;
264 end if;
265 if onClick is not null then
266 return('<INPUT TYPE="checkbox" VALUE="' || value || '" NAME="' ||
267 name || '" onClick="' || '"' || ccheck || '>');
268 else
269 return('<INPUT TYPE="checkbox" VALUE="' || value || '" NAME="' ||
270 name || '"' || ccheck || '>');
271 end if;
272 end;
273
274
275 /*************procedure checkbox *****************************************/
276 procedure checkbox (name varchar2, value varchar2, onClick varchar2,
277 checked boolean) is
278
279 begin
280 htp.p(js.checkbox(name, value, onClick, checked));
281 end;
282
283 /*************function text *****************************************/
284 function text (name varchar2, value varchar2,
285 sizze integer, onBlur varchar2, onChange varchar2,
286 onFocus varchar2, onSelect varchar2) return varchar2 is
287
288 def_val varchar2(100);
289 V_onBlur varchar2(300);
290 V_onChange varchar2(300);
291 V_onFocus varchar2(300);
292 V_onSelect varchar2(300);
293
294 begin
295
296 if value is not null then
297 def_val := ' VALUE="' || value || '" ';
298 else
299 def_val := null;
300 end if;
301
302 if onBlur is not null then
303 V_onBlur := ' onBlur = "' || onBlur || '" ';
304 else
305 V_onBlur := null;
306 end if;
307
308 if onChange is not null then
309 V_onChange := ' onChange = "' || onChange || '" ';
310 else
311 V_onChange := null;
312 end if;
313
314 if onFocus is not null then
315 V_onFocus := ' onFocus = "' || onFocus || '" ';
316 else
317 V_onFocus := null;
318 end if;
319
320 if onSelect is not null then
321 V_onSelect := ' onSelect = "' || onSelect || '" ';
322 else
323 V_onSelect := null;
324 end if;
325
326 return('<INPUT TYPE="text" NAME="' || name || '" SIZE="' || sizze ||
327 '"' || def_val || V_onBlur || V_onChange || V_onFocus ||
328 V_onSelect || '>');
329 end;
330
331 /************procedure text ******************************************/
332
333 procedure text (name varchar2, value varchar2,
334 sizze integer, onBlur varchar2, onChange varchar2,
335 onFocus varchar2, onSelect varchar2) is
336
337 begin
338 htp.p(js.text(name, value, sizze, onBlur, onChange, onFocus, onSelect));
339 end;
340
341 /*************procedure arrayCreate *****************************************/
342 procedure arrayCreate is
343
344 begin
345 htp.p('function MakeArray(n) {
346 this.length = n;
347 for (var i = 1; i <= n; i++)
348 this[i] = 0;
349 return this;
350 }
351 ');
352
353 end;
354
355 /*************procedure checkNumber *****************************************/
356
357 procedure checkNumber is
358
359 begin
360 fnd_message.set_name('ICX','ICX_NOT_NUMBER');
361 htp.p('function checkNumber(input) {
362 var msg = input.value + " '||icx_util.replace_quotes(fnd_message.get)||'";
363
364 var str = input.value;
365 for (var i = 0; i < str.length; i++) {
366 var ch = str.substring(i, i + 1);
367 if ((ch < "0" || "9" < ch) && ch != ".") {
368 alert(msg);
369 return false;
370 }
371 }
372 return true;
373 }
374 ');
375
376 end;
377
378 /*************procedure replaceDbQuote**************************************/
379
380 procedure replaceDbQuote is
381
382 begin
383 htp.p('function replaceDbQuote(input) {
384 var quote = "\"";
385 var srt = input.value;
386 var retStr = "";
387
388 for (var i = 0; i < str.length; i++) {
389 var ch = str.substring(i, i + 1);
390 if (ch == quote) {
391 retStr += quote + ch;
392 } else {
393 retStr += ch;
394 }
395 }
396 return retStr;
397 }
398 ');
399
400 end;
401 /*************procedure checkValue *****************************************/
402
403 procedure checkValue is
404
405 begin
406 fnd_message.set_name('ICX','ICX_NOT_NUMBER');
407 htp.p('function checkValue(input) {
408 var msg = input + " '||icx_util.replace_quotes(fnd_message.get)||'";
409 var str = input;
410 var space = true;
411 var x = 0;
412 for (var i = 0; i < str.length; i++) {
413 var ch = str.substring(i, i + 1);
414 if ((ch != " ") && (space = true)) {
415 space = false;
416 x = 1;
417 }
418 if ((x = 1) && (space = false)) {
419 if (((ch < "0") || ("9" < ch)) && (ch != ".") && (ch != "-")) {
420 alert(msg);
421 return false;
422 }
423 else {
424 x = 2;
425 }
426 }
427 if ((x != 1) && (space = false)) {
428 if (((ch < "0") || ("9" < ch)) && (ch != ".")) {
429 alert(msg);
430 return false;
431 }
432 }
433 }
434 return true;
435 }');
436
437 end;
438
439
440 /*************procedure checkValue *****************************************/
441 procedure checkValuePos is
442
443 begin
444 fnd_message.set_name('ICX','ICX_NOT_NUMBER');
445 htp.p('function checkValue(input) {
446 var msg = input + " '||icx_util.replace_quotes(fnd_message.get)||'";
447
448 var str = input;
449 for (var i = 0; i < str.length; i++) {
450 var ch = str.substring(i, i + 1);
451 if (((ch < "0") || ("9" < ch)) && (ch != ".")) {
452 alert(msg);
453 return false;
454 }
455 }
456 return true;
457 }
458 ');
459
460 end;
461
462
463
464 /*********************** procedure null_alert *****************/
465 /* This is a generic procedure that displays a javascript alert
466 and returns true if the value parameter is null, otherwise it
467 returns false */
468
469 procedure null_alert is
470
471 begin
472 htp.p('function null_alert(value,alert_text) {
473 if (value == "")
474 {
475 alert(alert_text)
476 return true
477 } else
478 return false
479 }');
480 end;
481
482
483
484 /*********************** procedure spaces_alert *****************/
485 /* This is a generic procedure that displays a javascript alert
486 and returns true if the value parameter contains spaces,
487 otherwise it returns false */
488
489 procedure spaces_alert is
490
491 begin
492 htp.p('function spaces_alert(value,alert_text) {
493 for (var i=0;i < value.length; i++) {
494 var ch = value.substring(i, i+1)
495 if (ch == " ")
496 {
497 alert(alert_text)
498 return true
499 }
500 }
501 return false
502 }');
503 end;
504
505
506 /*********************** procedure equal_alert *****************/
507 -- equal_alert place a javascript function in the html header
508 -- This is a generic function that accepts three parameters
509 -- The function will display a javascript alert and return true
510 -- if the first two parameters are equal
511 procedure equal_alert is
512
513 begin
514 htp.p('function equal_alert(value,value2,alert_text) {
515 if (value == value2) {
516 alert(alert_text)
517 return true
518 }
519 }');
520 end;
521
522
523
524
525
526
527 /*********************** procedure format number*****************/
528 /* This procedure should be used when displaying numbers. All number
529 columns should be read in AMERICAN territory (So we get periods
530 instead of commas. Then on display call this function. */
531
532 procedure format_number is
533 cursor getDivider is
534 SELECT substr(VALUE, 1, 1) from v$nls_parameters where value like '%.%';
535
536 v_divider varchar2(10);
537
538 begin
539
540 open getDivider;
541 fetch getDivider into v_divider;
542 close getDivider;
543
544 htp.p('function formatNumber(input) {');
545 if v_divider = '.' then
546 htp.p('return input;
547 }');
548 else
549 htp.p(' var str = input;
550 var retStr = "";
551 for (var i = 0; i < str.length; i++) {
552 if (ch == ".") {
553 retStr += "' || v_divider || '";
554 } else {
555 retStr += ch;
556 }
557 }
558 return retStr;
559 }
560 ');
561 end if;
562 end;
563
564
565
566 end js;