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 / ServerBeh-PHP-AdvRS.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  9.6 KB  |  394 lines

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