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 / SelectDatabase.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  6.8 KB  |  282 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. // *************** GLOBALS VARS *****************
  4.  
  5. var HELP_DOC = MM.HELP_cmdSelectPHPDSNList;
  6.  
  7. var DB_NAME_OBJ;
  8. var HOST_NAME_OBJ;
  9. var USERNAME_OBJ;
  10. var PASSWORD_OBJ;
  11.  
  12. var DB_TYPE = "";
  13.  
  14.  
  15. //*************************API**************************
  16.  
  17. //--------------------------------------------------------------------
  18. // FUNCTION:
  19. //   commandButtons
  20. //
  21. // DESCRIPTION:
  22. //   Returns the array of buttons that should be displayed on the
  23. //   right hand side of the dialog.  The array is comprised
  24. //   of name, handler function name pairs.
  25. //
  26. // ARGUMENTS:
  27. //   none
  28. //
  29. // RETURNS:
  30. //   array of strings - name, handler function name pairs
  31. //--------------------------------------------------------------------
  32.  
  33. function commandButtons()
  34. {
  35.   return new Array(MM.BTN_OK,      "okClicked()", 
  36.                    MM.BTN_Cancel,  "cancelClicked()", 
  37.                    // MM.BTN_Refresh, "refreshClicked()", 
  38.                    MM.BTN_Help,    "displayHelp()" );
  39. }
  40.  
  41.  
  42. //--------------------------------------------------------------------
  43. // FUNCTION:
  44. //   okClicked
  45. //
  46. // DESCRIPTION:
  47. //   This function is called when the OK button is clicked.
  48. //   It sets the command return value.
  49. //
  50. // ARGUMENTS:
  51. //   none
  52. //
  53. // RETURNS:
  54. //   nothing
  55. //--------------------------------------------------------------------
  56.  
  57. function okClicked()
  58. {
  59.   var retVal = new Array();
  60.   
  61.   retVal.push(DB_NAME_OBJ.get());
  62.   retVal.push(dwscripts.trim(HOST_NAME_OBJ.value));
  63.   retVal.push(dwscripts.trim(USERNAME_OBJ.value));
  64.   retVal.push(PASSWORD_OBJ.value);
  65.   
  66.   dwscripts.setCommandReturnValue(retVal);
  67.   
  68.   // reset the options list
  69.   DB_NAME_OBJ.setAll(new Array(MM.LABEL_Loading));
  70.   
  71.   window.close();
  72. }
  73.  
  74.  
  75. //--------------------------------------------------------------------
  76. // FUNCTION:
  77. //   cancelClicked
  78. //
  79. // DESCRIPTION:
  80. //   This function is called when the cancel button is pressed.
  81. //   Set the command return value to blank.
  82. //
  83. // ARGUMENTS:
  84. //   none
  85. //
  86. // RETURNS:
  87. //   nothing
  88. //--------------------------------------------------------------------
  89.  
  90. function cancelClicked()
  91. {
  92.   dwscripts.setCommandReturnValue("");
  93.   
  94.   // reset the options list
  95.   DB_NAME_OBJ.setAll(new Array(MM.LABEL_Loading));
  96.   
  97.   window.close();
  98. }
  99.  
  100.  
  101. //--------------------------------------------------------------------
  102. // FUNCTION:
  103. //   refreshClicked
  104. //
  105. // DESCRIPTION:
  106. //   This function is called when the refesh button is clicked.
  107. //
  108. // ARGUMENTS:
  109. //   none
  110. //
  111. // RETURNS:
  112. //   nothing
  113. //--------------------------------------------------------------------
  114.  
  115. // no longer needed since the username and password have been removed
  116. // from the SelectDB dialog.
  117. // function refreshClicked()
  118. // {
  119. //  refreshList(DB_NAME_OBJ.get());
  120. // }
  121.  
  122.  
  123. //--------------------------------------------------------------------
  124. // FUNCTION:
  125. //   displayHelp
  126. //
  127. // DESCRIPTION:
  128. //   Displays the built-in Dreamweaver help.
  129. //
  130. // ARGUMENTS:
  131. //   none
  132. //
  133. // RETURNS:
  134. //   nothing
  135. //--------------------------------------------------------------------
  136.  
  137. function displayHelp()
  138. {
  139.   // Replace the following call if you are modifying this file for your own use.
  140.   dwscripts.displayDWHelp(HELP_DOC);
  141. }
  142.  
  143.  
  144. //*******************LOCAL FUNCTIONS*********************
  145.  
  146. //--------------------------------------------------------------------
  147. // FUNCTION:
  148. //   initializeUI
  149. //
  150. // DESCRIPTION:
  151. //   Get the DOM objects for the various UI controls
  152. //
  153. // ARGUMENTS:
  154. //   none
  155. //
  156. // RETURNS:
  157. //   nothing
  158. //--------------------------------------------------------------------
  159.  
  160. function initializeUI()
  161. {
  162.   DB_NAME_OBJ = new ListControl("Database");
  163.   HOST_NAME_OBJ = dwscripts.findDOMObject("HostName");
  164.   USERNAME_OBJ = dwscripts.findDOMObject("UserName");
  165.   PASSWORD_OBJ = dwscripts.findDOMObject("Password");
  166.  
  167.   // get arguments: dbName, dbType, host name, username, password
  168.   var args = dwscripts.getCommandArguments();
  169.   
  170.   DB_TYPE = args[1];
  171.   HOST_NAME_OBJ.value = args[2];
  172.   USERNAME_OBJ.value = args[3];
  173.   PASSWORD_OBJ.value = args[4];
  174.  
  175.   // Validate connection
  176.   if (!testConnection(false))
  177.   {
  178.     // Show specific error message
  179.     testConnection(true);
  180.  
  181.     // Close dialog
  182.     cancelClicked();
  183.   }
  184.  
  185.   refreshList(args[0]);
  186. }
  187.  
  188.  
  189. //--------------------------------------------------------------------
  190. // FUNCTION:
  191. //   refreshList
  192. //
  193. // DESCRIPTION:
  194. //   Updates the list of remote DSN's, and selects the entry
  195. //   matching the given name.
  196. //
  197. // ARGUMENTS:
  198. //   selectedDB - string - the db name to select
  199. //
  200. // RETURNS:
  201. //   nothing
  202. //--------------------------------------------------------------------
  203.  
  204. function refreshList(selectedDB)
  205. {
  206.   // Build URL Parameters string. The HTTP Connectivity Scripts expect
  207.   // all parameters (except Type) to be in ADO Connection String format
  208.   // and passed as the "ConnectionString" URL Parameter
  209.   
  210.   var urlParams = "Type=" + DB_TYPE + "&ConnectionString=";
  211.  
  212.   var host = dwscripts.trim(HOST_NAME_OBJ.value);
  213.   if (host != "")
  214.   {
  215.     urlParams += "host=" + host + ";";
  216.   }
  217.  
  218.   var uid = dwscripts.trim(USERNAME_OBJ.value);
  219.   if (uid != "")
  220.   {
  221.     urlParams += "uid=" + uid + ";";
  222.   }
  223.  
  224.   var pwd = dwscripts.trim(PASSWORD_OBJ.value);
  225.   if (pwd != "")
  226.   {
  227.     urlParams += "pwd=" + pwd + ";";
  228.   }
  229.  
  230.   if (urlParams != "")
  231.   {
  232.     urlParams += "&Host=" + host + "&";
  233.     urlParams += "&Database=" + "&";
  234.     urlParams += "UserName=" + uid + "&";
  235.     urlParams += "Password=" + pwd + "&";
  236.     urlParams += "Timeout=30";
  237.   }
  238.  
  239.   var remoteDBs = MMDB.getRemoteDsnList(urlParams);
  240.   DB_NAME_OBJ.setAll(remoteDBs, remoteDBs);
  241.  
  242.   if (!DB_NAME_OBJ.pickValue(selectedDB))
  243.   {
  244.     DB_NAME_OBJ.setIndex(0);
  245.   }
  246. }
  247.  
  248.  
  249. //--------------------------------------------------------------------
  250. // FUNCTION:
  251. //   testConnection
  252. //
  253. // DESCRIPTION:
  254. //   Validates the current connection and displays a success or failure
  255. //   message if specified.
  256. //
  257. //   This function was copied from Connection_php_mysql.js
  258. //
  259. // ARGUMENTS:
  260. //   showMessage  true/false to display messages from MMDB.testConnection
  261. //
  262. // RETURNS:
  263. //   true/false
  264. //--------------------------------------------------------------------
  265.  
  266. function testConnection(showMessage)
  267. {
  268.     // build tokens array
  269.     var tokens = new Object();
  270.  
  271.     tokens.hostname = dwscripts.trim(HOST_NAME_OBJ.value);
  272.     tokens.username = dwscripts.trim(USERNAME_OBJ.value);
  273.     tokens.password = PASSWORD_OBJ.value;
  274.     tokens.databasename = "";
  275.     tokens.http = "true";
  276.     tokens.type = "MYSQL";
  277.     tokens.string = "type=MYSQL;host=" + tokens.hostname + ";db="  + tokens.databasename + ";uid=" + tokens.username + ";pwd=" + tokens.password + ";";
  278.     tokens.customURLParams = "Host=" + tokens.hostname + "&Database=" + tokens.databasename;
  279.  
  280.     return MMDB.testConnection(tokens, showMessage);
  281. }  
  282.