ws_roxieconfig_left.js 5.3 KB

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