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-ASPNET-AdvRS.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  14.5 KB  |  568 lines

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