setup.js 4.6 KB

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