prompttree.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // <script>
  2. /*
  3. =============================================================
  4. WebIntelligence(r) Report Panel
  5. Copyright(c) 2001-2003 Business Objects S.A.
  6. All rights reserved
  7. Use and support of this software is governed by the terms
  8. and conditions of the software license agreement and support
  9. policy of Business Objects S.A. and/or its subsidiaries.
  10. The Business Objects products and technology are protected
  11. by the US patent number 5,555,403 and 6,247,008
  12. File: treeview.js
  13. Custom treeview control
  14. =============================================================
  15. */
  16. // ================================================================================
  17. // ================================================================================
  18. //
  19. // OBJECT newTreePromptWidget (Constructor)
  20. //
  21. // Tree view class
  22. //
  23. // ================================================================================
  24. // ================================================================================
  25. function newTreePromptWidget(id,w,h,clickCB,doubleClickCB,bgClass,expandCB,collapseCB)
  26. {
  27. var o=newTreeWidget(id,w,h,_skin+'../prompt.gif',clickCB,doubleClickCB,bgClass,expandCB,collapseCB)
  28. o.padding=0
  29. o.iconW=15
  30. o.iconH=17
  31. o.dispIcnFuncName="dispIcnPrompt"
  32. return o
  33. }
  34. // ================================================================================
  35. // ================================================================================
  36. //
  37. // OBJECT newTreePromptElem (Constructor)
  38. //
  39. // Tree view element class
  40. //
  41. // ================================================================================
  42. // ================================================================================
  43. function newTreePromptElem(name,values,userData)
  44. // name [String] the prompt name
  45. // values [String] the prompt values. use null if no values (used to chnage the check mark)
  46. // userData [Varies - Optional] user data
  47. {
  48. var o=newTreeWidgetElem(3,name,userData,null,2,null)
  49. o.isPrompt=true
  50. o.values=values
  51. o.getHTML=TreePromptElem_getHTML
  52. o.isChecked=TreePromptElem_isChecked
  53. o.change=TreePromptElem_change
  54. o.selectedClass='promptSelected'
  55. o.nonselectedClass='promptNormal'
  56. o.select=TreePromptElem_select
  57. o.selected=false
  58. o.checkIcn=null
  59. o.init=TreePromptElem_init
  60. return o
  61. }
  62. // ================================================================================
  63. function TreePromptElem_init()
  64. {
  65. var o=this
  66. o.domElem=getLayer(_codeWinName+'trLstElt' + o.id)
  67. o.icnLyr=getLayer(_codeWinName+'icn' + o.id)
  68. o.toggleLyr=getLayer(_codeWinName+'trTog' + o.id)
  69. }
  70. // ================================================================================
  71. function TreePromptElem_change(name,values)
  72. {
  73. var o=this
  74. o.name=name
  75. o.values=values
  76. if (o.domElem==null)
  77. o.domElem=getLayer(_codeWinName+"trLstElt"+o.id);
  78. if (o.domElem!=null)
  79. {
  80. o.domElem.innerHTML=convStr(o.name)+(o.values!=null?('<b><span style="color:red">&nbsp;:&nbsp;</span>'+convStr(o.values)+'</b>'):'')
  81. if (o.par==null)
  82. {
  83. if (o.checkIcn==null)
  84. o.checkIcn=getLayer(_codeWinName+o.id+"_checkIcn")
  85. changeSimpleOffset(o.checkIcn,0,o.isChecked()?0:17,null,o.isChecked()?_checkedPromptLab:_nocheckedPromptLab)
  86. }
  87. //cf updatetooltip in treeview.js
  88. if(o.values)
  89. o.advTooltip=_selectionPromptLab +' '+ o.values
  90. else
  91. o.advTooltip=_noselectionPromptLab
  92. }
  93. }
  94. // ================================================================================
  95. function TreePromptElem_select(setFocus,ev)
  96. {
  97. with (this)
  98. {
  99. if (treeView.selId!=id)
  100. {
  101. if (treeView.selId>=0)
  102. {
  103. var prev=_TreeWidgetElemInstances[treeView.selId]
  104. prev.init()
  105. var e=prev.domElem
  106. e.className=prev.nonselectedClass
  107. e.parentNode.parentNode.className=prev.nonselectedClass
  108. var prevIcn=prev.icnLyr
  109. if (prevIcn==null)
  110. prevIcn=prev.icnLyr=getLayer(_codeWinName+"icn"+prev.id)
  111. prevIcn.parentNode.className=prev.nonselectedClass
  112. prev.selected=false
  113. var arrowL=prevIcn.childNodes[0]
  114. changeSimpleOffset(arrowL,prev.selected?15:0,prev.sub.length==0?17*4:(prev.expanded?17*2:17*3))
  115. }
  116. treeView.selId=id;
  117. init()
  118. treeView.layer._BOselId=id
  119. var de=domElem
  120. de.className=selectedClass
  121. de.parentNode.parentNode.className=selectedClass
  122. if (this.icnLyr==null)
  123. this.icnLyr=getLayer(_codeWinName+"icn"+id)
  124. this.icnLyr.parentNode.className=selectedClass
  125. this.selected=true
  126. var arrowL=this.icnLyr.childNodes[0]
  127. changeSimpleOffset(arrowL,this.selected?15:0,this.sub.length==0?17*4:(this.expanded?17*2:17*3))
  128. if (setFocus)
  129. de.focus()
  130. if (treeView.clickCB) treeView.clickCB(userData)
  131. }
  132. }
  133. // stop propagating event to the other link
  134. if (ev)
  135. eventCancelBubble(ev) //DOESN'T WORK WITH NETSCAPE
  136. }
  137. // ================================================================================
  138. function TreePromptElem_isChecked()
  139. {
  140. return this.values!=null
  141. }
  142. // ================================================================================
  143. function TreePromptElem_getHTML(indent,isFirst)
  144. // Get the prompt tree element HTML
  145. // indent [int] : element indentation in pixels
  146. // returns [String] the HTML
  147. {
  148. var o=this,a=new Array,i=0,len=o.sub.length,exp=(len>0)||o.isIncomplete,icns=o.treeView.icns
  149. var bord="border-top:0px;"
  150. if (isFirst)
  151. {
  152. o.treeView.isFirst=false
  153. bord=""
  154. }
  155. var isLast=false
  156. if (o.par)
  157. {
  158. var psub=o.par.sub,plen=psub.length
  159. if (plen>0)
  160. isLast = (psub[plen-1].id==o.id)
  161. }
  162. if ((o.par!=null)&&isLast)
  163. bord+="border-bottom:0px;"
  164. var cliEvt=' onclick="'+_codeWinName+'.TreeWidget_clickCB('+o.id+',false,event);if(_saf||_ie) return false" onmousedown="'+_codeWinName+'.TreeWidget_clickCB('+o.id+',false,event);if(_saf||_ie) return false" ondblclick="'+_codeWinName+'.treeDblClickCB('+o.id+',event);return false" '
  165. a[i++]='<table style="border:1px solid #E2E2E2;border-right:0px;'+bord+'" width="100%" border="0" cellspacing="0" cellpadding="0">'
  166. // first row
  167. a[i++]='<tr valign="top">'
  168. // Icon cheched/unchecked for first level elements
  169. if (o.par==null)
  170. a[i++]='<td width="15" style="border-right:1px solid #E2E2E2;">'+simpleImgOffset(icns,15,17,0,o.isChecked()?0:17,_codeWinName+o.id+"_checkIcn",null,o.isChecked()?_checkedPromptLab:_nocheckedPromptLab)+'</td>'
  171. // Icon
  172. a[i++]='<td '+cliEvt+' class="promptNormal" width="15"><span id="'+_codeWinName+'icn'+o.id+'" '+(_moz?'onclick':'onmousedown')+'="'+_codeWinName+'.TreeWidget_clickCB('+o.id+',true,event); if (_ie) return false" ondblclick="'+_codeWinName+'.treeDblClickCB('+o.id+',event);return false">'+simpleImgOffset(icns,15,17,0,exp?(o.expanded?34:51):68)+'</span></td>'
  173. // name & values
  174. a[i++]='<td '+cliEvt+' class="promptNormal" width="100%" style="padding-top:2px;padding-right:0px"><nobr>'
  175. a[i++]='&nbsp;<a class="promptNormal" id="'+_codeWinName+'trLstElt'+o.id+'" href="javascript:void(0)" onfocus="'+_codeWinName+'.treeFCCB(this,'+o.id+',true)" onblur="'+_codeWinName+'.treeFCCB(this,'+o.id+',false)">'
  176. a[i++]=''+convStr(o.name)+(o.values!=null?('<b><span style="color:red">&nbsp;:&nbsp;</span>'+convStr(o.values)+'</b>'):'')+'</a>'
  177. a[i++]='</nobr>'
  178. // child nodes
  179. if (exp)
  180. a[i++]='<table width="100%" style="display:'+(o.expanded?'block':'none')+' " border="0" cellspacing="0" cellpadding="0"><tr><td id="'+_codeWinName+'trTog'+o.id+'" style="padding:0px;padding-left:20px;padding-top:3px;">'
  181. // Generate child HTML if needed
  182. if (o.expanded)
  183. {
  184. o.generated=true
  185. var idt=indent+_trIndent
  186. for (var j=0;j<len;j++) a[i++]=o.sub[j].getHTML(idt,j==0);
  187. o.treeView.isFirst=false
  188. }
  189. // End child nodes
  190. if (exp)
  191. {
  192. nodeIndent=indent
  193. a[i++]="</td></tr></table>"
  194. }
  195. a[i++]='</td></tr></table>'
  196. // End first row
  197. //use in updatetooltip in treeview.js
  198. if(o.values)
  199. o.advTooltip=_selectionPromptLab +' '+ o.values
  200. else
  201. o.advTooltip=_noselectionPromptLab
  202. return a.join("");
  203. }
  204. // ================================================================================
  205. function dispIcnPrompt(eId)
  206. {
  207. var e=_TreeWidgetElemInstances[eId]
  208. with (e)
  209. {
  210. select()
  211. if (expanded&&!generated)
  212. {
  213. e.generated=true;
  214. var s='',len=sub.length,newInd=nodeIndent+_trIndent
  215. for (var j=0;j<len;j++) s+=sub[j].getHTML(newInd,j==0);
  216. toggleLyr.innerHTML=s;
  217. }
  218. var icn=treeView.icns[iconId]
  219. toggleLyr.parentNode.parentNode.parentNode.style.display=expanded?'block':'none'
  220. var arrowL=icnLyr.childNodes[0]
  221. changeSimpleOffset(arrowL,selected?15:0,expanded?17*2:17*3)
  222. }
  223. }