/esp/xslt/yuitree.xsl

http://github.com/hpcc-systems/HPCC-Platform · Extensible Stylesheet Language Transformations · 502 lines · 418 code · 84 blank · 0 comment · 0 complexity · 09422c21a10d4a3c5a69d42945db3e1a MD5 · raw file

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. ##############################################################################
  4. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ##############################################################################
  18. -->
  19. <!DOCTYPE xsl:stylesheet [
  20. <!--define the HTML non-breaking space:-->
  21. <!ENTITY nbsp "<xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>">
  22. ]>
  23. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  24. <xsl:output method="html"/>
  25. <xsl:variable name="debug" select="0"/>
  26. <xsl:variable name="filePath">
  27. <xsl:choose>
  28. <xsl:when test="$debug">c:/development/bin/debug/files</xsl:when>
  29. <xsl:otherwise>files_</xsl:otherwise>
  30. </xsl:choose>
  31. </xsl:variable>
  32. <xsl:variable name="rootNode" select="/*[1]"/>
  33. <xsl:variable name="disableCache">
  34. <xsl:choose>
  35. <xsl:when test="$rootNode/@cache='false' or $rootNode/@cache='0'">1</xsl:when>
  36. <xsl:otherwise>0</xsl:otherwise>
  37. </xsl:choose>
  38. </xsl:variable>
  39. <xsl:template match="/*">
  40. <html>
  41. <head>
  42. <title>ESP Navigation Window</title>
  43. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/fonts/fonts-min.css" />
  44. <link rel="stylesheet" type="text/css" href="/esp/files/css/espdefault.css" />
  45. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/reset/reset.css" />
  46. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/fonts/fonts-min.css" />
  47. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/reset-fonts-grids/reset-fonts-grids.css" />
  48. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/resize/assets/skins/sam/resize.css" />
  49. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/layout/assets/skins/sam/layout.css" />
  50. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/button/assets/skins/sam/button.css" />
  51. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/menu/assets/skins/sam/menu.css" />
  52. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/tabview/assets/skins/sam/tabview.css" />
  53. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/treeview/assets/skins/sam/treeview.css" />
  54. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/paginator/assets/skins/sam/paginator.css" />
  55. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/datatable/assets/skins/sam/datatable.css" />
  56. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/container/assets/skins/sam/container.css" />
  57. <link rel="stylesheet" type="text/css" href="/esp/files/yui/build/autocomplete/assets/skins/sam/autocomplete.css" />
  58. <script type="text/javascript" src="/esp/files/scripts/espdefault.js">&#160;</script>
  59. <script type="text/javascript" src="/esp/files/yui/build/yahoo/yahoo-min.js"></script>
  60. <script type="text/javascript" src="/esp/files/yui/build/yuiloader/yuiloader-min.js"></script>
  61. <script type="text/javascript" src="/esp/files/yui/build/event/event-min.js"></script>
  62. <script type="text/javascript" src="/esp/files/yui/build/dom/dom-min.js"></script>
  63. <script type="text/javascript" src="/esp/files/yui/build/yahoo-dom-event/yahoo-dom-event.js"></script>
  64. <script type="text/javascript" src="/esp/files/yui/build/element/element-min.js"></script>
  65. <script type="text/javascript" src="/esp/files/yui/build/connection/connection-min.js"></script>
  66. <script type="text/javascript" src="/esp/files/yui/build/dragdrop/dragdrop-min.js"></script>
  67. <script type="text/javascript" src="/esp/files/yui/build/container/container-min.js"></script>
  68. <script type="text/javascript" src="/esp/files/yui/build/resize/resize-min.js"></script>
  69. <script type="text/javascript" src="/esp/files/yui/build/animation/animation-min.js"></script>
  70. <script type="text/javascript" src="/esp/files/yui/build/button/button-min.js"></script>
  71. <script type="text/javascript" src="/esp/files/yui/build/menu/menu.js"></script>
  72. <script type="text/javascript" src="/esp/files/yui/build/animation/animation-min.js"></script>
  73. <script type="text/javascript" src="/esp/files/yui/build/layout/layout-min.js"></script>
  74. <script type="text/javascript" src="/esp/files/yui/build/datasource/datasource-min.js"></script>
  75. <script type="text/javascript" src="/esp/files/yui/build/paginator/paginator-min.js"></script>
  76. <script type="text/javascript" src="/esp/files/yui/build/datatable/datatable-min.js"></script>
  77. <script type="text/javascript" src="/esp/files/yui/build/json/json-min.js"></script>
  78. <script type="text/javascript" src="/esp/files/yui/build/tabview/tabview-min.js"></script>
  79. <script type="text/javascript" src="/esp/files/yui/build/treeview/treeview.js"></script>
  80. <script type="text/javascript" src="/esp/files/yui/build/autocomplete/autocomplete-min.js"></script>
  81. <script type="text/javascript" src="/esp/files/yui/build/hpcc-ext/DataView.js"></script>
  82. <script type="text/javascript" src="/esp/files/yui/build/hpcc-ext/RowFilter.js"></script>
  83. <style type="text/css">
  84. </style>
  85. </head>
  86. <body class="yui-skin-sam" onload="setReloadFunction('refreshNode');buildTree();" onclick="checkTreeClick();">
  87. <div id="left1" style="text-align:left; width:600px; font-size:0.85em; height:auto; min-height:100%;">
  88. <div id="espNavTree" class=" ygtv-highlight" style="font-size:0.90em; padding: 2px; height: 100%;">&nbsp;</div>
  89. </div>
  90. <script type="text/javascript">
  91. <xsl:text disable-output-escaping="yes"><![CDATA[
  92. var tree, currentIconMode;
  93. var lastClickIsTreeClick = null;
  94. var treeSelections;
  95. /*
  96. function init() {
  97. var loader = new YAHOO.util.YUILoader({
  98. require: ["treeview", "button", "animation", "autocomplete"],
  99. base: '/esp/files/yui/build/',
  100. loadOptional: false,
  101. combine: true,
  102. filter: "MIN",
  103. allowRollup: true,
  104. //When the loading is all complete, we want to initialize
  105. //our TabView process; we can set this here or pass this
  106. //in as an argument to the insert() method:
  107. onSuccess: function() {
  108. //YAHOO.util.Get.css('yui/build/treeview/assets/css/folders/tree.css');
  109. //YAHOO.util.Get.script('scripts/ws_roxieconfig_left.js');
  110. //YAHOO.util.Get.script('/esp/files/scripts/ws_roxieconfig.js');
  111. }
  112. });
  113. loader.insert();
  114. };
  115. YAHOO.util.Event.addListener(window, "load", init);
  116. */
  117. function checkTreeClick() {
  118. if (lastClickIsTreeClick == null) {
  119. clearNavTreeSelects();
  120. }
  121. lastClickIsTreeClick = null;
  122. }
  123. function loadNodeData(node, fnLoadComplete) {
  124. var nodeLabel = encodeURI(node.label);
  125. tree.locked = false;
  126. //prepare URL for XHR request:
  127. var sUrl = "/esp/navdata?" + node.data.params;
  128. //prepare our callback object
  129. var callback = {
  130. //if our XHR call is successful, we want to make use
  131. //of the returned data and create child nodes.
  132. success: function(oResponse) {
  133. var xmlDoc = oResponse.responseXML;
  134. node.setNodesProperty("propagateHighlightUp",false);
  135. node.setNodesProperty("propagateHighlightDown",false);
  136. var folderNodes = xmlDoc.getElementsByTagName("DynamicFolder");
  137. for(var i = 0; i < folderNodes.length; i++)
  138. {
  139. var childNode = new YAHOO.widget.TextNode({label: folderNodes[i].getAttribute("name")}, node);
  140. //childNode.labelStyle = "icon-doc";
  141. childNode.setNodesProperty("propagateHighlightUp",true);
  142. childNode.setNodesProperty("propagateHighlightDown",true);
  143. childNode.data = { elementType:'DynamicFolder', params: folderNodes[i].getAttribute("params") };
  144. }
  145. folderNodes = xmlDoc.getElementsByTagName("Link");
  146. for(var i = 0; i < folderNodes.length; i++)
  147. {
  148. var childNode = new YAHOO.widget.TextNode({label: folderNodes[i].getAttribute("name"), expanded:true}, node);
  149. //childNode.labelStyle = "icon-doc";
  150. childNode.isLeaf = true;
  151. childNode.data = { elementType:'Link', params: folderNodes[i].getAttribute("params") };
  152. childNode.setNodesProperty("propagateHighlightUp",true);
  153. childNode.setNodesProperty("propagateHighlightDown",true);
  154. }
  155. //When we're done creating child nodes, we execute the node's
  156. //loadComplete callback method which comes in via the argument
  157. //in the response object (we could also access it at node.loadComplete,
  158. //if necessary):
  159. oResponse.argument.fnLoadComplete();
  160. // Reset the propagate after the rending as it speeds up the dynamic load...
  161. node.setNodesProperty("propagateHighlightUp",true);
  162. node.setNodesProperty("propagateHighlightDown",true);
  163. },
  164. //if our XHR call is not successful, we want to
  165. //fire the TreeView callback and let the Tree
  166. //proceed with its business.
  167. failure: function(oResponse) {
  168. oResponse.argument.fnLoadComplete();
  169. },
  170. //our handlers for the XHR response will need the same
  171. //argument information we got to loadNodeData, so
  172. //we'll pass those along:
  173. argument: {
  174. "node": node,
  175. "fnLoadComplete": fnLoadComplete
  176. }
  177. //timeout -- if more than 7 seconds go by, we'll abort
  178. //the transaction and assume there are no children:
  179. //timeout: 21000
  180. };
  181. //With our callback object ready, it's now time to
  182. //make our XHR call using Connection Manager's
  183. //asyncRequest method:
  184. YAHOO.util.Connect.asyncRequest('GET', sUrl, callback);
  185. }
  186. function ImportFromTree(Node)
  187. {
  188. lastClickIsTreeClick = Node;
  189. if (Node != null){
  190. Node.highlightState = 1;
  191. tree.render;
  192. }
  193. var handleSuccess = function(o){
  194. if(o.responseText !== undefined){
  195. if (o.statusText == 'OK')
  196. {
  197. // update main frame and point to deploy tab.
  198. var f=top.frames['main'];
  199. if (f) {
  200. f.window.tabView.set('activeIndex',6)
  201. //f.window.loadTab(6);
  202. //f.location= '/ws_roxieconfig/NewRoxieConfigUI?ShowDeployTab=1';
  203. }
  204. clearNavTreeSelects();
  205. }
  206. }
  207. }
  208. var handleFailure = function(o){
  209. }
  210. var callback =
  211. {
  212. success:handleSuccess,
  213. failure: handleFailure,
  214. argument: ['foo','bar']
  215. };
  216. // create xml from tree.
  217. var postData = createXmlArg();
  218. YAHOO.util.Connect.initHeader("Content-Type", "application/x-www-form-urlencoded");
  219. var request = YAHOO.util.Connect.asyncRequest('POST', '/ws_roxieconfig/NavMenuEvent?cmd=DeployMultiple', callback, 'Cmd=DeployMultiple&XmlArg=' + postData);
  220. }
  221. function createXmlArg() {
  222. // Select this node
  223. var rootNode = tree.getRoot();
  224. var xmlArgs = '';
  225. if (rootNode.children.length > 0) {
  226. // Select All it's children...
  227. if (rootNode.highlightState > 0)
  228. {
  229. xmlArgs = '<EspNavigationData>' + selectChildNodes(rootNode) + '</EspNavigationData>';
  230. }
  231. }
  232. //var hiLit = Node.tree.getNodesByProperty('highlightState',1);
  233. //var xmlArgs = '<EspNavigationData><Folder name="Attribute Servers"><DynamicFolder name="dataland" params="type=repository&amp;subtype=as&amp;name=dataland&amp;netAddress=http://jprichard-vm:8145"><DynamicFolder name="stu_test" params="type=repository&amp;subtype=am&amp;netAddress=http://jprichard-vm:8145&amp;module=stu_test&amp;name=dataland"><Link name="Addition3" selected="true"/></DynamicFolder></DynamicFolder></Folder></EspNavigationData>';
  234. // if the node is a module then load it's children and then traverse up
  235. // otherwise wrap itself and traverse up.
  236. xmlArgs = escape(xmlArgs);
  237. xmlArgs = xmlArgs.replace(/'+'/g, '%20')
  238. return xmlArgs;
  239. }
  240. function selectChildNodes(Node){
  241. var xmlChildArgs = '';
  242. for(var i=0;i<Node.children.length;i++)
  243. {
  244. if (Node.children[i].highlightState > 0)
  245. {
  246. xmlChildArgs = xmlChildArgs + selectChildNodes(Node.children[i]);
  247. }
  248. }
  249. if (Node.parent == null) {
  250. return xmlChildArgs;
  251. }
  252. //return '<' + Node.data.elementType + ' name="' + Node.label + '" ' + (Node.data.params != null && Node.data.params != '' ? 'params="' + Node.data.params.replace(/&/g, '&amp;') + '" ': '') + (Node.data.elementType=='Link' ? 'selected="true" ': '') + '>' + xmlChildArgs + '</' + Node.data.elementType + '>';
  253. return '<' + Node.data.elementType + ' name="' + Node.label + '" ' + (Node.data.params != null && Node.data.params != '' ? 'params="' + Node.data.params.replace(/&/g, '&amp;') + '" ': '') + (Node.highlightState == 1 ? 'selected="true" ': '') + '>' + xmlChildArgs + '</' + Node.data.elementType + '>';
  254. }
  255. /*
  256. "contextmenu" event handler for the element(s) that
  257. triggered the display of the ContextMenu instance - used
  258. to set a reference to the TextNode instance that triggered
  259. the display of the ContextMenu instance.
  260. */
  261. function onNavTreeContextMenu(p_oEvent, eventargs) {
  262. lastClickIsTreeClick = true;
  263. var oTarget = this.contextEventTarget;
  264. /*
  265. Get the TextNode instance that that triggered the
  266. display of the ContextMenu instance.
  267. */
  268. oCurrentTextNode = tree.getNodeByElement(oTarget);
  269. if (!oCurrentTextNode) {
  270. // Cancel the display of the ContextMenu instance.
  271. this.cancel();
  272. } else {
  273. if (!eventargs[0].ctrlKey) {
  274. clearNavTreeSelects();
  275. }
  276. if (oCurrentTextNode.depth > 1) {
  277. oCurrentTextNode.highlight();
  278. }
  279. }
  280. }
  281. function deploy() {
  282. ImportFromTree(null);
  283. }
  284. function onImportTreeClick(oArgs) {
  285. tree.onEventToggleHighlight(oArgs);
  286. }
  287. function refreshNode() {
  288. tree.removeChildren(oCurrentTextNode);
  289. oCurrentTextNode.unhighlight();
  290. oCurrentTextNode.expand();
  291. }
  292. function clearNavTreeSelects() {
  293. var hiLit = tree.getNodesByProperty('highlightState',1);
  294. if (YAHOO.lang.isNull(hiLit)) {
  295. } else {
  296. for (var i = 0; i < hiLit.length; i++) {
  297. if (hiLit[i].depth == 3) {
  298. hiLit[i].unhighlight();
  299. }
  300. }
  301. }
  302. hiLit = tree.getNodesByProperty('highlightState',2);
  303. if (YAHOO.lang.isNull(hiLit)) {
  304. } else {
  305. for (var i = 0; i < hiLit.length; i++) {
  306. if (hiLit[i].depth == 2) {
  307. hiLit[i].unhighlight();
  308. }
  309. }
  310. }
  311. hiLit = tree.getNodesByProperty('highlightState',1);
  312. if (YAHOO.lang.isNull(hiLit)) {
  313. } else {
  314. for (var i = 0; i < hiLit.length; i++) {
  315. hiLit[i].unhighlight();
  316. }
  317. }
  318. }
  319. /*
  320. Instantiate a ContextMenu: The first argument passed to the constructor
  321. is the id for the Menu element to be created, the second is an
  322. object literal of configuration properties.
  323. */
  324. var oNavTreeContextMenu;
  325. /*
  326. Subscribe to the "contextmenu" event for the element(s)
  327. specified as the "trigger" for the ContextMenu instance.
  328. */
  329. var lastTreeNode;
  330. var onTreeClick = function(oArgs) {
  331. lastClickIsTreeClick = true;
  332. oCurrentTextNode = oArgs.node;
  333. if (!oArgs.event.ctrlKey && !oArgs.event.shiftKey) {
  334. clearNavTreeSelects();
  335. }
  336. if (oArgs.event.shiftKey) {
  337. if (oArgs.node.depth == 3) {
  338. //debugger;
  339. // check if the lastTreeNode and the current node have the same parent.
  340. if (lastTreeNode.parent == oArgs.node.parent) {
  341. var markNodes = false;
  342. for(var i=0;i<lastTreeNode.parent.children.length;i++) {
  343. if ((lastTreeNode.parent.children[i] == lastTreeNode || lastTreeNode.parent.children[i] == oArgs.node) && !markNodes) {
  344. markNodes = true;
  345. } else {
  346. if (markNodes) {
  347. lastTreeNode.parent.children[i].highlight();
  348. if (lastTreeNode.parent.children[i] == lastTreeNode || lastTreeNode.parent.children[i] == oArgs.node) {
  349. break;
  350. }
  351. }
  352. }
  353. }
  354. tree.clearTextSelection();
  355. }
  356. return false;
  357. }
  358. }
  359. if (oArgs.node.depth == 3) {
  360. lastTreeNode = oArgs.node;
  361. }
  362. var retVal = tree.onEventToggleHighlight(oArgs);
  363. if (oArgs.event.ctrlKey) {
  364. tree.clearTextSelection();
  365. }
  366. return retVal;
  367. };
  368. ]]></xsl:text>
  369. <xsl:call-template name="insertJavascriptTree"/>
  370. </script>
  371. </body>
  372. </html>
  373. </xsl:template>
  374. <xsl:template name="insertJavascriptTree">
  375. function buildTree() {
  376. tree = new YAHOO.widget.TreeView("espNavTree");
  377. tree.subscribe('dblClickEvent',function(oArgs) {
  378. ImportFromTree(oArgs.Node);
  379. });
  380. tree.locked = false;
  381. tree.setNodesProperty("propagateHighlightUp", true);
  382. tree.setNodesProperty("propagateHighlightDown", true);
  383. var root = tree.getRoot();
  384. root.setNodesProperty("propagateHighlightUp", true);
  385. root.setNodesProperty("propagateHighlightDown", true);
  386. tree.setDynamicLoad(loadNodeData, currentIconMode);
  387. tree.subscribe("clickEvent", onTreeClick);
  388. var serverNode, folderNode;
  389. <xsl:for-each select="Folder">
  390. serverNode = new YAHOO.widget.TextNode({label: "<xsl:value-of select="@name"/>", expanded:true, dynamicLoadComplete:false}, root);
  391. serverNode.data = { elementType: 'Folder', params: '' };
  392. serverNode.setNodesProperty("propagateHighlightUp",true);
  393. serverNode.setNodesProperty("propagateHighlightDown",true);
  394. <xsl:for-each select="DynamicFolder">
  395. folderNode = new YAHOO.widget.TextNode({label: "<xsl:value-of select="@name"/>"}, serverNode);
  396. //folderNode.labelStyle = "icon-doc";
  397. folderNode.setNodesProperty("propagateHighlightUp",true);
  398. folderNode.setNodesProperty("propagateHighlightDown",true);
  399. folderNode.data = { elementType: 'DynamicFolder', params: '<xsl:value-of select="@params" disable-output-escaping="yes"/>' };
  400. </xsl:for-each>
  401. </xsl:for-each>
  402. tree.render();
  403. var oNavTreeContextMenu = new YAHOO.widget.ContextMenu(
  404. "navtreecontextmenu",
  405. {
  406. trigger: "espNavTree",
  407. lazyload: true,
  408. itemdata: [
  409. { text: "Import", onclick: {fn: ImportFromTree} },
  410. { text: "Clear Selections", onclick: {fn: clearNavTreeSelects}},
  411. { text: "Refresh", onclick: {fn: refreshNode}}
  412. ]
  413. }
  414. );
  415. oNavTreeContextMenu.subscribe("triggerContextMenu", onNavTreeContextMenu);
  416. }
  417. </xsl:template>
  418. </xsl:stylesheet>