NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/js/expressionBuilder.js

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 // define global vars
2 var aoExpressions = new Array();
3 var szBrowser ="";
4 var nVersion = 0;
5
6 /* ============================================================================
7  * Determine browser and version.
8  * ========================================================================= */
9 if ( navigator.appName == "Netscape" )
10 {
11     szBrowser = "netscape";
12     if ( navigator.appVersion[0] <= 4)
13       nVersion = 4;
14     else
15       nVersion = 5;
16 }
17 else
18 {
19     szBrowser = "ie";
20 }
21
22 /**
23  * setLayerVis()
24  *
25  * Postcondition:  This function sets the given layer's visibility.
26  *
27  * @param szLayerName string - Layer name.
28  * @param bVisible boolean - Flag to indicate visibility.
29  * @return boolean - True if successful, false if not
30  **/
31 function setLayerVis( szLayerName, bVisible )
32 {
33     // init vars
34     var oLayer = getLayerObj( szLayerName );
35    
36     // set according to browser
37     if ( szBrowser == "netscape" && nVersion == 4 )
38     {
39         if ( bVisible )
40             oLayer.visibility = "show";
41         else
42             oLayer.visibility = "hide";
43     }
44     else
45     {
46         if ( bVisible )
47             oLayer.visibility = "visible";
48         else           
49             oLayer.visibility = "hidden";
50     }
51    
52     // return
53     return true;
54 }
55
56 /**
57  * toggleLayerVis()
58  *
59  * Postcondition:  This function toggles the given layer's visibility.
60  *
61  * @param szLayerName string - Layer name.
62  * @return boolean - True if successful, false if not
63  **/
64 function toggleLayerVis( szLayerName )
65 {
66     // init vars
67     var oLayer = getLayerObj( szLayerName );
68    
69     // set according to browser
70     if ( szBrowser == "netscape" && nVersion == 4 )
71     {
72         if ( oLayer.visibility == "show" )
73             oLayer.visibility = "hide";
74         else
75             oLayer.visibility = "show";
76     }
77     else
78     {
79         if ( oLayer.visibility == "visible" )
80             oLayer.visibility = "hidden";
81         else           
82             oLayer.visibility = "visible";
83     }
84    
85     // return
86     return true;
87 }
88
89 /**
90  * getLayerObj()
91  *
92  * Postcondition:  This function gets an object handle on the requested layer.
93  *
94  * @param szLayerName string - Layer name.
95  * @return object - Handle for layer object.
96  **/
97 function getLayerObj( szLayerName )
98 {
99     // init var
100     var oLayer;
101    
102     if ( szBrowser == "netscape" )
103     {
104         if ( nVersion == "4" )
105           return document.layers[szLayerName];
106         else
107         {
108             if ( eval( 'document.getElementById("' + szLayerName + '")' ) != null )
109             {
110                 oLayer = eval( 'document.getElementById("' + szLayerName + '").style' );
111                 return oLayer;
112             }
113             else
114             {
115                 return null;
116             }
117         }
118     }
119     else if ( szBrowser == "ie" )
120     {
121         if ( eval( 'document.all.' + szLayerName ) != null )
122         {
123             oLayer = eval( 'document.all.' + szLayerName + '.style' );
124             return oLayer;
125         } else
126         {
127             return null;
128         }
129     }
130 }
131
132 /**
133  * getImageObj()
134  *
135  * Postcondition:  This function gets an object handle on the requested image.
136  *
137  * @param szImageName string - Image name.
138  * @return object - Handle for image object.
139  **/
140 function getImageObj( szImageName )
141 {
142     var oImage;
143     if ( szBrowser == "netscape" )
144     {
145         if ( arguments.length == 2 )
146         {
147             oImage = document.layers[arguments[1]].document.images[szImageName];
148         }
149         else
150         {
151             oImage = document.images[szImageName];
152         }
153     }
154     else  //IE
155     {
156         oImage = document.getElementById(szImageName);
157     }
158     return oImage;
159 }
160
161 /**
162  * setLayerPos()
163  *
164  * Postcondition:  This function dynamically positions a layer in the page.
165  *
166  * @param szLayerName string - Layer name.
167  * @param nX integer - X position.
168  * @param nY integer - Y position.
169  * @return object - Handle for layer object.
170  **/
171 function setLayerPos( szLayerName, nX, nY )
172 {
173     if ( szBrowser == "netscape" )
174     {
175         if ( nVersion == "4" )
176         {
177             document.layers[szLayerName].left=nX;
178             document.layers[szLayerName].top=nY;
179         }
180         else if ( nVersion == "5" )
181         {
182             document.getElementById(szLayerName).style.left=nX;
183             document.getElementById(szLayerName).style.top=nY;
184         }
185     }
186     else if ( szBrowser == "ie" )
187     {
188         document.all[szLayerName].style.left=nX;
189         document.all[szLayerName].style.top=nY;
190     }
191 }
192
193 /**
194  * findObjectPosX()
195  *
196  * Postcondition:  This returns the x position of the given object.
197  *
198  * @param obj object - Object to process.
199  * @return integer - X position.
200  **/
201 function findObjectPosX( obj )
202 {
203     var curleft = 0;
204     if ( document.getElementById || document.all )  //Netscape 5+, IE
205     {
206         while ( obj.offsetParent )
207         {
208             curleft += obj.offsetLeft;
209             obj = obj.offsetParent;
210         }
211     }
212     else if ( document.layers )  //Netscape 4.x
213     curleft += obj.x;
214     return curleft;
215 }
216
217 /**
218  * findObjectPosY()
219  *
220  * Postcondition:  This returns the y position of the given object.
221  *
222  * @param obj object - Object to process.
223  * @return integer - Y position.
224  **/
225 function findObjectPosY(obj)
226 {
227     var curtop = 0;
228     if ( document.getElementById || document.all )  //Netscape 5+, IE
229     {
230         while ( obj.offsetParent )
231         {
232             curtop += obj.offsetTop;
233             obj = obj.offsetParent;
234         }
235     }
236     else if ( document.layers )  //Netscape 4.x
237     curtop += obj.y;
238     return curtop;
239 }
240
241 /**
242  * QueryExpression()
243  *
244  * Postcondition:  This function is the constructor to define a class of the same
245  *                 name.  The class object is used to store expression attributes.
246  **/
247 function QueryExpression()
248 {
249     this.query_type = 0;    // 0 for simple, 1 for complex
250     this.attribute = "";    // simple - attribute to use
251     this.operator = "";     // both - operator to use
252     this.not = "";          // complex - operator to use
253     this.value1 = "";       // both - value 1 for simple - expression 1 for complex
254     this.value2 = "";       // both - value 1 for simple - expression 1 for complex
255    
256 }
257
258 /**
259  * addExpression()
260  *
261  * Postcondition:  This function adds the given expression to the global
262  *                 javascript array and list box.
263  *
264  * @return boolean - True if successful, false if not
265  **/
266 function addExpression( nType, szAttribute, szOperator, szSimple1, szSimple2,
267                                          szAndOr, szNot, szComplex1, szComplex2 )
268 {
269     var nType = nType;
270     var szNOT = "";
271     var szExprToStore = "";
272    
273     // set flag to indicate save is required
274     bSaveRequired = true;
275    
276     // check to see if a " was used
277     szCheckText = document.forms[0].txtValue1.value;
278     szCheckText2 = document.forms[0].txtValue2.value;
279     if ( szCheckText.indexOf("\"") != -1 ||
280          szCheckText2.indexOf("\"") != -1 )
281     {
282         alert( szLang15 );
283         return;
284     }
285        
286     // get array length
287     var nCount = aoExpressions.length;
288    
289     // add according to type
290     if ( nType == 0 )
291     {
292         // create new simple object in array
293         aoExpressions[nCount] = new QueryExpression();
294         aoExpressions[nCount].type = nType;
295         aoExpressions[nCount].attribute = szAttribute;
296         aoExpressions[nCount].operator = szOperator;
297         aoExpressions[nCount].value1 = szSimple1;
298         aoExpressions[nCount].value2 = szSimple2;
299        
300         // concat the expression to store
301         szExprToStore = szAttribute + " " + szOperator + " " +  szSimple1;
302                
303         // add extra box for "between" if necessary
304         if ( szOperator == "BETWEEN" )
305             szExprToStore += " and " + szSimple2;
306            
307         // add the expression to the list of availble expressions
308         document.forms[0].selExpressions.options.length = nCount + 1;
309         document.forms[0].selExpressions.options[nCount].value = nCount;
310         document.forms[0].selExpressions.options[nCount].text =
311                "[Expr" + (nCount + 1) + "]: " +  szExprToStore;
312     }
313     else
314     {
315         // check that the two value boxes have different values
316         if ( szComplex1 == szComplex2 )
317         {
318             // give message
319             alert( szLang16 );
320             return;
321         }
322        
323         // create new complex object in array
324         aoExpressions[nCount] = new QueryExpression();
325         aoExpressions[nCount].type = nType;
326         aoExpressions[nCount].operator = szAndOr;
327         aoExpressions[nCount].not = szNot;
328         aoExpressions[nCount].value1 = szComplex1;
329         aoExpressions[nCount].value2 = szComplex2;
330        
331         // concat expression
332         szExprToStore = szComplex1 + " " + szAndOr + " " + szNot + " " + szComplex2;
333            
334         // add to expression list
335         document.forms[0].selExpressions.options.length = nCount + 1;
336         document.forms[0].selExpressions.options[nCount].value = nCount;
337         document.forms[0].selExpressions.options[nCount].text =
338                "[Expr" + (nCount + 1) + "]: " + szExprToStore;
339     }   
340    
341     // add the expression to the hidden textbox
342     var szTmpDivider;
343     if ( document.forms[0].txtExpressions.value == ""  )
344         szTmpDivider = "";
345     else
346         szTmpDivider = "||";
347     document.forms[0].txtExpressions.value += '|@|' +
348         aoExpressions[nCount].type + '|' +
349         aoExpressions[nCount].attribute + '|' +
350         aoExpressions[nCount].operator + '|' +
351         aoExpressions[nCount].not + '|' +
352         aoExpressions[nCount].value1 + '|' +
353         aoExpressions[nCount].value2;
354    
355     // add the expression to the drop downs
356     document.forms[0].selCompExpression1.options.length = nCount + 1;
357     document.forms[0].selCompExpression1.options[nCount].value = "Expr" + (nCount + 1);
358     document.forms[0].selCompExpression1.options[nCount].text = "Expr" + (nCount + 1);
359     document.forms[0].selCompExpression2.options.length = nCount + 1;
360     document.forms[0].selCompExpression2.options[nCount].value = "Expr" + (nCount + 1);
361     document.forms[0].selCompExpression2.options[nCount].text = "Expr" + (nCount + 1);
362 }
363
364 /**
365  * updateDetails()
366  *
367  * Postcondition:  This function updates the details box with the correct info and
368  *                 also generates the required XML tags to be returned.
369  *
370  * @param nType integer - Type of expression, 0 for simple, 1 for complex
371  * @return boolean - True if successful, false if not
372  **/
373 function updateDetails()
374 {
375     // init vars
376     var nIndex = 0;
377     var szNewExpression = "";
378    
379     // update with the current listbox selection
380     nIndex = document.forms[0].selExpressions.selectedIndex;
381    
382     // evaluate the expression
383     szNewExpression = concatExpression( nIndex );
384
385     // evaluate
386     document.forms[0].txtExpressionDetails.value = evalExpression( szNewExpression, false );
387    
388     // return
389     return true;
390 }
391
392 /**
393  * evalExpression()
394  *
395  * Postcondition:  This function evaluates the given expression and resolves all
396  *                 nested "ExprX" items.
397  *
398  * @param szExpression string - Expression to evaluate.
399  * @param bUseType boolean - Flag to indicate if type is to be considered.
400  * @return string - Resolved expression.
401  **/
402 function evalExpression( szExpression, bUseType )
403 {
404     // intialize vars
405     var szReturn = "";
406
407     // loop through each char and replace each expression with it's value
408     for( var i=0; i<szExpression.length; i++ )
409     {
410         //  check for Expr
411         if ( szExpression.substr( i, 4 ) == "Expr" )
412         {
413             // int vars
414             var szIndex = "";
415             var szNewExpression = "";
416            
417             // advance to the end of the Expr portion
418             i = i + 4;
419            
420             // loop until a non-numeric found or end of the expression
421             do
422             {
423                 // check if the end of the expression has been reached
424                 if ( i >= szExpression.length )
425                     break;
426                    
427                 // check if the value of the current char is numeric
428                 szChar = szExpression.substr( i, 1 );
429                 if ( szChar == "0" || szChar == "1" || szChar == "2" ||
430                      szChar == "3" || szChar == "4" || szChar == "5" ||
431                      szChar == "6" || szChar == "7" || szChar == "8" ||
432                      szChar == "9" )
433                 {
434                     // add to index
435                     szIndex = szIndex + szChar;
436                 }
437                 else
438                 {
439                    // done so exit loop
440                    break;
441                 }
442                
443                 // increment counter
444                 i++;
445             }
446             while( 1==1 );
447            
448             // decrement i
449             i--;
450            
451             // use index to get new expression (based on type if necessary)
452             if ( bUseType )
453             {
454                 // get type
455                 switch ( szWidgetType )
456                 {
457                     case "WFS" :
458                         szNewExpression = concatWFSExpression( szIndex - 1 );
459                         // resolve any more nested expressions
460                         szNewExpression = evalExpression( szNewExpression, true );
461                         break;
462                     default :
463                         szNewExpression = concatExpression( szIndex - 1 );
464                         // resolve any more nested expressions
465                         szNewExpression = evalExpression( szNewExpression, true );
466                         break;
467                 }
468             }
469             else
470             {
471                 // default
472                 szNewExpression = concatExpression( szIndex - 1 );
473                
474                 // resolve any more nested expressions
475                 szNewExpression = evalExpression( szNewExpression, false );               
476             }   
477            
478             // add to results
479             szReturn = szReturn + szNewExpression;
480         }
481         else
482         {
483             // just copy char
484             szReturn = szReturn + szExpression.substr( i, 1 );
485         }
486     }
487
488     // return
489     return szReturn;
490 }
491
492 /**
493  * concatExpression()
494  *
495  * Postcondition:  This function constructs the expression based on index.
496  *
497  * @param nIndex integer - Expression index.
498  * @return string - Expression.
499  **/
500 function concatExpression( nIndex )
501 {
502     // init vars
503     var szReturn = "";
504     var szNOTOpen = "";
505     var szNOTClose = "";
506    
507     // concat by type
508     if ( aoExpressions[nIndex].type == 0 )
509     {
510         szReturn = aoExpressions[nIndex].attribute + " " +
511                    aoExpressions[nIndex].operator + " " +
512                    aoExpressions[nIndex].value1;
513                    
514         // add the extra textbox value if operator is "BETWEEN"
515         if ( aoExpressions[nIndex].operator == "BETWEEN" )
516             szReturn = szReturn + " and " + aoExpressions[nIndex].value2;
517     }
518     else
519     {
520         // check if "NOT" isset
521         if ( aoExpressions[nIndex].not == "NOT" )
522         {
523             szNOTOpen = "NOT(";
524             szNOTClose = ")";
525         }
526         else
527         {
528             szNOTOpen = "";
529             szNOTClose = "";
530         }
531
532         szReturn = "(" + aoExpressions[nIndex].value1 + " " +
533                    aoExpressions[nIndex].operator + " " + szNOTOpen +
534                    aoExpressions[nIndex].value2 + szNOTClose + ")";
535     }
536    
537     // return
538     return szReturn;
539 }
540
541 /**
542  * showExpressionTab()
543  *
544  * Postcondition:  This function makes the requested tab visible.
545  *
546  * @param nType integer - Type to display - 0 for simple, 1 for complex.
547  * @return void.
548  **/
549 function showExpressionTab( nType )
550 {
551     // get info on image placeholder
552     //var oImage = getImageObj( "imgSpacer" );
553     //var xPos = findObjectPosX( oImage );
554     //var yPos = findObjectPosY( oImage );
555    
556     // show tab based on type
557     if ( nType == 0 )
558     {
559         // position the simple expression builder and show it
560         //setLayerPos( "simple_expression", xPos, yPos );
561         setLayerVis( "complex_expression", false );
562         setLayerVis( "simple_expression", true );
563        
564         // set the type in the hidden var
565         document.forms[0].txtExpressionType.value = 0;
566        
567         // hide the extra textbox for the between if necessary
568         checkBetween();
569     }
570     else
571     {
572         // position the complex expression builder and show it
573         //setLayerPos( "complex_expression", xPos, yPos );
574         setLayerVis( "simple_expression", false );
575         setLayerVis( "complex_expression", true );
576        
577         // set the type in the hidden var
578         document.forms[0].txtExpressionType.value = 1;
579        
580         // always hide the extra textbox for the between
581         setLayerVis( "extra_between", false );
582        
583         // hide like and attributes as well
584         setLayerVis( "attribute_layer", false );
585         //setLayerVis( "like_help", false );
586     }
587    
588     // return void
589     return;
590 }
591
592 /**
593  * checkBetween()
594  *
595  * Postcondition:  This function checks and sets the visibility of the extra
596  *                 textbox.
597  *
598  * @return void.
599  **/
600 function checkBetween()
601 {   
602     // show the extra textbox for the between option
603     if ( document.forms[0].selOperator.value == "BETWEEN" )
604         setLayerVis( "extra_between", true );
605     else
606         setLayerVis( "extra_between", false );
607        
608     // return void
609     return;
610 }
611
612 /**
613  * checkLikeHelp()
614  *
615  * Postcondition:  This function checks/sets the visibility and position of the
616  *                 like help box.
617  *
618  * @return void.
619  **/
620 function checkLikeHelp()
621 {
622     // get info on image placeholder
623     var oImage = getImageObj( "imgSpacer2" );
624     var xPos = findObjectPosX( oImage );
625     var yPos = findObjectPosY( oImage );
626    
627     // position
628     setLayerPos( "like_help", xPos, yPos );
629    
630     // show the extra textbox for the between option
631     if ( document.forms[0].selOperator.value == "LIKE" )
632         setLayerVis( "like_help", true );
633     else
634         setLayerVis( "like_help", false );
635        
636     // return void
637     return;
638 }
639
640 /**
641  * execute()
642  *
643  * Postcondition:  This function gets run when the execute button has been
644  *                 pressed.
645  *
646  * @return void.
647  **/
648 function execute()
649 {
650     // give message if the textbox is not set
651     if ( document.forms[0].txtExpressionDetails.value == "" &&
652          !document.forms[0].chkBBOnly.checked )
653     {
654         alert( szLang17 );
655         return;
656     }
657    
658     // perform different functionality based on widget type
659     switch ( szWidgetType )
660     {
661         case "WFS" :
662             // get expression
663             var szExpression = '';
664             if ( document.forms[0].chkBBOnly.checked )
665                 szExpression = "BBOXONLY";
666             else
667                 szExpression = buildWFSFilter();
668
669             // determine of the filter is to be applied to the current layer
670             var szApplyToMap = 0;
671             if ( document.forms[0].chkApplyToMap.checked )
672                 szApplyToMap = 1;
673            
674             // check restrictions
675             if ( !checkRestrictions( szExpression ) )
676             {
677                 // check failed, restrictions were found
678                 return;
679             }
680            
681             // get the name of the sld
682             var selectedSLD = '';
683             if ( document.forms[0].selSLD )
684             {
685                 selectedSLD = document.forms[0].selSLD.value;
686             }
687             else
688             {
689                 selectedSLD = 'expressionbuilder_default';
690             }
691            
692             // get the layer type if set
693             var layerType = '';
694             if ( document.forms[0].selLayerType )
695             {
696                 layerType = document.forms[0].selLayerType.value;
697             }         
698
699             // execute the opener's function to appply the filter
700             window.opener.applyWFSFilter( szExpression,
701                 document.forms[0].txtLayerIndex.value,
702                 document.forms[0].txtExpressions.value, szApplyToMap,
703                 selectedSLD, document.forms[0].txtWMSConnection.value, layerType );
704            
705             // cancel any save flags
706             bSaveRequired = false;
707            
708             // close the window
709             //window.close();
710
711             // set focus to main window
712             window.opener.focus();
713            
714             break;
715         default :
716             break;
717     }
718    
719     // return void
720     return;
721 }
722
723 /**
724  * buildWFSFilter()
725  *
726  * Postcondition:  This function builds the WFS filter based on the current
727  *                 selected expression.
728  *
729  * @return string - expression.
730  **/
731 function buildWFSFilter()
732 {
733     // init vars
734     var nIndex = 0;
735     var szNewExpression = "";
736    
737     // update with the current listbox selection
738     nIndex = document.forms[0].selExpressions.selectedIndex;
739    
740     // evaluate the expression
741     szNewExpression = concatWFSExpression( nIndex );
742
743     // evaluate
744     return evalExpression( szNewExpression, true );
745 }
746
747 /**
748  * concatWFSExpression()
749  *
750  * Postcondition:  This function constructs the expression based on index.
751  *
752  * @param nIndex integer - Expression index.
753  * @return string - Expression.
754  **/
755 function concatWFSExpression( nIndex )
756 {
757     // init vars
758     var szReturn = "";
759     var szOpenNot = "";
760     var szCloseNot = "";
761    
762     // concat by expression type
763     if ( aoExpressions[nIndex].type == 0 )
764     {
765         // build tags by operator
766         switch ( aoExpressions[nIndex].operator )
767         {
768             case "=" :
769                 szReturn = "<PropertyIsEqualTo>" +
770                            "<PropertyName>" +
771                            aoExpressions[nIndex].attribute +
772                            "</PropertyName>" +
773                            "<Literal>" +
774                            aoExpressions[nIndex].value1 +
775                            "</Literal>" +
776                            "</PropertyIsEqualTo>";
777                 break;
778             case "!=" :
779                 szReturn = "<NOT><PropertyIsEqualTo>" +
780                            "<PropertyName>" +
781                            aoExpressions[nIndex].attribute +
782                            "</PropertyName>" +
783                            "<Literal>" +
784                            aoExpressions[nIndex].value1 +
785                            "</Literal>" +
786                            "</PropertyIsEqualTo></NOT>";
787                 break;
788             case "<" :
789                 szReturn = "<PropertyIsLessThan>" +
790                            "<PropertyName>" +
791                            aoExpressions[nIndex].attribute +
792                            "</PropertyName>" +
793                            "<Literal>" +
794                            aoExpressions[nIndex].value1 +
795                            "</Literal>" +
796                            "</PropertyIsLessThan>";
797                 break;
798             case "<=" :
799                 szReturn = "<PropertyIsLessThanOrEqualTo>" +
800                            "<PropertyName>" +
801                            aoExpressions[nIndex].attribute +
802                            "</PropertyName>" +
803                            "<Literal>" +
804                            aoExpressions[nIndex].value1 +
805                            "</Literal>" +
806                            "</PropertyIsLessThanOrEqualTo>";
807                 break;
808             case ">" :
809                 szReturn = "<PropertyIsGreaterThan>" +
810                            "<PropertyName>" +
811                            aoExpressions[nIndex].attribute +
812                            "</PropertyName>" +
813                            "<Literal>" +
814                            aoExpressions[nIndex].value1 +
815                            "</Literal>" +
816                            "</PropertyIsGreaterThan>";
817                 break;
818             case ">=" :
819                 szReturn = "<PropertyIsGreaterThanOrEqualTo>" +
820                            "<PropertyName>" +
821                            aoExpressions[nIndex].attribute +
822                            "</PropertyName>" +
823                            "<Literal>" +
824                            aoExpressions[nIndex].value1 +
825                            "</Literal>" +
826                            "</PropertyIsGreaterThanOrEqualTo>";
827                 break;
828             case "LIKE" :
829                 szReturn = "<PropertyIsLike wildcard='" + szWildCard +
830                            "' singleChar='" + szSingleChar +
831                            "' escape='" + szEscapeChar + "'>" +
832                            "<PropertyName>" +
833                            aoExpressions[nIndex].attribute +
834                            "</PropertyName>" +
835                            "<Literal>" +
836                            aoExpressions[nIndex].value1 +
837                            "</Literal>" +
838                            "</PropertyIsLike>";
839                 break;
840                
841             case "BETWEEN" :
842                 szReturn = "<PropertyIsBetween>" +
843                            "<PropertyName>" +
844                            aoExpressions[nIndex].attribute +
845                            "</PropertyName>" +
846                            "<LowerBoundary>" +
847                            aoExpressions[nIndex].value1 +
848                            "</LowerBoundary>" +
849                            "<UpperBoundary>" +
850                            aoExpressions[nIndex].value2 +
851                            "</UpperBoundary>" +
852                            "</PropertyIsBetween>";
853                 break;
854                
855             default :
856                 break;
857         }
858     }
859     else
860     {
861         // check if "NOT" isset
862         if ( aoExpressions[nIndex].not == "NOT" )
863         {
864             szOpenNot = "<NOT>";
865             szCloseNot = "</NOT>";
866         }
867         else
868         {
869             szOpenNot = "";
870             szCloseNot = "";
871         }
872    
873         szReturn = "<" + aoExpressions[nIndex].operator + ">" +
874                    aoExpressions[nIndex].value1 +
875                    szOpenNot + aoExpressions[nIndex].value2 + szCloseNot +
876                    "</" + aoExpressions[nIndex].operator + ">";
877     }
878    
879     // return
880     return szReturn;
881 }
882
883 /**
884  * deleteAllExpressions()
885  *
886  * Postcondition:  This function deletes all expressions.
887  *
888  * @return void.
889  **/
890 function deleteAllExpressions()
891 {
892     // clear all text boxes
893     document.forms[0].selExpressions.length = 0;
894     document.forms[0].selCompExpression1.length = 0;
895     document.forms[0].selCompExpression2.length = 0;
896     document.forms[0].txtExpressionDetails.value = "";
897    
898     // expression textbox
899     document.forms[0].txtExpressions.value = "";
900    
901     // clear global array
902     aoExpressions = new Array();
903    
904     // return void
905     return;
906 }
907
908 /**
909  * checkRestrictions()
910  *
911  * Postcondition:  This function checks the current selected expression for
912  *                 restrictions.
913  *
914  * @return boolean - True if passed, false if restrictions found.
915  **/
916 function checkRestrictions( szExpression )
917 {
918     // get expression
919     var szCheck = szExpression;
920     szCheck = szCheck.toUpperCase();
921    
922     // check expression for "and" & "like"
923     if ( szCheck.indexOf( "<AND><PROPERTYISLIKE" ) != -1 ||
924          szCheck.indexOf( "<AND><NOT><PROPERTYISLIKE" ) != -1 ||
925          szCheck.indexOf( "</PROPERTYISLIKE></AND>" ) != -1 ||
926          szCheck.indexOf( "</PROPERTYISLIKE></NOT></AND>" ) != -1 )
927     {
928         // give error message
929         alert( szLang18 );
930            
931         // return false
932         return false;
933     }
934    
935     // check for at least 2 occurrances of "like"
936     var nPos = szCheck.indexOf( "<PROPERTYISLIKE" );
937     if ( nPos != -1 && nPos != (szCheck.length - 1) )
938     {
939         // check for a second occurrance
940         nPos = szCheck.indexOf( "<PROPERTYISLIKE", nPos + 1 );
941         if ( nPos != -1 )
942         {
943             // give error message
944             alert( szLang19 );
945                
946             // return false
947             return false;
948         }
949     }
950    
951     // otherwise return true
952     return true;
953 }
Note: See TracBrowser for help on using the browser.