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-ASPNET-AdvRS.js < prev    next >
Encoding:
JavaScript  |  2002-05-01  |  14.4 KB  |  567 lines

  1. // Copyright 2002 Macromedia, Inc. All rights reserved.
  2.  
  3. // *************** GLOBALS VARS *****************
  4.  
  5. var helpDoc = MM.HELP_sbASPNetAdvRecordset;
  6.  
  7. var SB_FILENAME = dwscripts.getSBFileName();
  8. var RECORDSET_SBOBJ;  // SBRecordset argument to the command.
  9. var CMD_FILENAME_SIMPLE;
  10. var STATIC_LENGTH = 190;
  11.  
  12. var _RecordsetName = new TextField(SB_FILENAME, "RecordsetName");
  13. var _ConnectionName = new ConnectionMenu(SB_FILENAME, "ConnectionName");
  14. var _SQL = new TextField(SB_FILENAME, "SQL");
  15. var _ParamList = new ListControl("ParamList");
  16. var _ParamName = null;
  17. var _ParamType = null;
  18. var _ParamValue = null;
  19. var _DBTree = null;
  20. var _PlusBtn = null;
  21. var _MinusBtn = null;
  22. var _SelectBtn = null;
  23. var _WhereBtn = null;
  24. var _OrderByBtn = null;
  25. var _FailureURL = new TextField(SB_FILENAME, "FailureURL");
  26. var _DebugInfo = new CheckBox(SB_FILENAME, "Debug");
  27. var _ParamEditBtn = null;
  28.  
  29. var sqlObject = null;
  30. var databaseType = null;
  31.  
  32. // ******************* API **********************
  33.  
  34. //--------------------------------------------------------------------
  35. // FUNCTION:
  36. //   commandButtons
  37. //
  38. // DESCRIPTION:
  39. //   Returns the list of buttons which should appear on the right hand
  40. //   side of the dialog
  41. //
  42. // ARGUMENTS:
  43. //   none
  44. //
  45. // RETURNS:
  46. //   Array - pairs of button name and function call
  47. //--------------------------------------------------------------------
  48.  
  49. function commandButtons()
  50. {
  51.   return new Array(MM.BTN_OK,     "clickedOK()", 
  52.                    MM.BTN_Cancel, "clickedCancel()", 
  53.                    MM.BTN_Test,   "clickedTest()", 
  54.                    MM.BTN_Simple, "clickedSimple()", 
  55.                    MM.BTN_Help,   "displayHelp()"); 
  56. }
  57.  
  58. //--------------------------------------------------------------------
  59. // FUNCTION:
  60. //   clickedOK
  61. //
  62. // DESCRIPTION:
  63. //   This function is called when the user clicks OK
  64. //
  65. // ARGUMENTS:
  66. //   none
  67. //
  68. // RETURNS:
  69. //   nothing
  70. //--------------------------------------------------------------------
  71.  
  72. function clickedOK()
  73. {
  74.   updateSBRecordsetObject();
  75.   recordsetDialog.onClickOK(window, RECORDSET_SBOBJ);
  76. }
  77.  
  78. //--------------------------------------------------------------------
  79. // FUNCTION:
  80. //   clickedCancel
  81. //
  82. // DESCRIPTION:
  83. //   This function is called when CANCEL is clicked
  84. //
  85. // ARGUMENTS:
  86. //   none
  87. //
  88. // RETURNS:
  89. //   nothing
  90. //--------------------------------------------------------------------
  91.  
  92. function clickedCancel()
  93. {
  94.   recordsetDialog.onClickCancel(window);
  95. }
  96.  
  97. //--------------------------------------------------------------------
  98. // FUNCTION:
  99. //   clickedTest
  100. //
  101. // DESCRIPTION:
  102. //   This function is called when the user clicks the TEST button
  103. //
  104. // ARGUMENTS:
  105. //   none
  106. //
  107. // RETURNS:
  108. //   nothing
  109. //--------------------------------------------------------------------
  110.  
  111. function clickedTest()
  112. {
  113.   updateSBRecordsetObject();
  114.   recordsetDialog.displayTestDialog(RECORDSET_SBOBJ);
  115. }
  116.  
  117. //--------------------------------------------------------------------
  118. // FUNCTION:
  119. //   clickedSimple
  120. //
  121. // DESCRIPTION:
  122. //   This function is called when the user clicks the SIMPLE button
  123. //
  124. // ARGUMENTS:
  125. //   none
  126. //
  127. // RETURNS:
  128. //   nothing
  129. //--------------------------------------------------------------------
  130.  
  131. function clickedSimple()
  132. {
  133.   updateSBRecordsetObject();
  134.   recordsetDialog.onClickSwitchUI(window,
  135.                                   recordsetDialog.UI_ACTION_SWITCH_SIMPLE, 
  136.                                   RECORDSET_SBOBJ,
  137.                                   CMD_FILENAME_SIMPLE);
  138. }
  139.  
  140. //--------------------------------------------------------------------
  141. // FUNCTION:
  142. //   displayHelp
  143. //
  144. // DESCRIPTION:
  145. //   This function is called when the user clicks the HELP button
  146. //
  147. // ARGUMENTS:
  148. //   none
  149. //
  150. // RETURNS:
  151. //   nothing
  152. //--------------------------------------------------------------------
  153.  
  154. function displayHelp()
  155. {
  156.   dwscripts.displayDWHelp(helpDoc);
  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.  
  184.   RECORDSET_SBOBJ = args[0];
  185.   CMD_FILENAME_SIMPLE = args[1];
  186.   
  187.   RECORDSET_SBOBJ.transformURLs(false);
  188.  
  189.   // Get the UI elements
  190.  
  191.   _RecordsetName.initializeUI();
  192.   _ConnectionName.initializeUI();
  193.   _SQL.initializeUI();
  194.   _DBTree = new DatabaseTreeControl("DBTree");
  195.   _SelectBtn = dwscripts.findDOMObject("SelectButton"); 
  196.   _WhereBtn = dwscripts.findDOMObject("WhereButton"); 
  197.   _OrderByBtn = dwscripts.findDOMObject("OrderByButton"); 
  198.   _PlusBtn = new ImageButton("plusButton", "_PlusBtn", "sSd", false);
  199.   _MinusBtn = new ImageButton("minusButton", "_MinusBtn", "sSd", false);
  200.   _ParamEditBtn = dwscripts.findDOMObject("EditParam"); 
  201.   _FailureURL.initializeUI(); 
  202.   _DebugInfo.initializeUI(); 
  203.  
  204.   _ParamName = dwscripts.findDOMObject("ParamName");
  205.   _ParamType = dwscripts.findDOMObject("ParamType");
  206.   _ParamValue = dwscripts.findDOMObject("ParamValue");
  207.  
  208.   // set the readonly param properties
  209.   _ParamName.innerHTML = dwscripts.entityNameEncode(MM.LABEL_ParamAttributesName);
  210.   _ParamType.innerHTML = dwscripts.entityNameEncode(MM.LABEL_ParamAttributesType);
  211.   _ParamValue.innerHTML = dwscripts.entityNameEncode(MM.LABEL_ParamAttributesValue);
  212.  
  213.   var rsName = RECORDSET_SBOBJ.getRecordsetName();
  214.  
  215.   if (!rsName)
  216.   {
  217.     rsName = RECORDSET_SBOBJ.getUniqueRecordsetName();
  218.   }
  219.  
  220.   _RecordsetName.setValue(rsName);
  221.   
  222.   var connectionName = RECORDSET_SBOBJ.getConnectionName();
  223.  
  224.   if (connectionName)
  225.   {
  226.     _ConnectionName.pickValue(RECORDSET_SBOBJ.getConnectionName());
  227.     databaseType = MMDB.getDatabaseType(connectionName);
  228.   }
  229.  
  230.   var sqlParams = new Array();
  231.   var sqlString = RECORDSET_SBOBJ.getDatabaseCall(sqlParams);
  232.  
  233.   if (sqlString)
  234.   {
  235.     sqlObject = new SQLStatement(sqlString);
  236.  
  237.     sqlObject.formatStatement();
  238.     _SQL.setValue(sqlObject.getStatement());
  239.   }
  240.   else
  241.   {
  242.     sqlObject = new SQLStatement("");
  243.   }
  244.  
  245.   var paramNames = new Array();
  246.  
  247.   for (var i = 0; i < sqlParams.length; i++)
  248.   {
  249.     paramNames.push(sqlParams[i].name);
  250.   }
  251.  
  252.   _ParamList.setAll(paramNames, sqlParams);
  253.  
  254.   onParameterChanged();
  255.  
  256.   _FailureURL.setValue(RECORDSET_SBOBJ.getFailureURL());
  257.   _DebugInfo.setCheckedState(RECORDSET_SBOBJ.getDebug());
  258.  
  259.   updateUI("Debug");
  260.  
  261.   elts = document.forms[0].elements;
  262.   if (elts && elts.length)
  263.   {
  264.     elts[0].focus();
  265.     elts[0].select();
  266.   }
  267. }
  268.  
  269. //--------------------------------------------------------------------
  270. // FUNCTION:
  271. //   setUIDisabledStateForSP
  272. //
  273. // DESCRIPTION:
  274. //   Determines whether a stored procedure item has been selected in the 
  275. //   DBTree control. If it has, disable the SQL buttons (select, where, orderby)
  276. //   and also set the plus/minus button be disabled. Otherwise, maintain 
  277. //   the default state of the dialog where these controls are enabled. 
  278. //
  279. // ARGUMENTS:
  280. //   none
  281. //
  282. // RETURNS:
  283. //   none
  284. //--------------------------------------------------------------------
  285.  
  286. function setUIDisabledStateForSP()
  287. {
  288.   var dbTreeInfo = _DBTree.getSelectedData(); 
  289.   var StoredProcWarnNode = dwscripts.findDOMObject("StoredProcWarning"); 
  290.  
  291.   if (dbTreeInfo.isProcedure())
  292.   {
  293.     _SelectBtn.setAttribute("disabled", "true"); 
  294.     _WhereBtn.setAttribute("disabled", "true");     
  295.     _OrderByBtn.setAttribute("disabled", "true"); 
  296.  
  297.     StoredProcWarnNode.innerHTML = dwscripts.entityNameEncode(MM.MSG_StoredProcWarning); 
  298.   }
  299.   else 
  300.   {
  301.     _SelectBtn.removeAttribute("disabled"); 
  302.     _WhereBtn.removeAttribute("disabled");     
  303.     _OrderByBtn.removeAttribute("disabled");   
  304.  
  305.     StoredProcWarnNode.innerHTML = ""; 
  306.   }
  307.  
  308.   updateButtons();
  309. }
  310.  
  311. //--------------------------------------------------------------------
  312. // FUNCTION:
  313. //   updateUI
  314. //
  315. // DESCRIPTION:
  316. //   This function is called by the UI controls to handle UI updates
  317. //
  318. // ARGUMENTS:
  319. //   control - string - the name of the control sending the event
  320. //   event - string - the event which is being sent
  321. //
  322. // RETURNS:
  323. //   nothing
  324. //--------------------------------------------------------------------
  325.  
  326. function updateUI(control, event)
  327. {
  328.   if (control == "plusButton")
  329.   {
  330.     if (!_PlusBtn.disabled)
  331.     {
  332.       var cmdArgs = new Array();
  333.   
  334.       cmdArgs.push(databaseType);
  335.     
  336.       cmdArgs = dwscripts.callCommand("AddASPNETParam", cmdArgs);
  337.  
  338.       if (cmdArgs)
  339.       {
  340.         var param = new Object();
  341.  
  342.         param.name = cmdArgs[0];
  343.         param.type = cmdArgs[1];
  344.         param.runtime = cmdArgs[2];
  345.       
  346.         _ParamList.add(param.name, param);
  347.         onParameterChanged();
  348.       }
  349.     }
  350.   }
  351.   else if (control == "minusButton")
  352.   {
  353.     if (!_MinusBtn.disabled)
  354.     {
  355.       _ParamList.del();
  356.       onParameterChanged();
  357.     }
  358.   }
  359.   else if (control == "Define")
  360.   {
  361.     var before = _ConnectionName.getValue();
  362.  
  363.     _ConnectionName.launchConnectionDialog();
  364.  
  365.     if (before != _ConnectionName.getValue())
  366.     {
  367.       updateUI("ConnectionName");
  368.     }
  369.   }
  370.   else if (control == "ConnectionName")
  371.   {
  372.     var connName = _ConnectionName.getValue();
  373.  
  374.     _DBTree.setConnection(connName);
  375.     databaseType = MMDB.getDatabaseType(connName);
  376.  
  377.     updateButtons();
  378.   }
  379.   else if (control == "ParamList")
  380.   {
  381.     onParameterChanged();
  382.   }
  383.   else if (control == "EditParam")
  384.   {
  385.     var param = _ParamList.getValue();
  386.     var cmdArgs = new Array();
  387.     
  388.     cmdArgs[0] = databaseType;
  389.     cmdArgs[1] = param.name;
  390.     cmdArgs[2] = param.type;
  391.     cmdArgs[3] = param.runtime;
  392.     
  393.     var ret = dwscripts.callCommand("EditASPNETParam", cmdArgs);
  394.     
  395.     if (ret && ret.length)
  396.     {
  397.       param.name = ret[0];
  398.       param.type = ret[1];
  399.       param.runtime = ret[2];
  400.  
  401.       _ParamList.set(param.name);
  402.  
  403.       onParameterChanged();
  404.     }
  405.   }
  406.   else if (control == "FailureURL")
  407.   {
  408.     var theFailureURL = dw.browseForFileURL("select", MM.LABEL_FileRedirect,0,0); 
  409.     
  410.     if (theFailureURL.length > 0)
  411.     {
  412.       _FailureURL.setValue(theFailureURL); 
  413.     }    
  414.   }
  415.   else if (control == "Debug")
  416.   {
  417.     _FailureURL.setDisabled(_DebugInfo.getCheckedState());
  418.   }
  419.   else if (control == "DBTree")
  420.   {
  421.     setUIDisabledStateForSP(); 
  422.   }
  423.   else if (control == "SelectButton")
  424.   {
  425.     sqlObject.setStatement(_SQL.getValue());
  426.  
  427.     if (sqlObject.getType() == SQLStatement.STMT_TYPE_SELECT ||
  428.         sqlObject.getType() == SQLStatement.STMT_TYPE_EMPTY)
  429.     {
  430.       var dbInfo = _DBTree.getSelectedData();
  431.  
  432.       if ( dbInfo && (dbInfo.isTable() || dbInfo.isColumn()) )
  433.       {
  434.         sqlObject.addFrom(dbInfo.table);
  435.  
  436.         if (dbInfo.isColumn())
  437.         {
  438.           sqlObject.addSelect(dbInfo.table, dbInfo.column);
  439.         }
  440.  
  441.         _SQL.setValue(sqlObject.getStatement());
  442.       }
  443.     }
  444.     else
  445.     {
  446.       alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements);
  447.     }
  448.   }
  449.   else if (control == "WhereButton")
  450.   {
  451.     sqlObject.setStatement(_SQL.getValue());
  452.  
  453.     if (sqlObject.getType() == SQLStatement.STMT_TYPE_SELECT)
  454.     {
  455.       var dbInfo = _DBTree.getSelectedData();
  456.  
  457.       if (dbInfo && dbInfo.isColumn())
  458.       {
  459.         sqlObject.addWhere(dbInfo.table, dbInfo.column);
  460.         _SQL.setValue(sqlObject.getStatement());
  461.       }
  462.     }
  463.     else if (sqlObject.getType() != SQLStatement.STMT_TYPE_EMPTY)
  464.     {
  465.       alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements);
  466.     }
  467.   }
  468.   else if (control == "OrderByButton")
  469.   {
  470.     sqlObject.setStatement(_SQL.getValue());
  471.  
  472.     if (sqlObject.getType() == SQLStatement.STMT_TYPE_SELECT)
  473.     {
  474.       var dbInfo = _DBTree.getSelectedData();
  475.  
  476.       if (dbInfo && dbInfo.isColumn())
  477.       {
  478.         sqlObject.addOrderBy(dbInfo.table, dbInfo.column);
  479.         _SQL.setValue(sqlObject.getStatement());
  480.       }
  481.     }
  482.     else if (sqlObject.getType() != SQLStatement.STMT_TYPE_EMPTY)
  483.     {
  484.       alert(MM.MSG_CanOnlyUseButtonsOnSelectStatements);
  485.     }
  486.   }
  487. }
  488.  
  489. //--------------------------------------------------------------------
  490. // FUNCTION:
  491. //   updateSBRecordsetObject
  492. //
  493. // DESCRIPTION:
  494. //   Collects information from the UI and sets the SBRecordset object
  495. //
  496. // ARGUMENTS:
  497. //   none
  498. //
  499. // RETURNS:
  500. //   boolean - true if successful, false otherwise
  501. //--------------------------------------------------------------------
  502.  
  503. function updateSBRecordsetObject()
  504. {
  505.   RECORDSET_SBOBJ.setRecordsetName(_RecordsetName.getValue());
  506.   RECORDSET_SBOBJ.setConnectionName(_ConnectionName.getValue());
  507.  
  508.   var sql = dwscripts.trim(_SQL.getValue());
  509.   var params = _ParamList.getValue('all');
  510.  
  511.   RECORDSET_SBOBJ.setDatabaseCall(sql, params);
  512.   RECORDSET_SBOBJ.setFailureURL(_FailureURL.getValue());
  513.   RECORDSET_SBOBJ.transformURLs(true);
  514.   RECORDSET_SBOBJ.setDebug(_DebugInfo.getCheckedState());
  515. }
  516.  
  517. function onParameterChanged()
  518. {
  519.   var paramName = "";
  520.   var paramType = "";
  521.   var paramValue = "";
  522.  
  523.   var param = _ParamList.getValue();
  524.     
  525.   if (param)
  526.   {
  527.       paramName = param.name;
  528.     paramType = param.type;
  529.     paramValue = param.runtime;
  530.   }
  531.  
  532.   var shortParamName = dw.shortenString(MM.LABEL_ParamAttributesName + paramName, STATIC_LENGTH, false);
  533.   _ParamName.innerHTML = dwscripts.entityNameEncode(shortParamName);
  534.   
  535.   var shortParamType = dw.shortenString(MM.LABEL_ParamAttributesType + paramType, STATIC_LENGTH, false);
  536.   _ParamType.innerHTML = dwscripts.entityNameEncode(shortParamType);
  537.  
  538.   var shortParamValue= dw.shortenString(MM.LABEL_ParamAttributesValue + paramValue, STATIC_LENGTH, false);
  539.   _ParamValue.innerHTML = dwscripts.entityNameEncode(shortParamValue);
  540.  
  541.   updateButtons();
  542. }
  543.  
  544. function updateButtons()
  545. {
  546.   var param = _ParamList.getValue();
  547.   var dbTreeInfo = _DBTree.getSelectedData(); 
  548.   var isProcedure = dbTreeInfo ? dbTreeInfo.isProcedure() : false;
  549.     
  550.   _MinusBtn.setDisabled(!param || isProcedure);
  551.  
  552.   if (databaseType && !isProcedure)
  553.   {
  554.     _PlusBtn.enable();
  555.     
  556.     if (param)
  557.     {
  558.       _ParamEditBtn.removeAttribute("disabled");
  559.     }
  560.   }
  561.   else
  562.   {
  563.     _PlusBtn.disable();
  564.     _ParamEditBtn.setAttribute("disabled", "disabled");
  565.   }
  566. }
  567.