configureCluster.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. function generateEligibleMountPoints () {
  2. /* The list we're about to build up. */
  3. var desiredMountPoints = [];
  4. var selections = globalYui.all("#configureClusterMountPointsDynamicRenderDivId input[type=checkbox]");
  5. selections.each( function(selection) {
  6. if( selection.get('checked') == true ) {
  7. desiredMountPoints.push( selection.get('value') );
  8. }
  9. });
  10. globalYui.log("desired mount points: "+globalYui.Lang.dump(desiredMountPoints));
  11. var customMountPointsString = globalYui.Lang.trim( globalYui.one("#customMountPointsId").get('value') );
  12. if( customMountPointsString.length != 0 ) {
  13. globalYui.log("custom string = " + customMountPointsString);
  14. /* Merge the split version of customMountPointsString into our final list
  15. * of mount points to send back to the server for committing...
  16. */
  17. desiredMountPoints.push.apply( desiredMountPoints, globalYui.Array.filter(customMountPointsString.split(','), function (elem) {
  18. if (globalYui.Lang.trim(elem).length > 0) {
  19. return true;
  20. } else {
  21. return false;
  22. }
  23. } ));
  24. globalYui.log(desiredMountPoints.join(','));
  25. }
  26. /* ...But not before performing a de-dupe, just to be safe. */
  27. return globalYui.Array.dedupe( desiredMountPoints );
  28. }
  29. function generateServiceDirs (servicesInfo) {
  30. var generatedServiceDirs = {};
  31. var eligibleMountPoints = generateEligibleMountPoints();
  32. for (items in servicesInfo) {
  33. for (serviceName in servicesInfo[items]) {
  34. for (component in servicesInfo[items][serviceName]) {
  35. var serviceInfo = servicesInfo[items][serviceName][component];
  36. var serviceDirs = [];
  37. for( currentDirNum = 0; currentDirNum < eligibleMountPoints.length; ++currentDirNum ) {
  38. /* serviceInfo.maxDirectoriesNeeded that we get from the server is a cap
  39. * on how many directories need to be generated for that service - the
  40. * user can always pick fewer than that, so guard against going out of
  41. * bounds.
  42. */
  43. if ((serviceInfo.maxDirectoriesNeeded != -1) &&
  44. (currentDirNum >= serviceInfo.maxDirectoriesNeeded)) {
  45. break;
  46. }
  47. var currentDirName = eligibleMountPoints[currentDirNum];
  48. /* Add a trailing slash if it doesn't exist already. */
  49. if( currentDirName.substr(-1) != '/' ) {
  50. currentDirName += '/';
  51. }
  52. serviceDirs.push( currentDirName + serviceInfo.suffix );
  53. }
  54. var serviceDirValue = serviceDirs.join(',');
  55. generatedServiceDirs[component] = {
  56. "serviceName" : serviceName,
  57. 'value' : serviceDirValue,
  58. 'displayName' : serviceInfo.displayName
  59. };
  60. }
  61. }
  62. }
  63. globalYui.log("Generated Service Dirs: "+globalYui.Lang.dump(generatedServiceDirs));
  64. return generatedServiceDirs;
  65. }
  66. function renderEffectiveClusterConfig (generatedClusterConfig) {
  67. var clusterConfigDisplayMarkup = "";
  68. for (var configKey in generatedClusterConfig) {
  69. if (generatedClusterConfig.hasOwnProperty( configKey )) {
  70. var configElement = generatedClusterConfig[configKey];
  71. var configElementName = configKey;
  72. var configElementIdName = configElementName + 'Id';
  73. var dirsArray = configElement.value.split(',');
  74. /* Inefficient, with all the string concatenations, but clear to read. */
  75. clusterConfigDisplayMarkup +=
  76. '<div class="formElement">' +
  77. '<label for=' + configElementIdName + '>' + configElement.displayName + '</label>' +
  78. '<ul style="list-style-type: none;float:left;" id=' + configElementIdName + '>';
  79. for (var dirs in dirsArray) {
  80. clusterConfigDisplayMarkup +=
  81. '<li>' + dirsArray[dirs] + '</li>';
  82. }
  83. clusterConfigDisplayMarkup += '</ul>' + '</div><br/>';
  84. globalYui.log("HTML GENERATED: " + clusterConfigDisplayMarkup);
  85. }
  86. }
  87. /* Link the newly-generated clusterConfigInputMarkup into the DOM (making
  88. * sure it comes before the existing #configureClusterSubmitButtonId), thus
  89. * rendering it.
  90. */
  91. globalYui.one("#configureClusterMountPointsDisplayDivId").setContent( clusterConfigDisplayMarkup );
  92. }
  93. /* Modify the working version of generatedClusterConfig to make it fit for
  94. * sending to our backend.
  95. */
  96. function polishClusterConfig (generatedClusterConfig) {
  97. var polishedClusterConfig = {};
  98. for (var configKey in generatedClusterConfig) {
  99. if (generatedClusterConfig.hasOwnProperty( configKey )) {
  100. serviceName = generatedClusterConfig[configKey]["serviceName"];
  101. if (!polishedClusterConfig.hasOwnProperty(serviceName)) {
  102. polishedClusterConfig[serviceName] = {};
  103. }
  104. polishedClusterConfig[serviceName][configKey] = generatedClusterConfig[configKey].value;
  105. }
  106. }
  107. return polishedClusterConfig;
  108. }
  109. var globalServicesInfo = null;
  110. function eventHandlerFunc (e)
  111. {
  112. renderEffectiveClusterConfig(generateServiceDirs(globalServicesInfo));
  113. }
  114. var registeredConfigureClusterEventHandlers = false;
  115. function renderConfigureCluster (clusterConfig) {
  116. globalServicesInfo = globalYui.Array( clusterConfig.servicesInfo );
  117. /* Clear out the contents of #customMountPointsId each time we render this
  118. * screen, to maintain our guarantee of invalidating all forward pages once
  119. * the user moves back.
  120. */
  121. globalYui.one("#customMountPointsId").set('value', '');
  122. if( !registeredConfigureClusterEventHandlers ) {
  123. globalYui.one('#configureClusterSubmitButtonId').on('click',function (e) {
  124. e.target.set('disabled', true);
  125. var itemsExist = false;
  126. var selections = globalYui.all("#configureClusterMountPointsDynamicRenderDivId input[type=checkbox]");
  127. selections.each( function(selection) {
  128. if( selection.get('checked') == true ) {
  129. itemsExist = true;
  130. }
  131. });
  132. if (globalYui.Lang.trim( globalYui.one("#customMountPointsId").get('value') ) != '') {
  133. itemsExist = true;
  134. }
  135. if (!itemsExist) {
  136. alert("Please select one mount point at the least");
  137. e.target.set('disabled', false);
  138. return;
  139. }
  140. /* For now, our cluster config consists solely of the generated service directories. */
  141. var generatedClusterConfig = generateServiceDirs(globalServicesInfo);
  142. var configureClusterRequestData = {
  143. mountPoints : generateEligibleMountPoints(),
  144. clusterConfig : polishClusterConfig(generatedClusterConfig)
  145. };
  146. globalYui.log(globalYui.Lang.dump(configureClusterRequestData.clusterConfig));
  147. var url = "../php/frontend/configureCluster.php?clusterName="+clusterConfig.clusterName;
  148. var requestData = configureClusterRequestData;
  149. var submitButton = e.target;
  150. var thisScreenId = "#configureClusterCoreDivId";
  151. var nextScreenId = "#configureClusterAdvancedCoreDivId";
  152. var nextScreenRenderFunction = renderOptionsPage;
  153. submitDataAndProgressToNextScreen(url, requestData, submitButton, thisScreenId, nextScreenId, nextScreenRenderFunction);
  154. });
  155. /* event on mountPoints to be checked. */
  156. globalYui.one('#configureClusterMountPointsInputDivId').delegate(
  157. {
  158. 'click': eventHandlerFunc,
  159. 'keyup' : eventHandlerFunc
  160. },
  161. "input[type=checkbox],input[type=text]");
  162. registeredConfigureClusterEventHandlers = true;
  163. }
  164. /* Generate the key form elements into clusterConfigInputMarkup. */
  165. var mountPoints = globalYui.Array( clusterConfig.mountPoints.sort(globalYui.ArraySort.compare) );
  166. var clusterConfigInputMarkup = "";
  167. globalYui.Array.each(mountPoints, function(mountPoint) {
  168. /* Inefficient, with all the string concatenations, but clear to read. */
  169. clusterConfigInputMarkup +=
  170. '<label class="checkbox" for="">' + mountPoint +
  171. '<input type=checkbox name=mountPoints id=mountPointsId checked=true value=' + mountPoint + '>' +
  172. '</label><br/>';
  173. });
  174. /* Link the newly-generated clusterConfigInputMarkup into the DOM. */
  175. globalYui.one("#configureClusterMountPointsDynamicRenderDivId").setContent( clusterConfigInputMarkup );
  176. hideLoadingImg();
  177. globalYui.one('#configureClusterCoreDivId').setStyle("display", "block");
  178. renderEffectiveClusterConfig(generateServiceDirs(globalServicesInfo));
  179. }