clustersList.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. function renderClusterList(Y) {
  2. Y.io("../php/frontend/listClusters.php", {
  3. method: 'GET',
  4. timeout : 10000,
  5. on: {
  6. success: function (x,o) {
  7. Y.log("RAW JSON DATA: " + o.responseText);
  8. // Process the JSON data returned from the server
  9. try {
  10. clusterListInfoJson = Y.JSON.parse(o.responseText);
  11. }
  12. catch (e) {
  13. alert("JSON Parse failed!");
  14. return;
  15. }
  16. Y.log("PARSED DATA: " + Y.Lang.dump(clusterListInfoJson));
  17. if (clusterListInfoJson.result != 0) {
  18. // Error!
  19. alert("Got error!" + clusterListInfoJson.error);
  20. return;
  21. }
  22. clusterListInfoJson = clusterListInfoJson.response;
  23. var numClusters = clusterListInfoJson.length;
  24. var clustersListMarkup;
  25. var clusterId;
  26. var multipleClustersSupported = false;
  27. if (numClusters == 0) {
  28. clustersListMarkup = "You don't have any installed cluster.";
  29. } else {
  30. if (multipleClustersSupported) {
  31. clustersListMarkup = "<table>" +
  32. "<caption>List of clusters</caption>" +
  33. "<thead><tr><th>Name of the cluster</th><th>Cluster status</th><th>Actions</th></tr></thead>";
  34. var i = 0;
  35. for (clusterId in clusterListInfoJson) {
  36. clustersListMarkup += "<tr><td><a href='manageServices.php?clusterId=" + clusterId + "' id='existingClusterLinkDivId'>" + clusterId + "</a></td><td>" + clusterListInfoJson[clusterId] + "</td><td>Uninstall</td></tr>" ;
  37. }
  38. clustersListMarkup += "</table>";
  39. } else {
  40. var clusterName; var clusterInfo;
  41. for (clusterId in clusterListInfoJson) {
  42. clusterName = clusterId;
  43. clusterInfo = clusterListInfoJson[clusterName];
  44. }
  45. clustersListMarkup = '<h3>Cluster information</h3>';
  46. clustersListMarkup += '<div class="clusterDiv">' +
  47. '<div class="formElement">' +
  48. '<label>ClusterName</label>' +
  49. '<input type=text readonly=readonly value=' + clusterName + '>' +
  50. '</div>' +
  51. '<div class="formElement">' +
  52. '<label>State</label>' +
  53. '<input type=text readonly=readonly value=' + clusterInfo + '>' +
  54. '</div>' +
  55. '<div class="formElement">' +
  56. '<label>Monitoring dashboard</label>' +
  57. '<a href="#">monitoringDashboard.com:4060</a>' +
  58. '</div>' +
  59. '<div class="formElement">' +
  60. '<label>Actions</label>' +
  61. '<a href="manageServices.php?clusterName=' + clusterName + '" id="existingClusterLinkDivId">[ Manage services ]</a>' +
  62. '<a href="addNodesWizard.php?clusterName=' + clusterName + '">[ Add slave nodes to cluster ]</a>' +
  63. '</div>' +
  64. '</div>';
  65. }
  66. }
  67. var newClusterLinkHTML = "<br/>Want to create a new cluster? Click <a href='initializeCluster.php' id='newClusterLinkDivId'>here</a> ";
  68. if (multipleClustersSupported || numClusters == 0) {
  69. clustersListMarkup += newClusterLinkHTML;
  70. }
  71. Y.one("#clustersListDivId").setContent( clustersListMarkup );
  72. if (Y.one('#newClusterLinkDivId') != null) {
  73. Y.one('#newClusterLinkDivId').on('click',function (e) {
  74. /* Done with this stage, hide it. */
  75. Y.one("#clustersListDivId").setStyle('display','none');
  76. // Y.one("#installationWizardDivId").setStyle('display','block');
  77. });
  78. }
  79. if(numClusters !=0) {
  80. Y.one('#existingClusterLinkDivId').on('click',function (e) {
  81. e.target.set('disabled', true);
  82. /* Done with this stage, hide it. */
  83. Y.one("#clustersListDivId").setStyle('display','none');
  84. /* Render the next stage. */
  85. getServicesStatus(Y, clusterId);
  86. /* Show off our rendering. */
  87. Y.one("#displayServiceStatusCoreDivId").setStyle('display','block');
  88. });
  89. }
  90. },
  91. failure: function (x,o) {
  92. // e.target.set('disabled', false);
  93. alert("Async call failed!");
  94. }
  95. }
  96. });
  97. }
  98. // Create business logic in a YUI sandbox using the 'io' and 'json' modules
  99. YUI().use("node", "io", "dump", "json", "arraysort", "panel", function (Y) {
  100. Y.log( Y.one("#pageTitleId").get('innerHTML') );
  101. // Y.one('#createClusterSubmitButtonId').on('click',function (e) {
  102. renderClusterList(Y);
  103. });