Tools.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2014
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. //----------------------------------------------------------
  13. com.cognos.admin.ObjectFactory("com.cognos.admin.util.Tools");
  14. com.cognos.admin.util.Tools.VERSION = "0.1.0";
  15. dojo.require("dojox.json.ref");
  16. com.cognos.admin.util.Tools.revertDsp = function (elt,dsp){
  17. if (typeof elt == "string")
  18. elt = xGetElementById(elt);
  19. if (dsp == true) {
  20. xDisplay(elt,"");
  21. } else if (dsp == false) {
  22. xDisplay(elt,"none");
  23. } else {
  24. if (elt.style.display == "none") {
  25. dsp = true;
  26. xDisplay(elt,"");
  27. } else {
  28. dsp = false;
  29. xDisplay(elt,"none");
  30. }
  31. }
  32. return dsp;
  33. };
  34. //TODO:
  35. com.cognos.admin.util.Tools.ToggleButton = function (elt){
  36. this.elt = elt;
  37. };
  38. //TODO:
  39. com.cognos.admin.util.Tools.ToggleButton.prototype = {
  40. getCurrentState : function (){
  41. return this.elt.getAttribute("state");
  42. },
  43. click : function (){
  44. if (this.elt.src){
  45. var currentState = this.getCurrentState();
  46. var stateModel = com.cognos.admin.util.Tools.cogEval(this.elt);
  47. var newState = stateModel.states[currentState].next;
  48. this.elt.src = stateModel.states[newState].image;
  49. this.elt.setAttribute("state", newState);
  50. }
  51. }
  52. };
  53. /*
  54. * @param exclude, ='true' will remove the prefix fragId + "_"
  55. * from the Id, if any; otherwise will add a fragId + "_" as prefix of the ID.
  56. *
  57. */
  58. com.cognos.admin.util.Tools.getNormalizedId = function (Id,fragId,exclude){
  59. var retId = Id;
  60. if (exclude){
  61. retId = Id.substring(fragId.length+1,Id.length);
  62. } else {
  63. retId = fragId + "_" + Id;
  64. }
  65. return retId;
  66. };
  67. com.cognos.admin.util.Tools.getFlag = function (id){
  68. var flags = id.toString().split("_");
  69. return flags[flags.length-1];
  70. }
  71. com.cognos.admin.util.Tools.getPartner = function (elt,postfix,postfixP){
  72. var reg = new RegExp ("_"+postfix+"$","i");
  73. var regP = new RegExp ("_"+postfixP+"$","i");
  74. var id="";
  75. if (reg.test(elt.id)){
  76. id = elt.id.replace(reg,"_"+postfixP);
  77. } else if (regP.test(elt.id)){
  78. id = elt.id.replace(regP,"_"+postfix);
  79. }
  80. return $(id);
  81. }
  82. com.cognos.admin.util.Tools.Masker = function (elt,hint,frag){
  83. if (!$(elt)) throw new Error("Masker cannot apply on an empty element.");
  84. this.maskID = $(elt).id + "_masker";
  85. this.backingID = $(elt).id + "masker_backing";
  86. this.elt = elt;
  87. var backing = $(this.backingID);
  88. if (backing == null) {
  89. backing = document.createElement("iframe");
  90. backing.id = this.backingID;
  91. backing.style.display = "none";
  92. backing.style.position ="absolute";
  93. backing.style.backgroundColor ="#dddddd";
  94. xOpacity (backing,0);
  95. backing.src = _F_Config.webContent + "/fragments/common/images/space.gif";
  96. document.body.appendChild(backing);
  97. }
  98. var mask = $(this.maskID);
  99. if (mask == null) {
  100. mask = document.createElement("DIV");
  101. mask.id = this.maskID;
  102. mask.style.display= "none";
  103. mask.style.position = "absolute";
  104. mask.style.backgroundColor = "#dddddd";
  105. mask.setAttribute("title",hint);
  106. document.body.appendChild(mask);
  107. }
  108. this.adjust();
  109. if (frag){
  110. evtHandler = _F_Document.associate(frag,this,"adjust");
  111. frag.onresize = evtHandler;
  112. } else {
  113. evtHandler = _F_Document.associate(window,this,"adjust");
  114. _F_Document.addEventListener(window, "resize", evtHandler, true);
  115. }
  116. }
  117. com.cognos.admin.util.Tools.Masker.OPACITY = 0.2;
  118. com.cognos.admin.util.Tools.Masker.prototype = {
  119. adjustEx : function (source,target) {
  120. xLeft(source,xPageX(target));
  121. xTop(source,xPageY(target));
  122. xResizeTo(source, xWidth(target), xHeight(target));
  123. },
  124. adjust : function (){
  125. this.adjustEx ($(this.maskID),this.elt);
  126. this.adjustEx ($(this.backingID),this.elt);
  127. },
  128. show : function (showing){
  129. if (showing){
  130. xOpacity($(this.maskID),com.cognos.admin.util.Tools.Masker.OPACITY);
  131. $(this.maskID).style.display = "";
  132. $(this.backingID).style.display = "";
  133. } else {
  134. $(this.maskID).style.display = "none";
  135. $(this.backingID).style.display = "none";
  136. }
  137. },
  138. destroy : function (){
  139. $(this.backingID).parentNode.removeChild($(this.backingID));
  140. $(this.backingID) = null;
  141. $(this.maskID).parentNode.removeChild($(this.maskID));
  142. $(this.maskID) = null;
  143. }
  144. };
  145. com.cognos.admin.util.Tools.setBusyCursor = function (tag,isBusy){
  146. tag.style.cursor = isBusy ? 'wait' : 'default';
  147. document.body.style.cursor = isBusy ? 'wait' : 'default';
  148. }
  149. com.cognos.admin.util.Tools.ThreeCheckbox = function (elt,fragId,toggler){
  150. this.tools = com.cognos.admin.util.Tools;
  151. this.elt = elt;
  152. this.onclickEvt = [];
  153. this.fragId = fragId;
  154. this.flag = this.tools.getFlag(elt.id);
  155. this.allToggler = $(com.cognos.admin.util.Tools.getNormalizedId("toggle_all_" + this.flag,this.fragId));
  156. this.allTogglerPartner = this.tools.getPartner(this.allToggler,com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_Y,com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_N);
  157. this.toggler = toggler;
  158. this.isToggled = false;
  159. this.isToggleAll = (this.allToggler === this.toggler);
  160. };
  161. com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED = "true";
  162. com.cognos.admin.util.Tools.ThreeCheckbox.UNCHECKED = "false";
  163. com.cognos.admin.util.Tools.ThreeCheckbox.MIXED = "mixed";
  164. com.cognos.admin.util.Tools.ThreeCheckbox.DISABLED = "disabled";
  165. com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_Y = "y";
  166. com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_N = "n";
  167. com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_M = "m";
  168. com.cognos.admin.util.Tools.ThreeCheckbox.prototype = {
  169. getCurrentState : function (){
  170. if (this.elt.src.search(/checkbox_checked.gif/i) != -1)
  171. return com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED;
  172. else if (this.elt.src.search(/checkbox_unchecked.gif/i) != -1)
  173. return com.cognos.admin.util.Tools.ThreeCheckbox.UNCHECKED;
  174. else if (this.elt.src.search(/checkbox_mixed.gif/i) != -1)
  175. return com.cognos.admin.util.Tools.ThreeCheckbox.MIXED;
  176. else if (this.elt.src.search(/checkbox_disabled.gif/i) != -1)
  177. return com.cognos.admin.util.Tools.ThreeCheckbox.DISABLED;
  178. else
  179. return "";
  180. },
  181. setIsToggled : function (isToggled){
  182. this.isToggled = isToggled || false;
  183. },
  184. onclickReg : function (handler) {
  185. if (typeof handler == "function"){
  186. this.onclickEvt.push(handler);
  187. }
  188. },
  189. getCurrentStatus : function () {
  190. return this.getCurrentState() != com.cognos.admin.util.Tools.ThreeCheckbox.DISABLED;
  191. },
  192. onclick : function (){
  193. var ret = true;
  194. this.onclickEvt.push(this.getCurrentStatus);
  195. for (var i = this.onclickEvt.length-1; i >= 0 ; i--){
  196. ret = ret && this.onclickEvt[i].apply(this);
  197. if (!ret) break;
  198. }
  199. return ret;
  200. },
  201. click : function (){
  202. if (this.onclick() && this.elt.src){
  203. if (this.isToggled){
  204. var state;
  205. if (this.isToggleAll) {
  206. state = this.toggler.checked ? com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED : com.cognos.admin.util.Tools.ThreeCheckbox.UNCHECKED;
  207. } else {
  208. state = this.toggler.getAttribute("state");
  209. }
  210. this.setState(state);
  211. } else {
  212. if (this.getCurrentState() == com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED){
  213. this.setState(com.cognos.admin.util.Tools.ThreeCheckbox.UNCHECKED);
  214. } else {
  215. this.setState(com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED);
  216. }
  217. }
  218. //Three stage checkbox generic toggle rule #1 deselect partner when the current one is checked.
  219. if (this.getCurrentState() == com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED){
  220. this.deselectElt("",true);
  221. }
  222. //Three stage checkbox generic toggle rule #2 deselect "n" toggler when current "n" is unchecked.
  223. if (!this.isToggleAll && !this.isToggled && (!(this.flag == com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_N && this.getCurrentState() == com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED))){
  224. this.deselectElt(this.toggler,(this.flag == com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_Y));
  225. }
  226. }
  227. },
  228. deselectElt : function (elt,isPartner){
  229. var elt = elt || this.elt;
  230. if (isPartner){
  231. elt = this.tools.getPartner(elt,com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_Y,com.cognos.admin.util.Tools.ThreeCheckbox.FLAG_N);
  232. }
  233. if (elt){
  234. this.setState(com.cognos.admin.util.Tools.ThreeCheckbox.UNCHECKED,elt);
  235. }
  236. },
  237. disableAllTogglerState : function (disabled){
  238. if (this.allToggler){
  239. if (disabled){
  240. this.deselectAllTogglerState();
  241. }
  242. this.allToggler.disabled = disabled;
  243. this.allTogglerPartner.disabled = disabled;
  244. }
  245. },
  246. deselectAllTogglerState : function (){
  247. if (this.allToggler){
  248. this.allToggler.checked = false;
  249. this.allTogglerPartner.checked = false;
  250. }
  251. },
  252. setState : function (state,elt){
  253. var elt = elt || this.elt;
  254. elt.setAttribute("state",state);
  255. dojo.attr(elt,"class","");
  256. dojo.attr(elt,"tabindex","0");
  257. this.disableAllTogglerState(false);
  258. //deselect the toggle all buttons regardingless (except the toggle all event)
  259. if (!this.isToggleAll){
  260. this.deselectAllTogglerState();
  261. }
  262. elt.disabled = false;
  263. elt.setAttribute("aria-disabled","false");
  264. switch (state) {
  265. case com.cognos.admin.util.Tools.ThreeCheckbox.CHECKED:
  266. elt.src = elt.src.replace(/checkbox_(.)*.gif/i,"checkbox_checked.gif");
  267. elt.setAttribute("aria-checked","true");
  268. break;
  269. case com.cognos.admin.util.Tools.ThreeCheckbox.MIXED:
  270. elt.setAttribute("aria-checked","mixed");
  271. elt.src = elt.src.replace(/checkbox_(.)*.gif/i,"checkbox_mixed.gif");
  272. break;
  273. case com.cognos.admin.util.Tools.ThreeCheckbox.DISABLED:
  274. elt.src = elt.src.replace(/checkbox_(.)*.gif/i,"checkbox_disabled.gif");
  275. dojo.attr(elt,"class","hiddenEntryIcon");
  276. dojo.attr(elt,"tabindex","-1");
  277. elt.disabled = true;
  278. elt.setAttribute("aria-disabled","true");
  279. elt.setAttribute("aria-checked","undefined");
  280. this.disableAllTogglerState(true);
  281. break;
  282. case com.cognos.admin.util.Tools.ThreeCheckbox.UNCHECKED:
  283. elt.setAttribute("aria-checked","false");
  284. default:
  285. elt.src = elt.src.replace(/checkbox_(.)*.gif/i,"checkbox_unchecked.gif");
  286. elt.setAttribute("aria-checked","false");
  287. }
  288. }
  289. };
  290. com.cognos.admin.util.Tools.revertImg = function (elt,dsp){
  291. if (elt.src) {
  292. if (dsp == true) {
  293. elt.src = elt.src.replace(/expand.gif/i,"collapse.gif");
  294. }
  295. else if (dsp == false) elt.src = elt.src.replace(/collapse.gif/i,"expand.gif");
  296. else {
  297. if (elt.src.search(/collapse.gif/i) != -1){
  298. elt.src = elt.src.replace(/collapse.gif/i,"expand.gif");
  299. dsp = false;
  300. } else if (elt.src.search(/expand.gif/i) != -1){
  301. elt.src = elt.src.replace(/expand.gif/i,"collapse.gif");
  302. dsp = true;
  303. } else {
  304. throw new Error ("the element is not a toggle image.");
  305. }
  306. }
  307. return dsp;
  308. }
  309. };
  310. com.cognos.admin.util.Tools.getLevelById = function (pre,id) {
  311. var retLevel = 0;
  312. if (id && _F_Array.indexOf(id,pre) == 0) {
  313. //following the naming convention, id ******_row_1
  314. retLevel = id.substring(pre.length,id.length).split("_").length - 2;
  315. }
  316. return retLevel;
  317. };
  318. //TODO: optimized the match process to meet the high performence require for toggle all event.
  319. com.cognos.admin.util.Tools.GetElementsById = function (exp,scope,isReg,excludedIds) {
  320. this.scope = scope || document.body;
  321. this.isReg = isReg;
  322. this.excludedIds = excludedIds || [];
  323. this.selectedElements = [];
  324. this.flag = false;
  325. this.n = 0;
  326. if (exp instanceof Array)
  327. this.exp = exp.join("|");
  328. else
  329. this.exp = exp;
  330. if (this.isReg){
  331. this.isMatch = function (targetId){
  332. var rExp = new RegExp (this.exp);
  333. if (rExp.test(targetId))
  334. return true;
  335. else
  336. return false;
  337. };
  338. } else {
  339. this.isMatch = function (targetId){
  340. return (_F_Array.indexOf(targetId,this.exp) != -1) ? true : false;
  341. };
  342. };
  343. };
  344. com.cognos.admin.util.Tools.GetElementsById.prototype = {
  345. reset : function () {
  346. this.selectedElements = []
  347. },
  348. getElt : function (rElt){
  349. if (!this.exp){
  350. return [];
  351. }
  352. var rootElt = rElt || this.scope;
  353. if (rootElt.id && (_F_Array.indexOf(this.excludedIds,rootElt.id) == -1) && this.isMatch(rootElt.id)) {
  354. this.selectedElements.push(rootElt);
  355. }
  356. var children = rootElt.childNodes;
  357. for (var i = 0; i < children.length; i++){
  358. if (children[i].nodeType != 1 )
  359. continue;
  360. this.getElt(children[i]);
  361. }
  362. },
  363. getSiblingElt : function (rElt){
  364. if (!this.exp)
  365. return [];
  366. var rootElt = rElt || this.scope;
  367. for (var c = rootElt.firstChild; c!=null; c=c.nextSibling){
  368. if (c.nodeType != 1 ){
  369. continue;
  370. } else if (c.id && (_F_Array.indexOf(this.excludedIds,c.id) == -1) && this.isMatch(c.id)) {
  371. this.selectedElements.push(c);
  372. this.flag = true;
  373. } else if (this.flag) {
  374. return this.selectedElements;
  375. } else {
  376. this.getSiblingElt(c);
  377. }
  378. }
  379. }
  380. };
  381. /* Recipe manager
  382. *
  383. */
  384. com.cognos.admin.util.Tools.Recipe = function () {
  385. this.recipe = [];
  386. };
  387. com.cognos.admin.util.Tools.Recipe.prototype = {
  388. add : function (cogType,fnName,evt,cap){
  389. var cap = cap || false;
  390. var evt = evt.toLowerCase();
  391. this.recipe.push ({cogType:cogType,fnName:fnName,evt:evt,cap:cap});
  392. },
  393. getAll : function (){ return this.recipe;},
  394. init : function () { this.recipe = [];},
  395. /**
  396. * helper to add mouseover/out recipe
  397. */
  398. enableAction : function (cogType){
  399. if (cogType){
  400. this.add (cogType,"mouseOverLink","init");
  401. this.add (cogType,"mouseOverElt","mouseover");
  402. this.add (cogType,"mouseOutElt","mouseout");
  403. this.add (cogType,"mouseClickElt","click");
  404. this.add (cogType,"mouseDownElt","mousedown");
  405. this.add (cogType,"mouseUpElt","mouseup");
  406. this.add (cogType,"doAction","click");
  407. this.add (cogType,"doAction","keypress");
  408. }
  409. }
  410. };
  411. com.cognos.admin.util.Tools.uniqueID = (function() {
  412. var id = 0;
  413. return function() { return id++; };
  414. })();
  415. //wrapper function around dojox.json.ref
  416. com.cognos.admin.util.Tools.JSON = function () {
  417. return {
  418. stringify : function (value){
  419. return dojox.json.ref.toJson(value);
  420. },
  421. parse : function(value){
  422. if (/^[\],:{}\s]*$/.test(value.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  423. return eval('(' + value + ')');
  424. }
  425. throw new SyntaxError('com.cognos.admin.util.Tools.JSON.parse');
  426. }
  427. };
  428. }();
  429. /**
  430. * Parse the XML document contained in the string argument and return
  431. * a Document object that represents it.
  432. */
  433. com.cognos.admin.util.Tools.XMLParse = function(text) {
  434. if (typeof DOMParser != "undefined") {
  435. // Mozilla, Firefox, and related browsers
  436. return (new DOMParser( )).parseFromString(text, "application/xml");
  437. }
  438. else if (typeof ActiveXObject != "undefined") {
  439. var doc = new ActiveXObject("MSXML2.DOMDocument"); // Create an empty document
  440. doc.loadXML(text); // Parse text into it
  441. return doc; // Return it
  442. }
  443. };
  444. /**
  445. * Parse the function name (e.g. "a.b.c") to a real function
  446. *
  447. */
  448. com.cognos.admin.util.Tools.fnParse = function(fnName,args) {
  449. if (typeof fnName != "string") return null;
  450. var obj = window;
  451. var arrFn = fnName.toString().split(".");
  452. for (var i=0; i<arrFn.length-1; i++){
  453. obj = obj[arrFn[i]];
  454. }
  455. return obj[arrFn[arrFn.length-1]].apply(obj,args);
  456. };
  457. /*
  458. * JavaScript eval wrapper
  459. *
  460. */
  461. //TODO: add a prefix and/or suffix to the JSON considering the security issue, when the server side code is ready.
  462. com.cognos.admin.util.Tools.cogEval = function (target){
  463. var strJSON = "";
  464. //for cogAdmin specific attribute
  465. if (typeof target == "object" && target.getAttribute("cogParam"))
  466. strJSON = target.getAttribute("cogParam");
  467. //for JSON object
  468. else if (typeof target == "string" && target.search(/^\s*{/) != -1)
  469. strJSON = target;
  470. //for XML generated by Fragment
  471. else if (typeof target == "string" && target.search(/<fragment>/i) != -1){
  472. var oXml = com.cognos.admin.util.Tools.XMLParse(target);
  473. var oMarkup;
  474. if (oXml){
  475. oMarkup = oXml.getElementsByTagName("markupString")[0];
  476. if (!oMarkup){
  477. oMarkup = oXml.getElementsByTagName("markupXml")[0];
  478. if (!oMarkup){
  479. oMarkup = oXml.getElementsByTagName("error")[0];
  480. }
  481. }
  482. if (oMarkup){
  483. var json = oMarkup.getElementsByTagName("json")[0];
  484. if (json) {
  485. strJSON = json.firstChild.nodeValue;
  486. }
  487. }
  488. }
  489. }
  490. if (com.cognos.admin.config.debug){
  491. _F_log ("D","JSON from cogParam:");
  492. _F_log ("D",strJSON);
  493. }
  494. if (strJSON) {
  495. try {
  496. return com.cognos.admin.util.Tools.JSON.parse(strJSON);
  497. } catch (ex) {
  498. _F_log("E",ex.message);
  499. return null;
  500. }
  501. } else {
  502. return oMarkup;
  503. }
  504. };
  505. com.cognos.admin.util.Tools.parseContent = function (objJSON,containerId,state){
  506. var retHTML = "";
  507. if (!$(containerId)){
  508. var contentId = "cogadmin_newcreated_content_"+com.cognos.admin.util.Tools.uniqueID();
  509. container = document.createElement("div");
  510. container.id = contentId;
  511. container.style.display = "none";
  512. containerId = container.id;
  513. document.body.appendChild(container);
  514. }
  515. switch (objJSON.type) {
  516. case "JSON":
  517. retHTML += "<table style=\"font-size:8pt\">";
  518. if (objJSON.content){
  519. for (var i = 0; i < objJSON.content.length; i++){
  520. var textHTML = "<tr><td style=\"white-space: nowrap; vertical-align:middle; padding-right: 10px;\">&nbsp;<img src=\"" + com.cognos.admin.WEBCONTENT + objJSON.content[i].image + "\" border=\"0\" alt=\""+objJSON.content[i].text+"\"/>&nbsp;"+objJSON.content[i].text+"</td></tr>";
  521. if (!objJSON.content[i].caption || (i>0 && objJSON.content[i].caption == objJSON.content[i-1].caption)){
  522. retHTML += textHTML;
  523. } else {
  524. retHTML += "<tr><td style=\"white-space: nowrap;\" class=\"popup-tooltip-label\">" + objJSON.content[i].caption + "</td></tr>";
  525. retHTML += textHTML;
  526. }
  527. }
  528. }
  529. retHTML += "</table>";
  530. $(containerId).innerHTML = retHTML;
  531. break;
  532. case "fragment":
  533. if (objJSON.url){
  534. var fragId = "cogadmin_newcreated_fragment_"+com.cognos.admin.util.Tools.uniqueID();
  535. var dFragment = new fragment(objJSON.url,fragId,containerId);
  536. dFragment.retrieve((objJSON.param ? encodeURI(objJSON.param) +"&" : '')+state.getStateURL());
  537. retHTML = $(containerId).innerHTML;
  538. } else {
  539. var fragId = objJSON.targetFragID;
  540. retHTML = $(fragId+"cog_controlled_div").innerHTML;
  541. $(containerId).innerHTML = retHTML;
  542. }
  543. break;
  544. case "xts":
  545. var iframe = xCreateElement("iframe");
  546. iframe.src = sGateway + '?b_action=xts.run&m=' + objJSON.src;
  547. iframe.frameborder = 0;
  548. iframe.width = "100%";
  549. iframe.height = "100%";
  550. iframe.marginheight = 0;
  551. iframe.marginwidth = 0;
  552. iframe.scrolling = "no";
  553. xAppendChild($(containerId),iframe);
  554. retHTML = iframe.document.body.innerHTML;
  555. case "AJAX":
  556. if (objJSON.url){
  557. var a = new com.cognos.admin.util.Tools.ajaxObj();
  558. a.setUrl (objJSON.url);
  559. if (objJSON.method)
  560. a.setMethod (objJSON.method);
  561. if (objJSON.parameters)
  562. a.setParameters (objJSON.parameters);
  563. a.onSuccess = function(transport) {
  564. retHTML = transport.responseText;
  565. $(containerId).innerHTML = retHTML;
  566. };
  567. a.run();
  568. $(containerId).innerHTML = "loading...";
  569. }
  570. default:
  571. }
  572. return retHTML;
  573. };
  574. /*
  575. *
  576. */
  577. com.cognos.admin.util.Tools.getKey = function (tag) {
  578. var initParam = com.cognos.admin.util.Tools.cogEval(tag);
  579. var ret = "";
  580. if (tag.getAttribute("key")){
  581. ret = tag.getAttribute("key");
  582. } else if (initParam && initParam["key"]){
  583. ret = initParam["key"];
  584. } else {
  585. var elt = tag;
  586. while (elt = xParent(elt,true)){
  587. if (elt.nodeType==1 && elt.getAttribute("key")){
  588. ret = elt.getAttribute("key");
  589. break;
  590. }
  591. }
  592. }
  593. return ret;
  594. };
  595. /*
  596. *
  597. */
  598. com.cognos.admin.util.Tools.generateQueryString = function (currentString,newName,newValue,ignoreEmptyValues) {
  599. if (!currentString) {
  600. currentString="";
  601. }
  602. if (newName) {
  603. if (ignoreEmptyValues && (!newValue || newValue.length == 0)) {
  604. return currentString;
  605. }
  606. if (currentString.length > 0) {
  607. currentString+="&";
  608. }
  609. return currentString+newName+"="+encodeURIComponent(newValue);
  610. }
  611. return currentString;
  612. }
  613. com.cognos.admin.util.Tools.dspOpacity = function (objectId,opacity,isFadeIn){
  614. var obj = $(objectId);
  615. xOpacity(obj,opacity/100);
  616. if (opacity == 0)
  617. obj.style.display = (isFadeIn) ? "" : "none";
  618. };
  619. /*
  620. * Adjust the cogadmin table's height to fit the fragment properly
  621. * @param outterTable string or object, usually refers to the Fragment container
  622. * @param innerTable string or object, refers to the container you want to adjust the height
  623. * @param windowState maximized/normal/minimized, refers to Fragment window statate.
  624. * @param numRow (integer,default:1) the number of the vertical fragment
  625. */
  626. com.cognos.admin.util.Tools.adjustTableHeight = function (outterTable,innerTable,windowState,numRow){
  627. var PAGELET_TOP_HEIGHT = 60;
  628. var FRAGMENT_MIN_HEIGHT = 500;
  629. var FRAGMENT_TOP_HEIGHT = 34;
  630. var defaultPageletHeight = (xClientHeight() < FRAGMENT_MIN_HEIGHT) ? FRAGMENT_MIN_HEIGHT : xClientHeight()-PAGELET_TOP_HEIGHT;
  631. var oTable = $(outterTable);
  632. var iTable = $(innerTable);
  633. var fragmentOtherHeight = (xHeight(iTable) && xHeight(oTable)) ? (xHeight(oTable) - xHeight(iTable) + 2) : 85;
  634. var num = numRow || 1;
  635. if (!oTable || !iTable){
  636. if (com.cognos.admin.config.debug){
  637. _F_log('D','One of the containers or both is not defined.');
  638. }
  639. return false;
  640. }
  641. switch (windowState){
  642. case "maximized":
  643. xHeight(iTable,defaultPageletHeight - fragmentOtherHeight);
  644. break;
  645. case "extended":
  646. xHeight(iTable,defaultPageletHeight - FRAGMENT_TOP_HEIGHT - fragmentOtherHeight);
  647. break;
  648. case "normal":
  649. default:
  650. xHeight(iTable,(defaultPageletHeight/num) - fragmentOtherHeight);
  651. }
  652. };
  653. com.cognos.admin.util.Tools.includeClass = function includeClass(elt,cName) {
  654. var elt = xGetElementById(elt);
  655. if (elt && elt.className){
  656. var reg = new RegExp("(^|\\s)"+cName+"(\\s|$)");
  657. return reg.test(elt.className);
  658. } else {
  659. return false;
  660. }
  661. }
  662. /*
  663. * Adjust the destination table's td width with the original table
  664. *
  665. * @param oriTable original table, could be a table's id or obj
  666. * @param desTable destination table.
  667. * @return "true" if adjustment applied, "false" otherwise.
  668. *
  669. * Currently reserved for the furture use (partially finished)
  670. */
  671. com.cognos.admin.util.Tools.adjustTdWidth = function (oriTable, desTable){
  672. var oTable = (typeof oriTable == "object") ? oriTable : $(oriTable);
  673. var dTable = (typeof desTable == "object") ? desTable : $(desTable);
  674. if (!oTable || !dTable){
  675. if (com.cognos.admin.config.debug){
  676. _F_log('D','One of the table or both is not defined.');
  677. }
  678. return false;
  679. }
  680. var firstOrow = oTable.rows[0].childNodes;
  681. var firstDrow = dTable.rows[0].childNodes;
  682. if (firstOrow.length == firstDrow.length){
  683. for (var i = 0; i < firstOrow.length; i++){
  684. if (firstDrow[i].nodeType == 1)
  685. xWidth(firstDrow[i],xWidth(firstOrow[i]));
  686. }
  687. } else {
  688. //TODO: Implement the case when table has a unmatched number of td
  689. }
  690. };
  691. //**************************Fragment wrapper begin*****************************************/
  692. com.cognos.admin.util.Tools.addFrgEvtListener = function (fragment, key, listener) {
  693. fragment.addEventListener("com.cognos.admin" + key, listener);
  694. };
  695. com.cognos.admin.util.Tools.removeFrgEvtListener = function (fragment, key, listener) {
  696. fragment.removeEventListener("com.cognos.admin" + key, listener);
  697. };
  698. com.cognos.admin.util.Tools.raiseFrgEvt = function (fragment, key, payload) {
  699. fragment.raiseEvent("com.cognos.admin" + key, payload);
  700. };
  701. /* @fragID: The ID for the fragment that will get created
  702. * @divID: The ID of the div that will get updated by the fragment
  703. * @targetURL: parameters that will get added to the URL. Should NOT start with &, can be either a xts call or path of
  704. * cogadmin pipleline.
  705. */
  706. com.cognos.admin.util.Tools.createFragment = function (targetURL,fragID, divID) {
  707. var fragContext = [];
  708. fragContext.path = encodeURI(targetURL);
  709. fragContext.id = fragID;
  710. fragContext.div = divID;
  711. return _F_attach(fragContext);
  712. };
  713. /*
  714. *
  715. */
  716. com.cognos.admin.util.Tools.createTransient = function (name, value, scope, channel) {
  717. var t = [];
  718. t["name"] = name
  719. t["scope"] = scope;
  720. t["channel"] = channel;
  721. t["value"] = value;
  722. return t;
  723. };
  724. com.cognos.admin.util.Tools.ajaxObj = function (){
  725. this.url = "";
  726. this.method = "post";
  727. this.text = "";
  728. this.xml = "";
  729. this.JSON = "";
  730. this.parameters;
  731. this.onSuccess;
  732. this.onFailure;
  733. this.onGoing;
  734. };
  735. com.cognos.admin.util.Tools.ajaxObj.prototype = {
  736. setUrl : function (url){
  737. this.url = url;
  738. },
  739. setMethod : function (method){
  740. this.method = method;
  741. },
  742. setParameters : function (parameters){
  743. this.parameters = parameters;
  744. },
  745. run : function (){
  746. var option = {};
  747. if (this.method)
  748. option.method = this.method;
  749. if (this.parameters)
  750. option.parameters = this.parameters;
  751. if (typeof this.onSuccess == "function")
  752. option.onSuccess = this.onSuccess;
  753. if (typeof this.onFailure == "function"){
  754. option.onFailure = this.onFailure;
  755. } else {
  756. option.onFailure = function () {
  757. _F_log ("E", "Loading failed!");
  758. }
  759. }
  760. var a = new _F_Ajax.Request(this.url,option);
  761. if (typeof this.onGoing == "function"){
  762. this.onGoing();
  763. } else {
  764. if (com.cognos.admin.config.debug)
  765. _F_log ("I", "Loading... from " + this.url);
  766. }
  767. },
  768. getXml : function () {
  769. return this.xml;
  770. },
  771. getText : function () {
  772. return this.text;
  773. },
  774. getJSON : function () {
  775. return this.JSON;
  776. }
  777. };
  778. //**************************Fragment wrapper end*****************************************/