home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / dwmx61.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerObject-FormCmnASPNet.js < prev    next >
Encoding:
JavaScript  |  2002-11-25  |  46.5 KB  |  1,723 lines

  1. // Copyright 2002 Macromedia, Inc. All rights reserved.
  2.     
  3. //**********************GLOBAL VARS********************
  4.  
  5. var TEXTFIELD        =  MM.LABEL_TextField;
  6. var HIDDENFIELD        =  MM.LABEL_HiddenField;
  7. var PASSWORDFIELD    =  MM.LABEL_PasswordField;
  8. var PASSWORD        =  MM.LABEL_Password;
  9. var FILEFIELD        =  MM.LABEL_FileField;
  10. var TEXTAREA        =  MM.LABEL_TextArea;
  11. var MENU            =  MM.LABEL_Menu;
  12. var CHECKBOX        =  MM.LABEL_CheckBox;
  13. var RADIOGROUP        =  MM.LABEL_RadioGroup;
  14. var STATICTEXT        =  MM.LABEL_Text;
  15.  
  16. var STR_DIVIDER = "* *";
  17. var STR_ELEMENT_NAMES = STR_DIVIDER;
  18.  
  19. var DB_UNSUPPORTED_COLUMNS_ENUM_MAP = null;
  20.  
  21. //--------------------------------------------------------------------
  22. // FUNCTION:
  23. //   createFormElementStrings
  24. //
  25. // DESCRIPTION:
  26. //   This function creates the form element strings that will be used
  27. //   to create the final form.
  28. //
  29. // ARGUMENTS:
  30. //   none
  31. //
  32. // RETURNS:
  33. //   nothing
  34. //--------------------------------------------------------------------
  35.  
  36. function createFormElementStrings(rowInfoArr)
  37. {
  38.   var nRows = rowInfoArr.length;
  39.   var formElemStrArr = new Array();
  40.  
  41.   for (var i = 0; i < nRows; i++)
  42.   {
  43.     var currRowInfoObj = rowInfoArr[i];
  44.     var fieldInfoObj = currRowInfoObj.displayAs; 
  45.     
  46.     fieldInfoObj.fieldName = currRowInfoObj.fieldName;
  47.     
  48.     var fieldLabel = currRowInfoObj.label;    
  49.     var fieldVal = fieldInfoObj.value;         
  50.     var fieldType = fieldInfoObj.type;
  51.     
  52.     var formElemObj = new Object();    
  53.     
  54.     formElemObj.ElementName = fieldInfoObj.fieldName;
  55.     formElemObj.ElementType = fieldType.toLowerCase();
  56.     formElemObj.ElementValue = fieldVal;
  57.     formElemObj.ElementLabel = fieldLabel;
  58.     formElemObj.EqualToVal = "";
  59.     formElemObj.UseWebFormControl = currRowInfoObj.useWebFormControl;
  60.  
  61.     if (fieldType == "text")
  62.     {
  63.       formElemObj.ElementValue = fieldInfoObj.text;
  64.     }
  65.     else if (fieldType == "checkBox")
  66.     {
  67.       if (fieldInfoObj.checked)
  68.       {
  69.         formElemObj.ElementChecked = "checked";
  70.         formElemObj.CheckedState = "true";
  71.       }
  72.       else
  73.       {
  74.         formElemObj.ElementChecked = "";
  75.         formElemObj.CheckedState = "false";
  76.       }
  77.     }
  78.     else if (fieldType == "dynamicCheckBox")
  79.     {  
  80.       if (fieldInfoObj.checkIf)
  81.       {
  82.         var trueValue = fieldInfoObj.equalTo;
  83.  
  84.         // Add quotes if none
  85.  
  86.         if ((trueValue.charAt(0) != "'") && (trueValue.charAt(0) != '"'))
  87.         {
  88.           trueValue = '"' + trueValue + '"';
  89.         }
  90.  
  91.         var checkIf = fieldInfoObj.checkIf;
  92.  
  93.         // If the conditional is surrounded by script tags, remove them
  94.  
  95.         var re = /<%#\s*([\s\S]+)\s*%>/ig
  96.         var attrib;
  97.  
  98.         while ((attrib = re.exec(checkIf)) != null)
  99.         {
  100.           checkIf = checkIf.replace(attrib[0], attrib[1]);
  101.         }
  102.  
  103.         checkIf = "(" + dwscripts.getEqualsStatement(checkIf, trueValue) + ")";
  104.  
  105.         formElemObj.ElementValue = trueValue;
  106.         formElemObj.ElementChecked = "<%# " + dwscripts.getTernaryStatement(checkIf, "\"checked\"", "\"\"") + " %>";
  107.         formElemObj.CheckedState = "<%# " + dwscripts.getTernaryStatement(checkIf, "true", "false") + " %>";
  108.       }
  109.       else
  110.       {
  111.         formElemObj.ElementChecked = "";
  112.         formElemObj.CheckedState = "false";
  113.       }
  114.     }
  115.     else if (fieldType == "menu")
  116.     {
  117.       var nOptions = fieldInfoObj.textArr.length;
  118.       var defaultSelected = fieldInfoObj.defaultSelected;
  119.       
  120.       // If the selected value code is surrounded by script tags, remove them
  121.       // If it's not, then make sure it's surrounded by quotes.
  122.  
  123.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  124.       var attrib = re.exec(defaultSelected);
  125.  
  126.       if (attrib != null)
  127.       {
  128.         do
  129.         {
  130.           defaultSelected = defaultSelected.replace(attrib[0], attrib[1]);
  131.         }
  132.         while (attrib == re.exec(defaultSelected));
  133.       }
  134.       else if (defaultSelected.charAt(0) != '"')
  135.       {
  136.         defaultSelected = "\"" + defaultSelected + "\"";
  137.       }
  138.  
  139.       // Replace instances of "Container" with null
  140.  
  141.       defaultSelected = defaultSelected.replace(/Container/g, dwscripts.getNullToken());
  142.  
  143.       if (!nOptions) 
  144.       {
  145.          var labelText = "[ " + MM.LABEL_Label + " ]";
  146.  
  147.          fieldInfoObj.textArr = new Array(labelText, labelText);
  148.          fieldInfoObj.valArr   = new Array("menuitem1","menuitem2");
  149.          nOptions = 2;
  150.       }      
  151.       
  152.       formElemObj.OptionText = fieldInfoObj.textArr;
  153.       formElemObj.OptionValue = fieldInfoObj.valArr;
  154.       formElemObj.SelectedValue = defaultSelected;
  155.  
  156.       // This logic checks if the selected field is same as the value,
  157.       // if so marks it as selected, otherwise adds an empty string.
  158.       // this logic is required because all the arrays should be of same
  159.       // length for loop in edml file
  160.  
  161.       var optionSelectedArr = new Array();
  162.  
  163.       for (var j = 0; j < nOptions; j++)
  164.       {
  165.         if (fieldInfoObj.valArr[j] && defaultSelected)
  166.         {
  167.           var selObj = new Object;
  168.  
  169.           selObj.DefaultSelected = defaultSelected;
  170.           selObj.ItemValue = fieldInfoObj.valArr[j];
  171.  
  172.           // If ItemValue doesn't have quotes, add them
  173.  
  174.           if (selObj.ItemValue.charAt(0) != '"')
  175.           {
  176.             selObj.ItemValue = "\"" + selObj.ItemValue + "\"";
  177.           }
  178.  
  179.           optionSelectedArr.push(extPart.getInsertString("", "Menu_OptionSelected", selObj, ""));
  180.         }
  181.         else
  182.         {
  183.           optionSelectedArr.push("");
  184.         }
  185.       }
  186.  
  187.       formElemObj.OptionSelected = optionSelectedArr;
  188.     }
  189.     else if (fieldType == "radioGroup")
  190.     {
  191.       var nButtons = fieldInfoObj.labelArr.length;
  192.       var defaultChecked = fieldInfoObj.defaultChecked;
  193.       
  194.       // If the selected value code is surrounded by script tags, remove them
  195.       // If it's not, then make sure it's surrounded by quotes.
  196.  
  197.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  198.       var attrib = re.exec(defaultChecked);
  199.  
  200.       if (attrib != null)
  201.       {
  202.         do
  203.         {
  204.           defaultChecked = defaultChecked.replace(attrib[0], attrib[1]);
  205.         }
  206.         while (attrib == re.exec(defaultChecked));
  207.       }
  208.       else if (defaultChecked.charAt(0) != '"')
  209.       {
  210.         defaultChecked = "\"" + defaultChecked + "\"";
  211.       }
  212.  
  213.       // Replace instances of "Container" with null
  214.  
  215.       defaultChecked = defaultChecked.replace(/Container/g, dwscripts.getNullToken());
  216.  
  217.       if (!nButtons) 
  218.       {
  219.          var labelText = "[ " + MM.LABEL_Label + " ]";
  220.  
  221.          fieldInfoObj.labelArr = new Array(labelText, labelText);
  222.          fieldInfoObj.valArr   = new Array("radiobutton1","radiobutton2");
  223.          nButtons = 2;
  224.       }
  225.       
  226.       formElemObj.OptionText = fieldInfoObj.labelArr;
  227.       formElemObj.OptionValue = fieldInfoObj.valArr;
  228.       formElemObj.SelectedValue = defaultChecked;
  229.  
  230.       // This logic checks if the selected field is same as the value,
  231.       // if so marks it as selected, otherwise adds an empty string.
  232.       // this logic is required because all the arrays should be of same
  233.       // length for loop in edml file
  234.  
  235.       var optionSelectedArr = new Array();
  236.  
  237.       for (var j = 0; j < nButtons; j++)
  238.       {
  239.         if (fieldInfoObj.valArr[j] && defaultChecked)
  240.         {
  241.           var selObj = new Object;
  242.  
  243.           selObj.DefaultChecked = defaultChecked;
  244.           selObj.ItemValue = fieldInfoObj.valArr[j];
  245.  
  246.           // If ItemValue doesn't have quotes, add them
  247.  
  248.           if (selObj.ItemValue.charAt(0) != '"')
  249.           {
  250.             selObj.ItemValue = "\"" + selObj.ItemValue + "\"";
  251.           }
  252.  
  253.           optionSelectedArr.push(extPart.getInsertString("", "Radio_OptionChecked", selObj, ""));
  254.         }
  255.         else
  256.         {
  257.           optionSelectedArr.push("\"FALSE\"");
  258.         }
  259.       }
  260.  
  261.       formElemObj.OptionSelected = optionSelectedArr;
  262.     }
  263.     else if (fieldType == "dynamicMenu")
  264.     {
  265.       var defaultSelected = fieldInfoObj.defaultSelected;
  266.       
  267.       // If the selected value code is surrounded by script tags, remove them
  268.       // If it's not, then make sure it's surrounded by quotes.
  269.  
  270.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  271.       var attrib = re.exec(defaultSelected);
  272.  
  273.       if (attrib != null)
  274.       {
  275.         do
  276.         {
  277.           defaultSelected = defaultSelected.replace(attrib[0], attrib[1]);
  278.         }
  279.         while (attrib == re.exec(defaultSelected));
  280.       }
  281.       else if (defaultSelected.charAt(0) != '"')
  282.       {
  283.         defaultSelected = "\"" + defaultSelected + "\"";
  284.       }
  285.  
  286.       // Replace instances of "Container" with null
  287.  
  288.       defaultSelected = defaultSelected.replace(/Container/g, dwscripts.getNullToken());
  289.  
  290.       formElemObj.DynOptionText = fieldInfoObj.textCol;
  291.       formElemObj.DynOptionValue = fieldInfoObj.valCol;
  292.  
  293.       var selObj = new Object;
  294.  
  295.       selObj.DefaultSelected = defaultSelected;
  296.       selObj.ItemValue = dwscripts.sprintf("%s.FieldValue(\"%s\", Container)", fieldInfoObj.recordset, fieldInfoObj.valCol);
  297.  
  298.       formElemObj.DynOptionSelected = extPart.getInsertString("", "Menu_OptionSelected", selObj, "");
  299.       formElemObj.RecordsetName = fieldInfoObj.recordset;
  300.       formElemObj.SelectedValue = defaultSelected;
  301.     }
  302.     else if (fieldType == "dynamicRadioGroup")
  303.     {
  304.       var defaultChecked = fieldInfoObj.defaultChecked;
  305.       
  306.       // If the selected value code is surrounded by script tags, remove them
  307.       // If it's not, then make sure it's surrounded by quotes.
  308.  
  309.       var re = /<%#\s*([\s\S]+)\s*%>/ig
  310.       var attrib = re.exec(defaultChecked);
  311.  
  312.       if (attrib != null)
  313.       {
  314.         do
  315.         {
  316.           defaultChecked = defaultChecked.replace(attrib[0], attrib[1]);
  317.         }
  318.         while (attrib == re.exec(defaultChecked));
  319.       }
  320.       else if (defaultChecked.charAt(0) != '"')
  321.       {
  322.         defaultChecked = "\"" + defaultChecked + "\"";
  323.       }
  324.  
  325.       // Replace instances of "Container" with null
  326.  
  327.       defaultChecked = defaultChecked.replace(/Container/g, dwscripts.getNullToken());
  328.  
  329.       formElemObj.DynOptionText = fieldInfoObj.labelCol;
  330.       formElemObj.DynOptionValue = fieldInfoObj.valCol;
  331.  
  332.       var selObj = new Object;
  333.  
  334.       selObj.DefaultChecked = defaultChecked;
  335.       selObj.ItemValue = dwscripts.sprintf("%s.FieldValue(\"%s\", Container)", fieldInfoObj.recordset, fieldInfoObj.valCol);
  336.  
  337.       formElemObj.DynOptionSelected = extPart.getInsertString("", "Radio_OptionChecked", selObj, "");
  338.       formElemObj.RecordsetName = fieldInfoObj.recordset;
  339.       formElemObj.SelectedValue = defaultChecked;
  340.     }
  341.  
  342.     //  There is some conditional logic in the downstream edml files that must check
  343.     //  the length of the SelectedValue.  Because the conditional edml system must always
  344.     //  find some value for elements it uses within conditions, we have to be sure something
  345.     //  is always set.
  346.  
  347.     formElemObj.SelectedValue = formElemObj.SelectedValue ? formElemObj.SelectedValue : "";
  348.  
  349.     formElemStrArr.push(extPart.getInsertString("", "EditOp-FormElement", formElemObj, ""));
  350.   }
  351.   
  352.   return formElemStrArr;
  353. }
  354.  
  355. //--------------------------------------------------------------------
  356. // FUNCTION:
  357. //   populateColumnGrid
  358. //
  359. // DESCRIPTION:
  360. //   This function is called by updateUI function.  It is responsible
  361. //   for populating the Column grid.
  362. //
  363. // ARGUMENTS:
  364. //   none
  365. //
  366. // RETURNS:
  367. //   nothing
  368. //--------------------------------------------------------------------
  369.  
  370. function populateColumnGrid()
  371. {
  372.   // clear additional column list
  373.   // it lists columns that don't get populated in the grid, and needs to be cleared
  374.   
  375.   updateAdditionalColumnList('clear'); 
  376.     
  377.   // if there are no tables, then clear grid
  378.   
  379.   if (!connectionHasBeenChosen())
  380.   {
  381.     _ColumnNames.setAllRows(new Array(), new Array());
  382.     return;
  383.   }
  384.  
  385.   //var colsAndTypes = MMDB.getColumnAndTypeOfTable(_ConnectionName.getValue(), _TableName.getValue());
  386.   var columnInfo = dwscripts.getColumnValueList(_ConnectionName.getValue(), _TableName.getValue());
  387.   var rowTextArr = new Array();
  388.   var rowValArr  = new Array();
  389.   
  390.   ColumnTypes = new Array();  // clear the column types map
  391.  
  392.   //for (var i = 0; i < colsAndTypes.length; i+=2)
  393.   for (var i = 0; i < columnInfo.length; i++)
  394.   {
  395.     var columnName = columnInfo[i].getColumnName();
  396.     var columnType = columnInfo[i].getColumnType();
  397.  
  398.     ColumnTypes[columnName] = columnType;
  399.     
  400.     if (EDIT_OP_TYPE == "Update") 
  401.     {
  402.       rowInfo = getRowTextAndValue(columnName,
  403.                                    columnType,
  404.                                    _RecordsetName.getValue(),
  405.                                    _UniqueKeyColumn.getValue());
  406.  
  407.       if (columnInfo[i].getIsPrimaryKey() && !uniqueKeyColumnName)
  408.       {
  409.         uniqueKeyColumnName = columnName;
  410.       }
  411.     } 
  412.     else 
  413.     {  
  414.       rowInfo = getRowTextAndValue(columnName, columnType);
  415.     }
  416.     
  417.     rowTextArr.push(rowInfo[0]);
  418.     rowValArr.push(rowInfo[1]);
  419.   }
  420.  
  421.   _ColumnNames.setAllRows(rowTextArr, rowValArr);
  422.     
  423.   // clear global field names array (used to check for dupe field names)
  424.  
  425.   STR_ELEMENT_NAMES = STR_DIVIDER;    
  426. }
  427.  
  428. //--------------------------------------------------------------------
  429. // FUNCTION:
  430. //   checkForUnsupportedColumnTypes
  431. //
  432. // DESCRIPTION:
  433. //   This function checks if all the columns are supported or not,
  434. //   displaying a message
  435. //
  436. // ARGUMENTS:
  437. //   Boolean - to display alert message or not
  438. //
  439. // RETURNS:
  440. //   Nothing
  441. //--------------------------------------------------------------------
  442.  
  443. function checkForUnsupportedColumnTypes(displayMsg)
  444. {   
  445.   // check for the colTypes to make sure we support them, if not
  446.   // the flow is that they don't appear in the form fields grids,
  447.   // But we do display a message saying that they are not displayed,
  448.   // but the user can add them manually by clicking on the + button...
  449.  
  450.   var unsupportedColTypes = new Array();
  451.   var unsupportedColNames = new Array();
  452.   
  453.   for (var i = 0; i < _ColumnNames.valueList.length; i++)
  454.   {
  455.     var rowInfoObj = _ColumnNames.valueList[i];
  456.  
  457.     if (rowInfoObj && rowInfoObj.colType)
  458.     {
  459.       if (!isColTypeSupported(rowInfoObj.colType))
  460.       {
  461.         unsupportedColTypes.push(rowInfoObj.colType);
  462.         unsupportedColNames.push(rowInfoObj);
  463.       }
  464.     }
  465.   }  
  466.   
  467.   if (unsupportedColTypes.length && unsupportedColNames.length)
  468.   {
  469.     if (displayMsg)
  470.       alert(dwscripts.sprintf(MM.Msg_UnsupportedColumnsInTable, unsupportedColTypes));
  471.     for (var i = 0; i < unsupportedColNames.length; i++)
  472.     {
  473.       // select the row that is to be deleted...
  474.       _ColumnNames.pickRowValue(unsupportedColNames[i]);
  475.       deleteGridRow();    
  476.     }
  477.   }
  478.  
  479. }
  480.  
  481. //--------------------------------------------------------------------
  482. // FUNCTION:
  483. //   isColTypeSupported
  484. //
  485. // DESCRIPTION:
  486. //   This function returns if the colType is supported by UD or not.
  487. //
  488. // ARGUMENTS:
  489. //   colType - string - column type for update
  490. //
  491. // RETURNS:
  492. //   boolean
  493. //--------------------------------------------------------------------
  494.  
  495. function isColTypeSupported(colType)
  496. {
  497.   if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  498.   {
  499.     buildUnsupportedColumnsEnum();
  500.   }
  501.   
  502.   return (!DB_UNSUPPORTED_COLUMNS_ENUM_MAP[colType.toLowerCase()]);
  503. }
  504.  
  505. //--------------------------------------------------------------------
  506. // FUNCTION:
  507. //   buildUnsupportedColumnsEnum
  508. //
  509. // DESCRIPTION:
  510. //   This function returns if the colType is supported by UD or not.
  511. //
  512. // ARGUMENTS:
  513. //   colType - string - column type for update
  514. //
  515. // RETURNS:
  516. //   boolean
  517. //--------------------------------------------------------------------
  518.  
  519. function buildUnsupportedColumnsEnum()
  520. {
  521.   if (DB_UNSUPPORTED_COLUMNS_ENUM_MAP == null)
  522.   {
  523.     // TODO: read in from a configuration file
  524.   
  525.     var a = new Array();
  526.  
  527.     a["binary"] = 128; 
  528.     a["varbinary"] = 204;
  529.     a["longvarbinary"] = 204; 
  530.     a["longbinary"] = 205; // matched to longvarbinary
  531.  
  532.     // oracle
  533.  
  534.     a["raw"]  = 204;// Match it to Binary
  535.     a["nclob"]  = 204;//Match it to Binary
  536.     a["bfile"]  = 204;//Match it to Binary
  537.     a["ref cursor"] = 900; //Arbitrary ID Val
  538.     a["refcursor"] = 900;
  539.  
  540.     // SQL Server 7
  541.     
  542.     a["image"]  =  204 ;// binary
  543.  
  544.     DB_UNSUPPORTED_COLUMNS_ENUM_MAP = a;
  545.   }
  546. }
  547.  
  548. //--------------------------------------------------------------------
  549. // FUNCTION:
  550. //   getRowTextAndValue
  551. //
  552. // DESCRIPTION:
  553. //   This function returns the information for a row in the column table.
  554. //
  555. // ARGUMENTS:
  556. //   colName - string - column name
  557. //   colType - string - column type
  558. //   rsName  - string - (optional) recordset name, only needed for update
  559. //   uniqueColName - string - (optional) Unique Key Column, only needed
  560. //                            for update
  561. //
  562. // RETURNS:
  563. //   array of 2 values
  564. //--------------------------------------------------------------------
  565.  
  566. function getRowTextAndValue(colName, colType, rsName, uniqueColName)
  567. {
  568.   var retVal = new Array(2);
  569.   var colFieldType = "";
  570.   var colSubmitType = "";
  571.   var colSubmitName = "";
  572.   var colLabel = getLabelFromColumnName(colName);
  573.   var fieldName = getElementNameFromColumnName(colName);
  574.   
  575.   // if update, the unique key column should be a static text...
  576.   
  577.   if ((EDIT_OP_TYPE == "Update") && (colName == uniqueColName))
  578.   {
  579.     colFieldType = STATICTEXT;
  580.   }
  581.   else
  582.   {
  583.     // default to password display type if "password" appears in field name
  584.     
  585.     if (colName.toLowerCase().indexOf(PASSWORD) != (-1))
  586.     {
  587.       colFieldType = PASSWORDFIELD;
  588.     }
  589.     else
  590.     {
  591.       colFieldType = getFieldTypeFromColumnType(colType);
  592.     }
  593.   }
  594.   
  595.   var databaseType = MMDB.getDatabaseType(_ConnectionName.getValue());
  596.   var colSubmitType = dwscripts.getDBColumnTypeAsString(colType, databaseType);
  597.   var colSubmitName = colSubmitType;
  598.   var colDisplayAs = getFormFieldStorageObjectFromFormFieldType(colFieldType);
  599.   
  600.   // disable the _SubmitAs field if it is for the Primary Key column
  601.   
  602.   if ((EDIT_OP_TYPE == "Update") && (colName == uniqueColName))
  603.   {
  604.     UniqueColSubmitAs = colSubmitType;
  605.  
  606.     colSubmitType = "";  
  607.     colSubmitName = "";
  608.  
  609.     toggleSubmitAs(false);                  // enable or disable Submit As Menu
  610.     toggleLabelVisibility(colDisplayAs);    // enable or disable Label textfield
  611.   }
  612.   
  613.   var rowText = colName + "|" + colLabel + "|" + colFieldType + "|" + colSubmitName;
  614.   var rowValObj = new Object();
  615.  
  616.   rowValObj.column = colName;
  617.   rowValObj.label = colLabel;
  618.   rowValObj.displayAs = colDisplayAs;
  619.   rowValObj.submitAs = colSubmitType;
  620.   rowValObj.fieldName = fieldName;
  621.   rowValObj.defaultStr = "";
  622.   rowValObj.passwordStr = "";
  623.   rowValObj.colType = colType;
  624.   rowValObj.useWebFormControl = true;
  625.  
  626.   // populate storage object with any default values
  627.   
  628.   if ((EDIT_OP_TYPE == "Update") && (rowValObj.displayAs.type != "passwordField"))
  629.   {
  630.     var rs = (rsName) ? rsName : _RecordsetName.getValue();
  631.     rowValObj = populateFormFieldStorageType(rowValObj, rs, colName);
  632.   }
  633.  
  634.   retVal[0] = rowText;
  635.   retVal[1] = rowValObj;
  636.             
  637.   return retVal;
  638. }
  639.  
  640. //--------------------------------------------------------------------
  641. // FUNCTION:
  642. //   getLabelFromColumnName
  643. //
  644. // DESCRIPTION:
  645. //
  646. // ARGUMENTS:
  647. //
  648. // RETURNS:
  649. //   Nothing
  650. //--------------------------------------------------------------------
  651.  
  652. function getLabelFromColumnName(colName)
  653. {
  654.   return colName.charAt(0).toUpperCase() + colName.substring(1) + MM.LABEL_Delimiter;      
  655. }
  656.  
  657. //--------------------------------------------------------------------
  658. // FUNCTION:
  659. //   getElementNameFromColumnName
  660. //
  661. // DESCRIPTION:
  662. //
  663. // ARGUMENTS:
  664. //   col - string - the column name to create an element name from
  665. //
  666. // RETURNS:
  667. //   string -  the element name
  668. //--------------------------------------------------------------------
  669.  
  670. function getElementNameFromColumnName(col)
  671. {
  672.   var elemName = col;
  673.   var counter = 2;
  674.   var divider = STR_DIVIDER;
  675.  
  676.   // replace spaces with underscores
  677.  
  678.   elemName = elemName.replace(/ /g, "_");
  679.   
  680.   // strip out all characters that are not alpha-numeric, or underscores
  681.  
  682.   elemName = elemName.replace(/[^a-zA-Z_0-9]/g, "");
  683.   
  684.   // don't allow the first character to be numeric
  685.  
  686.   while (parseInt(elemName.charAt(0)) &&
  687.          parseInt(elemName.charAt(0)) == elemName.charAt(0))
  688.   {
  689.     elemName = elemName.substring(1);
  690.   }
  691.  
  692.   // in the unlikely case that no characters are left after the above,
  693.   // then name element generically as "element"
  694.  
  695.   if (elemName.length == 0)
  696.   {
  697.     elemName = MM.LABEL_Element;
  698.   }
  699.  
  700.   // ensure that name is not a dupe
  701.  
  702.   var tempName = elemName; 
  703.  
  704.   while (STR_ELEMENT_NAMES.indexOf(divider + elemName + divider) != (-1))
  705.   {
  706.     elemName = tempName + counter++;
  707.   }
  708.  
  709.   // add name to global names list
  710.   
  711.   STR_ELEMENT_NAMES += elemName + divider;
  712.  
  713.   // You can't have a web form control whose id is "id"
  714.  
  715.   if (elemName.toLowerCase() == "id")
  716.   {
  717.     elemName = "theID";
  718.   }
  719.  
  720.   return elemName;
  721. }
  722.  
  723. //--------------------------------------------------------------------
  724. // FUNCTION:
  725. //   getFieldTypeFromColumnType
  726. //
  727. // DESCRIPTION:
  728. //   This function returns the field type based on the given column type
  729. //
  730. // ARGUMENTS:
  731. //   colType - string - the column type returned from MMDB
  732. //
  733. // RETURNS:
  734. //   Nothing
  735. //--------------------------------------------------------------------
  736.  
  737. function getFieldTypeFromColumnType(colType)
  738. {
  739.   return (dwscripts.isBooleanDBColumnType(colType)) ? CHECKBOX : TEXTFIELD;
  740. }
  741.  
  742. //--------------------------------------------------------------------
  743. // FUNCTION:
  744. //   getFormFieldStorageObjectFromFormFieldType
  745. //
  746. // DESCRIPTION:
  747. //   This function returns a field storage object, based on the 
  748. //   given field type.
  749. //
  750. // ARGUMENTS:
  751. //   fieldType - string - the field type selected in the UI
  752. //
  753. // RETURNS:
  754. //   object
  755. //--------------------------------------------------------------------
  756.  
  757. function getFormFieldStorageObjectFromFormFieldType(fieldType)
  758. {
  759.   var retObj = "";
  760.  
  761.   if (fieldType == STATICTEXT)
  762.   {
  763.     retObj = new eoText();
  764.   }
  765.   else if (fieldType == TEXTFIELD)
  766.   {
  767.     retObj = new eoTextField();
  768.   }
  769.   else if (fieldType == HIDDENFIELD)
  770.   {
  771.     retObj = new eoHiddenField();
  772.   }
  773.   else if (fieldType == PASSWORDFIELD)
  774.   {
  775.     retObj = new eoPasswordField();
  776.   }
  777.   else if (fieldType == FILEFIELD)
  778.   {
  779.     retObj = new eoFileField();
  780.   }
  781.   else if (fieldType == TEXTAREA)
  782.   {
  783.     retObj = new eoTextArea();
  784.   }
  785.   else if (fieldType == MENU)
  786.   {
  787.     retObj = new eoMenu();
  788.   }
  789.   else if (fieldType == RADIOGROUP)
  790.   {
  791.     retObj = new eoRadioGroup();
  792.   }
  793.   else if (fieldType == CHECKBOX)
  794.   {
  795.     retObj = (EDIT_OP_TYPE == "Insert") ? new eoCheckBox() : new eoDynamicCheckBox();
  796.   } 
  797.  
  798.   return retObj;
  799. }
  800.  
  801. //--------------------------------------------------------------------
  802. // FUNCTION:
  803. //   displayGridFieldValues
  804. //
  805. // DESCRIPTION:
  806. //   This function is called when the user clicks on a new row in the 
  807. //   grid, changes the values of the UI fields to display the correct
  808. //   information
  809. //
  810. // ARGUMENTS:
  811. //   None
  812. //
  813. // RETURNS:
  814. //   Nothing
  815. //--------------------------------------------------------------------
  816.  
  817. function displayGridFieldValues()
  818.   // don't bother if grid is empty -- needed because this fn is also
  819.   // called when the connection or table changes
  820.  
  821.   if (_ColumnNames.list.length == 0)
  822.   {
  823.     _ElementLabel.value = "";
  824.   }
  825.   else
  826.   {
  827.     var currRowText = _ColumnNames.getRow();
  828.     var currRowVal  = _ColumnNames.getRowValue();
  829.     
  830.     var rowTextTokens = getTokens(currRowText, "|");
  831.  
  832.     // TODO: this should be taken from the record, not the display
  833.  
  834.     _ElementLabel.value = currRowVal.label;                // update label field
  835.     _DisplayAs.pickValue(rowTextTokens[2]);                // update display menu
  836.     _UseWebFormCtrl.setCheckedState(currRowVal.useWebFormControl);
  837.  
  838.     // if the column is the unique key, don't let the "display as" be changed away from "text".
  839.  
  840.     if (EDIT_OP_TYPE == "Update")
  841.     {
  842.         if (rowTextTokens[0] == uniqueKeyColumnName)
  843.         {
  844.             _DisplayAs.disable();
  845.         }
  846.         else
  847.         {
  848.             _DisplayAs.enable();
  849.         }
  850.     }
  851.  
  852.     // change UI at bottom of dialog, if relevent
  853.     // for instance, if prior row had displayAs = Text, but this row has displayAs = Menu
  854.     
  855.     showDifferentParams(); 
  856.  
  857.     if (dwscripts.findDOMObject("SubmitAs")) 
  858.     {
  859.       _SubmitAs.pickValue(currRowVal.submitAs); // update submit menu
  860.     }
  861.  
  862.     // fill in form parameters at bottom of UI
  863.     // note that in the case of radio or menu, there is nothing to fill in
  864.     
  865.     switch (currRowVal.displayAs.type)
  866.     {
  867.     case "text":
  868.       dwscripts.findDOMObject("Text").value = currRowVal.displayAs.text = currRowVal.defaultStr;
  869.       break;
  870.     case "textArea":
  871.     case "textField":
  872.     case "hiddenField":
  873.     case "fileField":
  874.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.defaultStr;
  875.       break;
  876.     case "passwordField":
  877.       dwscripts.findDOMObject("SetValueTo").value = currRowVal.displayAs.value = currRowVal.passwordStr;
  878.       break;
  879.     case "checkBox": 
  880.       // note: dwscripts.findDOMObject doesn't work with radios, so manual references are needed
  881.       var InitialStateRadios = document.forms[0].InitialState;
  882.       if (currRowVal.displayAs.checked.toString() == "true")
  883.       {
  884.         InitialStateRadios[0].checked = true; InitialStateRadios[1].checked = false;
  885.       }
  886.       else
  887.       {
  888.         InitialStateRadios[0].checked = false; InitialStateRadios[1].checked = true;
  889.       }
  890.       break;
  891.  
  892.     case "dynamicCheckBox":
  893.       dwscripts.findDOMObject("CheckIf").value = currRowVal.displayAs.checkIf;
  894.       dwscripts.findDOMObject("EqualTo").value = currRowVal.displayAs.equalTo;
  895.       break;
  896.  
  897.     case "default":
  898.       break; 
  899.     }
  900.  
  901.     _ColumnNames.setRowIndex(_ColumnNames.getRowIndex());
  902.   }
  903. }
  904.  
  905. //--------------------------------------------------------------------
  906. // FUNCTION:
  907. //   showDifferentParams
  908. //
  909. // DESCRIPTION:
  910. //   This function shows form field specific parameters at the bottom
  911. //   of the dialog for instance, shows "Menu Properties" button for 
  912. //   menu, value field for textfield, etc
  913. //
  914. // ARGUMENTS:
  915. //   displayDefaultStr - Column Name
  916. //
  917. // RETURNS:
  918. //   Nothing
  919. //--------------------------------------------------------------------
  920.  
  921. function showDifferentParams(displayDefaultStr)
  922. {
  923.   // don't bother if connection has not been chosen
  924.  
  925.   if (connectionHasBeenChosen())
  926.   {
  927.     var displayAs = _DisplayAs.getValue() ? _DisplayAs.getValue() : "none";
  928.     var tables = domUIPieces.getElementsByTagName("TABLE"), param, i;
  929.     var mmParamsTag = document.getElementsByTagName("mmParams").item(0);
  930.     var rowInfoObj = _ColumnNames.getRowValue();
  931.  
  932.     if (EDIT_OP_TYPE == "Update" && rowInfoObj.fieldName == _UniqueKeyColumn.getValue())
  933.     {
  934.       toggleSubmitAs(false);
  935.     }
  936.     else
  937.     {
  938.       toggleSubmitAsVisibility(displayAs); // enable or disable Submit As Menu
  939.       toggleLabelVisibility(displayAs);    // enable or disable Label textfield
  940.     }
  941.  
  942.     if ((displayAs == TEXTFIELD) ||
  943.         (displayAs == TEXTAREA) ||
  944.         (displayAs == HIDDENFIELD) ||
  945.         (displayAs == PASSWORDFIELD) ||
  946.         (displayAs == FILEFIELD))
  947.     {
  948.       param = "textField";
  949.     }
  950.     else if (displayAs == STATICTEXT)
  951.     {
  952.       param = "text";
  953.     }
  954.     else if (displayAs == RADIOGROUP)
  955.     {
  956.       param = "radio";
  957.     }
  958.     else if (displayAs == MENU)
  959.     {
  960.       param = "menu";
  961.     }
  962.     else if (displayAs == CHECKBOX)
  963.     {
  964.       param = (EDIT_OP_TYPE == "Insert") ? "checkBox" : "dynamicCheckBox";
  965.     }
  966.     else if (displayAs == "none")
  967.     {
  968.       param = "none";
  969.     }
  970.  
  971.     for (i = 0;i < tables.length; i++)
  972.     {
  973.       if (tables[i].name && tables[i].name == param)
  974.       {
  975.         mmParamsTag.innerHTML = tables[i].innerHTML;
  976.         break;
  977.       }
  978.     }
  979.  
  980.     // if display as equals text, text area, or text field, and the display as menu has
  981.     // just been changed, then display the default text for this column
  982.  
  983.     if (displayDefaultStr)
  984.     {
  985.       var rowInfoObj = _ColumnNames.getRowValue();
  986.       var defaultStr = _ColumnNames.getRowValue().defaultStr;
  987.       var passwordStr = _ColumnNames.getRowValue().passwordStr;
  988.  
  989.       if ((displayAs == TEXTFIELD) ||
  990.           (displayAs == TEXTAREA) ||
  991.           (displayAs == HIDDENFIELD) ||
  992.           (displayAs == FILEFIELD))
  993.       {
  994.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = defaultStr;  // set UI
  995.       }
  996.       else if (displayAs == PASSWORDFIELD)
  997.       {
  998.         dwscripts.findDOMObject("SetValueTo").value = rowInfoObj.displayAs.value = passwordStr;    // set UI
  999.       }
  1000.       else if (displayAs == STATICTEXT)
  1001.       {
  1002.         dwscripts.findDOMObject("Text").value = rowInfoObj.displayAs.text = defaultStr;    // set UI
  1003.       }
  1004.       else if (param == "dynamicCheckBox")
  1005.       {
  1006.         dwscripts.findDOMObject("CheckIf").value = rowInfoObj.displayAs.checkIf = defaultStr;
  1007.       }
  1008.     }
  1009.   }
  1010. }
  1011.  
  1012. //--------------------------------------------------------------------
  1013. // FUNCTION:
  1014. //   addGridRow
  1015. //
  1016. // DESCRIPTION:
  1017. //   This function is called if there are columns not already 
  1018. //   displayed in the grid pop up the "Add Columns" dialog, and allow
  1019. //   the user to add them
  1020. //
  1021. // ARGUMENTS:
  1022. //   None
  1023. //
  1024. // RETURNS:
  1025. //   Nothing
  1026. //--------------------------------------------------------------------
  1027.  
  1028. function addGridRow()
  1029. {
  1030.   // check to see if there are columns to add first
  1031.  
  1032.   if (ColumnsToAdd.length == 0)
  1033.   {
  1034.     alert(MM.MSG_NoMoreColumnsToAdd);
  1035.     return;
  1036.   }
  1037.  
  1038.   var addedCols = dwscripts.callCommand("Add Column.htm", ColumnsToAdd);
  1039.  
  1040.   if (!addedCols)
  1041.     return; // user clicked Cancel
  1042.   
  1043.   var nCols = addedCols.length,i, currCol, rowInfoArr;
  1044.  
  1045.   for (i=0;i<nCols;i++)
  1046.   {
  1047.     currCol = addedCols[i];
  1048.     rowInfoArr = getRowTextAndValue(currCol, ColumnTypes[currCol]);
  1049.   
  1050.     _ColumnNames.addRow(rowInfoArr[0], rowInfoArr[1]);
  1051.   
  1052.     updateAdditionalColumnList('del', currCol);
  1053.   }
  1054. }
  1055.  
  1056. //--------------------------------------------------------------------
  1057. // FUNCTION:
  1058. //   deleteGridRow
  1059. //
  1060. // DESCRIPTION:
  1061. //   This function is called when the user clicks the "-" image button
  1062. //
  1063. // ARGUMENTS:
  1064. //  None
  1065. //
  1066. // RETURNS:
  1067. //   Nothing
  1068. //--------------------------------------------------------------------
  1069.  
  1070. function deleteGridRow()
  1071. {
  1072.   var currRow = _ColumnNames.getRow();
  1073.   var currCol = currRow.substring(0,currRow.indexOf("|"));
  1074.   var nRows = _ColumnNames.list.length;
  1075.  
  1076.   if (nRows > 1)
  1077.   {
  1078.     updateAdditionalColumnList('add',currCol);
  1079.     _ColumnNames.delRow();
  1080.     displayGridFieldValues(); 
  1081.   }
  1082.   else
  1083.   {
  1084.     alert(MM.MSG_NeedOneColumnInList);
  1085.   }
  1086. }
  1087.  
  1088. //--------------------------------------------------------------------
  1089. // FUNCTION:
  1090. //   updateGridRow
  1091. //
  1092. // DESCRIPTION:
  1093. //   This function is called whenever the label, submitAs, or displayAs
  1094. //   fields are edited updates both the actual text display in the grid, 
  1095. //   and the object that stores the information about the display
  1096. //
  1097. // ARGUMENTS:
  1098. //   whichColumn: the parameter which has been edited -- displayAs, 
  1099. //   submitAs, or label
  1100. //
  1101. // RETURNS:
  1102. //   Nothing
  1103. //--------------------------------------------------------------------
  1104.  
  1105. function updateGridRow(whichColumn)
  1106. {
  1107.   // check that connection has been chosen before proceeding
  1108.  
  1109.   if (!connectionHasBeenChosen())
  1110.   {
  1111.     alert(MM.MSG_NoConnectionSelected);
  1112.     return;
  1113.   }
  1114.  
  1115.   var currRowObj  = _ColumnNames.getRowValue();
  1116.   var currRowText = _ColumnNames.getRow();
  1117.   var currColName = currRowText.substring(0, currRowText.indexOf("|"));
  1118.  
  1119.   // update grid row text
  1120.  
  1121.   var newRowText = currColName;
  1122.  
  1123.   newRowText += "|" + _ElementLabel.value;
  1124.   newRowText += "|" + _DisplayAs.get();
  1125.   newRowText += "|" + (dwscripts.findDOMObject("SubmitAs") ? _SubmitAs.get() : "");
  1126.    
  1127.    _ColumnNames.setRow(newRowText);
  1128.  
  1129.   // update object that stores information about grid row
  1130.   // this object is stored in a value attribute of the Grid object
  1131.   // these objects are stored in an array: GridObj.valueList
  1132.  
  1133.   switch (whichColumn)
  1134.   {
  1135.   case "label":
  1136.     currRowObj.label = _ElementLabel.value;
  1137.     break;
  1138.  
  1139.   case "submitAs":
  1140.     currRowObj.submitAs = _SubmitAs.getValue();
  1141.     break;
  1142.  
  1143.   case "useWebFormControl":
  1144.     currRowObj.useWebFormControl = _UseWebFormCtrl.getCheckedState();
  1145.     break;
  1146.  
  1147.   case "displayAs": 
  1148.     currRowObj.displayAs = getFormFieldStorageObjectFromFormFieldType(_DisplayAs.getValue());
  1149.   
  1150.     // need to update submit property, because changing displayAs menu can
  1151.     // auto-change submit type
  1152.     
  1153.     if (dwscripts.findDOMObject("SubmitAs"))
  1154.     {
  1155.       currRowObj.submitAs = _SubmitAs.getValue();
  1156.     }
  1157.  
  1158.     var defaultStr = currRowObj.defaultStr;
  1159.     var passwordStr = currRowObj.passwordStr;
  1160.     var fieldType = currRowObj.displayAs.type;
  1161.  
  1162.     if ((fieldType == "textField") ||
  1163.         (fieldType == "hiddenField") || 
  1164.         (fieldType == "fileField") ||
  1165.         (fieldType == "textArea"))
  1166.     {
  1167.       currRowObj.displayAs.value = defaultStr;
  1168.     }
  1169.     else if (fieldType == "passwordField")
  1170.     {
  1171.       currRowObj.displayAs.value = passwordStr;          
  1172.     }
  1173.     else if (fieldType == "text")
  1174.     {
  1175.       currRowObj.displayAs.text = defaultStr;
  1176.     }
  1177.     else if (fieldType == "menu")
  1178.     {
  1179.       currRowObj.displayAs.defaultSelected = defaultStr;
  1180.     }
  1181.     else if (fieldType == "radioGroup")
  1182.     {
  1183.       currRowObj.displayAs.defaultChecked = defaultStr;
  1184.     }
  1185.     else if (fieldType == "dynamicCheckBox")
  1186.     {
  1187.       currRowObj.displayAs.checkIf = defaultStr;
  1188.     }
  1189.     break;
  1190.  
  1191.   default:
  1192.     break;
  1193.   }
  1194. }
  1195.  
  1196. //--------------------------------------------------------------------
  1197. // FUNCTION:
  1198. //   popUpFormFieldPropertiesDialog
  1199. //
  1200. // DESCRIPTION:
  1201. //   It pops up the Radio or Menu Properties dialog, and passes in the 
  1202. //   current menu/radio storage object so that the dialog can be 
  1203. //   initialized correctly
  1204. //
  1205. // ARGUMENTS:
  1206. //   whichOne - String that can be "Radio" or "Menu"
  1207. //
  1208. // RETURNS:
  1209. //   Nothing
  1210. //--------------------------------------------------------------------
  1211.  
  1212. function popUpFormFieldPropertiesDialog(whichOne)
  1213. {
  1214.   var commandFileName = "ServerObject-" + whichOne + "Props.htm";
  1215.   var rowObj = _ColumnNames.getRowValue();
  1216.   var fieldInfoObj = dwscripts.callCommand(commandFileName,rowObj.displayAs)
  1217.  
  1218.   // note: use the "type" property on the menuInfoObj to see which
  1219.   // type of object was returned
  1220.   
  1221.   if (fieldInfoObj)
  1222.   {
  1223.     rowObj.displayAs = fieldInfoObj;
  1224.   }
  1225. }
  1226.  
  1227. //--------------------------------------------------------------------
  1228. // FUNCTION:
  1229. //   updateAdditionalColumnList
  1230. //
  1231. // DESCRIPTION:
  1232. //   The + button calls up an Add Columns dialog, allowing
  1233. //   the user to add additional columns to the list. When the Add Columns
  1234. //   dialog is called, it is populated with the "additional columns list".
  1235. //   This list is updated when a user adds or deletes a column from the UI.
  1236. //
  1237. // ARGUMENTS:
  1238. //   action - Action argument that can Add, Del or Clear
  1239. //   col    - Column
  1240. //
  1241. // RETURNS:
  1242. //   Nothing
  1243. //--------------------------------------------------------------------
  1244.  
  1245. function updateAdditionalColumnList(action, col)
  1246. {
  1247.   if (action == 'add')
  1248.   {
  1249.     ColumnsToAdd.push(col);
  1250.   }
  1251.   else if (action == 'clear')
  1252.   {
  1253.     ColumnsToAdd = new Array();
  1254.   }
  1255.   else
  1256.   { 
  1257.     // delete an item from additional column list
  1258.     
  1259.     for (var i = 0; i < ColumnsToAdd.length; i++)
  1260.     {
  1261.       if (ColumnsToAdd[i] == col)
  1262.       {
  1263.         ColumnsToAdd.splice(i,1);
  1264.         break;
  1265.       }
  1266.     }
  1267.   }
  1268. }
  1269.  
  1270. //--------------------------------------------------------------------
  1271. // FUNCTION:
  1272. //   connectionHasBeenChosen
  1273. //
  1274. // DESCRIPTION:
  1275. //   This function is called when the grid is populated, to choose a 
  1276. //   submit type based on the column type
  1277. //
  1278. // ARGUMENTS:
  1279. //   None
  1280. //
  1281. // RETURNS:
  1282. //   Nothing
  1283. //--------------------------------------------------------------------
  1284.  
  1285. function connectionHasBeenChosen()
  1286. {
  1287.   return (_ConnectionName.getValue());
  1288. }
  1289.  
  1290. //--------------------------------------------------------------------
  1291. // FUNCTION:
  1292. //   checkThatCursorIsNotInsideOfAForm
  1293. //
  1294. // DESCRIPTION:
  1295. //   Before inserting a form, check that cursor is not inside of 
  1296. //   an existing form. If it is, set IP location to be just after the form
  1297. //
  1298. // ARGUMENTS:
  1299. //   None
  1300. //
  1301. // RETURNS:
  1302. //   Nothing
  1303. //--------------------------------------------------------------------
  1304.  
  1305. function checkThatCursorIsNotInsideOfAForm()
  1306. {
  1307.   var dom = dw.getDocumentDOM();
  1308.   var formNode = findForm(dom);
  1309.  
  1310.   if (formNode)
  1311.   {
  1312.     // if inside of a form tag
  1313.     
  1314.     formArr = dom.nodeToOffsets(formNode);
  1315.     dom.setSelection(formArr[1] + 1, formArr[1] + 1);
  1316.   }
  1317. }
  1318.  
  1319. //--------------------------------------------------------------------
  1320. // FUNCTION:
  1321. //   findForm
  1322. //
  1323. // DESCRIPTION:
  1324. //   Before inserting a form, check that cursor is not inside of 
  1325. //   an existing form. If it is, set IP location to be just after the form
  1326. //
  1327. // ARGUMENTS:
  1328. //   dom - DOM object
  1329. //
  1330. // RETURNS:
  1331. //   formObj
  1332. //--------------------------------------------------------------------
  1333.  
  1334. function findForm(dom)
  1335. {
  1336.   var formObj = "";
  1337.   var selArr = dom.getSelection();
  1338.   var selObj = dom.offsetsToNode(selArr[0], selArr[1]);
  1339.  
  1340.   while (formObj == "" && selObj.parentNode)
  1341.   {
  1342.     if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName == "FORM")
  1343.     {
  1344.       formObj = selObj;
  1345.     }
  1346.     else
  1347.     {
  1348.       selObj = selObj.parentNode;
  1349.     }
  1350.   }
  1351.   
  1352.   return formObj;
  1353. }
  1354.  
  1355. //--------------------------------------------------------------------
  1356. // FUNCTION:
  1357. //   toggleSubmitAsVisibility
  1358. //
  1359. // DESCRIPTION:
  1360. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1361. //   the UI.  This menu should be visible for all items except text
  1362. //
  1363. // ARGUMENTS:
  1364. //   displayAs
  1365. //
  1366. // RETURNS:
  1367. //   Nothing
  1368. //--------------------------------------------------------------------
  1369.  
  1370. function toggleSubmitAsVisibility(displayAs)
  1371. {
  1372.   var currentVal = _SubmitAs.getValue();
  1373.  
  1374.   if ((displayAs != STATICTEXT) && (currentVal == " " || !currentVal))
  1375.   {
  1376.     // if any form field is chosen in displayAs menu
  1377.     
  1378.     var databaseType = MMDB.getDatabaseType(_ConnectionName.getValue());
  1379.  
  1380.     _SubmitAs.enable();
  1381.     _SubmitAs.del();
  1382.     _SubmitAs.pickValue(dwscripts.getDBColumnTypeAsString(ColumnTypes[_ColumnNames.getRowValue().column], databaseType));
  1383.   }
  1384.   else if (displayAs == STATICTEXT)
  1385.   {
  1386.     // if plain text was chosen in displayAs menu
  1387.     
  1388.     _SubmitAs.append(" ");
  1389.     _SubmitAs.disable();
  1390.   }
  1391. }
  1392.  
  1393. //--------------------------------------------------------------------
  1394. // FUNCTION:
  1395. //   toggleLabelVisibility
  1396. //
  1397. // DESCRIPTION:
  1398. //   toggles the visibility of "Label: [textfield]" that appears on
  1399. //   the UI.  This textfield should be visible for all items except 
  1400. //   hidden fields
  1401. //
  1402. // ARGUMENTS:
  1403. //   displayAs
  1404. //
  1405. // RETURNS:
  1406. //   Nothing
  1407. //--------------------------------------------------------------------
  1408.  
  1409. function toggleLabelVisibility(displayAs)
  1410. {
  1411.   var labelFieldIsVisible = ( _ElementLabel.disabled != "true");
  1412.  
  1413.   if (displayAs != HIDDENFIELD && !labelFieldIsVisible)
  1414.   {
  1415.     // if non-hidden field & non-visible label field
  1416.     
  1417.     _ElementLabel.setAttribute("disabled","false");
  1418.     _ElementLabel.setAttribute("value", _ColumnNames.getRowValue().label);
  1419.   }
  1420.   else if (displayAs == HIDDENFIELD && labelFieldIsVisible)
  1421.   {
  1422.     // if hidden field
  1423.     
  1424.     _ElementLabel.setAttribute("value", "");
  1425.     _ElementLabel.setAttribute("disabled", "true");
  1426.   }
  1427. }
  1428.  
  1429. //--------------------------------------------------------------------
  1430. // FUNCTION:
  1431. //   toggleSubmitAs
  1432. //
  1433. // DESCRIPTION:
  1434. //   toggles the visibility of "Submit As: [menu]" that appears on 
  1435. //   the UI.  This menu is disabled in case of Update form and if
  1436. //   it is a primary key column
  1437. //
  1438. // ARGUMENTS:
  1439. //   show - boolean 
  1440. //
  1441. // RETURNS:
  1442. //   Nothing
  1443. //--------------------------------------------------------------------
  1444.  
  1445. function toggleSubmitAs(bShow)
  1446. {
  1447.   if (bShow)
  1448.   { 
  1449.     _SubmitAs.enabled();
  1450.   }
  1451.   else
  1452.   {
  1453.     _SubmitAs.append(" ");
  1454.     _SubmitAs.disable();
  1455.   }
  1456. }
  1457.  
  1458. //--------------------------------------------------------------------
  1459. // FUNCTION:
  1460. //   EnableDisableUpDownBtns
  1461. //
  1462. // DESCRIPTION:
  1463. //   Enable/disables the elemUp and elemDown buttons
  1464. //
  1465. // ARGUMENTS:
  1466. //   None
  1467. //
  1468. // RETURNS:
  1469. //   Nothing
  1470. //--------------------------------------------------------------------
  1471.  
  1472. function EnableDisableUpDownBtns()
  1473. {
  1474.   if ((_ColumnNames.list.length <= 1) ||
  1475.       (_ColumnNames.getRowIndex() <= 0))
  1476.   {
  1477.     _ElemUp.setAttribute("disabled", true);
  1478.     _ElemUp.src = "../Shared/MM/Images/btnUp_dis.gif";   
  1479.   }
  1480.   else
  1481.   {
  1482.     _ElemUp.setAttribute("disabled", false);
  1483.     _ElemUp.src = "../Shared/MM/Images/btnUp.gif";      
  1484.   }
  1485.   
  1486.   if ((_ColumnNames.list.length <= 1) ||
  1487.       (_ColumnNames.getRowIndex() == (-1)) ||
  1488.       ((_ColumnNames.list.length - 1) == _ColumnNames.getRowIndex()))
  1489.   {
  1490.     _ElemDown.setAttribute("disabled", true);
  1491.     _ElemDown.src = "../Shared/MM/Images/btnDown_dis.gif";        
  1492.   }
  1493.   else
  1494.   {
  1495.     _ElemDown.setAttribute("disabled", false);
  1496.     _ElemDown.src = "../Shared/MM/Images/btnDown.gif";      
  1497.   }
  1498. }
  1499.  
  1500. //--------------------------------------------------------------------
  1501. // FUNCTION:
  1502. //   EnableDisableAddDelBtns
  1503. //
  1504. // DESCRIPTION:
  1505. //   Enable/disables the elemAdd and elemDel buttons
  1506. //
  1507. // ARGUMENTS:
  1508. //   None
  1509. //
  1510. // RETURNS:
  1511. //   Nothing
  1512. //--------------------------------------------------------------------
  1513.  
  1514. function EnableDisableAddDelBtns()
  1515. {
  1516.   // Check if there are any columns
  1517.   
  1518.   if (ColumnsToAdd.length == 0)
  1519.   {
  1520.     _ElemAdd.setAttribute("disabled", true);
  1521.     _ElemAdd.src = "../Shared/MM/Images/btnAdd_dis.gif";   
  1522.   }
  1523.   else
  1524.   {
  1525.     _ElemAdd.setAttribute("disabled", false);
  1526.     _ElemAdd.src = "../Shared/MM/Images/btnAdd.gif"; 
  1527.   }
  1528.     
  1529.   if ((_ColumnNames.list.length == 0) ||
  1530.       (_ColumnNames.getRowIndex() == (-1)))
  1531.   {
  1532.     _ElemDel.setAttribute("disabled", true);
  1533.     _ElemDel.src = "../Shared/MM/Images/btnDel_dis.gif";        
  1534.   }
  1535.   else
  1536.   {
  1537.     _ElemDel.setAttribute("disabled", false);
  1538.     _ElemDel.src = "../Shared/MM/Images/btnDel.gif";                
  1539.   }
  1540. }
  1541.  
  1542. //--------------------------------------------------------------------
  1543. // FUNCTION:
  1544. //   displayDynamicDataDialog
  1545. //
  1546. // DESCRIPTION:
  1547. //   pops up the dialog allowing the user to choose dynamic data
  1548. //
  1549. // ARGUMENTS:
  1550. //   textFieldObj
  1551. //
  1552. // RETURNS:
  1553. //   Nothing
  1554. //--------------------------------------------------------------------
  1555.  
  1556. function displayDynamicDataDialog(textFieldObj)
  1557. {
  1558.   var expression = dw.showDynamicDataDialog(textFieldObj.value);
  1559.  
  1560.   if (expression)
  1561.   {
  1562.     textFieldObj.value = expression;
  1563.   }
  1564. }
  1565.  
  1566. //--------------------------------------------------------------------
  1567. // FUNCTION:
  1568. //   populateFormFieldStorageType
  1569. //
  1570. // DESCRIPTION:
  1571. //   This function is called by updateUI function.  It is responsible
  1572. //   for populating the Column grid.
  1573. //
  1574. // ARGUMENTS:
  1575. //   rowValObj - Column Name
  1576. //   rsName - Column Type
  1577. //   colName  - Recordset Name
  1578. //
  1579. // RETURNS:
  1580. //   Array
  1581. //--------------------------------------------------------------------
  1582.  
  1583. function populateFormFieldStorageType(rowValObj, rsName, colName)
  1584. {
  1585.   // note: this fn is only called when the row is first created, which is why
  1586.   // it only lists some of the available form types
  1587.  
  1588.   var displayType = rowValObj.displayAs.type;
  1589.   var dynDataVal = createDynamicData(rsName, colName);
  1590.   
  1591.   rowValObj.defaultStr = dynDataVal;
  1592.  
  1593.   if (displayType == "textField" || 
  1594.       displayType  == "textArea" || 
  1595.       displayType  == "hiddenField")
  1596.   {
  1597.     rowValObj.displayAs.value = dynDataVal;
  1598.   }
  1599.   else if (displayType == "text")
  1600.   {
  1601.     rowValObj.displayAs.text = dynDataVal;
  1602.   }
  1603.   else if (displayType == "dynamicCheckBox")
  1604.   {
  1605.     rowValObj.displayAs.checkIf = dynDataVal;
  1606.   }
  1607.  
  1608.   return rowValObj;
  1609. }
  1610.  
  1611. //--------------------------------------------------------------------
  1612. // FUNCTION:
  1613. //   createDynamicData
  1614. //
  1615. // DESCRIPTION:
  1616. //   Pops up the dialog allowing the user to choose dynamic data
  1617. //
  1618. // ARGUMENTS:
  1619. //   rs - Recordset
  1620. //   col - Column Name
  1621. //
  1622. // RETURNS:
  1623. //   String
  1624. //--------------------------------------------------------------------
  1625.  
  1626. function createDynamicData(rs, col)
  1627. {
  1628.   var retVal = "";
  1629.  
  1630.   var retVal = "";
  1631.   if (rs){
  1632.     var colArray = dwscripts.getFieldNames(rs);
  1633.     if (dwscripts.findInArray(colArray, col) != -1){
  1634.       var paramObj = new Object();
  1635.       paramObj.sourceName = rs;
  1636.       paramObj.bindingName = col;
  1637.  
  1638.       retVal = extPart.getInsertString("", "Recordset_DataRef", paramObj);
  1639.     }
  1640.   }
  1641.   return retVal;
  1642. }
  1643.  
  1644. //--------------------------------------------------------------------
  1645. // FUNCTION:
  1646. //   updateDefaultFormFieldValues
  1647. //
  1648. // DESCRIPTION:
  1649. //   Goes through the default values, and replace references to the old
  1650. //   recordset with the new recordset
  1651. //
  1652. // ARGUMENTS:
  1653. //   oldRS - old Recordset
  1654. //   newRS - new Recordset
  1655. //
  1656. // RETURNS:
  1657. //   Nothing
  1658. //--------------------------------------------------------------------
  1659.  
  1660. function updateDefaultFormFieldValues(oldRS, newRS)
  1661. {
  1662.   var rowObjs = _ColumnNames.valueList;
  1663.   var nRows = rowObjs.length, i, fieldType, currRowObj, regExp;
  1664.  
  1665.   for (i = 0; i < nRows; i++)
  1666.   {
  1667.     currRowObj = rowObjs[i];
  1668.     regExp = new RegExp(oldRS,"g");
  1669.     currRowObj.defaultStr = currRowObj.defaultStr.toString().replace(regExp, newRS);
  1670.     currRowObj.passwordStr = currRowObj.passwordStr.toString().replace(regExp, newRS);
  1671.  
  1672.     // update the current display
  1673.  
  1674.     switch (currRowObj.displayAs.type)
  1675.     {
  1676.       case "textField":
  1677.       case "textArea":
  1678.       case "hiddenField":
  1679.         currRowObj.displayAs.value = currRowObj.defaultStr;
  1680.         break;
  1681.       case "passwordField":
  1682.         currRowObj.passwordField.value = currRowObj.passwordStr;
  1683.         break;
  1684.       case "text":
  1685.         currRowObj.displayAs.text = currRowObj.defaultStr;
  1686.         break;
  1687.       case "radioGroup":
  1688.       case "dynamicRadioGroup":
  1689.         currRowObj.displayAs.defaultChecked = currRowObj.defaultStr;
  1690.         break;
  1691.       case "menu":
  1692.       case "dynamicMenu":
  1693.         currRowObj.displayAs.defaultSelected = currRowObj.defaultStr;
  1694.         break;
  1695.       case "dynamicCheckBox":
  1696.         currRowObj.displayAs.checkIf = currRowObj.defaultStr;
  1697.         break;
  1698.       case "default":
  1699.         break;  
  1700.     }
  1701.   } 
  1702. }
  1703.  
  1704. //--------------------------------------------------------------------
  1705. // FUNCTION:
  1706. //   sortByPrimaryKeyCB
  1707. //
  1708. // DESCRIPTION:
  1709. //   Sort such that columns that are primary keys are at the end.
  1710. //
  1711. // ARGUMENTS:
  1712. //   a, b: columnValueNodes.
  1713. //
  1714. // RETURNS:
  1715. //   If -1 is returned: order stays the same, if 1: values are switched, if 0: values are equal
  1716. //--------------------------------------------------------------------
  1717.  
  1718. function sortByPrimaryKeyCB(a, b)
  1719. {
  1720.   return (a.getIsPrimaryKey() && !b.getIsPrimaryKey()) ? 1 : (-1);
  1721. }
  1722.