setup.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. function NameIsValid(name)
  2. {
  3. sName = new String(name);
  4. if (sName.match(/^[A-Za-z][A-Za-z0-9_]*$/)) return true;
  5. return false;
  6. }
  7. function DoGoBack(iStep)
  8. {
  9. $('input[name=operation]').val('step'+(iStep-1));
  10. $('#theForm').submit(); // Submit the form
  11. return true;
  12. }
  13. function DoSubmit(sMsg, iStep)
  14. {
  15. var bResult = true;
  16. switch(iStep)
  17. {
  18. case 1: // Licence agreement
  19. if ($('#licence_ok:checked').length < 1)
  20. {
  21. alert('Please accept the licence agreement before continuing.');
  22. bResult = false;
  23. }
  24. break;
  25. case 2: // Database server selection
  26. if ($('#db_server').val() == '')
  27. {
  28. alert('Please specify a database server. Use "localhost" for a local DB server.');
  29. bResult = false;
  30. }
  31. else if ($('#db_user').val() == '')
  32. {
  33. alert('Please specify a user name to connect to the database.');
  34. bResult = false;
  35. }
  36. break;
  37. case 3: // Database instance selection
  38. if ($("input[@type=radio]:checked").length < 1)
  39. {
  40. alert('Please specify a database name');
  41. bResult = false;
  42. }
  43. else if( ($("#new_db:checked").length == 1))
  44. {
  45. if ($('#new_db_name').val() == '')
  46. {
  47. alert('Please specify the name of the database to create');
  48. bResult = false;
  49. }
  50. else if (!NameIsValid($('#new_db_name').val()))
  51. {
  52. alert($('#new_db_name').val()+' is not a valid database name. Please limit yourself to letters, numbers and the underscore character.');
  53. bResult = false;
  54. }
  55. }
  56. else if ($("#current_db:checked").length == 1)
  57. {
  58. // Special case (DB enumeration failed, user must enter DB name)
  59. if ($("#current_db_name").val() == '')
  60. {
  61. alert('Please specify the name of the database.');
  62. bResult = false;
  63. }
  64. else
  65. {
  66. // Copy the typed value as the value of the radio
  67. $("#current_db").val($("#current_db_name").val());
  68. }
  69. }
  70. if( ($('#db_prefix').val() != '') && (!NameIsValid($('#db_prefix').val())) )
  71. {
  72. alert($('#db_prefix').val()+' is not a valid table name. Please limit yourself to letters, numbers and the underscore character.');
  73. bResult = false;
  74. }
  75. break;
  76. case 4: // Choice of iTop modules
  77. break;
  78. case 5: // Administrator account
  79. if ($('#auth_user').val() == '')
  80. {
  81. alert('Please specify a login name for the administrator account');
  82. bResult = false;
  83. }
  84. else if ($('#auth_pwd').val() != $('#auth_pwd2').val())
  85. {
  86. alert('Retyped password does not match! Please verify the password.');
  87. bResult = false;
  88. }
  89. break;
  90. case 6: // Asynchronous load of data
  91. bResult = DoLoadDataAsynchronous();
  92. break;
  93. // Email test page
  94. case 10:
  95. if ($('#to').val() == '')
  96. {
  97. alert('Please specify a destination address');
  98. bResult = false;
  99. }
  100. }
  101. if (bResult && (sMsg != ''))
  102. {
  103. $('#setup').block({message: '<img src="../images/indicator.gif">&nbsp;'+sMsg});
  104. }
  105. return bResult;
  106. }
  107. var aFilesToLoad = new Array();
  108. var iCounter = 0;
  109. function DoLoadDataAsynchronous()
  110. {
  111. try
  112. {
  113. // The array aFilesToLoad is populated by this function dynamically written on the server
  114. PopulateDataFilesList();
  115. iCounter = 0;
  116. $('#log').html('');
  117. $('#setup').block({message: '<p>Loading data...<br/><div id=\"progress\">0%</div></p>'});
  118. $('#progress').progression( {Current:0, Maximum: 100, aBackgroundImg: 'orange-progress.gif', aTextColor: '#000000'} );
  119. $('#log').ajaxError(
  120. function(e, xhr, settings, exception)
  121. {
  122. alert('Fatal error detected: '+ xhr.responseText);
  123. $('#log').append(xhr.responseText);
  124. $('#setup').unblock();
  125. } );
  126. LoadNextDataFile('', '', '');
  127. }
  128. catch(err)
  129. {
  130. alert('An exception occured: '+err);
  131. }
  132. return false; // Stop here for now
  133. }
  134. function LoadNextDataFile(response, status, xhr)
  135. {
  136. if (status == 'error')
  137. {
  138. $('#setup').unblock();
  139. return; // Stop here
  140. }
  141. try
  142. {
  143. if (iCounter < aFilesToLoad.length)
  144. {
  145. if (iCounter == (aFilesToLoad.length - 1))
  146. {
  147. // Last file in the list (or only 1 file), this completes the session
  148. sSessionStatus = 'end';
  149. }
  150. else if (iCounter == 0)
  151. {
  152. // First file in the list, start the session
  153. sSessionStatus = 'start';
  154. }
  155. else
  156. {
  157. sSessionStatus = 'continue';
  158. }
  159. iPercent = Math.round((100.0 * (1+iCounter)) / aFilesToLoad.length);
  160. sFileName = aFilesToLoad[iCounter];
  161. //alert('Loading file '+sFileName+' ('+iPercent+' %) - '+sSessionStatus);
  162. $("#progress").progression({ Current: iPercent });
  163. iCounter++;
  164. $('#log').load( 'ajax.dataloader.php', { 'file': sFileName, 'percent': iPercent, 'session_status': sSessionStatus }, LoadNextDataFile, 'html');
  165. }
  166. else
  167. {
  168. // We're done
  169. $('#setup').unblock();
  170. $('#GoToNextStep').submit(); // Use the hidden form to navigate to the next step
  171. }
  172. }
  173. catch(err)
  174. {
  175. alert('An exception occurred: '+err);
  176. }
  177. }