rank.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. // This forms the javascript functions used for the Rank pane of
  9. // PowerPlay Studio.
  10. // The functions handle any minor browser differences.
  11. var rc;
  12. var dim;
  13. var editCode;
  14. var catarr;
  15. var rankID;
  16. var categories = new Array();
  17. categories["R"] = new Array();
  18. categories["C"] = new Array();
  19. var RANK_DEFAULT_NUM_ORDINALS = 10;
  20. function init() {
  21. topparent.openActionPane();
  22. ContextMenu.initialize(true,false);
  23. initErrorVars();
  24. resetDialog();
  25. }
  26. function refresh() {
  27. resetDialog();
  28. }
  29. function addToArray(rc, name, code, calc, rankable) {
  30. categories[rc][categories[rc].length] = new categoryRecord(name, code, calc, rankable);
  31. }
  32. function categoryRecord(name, code, calc, rankable) {
  33. this._name = name;
  34. this._code = code;
  35. this._calc = calc;
  36. this._rankable = rankable;
  37. }
  38. function dialogOperand(type, code) {
  39. this._type = type;
  40. this._code = code;
  41. }
  42. function rankInfo(label, operand, show_op, show_num, start_op, sort_op) {
  43. this._operand = operand;
  44. this._label = label;
  45. this._show_op = show_op;
  46. this._show_num = show_num;
  47. this._start_op = start_op;
  48. this._sort_op = sort_op;
  49. }
  50. function submitPreRankDialog() {
  51. topparent.setGlobal("editingRank", 0);
  52. if(document.preEditRank.rank_edit.checked)
  53. topparent.setGlobal("editingRank", 1);
  54. else if(document.preEditRank.rank_rename.checked)
  55. topparent.setGlobal("editingRank", 2);
  56. else if(document.preEditRank.rank_delete.checked)
  57. topparent.setGlobal("editingRank", 3);
  58. resetDialog();
  59. }
  60. function resetDialog() {
  61. removeMessage();
  62. displayContent();
  63. var rowSelections = getSelected("r");
  64. var colSelections = getSelected("c");
  65. if (rowSelections.length && colSelections.length) { //Both rows and columns selected
  66. handleError(strNoSelectionsMsg, true);
  67. return;
  68. } else if (!rowSelections.length && !colSelections.length) {//No rows or columns selected
  69. handleError(strNoSelectionsMsg, true);
  70. return;
  71. } else {
  72. if (rowSelections.length) {
  73. if (rc != "R")
  74. rowcolswitch = true;
  75. rc = "R";
  76. xtabgroup = topparent.getXtabFrame().numRowLevels;
  77. for (var i = 0;i < rowSelections.length;i++) {
  78. if (!topparent.getXtabFrame().isBottomDimension(rowSelections[i])) {
  79. clearDialogs();
  80. handleError(strNoSelectionsMsg, true);
  81. return;
  82. }
  83. }
  84. } else {
  85. if (rc != "C")
  86. rowcolswitch = true;
  87. rc = "C";
  88. xtabgroup = topparent.getXtabFrame().numColLevels;
  89. for (var i = 0;i < colSelections.length;i++) {
  90. if (!topparent.getXtabFrame().isBottomDimension(colSelections[i])) {
  91. handleError(strNoSelectionsMsg, true);
  92. clearDialogs();
  93. return;
  94. }
  95. }
  96. }
  97. }
  98. if (rowSelections.length) {
  99. if (rc != "R")
  100. rowcolswitch = true;
  101. rc = "R";
  102. setRankByLabel(strRankByRowLabel);
  103. } else {
  104. if (rc != "C")
  105. rowcolswitch = true;
  106. rc = "C";
  107. setRankByLabel(strRankByColumnLabel);
  108. }
  109. catarr = categories[rc];
  110. if (!catarr || !catarr.length) {
  111. handleError(strNoSelectionsMsg, true);
  112. return;
  113. }
  114. //if the editingRank is true, then user is editting a rank (value of 2 is for renaming rank only).
  115. var editRank = topparent.getGlobal("editingRank");
  116. //the only selection is a non-isolated rank, so render the preContent to ask user to
  117. //choose it is going to be an insert or edit.
  118. if(catarr != null){
  119. if(catarr.length > 1 && (rowSelections.length == 1 ^ colSelections.length == 1)){
  120. if(editRank == -1) {
  121. var theSel = rowSelections.length > 0 ? rowSelections[0] : colSelections[0];
  122. if(theSel.getAttribute("rank") == 'true'){
  123. selecteddim = null;
  124. clearDialogs();
  125. displayPreContent();
  126. return;
  127. }
  128. }
  129. }
  130. }
  131. rankID = "0";
  132. editCode = "";
  133. if(editRank == 1 || editRank == 2 || editRank == 3){
  134. editCode = rowSelections.length == 1 ? rowSelections[0].getAttribute("ppdsId") : colSelections[0].getAttribute("ppdsId");
  135. if(editCode.charAt(0) == 'T')
  136. rankID = editCode.substring(1, editCode.length);//will be used in the command sent to server when apply changes.
  137. }
  138. topparent.setGlobal("editingRank", -1);
  139. presetRankFields();
  140. if (rowSelections.length && resetforRank(rowSelections, editRank))
  141. return;
  142. else if (resetforRank(colSelections, editRank))
  143. return;
  144. if (!popOptions(document.getElementById("rankByItemId"))) {
  145. handleError(strNoSelectionsMsg, true);
  146. return;
  147. }
  148. preSelectOptions(document.getElementById("rankByItemId"));
  149. if (!document.getElementById("rankShowOrdinalsId").disabled)
  150. document.getElementById("rankOrdinalsNum").value = RANK_DEFAULT_NUM_ORDINALS;
  151. }
  152. function presetRankFields() {
  153. var rowSelections = getSelected("r");
  154. var colSelections = getSelected("c");
  155. var selections = (rowSelections.length)? rowSelections : colSelections;
  156. if (!topparent.getXtabFrame().isOnlyDimensioninAxis(selections[0])) {
  157. document.getElementById("rankShowOrdinalsId").selectedIndex = 2;
  158. document.getElementById("rankShowOrdinalsId").disabled = true;
  159. document.getElementById("rankOrdinalsNum").value = "";
  160. document.getElementById("rankOrdinalsNum").disabled = true;
  161. document.getElementById("rankOrdinalsNum").style.visibility = "hidden";
  162. document.getElementById("rankSortOrderId").selectedIndex = 2;
  163. document.getElementById("rankSortOrderId").disabled = true;
  164. }
  165. }
  166. function resetforRank(categ, editRank) {
  167. if(rankID == "0")
  168. return false;
  169. if ((categ.length != 1) || (categ[0].getAttribute("ppdsId").charAt(0) != 'T')) //not a rank edit
  170. return false;
  171. //set the calcId to new calculation;
  172. dim = categ[0].getAttribute("dimIdx");
  173. catarr = categories[rc];
  174. if(editRank == 1) {
  175. popDialogWithRankInfo(categ[0].getAttribute("ppdsId")); //We have to populate for the calculation.
  176. displayContent();
  177. }
  178. else if (editRank == 2) {
  179. displayRenameContent(); //change label only
  180. popRenameInfo(categ[0].getAttribute("ppdsId"));
  181. document.getElementById("labelRenameField").select()
  182. }
  183. else if(editRank == 3 )
  184. {
  185. if (categ[0].getAttribute("dependent_cats") != null) {
  186. displayDeleteContent();
  187. popDeleteInfo(categ[0].getAttribute("dependent_cats"));
  188. } else {
  189. topparent.closeActionPane();
  190. var del = 'MK:' + categ[0].getAttribute("ppdsId");
  191. topparent.getXtabFrame().doit(del);
  192. }
  193. return true;
  194. }
  195. if (document.getElementById("applyButton"))
  196. enableButton(document.getElementById("applyButton"));
  197. return true;
  198. }
  199. function popDeleteInfo(dependents) {
  200. var div = document.getElementById("referencedCalcs");
  201. var deps = dependents.split("\\t");
  202. for (var i = 0; i < deps.length; i++) {
  203. div.appendChild(document.createTextNode(deps[i]));
  204. div.appendChild(document.createElement("BR"));
  205. }
  206. }
  207. function popDialogWithRankInfo(id) {
  208. var rankInfo = getRankInfo(id);
  209. var catSelect = document.getElementById("rankByItemId");
  210. popOptions(catSelect);
  211. //find and select proper categories;
  212. var operandCode = "";
  213. if( rankInfo._operand._code.substring(0,1) == "T" )
  214. operandCode = rankInfo._operand._code;
  215. else
  216. operandCode = rankInfo._operand._code.substring(0,rankInfo._operand._code.indexOf(","));
  217. var ctr = 0;
  218. for (var i = 0; i < catarr.length; i++)
  219. {
  220. //LB: if it is calculation code "T..." it has to be matched as is: "T24",
  221. //and if it is a regular category, than we need to extract and match it's code
  222. //relying on "," as a separator
  223. if( ((catarr[i]._code.substring(0,1) == "T") && (catarr[i]._code == operandCode ))
  224. || (catarr[i]._code.substring(0,catarr[i]._code.indexOf(",")) == operandCode )
  225. )
  226. {
  227. catSelect.selectedIndex = ctr;
  228. break;
  229. }
  230. if (catarr[i]._rankable)
  231. ctr++;
  232. }
  233. //fill in label field
  234. document.getElementById("RankLabelField").value = rankInfo._label;
  235. document.getElementById("rankShowOrdinalsId").selectedIndex = rankInfo._show_op;
  236. if (rankInfo._show_op == 2)
  237. document.getElementById("rankOrdinalsNum").style.visibility = "hidden";
  238. else {
  239. document.getElementById("rankOrdinalsNum").style.visibility = "";
  240. if (rankInfo._show_num >= 0)
  241. document.getElementById("rankOrdinalsNum").value = rankInfo._show_num;
  242. }
  243. document.getElementById("rankStartFromId").selectedIndex = rankInfo._start_op;
  244. document.getElementById("rankSortOrderId").selectedIndex = rankInfo._sort_op;
  245. }
  246. function popRenameInfo(id) {
  247. // adjust the size of the action pane for the rename calculation pane.
  248. topparent.setActionPaneHeight("180");
  249. var rankInfo = getRankInfo(id);
  250. if(rankInfo._label != "") {
  251. document.getElementById("labelRenameField").value = rankInfo._label;
  252. }
  253. else {
  254. for (var i = 0; i < catarr.length; i++) {
  255. var temp = catarr[i]._code.split(",");
  256. if(temp[0] == id)
  257. document.getElementById("labelRenameField").value = catarr[i]._name;
  258. }
  259. }
  260. }
  261. function getRankInfo(id) {
  262. var idx = parseInt(id.substring(1));
  263. if (topparent.getXtabFrame().fh && topparent.getXtabFrame().fh.PT) {
  264. var calcs = topparent.getXtabFrame().fh.PT.value.split("\t\t");
  265. var dim;
  266. for (var i = 0; i < calcs.length; i++) {
  267. var x = calcs[i].split("\t");
  268. var j = 0;
  269. if (x[j].charAt(0) == 'D') dim = x[j++].substring(1);
  270. if (i == idx - 1) {
  271. var rIdx = 0;
  272. var op = x[j++];
  273. if (op.charAt(0) == 'R') {
  274. var opt = op.substring(2).split(",");
  275. var label = opt[1];
  276. //var decimal = opt[0]; //for the moment;
  277. var operand
  278. if (x[j].charAt(0) == 'T') {
  279. operand = new dialogOperand('T',x[j]);
  280. } else {
  281. var p = x[j].split(",");
  282. operand = new dialogOperand('C', p[0] + "," + dim + "," + p[1]);
  283. }
  284. j++;
  285. var show_op = parseInt(x[j++]);
  286. var show_num = parseInt(x[j++]);
  287. var start_op = parseInt(x[j++]);
  288. var sort_op = parseInt(x[j]);
  289. var result = new rankInfo(label,operand,show_op,show_num,start_op,sort_op);
  290. return(result);
  291. }
  292. }
  293. }
  294. }
  295. return null;
  296. }
  297. function popOptions(select) {
  298. while (select.childNodes.length) {
  299. select.removeChild(select.firstChild);
  300. }
  301. var selIdx = 0;
  302. if (catarr != null) {
  303. for (var i = 0; i < catarr.length; i++){
  304. if (catarr[i]._rankable) {
  305. select.options[selIdx] = new Option(catarr[i]._name,i);
  306. select.options[selIdx++].label = catarr[i]._name;
  307. }
  308. }
  309. }
  310. return selIdx;
  311. }
  312. function handleError(sError, closeActionPane){
  313. if (closeActionPane)
  314. displayCommonMessage(sError, MESSAGE_TYPE_INFO, [], []);
  315. else
  316. displayCommonMessage(sError, MESSAGE_TYPE_INFO, [message_ok_button_text], [function() {removeMessage();}]);
  317. }
  318. function clearDialogs() {
  319. if (document.getElementById("labelField"))
  320. document.getElementById("labelField").value = "";
  321. }
  322. function preSelectOptions(select) {
  323. var selects = getSelected("r");
  324. if (selects.length != 1) {
  325. selects = getSelected("c");
  326. if (selects.length != 1)
  327. return;
  328. }
  329. for (var i = 0; i < select.length; i++) {
  330. var catCode = catarr[select[i].value]._code;
  331. if (catCode.charAt(0) == 'T')
  332. select[i].selected = (catCode == selects[0].getAttribute("ppdsId"));
  333. else
  334. select[i].selected = (catCode == selects[0].getAttribute("ppdsId") + "," + selects[0].getAttribute("dimIdx") + "," + selects[0].getAttribute("code"));
  335. }
  336. }
  337. function setRankByLabel(str) {
  338. var cell = document.getElementById("RankByLabelText");
  339. while (cell.childNodes.length)
  340. cell.removeChild(cell.firstChild);
  341. cell.appendChild(document.createTextNode(str));
  342. }
  343. function applyChanges() {
  344. if (!validateInput())
  345. return;
  346. var cmd = "CR:";
  347. var label = document.getElementById("RankLabelField").value;
  348. cmd += (label) ? ('"' + CEncodingUtil.EncodeStrOperand(label) + '"') : "";
  349. cmd += "\t" + rankID;
  350. cmd += "\t-1\t0\t0\t";
  351. var catSelect = document.getElementById("rankByItemId");
  352. cmd += catarr[catSelect.options[catSelect.selectedIndex].value]._code + "\t";
  353. var numVals = -1;
  354. if (document.getElementById("rankShowOrdinalsId").selectedIndex != 2)
  355. numVals = document.getElementById("rankOrdinalsNum").value;
  356. cmd += document.getElementById("rankShowOrdinalsId").selectedIndex + "\t" + numVals + "\t";
  357. cmd += document.getElementById("rankStartFromId").selectedIndex + "\t";
  358. cmd += document.getElementById("rankSortOrderId").selectedIndex;
  359. topparent.getXtabFrame().fh.ACTPANE.value = 0;
  360. topparent.getXtabFrame().doit(cmd);
  361. topparent.closeActionPane();
  362. }
  363. function doRankOrdinalsChange() {
  364. var select = document.getElementById("rankShowOrdinalsId");
  365. if (select.selectedIndex == 2) {
  366. document.getElementById("rankOrdinalsNum").style.visibility = "hidden";
  367. } else {
  368. document.getElementById("rankOrdinalsNum").style.visibility = "";
  369. }
  370. }
  371. function onRenameRank() {
  372. if (document.getElementById("labelRenameField").value == "") {
  373. topparent.closeActionPane();
  374. return;
  375. }
  376. var label = document.getElementById("labelRenameField").value;
  377. var cmd = 'MN:' + editCode;
  378. cmd += "\t";
  379. cmd += '"' + CEncodingUtil.EncodeStrOperand(label) + '"';
  380. topparent.closeActionPane();
  381. topparent.getXtabFrame().doit(cmd);
  382. }
  383. function onDeleteRank() {
  384. if (document.getElementById("delRank").checked) {
  385. topparent.closeActionPane();
  386. var cmd = 'MK:' + editCode;
  387. topparent.getXtabFrame().doit(cmd);
  388. } else {
  389. topparent.closeActionPane();
  390. var cmd = 'MH:0\t' + editCode;
  391. topparent.getXtabFrame().doit(cmd);
  392. }
  393. }
  394. function validateInput() {
  395. var validChars = "/[^0-9]/";
  396. if ((document.getElementById("rankShowOrdinalsId").selectedIndex != 2) && (document.getElementById("rankOrdinalsNum").value <= 0) || !CNumUtil.validateNumField(document.getElementById("rankOrdinalsNum"),true, validChars )) {
  397. handleError(strInvalidOrdinalNumber, false);
  398. return false;
  399. }
  400. return true;
  401. }