installationWizard.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. var InstallationWizardStages = {
  22. /* The keys in 'stages' need to be kept in-sync with the <li> elements in
  23. * the markup.
  24. */
  25. stages : {
  26. 'createClusterStageId' : {
  27. divSelector : '#createClusterCoreDivId'
  28. },
  29. 'addNodesStageId' : {
  30. divSelector : '#addNodesCoreDivId'
  31. },
  32. 'selectServicesStageId' : {
  33. divSelector : '#selectServicesCoreDivId'
  34. },
  35. 'assignHostsStageId' : {
  36. divSelector : '#assignHostsCoreDivId'
  37. },
  38. 'configureClusterStageId' : {
  39. divSelector : '#configureClusterCoreDivId'
  40. },
  41. 'configureClusterAdvancedStageId' : {
  42. divSelector : '#configureClusterAdvancedCoreDivId'
  43. },
  44. 'deployClusterStageId' : {
  45. divSelector : '#deployCoreDivId'
  46. }
  47. },
  48. transitionToCachedStage :
  49. function (currentStageId, cachedStageId) {
  50. clearFormStatus();
  51. globalYui.log("In transitionToCachedStage: " + currentStageId + "->" + cachedStageId);
  52. swapStageVisibilities( this.stages[currentStageId].divSelector,
  53. this.stages[cachedStageId].divSelector );
  54. }
  55. };
  56. /* Setup the behavior for #installationWizardProgressBarListId */
  57. globalYui.one('#installationWizardProgressBarListId').delegate('click', function (e) {
  58. /* Important: When we specify CSS filters to delegate, we need to access
  59. * the filtered CSS element (which is what we really care to get at) via
  60. * 'this', not e.target.
  61. *
  62. * Only do anything with clicks on stages that have previously been visited.
  63. */
  64. if( this.hasClass('installationWizardVisitedStage') ) {
  65. var newCurrentStage = this;
  66. var nextStage = null;
  67. /* Mark the clicked-on stage as 'current'. */
  68. newCurrentStage.replaceClass( 'installationWizardVisitedStage', 'installationWizardCurrentStage' );
  69. globalYui.log("Marked " + newCurrentStage.get('id') + "from visited to current");
  70. var currentStage = newCurrentStage;
  71. while( nextStage = currentStage.next('.installationWizardVisitedStage') ) {
  72. /* Mark all the following 'visited' stages as 'unvisited'. */
  73. nextStage.replaceClass( 'installationWizardVisitedStage', 'installationWizardUnvisitedStage' );
  74. globalYui.log("Marked " + nextStage.get('id') + "from visited to unvisited");
  75. currentStage = nextStage;
  76. }
  77. var previouslyCurrentStage = currentStage.next();
  78. /* And finally, also mark the up-until-now 'current' stage as unvisited.
  79. * We know at this point that currentStage points to the last
  80. * previously-visited stage, and the last previously-visited stage is always
  81. * followed immediately by the up-until-now 'current' stage, so no fancier
  82. * checks are required - just depend on the invariants.
  83. */
  84. previouslyCurrentStage.replaceClass( 'installationWizardCurrentStage', 'installationWizardUnvisitedStage' );
  85. globalYui.log("Marked " + previouslyCurrentStage.get('id') + "from current to unvisited");
  86. /* Finally, flip to this newly 'current' stage, from the previously current one. */
  87. InstallationWizardStages.transitionToCachedStage( previouslyCurrentStage.get('id'), newCurrentStage.get('id') );
  88. }
  89. }, 'li' );
  90. globalYui.one('#installationMainFormsDivId').delegate('key', function (e) {
  91. /* Prevent the refresh of the page. */
  92. e.preventDefault();
  93. /* We don't have identically structured markup around all our
  94. * 'a.btn' elements, so we need this bubble-up search logic.
  95. */
  96. var currentButtonSibling = e.target.ancestor();
  97. while( !currentButtonSibling.next('a.btn') ) {
  98. currentButtonSibling = currentButtonSibling.ancestor();
  99. }
  100. /* Generate the click. */
  101. currentButtonSibling.next('a.btn').simulate('click');
  102. }, 'enter' );