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

  1. // Copyright 2002 Macromedia, Inc. All rights reserved.
  2.  
  3.  
  4. // *************** GLOBALS VARS *****************
  5.  
  6. var helpDoc = MM.HELP_ssAdvancedRecordset;
  7.  
  8.  
  9. var RECORDSET_SBOBJ;  // SBRecordset argument to the command.
  10. var CMD_FILENAME_SIMPLE;
  11.  
  12. var _RecordsetName = new TextField("Recordset.htm", "RecordsetName");
  13. var _ConnectionName = new ConnectionMenu("Recordset.htm", "ConnectionName");
  14. var _SQL = new TextField("Recordset.htm", "SQL");
  15. var _ParamList = null;
  16. var _DBTree = null;
  17.  
  18. var sqlObject = null;
  19.  
  20.  
  21. // ******************* API **********************
  22.  
  23. //--------------------------------------------------------------------
  24. // FUNCTION:
  25. //   commandButtons
  26. //
  27. // DESCRIPTION:
  28. //   Returns the list of buttons which should appear on the right hand
  29. //   side of the dialog
  30. //
  31. // ARGUMENTS:
  32. //   none
  33. //
  34. // RETURNS:
  35. //   Array - pairs of button name and function call
  36. //--------------------------------------------------------------------
  37.  
  38. function commandButtons()
  39. {
  40.   return new Array(MM.BTN_OK,     "clickedOK()", 
  41.                    MM.BTN_Cancel, "clickedCancel()", 
  42.                    MM.BTN_Test,   "clickedTest()", 
  43.                    MM.BTN_Simple, "clickedSimple()", 
  44.                    MM.BTN_Help,   "displayHelp()"); 
  45. }
  46.  
  47.  
  48. //--------------------------------------------------------------------
  49. // FUNCTION:
  50. //   clickedOK
  51. //
  52. // DESCRIPTION:
  53. //   This function is called when the user clicks OK
  54. //
  55. // ARGUMENTS:
  56. //   none
  57. //
  58. // RETURNS:
  59. //   nothing
  60. //--------------------------------------------------------------------
  61.  
  62. function clickedOK()
  63. {
  64.   // Update RECORDSET_SBOBJ from the UI.
  65.   updateSBRecordsetObject();
  66.  
  67.   recordsetDialog.onClickOK(window, RECORDSET_SBOBJ);
  68. }
  69.  
  70.  
  71. //--------------------------------------------------------------------
  72. // FUNCTION:
  73. //   clickedCancel
  74. //
  75. // DESCRIPTION:
  76. //   This function is called when CANCEL is clicked
  77. //
  78. // ARGUMENTS:
  79. //   none
  80. //
  81. // RETURNS:
  82. //   nothing
  83. //--------------------------------------------------------------------
  84.  
  85. function clickedCancel()
  86. {
  87.   recordsetDialog.onClickCancel(window);
  88. }
  89.  
  90.  
  91. //--------------------------------------------------------------------
  92. // FUNCTION:
  93. //   clickedTest
  94. //
  95. // DESCRIPTION:
  96. //   This function is called when the user clicks the TEST button
  97. //
  98. // ARGUMENTS:
  99. //   none
  100. //
  101. // RETURNS:
  102. //   nothing
  103. //--------------------------------------------------------------------
  104.  
  105. function clickedTest()
  106. {
  107.   // Update RECORDSET_SBOBJ from the UI.
  108.   updateSBRecordsetObject();
  109.  
  110.   recordsetDialog.displayTestDialog(RECORDSET_SBOBJ);
  111. }
  112.  
  113.  
  114. //--------------------------------------------------------------------
  115. // FUNCTION:
  116. //   clickedSimple
  117. //
  118. // DESCRIPTION:
  119. //   This function is called when the user clicks the SIMPLE button
  120. //
  121. // ARGUMENTS:
  122. //   none
  123. //
  124. // RETURNS:
  125. //   nothing
  126. //--------------------------------------------------------------------
  127.  
  128. function clickedSimple()
  129. {
  130.   // Update RECORDSET_SBOBJ from the UI.
  131.   updateSBRecordsetObject();
  132.  
  133.   recordsetDialog.onClickSwitchUI(window, recordsetDialog.UI_ACTION_SWITCH_SIMPLE, 
  134.                                   RECORDSET_SBOBJ, CMD_FILENAME_SIMPLE);
  135. }
  136.  
  137.  
  138. //--------------------------------------------------------------------
  139. // FUNCTION:
  140. //   displayHelp
  141. //
  142. // DESCRIPTION:
  143. //   This function is called when the user clicks the HELP button
  144. //
  145. // ARGUMENTS:
  146. //   none
  147. //
  148. // RETURNS:
  149. //   nothing
  150. //--------------------------------------------------------------------
  151.  
  152. function displayHelp()
  153. {
  154.   dwscripts.displayDWHelp(helpDoc);
  155. }
  156.  
  157.  
  158. // ***************** LOCAL FUNCTIONS  ******************
  159.  
  160. //--------------------------------------------------------------------
  161. // FUNCTION:
  162. //   initializeUI
  163. //
  164. // DESCRIPTION:
  165. //   This function is called in the onLoad event.  It is responsible
  166. //   for initializing the UI.  If we are inserting a recordset, this
  167. //   is a matter of populating the connection drop down.
  168. //
  169. //   If we are modifying a recordset, this is a matter of inspecting
  170. //   the recordset tag and setting all the form elements.
  171. //
  172. // ARGUMENTS:
  173. //   none
  174. //
  175. // RETURNS:
  176. //   nothing
  177. //--------------------------------------------------------------------
  178.  
  179. function initializeUI()
  180. {
  181.   var args = dwscripts.getCommandArguments();
  182.   RECORDSET_SBOBJ = args[0];
  183.   CMD_FILENAME_SIMPLE = args[1];
  184.   
  185.   // Get the UI elements
  186.   _RecordsetName.initializeUI();
  187.   _ConnectionName.initializeUI();
  188.   _SQL.initializeUI();
  189.   _ParamList = new GridControl("ParamList");
  190.   _DBTree = new DatabaseTreeControl("DBTree");
  191.  
  192.   var rsName = RECORDSET_SBOBJ.getRecordsetName();
  193.   if (!rsName)
  194.   {
  195.     rsName = RECORDSET_SBOBJ.getUniqueRecordsetName();
  196.   }
  197.   _RecordsetName.setValue(rsName);
  198.   
  199.   var connectionName = RECORDSET_SBOBJ.getConnectionName();
  200.   if (connectionName)
  201.   {
  202.     _ConnectionName.pickValue(RECORDSET_SBOBJ.getConnectionName());
  203.   }
  204.  
  205.   var sqlParams = new Array();
  206.   var sqlString = RECORDSET_SBOBJ.getDatabaseCall(sqlParams);
  207.   if (sqlString)
  208.   {
  209.     sqlObject = new SQLStatement(sqlString);
  210.     sqlObject.formatStatement();
  211.     _SQL.setValue(sqlObject.getStatement());
  212.   }
  213.   else
  214.   {
  215.     sqlObject = new SQLStatement("");
  216.   }
  217.  
  218.   var varArray = new Array();
  219.   var count = sqlParams.length;
  220.   for (var i=0; i < count; i++)
  221.   {
  222.     var param = sqlParams[i];
  223.     var row = new Array();
  224.     row.push(param.varName);
  225.     row.push(param.defaultValue);
  226.     row.push(param.runtimeValue);
  227.     varArray.push(row);
  228.   }
  229.   _ParamList.setAll(varArray);
  230.  
  231.   elts = document.forms[0].elements;
  232.   if (elts && elts.length)
  233.   {
  234.     elts[0].focus();
  235.     elts[0].select();
  236.   }
  237. }
  238.  
  239.  
  240. //--------------------------------------------------------------------
  241. // FUNCTION:
  242. //   updateUI
  243. //
  244. // DESCRIPTION:
  245. //   This function is called by the UI controls to handle UI updates
  246. //
  247. // ARGUMENTS:
  248. //   control - string - the name of the control sending the event
  249. //   event - string - the event which is being sent
  250. //
  251. // RETURNS:
  252. //   nothing
  253. //--------------------------------------------------------------------
  254.  
  255. function updateUI(control, event)
  256. {
  257.   if (control == "plusButton")
  258.   {
  259.     var cmdArgs = dwscripts.callCommand("AddPHPParam", null);
  260.     
  261.     if (cmdArgs)
  262.     {
  263.      // var param = new Object();
  264.      // param.name = cmdArgs[0];
  265.      // param.defValue = cmdArgs[1];
  266.      // param.runtime = cmdArgs[2];
  267.  
  268.       _ParamList.add( cmdArgs );
  269.       // _ParamList.add(param.name, param);
  270.      }
  271.   }
  272.   else if (control == "minusButton")
  273.   {
  274.     _ParamList.del();
  275.   }
  276.   else if (control == "Define")
  277.   {
  278.     _ConnectionName.launchConnectionDialog();
  279.     _DBTree.setConnection(_ConnectionName.getValue());
  280.   }
  281.   else if (control == "ConnectionName")
  282.   {
  283.     _DBTree.setConnection(_ConnectionName.getValue());
  284.   }
  285.   else if (control == "DBTree")
  286.   {
  287.     // place code here to enable and disable insertion buttons
  288.     // based on the DB tree selection
  289.   }
  290.   else if (control == "SelectButton")
  291.   {
  292.     sqlObject.setStatement(_SQL.getValue());
  293.     if (sqlObject.getType() == SQLStatement.STMT_TYPE_SELECT ||
  294.         sqlObject.getType() == SQLStatement.STMT_TYPE_EMPTY)
  295.     {
  296.       var dbInfo = _DBTree.getSelectedData();
  297.  
  298.       if ( dbInfo && (dbInfo.isTable() || dbInfo.isColumn()) )
  299.       {
  300.         sqlObject.addFrom(dbInfo.table);
  301.         if (dbInfo.isColumn())
  302.         {
  303.           sqlObject.addSelect(dbInfo.table, dbInfo.column);
  304.         }
  305.  
  306.         _SQL.setValue(sqlObject.getStatement());
  307.       }
  308.     }
  309.     else
  310.     {
  311.       alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements);
  312.     }
  313.   }
  314.   else if (control == "WhereButton")
  315.   {
  316.     sqlObject.setStatement(_SQL.getValue());
  317.     if (sqlObject.getType() == SQLStatement.STMT_TYPE_SELECT)
  318.     {
  319.       var dbInfo = _DBTree.getSelectedData();
  320.  
  321.       if ( dbInfo && dbInfo.isColumn() )
  322.       {
  323.         sqlObject.addWhere(dbInfo.table, dbInfo.column);
  324.         _SQL.setValue(sqlObject.getStatement());
  325.       }
  326.     }
  327.     else if (sqlObject.getType() != SQLStatement.STMT_TYPE_EMPTY)
  328.     {
  329.       alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements);
  330.     }
  331.   }
  332.   else if (control == "OrderByButton")
  333.   {
  334.     sqlObject.setStatement(_SQL.getValue());
  335.     if (sqlObject.getType() == SQLStatement.STMT_TYPE_SELECT)
  336.     {
  337.       var dbInfo = _DBTree.getSelectedData();
  338.  
  339.       if ( dbInfo && dbInfo.isColumn() )
  340.       {
  341.         sqlObject.addOrderBy(dbInfo.table, dbInfo.column);
  342.         _SQL.setValue(sqlObject.getStatement());
  343.       }
  344.     }
  345.     else if (sqlObject.getType() != SQLStatement.STMT_TYPE_EMPTY)
  346.     {
  347.       alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements);
  348.     }
  349.   }
  350.   else if (control == "SQL")
  351.   {
  352.   }
  353. }
  354.  
  355.  
  356. //--------------------------------------------------------------------
  357. // FUNCTION:
  358. //   updateSBRecordsetObject
  359. //
  360. // DESCRIPTION:
  361. //   Collects information from the UI and sets the SBRecordset object
  362. //
  363. // ARGUMENTS:
  364. //   none
  365. //
  366. // RETURNS:
  367. //   boolean - true if successful, false otherwise
  368. //--------------------------------------------------------------------
  369.  
  370. function updateSBRecordsetObject()
  371. {
  372.   RECORDSET_SBOBJ.setRecordsetName(_RecordsetName.getValue());
  373.  
  374.   RECORDSET_SBOBJ.setConnectionName(_ConnectionName.getValue());
  375.  
  376.   var sqlParams = new Array();
  377.   var varArray = _ParamList.getAll();
  378.   for (var i=0; i < varArray.length; i++)
  379.   {
  380.     var param = new Object();
  381.     param.varName = varArray[i][0];
  382.     param.defaultValue = varArray[i][1];
  383.     param.runtimeValue = varArray[i][2];
  384.     sqlParams.push(param);
  385.   }
  386.  
  387.   RECORDSET_SBOBJ.setDatabaseCall(_SQL.getValue(), sqlParams);
  388. }
  389.  
  390.  
  391.  
  392.  
  393.