ReportPage.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. if (typeof(bobj.crv.ReportPage) == 'undefined') {
  3. bobj.crv.ReportPage = {};
  4. }
  5. /**
  6. * ReportPage constructor
  7. *
  8. * @param kwArgs.id [String] DOM node id
  9. * @param kwArgs.bgColor [String] Background color of the page
  10. * @param kwArgs.width [Int] Page content's width in pixels
  11. * @param kwArgs.height [Int] Page content's height in pixels
  12. * @param kwArgs.topMargin [Int] Top margin of report page in pixels
  13. * @param kwArgs.rightMargin [Int] Right margin of report page in pixels
  14. * @param kwArgs.bottomMargin [Int] Bottom margin of report page in pixels
  15. * @param kwArgs.leftMargin [Int] Left margin of report page in pixels
  16. */
  17. bobj.crv.ReportPage.DocumentView = {
  18. WEB_LAYOUT : 'weblayout',
  19. PRINT_LAYOUT: 'printlayout'
  20. };
  21. bobj.crv.newReportPage = function(kwArgs) {
  22. kwArgs = MochiKit.Base.update({
  23. id: bobj.uniqueId(),
  24. bgColor: '#FFFFFF',
  25. width: 720,
  26. height: 984,
  27. topMargin: 0,
  28. rightMargin: 0,
  29. leftMargin: 0,
  30. bottomMargin: 0,
  31. documentView: bobj.crv.ReportPage.DocumentView.PRINT_LAYOUT
  32. }, kwArgs);
  33. var o = newWidget(kwArgs.id);
  34. o.widgetType = 'ReportPage';
  35. // Update instance with constructor arguments
  36. bobj.fillIn(o, kwArgs);
  37. // Update instance with member functions
  38. o.initOld = o.init;
  39. o.resizeOld = o.resize;
  40. MochiKit.Base.update(o, bobj.crv.ReportPage);
  41. return o;
  42. };
  43. /**
  44. * Overrides parent. Sets the content of the report page.
  45. *
  46. * @param content [String|DOM Node] Html or Node to use as report page content
  47. */
  48. bobj.crv.ReportPage.setHTML = function (content) {
  49. var pageNode = this._pageNode;
  50. bobj.removeAllChildElements(pageNode);
  51. if (bobj.isString(content)) {
  52. pageNode.innerHTML = content;
  53. }
  54. else if (bobj.isObject(content)) {
  55. pageNode.appendChild(content);
  56. var contentStyle = content.style;
  57. contentStyle.display = 'block';
  58. contentStyle.visibility = 'visible';
  59. }
  60. };
  61. bobj.crv.ReportPage.update = function(update, updatePack) {
  62. if(update && update.cons == "bobj.crv.newReportPage") {
  63. this.updateSize({width: update.args.width,
  64. height: update.args.height,
  65. leftMargin: update.args.leftMargin,
  66. rightMargin: update.args.rightMargin,
  67. topMargin: update.args.topMargin,
  68. bottomMargin: update.args.bottomMargin});
  69. this.updateHTML(update.args.content);
  70. this.layer.scrollLeft = 0;
  71. this.layer.scrollTop =0;
  72. }
  73. };
  74. bobj.crv.ReportPage.loadContent = function()
  75. {
  76. if(this.content) {
  77. this.updateHTML(this.content);
  78. }
  79. }
  80. bobj.crv.ReportPage.updateHTML = function(content) {
  81. var cssID = this.id + '_stylesheet';
  82. var prevStyle = getLayer(cssID);
  83. var styleText = '';
  84. if(content) {
  85. var ext = bobj.html.extractHtml(content);
  86. var links = ext.links;
  87. for(var iLinks = 0, linksLen = links.length; iLinks < linksLen; ++iLinks){
  88. bobj.includeLink(links[iLinks]);
  89. }
  90. var styleText = "";
  91. for (var i = 0, len = ext.styles.length; i < len ; i++) {
  92. styleText += ext.styles[i].text + '\n';
  93. }
  94. if(prevStyle) {
  95. MochiKit.DOM.removeElement(prevStyle);
  96. }
  97. bobj.addStyleSheet(styleText, cssID);
  98. this.setHTML(ext.html);
  99. var scripts = ext.scripts;
  100. for (var iScripts = 0, scriptsLen = scripts.length; iScripts < scriptsLen; ++iScripts) {
  101. var script = scripts[iScripts];
  102. if (!script) {continue;}
  103. if (script.text) {
  104. try {
  105. bobj.evalInWindow(script.text);
  106. }
  107. catch(err) {}
  108. }
  109. }
  110. var divs = this._pageNode.getElementsByTagName("div");
  111. if(divs && divs[0]) {
  112. divs[0].style.position = "relative";
  113. divs[0].style.visibility = "visible";
  114. }
  115. }
  116. }
  117. /* Updates size of report page based on update object
  118. * @param update [{width,height,marginLeft,marginRight,marginTop}] dimension and margins of report p
  119. */
  120. bobj.crv.ReportPage.updateSize= function(sizeObject) {
  121. if(sizeObject) {
  122. this.width = (sizeObject.width != undefined) ? sizeObject.width : this.width;
  123. this.height = (sizeObject.height != undefined) ? sizeObject.height : this.height;
  124. this.leftMargin = (sizeObject.leftMargin != undefined) ? sizeObject.leftMargin : this.leftMargin;
  125. this.rightMargin = (sizeObject.rightMargin != undefined) ? sizeObject.rightMargin : this.rightMargin;
  126. this.topMargin = (sizeObject.topMargin != undefined) ? sizeObject.topMargin : this.topMargin;
  127. this.bottomMargin = (sizeObject.bottomMargin != undefined) ? sizeObject.bottomMargin : this.bottomMargin;
  128. }
  129. var isBorderBoxModel = bobj.isBorderBoxModel();
  130. var pageOuterHeight = this.height + this.topMargin + this.bottomMargin;
  131. var pageOuterWidth = this.width + this.leftMargin + this.rightMargin;
  132. var contentHeight = isBorderBoxModel ? pageOuterHeight : this.height;
  133. var contentWidth = isBorderBoxModel ? pageOuterWidth : this.width;
  134. if(this._pageCtnNode) {
  135. this._pageCtnNode.style.width = pageOuterWidth + 'px';
  136. this._pageCtnNode.style.height = pageOuterHeight + 'px';
  137. }
  138. if(this._pageNode) {
  139. this._pageNode.style.width = contentWidth + 'px';
  140. this._pageNode.style.height = contentHeight + 'px';
  141. this._pageNode.style.paddingTop = this.topMargin + 'px';
  142. this._pageNode.style.paddingRight = this.rightMargin + 'px';
  143. this._pageNode.style.paddingLeft = this.leftMargin + 'px';
  144. this._pageNode.style.paddingBottom = this.bottomMargin +'px';
  145. }
  146. if(this._shadowNode) {
  147. this._shadowNode.style.width = pageOuterWidth + 'px';
  148. this._shadowNode.style.height = pageOuterHeight + 'px';
  149. }
  150. }
  151. bobj.crv.ReportPage.getHTML = function () {
  152. var h = bobj.html;
  153. var isBorderBoxModel = bobj.isBorderBoxModel();
  154. var layerStyle = {
  155. width: '100%',
  156. height: '100%',
  157. overflow: 'auto',
  158. position: 'absolute'
  159. };
  160. var pageOuterHeight = this.height + this.topMargin + this.bottomMargin;
  161. var pageOuterWidth = this.width + this.leftMargin + this.rightMargin;
  162. var contentHeight = isBorderBoxModel ? pageOuterHeight : this.height;
  163. var contentWidth = isBorderBoxModel ? pageOuterWidth : this.width;
  164. var positionStyle = {
  165. left: '4px',
  166. width: pageOuterWidth + 'px',
  167. height: pageOuterHeight + 'px',
  168. 'text-align' : 'left',
  169. top: '4px',
  170. overflow: 'visible',
  171. position: 'relative'
  172. };
  173. if(_saf) {
  174. positionStyle['display'] = 'table';
  175. }
  176. var pageStyle = {
  177. position: 'relative',
  178. width: contentWidth + 'px',
  179. height: contentHeight + 'px',
  180. 'z-index': 1,
  181. 'border-width' : '1px',
  182. 'border-style' : 'solid',
  183. 'background-color': this.bgColor,
  184. 'padding-top': this.topMargin + 'px',
  185. 'padding-right': this.rightMargin + 'px',
  186. 'padding-left': this.leftMargin + 'px',
  187. 'padding-bottom': this.bottomMargin + 'px'
  188. };
  189. var shadowStyle = {
  190. position: 'absolute',
  191. filter: "progid:DXImageTransform.Microsoft.Blur(PixelRadius='2', MakeShadow='false', ShadowOpacity='0.75')",
  192. 'z-index': 0,
  193. width: pageOuterWidth + 'px',
  194. height: pageOuterHeight + 'px',
  195. margin: '0 auto',
  196. left: (isBorderBoxModel ? 2 : 6) + 'px',
  197. top: (isBorderBoxModel ? 2 : 6) + 'px'
  198. };
  199. var shadowHTML = '';
  200. if(this.documentView.toLowerCase() == bobj.crv.ReportPage.DocumentView.PRINT_LAYOUT) {
  201. layerStyle['background-color'] = '#8E8E8E';
  202. pageStyle['border-color'] = '#000000';
  203. shadowStyle['background-color'] = '#737373';
  204. shadowHTML = h.DIV({id : this.id + '_shadow', 'class': 'menuShadow', style:shadowStyle})
  205. // page should appear in the center for print layouts
  206. layerStyle['text-align'] = 'center'; // For page centering in IE quirks mode
  207. positionStyle['margin'] = '0 auto'; // center the page horizontally - CSS2
  208. }
  209. else {
  210. // Web Layout
  211. layerStyle['background-color'] = '#FFFFFF';
  212. pageStyle['border-color'] = '#FFFFFF';
  213. // page should appear in left for web layouts
  214. positionStyle['margin'] = '0';
  215. }
  216. var html = h.DIV({id: this.id, style: layerStyle, 'class' : 'insetBorder'},
  217. h.DIV({id: this.id + '_pageCtn', style:positionStyle},
  218. h.DIV({id:this.id + '_page', style:pageStyle}),
  219. shadowHTML ));
  220. return html + bobj.crv.getInitHTML(this.widx);
  221. };
  222. bobj.crv.ReportPage.init = function () {
  223. this._pageCtnNode = getLayer(this.id + '_pageCtn');
  224. this._pageNode = getLayer(this.id + '_page');
  225. this._shadowNode = getLayer(this.id + '_shadow');
  226. this.initOld();
  227. };
  228. /**
  229. * Resizes the outer dimensions of the widget.
  230. */
  231. bobj.crv.ReportPage.resize = function (w, h) {
  232. bobj.setOuterSize(this.layer, w, h);
  233. if(_moz) {
  234. this.css.clip = bobj.getRect(0,w,h,0);
  235. }
  236. };
  237. /**
  238. * @return Returns an object with width and height properties such that there
  239. * would be no scroll bars around the page if they were applied to the widget.
  240. */
  241. bobj.crv.ReportPage.getBestFitSize = function() {
  242. var page = this._pageNode;
  243. return {
  244. width: page.offsetWidth + 30,
  245. height: page.offsetHeight + 30
  246. };
  247. };