home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet Web Designer 86 / PIWD86.iso / pc / contents / dreamweaver / software / dwmx2004.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerBeh4-SimpRS.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  18.9 KB  |  934 lines

  1. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. var helpDoc = MM.HELP_ssSimpleRecordset
  4. var gSimpleParamName = "MMColParam"
  5. var gTypes //This is an array that holds the types of the columns in the column lists.
  6. var ERROR_MESSAGE = "";
  7.  
  8. var RS_NAME_BOX,CONN_LIST,COLUMN_RADIO,TABLE_LIST,COLUMN_LIST,FILTER_COL,
  9.     OPERATOR,PARAM_TYPE,PARAM_VAL,SORT_COL,SORT_TYPE,OLD_FILTER_COL_STRING;
  10.      
  11.      
  12. function clickedAdvanced()
  13. {
  14.  
  15.   MM.RecordsetObject = GetDataFromUI()
  16.   MM.IsSimpleRecordset = false
  17.   MM.RecordsetSwitchingUI = true
  18.   MM.RecordsetDone = false
  19.   window.close()
  20. }
  21.  
  22.  
  23. function clickedOK()
  24. {
  25.   MM.RecordsetOK = true
  26.  
  27.   if (MM.RecordsetPriorRec)
  28.   {
  29.     var errMsg = CheckData(FINAL, MM.RecordsetPriorRec)
  30.   }
  31.   else
  32.   {
  33.     var errMsg = CheckData(FINAL, "")
  34.   }
  35.  
  36.   if (errMsg != "")
  37.   {
  38.     MM.RecordsetOK = false
  39.     alert(errMsg)
  40.     return
  41.   }
  42.  
  43.   MM.RecordsetObject = GetDataFromUI()
  44.  
  45.   RememberSimpleRecordset()
  46.  
  47.   window.close()
  48. }
  49.  
  50.  
  51. function RememberSimpleRecordset()
  52. {
  53.  
  54.   var path = dreamweaver.getConfigurationPath() + '/ServerBehaviors/Shared/RSSeverModelSwitches.js';
  55.   var metaFile;
  56.  
  57.   metaFile = MMNotes.open(path, true); // Force create the note file.
  58.   if (metaFile) {
  59.     MMNotes.set(metaFile, 'PREF_rsType', '');
  60.     MMNotes.close(metaFile);
  61.   }
  62. }
  63.  
  64.  
  65. function clickedCancel()
  66. {
  67.   window.close()
  68. }
  69.  
  70.  
  71. function commandButtons()
  72. {
  73.   return new Array(MM.BTN_OK, "clickedOK()", MM.BTN_Cancel, "clickedCancel()", MM.BTN_Test, "PopUpTestDialog()", MM.BTN_Advanced, "clickedAdvanced()", MM.BTN_Help, "displayHelp()") 
  74. }
  75.  
  76.  
  77. function GetParametersFromUI()
  78. {
  79.   var outArray = new Array()
  80.  
  81.   if (IsFilterEnabled())
  82.   {
  83.     outArray[0] = GetParamObject(PARAM_TYPE.getIndex(), PARAM_VAL.value, Trim(RS_NAME_BOX.value))
  84.       
  85.     if (outArray[0].defaultVal == 0 && MM.SimpleRecordsetDefaultVal)
  86.     {
  87.       outArray[0].defaultVal = MM.SimpleRecordsetDefaultVal
  88.     }
  89.   }
  90.   return outArray
  91. }
  92.  
  93.  
  94. function GetDataFromUI()
  95. {
  96.   var uiData = new Object()
  97.  
  98.   uiData.name = Trim(RS_NAME_BOX.value)
  99.   uiData.connectionName = CONN_LIST.getValue()
  100.   uiData.paramArray = GetParametersFromUI()
  101.   uiData.sql = GetSQLFromUI()
  102.   uiData.isSimple = true  
  103.  
  104.   return uiData
  105. }
  106.  
  107.  
  108. function inspectTable(sqlObj)
  109. {
  110.   var ops = TABLE_LIST.object.options
  111.   var foundTable = false
  112.   for (var i = 0; i < ops.length; i++)
  113.   {
  114.     if (String(ops[i].text).toLowerCase() == String(sqlObj.table).toLowerCase())
  115.     {
  116.       foundTable = true
  117.       ops[i].selected = true
  118.     }
  119.     else
  120.     {
  121.       ops[i].selected = false
  122.     }
  123.   }
  124. }
  125.  
  126.  
  127. function inspectColumns(sqlObj)
  128. {
  129.   var ops = COLUMN_LIST.object.options
  130.  
  131.   if (sqlObj.all)
  132.   {
  133.     COLUMN_RADIO[0].checked = true
  134.     COLUMN_RADIO[1].checked = false
  135.   }
  136.   else
  137.   {
  138.     COLUMN_RADIO[0].checked = false
  139.     COLUMN_RADIO[1].checked = true  
  140.           
  141.     for (var i = 0; i < ops.length; i++)
  142.     {
  143.       var shouldBeSelected = false
  144.  
  145.       for (var j = 0; j < sqlObj.columns.length; j++)
  146.       {
  147.         if (String(sqlObj.columns[j]).toLowerCase() == String(ops[i].text).toLowerCase())
  148.         {
  149.           shouldBeSelected = true
  150.           break
  151.         }
  152.       }
  153.  
  154.       ops[i].selected = shouldBeSelected
  155.     }
  156.   }
  157. }
  158.  
  159.  
  160. function inspectFilter(sqlObj, rsName)
  161. {
  162.  
  163.   if (sqlObj.filterColumn)
  164.   {
  165.     FILTER_COL.pickValue(sqlObj.filterColumn)
  166.     PickValue(OPERATOR, sqlObj.filterOperator)
  167.  
  168.     // Parse the Runtime value of the parameter to see what type it is
  169.     // and what the name of the param is
  170.  
  171.     var paramType = 0
  172.     var paramName = "x"
  173.  
  174.  
  175.     var paramObj = GetParamTypeAndName(MM.RecordsetObject.paramArray[0], rsName)
  176.     if (paramObj)
  177.     {
  178.       paramType = paramObj.paramType
  179.       paramName = paramObj.paramName
  180.     }
  181.  
  182.     PARAM_TYPE.setIndex(paramType)
  183.     PARAM_VAL.value = paramName
  184.     if (paramName == sqlObj.filterColumn)
  185.     {
  186.       OLD_FILTER_COL_STRING = paramName // Remember that they used the name of the col
  187.                                         // as the name of the param for use in
  188.                                         // FilterColChanged.
  189.     }
  190.  
  191.     SetFilterControlsEnabled(true)
  192.   }
  193.   else
  194.   {
  195.     //reset to disabled
  196.     FILTER_COL.setIndex(0)
  197.     SetFilterControlsEnabled(false)
  198.   }
  199. }
  200.  
  201.  
  202. function inspectSort(sqlObj)
  203. {
  204.   if (sqlObj.sortColumn)
  205.   {
  206.  
  207.     //Don't use the built-in pickValue method, as it is case sensitive.
  208.     //Do it manually instead. Copy the code from the ListControl class..
  209.  
  210.     var indx = 0;
  211.     var columnUpperCase = String(sqlObj.sortColumn).toUpperCase();
  212.  
  213.     for (var i=0; i < SORT_COL.getLen(); i++) {
  214.       if (String(SORT_COL.getValue(i)).toUpperCase() == columnUpperCase) {  //  TO DO: what if value is an object?
  215.         indx = i;
  216.       }
  217.     }
  218.     SORT_COL.setIndex(indx);
  219.         
  220.     var ops = SORT_TYPE.options
  221.     for (var i = 0; i < ops.length; i++)
  222.     {
  223.       if (ops[i].value == sqlObj.sortType)
  224.       {
  225.         ops[i].selected = true
  226.         break
  227.       }
  228.     }
  229.  
  230.     SetEnabled(SORT_TYPE, true)
  231.   }
  232.   else
  233.   {
  234.     //reset disabled
  235.     SORT_COL.setIndex(0)
  236.     SetEnabled(SORT_TYPE, false)
  237.   } 
  238. }
  239.  
  240.  
  241. function inspectUI() 
  242.  
  243.   if (MM.RecordsetObject.paramArray.length == 1)
  244.   {
  245.     // Remember if there was a default val for use in GetParametersFromUI()
  246.     MM.SimpleRecordsetDefaultVal = MM.RecordsetObject.paramArray[0].defaultVal
  247.   }
  248.  
  249.   RS_NAME_BOX.value = MM.RecordsetObject.name
  250.   CONN_LIST.pickValue(MM.RecordsetObject.connectionName)
  251.  
  252.   ConnectionChanged()
  253.  
  254.  
  255.   var sqlObj = ParseSimpleSQL(MM.RecordsetObject.sql)
  256.  
  257.   if (!sqlObj)
  258.   {
  259.     alert(dwscripts.sprintf(MM.MSG_SQLNotSimple, dwscripts.getRecordsetDisplayName()));
  260.     return
  261.   }
  262.  
  263.   if (sqlObj.empty)
  264.   {
  265.     // nothing to inspect
  266.  
  267.     return
  268.   }
  269.  
  270.   if (sqlObj.table != TABLE_LIST.getValue())
  271.   {
  272.     refreshColumns = true
  273.   }
  274.   else
  275.   {
  276.     refreshColumns = false
  277.   }
  278.  
  279.   inspectTable(sqlObj)
  280.  
  281.   if (refreshColumns)
  282.   {
  283.     TableChanged() 
  284.   }
  285.  
  286.   inspectColumns(sqlObj)
  287.  
  288.   inspectFilter(sqlObj, MM.RecordsetObject.name)
  289.  
  290.   inspectSort(sqlObj) 
  291.  
  292.   RadioChanged()
  293.  
  294. }
  295.  
  296.  
  297. function PickValue(list, val)
  298. {
  299.   var ops = list.options
  300.   for (var i = 0; i < ops.length; i++)
  301.   {
  302.     if (ops[i].value == val)
  303.     {
  304.       ops[i].selected = true
  305.       break
  306.     }
  307.   }
  308. }
  309.  
  310.  
  311. function CheckData(reason, priorName)
  312. {
  313.   /*
  314.   This function checks all of the input variables to see
  315.   if the user has filled out everything okay...if not
  316.   return an error string.  If so, return empty string
  317.   */
  318.  
  319.   var strOut = ""
  320.  
  321.   if (reason == FINAL)
  322.   {
  323.     // we don't get here if we are just testing the SQL statement
  324.     var theName = Trim(RS_NAME_BOX.value)
  325.     if (theName == "")
  326.     {
  327.       strOut += MM.MSG_NoRecordsetName;
  328.       return strOut
  329.     }
  330.  
  331.     if (!IsValidVarName(theName))
  332.     {
  333.       strOut = MM.MSG_InvalidRecordsetName
  334.       return strOut
  335.     }
  336.  
  337.     if (IsDupeObjectName(theName, priorName))
  338.     {
  339.       return MM.MSG_DupeRecordsetName;
  340.     }
  341.   
  342.     if (IsReservedWord(theName))
  343.     {
  344.       return dwscripts.sprintf(MM.MSG_ReservedWord, theName);
  345.     }
  346.     
  347.   }
  348.  
  349.   if (CONN_LIST.getIndex() == 0)
  350.   {
  351.     strOut += MM.MSG_NoConnection;
  352.     return strOut
  353.   }
  354.  
  355.   var tableName = TABLE_LIST.getValue();
  356.   if(Trim(tableName) == "")
  357.   {
  358.     strOut += MM.MSG_NoTableSelected;
  359.     return strOut;
  360.   }
  361.   
  362.   if (GetColumns() == "")
  363.   {
  364.     return MM.MSG_SelectColumns 
  365.   }
  366.  
  367.   if (IsFilterEnabled())
  368.   {
  369.     if (Trim(PARAM_VAL.value) == "")
  370.     {
  371.       PARAM_VAL.focus()
  372.       if (!IsLiteralValue(PARAM_TYPE.getIndex()))
  373.       {
  374.         return MM.MSG_MissingParamName + " " + PARAM_TYPE.getValue()
  375.       }
  376.       else
  377.       {
  378.         return MM.MSG_MissingFilterVal;
  379.       }
  380.       
  381.     }
  382.  
  383.     if (!isFilterColumnString())
  384.     {
  385.       var operator = OPERATOR.options[OPERATOR.selectedIndex].value
  386.       switch(operator)
  387.       {
  388.         case "begins with":
  389.         case "ends with":
  390.         case "contains":
  391.           
  392.           return MM.MSG_CanOnlyUseThisOperatorOnAString;
  393.       }
  394.     } 
  395.   }
  396.  
  397.   return strOut
  398. }
  399.  
  400.  
  401. function GetSQLFromUI()
  402. {
  403.   var theTable = TABLE_LIST.getValue()
  404.  
  405.   if (theTable == null || theTable == "")
  406.   {
  407.     return "";
  408.   }
  409.   if (theTable.indexOf(" ") >= 0)
  410.   {
  411.     var aBracketedTable = "";
  412.     var theSplitTable = theTable.split(".");
  413.     var n = theSplitTable.length;
  414.     for(var i = 0; i < n; i++)
  415.     {
  416.         if(i > 0)
  417.         {
  418.             aBracketedTable += ".";
  419.         }
  420.         var aSlice = theSplitTable[i];
  421.         if(aSlice.indexOf(" ") >= 0)
  422.         {
  423.             aBracketedTable += "[" + aSlice + "]";
  424.         }
  425.         else
  426.         {
  427.             aBracketedTable += aSlice;
  428.         }
  429.     }
  430.     theTable = aBracketedTable;
  431.   }
  432.  
  433.   var cols = GetColumns()
  434.   var theSQL = "SELECT " + cols + " FROM " + theTable
  435.  
  436.   if (IsFilterEnabled())
  437.   {
  438.     theSQL += " WHERE " + FILTER_COL.getValue() 
  439.     var theOperator = OPERATOR.options[OPERATOR.selectedIndex].value
  440.     switch(theOperator)
  441.     {
  442.       case "=":
  443.       case ">":
  444.       case "<":
  445.       case ">=":
  446.       case "<=":
  447.       case "<>":
  448.         theSQL += " " + theOperator + " "
  449.         var enclosingToken = getToken()
  450.         theSQL += enclosingToken + gSimpleParamName + enclosingToken
  451.         break;
  452.       case "begins with":
  453.         theSQL += " LIKE '" + gSimpleParamName + "%'"
  454.         break
  455.       case "ends with":
  456.         theSQL += " LIKE '%" + gSimpleParamName + "'"
  457.         break
  458.       case "contains":
  459.         theSQL += " LIKE '%" + gSimpleParamName + "%'"
  460.         break
  461.     }
  462.   }
  463.  
  464.   if (IsSortEnabled())
  465.   {
  466.     theSQL += " ORDER BY " + SORT_COL.getValue() + " " + SORT_TYPE.options[SORT_TYPE.selectedIndex].value
  467.   }
  468.  
  469.   
  470.   return theSQL
  471. }
  472.  
  473.  
  474. function isFilterColumnString()
  475. {
  476.   return (getToken() == "'");
  477. }
  478.  
  479. function getToken()
  480. {
  481.   if (IsFilterEnabled())
  482.   {
  483.     if (IsLiteralValue(PARAM_TYPE.getIndex()))
  484.     {
  485.       var value = PARAM_VAL.value;
  486.       if (value.length)
  487.       {
  488.         if ((value.charAt(0)=="#") &&
  489.           (value.charAt(value.length-1)=="#"))
  490.         {
  491.           return "";
  492.         }
  493.       }
  494.     }
  495.   }
  496.  
  497.   var index = FILTER_COL.object.selectedIndex - 1
  498.   
  499.   var retVal = "";
  500.   if (   dwscripts.isStringDBColumnType(gTypes[index])
  501.       || dwscripts.isDateDBColumnType(gTypes[index])
  502.      )
  503.   {
  504.     retVal = "'";
  505.   }
  506.   
  507.   return retVal;
  508. }
  509.  
  510.  
  511. function GetColumns()
  512. {
  513.   var cols = "*"
  514.  
  515.   if (COLUMN_RADIO[1].checked)
  516.   {
  517.     var ops = COLUMN_LIST.object.options
  518.     cols = ""
  519.     for (var i = 0; i < ops.length; i++)
  520.     {
  521.       if (ops[i].selected)
  522.       {
  523.         if(cols != "")
  524.         {
  525.           cols += ", "
  526.         }
  527.         cols += ops[i].text
  528.       }
  529.     }
  530.   }
  531.  
  532.   return cols
  533. }
  534.  
  535. function initializeUI()
  536. {
  537.   
  538.   //Create global vars for all controls
  539.   
  540.   MM.SimpleRecordsetDefaultVal = null  //Clear the default Val holder. It
  541.                                           //may be set again in inspectUI
  542.   
  543.   RS_NAME_BOX = findObject("RecordsetName")
  544.  
  545.   RS_NAME_BOX.value = CreateNewName()
  546.   CONN_LIST = new ListControl("ConnectionList")
  547.  
  548.   COLUMN_RADIO = findObject("RadioButton")
  549.   TABLE_LIST = new ListControl("TableList")
  550.   COLUMN_LIST = new ListControl("ColumnList")
  551.  
  552.   FILTER_COL = new ListControl("ColumnDropDown")
  553.   OPERATOR = findObject("OperatorDropDown")
  554.   PARAM_TYPE = new ListControl("ParameterTypeDropDown")
  555.   PARAM_VAL = findObject("ParameterValue")
  556.   SORT_COL = new ListControl("SortByColumnDropDown")
  557.   SORT_TYPE = findObject("SortByTypeDropDown")
  558.  
  559.   OLD_FILTER_COL_STRING = ""  // Global var to remember the last filter
  560.                               // col selected. (This var is used in
  561.                               // FilterColChanged and inspectFilter)
  562.  
  563.   PopulateConnectionList()
  564.  
  565.   ConnectionChanged()
  566.  
  567.   PopulateParamTypeList() 
  568.  
  569.  
  570.   if (MM.RecordsetSwitchingUI || MM.RecordsetPriorRec)
  571.   {
  572.  
  573.     inspectUI()
  574.  
  575.   }
  576.   else
  577.   {
  578.     // Make sure these are disabled
  579.  
  580.     FILTER_COL.setIndex(0)
  581.     SetFilterControlsEnabled(false)
  582.  
  583.     SORT_COL.setIndex(0)
  584.     SetEnabled(SORT_TYPE, false)
  585.  
  586.   }
  587.  
  588.   if (ERROR_MESSAGE) alert(ERROR_MESSAGE);
  589.   
  590.   elts = document.forms[0].elements;
  591.   if (elts && elts.length)
  592.   {
  593.     elts[0].focus();
  594.     elts[0].select();
  595.   }
  596. }
  597.  
  598.  
  599. function PopulateParamTypeList()
  600. {
  601.   var paramTypes = GetParamTypeArray()
  602.   PARAM_TYPE.setAll(paramTypes, paramTypes)
  603.   PARAM_TYPE.setIndex(0)
  604. }
  605.  
  606.  
  607. function IsFilterEnabled()
  608. {
  609.   return (FILTER_COL.object.selectedIndex > 0)
  610. }
  611.  
  612.  
  613. function IsSortEnabled()
  614. {
  615.   return (SORT_COL.object.selectedIndex > 0)
  616. }
  617.  
  618.  
  619. function PopUpTestDialog()
  620. {
  621.  
  622.   var msg = CheckData(FOR_TEST, "")
  623.   if (msg != "")
  624.   {
  625.     alert(msg)
  626.     return
  627.   }
  628.  
  629.   var statement = GetSQLFromUI()
  630.  
  631.   if (IsFilterEnabled())
  632.   {
  633.   
  634.     var isEmpty = Trim(PARAM_VAL.value) == ""
  635.   
  636.     if (!IsLiteralValue(PARAM_TYPE.getIndex()))
  637.     {
  638.       // Pop up a dialog to get the default value to use in the test  
  639.       MM.paramName = PARAM_TYPE.getValue() + ": " + PARAM_VAL.value
  640.       dw.runCommand("GetTestValue")
  641.       if (!MM.clickedOK)
  642.       {
  643.         return
  644.       }
  645.     }
  646.     else
  647.     {
  648.       // The user has chosen to provide the comparison value of the filter
  649.       MM.retVal = PARAM_VAL.value
  650.     }
  651.   }
  652.  
  653.   var re = new RegExp("\\b" + gSimpleParamName + "\\b", "g")
  654.  
  655.   statement = statement.replace(re, String(MM.retVal).replace(/'/g, "''"))
  656.  
  657.   //alert(statement)
  658.  
  659.   MMDB.showResultset(CONN_LIST.getValue(), statement)
  660. }
  661.  
  662.  
  663. function RemoveWhereClause(sql)
  664. {
  665.   var theSQL = String(sql)
  666.   var strOut = theSQL
  667.  
  668.   var wherePos = theSQL.search(/\s+where\s+/i)
  669.   if (wherePos != -1)
  670.   {
  671.     var orderByPos = theSQL.search(/\s+order\s+by\s+/i)
  672.     if (orderByPos != -1)
  673.     {
  674.       strOut = theSQL.substring(0, wherePos) + theSQL.substring(orderByPos)
  675.     }
  676.     else
  677.     {
  678.       strOut = theSQL.substring(0, wherePos)
  679.     }
  680.   }
  681.  
  682.   return strOut
  683. }
  684.  
  685.  
  686. function ConnectionChanged()
  687. {
  688.  
  689.   var i, tables
  690.   
  691.   if (CONN_LIST.getIndex() == 0)
  692.   {
  693.     tables = new Array()
  694.   }
  695.   else
  696.   {
  697.     // Get the tables and views
  698.  
  699.     // First get the tables
  700.     tables = new Array()
  701.     tableObjects = MMDB.getTables(CONN_LIST.getValue())    
  702.     if (tableObjects.length == 0)
  703.     {
  704.       alert(MM.MSG_ConnErrs)
  705.     }
  706.     for (i = 0; i < tableObjects.length; i++)
  707.     {
  708.       var thisTable = tableObjects[i]
  709.       thisSchema =  Trim(thisTable.schema)
  710.       if (thisSchema.length == 0)
  711.       {
  712.         thisSchema = Trim(thisTable.catalog)
  713.       }
  714.       if (thisSchema.length > 0)
  715.       {
  716.         thisSchema += "."
  717.       }
  718.       tables.push(String(thisSchema + thisTable.table))
  719.     }
  720.  
  721.     // Now get the views
  722.     views = new Array()
  723.     tableObjects = MMDB.getViews(CONN_LIST.getValue())
  724.     for (i = 0; i < tableObjects.length; i++)
  725.     {
  726.       thisTable = tableObjects[i]
  727.       thisSchema =  Trim(thisTable.schema)
  728.       if (thisSchema.length == 0)
  729.       {
  730.         thisSchema = Trim(thisTable.catalog)
  731.       }
  732.       if (thisSchema.length > 0)
  733.       {
  734.         thisSchema += "."
  735.       }
  736.       views.push(String(thisSchema + thisTable.view))
  737.     }
  738.  
  739.     if (views.length > 0)
  740.     {
  741.     var isMySQL = false;
  742.     var tableslen = tables.length;
  743.     var viewslen = views.length;
  744.  
  745.     if (tableslen == viewslen)
  746.     {
  747.      if ((tableslen) && (viewslen))
  748.      {
  749.       //Quick check for mysql...
  750.       if ((tables[0] == views[0]) &&
  751.           (tables[tableslen-1] == views[viewslen-1]) &&
  752.         (tables[tableslen/2] == views[viewslen/2]))
  753.       {
  754.         isMySQL = true;
  755.       }
  756.      }
  757.     }
  758.  
  759.     if (!isMySQL)
  760.     { 
  761.     tables = tables.concat(views)
  762.     }
  763.     }
  764.  
  765.   }
  766.  
  767.  
  768.   TABLE_LIST.setAll(tables, tables)
  769.   TABLE_LIST.setIndex(0)
  770.  
  771.   TableChanged()
  772.   RadioChanged()
  773. }
  774.  
  775.  
  776. function TableChanged()
  777. {
  778.   var colsAndTypes = MMDB.getColumnAndTypeOfTable(CONN_LIST.getValue(), TABLE_LIST.getValue())
  779.  
  780.   var cols = new Array()
  781.   gTypes = new Array()
  782.  
  783.   if (String(colsAndTypes[0]).indexOf("MM_ERROR:") == -1)
  784.   {
  785.     var numCols = 0
  786.     for (var i = 0; i < colsAndTypes.length; i+=2)
  787.     {
  788.       cols[numCols] = colsAndTypes[i]
  789.       gTypes[numCols] = colsAndTypes[i + 1]
  790.       numCols++
  791.     }
  792.   }
  793.  
  794.   COLUMN_LIST.setAll(cols, cols)
  795.  
  796.   var ops = COLUMN_LIST.object.options
  797.   
  798.   if(COLUMN_RADIO[0].checked)
  799.   {
  800.     if(ops.length > 0)
  801.     {
  802.       ops[0].selected = false
  803.     }
  804.   }
  805.  
  806.  
  807.   var colsWithNone = new Array(MM.LABEL_None)
  808.   colsWithNone = colsWithNone.concat(cols)
  809.   FILTER_COL.setAll(colsWithNone, colsWithNone)
  810.   SORT_COL.setAll(colsWithNone, colsWithNone)
  811.  
  812.  
  813.   //Reset the controls
  814.   PARAM_VAL.value = ""
  815.   // Set the ALL radio to be checked
  816.   COLUMN_RADIO[0].checked = true
  817.   //COLUMN_RADIO[1].checked = false
  818.   RadioChanged()
  819.   FILTER_COL.setIndex(0)
  820.   SORT_COL.setIndex(0)
  821.   FilterColChanged()
  822.   SortColChanged()
  823. }
  824.  
  825.  
  826.  
  827. function LaunchConnectionManager()
  828. {
  829.   var oldList = String(CONN_LIST.valueList).split(",")
  830.   MMDB.showConnectionMgrDialog()
  831.   PopulateConnectionList()
  832.   var newConnectionIndex = getNewConnection(oldList, CONN_LIST.valueList)
  833.   if (newConnectionIndex != -1)
  834.   {
  835.     CONN_LIST.setIndex(newConnectionIndex)
  836.   }
  837.   ConnectionChanged()
  838. }
  839.  
  840.  
  841. function RadioChanged()
  842. {
  843.  
  844.   var ops = COLUMN_LIST.object.options
  845.  
  846.   if(COLUMN_RADIO[0].checked)
  847.   {
  848.  
  849.     SetEnabled(COLUMN_LIST.object, false) 
  850.  
  851.     for (var i = 0; i < ops.length; i++)
  852.     {
  853.       ops[i].selected = false
  854.     }
  855.  
  856.   } 
  857.   else 
  858.   {
  859.  
  860.     SetEnabled(COLUMN_LIST.object, true)
  861.  
  862.   }
  863.  
  864. }
  865.  
  866.  
  867. function FilterColChanged()
  868. {
  869.   var filCol = FILTER_COL.getValue()
  870.   if (IsFilterEnabled() && (Trim(PARAM_VAL.value) == "" || PARAM_VAL.value == OLD_FILTER_COL_STRING))
  871.   {
  872.     // If the filter is enabled and
  873.     // (the param val is blank or the param val is the name of the old filter col)
  874.     // change the param val.
  875.     // If the user entered their own param val, we will not write over it.
  876.     PARAM_VAL.value = filCol
  877.     OLD_FILTER_COL_STRING = filCol  // Remember for next time we are called
  878.   }
  879.   SetFilterControlsEnabled(IsFilterEnabled())
  880. }
  881.  
  882.  
  883. function SortColChanged()
  884. {
  885.   SetEnabled(SORT_TYPE, IsSortEnabled())
  886. }
  887.  
  888.  
  889. function SetFilterControlsEnabled(enable)
  890. {
  891.   SetEnabled(OPERATOR, enable)
  892.   SetEnabled(PARAM_TYPE.object, enable)
  893.   SetEnabled(PARAM_VAL, enable)
  894. }
  895.  
  896.  
  897. // As opposed to the Advanced RS, the simple RS does not
  898. // automatically choose the connection if it is the only
  899. // one.  This is because it takes a while for the
  900. // UI to populate itself if we do it that way.
  901.  
  902. function PopulateConnectionList()
  903. {
  904.   var oldConn = CONN_LIST.getValue()
  905.  
  906.   var connList = MMDB.getConnectionList()
  907.  
  908.   var wholeList = new Array()
  909.  
  910.   wholeList.push(MM.LABEL_None)
  911.   for (var i = 0; i < connList.length; i++)
  912.   {
  913.     wholeList.push(connList[i])
  914.   }
  915.  
  916.   CONN_LIST.setAll(wholeList, wholeList)
  917.   CONN_LIST.setValue(MM.LABEL_None, 0)
  918.  
  919.   var index = CONN_LIST.getIndex(oldConn)
  920.  
  921.   if (!CONN_LIST.pickValue(oldConn)) 
  922.   {
  923.   
  924.     CONN_LIST.setIndex(0)
  925.     
  926.   }
  927. }
  928.  
  929.  
  930. function receiveArguments(errorMsg) {
  931.   ERROR_MESSAGE = errorMsg;
  932. }
  933.