DragDropControllerIE5.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** BI and PM: qs
  5. **
  6. ** (C) Copyright IBM Corp. 2001, 2015
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or
  9. ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *****************************************************************/
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All Rights Reserved.
  12. // Cognos and the Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated) in the United States and/or other countries. IBM and the IBM logo are trademarks of International Business Machines Corporation in the United States, or other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
  13. function DragDropController()
  14. {
  15. this.m_xtabHorizDropZone = null;
  16. this.m_xtabVertDropZone = null;
  17. this.m_xtabCornerDropZone = null;
  18. this.m_lastSectionDropZone = null;
  19. this.m_ddi = null;
  20. var rfDoc = getReportFrameDoc();
  21. if (rfDoc == null)
  22. return;
  23. this.m_xtabHorizDropZone = new DragDropZone(rfDoc.getElementById("xtabHorizDropZone"), HORIZONTAL_ZONE, 0, 0);
  24. this.m_xtabVertDropZone = new DragDropZone(rfDoc.getElementById("xtabVertDropZone"), VERTICAL_ZONE, 0, 0);
  25. this.m_xtabCornerDropZone = new DragDropZone(rfDoc.getElementById("xtabCornerDropZone"), VERTICAL_ZONE, 6, 0);
  26. this.m_lastSectionDropZone = new DragDropZone(rfDoc.getElementById("lastSectionDropZone"), HORIZONTAL_ZONE, 0, 6);
  27. this.m_ddi = new DragDropIndicator(rfDoc.getElementById("dragDropIndicator"));
  28. };
  29. function DragDropController_getDragDropZoneIds()
  30. {
  31. var idArray = new Array();
  32. try
  33. {
  34. if (goApplicationManager.getMiniQueryManager().hasPivottedColumns())
  35. {
  36. if (this.m_xtabHorizDropZone.getElement() != null)
  37. idArray[idArray.length] = this.m_xtabHorizDropZone.getElement().id;
  38. if (this.m_xtabVertDropZone.getElement() != null)
  39. idArray[idArray.length] = this.m_xtabVertDropZone.getElement().id;
  40. if (this.m_xtabCornerDropZone.getElement() != null)
  41. idArray[idArray.length] = this.m_xtabCornerDropZone.getElement().id;
  42. }
  43. if (this.m_lastSectionDropZone.getElement() != null && this.m_lastSectionDropZone.getElement().style.display == "inline")
  44. {
  45. idArray[idArray.length] = this.m_lastSectionDropZone.getElement().id;
  46. }
  47. }
  48. catch (e)
  49. {
  50. }
  51. return idArray;
  52. };
  53. function DragDropController_dragStart()
  54. {
  55. if (goApplicationManager.getMiniQueryManager().hasPivottedColumns())
  56. {
  57. this.dragStartCrosstab(null);
  58. this.dragStartCornerDropZone(null);
  59. }
  60. this.dragStartSection(null)
  61. };
  62. function DragDropController_dragStartCrosstab(srcElem)
  63. {
  64. var oMQMgr = goApplicationManager.getMiniQueryManager();
  65. var rfDoc = getReportFrameDoc();
  66. if (rfDoc == null)
  67. return;
  68. var reportCells = rfDoc.getElementsByTagName("TD");
  69. var el = srcElem, left = 0, width = 0, top = 0, height = 0;
  70. var lastPivotColIndex = null, lastPivotColId = null;
  71. var numPivots = 0;
  72. for (var i=0; i < oMQMgr.getAllColumns().length; i++)
  73. {
  74. if (oMQMgr.isPivoted(i))
  75. {
  76. lastPivotColIndex = i;
  77. numPivots++;
  78. }
  79. }
  80. var numMeasures = oMQMgr.getElementsByAttribute("usage", USAGE_VALUE_MEASURE).length;
  81. if (lastPivotColIndex != null) {
  82. lastPivotColId = oMQMgr.getTag(lastPivotColIndex);
  83. el = getFirstElementWithTag(reportCells, el, lastPivotColId);
  84. if (el == null) return;
  85. var row = el.parentNode;
  86. var lastCellIndex = row.cells.length - 1 - ((numPivots > 1 || numMeasures == 0 || !reLevelFooter.test(row.cells[row.cells.length-1].className)) ? 0 : 1)
  87. for (i = el.cellIndex; i <= lastCellIndex; i++)
  88. {
  89. width += row.cells[i].offsetWidth;
  90. }
  91. top += el.offsetHeight - 4;
  92. while (el != null)
  93. {
  94. if (el.tagName != "TR" && typeof el.offsetLeft=="number")
  95. left += el.offsetLeft;
  96. if (el.tagName != "TR" && typeof el.offsetTop=="number")
  97. top += el.offsetTop;
  98. el = el.parentNode;
  99. }
  100. if (this.m_xtabHorizDropZone != null)
  101. this.m_xtabHorizDropZone.setStyle(14, width, top, left, "inline");
  102. }
  103. top = 0;
  104. left = 0;
  105. el = srcElem;
  106. var lastNonMeasure = null;
  107. for (var i=0; i < oMQMgr.getAllColumns().length; i++) {
  108. if ( !oMQMgr.isMeasure(i) && (oMQMgr.getColumnRole(i) === MINI_QUERY_NONE_STR || oMQMgr.getColumnRole(i) === MINI_QUERY_GROUP_LIST) )
  109. lastNonMeasure = i;
  110. }
  111. if (lastNonMeasure != null)
  112. {
  113. lastNonMeasure = oMQMgr.getTag(lastNonMeasure);
  114. el = getFirstElementWithTag(reportCells, el, lastNonMeasure);
  115. if (el == null) return;
  116. var rows = el.parentNode.parentNode.rows;
  117. var cellIndex = el.cellIndex;
  118. var ci = cellIndex;
  119. for (i = numPivots; i < rows.length; i++)
  120. {
  121. if (!reLevelFooter.test(rows[i].cells[ci].className))
  122. {
  123. if (rows[i].cells[ci].getAttribute("tag") == lastNonMeasure)
  124. {
  125. height += rows[i].cells[ci].offsetHeight;
  126. }
  127. else
  128. {
  129. ci = cellIndex;
  130. while (ci >= 0 && rows[i].cells[ci].getAttribute("tag") != lastNonMeasure)
  131. ci--;
  132. if (ci < 0)
  133. {
  134. if (rows[i].cells[0].colSpan > 1)
  135. height += rows[i].cells[0].offsetHeight;
  136. ci = cellIndex;
  137. }
  138. else
  139. height += rows[i].cells[ci].offsetHeight;
  140. }
  141. }
  142. }
  143. left += el.offsetWidth - 4;
  144. while (el != null)
  145. {
  146. if (el.tagName != "TR" && typeof el.offsetLeft=="number")
  147. left += el.offsetLeft;
  148. if (el.tagName != "TR" && typeof el.offsetTop=="number")
  149. top += el.offsetTop;
  150. el = el.parentNode;
  151. }
  152. if (this.m_xtabVertDropZone)
  153. this.m_xtabVertDropZone.setStyle(height, 14, top, left, "inline");
  154. }
  155. };
  156. function DragDropController_dragStartCornerDropZone(cornerElem)
  157. {
  158. var oMQMgr = goApplicationManager.getMiniQueryManager();
  159. var top = 0;
  160. var left = 0;
  161. var height = 0;
  162. var width = 0;
  163. el = cornerElem;
  164. var numCols = oMQMgr.getAllColumns().length;
  165. var numMeasures = oMQMgr.getElementsByAttribute("usage", USAGE_VALUE_MEASURE).length;
  166. if (numMeasures == 1)
  167. {
  168. var rfDoc = getReportFrameDoc();
  169. if (rfDoc == null)
  170. return;
  171. if (el == null)
  172. {
  173. var reportCells = rfDoc.getElementsByTagName("TD");
  174. for (var i = 0; i < reportCells.length; i++)
  175. {
  176. if (reCrosstabCorner.test(reportCells[i].className))
  177. {
  178. el = reportCells[i];
  179. height = el.offsetHeight;
  180. break;
  181. }
  182. }
  183. if (el == null) return;
  184. }
  185. else
  186. {
  187. height = el.offsetHeight;
  188. }
  189. left += el.offsetWidth - 10;
  190. while (el != null)
  191. {
  192. if (el.tagName != "TR" && typeof el.offsetLeft=="number")
  193. left += el.offsetLeft;
  194. if (el.tagName != "TR" && typeof el.offsetTop=="number")
  195. top += el.offsetTop;
  196. el = el.parentNode;
  197. }
  198. if (this.m_xtabCornerDropZone != null)
  199. this.m_xtabCornerDropZone.setStyle(height, 20, top, left, "inline");
  200. }
  201. };
  202. function DragDropController_dragStartSection(srcElem)
  203. {
  204. var oMQMgr = goApplicationManager.getMiniQueryManager();
  205. var rfDoc = getReportFrameDoc();
  206. if (rfDoc == null)
  207. return;
  208. var el = srcElem, left = 0, width = 0, top = 0, height = 0;
  209. var lastSection = null;
  210. for (var i = 0; i < oMQMgr.getAllColumns().length; i++)
  211. {
  212. if (oMQMgr.getColumnRole(i) === MINI_QUERY_GROUP_SECTION)
  213. {
  214. lastSection = i;
  215. }
  216. }
  217. if (lastSection != null)
  218. {
  219. lastSection = oMQMgr.getTag(lastSection);
  220. if (el == null)
  221. {
  222. var reportCells = rfDoc.getElementsByTagName("TD");
  223. for (var i = 0; i < reportCells.length; i++)
  224. {
  225. if (reSectionHeader.test(reportCells[i].className) && reportCells[i].getAttribute("tag") == lastSection)
  226. {
  227. el = reportCells[i];
  228. break;
  229. }
  230. }
  231. }
  232. else
  233. {
  234. var table = el.parentNode.parentNode;
  235. var ri = el.parentNode.sectionRowIndex;
  236. el = null;
  237. for (var i = ri; i < table.rows.length; i++)
  238. {
  239. if (reSectionHeader.test(table.rows[i].cells[0].className) && table.rows[i].cells[0].getAttribute("tag") == lastSection)
  240. {
  241. el = table.rows[i].cells[0];
  242. break;
  243. }
  244. }
  245. }
  246. if (el == null) return;
  247. top += el.offsetHeight - 14;
  248. width = el.offsetWidth;
  249. while (el != null)
  250. {
  251. if (el.tagName != "TR" && typeof el.offsetLeft=="number")
  252. left += el.offsetLeft;
  253. if (el.tagName != "TR" && typeof el.offsetTop=="number")
  254. top += el.offsetTop;
  255. el = el.parentNode;
  256. }
  257. if (this.m_lastSectionDropZone != null)
  258. this.m_lastSectionDropZone.setStyle(14, width, top, left, "inline");
  259. }
  260. };
  261. function DragDropController_dragEnd()
  262. {
  263. if (this.m_xtabHorizDropZone != null)
  264. this.m_xtabHorizDropZone.hide();
  265. if (this.m_xtabVertDropZone != null)
  266. this.m_xtabVertDropZone.hide();
  267. if (this.m_xtabCornerDropZone != null)
  268. this.m_xtabCornerDropZone.hide();
  269. if (this.m_lastSectionDropZone != null)
  270. this.m_lastSectionDropZone.hide();
  271. if (this.m_ddi != null)
  272. this.m_ddi.hide();
  273. };
  274. function DragDropController_setDropEffect(evt)
  275. {
  276. evt.returnValue = false;
  277. evt.dataTransfer.dropEffect = DROP_EFFECT;
  278. };
  279. function DragDropController_allowDropEffect(evt)
  280. {
  281. evt.dataTransfer.effectAllowed = DROP_EFFECT;
  282. };
  283. DragDropController.prototype.getDragDropZoneIds = DragDropController_getDragDropZoneIds;
  284. DragDropController.prototype.dragStart = DragDropController_dragStart;
  285. DragDropController.prototype.dragStartCrosstab = DragDropController_dragStartCrosstab;
  286. DragDropController.prototype.dragStartCornerDropZone = DragDropController_dragStartCornerDropZone;
  287. DragDropController.prototype.dragStartSection = DragDropController_dragStartSection;
  288. DragDropController.prototype.dragEnd = DragDropController_dragEnd;
  289. DragDropController.prototype.setDropEffect = DragDropController_setDropEffect;
  290. DragDropController.prototype.allowDropEffect = DragDropController_allowDropEffect;
  291. function DragDropZone(ddZone, zoneDirection, offsetLeft, offsetTop)
  292. {
  293. this.m_oDDZone = ddZone;
  294. this.m_zoneDirection = zoneDirection;
  295. this.m_offsetLeft = offsetLeft;
  296. this.m_offsetTop = offsetTop;
  297. };
  298. function DragDropZone_setStyle(height, width, top, left, display)
  299. {
  300. try
  301. {
  302. if (this.getElement() != null)
  303. {
  304. this.getElement().style.height = height+"px";
  305. this.getElement().style.width = width+"px";
  306. this.getElement().style.top = top+"px";
  307. this.getElement().style.left = left+"px";
  308. this.getElement().style.display = display;
  309. }
  310. }
  311. catch (e)
  312. {
  313. }
  314. };
  315. function DragDropZone_hide()
  316. {
  317. try
  318. {
  319. if (this.getElement() != null)
  320. this.getElement().style.display = "none";
  321. }
  322. catch (e)
  323. {
  324. }
  325. };
  326. function DragDropZone_show()
  327. {
  328. try
  329. {
  330. if (this.getElement() != null)
  331. this.getElement().style.display = "inline";
  332. }
  333. catch (e)
  334. {
  335. }
  336. };
  337. function DragDropZone_getElement()
  338. {
  339. return this.m_oDDZone;
  340. };
  341. function DragDropZone_dragOver()
  342. {
  343. if (ddController == null)
  344. return;
  345. var ddi = ddController.m_ddi;
  346. var zone = this.m_oDDZone;
  347. if (ddi != null && zone != null)
  348. {
  349. var height = this.m_zoneDirection == VERTICAL_ZONE ? zone.offsetHeight: DDI_SMALL_SIZE;
  350. var width = this.m_zoneDirection == HORIZONTAL_ZONE ? zone.offsetWidth : DDI_SMALL_SIZE;
  351. var top = zone.offsetTop + this.m_offsetTop;
  352. var left = zone.offsetLeft + this.m_offsetLeft
  353. ddi.setStyle(height, width, top, left, "inline");
  354. cfgSet("lastDropTarget", zone.id);
  355. _last_srcElem = zone;
  356. }
  357. };
  358. DragDropZone.prototype.getElement = DragDropZone_getElement;
  359. DragDropZone.prototype.setStyle = DragDropZone_setStyle;
  360. DragDropZone.prototype.hide = DragDropZone_hide;
  361. DragDropZone.prototype.show = DragDropZone_show;
  362. DragDropZone.prototype.dragOver = DragDropZone_dragOver;
  363. function DragDropIndicator(ddIndicator)
  364. {
  365. this.m_oDDZone = ddIndicator;
  366. this.m_zoneDirection = 0;
  367. };
  368. DragDropIndicator.prototype.getElement = DragDropZone_getElement;
  369. DragDropIndicator.prototype.setStyle = DragDropZone_setStyle;
  370. DragDropIndicator.prototype.hide = DragDropZone_hide;
  371. DragDropIndicator.prototype.show = DragDropZone_show;
  372. function getReportFrameDoc()
  373. {
  374. var rf = getReportFrame();
  375. return rf ? rf.document : null;
  376. };
  377. function getFirstElementWithTag(reportCells, el, tag)
  378. {
  379. var i;
  380. if (el == null)
  381. {
  382. for (i = 0; i < reportCells.length; i++)
  383. {
  384. if (reportCells[i].getAttribute("tag") == tag)
  385. return reportCells[i];
  386. }
  387. }
  388. else
  389. {
  390. var table = el.parentNode.parentNode;
  391. var rows = (window.ie) ? table.rows : table.getAttribute("rows");
  392. var row;
  393. for (var ri = 0; ri < rows.length; ri++)
  394. {
  395. row = rows[ri];
  396. for (var ci = 0; ci < row.cells.length; ci++)
  397. {
  398. if (row.cells[ci].getAttribute("tag") == tag)
  399. {
  400. return row.cells[ci];
  401. }
  402. }
  403. }
  404. }
  405. return null;
  406. };
  407. var ddController = null;
  408. var DROP_EFFECT = 'move';
  409. var VERTICAL_ZONE = 1;
  410. var HORIZONTAL_ZONE = 2;
  411. var DDI_SMALL_SIZE = 8;