Browse Source

AMBARI-416. Fix Inconsistent Validation Error Messages (Contributed by Varun)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/ambari-186@1347220 13f79535-47bb-0310-9956-ffa450edef68
Vikram Dixit K 13 years ago
parent
commit
dd1ceae7c5
4 changed files with 17 additions and 50 deletions
  1. 2 0
      CHANGES.txt
  2. 2 0
      hmc/js/addNodes.js
  3. 12 49
      hmc/js/createCluster.js
  4. 1 1
      hmc/js/utils.js

+ 2 - 0
CHANGES.txt

@@ -6,6 +6,8 @@ characters wide.
 
 Release 0.1.x - unreleased
 
+  AMBARI-416. Fix Inconsistent Validation Error Messages (Varun via Vikram)
+
   AMBARI-417. Typo fix in uninstall path. (Vikram)
 
   AMBARI-415. Reset service back to original state after reconfiguration (Hitesh via Vikram)

+ 2 - 0
hmc/js/addNodes.js

@@ -24,6 +24,8 @@ InstallationWizard.AddNodes = {
         globalYui.one("#hmcArtifactsDownloadUrlId").set('value', addNodesRenderData.yumRepo.hdpArtifactsDownloadUrl);
         globalYui.one("#hmcGplArtifactsDownloadUrlId").set('value', addNodesRenderData.yumRepo.gplArtifactsDownloadUrl);
       }
+
+      hideLoadingImg();
     }
 };
 

+ 12 - 49
hmc/js/createCluster.js

@@ -1,3 +1,10 @@
+function handleCreateClusterError (errorResponse) {
+
+  globalYui.one("#clusterNameId").addClass('formInputError');
+  setFormStatus(errorResponse.error, true);
+  globalYui.one("#clusterNameId").focus();
+}
+
 globalYui.one('#createClusterSubmitButtonId').on('click',function (e) {
 
       var createClusterData = {
@@ -6,58 +13,14 @@ globalYui.one('#createClusterSubmitButtonId').on('click',function (e) {
 
       globalYui.log("Cluster Name: "+globalYui.Lang.dump(createClusterData));
 
-      if (createClusterData.clusterName == '') {
-        globalYui.one("#clusterNameId").addClass('formInputError');
-        setFormStatus("Cluster name cannot be empty", true);
-        globalYui.one("#clusterNameId").focus();
-        return;
-      }
-
+      /* Always clear the slate with each submit. */
       clearFormStatus();
       globalYui.one("#clusterNameId").removeClass('formInputError');
-      globalYui.io("../php/frontend/createCluster.php", {
-
-          method: 'POST',
-          data: globalYui.JSON.stringify(createClusterData),
-          timeout : 10000,
-          on: {
-
-            start: function (x,o) {
-              showLoadingImg();
-            },
-            success: function (x,o) {
-              hideLoadingImg();
-              globalYui.log("RAW JSON DATA: " + o.responseText);
-
-              // Process the JSON data returned from the server
-              try {
-                createClusterResponseJson = globalYui.JSON.parse(o.responseText);
-              }
-              catch (e) {
-                alert("JSON Parse failed!");
-                return;
-              }
-
-              globalYui.log("PARSED DATA: " + globalYui.Lang.dump(createClusterResponseJson));
-
-              if (createClusterResponseJson.result != 0) {
-                // Error!
-                alert("Got error!" + createClusterResponseJson.error); 
-                return;
-              }
-
-              createClusterResponseJson = createClusterResponseJson.response;
 
-              /* Done with this stage, transition to the next. */
-              transitionToNextStage( "#createClusterCoreDivId", createClusterData, 
-                  "#addNodesCoreDivId", createClusterResponseJson, InstallationWizard.AddNodes.render );
-            },
-            failure: function (x,o) {
-              hideLoadingImg();
-              alert("Async call failed!");
-            }
-          }
-      });
+      submitDataAndProgressToNextScreen(
+        '../php/frontend/createCluster.php', createClusterData, e.target, 
+        '#createClusterCoreDivId', '#addNodesCoreDivId', InstallationWizard.AddNodes.render,
+        handleCreateClusterError );
 });
 
 /* Signify that the containing application is ready for business. */

+ 1 - 1
hmc/js/utils.js

@@ -309,7 +309,6 @@ function submitDataAndProgressToNextScreen(url, requestData, submitButton, thisS
 
           if (responseJson.result != 0) {
              submitButton.set('disabled', false);
-             hideLoadingImg();
              // Error!
              globalYui.log("Got error during submit data!" + responseJson.error);
              if ( errorHandlerFunction ) {
@@ -318,6 +317,7 @@ function submitDataAndProgressToNextScreen(url, requestData, submitButton, thisS
              } else {
                alert("Got error during submit data!" + responseJson.error);
              }
+             hideLoadingImg();
              return;
            }
           responseJson = responseJson.response;