ReportView.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. if (typeof(bobj.crv.ReportView) == 'undefined') {
  3. bobj.crv.ReportView = {};
  4. }
  5. /**
  6. * ReportView Constructor
  7. */
  8. bobj.crv.newReportView = function(kwArgs) {
  9. kwArgs = MochiKit.Base.update({
  10. id: bobj.uniqueId(),
  11. viewStateId: null,
  12. isMainReport: false
  13. }, kwArgs);
  14. var o = newWidget(kwArgs.id);
  15. bobj.fillIn(o, kwArgs);
  16. o.widgetType = 'ReportView';
  17. o.toolPanel = null;
  18. o.reportPage = null;
  19. o.grabber = null;
  20. o._lastPanelWidth = null;
  21. // Attach member functions
  22. o.initOld = o.init;
  23. o.isMainReportFlag = o.isMainReport;
  24. o.setDisplayOld = o.setDisplay;
  25. MochiKit.Base.update(o, bobj.crv.ReportView);
  26. return o;
  27. };
  28. bobj.crv.ReportView.init = function() {
  29. var connect = MochiKit.Signal.connect;
  30. var signal = MochiKit.Signal.signal;
  31. var partial = MochiKit.Base.partial;
  32. this.initOld();
  33. if (this.toolPanel) {
  34. connect(this.toolPanel, 'grpDrilldown', partial(signal, this, 'grpDrilldown'));
  35. connect(this.toolPanel, 'grpNodeRetrieveChildren', partial(signal, this, 'grpNodeRetrieveChildren'));
  36. connect(this.toolPanel, 'grpNodeCollapse', partial(signal, this, 'grpNodeCollapse'));
  37. connect(this.toolPanel, 'grpNodeExpand', partial(signal, this, 'grpNodeExpand'));
  38. connect(this.toolPanel, 'paramAdvanced', partial(signal, this, 'paramAdvanced'));
  39. connect(this.toolPanel, 'paramApply', partial(signal, this, 'paramApply'));
  40. }
  41. if (this.grabber) {
  42. this.grabber.init();
  43. if (!this.toolPanel.isDisplayed()) {
  44. this.grabber.setDisplay(false);
  45. }
  46. }
  47. };
  48. bobj.crv.ReportView.addChild = function(widget) {
  49. var mb = MochiKit.Base;
  50. var ms = MochiKit.Signal;
  51. if (widget.widgetType == 'ToolPanel') {
  52. this.toolPanel = widget;
  53. ms.connect(this.toolPanel, 'resize', mb.partial(ms.signal, this, 'resizeToolPanel'));
  54. }
  55. else if (widget.widgetType == 'ReportPage') {
  56. this.reportPage = widget;
  57. }
  58. };
  59. bobj.crv.ReportView.update = function(update, updatePack) {
  60. if(update && update.cons == "bobj.crv.newReportView") {
  61. for(var childVar in update.children) {
  62. var child = update.children[childVar];
  63. if(child) {
  64. switch(child.cons) {
  65. case "bobj.crv.newToolPanel":
  66. if(this.toolPanel && updatePack.updateToolPanel()) {
  67. this.toolPanel.update(child, updatePack);
  68. }
  69. break;
  70. case "bobj.crv.newReportPage":
  71. if(this.reportPage && updatePack.updateReportPage()) {
  72. this.reportPage.update(child,updatePack);
  73. }
  74. break;
  75. }
  76. }
  77. }
  78. }
  79. };
  80. bobj.crv.ReportView.getHTML = function() {
  81. var h = bobj.html;
  82. if (this.toolPanel && this.reportPage) {
  83. this.grabber = newGrabberWidget(
  84. this.id + '_grabber',
  85. MochiKit.Base.bind(bobj.crv.ReportView._grabberCB, this),
  86. 0, // intial left
  87. 0, // intial top
  88. 4, // width
  89. 1, // intial height (has to be pixels so we'll figure it out later)
  90. true); // Moves on the horizontal axis
  91. }
  92. var layerStyle = {
  93. width:'100%',
  94. height:'100%',
  95. overflow: 'hidden',
  96. position: 'relative'
  97. };
  98. var html = h.DIV({id: this.id, style: layerStyle},
  99. this.toolPanel ? this.toolPanel.getHTML(): '',
  100. this.grabber ? this.grabber.getHTML() : '',
  101. this.reportPage ? this.reportPage.getHTML() : '' );
  102. return html + bobj.crv.getInitHTML(this.widx);
  103. };
  104. bobj.crv.ReportView._doLayout = function() {
  105. if (!this.isDisplayed()) {
  106. return;
  107. }
  108. var panelW = this.toolPanel && this.toolPanel.isDisplayed() ? this.toolPanel.getWidth() : 0;
  109. var grabberW = this.grabber && this.grabber.isDisplayed() ? this.grabber.getWidth() : 0;
  110. var innerHeight = this.getHeight();
  111. if (this.reportPage) {
  112. this.reportPage.resize(this.getWidth() - panelW - grabberW, innerHeight);
  113. this.reportPage.move(panelW + grabberW, 0);
  114. }
  115. if (this.grabber && this.grabber.isDisplayed()) {
  116. this.grabber.resize(null, innerHeight);
  117. this.grabber.move(panelW, 0);
  118. }
  119. if (this.toolPanel && this.toolPanel.isDisplayed()) {
  120. this.toolPanel.resize(null, innerHeight);
  121. }
  122. };
  123. bobj.crv.ReportView.isMainReport = function() {
  124. return this.isMainReportFlag;
  125. };
  126. /**
  127. * Private. Handles drag and drop of the resize bar (grabber).
  128. */
  129. bobj.crv.ReportView._grabberCB = function(x, y) {
  130. this.toolPanel.resize(x);
  131. this._doLayout();
  132. };
  133. bobj.crv.ReportView.setDisplay = function(isDisplayed) {
  134. this.setDisplayOld(isDisplayed);
  135. if (isDisplayed) {
  136. this._doLayout();
  137. }
  138. };
  139. /**
  140. * ReportView will always fill its container but it should be told when to
  141. * resize so that the layout of its contents will be updated.
  142. */
  143. bobj.crv.ReportView.resize = function() {
  144. this._doLayout();
  145. };
  146. /**
  147. * @return Returns a suggested size for the widget as an object with width and
  148. * height integer properties that specify the dimensions in pixels.
  149. */
  150. bobj.crv.ReportView.getBestFitSize = function() {
  151. var w = 0;
  152. var h = 0;
  153. var pageSize = this.reportPage ? this.reportPage.getBestFitSize() : null;
  154. if (pageSize) {
  155. w += pageSize.width;
  156. h += pageSize.height;
  157. } else if (this.toolPanel) {
  158. h += this.toolPanel.getHeight();
  159. }
  160. if (this.toolPanel) {
  161. w += this.toolPanel.getWidth();
  162. }
  163. if (this.grabber) {
  164. w += this.grabber.getWidth();
  165. }
  166. return {
  167. width: w,
  168. height: h
  169. }
  170. };
  171. /**
  172. * Shows or hides the tool panel.
  173. *
  174. * @param disp [bool] True value shows panel. False value hides it.
  175. */
  176. bobj.crv.ReportView.setDisplayToolPanel = function(disp) {
  177. if (this.toolPanel) {
  178. this.toolPanel.setDisplay(disp);
  179. if (this.grabber) {
  180. this.grabber.setDisplay(disp);
  181. }
  182. this._doLayout();
  183. MochiKit.Signal.signal(this, disp ? 'showToolPanel' : 'hideToolPanel');
  184. }
  185. };
  186. /**
  187. * @return True if the view has report content. False if the view is empty.
  188. */
  189. bobj.crv.ReportView.hasContent = function() {
  190. return this.toolPanel || this.reportPage;
  191. };
  192. /**
  193. * TODO
  194. * overriding this function from the library because it generated unbalanced tags.
  195. * need to submit a fix to the official source tree.
  196. */
  197. function GrabberWidget_getHTML()
  198. // returns [String] widget HTML
  199. {
  200. var o=this
  201. var cr=o.isHori?_resizeW:_resizeH
  202. var moveableCb='onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.GrabberWidget_down(event,\''+o.index+'\',this);return false;"'
  203. var imgG=_ie?('<img onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.eventCancelBubble(event)" border="0" hspace="0" vspace="0" src="'+_skin+'../transp.gif" id="modal_'+o.id+'" style="z-index:10000;display:none;position:absolute;top:0px;left:0px;width:1px;height:1px;cursor:'+cr+'">'):('<div onselectstart="return false" ondragstart="return false" onmousedown="'+_codeWinName+'.eventCancelBubble(event)" border="0" hspace="0" vspace="0" id="modal_'+o.id+'" style="z-index:10000;display:none;position:absolute;top:0px;left:0px;width:1px;height:1px;cursor:'+cr+'"></div>')
  204. return getBGIframe('grabIframe_'+o.id)+imgG+'<table cellpadding="0" cellspacing="0" border="0" '+moveableCb+' id="'+o.id+'" style="overflow:hidden;position:absolute;left:'+o.x+'px;top:'+o.y+'px;width:'+o.w+'px;height:'+o.h+'px;cursor:'+cr+'"><tr><td></td></tr></table>'
  205. }