home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 July / 07_02.iso / software / mdmx / files / DreamweaverMXInstaller.exe / Disk1 / data1.cab / Configuration_En / Commands / ServerBeh4-SimpRS.js < prev    next >
Encoding:
JavaScript  |  2002-05-01  |  18.9 KB  |  932 lines

  1. // Copyright 2002 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.   {
  502.     retVal = "'";
  503.   }
  504.   
  505.   return retVal;
  506. }
  507.  
  508.  
  509. function GetColumns()
  510. {
  511.   var cols = "*"
  512.  
  513.   if (COLUMN_RADIO[1].checked)
  514.   {
  515.     var ops = COLUMN_LIST.object.options
  516.     cols = ""
  517.     for (var i = 0; i < ops.length; i++)
  518.     {
  519.       if (ops[i].selected)
  520.       {
  521.         if(cols != "")
  522.         {
  523.           cols += ", "
  524.         }
  525.         cols += ops[i].text
  526.       }
  527.     }
  528.   }
  529.  
  530.   return cols
  531. }
  532.  
  533. function initializeUI()
  534. {
  535.   
  536.   //Create global vars for all controls
  537.   
  538.   MM.SimpleRecordsetDefaultVal = null  //Clear the default Val holder. It
  539.                                           //may be set again in inspectUI
  540.   
  541.   RS_NAME_BOX = findObject("RecordsetName")
  542.  
  543.   RS_NAME_BOX.value = CreateNewName()
  544.   CONN_LIST = new ListControl("ConnectionList")
  545.  
  546.   COLUMN_RADIO = findObject("RadioButton")
  547.   TABLE_LIST = new ListControl("TableList")
  548.   COLUMN_LIST = new ListControl("ColumnList")
  549.  
  550.   FILTER_COL = new ListControl("ColumnDropDown")
  551.   OPERATOR = findObject("OperatorDropDown")
  552.   PARAM_TYPE = new ListControl("ParameterTypeDropDown")
  553.   PARAM_VAL = findObject("ParameterValue")
  554.   SORT_COL = new ListControl("SortByColumnDropDown")
  555.   SORT_TYPE = findObject("SortByTypeDropDown")
  556.  
  557.   OLD_FILTER_COL_STRING = ""  // Global var to remember the last filter
  558.                               // col selected. (This var is used in
  559.                               // FilterColChanged and inspectFilter)
  560.  
  561.   PopulateConnectionList()
  562.  
  563.   ConnectionChanged()
  564.  
  565.   PopulateParamTypeList() 
  566.  
  567.  
  568.   if (MM.RecordsetSwitchingUI || MM.RecordsetPriorRec)
  569.   {
  570.  
  571.     inspectUI()
  572.  
  573.   }
  574.   else
  575.   {
  576.     // Make sure these are disabled
  577.  
  578.     FILTER_COL.setIndex(0)
  579.     SetFilterControlsEnabled(false)
  580.  
  581.     SORT_COL.setIndex(0)
  582.     SetEnabled(SORT_TYPE, false)
  583.  
  584.   }
  585.  
  586.   if (ERROR_MESSAGE) alert(ERROR_MESSAGE);
  587.   
  588.   elts = document.forms[0].elements;
  589.   if (elts && elts.length)
  590.   {
  591.     elts[0].focus();
  592.     elts[0].select();
  593.   }
  594. }
  595.  
  596.  
  597. function PopulateParamTypeList()
  598. {
  599.   var paramTypes = GetParamTypeArray()
  600.   PARAM_TYPE.setAll(paramTypes, paramTypes)
  601.   PARAM_TYPE.setIndex(0)
  602. }
  603.  
  604.  
  605. function IsFilterEnabled()
  606. {
  607.   return (FILTER_COL.object.selectedIndex > 0)
  608. }
  609.  
  610.  
  611. function IsSortEnabled()
  612. {
  613.   return (SORT_COL.object.selectedIndex > 0)
  614. }
  615.  
  616.  
  617. function PopUpTestDialog()
  618. {
  619.  
  620.   var msg = CheckData(FOR_TEST, "")
  621.   if (msg != "")
  622.   {
  623.     alert(msg)
  624.     return
  625.   }
  626.  
  627.   var statement = GetSQLFromUI()
  628.  
  629.   if (IsFilterEnabled())
  630.   {
  631.   
  632.     var isEmpty = Trim(PARAM_VAL.value) == ""
  633.   
  634.     if (!IsLiteralValue(PARAM_TYPE.getIndex()))
  635.     {
  636.       // Pop up a dialog to get the default value to use in the test  
  637.       MM.paramName = PARAM_TYPE.getValue() + ": " + PARAM_VAL.value
  638.       dw.runCommand("GetTestValue")
  639.       if (!MM.clickedOK)
  640.       {
  641.         return
  642.       }
  643.     }
  644.     else
  645.     {
  646.       // The user has chosen to provide the comparison value of the filter
  647.       MM.retVal = PARAM_VAL.value
  648.     }
  649.   }
  650.  
  651.   var re = new RegExp("\\b" + gSimpleParamName + "\\b", "g")
  652.  
  653.   statement = statement.replace(re, String(MM.retVal).replace(/'/g, "''"))
  654.  
  655.   //alert(statement)
  656.  
  657.   MMDB.showResultset(CONN_LIST.getValue(), statement)
  658. }
  659.  
  660.  
  661. function RemoveWhereClause(sql)
  662. {
  663.   var theSQL = String(sql)
  664.   var strOut = theSQL
  665.  
  666.   var wherePos = theSQL.search(/\s+where\s+/i)
  667.   if (wherePos != -1)
  668.   {
  669.     var orderByPos = theSQL.search(/\s+order\s+by\s+/i)
  670.     if (orderByPos != -1)
  671.     {
  672.       strOut = theSQL.substring(0, wherePos) + theSQL.substring(orderByPos)
  673.     }
  674.     else
  675.     {
  676.       strOut = theSQL.substring(0, wherePos)
  677.     }
  678.   }
  679.  
  680.   return strOut
  681. }
  682.  
  683.  
  684. function ConnectionChanged()
  685. {
  686.  
  687.   var i, tables
  688.   
  689.   if (CONN_LIST.getIndex() == 0)
  690.   {
  691.     tables = new Array()
  692.   }
  693.   else
  694.   {
  695.     // Get the tables and views
  696.  
  697.     // First get the tables
  698.     tables = new Array()
  699.     tableObjects = MMDB.getTables(CONN_LIST.getValue())    
  700.     if (tableObjects.length == 0)
  701.     {
  702.       alert(MM.MSG_ConnErrs)
  703.     }
  704.     for (i = 0; i < tableObjects.length; i++)
  705.     {
  706.       var thisTable = tableObjects[i]
  707.       thisSchema =  Trim(thisTable.schema)
  708.       if (thisSchema.length == 0)
  709.       {
  710.         thisSchema = Trim(thisTable.catalog)
  711.       }
  712.       if (thisSchema.length > 0)
  713.       {
  714.         thisSchema += "."
  715.       }
  716.       tables.push(String(thisSchema + thisTable.table))
  717.     }
  718.  
  719.     // Now get the views
  720.     views = new Array()
  721.     tableObjects = MMDB.getViews(CONN_LIST.getValue())
  722.     for (i = 0; i < tableObjects.length; i++)
  723.     {
  724.       thisTable = tableObjects[i]
  725.       thisSchema =  Trim(thisTable.schema)
  726.       if (thisSchema.length == 0)
  727.       {
  728.         thisSchema = Trim(thisTable.catalog)
  729.       }
  730.       if (thisSchema.length > 0)
  731.       {
  732.         thisSchema += "."
  733.       }
  734.       views.push(String(thisSchema + thisTable.view))
  735.     }
  736.  
  737.     if (views.length > 0)
  738.     {
  739.     var isMySQL = false;
  740.     var tableslen = tables.length;
  741.     var viewslen = views.length;
  742.  
  743.     if (tableslen == viewslen)
  744.     {
  745.      if ((tableslen) && (viewslen))
  746.      {
  747.       //Quick check for mysql...
  748.       if ((tables[0] == views[0]) &&
  749.           (tables[tableslen-1] == views[viewslen-1]) &&
  750.         (tables[tableslen/2] == views[viewslen/2]))
  751.       {
  752.         isMySQL = true;
  753.       }
  754.      }
  755.     }
  756.  
  757.     if (!isMySQL)
  758.     { 
  759.     tables = tables.concat(views)
  760.     }
  761.     }
  762.  
  763.   }
  764.  
  765.  
  766.   TABLE_LIST.setAll(tables, tables)
  767.   TABLE_LIST.setIndex(0)
  768.  
  769.   TableChanged()
  770.   RadioChanged()
  771. }
  772.  
  773.  
  774. function TableChanged()
  775. {
  776.   var colsAndTypes = MMDB.getColumnAndTypeOfTable(CONN_LIST.getValue(), TABLE_LIST.getValue())
  777.  
  778.   var cols = new Array()
  779.   gTypes = new Array()
  780.  
  781.   if (String(colsAndTypes[0]).indexOf("MM_ERROR:") == -1)
  782.   {
  783.     var numCols = 0
  784.     for (var i = 0; i < colsAndTypes.length; i+=2)
  785.     {
  786.       cols[numCols] = colsAndTypes[i]
  787.       gTypes[numCols] = colsAndTypes[i + 1]
  788.       numCols++
  789.     }
  790.   }
  791.  
  792.   COLUMN_LIST.setAll(cols, cols)
  793.  
  794.   var ops = COLUMN_LIST.object.options
  795.   
  796.   if(COLUMN_RADIO[0].checked)
  797.   {
  798.     if(ops.length > 0)
  799.     {
  800.       ops[0].selected = false
  801.     }
  802.   }
  803.  
  804.  
  805.   var colsWithNone = new Array(MM.LABEL_None)
  806.   colsWithNone = colsWithNone.concat(cols)
  807.   FILTER_COL.setAll(colsWithNone, colsWithNone)
  808.   SORT_COL.setAll(colsWithNone, colsWithNone)
  809.  
  810.  
  811.   //Reset the controls
  812.   PARAM_VAL.value = ""
  813.   // Set the ALL radio to be checked
  814.   COLUMN_RADIO[0].checked = true
  815.   //COLUMN_RADIO[1].checked = false
  816.   RadioChanged()
  817.   FILTER_COL.setIndex(0)
  818.   SORT_COL.setIndex(0)
  819.   FilterColChanged()
  820.   SortColChanged()
  821. }
  822.  
  823.  
  824.  
  825. function LaunchConnectionManager()
  826. {
  827.   var oldList = String(CONN_LIST.valueList).split(",")
  828.   MMDB.showConnectionMgrDialog()
  829.   PopulateConnectionList()
  830.   var newConnectionIndex = getNewConnection(oldList, CONN_LIST.valueList)
  831.   if (newConnectionIndex != -1)
  832.   {
  833.     CONN_LIST.setIndex(newConnectionIndex)
  834.   }
  835.   ConnectionChanged()
  836. }
  837.  
  838.  
  839. function RadioChanged()
  840. {
  841.  
  842.   var ops = COLUMN_LIST.object.options
  843.  
  844.   if(COLUMN_RADIO[0].checked)
  845.   {
  846.  
  847.     SetEnabled(COLUMN_LIST.object, false) 
  848.  
  849.     for (var i = 0; i < ops.length; i++)
  850.     {
  851.       ops[i].selected = false
  852.     }
  853.  
  854.   } 
  855.   else 
  856.   {
  857.  
  858.     SetEnabled(COLUMN_LIST.object, true)
  859.  
  860.   }
  861.  
  862. }
  863.  
  864.  
  865. function FilterColChanged()
  866. {
  867.   var filCol = FILTER_COL.getValue()
  868.   if (IsFilterEnabled() && (Trim(PARAM_VAL.value) == "" || PARAM_VAL.value == OLD_FILTER_COL_STRING))
  869.   {
  870.     // If the filter is enabled and
  871.     // (the param val is blank or the param val is the name of the old filter col)
  872.     // change the param val.
  873.     // If the user entered their own param val, we will not write over it.
  874.     PARAM_VAL.value = filCol
  875.     OLD_FILTER_COL_STRING = filCol  // Remember for next time we are called
  876.   }
  877.   SetFilterControlsEnabled(IsFilterEnabled())
  878. }
  879.  
  880.  
  881. function SortColChanged()
  882. {
  883.   SetEnabled(SORT_TYPE, IsSortEnabled())
  884. }
  885.  
  886.  
  887. function SetFilterControlsEnabled(enable)
  888. {
  889.   SetEnabled(OPERATOR, enable)
  890.   SetEnabled(PARAM_TYPE.object, enable)
  891.   SetEnabled(PARAM_VAL, enable)
  892. }
  893.  
  894.  
  895. // As opposed to the Advanced RS, the simple RS does not
  896. // automatically choose the connection if it is the only
  897. // one.  This is because it takes a while for the
  898. // UI to populate itself if we do it that way.
  899.  
  900. function PopulateConnectionList()
  901. {
  902.   var oldConn = CONN_LIST.getValue()
  903.  
  904.   var connList = MMDB.getConnectionList()
  905.  
  906.   var wholeList = new Array()
  907.  
  908.   wholeList.push(MM.LABEL_None)
  909.   for (var i = 0; i < connList.length; i++)
  910.   {
  911.     wholeList.push(connList[i])
  912.   }
  913.  
  914.   CONN_LIST.setAll(wholeList, wholeList)
  915.   CONN_LIST.setValue(MM.LABEL_None, 0)
  916.  
  917.   var index = CONN_LIST.getIndex(oldConn)
  918.  
  919.   if (!CONN_LIST.pickValue(oldConn)) 
  920.   {
  921.   
  922.     CONN_LIST.setIndex(0)
  923.     
  924.   }
  925. }
  926.  
  927.  
  928. function receiveArguments(errorMsg) {
  929.   ERROR_MESSAGE = errorMsg;
  930. }
  931.