ws_roxieconfig_left.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. //Here's the code that will set up our Left Nav instance.
  18. var tree, currentIconMode;
  19. (function(){
  20. function changeIconMode() {
  21. var newVal = parseInt(this.value);
  22. if (newVal != currentIconMode) {
  23. currentIconMode = newVal;
  24. }
  25. buildTree();
  26. }
  27. tree = new YAHOO.widget.TreeView("espNavTree");
  28. tree.setDynamicLoad(loadNodeData, currentIconMode);
  29. var root = tree.getRoot();
  30. var attributeServersNode = new YAHOO.widget.TextNode({label: "Attribute Servers", expanded:true, dynamicLoadComplete:true}, root);
  31. var tmpNode2 = new YAHOO.widget.TextNode({label: "dataland"}, attributeServersNode);
  32. tmpNode2.labelStyle = "icon-doc";
  33. var tmpNode3 = new YAHOO.widget.TextNode({label: "prod"}, attributeServersNode);
  34. tmpNode3.labelStyle = "icon-doc";
  35. var tmpNode4 = new YAHOO.widget.TextNode({label: "qa", expanded: false}, attributeServersNode);
  36. tmpNode4.labelStyle = "icon-doc";
  37. var roxieClustersNode = new YAHOO.widget.TextNode({label: "Roxie Clusters", expanded:true, dynamicLoadComplete:true}, root);
  38. var tmpNode5 = new YAHOO.widget.TextNode({label: "QA-Roxie"}, roxieClustersNode);
  39. tmpNode5.labelStyle = "icon-doc";
  40. var tmpNode6 = new YAHOO.widget.TextNode({label: "Staging", expanded: false}, roxieClustersNode);
  41. tmpNode6.labelStyle = "icon-doc";
  42. var tmpNode7 = new YAHOO.widget.TextNode({label: "40-Way"}, roxieClustersNode);
  43. tmpNode7.labelStyle = "icon-doc";
  44. tree.render();
  45. })();
  46. function loadNodeData(node, fnLoadComplete) {
  47. //We'll load node data based on what we get back when we
  48. //use Connection Manager topass the text label of the
  49. //expanding node to the Yahoo!
  50. //Search "related suggestions" API. Here, we're at the
  51. //first part of the request -- we'll make the request to the
  52. //server. In our success handler, we'll build our new children
  53. //and then return fnLoadComplete back to the tree.
  54. //Get the node's label and urlencode it; this is the word/s
  55. //on which we'll search for related words:
  56. var nodeLabel = encodeURI(node.label);
  57. //prepare URL for XHR request:
  58. var sUrl = "assets/ysuggest_proxy.php?query=" + nodeLabel;
  59. //prepare our callback object
  60. var callback = {
  61. //if our XHR call is successful, we want to make use
  62. //of the returned data and create child nodes.
  63. success: function(oResponse) {
  64. YAHOO.log("XHR transaction was successful.", "info", "example");
  65. //YAHOO.log(oResponse.responseText);
  66. var oResults = eval("(" + oResponse.responseText + ")");
  67. if((oResults.ResultSet.Result) && (oResults.ResultSet.Result.length)) {
  68. //Result is an array if more than one result, string otherwise
  69. if(YAHOO.lang.isArray(oResults.ResultSet.Result)) {
  70. for (var i=0, j=oResults.ResultSet.Result.length; i<j; i++) {
  71. var tempNode = new YAHOO.widget.TextNode(oResults.ResultSet.Result[i], node, false);
  72. }
  73. } else {
  74. //there is only one result; comes as string:
  75. var tempNode = new YAHOO.widget.TextNode(oResults.ResultSet.Result, node, false)
  76. }
  77. }
  78. //When we're done creating child nodes, we execute the node's
  79. //loadComplete callback method which comes in via the argument
  80. //in the response object (we could also access it at node.loadComplete,
  81. //if necessary):
  82. oResponse.argument.fnLoadComplete();
  83. },
  84. //if our XHR call is not successful, we want to
  85. //fire the TreeView callback and let the Tree
  86. //proceed with its business.
  87. failure: function(oResponse) {
  88. YAHOO.log("Failed to process XHR transaction.", "info", "example");
  89. oResponse.argument.fnLoadComplete();
  90. },
  91. //our handlers for the XHR response will need the same
  92. //argument information we got to loadNodeData, so
  93. //we'll pass those along:
  94. argument: {
  95. "node": node,
  96. "fnLoadComplete": fnLoadComplete
  97. },
  98. //timeout -- if more than 7 seconds go by, we'll abort
  99. //the transaction and assume there are no children:
  100. timeout: 7000
  101. };
  102. //With our callback object ready, it's now time to
  103. //make our XHR call using Connection Manager's
  104. //asyncRequest method:
  105. YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
  106. }