PinFreezeManager.js 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2013
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. * Control all pin and freeze headings in a report.
  14. */
  15. function PinFreezeManager(oCV) {
  16. this.m_oCV=oCV;
  17. this.m_viewerId=oCV.getId();
  18. this.m_frozenInfo = null;
  19. this.m_lastWidthProcessed=0;
  20. this.m_lastHeightProcessed=0;
  21. this.c_resizeTweekLimit=5; //Resizes smaller than this threshold will not be processed.
  22. this.m_repaintOnVisible=false; //If a canvas resize (or zoom) event happens, repaint the widget if it becomes visible.
  23. }
  24. /**
  25. * Add a new container object to the frozen container list.
  26. * If the list does not exist (no frozen containers), create the list.
  27. */
  28. PinFreezeManager.prototype.addContainerObject = function(lid, freezeTop, freezeSide, containerNode, index) {
  29. if (freezeTop || freezeSide) {
  30. if (!this.m_frozenInfo) {
  31. this.m_frozenInfo = {};
  32. }
  33. // Each lid can have multiple containers associated to it (report with sections for example)
  34. if (!this.m_frozenInfo[lid]) {
  35. this._createDefaultFrozenInfo(lid);
  36. }
  37. this.m_frozenInfo[lid].freezeTop = freezeTop;
  38. this.m_frozenInfo[lid].freezeSide = freezeSide;
  39. var oNewPinFreezeContainer = this.newContainer(lid, freezeTop, freezeSide, containerNode, index);
  40. this.m_frozenInfo[lid].pinFreezeContainers.push(oNewPinFreezeContainer);
  41. return oNewPinFreezeContainer;
  42. }
  43. return null;
  44. };
  45. /**
  46. * Wrapper function used to jsunit tests
  47. */
  48. PinFreezeManager.prototype.newContainer = function(lid, freezeTop, freezeSide, containerNode, index) {
  49. return new PinFreezeContainer(this, lid, this.m_viewerId, freezeTop, freezeSide, containerNode, index);
  50. };
  51. PinFreezeManager.prototype.clearPinInfo = function(lid) {
  52. if (!this.m_frozenInfo) {
  53. return;
  54. }
  55. if (lid) {
  56. if (this.m_frozenInfo[lid]) {
  57. delete this.m_frozenInfo[lid];
  58. }
  59. }
  60. else {
  61. delete this.m_frozenInfo;
  62. this.m_frozenInfo = null;
  63. }
  64. };
  65. PinFreezeManager.prototype._createDefaultFrozenInfo = function(lid) {
  66. this.m_frozenInfo[lid] = {
  67. "lid" : lid,
  68. "freezeTop" : false,
  69. "freezeSide" : false,
  70. "pinFreezeContainers" : [],
  71. "childContainers" : {}
  72. };
  73. };
  74. PinFreezeManager.prototype._resetFrozenInfo = function(lid) {
  75. var frozenInfo = this.m_frozenInfo[lid];
  76. if (frozenInfo) {
  77. delete frozenInfo.pinFreezeContainers;
  78. frozenInfo.pinFreezeContainers = [];
  79. frozenInfo.freezeTop = false;
  80. frozenInfo.freezeSide = false;
  81. }
  82. };
  83. /**
  84. * Find all the LIDs on the current page and add their information to the frozenInfo object. Also
  85. * keep track of a list of child LIDs in the case that we have nested containers
  86. */
  87. PinFreezeManager.prototype.prepopulateFrozenInfo = function(oReportDiv) {
  88. var containerNodes = getDescendantElementsByAttribute(oReportDiv, "table", "lid", "", false, -1, new RegExp("[\\s\\S]*"));
  89. if (containerNodes) {
  90. if (!this.m_frozenInfo) {
  91. this.m_frozenInfo = {};
  92. }
  93. for (var i=0; i < containerNodes.length; i++) {
  94. var containerNode = containerNodes[i];
  95. // The top parent table can't be frozen, so skip it
  96. if (containerNode.getAttribute("id") == "rt" + this.m_viewerId) {
  97. continue;
  98. }
  99. var lid = this.removeNamespace(containerNode.getAttribute("lid"));
  100. if (this.m_frozenInfo[lid] && this.m_frozenInfo[lid].childContainers) {
  101. continue;
  102. }
  103. if (!this.m_frozenInfo[lid]) {
  104. this._createDefaultFrozenInfo(lid);
  105. }
  106. if (!this.m_frozenInfo[lid].childContainers) {
  107. this.m_frozenInfo[lid].childContainers = {};
  108. }
  109. // We need to know the ID's of child containers to we can refreeze them when the parent is unfrozen/frozen
  110. var nestedChildContainers = getDescendantElementsByAttribute(containerNode, "table", "lid", "", false, -1, new RegExp("[\\s\\S]*"));
  111. if (nestedChildContainers) {
  112. for (var childIndex=0; childIndex < nestedChildContainers.length; childIndex++) {
  113. var childNode = nestedChildContainers[childIndex];
  114. var childLID = this.removeNamespace(childNode.getAttribute("lid"));
  115. if (!this.m_frozenInfo[lid].childContainers[childLID]) {
  116. // We only want direct descendant containers in this list.
  117. var parentNode = childNode.parentNode;
  118. while (parentNode && !parentNode.getAttribute("lid")) {
  119. parentNode = parentNode.parentNode;
  120. }
  121. if (parentNode && this.removeNamespace(parentNode.getAttribute("lid")) == lid) {
  122. this.m_frozenInfo[lid].childContainers[childLID] = true;
  123. }
  124. }
  125. }
  126. }
  127. }
  128. this._updateParentContainerInfo();
  129. }
  130. };
  131. /**
  132. * Now that we have the child containers, update the containers with parent info
  133. */
  134. PinFreezeManager.prototype._updateParentContainerInfo = function() {
  135. // update the parentInfo
  136. for (var containerLID in this.m_frozenInfo) {
  137. var childContainers = this.m_frozenInfo[containerLID].childContainers;
  138. if (childContainers) {
  139. for (var childLID in childContainers) {
  140. if (this.m_frozenInfo[childLID]) {
  141. this.m_frozenInfo[childLID].parentContainer = containerLID;
  142. break;
  143. }
  144. }
  145. }
  146. }
  147. };
  148. PinFreezeManager.prototype.getTopLevelContainerLID = function(lid) {
  149. if (this.m_frozenInfo[lid]) {
  150. while (this.m_frozenInfo[lid].parentContainer) {
  151. lid = this.m_frozenInfo[lid].parentContainer;
  152. }
  153. }
  154. return lid;
  155. };
  156. /**
  157. * Freeze the container having layoutID lid as specified by the booleans to freeze top/side or both.
  158. */
  159. PinFreezeManager.prototype.freezeContainer=function(lid, freezeTop, freezeSide) {
  160. var oReportDiv = document.getElementById("CVReport" + this.m_viewerId);
  161. this.prepopulateFrozenInfo(oReportDiv);
  162. var topLevelLID = this.getTopLevelContainerLID(lid);
  163. this.unfreezeAllNestedContainers(topLevelLID, oReportDiv);
  164. this.m_frozenInfo[lid].freezeTop = freezeTop;
  165. this.m_frozenInfo[lid].freezeSide = freezeSide;
  166. var oNewPinFreezeContainer = this._createPinAndFreezeObject(oReportDiv, topLevelLID);
  167. this.m_lastWidthProcessed=0;
  168. this.m_lastHeightProcessed=0;
  169. this._resizePinFreezeObjects(oNewPinFreezeContainer);
  170. this.sectionStructureChange();
  171. // force IE to repaint the div or the the RVContent div won't resize
  172. if (isIE()) {
  173. // When in IE we sometimes have 'left over' crosstabs. Call refresh in a setTimeout
  174. // so that we resynch our scrollbars correctly once the Pin & Freeze is done.
  175. var obj = this;
  176. setTimeout(function() {obj.refresh(); }, 1);
  177. var oRVContent = document.getElementById("RVContent" + this.m_viewerId);
  178. this.m_oCV.repaintDiv(oRVContent);
  179. }
  180. return oNewPinFreezeContainer;
  181. };
  182. /**
  183. * When not frozen (or freeze is changed), a widget may be extremely wide or tall because when the widget is rendered, it is fit to data contents.
  184. * To handle this case, when a user freezes the container (or changes how its frozen), we pick a "threshold" size for the content so that resize to
  185. * fit content will easily resize into the bounds of the document window. Afterward, a user may resize larger.
  186. */
  187. PinFreezeManager.prototype.getInitialWidthThreshold=function() {
  188. return document.body.clientWidth * 3 / 4;
  189. };
  190. PinFreezeManager.prototype.getInitialHeightThreshold=function() {
  191. return document.body.clientWidth * 9 / 10;
  192. };
  193. /**
  194. * Return true if there are any frozen containers.
  195. */
  196. PinFreezeManager.prototype.hasFrozenContainers = function() {
  197. return ((this.m_frozenInfo) ? true : false );
  198. };
  199. /**
  200. * return true if row headings are frozen in the passed lid
  201. */
  202. PinFreezeManager.prototype.hasFrozenRowHeadings = function(lid) {
  203. if (this.m_frozenInfo && this.m_frozenInfo[lid]) {
  204. return this.m_frozenInfo[lid].freezeSide ? this.m_frozenInfo[lid].freezeSide : false;
  205. }
  206. return false;
  207. };
  208. /**
  209. * return true if row headings are frozen in the passed lid
  210. */
  211. PinFreezeManager.prototype.hasFrozenColumnHeadings = function(lid) {
  212. if (this.m_frozenInfo && this.m_frozenInfo[lid]) {
  213. return this.m_frozenInfo[lid].freezeTop ? this.m_frozenInfo[lid].freezeTop : false;
  214. }
  215. return false;
  216. };
  217. /**
  218. * If this string is marked with a namespace, remove it.
  219. * If not, return the string.
  220. */
  221. PinFreezeManager.prototype.removeNamespace = function(idNS) {
  222. if (idNS.length > this.m_viewerId.length) {
  223. if (idNS.indexOf(this.m_viewerId) > 0) {
  224. return idNS.substring(0, idNS.indexOf(this.m_viewerId));
  225. }
  226. }
  227. return idNS; //The string does not have a namespace.
  228. };
  229. /**
  230. * Return the PinFreezeContainer JS Object with the specified lid.
  231. */
  232. PinFreezeManager.prototype.getContainer = function(lid, index) {
  233. if (this.m_frozenInfo && this.m_frozenInfo[lid] && this.m_frozenInfo[lid].pinFreezeContainers[0]) {
  234. index = index ? index : 0;
  235. return this.m_frozenInfo[lid].pinFreezeContainers[index];
  236. }
  237. return null;
  238. };
  239. /**
  240. * Return the PinFreezeContainer which contains the given node.
  241. */
  242. PinFreezeManager.prototype.nodeToContainer = function(node) {
  243. var slid = PinFreezeContainer.nodeToSlid(node);
  244. var container = null;
  245. if(slid) {
  246. var lid = this.removeNamespace(PinFreezeContainer.getLidFromSlid(slid));
  247. container = this.getContainer(lid);
  248. }
  249. return container;
  250. };
  251. /**
  252. * get the container element associated with the lid of the passed in layoutElement.
  253. * ie: The container that contains this layout element as its base container.
  254. */
  255. PinFreezeManager.prototype.getContainerElement = function(layoutElement) {
  256. var lid=this.removeNamespace(layoutElement.getAttribute("lid"));
  257. if (lid) {
  258. var container = this.getContainer(lid);
  259. if(container) {
  260. return container.getContainer();
  261. }
  262. }
  263. return null; //The container isn't frozen.
  264. };
  265. /**
  266. * Given an lid, will create pin and freeze objects for it and any child containers
  267. */
  268. PinFreezeManager.prototype._createPinAndFreezeObject = function(oReportDiv, lid) {
  269. var oNewPinFreezeContainer = null;
  270. if (this.m_frozenInfo) {
  271. var frozenInfo = this.m_frozenInfo[lid];
  272. // The only time we need to keep the old sizes is on the first load when we open a saved workspace.
  273. var initialLoad = frozenInfo.initialLoad;
  274. if (initialLoad) {
  275. delete frozenInfo.initialLoad;
  276. }
  277. var freezeTop = frozenInfo.freezeTop;
  278. var freezeSide = frozenInfo.freezeSide;
  279. var oldContainers = null;
  280. if (initialLoad && frozenInfo.pinFreezeContainers && (freezeTop || freezeSide)) {
  281. // Need to keep track of the frozen info
  282. oldContainers = frozenInfo.pinFreezeContainers.slice(0);
  283. }
  284. var mainParentNode = oReportDiv;
  285. // If we have nested containers, make sure we don't search through the 'cloned' parent nodes if the
  286. // parent is also frozen
  287. if (frozenInfo && frozenInfo.parentContainer) {
  288. var parentNodes = getElementsByAttribute(oReportDiv, "table", "lid", frozenInfo.parentContainer + this.m_viewerId);
  289. if (parentNodes) {
  290. for (parentIndex=0; parentIndex < parentNodes.length; parentIndex++) {
  291. if (!parentNodes[parentIndex].getAttribute("clonednode")) {
  292. mainParentNode = parentNodes[parentIndex];
  293. break;
  294. }
  295. }
  296. }
  297. }
  298. if (frozenInfo.childContainers) {
  299. for (var childLID in frozenInfo.childContainers) {
  300. var pinFreezeObject = this._createPinAndFreezeObject(mainParentNode, childLID);
  301. oNewPinFreezeContainer = oNewPinFreezeContainer ? oNewPinFreezeContainer : pinFreezeObject;
  302. }
  303. }
  304. var containerNodes = getElementsByAttribute(mainParentNode, "table", "lid", lid + this.m_viewerId);
  305. if (containerNodes && containerNodes.length > 0) {
  306. delete frozenInfo.pinFreezeContainers;
  307. frozenInfo.pinFreezeContainers = [];
  308. }
  309. else {
  310. // The container isn't on the current page
  311. return null;
  312. }
  313. if (containerNodes && (freezeTop || freezeSide)) {
  314. var frozenChild = (oNewPinFreezeContainer !== null);
  315. for (var i=0; i < containerNodes.length; i++) {
  316. var containerNode = containerNodes[i];
  317. if (containerNode.getAttribute("clonednode") == "true") {
  318. continue;
  319. }
  320. oNewPinFreezeContainer = this.addContainerObject(lid, freezeTop, freezeSide, containerNode, i);
  321. if (oNewPinFreezeContainer) {
  322. oNewPinFreezeContainer.createPFContainer(mainParentNode, frozenChild);
  323. if (initialLoad) {
  324. oNewPinFreezeContainer.copyProperties(oldContainers[0]);
  325. }
  326. oNewPinFreezeContainer.freezeContainerInReport(oReportDiv);
  327. }
  328. }
  329. }
  330. }
  331. return oNewPinFreezeContainer;
  332. };
  333. /**
  334. * Given a report dom, render the report with the containers frozen
  335. * as specified by the pinFreezeContainers list.
  336. */
  337. PinFreezeManager.prototype.renderReportWithFrozenContainers = function(oReportDiv) {
  338. if (this.m_frozenInfo) {
  339. var initialLoad = false;
  340. var oNewPinFreezeContainer = null;
  341. for (var pinFreezeContainerID in this.m_frozenInfo) {
  342. var frozenInfo = this.m_frozenInfo[pinFreezeContainerID];
  343. if (!initialLoad) {
  344. initialLoad = frozenInfo.initialLoad;
  345. }
  346. if (!frozenInfo.parentContainer) {
  347. var temp = this._createPinAndFreezeObject(oReportDiv, frozenInfo.lid);
  348. oNewPinFreezeContainer = oNewPinFreezeContainer ? oNewPinFreezeContainer : temp;
  349. }
  350. }
  351. if (!initialLoad && oNewPinFreezeContainer) {
  352. this._resizePinFreezeObjects(oNewPinFreezeContainer);
  353. }
  354. // With nested containers, we'd sometimes get our of synch with our scrollbars after loading a workspace. Do a quick refresh
  355. // to make sure our scrollbars are correct
  356. this.refresh();
  357. }
  358. };
  359. PinFreezeManager.prototype._resizePinFreezeObjects = function(oNewPinFreezeContainer) {
  360. var height, width;
  361. var widget = this.m_oCV.getViewerWidget();
  362. if (widget) {
  363. //Set an initial freeze size that's close to the widget client size unless it exceeds the "initial width/height threshold".
  364. var size = widget.getWidgetSize();
  365. width = (size && size.w && (size.w < this.getInitialWidthThreshold())) ? size.w : oNewPinFreezeContainer.getClientWidth();
  366. height= (size && size.h && (size.h < this.getInitialHeightThreshold())) ? size.h : oNewPinFreezeContainer.getClientHeight();
  367. }
  368. else {
  369. var oRVContent = document.getElementById("RVContent" + this.m_viewerId);
  370. var mainViewerTable = document.getElementById("mainViewerTable" + this.m_viewerId);
  371. width = oRVContent.clientWidth;
  372. height = mainViewerTable.clientHeight;
  373. }
  374. this.m_lastWidthProcessed=0;
  375. this.m_lastHeightProcessed=0;
  376. this.resize(width, height);
  377. };
  378. /**
  379. * Adjust the size of all frozen containers based on the passed in width and height according to these defaulting rules.
  380. * 1) Normally, containers are sized such that the "frozen dimension(s)" of any container fits the visible width/height of the widget.
  381. * 2) Small size changes (< "resizeTweekLimit" pixels in either dimension) will not result in a resize of the containers.
  382. * 3) Size changes in one axis only keeps the opposite axis "as is" (minimizes effect on layout for multi-container reports)
  383. * 4) Resize events related to "resize to fit content" do not change the size of containers.
  384. */
  385. PinFreezeManager.prototype.resize = function(width, height) {
  386. var widthDimensionTweeked=(Math.abs(width-this.m_lastWidthProcessed) < this.c_resizeTweekLimit);
  387. var heightDimensionTweeked=(Math.abs(height-this.m_lastHeightProcessed) < this.c_resizeTweekLimit);
  388. if (widthDimensionTweeked && heightDimensionTweeked) {
  389. //Don't process size changes when they're just small "tweeks"...the user is likely adjusting for scrollbars.
  390. return;
  391. }
  392. //Only process changes to the dimension that changed size.
  393. //If the height changed, dont change the width and vice versa.
  394. var newWidth=(Math.abs(width-this.m_lastWidthProcessed) > 2) ? width : 0;
  395. var newHeight=(Math.abs(height-this.m_lastHeightProcessed) > 2) ? height : 0;
  396. for (var lid in this.m_frozenInfo) {
  397. if (!this.m_frozenInfo[lid].parentContainer) {
  398. this.resizeContainer(lid, newWidth, newHeight);
  399. }
  400. }
  401. this.m_lastWidthProcessed=width;
  402. this.m_lastHeightProcessed=height;
  403. };
  404. PinFreezeManager.prototype.resizeContainer = function(lid, width, height) {
  405. var frozenInfo = this.m_frozenInfo[lid];
  406. if (frozenInfo) {
  407. var childContainerInfo = null;
  408. if (frozenInfo.childContainers) {
  409. var childWidth = width > 10 ? width - 10 : width;
  410. var childHeight = height > 10 ? height - 10 : height;
  411. for (var childLID in frozenInfo.childContainers) {
  412. childContainerInfo = this.resizeContainer(childLID, childWidth, childHeight);
  413. }
  414. }
  415. var oPinFreezeContainers = frozenInfo.pinFreezeContainers;
  416. var pinAndFreezeContainer = null;
  417. var widestContainerInfo = null;
  418. if (oPinFreezeContainers) {
  419. for (var i=0; i < oPinFreezeContainers.length; i++) {
  420. pinAndFreezeContainer = oPinFreezeContainers[i];
  421. pinAndFreezeContainer.resize(width, height, frozenInfo.parentContainer, childContainerInfo);
  422. var container = pinAndFreezeContainer.getContainer();
  423. if (container && (!widestContainerInfo || (widestContainerInfo.width < container.clientWidth))) {
  424. widestContainerInfo = {
  425. "width" : container.clientWidth,
  426. "lid" : pinAndFreezeContainer.m_lidNS
  427. };
  428. }
  429. }
  430. }
  431. return widestContainerInfo;
  432. }
  433. };
  434. /**
  435. * When an autoResize occurs, we don't resize anything but we do need to track the size
  436. * for subsequent resizes to work properly (ie: detect height or width hasn't changed).
  437. */
  438. PinFreezeManager.prototype.processAutoResize = function(width, height) {
  439. this.m_lastWidthProcessed = width;
  440. this.m_lastHeightProcessed = height;
  441. };
  442. /**
  443. * When the widget becomes visible, do a lightweight refresh.
  444. * If the canvas was resized, repaintOnVisible is set to true...repaint.
  445. */
  446. PinFreezeManager.prototype.onSetVisible = function() {
  447. this.refresh();
  448. if (this.m_repaintOnVisible) {
  449. this.rePaint();
  450. this.m_repaintOnVisible=false;
  451. }
  452. };
  453. PinFreezeManager.prototype.onResizeCanvas = function(isVisible) {
  454. if (isVisible) {
  455. this.rePaint();
  456. } else {
  457. this.m_repaintOnVisible=true;
  458. }
  459. };
  460. PinFreezeManager.prototype.rePaint = function() {
  461. for (var lid in this.m_frozenInfo) {
  462. if (!this.m_frozenInfo[lid].parentContainer) {
  463. this.resizeContainer(lid, this.m_lastWidthProcessed, this.m_lastHeightProcessed);
  464. }
  465. }
  466. };
  467. /**
  468. * Lightweight refresh - check properties which may have been corrupted
  469. */
  470. PinFreezeManager.prototype.refresh = function() {
  471. for (var pinFreezeContainerID in this.m_frozenInfo) {
  472. var oPinFreezeContainers = this.m_frozenInfo[pinFreezeContainerID].pinFreezeContainers;
  473. if (oPinFreezeContainers) {
  474. for (var i=0; i < oPinFreezeContainers.length; i++) {
  475. var oPinFreezeContainer = oPinFreezeContainers[i];
  476. oPinFreezeContainer.synchScroll();
  477. oPinFreezeContainer.synchVScroll();
  478. }
  479. }
  480. }
  481. };
  482. /**
  483. * Freeze the row headings for the specified container. The state of the column
  484. * headings is unchanged (ie: if it was frozen before, it is still frozen)
  485. */
  486. PinFreezeManager.prototype.freezeContainerRowHeadings = function(lid) {
  487. return this.freezeContainer(lid, /*top*/this.hasFrozenColumnHeadings(lid), /*side*/true);
  488. };
  489. /**
  490. * Freeze the row headings that are selected.
  491. * headings is unchanged (ie: if it was frozen before, it is still frozen)
  492. */
  493. PinFreezeManager.prototype.freezeSelectedRowHeadings = function() {
  494. var lid=this.getValidSelectedContainerId(/*freezeTop*/false);
  495. if (lid) {
  496. this.m_oCV.getSelectionController().resetSelections();
  497. return this.freezeContainerRowHeadings(lid);
  498. }
  499. return null;
  500. };
  501. PinFreezeManager.prototype.canFreezeSelectedRowHeadings = function() {
  502. var lid=this.getValidSelectedContainerId(/*freezeTop*/false);
  503. if (lid) {
  504. return (!this.hasFrozenRowHeadings(lid));
  505. }
  506. return false;
  507. };
  508. /**
  509. * Unfreeze the row headings for the specified container. The state of the column
  510. * headings is unchanged (ie: if it was frozen before, it is still frozen,
  511. * if not, the container is now totally unfrozen)
  512. */
  513. PinFreezeManager.prototype.unfreezeContainerRowHeadings = function(lid) {
  514. this.freezeContainer(lid, /*top*/this.hasFrozenColumnHeadings(lid), /*side*/false);
  515. };
  516. /**
  517. * Freeze the row headings that are selected.
  518. * headings is unchanged (ie: if it was frozen before, it is still frozen)
  519. */
  520. PinFreezeManager.prototype.unfreezeSelectedRowHeadings = function() {
  521. var lid=this.getValidSelectedContainerId(/*freezeTop*/false);
  522. if (lid) {
  523. this.m_oCV.getSelectionController().resetSelections();
  524. this.unfreezeContainerRowHeadings(lid);
  525. }
  526. };
  527. PinFreezeManager.prototype.canUnfreezeSelectedRowHeadings = function() {
  528. var lid=this.getValidSelectedContainerId(/*freezeTop*/false);
  529. if (lid) {
  530. return (this.hasFrozenRowHeadings(lid));
  531. }
  532. return false;
  533. };
  534. /**
  535. * Freeze the column headings for the specified container. The state of the row
  536. * headings is unchanged (ie: if it was frozen before, it is still frozen)
  537. */
  538. PinFreezeManager.prototype.freezeContainerColumnHeadings = function(lid) {
  539. return this.freezeContainer(lid, /*top*/true, /*side*/this.hasFrozenRowHeadings(lid));
  540. };
  541. /**
  542. * Freeze the selected headings that are selected.
  543. * headings is unchanged (ie: if it was frozen before, it is still frozen)
  544. */
  545. PinFreezeManager.prototype.freezeSelectedColumnHeadings = function() {
  546. var lid=this.getValidSelectedContainerId(/*freezeTop*/true);
  547. if (lid) {
  548. this.m_oCV.getSelectionController().resetSelections();
  549. return this.freezeContainerColumnHeadings(lid);
  550. }
  551. return null;
  552. };
  553. PinFreezeManager.prototype.canFreezeSelectedColumnHeadings = function() {
  554. var lid=this.getValidSelectedContainerId(/*freezeTop*/true);
  555. if (lid) {
  556. return (!this.hasFrozenColumnHeadings(lid));
  557. }
  558. return false;
  559. };
  560. /**
  561. * Unfreeze the column headings for the specified container. The state of the row
  562. * headings is unchanged (ie: if it was frozen before, it is still frozen,
  563. * if not, the container is now totally unfrozen)
  564. */
  565. PinFreezeManager.prototype.unfreezeContainerColumnHeadings = function(lid) {
  566. this.freezeContainer(lid, /*top*/false, /*side*/this.hasFrozenRowHeadings(lid));
  567. };
  568. /**
  569. * Freeze the selected headings that are selected.
  570. * headings is unchanged (ie: if it was frozen before, it is still frozen)
  571. */
  572. PinFreezeManager.prototype.unfreezeSelectedColumnHeadings = function() {
  573. var lid=this.getValidSelectedContainerId(/*freezeTop*/true);
  574. if (lid) {
  575. this.m_oCV.getSelectionController().resetSelections();
  576. this.unfreezeContainerColumnHeadings(lid);
  577. }
  578. };
  579. PinFreezeManager.prototype.canUnfreezeSelectedColumnHeadings = function() {
  580. var lid=this.getValidSelectedContainerId(/*freezeTop*/true);
  581. if (lid) {
  582. return (this.hasFrozenColumnHeadings(lid));
  583. }
  584. return false;
  585. };
  586. /**
  587. * Given a cognos viewer object, return the id of the selected container
  588. * if it meets the rules for freezing containers
  589. * (ie: crosstabs only for side headings, crosstabs or lists for top headings).
  590. */
  591. PinFreezeManager.prototype.getValidSelectedContainerId = function(freezeTopRule)
  592. {
  593. var selectedObjects = this.m_oCV.getSelectionController().getAllSelectedObjects();
  594. if (selectedObjects && selectedObjects.length &&
  595. (selectedObjects[0].getDataContainerType() === "crosstab" ||
  596. (freezeTopRule && selectedObjects[0].getDataContainerType() === "list"))) {
  597. var lid=(selectedObjects[0].getLayoutElementId());
  598. if (lid) {
  599. if(!this.hasPromptControlsInFreezableCells(lid)) {
  600. return this.removeNamespace(lid);
  601. }
  602. }
  603. }
  604. return null;
  605. };
  606. PinFreezeManager.prototype.hasPromptControlsInFreezableCells = function(lid) {
  607. var layoutElement = this.m_oCV.getLayoutElementFromLid(lid);
  608. var potentiallyFrozen = getElementsByAttribute(layoutElement, ["td","th"], "type", "columnTitle");
  609. //This regex finds class attributes which contain the property 'clsPromptComponent',
  610. var promptClass = new RegExp("(^|[\W])clsPromptComponent($|[\W])");
  611. var attributeName = isIE() ? "className" : "class";
  612. for(var j in potentiallyFrozen) {
  613. if (potentiallyFrozen.hasOwnProperty(j)){
  614. var prompts = getElementsByAttribute(potentiallyFrozen[j], "*", attributeName, null, 1, promptClass);
  615. if(prompts.length > 0) {
  616. return true;
  617. }
  618. }
  619. }
  620. return false;
  621. };
  622. /**
  623. * Given the html for a report, completely unfreeze the container with the matching lid
  624. */
  625. PinFreezeManager.prototype.unfreeze = function(lid, oReportDiv, reset) {
  626. if (this.m_frozenInfo && this.m_frozenInfo[lid]) {
  627. var oPinFreezeContainers = this.m_frozenInfo[lid].pinFreezeContainers;
  628. if (oPinFreezeContainers) {
  629. for (var i=0; i < oPinFreezeContainers.length; i++) {
  630. var oPinFreezeContainer = oPinFreezeContainers[i];
  631. oPinFreezeContainer.unfreeze(oReportDiv);
  632. }
  633. if (reset) {
  634. this._resetFrozenInfo(lid);
  635. }
  636. }
  637. }
  638. };
  639. /**
  640. * Given an LID, unfreeze every child container
  641. */
  642. PinFreezeManager.prototype.unfreezeAllNestedContainers = function(lid, oReportDiv) {
  643. var frozenInfo = this.m_frozenInfo[lid];
  644. if (frozenInfo) {
  645. if (frozenInfo.freezeTop || frozenInfo.freezeSide) {
  646. this.unfreeze(lid, oReportDiv, false);
  647. }
  648. if (frozenInfo.childContainers) {
  649. for (var childLID in frozenInfo.childContainers) {
  650. this.unfreezeAllNestedContainers(childLID, oReportDiv);
  651. }
  652. }
  653. }
  654. };
  655. /**
  656. * Returns true if the HTML Node is currently seen by the user.
  657. * This accounts for hidden pieces of the DOM, or nodes which will always
  658. * be scrolled out of view of the user.
  659. */
  660. PinFreezeManager.prototype.isNodeVisible = function(node) {
  661. var slid = PinFreezeContainer.nodeToSlid(node);
  662. if(!slid) {
  663. return true;
  664. }
  665. var lid = this.removeNamespace(PinFreezeContainer.getLidFromSlid(slid)) ;
  666. var container = this.getContainer(lid);
  667. if(!container) {
  668. return true;
  669. }
  670. var sectionName = PinFreezeContainer.getSectionNameFromSlid(slid);
  671. var section = container.getSection(sectionName);
  672. var refToMain = null, refToCopy = null;
  673. var nodeI = node;
  674. var refSrc = null;
  675. //Search for main/copy pointers.
  676. while(nodeI && nodeI !== section && !refToMain && !refToCopy) {
  677. refToMain = container.getMain(nodeI);
  678. refToCopy = container.getCopy(nodeI);
  679. refSrc = nodeI;
  680. nodeI = nodeI.parentNode;
  681. }
  682. var isCopy = refToMain ? true : false;
  683. var isMainAndHasCopy = refToCopy ? true : false;
  684. if(isCopy) {
  685. //The node is visible iff the container computes
  686. //its visible version to be the node.
  687. return container.getCopy(refToMain) === refSrc;
  688. } else if(isMainAndHasCopy) {
  689. //The node is visible iff the section its copy is in is not visible.
  690. //(Note: this node may indeed be considered by the browser to be
  691. //visible, but if its copy is currently visible, our code will
  692. //always keep it scrolled out of sight).
  693. return container.getCopy(refSrc) ? false : true;
  694. } else { //i.e. is in main and has no copy
  695. //Since there is no copy of this node, it should be visible.
  696. return true;
  697. }
  698. };
  699. /**
  700. * Invoke this method when there is a change in the structure of
  701. * the pin and freeze sections to handle necessary changes in the
  702. * Viewer.
  703. */
  704. PinFreezeManager.prototype.sectionStructureChange = function() {
  705. var widget = this.m_oCV.getViewerWidget();
  706. if(widget && widget.getAnnotationHelper()) {
  707. widget.getAnnotationHelper().repositionCommentIndicators();
  708. }
  709. };
  710. /**
  711. * Perform a deep clone, but exclude any dojo dijits - they
  712. * are not meant to be cloned, and need to special handling.
  713. */
  714. PinFreezeManager.prototype.deepCloneNode = function(original) {
  715. var copy = original.cloneNode(true);
  716. var widget = this.m_oCV.getViewerWidget();
  717. if(widget) {
  718. if(widget.reportContainsDijits()) {
  719. var dijits = getElementsByAttribute(copy, "*", "widgetid", "*");
  720. if(dijits && dijits.length) {
  721. for(var i = 0; i < dijits.length; i++) {
  722. dijits[i].parentNode.removeChild(dijits[i]);
  723. }
  724. }
  725. }
  726. }
  727. return copy;
  728. };
  729. /**
  730. * Called when saving the dashboard. This function will serialize all the information
  731. * needed to correctly reload the dashboard with frozen containers
  732. */
  733. PinFreezeManager.prototype.toJSONString = function() {
  734. var sContainers = '';
  735. var sResponse = '';
  736. for (var pinFreezeContainerID in this.m_frozenInfo) {
  737. if (sContainers.length > 0) {
  738. sContainers += ',';
  739. }
  740. var frozenInfo = this.m_frozenInfo[pinFreezeContainerID];
  741. sContainers += '{';
  742. sContainers += '"lid":"' + frozenInfo.lid.replace('"', '\\"') + '",';
  743. sContainers += '"freezeTop":' + frozenInfo.freezeTop + ',';
  744. sContainers += '"freezeSide":' + frozenInfo.freezeSide + ',';
  745. if (frozenInfo.parentContainer) {
  746. sContainers += '"parentContainer":"' + frozenInfo.parentContainer + '",';
  747. }
  748. if (frozenInfo.pinFreezeContainers && frozenInfo.pinFreezeContainers.length > 0) {
  749. sContainers += '"properties":' + frozenInfo.pinFreezeContainers[0].toJSONString() + ',';
  750. }
  751. sContainers += '"childContainers": {';
  752. if (frozenInfo.childContainers) {
  753. var first = true;
  754. for (var childLID in frozenInfo.childContainers) {
  755. if (!first) {
  756. sContainers += ',';
  757. }
  758. sContainers += '"' + childLID + '":true';
  759. first = false;
  760. }
  761. }
  762. sContainers += '}}';
  763. }
  764. if (sContainers.length > 0) {
  765. // VERSION INFO
  766. // * no version info is initial implementation
  767. // * 1 is when we added nested container support.
  768. sResponse = '{"version":1, "containers":[' + sContainers + ']}';
  769. }
  770. return sResponse;
  771. };
  772. /**
  773. * Called on dashboard open
  774. */
  775. PinFreezeManager.prototype.fromJSONString = function(sJSON) {
  776. if (!sJSON || sJSON.length === 0) {
  777. return;
  778. }
  779. var oJSON = null;
  780. try {
  781. oJSON = eval("(" + sJSON + ")");
  782. }
  783. catch (e) {
  784. if(typeof console != "undefined") {
  785. console.log("PinFreezeManager.prototype.fromJSON could not parse JSON - " + sJSON);
  786. console.log(e);
  787. }
  788. }
  789. if (!oJSON) {
  790. return;
  791. }
  792. var aContainers = oJSON.containers;
  793. var version = oJSON.version;
  794. if (aContainers.length > 0) {
  795. this.m_frozenInfo = {};
  796. }
  797. for (var iIndex=0; iIndex < aContainers.length; iIndex++) {
  798. var frozenInfo = aContainers[iIndex];
  799. var lid = frozenInfo.lid;
  800. var freezeTop = frozenInfo.freezeTop;
  801. var freezeSide = frozenInfo.freezeSide;
  802. var oReportDiv = document.getElementById("CVReport" + this.m_viewerId);
  803. var containerNodes = getElementsByAttribute(oReportDiv, "table", "lid", lid + this.m_viewerId);
  804. var pinFreezeContainers = [];
  805. if (containerNodes && (freezeTop || freezeSide)) {
  806. for (var i=0; i < containerNodes.length; i++) {
  807. var containerNode = containerNodes[i];
  808. var oNewPinFreezeContainer = new PinFreezeContainer(this, lid, this.m_viewerId, frozenInfo.freezeTop, frozenInfo.freezeSide, containerNode, i);
  809. if (frozenInfo.properties) {
  810. applyJSONProperties(oNewPinFreezeContainer, frozenInfo.properties);
  811. }
  812. pinFreezeContainers.push(oNewPinFreezeContainer);
  813. }
  814. }
  815. this.m_frozenInfo[lid] = {
  816. "lid" : lid,
  817. "freezeTop" : freezeTop,
  818. "freezeSide" : freezeSide,
  819. "pinFreezeContainers" : pinFreezeContainers,
  820. "initialLoad" : true
  821. };
  822. if (version >= 1) {
  823. if (frozenInfo.childContainers) {
  824. this.m_frozenInfo[lid].childContainers = frozenInfo.childContainers;
  825. }
  826. if (frozenInfo.parentContainer) {
  827. this.m_frozenInfo[lid].parentContainer = frozenInfo.parentContainer;
  828. }
  829. }
  830. }
  831. };
  832. /**
  833. * Remove id attributes on the element passes and its children
  834. */
  835. PinFreezeManager.prototype.removeIdAttribute = function(element) {
  836. // IE8 or eailer versions do not support 'hasAttribute' function. So use this logic.
  837. var idValue = element.getAttribute("id");
  838. if (idValue !== null && idValue !== "") {
  839. element.removeAttribute("id");
  840. }
  841. var elements = getElementsByAttribute(element, "*", "id", "*");
  842. if(elements && elements.length) {
  843. for(var i = 0; i < elements.length; i++) {
  844. elements[i].removeAttribute("id");
  845. }
  846. }
  847. return element;
  848. };
  849. PinFreezeManager.prototype.isElementInMainOutput = function(element) {
  850. return PinFreezeContainer.isElementInMainOutput(element);
  851. };
  852. PinFreezeManager.prototype.isIWidgetMobile = function() {
  853. return (this.m_oCV && this.m_oCV.isIWidgetMobile());
  854. };
  855. PinFreezeManager.prototype.destroy = function() {
  856. GUtil.destroyProperties(this);
  857. };