G_QanPrettyPrint.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /****************************************************************************************************************************
  2. Licensed Materials - Property of IBM
  3. BI and PM: QFW
  4. © Copyright IBM Corp. 2005, 2010
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. *****************************************************************************************************************************/
  7. var G_QanPrettyPrint = {};
  8. G_QanPrettyPrint.F_OnClick = function( v_elSrc, sFoldingState, sLang )
  9. {
  10. for( ; v_elSrc && v_elSrc.className != "selectTitle" &&
  11. v_elSrc.className != "selectAlias" &&
  12. v_elSrc.className != "itemDef";
  13. v_elSrc = v_elSrc.parentElement );
  14. if( !v_elSrc )
  15. return;
  16. if( v_elSrc.className == "itemDef" )
  17. return this.f_itemDefOnClick( v_elSrc, sLang );
  18. var v_elContent;
  19. var v_elHiddenContent;
  20. var v_elChild = v_elSrc.parentElement.firstChild;
  21. for( ; v_elChild; v_elChild = v_elChild.nextSibling )
  22. {
  23. if( v_elChild.className == "content" || v_elChild.className == "selectNest" )
  24. v_elContent = v_elChild;
  25. if( v_elChild.className == "collapsed" )
  26. v_elHiddenContent = v_elChild;
  27. }
  28. if( sFoldingState )
  29. {
  30. v_elContent.v_sFolding = (sFoldingState == "open")? null: sFoldingState;
  31. }
  32. else if( !v_elContent.v_sFolding )
  33. {
  34. if( v_elSrc.innerText.toUpperCase() == "FROM" ||
  35. v_elSrc.innerText.toUpperCase() == "WITH" )
  36. {
  37. v_elContent.v_sFolding = "halfOpen";
  38. }
  39. else
  40. v_elContent.v_sFolding = "closed";
  41. }
  42. else
  43. if( v_elContent.v_sFolding == "halfOpen" )
  44. v_elContent.v_sFolding = "closed";
  45. else
  46. v_elContent.v_sFolding = null;
  47. if( !v_elContent.v_sFolding )
  48. {
  49. v_elContent.style.display = "";
  50. v_elHiddenContent.style.display = "none";
  51. }
  52. else if( v_elContent.v_sFolding == "halfOpen")
  53. {
  54. for( var iAS = 0; iAS < v_elContent.childNodes.length; ++iAS )
  55. {
  56. var v_elItem = v_elContent.childNodes[iAS];
  57. if( v_elItem.className != "item" )
  58. continue;
  59. var v_elItemDef = v_elItem.firstChild;
  60. if( v_elItemDef.className != "itemDef" )
  61. continue;
  62. var v_elAliasedSelect = v_elItemDef.firstChild;
  63. if( v_elAliasedSelect.className != "aliasedSelect" )
  64. continue;
  65. for( var iA = 0; iA < v_elAliasedSelect.childNodes.length; ++iA )
  66. {
  67. var v_elAlias = v_elAliasedSelect.childNodes[iA];
  68. if( v_elAlias.className != "selectAlias" )
  69. continue;
  70. this.F_OnClick( v_elAlias, "closed" );
  71. }
  72. }
  73. }
  74. else
  75. {
  76. v_elContent.style.display = "none";
  77. if( !v_elHiddenContent )
  78. {
  79. v_elHiddenContent = v_elContent.document.createElement( "span" );
  80. v_elContent.parentElement.insertBefore( v_elHiddenContent, v_elContent );
  81. v_elHiddenContent.className = "collapsed";
  82. }
  83. v_elHiddenContent.style.display = "inline";
  84. }
  85. }
  86. G_QanPrettyPrint.f_getQanParser = function()
  87. {
  88. if( !this.f_oQanParser )
  89. this.f_oQanParser = new C_QanParser();
  90. return this.f_oQanParser;
  91. }
  92. G_QanPrettyPrint.f_getItemExprType = function( v_elSrc, sLang )
  93. {
  94. if( sLang == "MDX" )
  95. return "axisDef";
  96. for( ; v_elSrc && v_elSrc.className != "selectBlock"; v_elSrc = v_elSrc.parentElement );
  97. if( !v_elSrc )
  98. return;
  99. var v_elTitle = v_elSrc.firstChild;
  100. if( !v_elTitle || v_elTitle.className != "selectTitle" )
  101. return;
  102. var v_sBlockType = v_elTitle.innerText;
  103. if( v_sBlockType.toUpperCase() == "FROM" )
  104. return "fromItemExpr";
  105. else
  106. return "itemExpr";
  107. }
  108. G_QanPrettyPrint.f_itemDefOnClick = function( v_elSrc, sLang )
  109. {
  110. var v_sExprType = this.f_getItemExprType( v_elSrc, sLang );
  111. var v_elChild = v_elSrc.firstChild;
  112. for( ; v_elChild; v_elChild = v_elChild.nextSibling )
  113. if( v_elChild.className == v_sExprType )
  114. return;
  115. var v_oParser = this.f_getQanParser();
  116. var v_xmlResult = v_oParser.F_TransformBlockToXML( v_elSrc.innerText.F_LTrim(), v_sExprType, sLang );
  117. if( !v_xmlResult.nodeType )
  118. return;
  119. v_elSrc.onclick = function() { G_QanPrettyPrint.F_BlockOnClick(); };
  120. v_elSrc.onmouseover = function() { G_QanPrettyPrint.F_BlockOnMouseOver(); };
  121. v_elSrc.onmouseout = function() { G_QanPrettyPrint.F_BlockOnMouseOut(); };
  122. v_elSrc.innerHTML = v_oParser.F_TransformBlockToHTML( v_xmlResult );
  123. }
  124. G_QanPrettyPrint.f_getEventSrc = function( v_elSrc )
  125. {
  126. return ( event )? event.srcElement: G_QanApp.F_GetLoggingView().event.srcElement;
  127. }
  128. G_QanPrettyPrint.f_setNextBlockState = function( v_elSrc )
  129. {
  130. if( !v_elSrc.state )
  131. v_elSrc.state = "block";
  132. else if( v_elSrc.state == "block" )
  133. /* v_elSrc.state = "closed";
  134. else if( v_elSrc.state == "closed" ) */
  135. v_elSrc.state = null;
  136. }
  137. G_QanPrettyPrint.f_getBlockEffectiveSrc = function( v_elSrc )
  138. {
  139. if( v_elSrc.className != 'binaryOp' &&
  140. v_elSrc.className != 'fTitle' &&
  141. v_elSrc.className != 'joinTypeOn' &&
  142. v_elSrc.className != 'joinType' &&
  143. v_elSrc.className != 'joinOn' &&
  144. v_elSrc.className != 'betweenOp' &&
  145. v_elSrc.className != 'likeOp' &&
  146. v_elSrc.className != 'paramBlockId' &&
  147. v_elSrc.className != 'orderBlockId' &&
  148. v_elSrc.className != 'dimPropTitle' &&
  149. v_elSrc.className != 'caseOp' &&
  150. v_elSrc.className != 'when' &&
  151. v_elSrc.className != 'then' &&
  152. v_elSrc.className != 'else' )
  153. {
  154. return null;
  155. }
  156. // v_elSrc = this.f_getActiveBlock( v_elSrc );
  157. if( v_elSrc.className != 'when' &&
  158. v_elSrc.className != 'then' &&
  159. v_elSrc.className != 'joinOn' &&
  160. v_elSrc.className != 'else' )
  161. {
  162. return v_elSrc.parentElement;
  163. }
  164. return v_elSrc;
  165. }
  166. G_QanPrettyPrint.F_BlockOnClick = function()
  167. {
  168. var v_elSrc = this.f_getEventSrc();
  169. var v_elInitSrc = v_elSrc;
  170. v_elSrc = this.f_getBlockEffectiveSrc( v_elSrc );
  171. if( !v_elSrc )
  172. return;
  173. this.f_setNextBlockState( v_elSrc );
  174. var v_elChild = v_elSrc.firstChild;
  175. for( ; v_elChild; v_elChild = v_elChild.nextSibling )
  176. {
  177. if( !v_elChild.style || v_elChild == v_elInitSrc )
  178. continue;
  179. if( !v_elSrc.state )
  180. {
  181. v_elChild.style.width = "";
  182. v_elChild.style.overflow = "";
  183. v_elChild.style.height = "";
  184. v_elChild.style.paddingTop = "";
  185. v_elChild.style.backgroundColor = "";
  186. v_elChild.style.marginLeft = "";
  187. v_elChild.style.marginRight = "";
  188. v_elChild.style.borderBottom = "";
  189. v_elChild.style.borderLeft = "";
  190. v_elChild.style.borderRight = "";
  191. v_elChild.style.display = "";
  192. v_elChild.style.paddingLeft = "";
  193. }
  194. else if( v_elSrc.state == "block" )
  195. {
  196. v_elChild.style.display = "block";
  197. v_elChild.style.paddingLeft = "1em";
  198. }
  199. else if( v_elSrc.state == "closed" )
  200. {
  201. v_elChild.style.width = "1em";
  202. v_elChild.style.height = "0.5em";
  203. v_elChild.style.overflow = "hidden";
  204. v_elChild.style.paddingTop = "3em";
  205. v_elChild.style.backgroundColor = "#F7F7F7";
  206. v_elChild.style.marginLeft = "2px";
  207. v_elChild.style.marginRight = "2px";
  208. v_elChild.style.borderBottom = "#777777 1px solid";
  209. v_elChild.style.borderLeft = "#777777 1px solid";
  210. v_elChild.style.borderRight = "#777777 1px solid";
  211. v_elChild.style.display = "inline";
  212. }
  213. }
  214. }
  215. G_QanPrettyPrint.f_getActiveBlock = function( v_elSrc )
  216. {
  217. var v_elActive = v_elSrc;
  218. for( ; v_elActive.className == "unaryOp" ||
  219. v_elActive.className == "binaryOp" ||
  220. v_elActive.className == "unaryOp" ||
  221. v_elActive.className == "joinType" ||
  222. v_elActive.className == "joinTypeOn"||
  223. v_elActive.className == "paramBlockId"||
  224. v_elActive.className == "orderBlockId"||
  225. v_elActive.className == "fTitle"||
  226. v_elActive.className == "qnames"; )
  227. {
  228. v_elActive = v_elActive.parentElement;
  229. }
  230. return (v_elActive)? v_elActive: v_elSrc;
  231. }
  232. G_QanPrettyPrint.F_BlockOnMouseOver = function()
  233. {
  234. this.f_blockHightlight("#DDDDDD");
  235. }
  236. G_QanPrettyPrint.F_BlockOnMouseOut = function()
  237. {
  238. this.f_blockHightlight( "" );
  239. }
  240. G_QanPrettyPrint.f_blockHightlight = function(sColor )
  241. {
  242. var v_elSrc = this.f_getEventSrc();
  243. var v_elInitSrc = v_elSrc;
  244. v_elSrc = this.f_getBlockEffectiveSrc( v_elSrc );
  245. if( !v_elSrc )
  246. return;
  247. var v_elChild = v_elSrc.firstChild;
  248. for( ; v_elChild; v_elChild = v_elChild.nextSibling )
  249. {
  250. if( !v_elChild.style || v_elChild == v_elInitSrc ||
  251. v_elChild == v_elInitSrc.parentElement)
  252. {
  253. continue;
  254. }
  255. v_elChild.style.backgroundColor = sColor;
  256. }
  257. }