dimbar.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: pps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2017
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. /************************************/
  9. /* dimbar methods */
  10. var last_item;
  11. var last_on_page;
  12. var first_on_page;
  13. var DISPLAY_ALL_ITEMS = 0;
  14. var flyoutM = new flyoutManager();
  15. var wrap_images = new Array();
  16. var DIMBAR_FLYOUT_MIN_WIDTH = 120;
  17. var DIMBAR_FLYOUT_MAX_HEIGHT = 150;
  18. var DIMBAR_FLYOUT_MIN_RIGHT_PADDING = 20;
  19. var DIMBAR_FLYOUT_SCROLLBAR_PADDING = 10;
  20. var DIMBAR_FLYOUT_DELAY = 350;
  21. var DIMBAR_FLYOUT_NOT_INITIALIZED = 0;
  22. var DIMBAR_FLYOUT_LOADING = 1;
  23. var DIMBAR_FLYOUT_DISPLAYED = 2;
  24. var currentDimbarWrapBrowserText;
  25. var actionPaneDimBar = (window.name == "ActionPane");
  26. function hasNextSibling(item) {
  27. return (item && item.parentNode && item.parentNode.nextSibling);
  28. }
  29. function rollover_button(event, button ) {
  30. //If the right button was clicked, do not perform the action.
  31. var eventM = new eventManager(event);
  32. if (eventM.theEvent.button == 2)
  33. return;
  34. if (button.className != "dimbar-button-img-disabled")
  35. button.className="dimbar-button-img-rollover";
  36. }
  37. function rollout_button( button ) {
  38. if (button.className != "dimbar-button-img-disabled")
  39. button.className="dimbar-button-img";
  40. }
  41. function refresh_dimbar() {
  42. var button_farleft = document.getElementById("dimbar_farleft");
  43. if (!button_farleft)
  44. return;
  45. var button_farright = document.getElementById("dimbar_farright");
  46. var button_pageleft = document.getElementById("dimbar_pageleft");
  47. var button_pageright = document.getElementById("dimbar_pageright");
  48. var menuPath = topparent.getGlobal("menuImagePath");
  49. var farLeftDisGif = "farleft_dis.gif";
  50. var farRightDisGif = "farright_dis.gif";
  51. var farLeftGif = "farleft.gif";
  52. var farRightGif = "farright.gif";
  53. var pageLeftDisGif = "pageleft_dis.gif";
  54. var pageRightDisGif = "pageright_dis.gif";
  55. var pageLeftGif = "pageleft.gif";
  56. var pageRightGif = "pageright.gif";
  57. if ((!actionPaneDimBar && topparent.getGlobal("dimbar_wrap")) || is_item_on_page(1)) {
  58. if (!button_farleft.src || button_farleft.src.indexOf("/" + farLeftDisGif) < 0)
  59. button_farleft.src = menuPath + farLeftDisGif;
  60. if (!button_pageleft.src || button_pageleft.src.indexOf("/" + pageLeftDisGif) < 0)
  61. button_pageleft.src = menuPath + pageLeftDisGif;
  62. button_farleft.className = "dimbar-button-img-disabled";
  63. button_pageleft.className = "dimbar-button-img-disabled";
  64. } else {
  65. if (!button_farleft.src || button_farleft.src.indexOf("/" + farLeftGif) < 0)
  66. button_farleft.src = menuPath + farLeftGif;
  67. if (!button_pageleft.src || button_pageleft.src.indexOf("/" + pageLeftGif) < 0)
  68. button_pageleft.src = menuPath + pageLeftGif;
  69. button_farleft.className = "dimbar-button-img";
  70. button_pageleft.className = "dimbar-button-img";
  71. }
  72. if ((!actionPaneDimBar && topparent.getGlobal("dimbar_wrap")) || is_item_on_page(last_item)) {
  73. if (!button_farright.src || button_farright.src.indexOf("/" + farRightDisGif) < 0)
  74. button_farright.src = menuPath + farRightDisGif;
  75. if (!button_pageright.src || button_pageright.src.indexOf("/" + pageRightDisGif) < 0)
  76. button_pageright.src = menuPath + pageRightDisGif;
  77. button_farright.className = "dimbar-button-img-disabled";
  78. button_pageright.className = "dimbar-button-img-disabled";
  79. } else {
  80. if (!button_farright.src || button_farright.src.indexOf("/" + farRightGif) < 0)
  81. button_farright.src = menuPath + farRightGif;
  82. if (!button_pageright.src || button_pageright.src.indexOf("/" + pageRightGif) < 0)
  83. button_pageright.src = menuPath + pageRightGif;
  84. button_farright.className = "dimbar-button-img";
  85. button_pageright.className = "dimbar-button-img";
  86. }
  87. }
  88. function reflow_dimbar() {
  89. if (!document.getElementById("dimbar-content"))
  90. return;
  91. //get the last item
  92. if (!actionPaneDimBar)
  93. last_on_page = get_last_from_first(topparent.getGlobal("dimbar_first_item"));
  94. else
  95. last_on_page = get_last_from_first(first_on_page);
  96. //In case we have grown the dimbar and can fit more at the beginning.
  97. var best_first_item = get_first_from_last(last_on_page);
  98. if (actionPaneDimBar) {
  99. if (best_first_item < parseInt(first_on_page))
  100. display_items(best_first_item);
  101. } else {
  102. if (best_first_item < parseInt(topparent.getGlobal("dimbar_first_item")))
  103. display_items(best_first_item);
  104. }
  105. refresh_dimbar();
  106. }
  107. function init_dimbar() {
  108. first_on_page = 1;
  109. wrap_images["nowrap"] = new Image();
  110. wrap_images["nowrap"].src = topparent.getGlobal("menuImagePath") + "nowrap.gif";
  111. wrap_images["wrap"] = new Image();
  112. wrap_images["wrap"].src = topparent.getGlobal("menuImagePath") + "wrap.gif";
  113. last_item = document.getElementById("dimbar-content").getAttribute("num_items");
  114. set_item_attributes();
  115. set_dimbar_wrap();
  116. reflow_dimbar();
  117. }
  118. function set_item_attributes() {
  119. //quickly unhide each item so that we can set their item_width attributes
  120. var item = document.getElementById("dimbar_item1");
  121. while (item && item.getAttribute && item.getAttribute("number")) {
  122. item.className = "dimbar-item-table";
  123. item.setAttribute("item_width",item.offsetWidth);
  124. if (!hasNextSibling(item)) break;
  125. item = item.parentNode.nextSibling.firstChild;
  126. }
  127. }
  128. function set_dimbar_wrap() {
  129. var dimbar = document.getElementById("dimbar-content");
  130. var icon = document.getElementById("dimbar_wrap");
  131. if (!actionPaneDimBar && topparent.getGlobal("dimbar_wrap")) {
  132. display_items(DISPLAY_ALL_ITEMS);
  133. if (!icon.src || icon.src.indexOf("/wrap.gif") < 0)
  134. icon.src = wrap_images["wrap"].src;
  135. icon.setAttribute("title", dimbar_alt_wrap_off);
  136. currentDimbarWrapBrowserText = dimbar_help_wrap_off;
  137. dimbar.className = "dimbar-content-div-wrap";
  138. } else if (!actionPaneDimBar) {
  139. display_items(topparent.getGlobal("dimbar_first_item"));
  140. if (!icon.src || icon.src.indexOf("/nowrap.gif") < 0)
  141. icon.src = wrap_images["nowrap"].src;
  142. icon.setAttribute("title", dimbar_alt_wrap_on);
  143. currentDimbarWrapBrowserText = dimbar_help_wrap_on;
  144. dimbar.className = "dimbar-content-div";
  145. } else {
  146. display_items(first_on_page);
  147. dimbar.className = "dimbar-content-div";
  148. }
  149. // Resize the crosstab, because wrapping on/off the dimbar may change image height
  150. if (!actionPaneDimBar)
  151. doResize();
  152. }
  153. function display_items(start) {
  154. start = parseInt(start);
  155. var item = document.getElementById("dimbar_item1");
  156. while (item && item.getAttribute && item.getAttribute("number")) {
  157. if (item.getAttribute("number") < start)
  158. item.className = "dimbar-item-table-hidden";
  159. else
  160. item.className = "dimbar-item-table";
  161. if (!hasNextSibling(item)) break;
  162. item = item.parentNode.nextSibling.firstChild;
  163. }
  164. if (start != DISPLAY_ALL_ITEMS) {
  165. if (!actionPaneDimBar)
  166. topparent.setGlobal("dimbar_first_item",start);
  167. else
  168. first_on_page = start;
  169. last_on_page = get_last_from_first(start);
  170. }
  171. }
  172. function get_first_from_last(last_item) {
  173. last_item = parseInt(last_item);
  174. var width = document.getElementById("dimbar-content").offsetWidth;
  175. var totalwidth = 0;
  176. var item = document.getElementById("dimbar_item" + last_item);
  177. while (item && item.getAttribute && item.getAttribute("number") &&
  178. ((totalwidth + parseInt(item.getAttribute("item_width"))) <= width)) {
  179. totalwidth += parseInt(item.getAttribute("item_width"));
  180. item = document.getElementById("dimbar_item" + (parseInt(item.getAttribute("number")) - 1));
  181. }
  182. if (!item)
  183. return 1;
  184. else
  185. return item.parentNode.nextSibling.firstChild.getAttribute("number");
  186. }
  187. function get_last_from_first (first_item) {
  188. first_item = parseInt(first_item);
  189. var width = document.getElementById("dimbar-content").offsetWidth;
  190. var item = document.getElementById("dimbar_item" + first_item);
  191. var totalwidth = 0;
  192. while (item && item.getAttribute && item.getAttribute("number") &&
  193. ((totalwidth + parseInt(item.getAttribute("item_width"))) <= width)) {
  194. totalwidth += parseInt(item.getAttribute("item_width"));
  195. if (!hasNextSibling(item)) break;
  196. item = item.parentNode.nextSibling.firstChild;
  197. }
  198. if (!item || !item.getAttribute || !item.getAttribute("number"))
  199. return last_item;
  200. else
  201. return document.getElementById("dimbar_item" + (parseInt(item.getAttribute("number")) - 1)).getAttribute("number");
  202. }
  203. function is_item_on_page (item_num) {
  204. if (!actionPaneDimBar) {
  205. return (parseInt(topparent.getGlobal("dimbar_first_item")) <= parseInt(item_num) && parseInt(item_num) <= parseInt(last_on_page));
  206. } else {
  207. return (first_on_page <= parseInt(item_num) && parseInt(item_num) <= parseInt(last_on_page));
  208. }
  209. }
  210. function resetDimbarToTop() {
  211. var dimbar = document.getElementById("dimbar-content");
  212. for (var i = 0; i < dimbar.childNodes.length; i++) {
  213. var barItem = dimbar.childNodes[i];
  214. if (barItem.firstChild && barItem.firstChild.getAttribute && barItem.firstChild.tagName == "TABLE") {
  215. barItem = barItem.firstChild;
  216. var catNode = dimCache.getDimTopNode(parseInt(barItem.getAttribute("dimIdx")));
  217. barItem.setAttribute("category",catNode.getLabel());
  218. barItem.setAttribute("name",catNode.getFullName());
  219. barItem.setAttribute("code",catNode.getCode());
  220. barItem.setAttribute("alternate",false);
  221. barItem.setAttribute("leaf",false);
  222. barItem.setAttribute("ppds_id",catNode.getPPDSID());
  223. var span = document.getElementById("dimbar_item" + parseInt(barItem.getAttribute("number")) + "_cell").firstChild;
  224. var isrc = span.firstChild.childNodes[1].src;
  225. var iclass = span.firstChild.childNodes[1].className;
  226. for (var j = span.firstChild.childNodes.length - 1; j >= 0; j--) {
  227. span.firstChild.removeChild(span.firstChild.childNodes[j]);
  228. }
  229. span.firstChild.appendChild(document.createTextNode(catNode.getLabel()));
  230. insertIMGNode(span.firstChild, isrc, iclass, []);
  231. span.className = "dimbar-dimension-span";
  232. }
  233. }
  234. }
  235. function button_action( event, button ) {
  236. //If the right button was clicked, do not perform the action.
  237. var eventM = new eventManager(event);
  238. if (eventM.theEvent.button == 2)
  239. return;
  240. if (button.className != "dimbar-button-img-disabled") {
  241. rollout_button( button );
  242. if (button.id == "dimbar_reset") {
  243. if (!actionPaneDimBar)
  244. if (topparent.getGlobal("isSplitView"))
  245. parent.Crosstab.doit('H');
  246. else
  247. parent.Data.doit('H');
  248. else
  249. resetDimbarToTop();
  250. } else if (button.id == "dimbar_wrap") {
  251. topparent.setGlobal("dimbar_wrap",(!topparent.getGlobal("dimbar_wrap")));
  252. set_dimbar_wrap();
  253. } else if (button.id == "dimbar_farleft") {
  254. display_items(1);
  255. } else if (button.id == "dimbar_farright") {
  256. display_items(get_first_from_last(last_item));
  257. } else if (button.id == "dimbar_pageleft") {
  258. if (!actionPaneDimBar)
  259. display_items(parseInt(topparent.getGlobal("dimbar_first_item")) - 1);
  260. else
  261. display_items(first_on_page - 1);
  262. } else if (button.id == "dimbar_pageright") {
  263. display_items(get_first_from_last(parseInt(last_on_page) + 1));
  264. }
  265. refresh_dimbar();
  266. }
  267. }
  268. function performDimbarItemSiblingRollover(item) {
  269. if (!actionPaneDimBar) {
  270. if (item.getAttribute("type") == "up")
  271. item.className='dimbar-item-sibling-cell-rollover-top';
  272. else
  273. item.className='dimbar-item-sibling-cell-rollover-bottom';
  274. }
  275. }
  276. function doDimbarItemRollover(item) {
  277. item.className = "dimbar-item-cell-rollover";
  278. }
  279. function getDimensionTable(item) {
  280. while (item.tagName != "TABLE") {
  281. item = item.parentNode;
  282. }
  283. return item;
  284. }
  285. function doDimbarItemRollout(item) {
  286. var table = item;
  287. while (table.tagName != "TABLE")
  288. table = table.parentNode;
  289. if (parseInt(flyoutM.getCurrentFlyoutDim()) != parseInt(table.getAttribute("dimIdx")))
  290. item.className = "dimbar-item-cell";
  291. }
  292. function performDimbarItemSiblingRollout(item) {
  293. item.className='dimbar-item-sibling-cell';
  294. }
  295. function clearDimRollover(dim) {
  296. var item = document.getElementById("dimbar_item1");
  297. while (item && item.getAttribute && item.getAttribute("number")) {
  298. if (parseInt(item.getAttribute("dimIdx")) == parseInt(dim))
  299. document.getElementById(item.id + "_cell").className = "dimbar-item-cell";
  300. if (!hasNextSibling(item)) break;
  301. item = item.parentNode.nextSibling.firstChild;
  302. }
  303. }
  304. function performDimbarItemSiblingFilterPrevious(event, item) {
  305. var eventM = new eventManager(event);
  306. eventM.cancelBubble();
  307. if (!actionPaneDimBar) {
  308. var com = 'DP' + ':' + item.getAttribute("cat_id") + "," + item.getAttribute("dimIdx") + ';' + item.getAttribute("cat_code");
  309. //Since we can have more than one measure dimbar item, we have to use the number of the dimbar item not the dimIdx
  310. //In the creation of the command. Note: this assumes that the dimbar items are in order of dimension id.
  311. if (parseInt(item.getAttribute("number")) > topparent.getGlobal("gDimensionInfo").length)
  312. com += "\t" + (parseInt(item.getAttribute("number")) - 1);
  313. topparent.getXtabFrame().doit(com);
  314. }
  315. }
  316. function performDimbarItemSiblingFilterNext(event, item) {
  317. var eventM = new eventManager(event);
  318. eventM.cancelBubble();
  319. if (!actionPaneDimBar) {
  320. var com = 'DN' + ':' + item.getAttribute("cat_id") + "," + item.getAttribute("dimIdx") + ';' + item.getAttribute("cat_code");
  321. //Since we can have more than one measure dimbar item, we have to use the number of the dimbar item not the dimIdx
  322. //In the creation of the command. Note: this assumes that the dimbar items are in order of dimension id.
  323. if (parseInt(item.getAttribute("number")) > topparent.getGlobal("gDimensionInfo").length)
  324. com += "\t" + (parseInt(item.getAttribute("number")) - 1);
  325. topparent.getXtabFrame().doit(com);
  326. }
  327. }
  328. function doDimbarItemDragStart(item) {
  329. var rs = "@";
  330. topparent.getGlobal("dndManager").setDrag("dim" + rs + item.getAttribute("dimIdx") + rs + "level" + rs + "1" + rs + "ppds_id" + rs + item.getAttribute("ppds_id") + rs + "code" + rs + item.getAttribute("code"));
  331. window.event.dataTransfer.effectAllowed="all";
  332. }
  333. function preventDefault(event) {
  334. (new eventManager(event)).preventDefault();
  335. }
  336. function clearFlyouts() {
  337. if (!topparent.allFramesInitialized())
  338. return;
  339. flyoutM.clearFlyouts();
  340. }
  341. /***********************************/
  342. /* Flyouts */
  343. //Flyout cache class
  344. //This maintains a pointer to each flyout so they can be found through javascript.
  345. //all creation and deletion of Flyouts should be done through this class.
  346. function flyoutManager() {
  347. var flyouts = new Array();
  348. var topFlyout = null;
  349. var currentDimbarObj = null;
  350. this.createTopFlyout = function(obj, dimIdx) {
  351. if (topFlyout) {
  352. clearDimRollover(topFlyout.getDimIdx());
  353. removeFlyout(topFlyout.getId());
  354. }
  355. var category = dimCache.getCategory(dimIdx, obj.getAttribute("code"));
  356. if (!category) {
  357. category = dimCache.createCategory(dimIdx, obj.getAttribute("code"), obj.getAttribute("category"), obj.getAttribute("name"), obj.getAttribute("ppds_id"), obj.getAttribute("alternate") == "true", obj.getAttribute("leaf") == "true", obj.getAttribute("calculated") == "true", obj.getAttribute("nonselectable") == "true", obj.getAttribute("customSubset") == "true");
  358. }
  359. topFlyout = new dimbarFlyout(dimIdx, 0, category.getCode(), obj, true, 0);
  360. currentDimbarObj = obj;
  361. }
  362. this.createFlyout = function(parentid, dimIdx, index, firstItem) {
  363. var parentFlyout = getFlyout(parentid);
  364. var id = parentFlyout.getId() + "-" + index;
  365. if (!parentFlyout || getFlyout(id))
  366. return;
  367. if (parentFlyout.getChildFlyout()) {
  368. removeFlyout(parentFlyout.getChildFlyout().getId());
  369. }
  370. var flyout = new dimbarFlyout(dimIdx, index, parentFlyout.getCategory(index), parentFlyout, false, firstItem);
  371. flyouts[flyout.getId()] = flyout;
  372. parentFlyout.setChildFlyout(flyout);
  373. }
  374. this.displayFlyout = function(id) {
  375. var flyout = getFlyout(id);
  376. if (flyout) {
  377. if (flyout.tryLoad()) {
  378. flyout.displayContent();
  379. } else {
  380. flyout.displayLoading();
  381. }
  382. }
  383. }
  384. this.hideFlyouts = function() {
  385. if (topFlyout) {
  386. hideFlyout(topFlyout.getId());
  387. }
  388. }
  389. this.clearFlyouts = function() {
  390. if (topFlyout) {
  391. clearDimRollover(topFlyout.getDimIdx());
  392. removeFlyout(topFlyout.getId());
  393. topFlyout = null;
  394. currentDimbarObj = null;
  395. }
  396. }
  397. this.cancelUnloadedFlyout = function(id, index) {
  398. var flyoutId = id + "-" + index;
  399. var flyout = getFlyout(flyoutId);
  400. if (flyout && !flyout.isLoaded())
  401. removeFlyout(flyoutId);
  402. }
  403. this.clearChildFlyout = function(id) {
  404. var flyout = getFlyout(id);
  405. if (flyout.getChildFlyout()) {
  406. removeFlyout(flyout.getChildFlyout().getId());
  407. }
  408. }
  409. this.getCurrentFlyoutDim = function() {
  410. if (topFlyout == null) {
  411. return -1;
  412. } else {
  413. return topFlyout.getDimIdx();
  414. }
  415. }
  416. this.getCurrentDimbarObj = function() {
  417. return currentDimbarObj;
  418. }
  419. function hideFlyout(id) {
  420. if (topFlyout && topFlyout.getId() == id) {
  421. if (topFlyout.getChildFlyout())
  422. hideFlyout(topFlyout.getChildFlyout().getId());
  423. topFlyout.hideFlyout();
  424. } else {
  425. if (flyouts[id]) {
  426. if (flyouts[id].getChildFlyout()) {
  427. hideFlyout(flyouts[id].getChildFlyout().getId())
  428. }
  429. flyouts[id].hideFlyout();
  430. }
  431. }
  432. }
  433. function removeFlyout(id) {
  434. if (topFlyout && topFlyout.getId() == id) {
  435. if (topFlyout.getChildFlyout())
  436. removeFlyout(topFlyout.getChildFlyout().getId());
  437. topFlyout.clearFlyout();
  438. topFlyout = null;
  439. } else {
  440. if (flyouts[id]) {
  441. if (flyouts[id].getChildFlyout()) {
  442. removeFlyout(flyouts[id].getChildFlyout().getId())
  443. }
  444. flyouts[id].clearFlyout();
  445. flyouts[id] = null;
  446. }
  447. }
  448. }
  449. function getFlyout(id) {
  450. if (topFlyout && topFlyout.getId() == id)
  451. return topFlyout
  452. else
  453. return flyouts[id];
  454. }
  455. }
  456. //Flyout class
  457. function dimbarFlyout(dimIdx, idx, cat, cal, top, firstItem) {
  458. var category = cat;
  459. var flyout = null;
  460. var childFlyout = null;
  461. var items = new Array();
  462. var id = "flyout";
  463. var index = idx;
  464. var caller = cal;
  465. var topLevel = top;
  466. var firstItem = firstItem;
  467. var dimIdx = dimIdx;
  468. var dataLoaded = false;
  469. var state = DIMBAR_FLYOUT_NOT_INITIALIZED;
  470. var timerID;
  471. //Constructor
  472. if (!topLevel) {
  473. id = caller.getId() + "-" + index;
  474. }
  475. flyout = document.createElement("DIV");
  476. flyout.className = "dimbar_flyout";
  477. flyout.id = id;
  478. flyout_content = document.createElement("DIV");
  479. flyout_content.className = "dimbar_flyout_insert";
  480. flyout.appendChild(flyout_content);
  481. flyout.onmousedown = function(event) { preventNetscapeDrag(event); };
  482. //Add the flyout to the document.
  483. flyout.style.visibility = "hidden";
  484. flyout.style.top = "0px";
  485. flyout.style.left = "0px";
  486. document.body.appendChild(flyout);
  487. timerID = setInterval("flyoutM.displayFlyout('" + id + "')",DIMBAR_FLYOUT_DELAY);
  488. //Public methods
  489. this.getId = function() {
  490. return id;
  491. }
  492. this.getChildFlyout = function() {
  493. return childFlyout;
  494. }
  495. this.isLoaded = function() {
  496. return (state == DIMBAR_FLYOUT_DISPLAYED);
  497. }
  498. this.setChildFlyout = function(child) {
  499. childFlyout = child;
  500. }
  501. this.getFlyoutLeft = function() {
  502. return flyout.offsetLeft;
  503. }
  504. this.getFlyoutWidth = function() {
  505. return flyout.offsetWidth;
  506. }
  507. this.getCode = function() {
  508. return category;
  509. }
  510. this.getDimIdx = function() {
  511. return dimIdx;
  512. }
  513. this.getCategory = function(idx) {
  514. return items[idx];
  515. }
  516. this.getPage = function() {
  517. return page;
  518. }
  519. this.getItemTop = function(idx) {
  520. var topItem = getFlyoutContent().childNodes[0];
  521. var item = getFlyoutContent().childNodes[0];
  522. while (item && ((item.getAttribute("index") == null) || (item.getAttribute("index") < idx)))
  523. item = item.nextSibling;
  524. return item.offsetTop - topItem.offsetTop + flyout.offsetTop - flyout.scrollTop;
  525. }
  526. this.displayLoading = function() {
  527. if (state == DIMBAR_FLYOUT_NOT_INITIALIZED) {
  528. populateLoading();
  529. setFlyoutDimensions();
  530. setFlyoutPosition(true);
  531. flyout.style.visibility = "visible";
  532. state = DIMBAR_FLYOUT_LOADING;
  533. }
  534. }
  535. this.displayContent = function() {
  536. clearInterval(timerID);
  537. populateFlyout();
  538. setFlyoutDimensions();
  539. setFlyoutPosition(false);
  540. flyout.style.visibility = "visible";
  541. state = DIMBAR_FLYOUT_DISPLAYED;
  542. }
  543. this.tryLoad = function() {
  544. if (topLevel) {
  545. if (getCatNode(category).allLoaded())
  546. return true;
  547. if (!dataLoaded)
  548. getCatNode(category).loadAllRelated();
  549. } else {
  550. if (getCatNode(category).childrenLoaded(firstItem))
  551. return true;
  552. if (!dataLoaded)
  553. getCatNode(category).loadChildren();
  554. }
  555. dataLoaded = true;
  556. return false;
  557. }
  558. this.hideFlyout = function() {
  559. //This for all intents and purposes gets rid of the flyout,
  560. //however it leaves it in the DOM tree so it can be accessed by script.
  561. //Important for Drag and Drop.
  562. clearInterval(timerID);
  563. setTimeout(function() {
  564. flyout.style.display = "none";
  565. },0);
  566. }
  567. this.clearFlyout = function() {
  568. clearInterval(timerID);
  569. clearFlyoutItems();
  570. flyout.onmousedown = null;
  571. document.body.removeChild(flyout);
  572. flyout = null;
  573. }
  574. //Private methods
  575. function getFlyoutContent() {
  576. return flyout.firstChild;
  577. }
  578. function getCatNode(code) {
  579. return dimCache.getCategory(dimIdx, code);
  580. }
  581. function setFlyoutPosition(isLoading) {
  582. var windowWidth = document.body.offsetWidth;
  583. var windowHeight = document.body.offsetHeight;
  584. if (window.innerWidth) {
  585. windowWidth = window.innerWidth;
  586. windowHeight = window.innerHeight;
  587. }
  588. if (topLevel) {
  589. if (actionPaneDimBar)
  590. flyout.style.top = getPageOffsetTop(caller) - flyout.offsetHeight;
  591. else
  592. flyout.style.top = getPageOffsetTop(caller) + caller.offsetHeight;
  593. if (getPageOffsetLeft(caller) + flyout.offsetWidth < windowWidth)
  594. flyout.style.left = getPageOffsetLeft(caller);
  595. else
  596. flyout.style.left = windowWidth - flyout.offsetWidth;
  597. } else {
  598. if ((caller.getItemTop(index) + flyout.offsetHeight) < windowHeight)
  599. flyout.style.top = caller.getItemTop(index);
  600. else
  601. flyout.style.top = windowHeight - flyout.offsetHeight;
  602. if ((caller.getFlyoutLeft() + caller.getFlyoutWidth() + flyout.offsetWidth) < windowWidth)
  603. flyout.style.left = caller.getFlyoutLeft() + caller.getFlyoutWidth();
  604. else if (caller.getFlyoutLeft() - flyout.offsetWidth >= 0)
  605. flyout.style.left = caller.getFlyoutLeft() - flyout.offsetWidth;
  606. else {
  607. flyout.style.left = "0px";
  608. if (isLoading) {
  609. flyout.style.top = caller.getItemTop(index) + flyout.offsetHeight;
  610. }
  611. }
  612. }
  613. }
  614. function setFlyoutDimensions() {
  615. flyout.style.width = "0px";
  616. flyout.style.width = flyout.scrollWidth + DIMBAR_FLYOUT_MIN_RIGHT_PADDING;
  617. if (flyout.scrollHeight > DIMBAR_FLYOUT_MAX_HEIGHT) {
  618. flyout.style.height = DIMBAR_FLYOUT_MAX_HEIGHT;
  619. // since we forced scrolling we have to correct the horizontal width now
  620. flyout.style.width = flyout.scrollWidth + DIMBAR_FLYOUT_MIN_RIGHT_PADDING + DIMBAR_FLYOUT_SCROLLBAR_PADDING;
  621. }
  622. if (flyout.offsetWidth < DIMBAR_FLYOUT_MIN_WIDTH) {
  623. flyout.style.width = DIMBAR_FLYOUT_MIN_WIDTH;
  624. }
  625. }
  626. function populateLoading() {
  627. var item = document.createElement("DIV");
  628. item.className = "dimbar_flyout_entry";
  629. item.appendChild(document.createTextNode(topparent.getGlobal("gLoadingText")));
  630. getFlyoutContent().appendChild(item);
  631. }
  632. function clearFlyoutItems() {
  633. var content = getFlyoutContent();
  634. while (content.firstChild) {
  635. //Remove each function explicitly from the object to break the circular reference.
  636. var child = content.firstChild;
  637. if (child.onmouseover)
  638. child.onmouseover = null;
  639. if (child.onmouseout)
  640. child.onmouseout = null;
  641. if (child.onclick)
  642. child.onclick = null;
  643. if (child.ondragstart)
  644. child.ondragstart = null;
  645. content.removeChild(child);
  646. }
  647. }
  648. function populateFlyout() {
  649. clearFlyoutItems();
  650. var content = getFlyoutContent();
  651. if (topLevel) {
  652. //Get all the ancestors except the root
  653. var ancestors = new Array();
  654. if (!getCatNode(category).isTopNode()) {
  655. ancestors[0] = category; //treat the category as the last ancestor
  656. var parent = getCatNode(category).getParent();
  657. while (!getCatNode(parent).isTopNode()) {
  658. ancestors[ancestors.length] = parent;
  659. parent = getCatNode(parent).getParent();
  660. }
  661. //for each ancestor (starting at the highest) add their parents to the flyout
  662. var lastAncestor = ancestors.length - 1;
  663. while (lastAncestor >= 0) {
  664. var parents = getCatNode(ancestors[lastAncestor]).getParents();
  665. for (var i = 0; i < parents.length; i++) {
  666. if (!dimCache.getCategory(dimIdx, parents[i]).isCustomSubset() || !actionPaneDimBar)
  667. content.appendChild(createFlyoutItem(parents[i]));
  668. }
  669. //Add a separator
  670. content.appendChild(createFlyoutSeperator());
  671. //remove the ancestor from the array
  672. lastAncestor--;
  673. }
  674. //add the siblings
  675. var siblings = getCatNode(category).getSiblings();
  676. for (var i = 0; i < parseInt(topparent.getGlobal("childLimit")) && i < siblings.length; i++)
  677. if (!dimCache.getCategory(dimIdx, siblings[i]).isCustomSubset() || !actionPaneDimBar)
  678. content.appendChild(createFlyoutItem(siblings[i]));
  679. if ((getCatNode(getCatNode(category).getParent()) > parseInt(topparent.getGlobal("childLimit"))) || !getCatNode(getCatNode(category).getParent()).allChildrenLoaded()) {
  680. content.appendChild(createMoreItem(getCatNode(category).getParent()));
  681. }
  682. //Add a separator
  683. if (!getCatNode(category).isLeaf())
  684. content.appendChild(createFlyoutSeperator());
  685. } else { //We want one sibling (this particular one)
  686. content.appendChild(createFlyoutItem(category));
  687. if (!getCatNode(category).isLeaf())
  688. content.appendChild(createFlyoutSeperator());
  689. }
  690. }
  691. //add the categories children
  692. if (!getCatNode(category).isLeaf()) {
  693. var catNodes = getCatNode(category).getChildren();
  694. for (var i = firstItem; i < firstItem + parseInt(topparent.getGlobal("childLimit")) && i < catNodes.length; i++) {
  695. if (!dimCache.getCategory(dimIdx, catNodes[i]).isCustomSubset() || !actionPaneDimBar)
  696. content.appendChild(createFlyoutItem(catNodes[i]));
  697. }
  698. if ((getCatNode(category).getNumChildrenLoaded() > firstItem + parseInt(topparent.getGlobal("childLimit"))) || !getCatNode(category).allChildrenLoaded()) {
  699. content.appendChild(createMoreItem(category));
  700. }
  701. }
  702. }
  703. function createFlyoutItem(catNode) {
  704. var idx = items.length;
  705. items[idx] = catNode;
  706. var node = getCatNode(catNode);
  707. var item = document.createElement("A");
  708. item.className = (node.isAlternateParent()? "dimbar_flyout_entry_alternate" : "dimbar_flyout_entry");
  709. item.setAttribute("origClass",item.className);
  710. item.setAttribute("flyout",id);
  711. item.setAttribute("category",node.getCode());
  712. item.setAttribute("index",idx);
  713. item.setAttribute("ppdsId",node.getPPDSID());
  714. if (node.getParent())
  715. item.setAttribute("parentId",dimCache.getCategory(node.getDimension(), node.getParent()).getPPDSID());
  716. else
  717. item.setAttribute("parentId","0");
  718. item.setAttribute("dimIdx",node.getDimension());
  719. item.setAttribute("code",node.getCode());
  720. item.setAttribute("name",node.getLabel());
  721. item.setAttribute("tag",node.getFullName());
  722. item.setAttribute("leaf",node.isLeaf());
  723. item.href = "#"; //Needed to enable Drag and Drop for IE.
  724. var mouseOverFunc = "this.className = this.getAttribute('origClass') + ' dimbar_flyout_entry_rollover';";
  725. if (!node.isLeaf()) {
  726. mouseOverFunc += "\nflyoutM.createFlyout(this.getAttribute('flyout'), this.getAttribute('dimIdx'), parseInt(this.getAttribute('index')), 0);";
  727. } else {
  728. mouseOverFunc += "\nflyoutM.clearChildFlyout(this.getAttribute('flyout'));";
  729. }
  730. item.onmouseover = new Function(mouseOverFunc);
  731. var mouseOutFunc = "this.className = this.getAttribute('origClass');";
  732. if (!node.isLeaf()) {
  733. mouseOutFunc += "\nflyoutM.cancelUnloadedFlyout(this.getAttribute('flyout'), parseInt(this.getAttribute('index')));";
  734. }
  735. item.onmouseout = new Function(mouseOutFunc);
  736. if (!actionPaneDimBar) {
  737. item.onclick = function() {
  738. var com = 'DC' + ':' + this.getAttribute("ppdsId") + "," + this.getAttribute("dimIdx") + ';' + this.getAttribute("code");
  739. //Since we can have more than one measure dimbar item, we have to use the number of the dimbar item not the dimIdx
  740. //In the creation of the command. Note: this assumes that the dimbar items are in order of dimension id.
  741. if (parseInt(flyoutM.getCurrentDimbarObj().getAttribute("number")) > topparent.getGlobal("gDimensionInfo").length)
  742. com += "\t" + (flyoutM.getCurrentDimbarObj().getAttribute("number") - 1);
  743. topparent.getXtabFrame().doit(com);
  744. }
  745. } else {
  746. item.onclick = function() {
  747. handleDimbarClick(this);
  748. }
  749. }
  750. item.ondragstart = function() {
  751. flyoutM.hideFlyouts();
  752. var rs = "@";
  753. topparent.getGlobal("dndManager").setDrag("dim" + rs + this.getAttribute("dimIdx") + rs + "level" + rs + "1" + rs + "ppds_id" + rs + this.getAttribute("ppdsId") + rs + "code" + rs + this.getAttribute("code") + rs + "parentId" + rs + this.getAttribute("parentId"));
  754. window.event.dataTransfer.effectAllowed="all";
  755. }
  756. if (!node.isLeaf()) {
  757. insertIMGNode(item, topparent.getGlobal("menuImagePath") + "arrow.right.png", "dimbar_flyout_arrow", []);
  758. }
  759. var currentLabel = node.getLabel();
  760. var hiddenForm = topparent.getXtabFrame().document.fhidden;
  761. if (hiddenForm && hiddenForm.SHN != "undefined" && hiddenForm.SHN != null && hiddenForm.SHN.value == 1) {
  762. currentLabel = node.getFullName();
  763. }
  764. item.appendChild(document.createTextNode(currentLabel));
  765. return item;
  766. }
  767. function createFlyoutSeperator() {
  768. var sep = document.createElement("DIV");
  769. sep.className = "dimbar-flyout-separator";
  770. return sep;
  771. }
  772. function createMoreItem(parent) {
  773. var idx = items.length;
  774. items[idx] = parent;
  775. var item = document.createElement("A");
  776. item.className = "dimbar_flyout_entry";
  777. item.setAttribute("origClass",item.className);
  778. item.setAttribute("flyout",id);
  779. item.setAttribute("index",idx);
  780. item.setAttribute("dimIdx",dimIdx);
  781. item.setAttribute("firstItem",firstItem + parseInt(topparent.getGlobal("childLimit")));
  782. var mouseOverFunc = "this.className = this.getAttribute('origClass') + ' dimbar_flyout_entry_rollover';";
  783. mouseOverFunc += "\nflyoutM.createFlyout(this.getAttribute('flyout'), this.getAttribute('dimIdx'), parseInt(this.getAttribute('index')), parseInt(this.getAttribute('firstItem')));";
  784. item.onmouseover = new Function(mouseOverFunc);
  785. var mouseOutFunc = "this.className = this.getAttribute('origClass');";
  786. mouseOutFunc += "\nflyoutM.cancelUnloadedFlyout(this.getAttribute('flyout'), parseInt(this.getAttribute('index')));";
  787. item.onmouseout = new Function(mouseOutFunc);
  788. insertIMGNode(item, topparent.getGlobal("menuImagePath") + "arrow.right.png", "dimbar_flyout_arrow", []);
  789. item.appendChild(document.createTextNode(topparent.getGlobal("gMoreText")));
  790. return item;
  791. }
  792. }
  793. function getPageOffsetLeft(obj) {
  794. var left = obj.offsetLeft;
  795. var oParent = obj.offsetParent;
  796. while (oParent) {
  797. left += oParent.offsetLeft;
  798. oParent = oParent.offsetParent;
  799. }
  800. return left;
  801. }
  802. function getPageOffsetTop(obj) {
  803. var top = obj.offsetTop;
  804. var oParent = obj.offsetParent;
  805. while (oParent) {
  806. top += oParent.offsetTop;
  807. oParent = oParent.offsetParent;
  808. }
  809. return top;
  810. }
  811. function toggleDimTip(obj, showalt, hidealt) {
  812. if (topparent.getGlobal("treeVisible"))
  813. obj.alt = hidealt;
  814. else
  815. obj.alt = showalt;
  816. }
  817. function toggleTree(event, obj) {
  818. if (topparent.getGlobal("treeVisible")) {
  819. topparent.closeTreeFrame();
  820. }
  821. else {
  822. topparent.openTreeFrame();
  823. }
  824. if (event) {
  825. var eventM = new eventManager(event);
  826. eventM.cancelBubble();
  827. }
  828. // Update toolbar icons to show the new tree state
  829. if (topparent.getGlobal('is_dashboard'))
  830. topparent.updateToolbar();
  831. }
  832. function setToggleTreeIconOpen() {
  833. var img = document.getElementById("hideShowTree");
  834. if (img)
  835. img.src = topparent.getGlobal("imgPath") + "close_tab.gif";
  836. }
  837. function setToggleTreeIconClosed() {
  838. var img = document.getElementById("hideShowTree");
  839. if (img)
  840. img.src = topparent.getGlobal("imgPath") + "open_tab.gif";
  841. }