cwApi.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *|
  5. *| IBM Cognos Products: BUX
  6. *|
  7. *| (C) Copyright IBM Corp. 2013
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or
  10. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. if (!window.cwApi) {(function () {
  14. function _getCMStr(p){
  15. var sCM = null;
  16. if (p.workspaceId) {
  17. sCM = "id/" + p.workspaceId;
  18. } else if (p.workspacePath) {
  19. sCM = "path/" + p.workspacePath;
  20. }
  21. return sCM;
  22. }
  23. window.cwApi = function(p, container, fCallback) {
  24. var c = document.getElementById(container);
  25. if (!c) {
  26. return null;
  27. }
  28. c.innerHTML = ""; // clear everything from the container
  29. var nIframe = document.createElement('iframe');
  30. c.appendChild(nIframe);
  31. var sUrl = p.baseurl + "?b_action=icd";
  32. var sCM = _getCMStr(p);
  33. var temp = null;
  34. if(p.baseurl) {
  35. temp = p.baseurl;
  36. temp = temp.replace(/^[^\/]*(?:\/[^\/]*){2}/, "");
  37. p.rbase = temp;
  38. }
  39. if (sCM && temp) {
  40. sUrl += "&src=" + encodeURIComponent(temp + "/icd/feeds/cm/" + sCM + "?entry=");
  41. } else {
  42. sUrl += "&ui.action=new";
  43. }
  44. if (p.profile) {
  45. sUrl += "&profile=" + p.profile;
  46. }
  47. if (p.remUI) {
  48. sUrl += "&remUI=" + p.remUI;
  49. }
  50. if (p.api) {
  51. sUrl += "&api=" + p.api;
  52. }
  53. if (p.container) {
  54. sUrl += "&container=" + p.container;
  55. }
  56. if( p.debug ) {
  57. sUrl += "&debug=true";
  58. }
  59. nIframe.setAttribute( "style", typeof p.style == "string" ? p.style : "width:100%;height:100%;border:0" );
  60. // TODO: inline
  61. var m = {};
  62. if (p.listenTo) {
  63. for (var i=0,handle; handle = p.listenTo[i]; i++) {
  64. m[ [handle[0],handle[1]].join() ] = handle[2];
  65. }
  66. }
  67. nIframe.setAttribute("src", sUrl);
  68. var oApi = {
  69. config: p,
  70. _the_frame: nIframe,
  71. listenToMap: m,
  72. info: function() {
  73. alert("\t\t-- CW API --\n\nload() needs baseurl,(workspace)id|path,profile?,userRole?\nunload - tbd");
  74. },
  75. invoke: function(wcType, action, oParam) {
  76. // TODO: make it work with postMessage.
  77. //this._the_frame.contentWindow.postMessage(msg, '*');
  78. this._the_frame.contentWindow.buxApi(wcType, action, oParam);
  79. },
  80. load: function(oParam) {
  81. // TODO: make it work with postMessage.
  82. //this._the_frame.contentWindow.postMessage(msg, '*');
  83. if(oParam && this.config.rbase) {
  84. var sCM = _getCMStr(oParam);
  85. if( sCM ) {
  86. var p = {
  87. 'sSource': this.config.rbase + "/icd/feeds/cm/" + sCM + "?entry=",
  88. 'oParam' : oParam
  89. };
  90. this._the_frame.contentWindow.buxApi("workspace", "load", p);
  91. }
  92. }
  93. },
  94. _inspect: function(oParam) {
  95. return this._the_frame.contentWindow.buxApi("app","_inspect", oParam);
  96. },
  97. unload: function() {
  98. this._the_frame.contentWindow.buxApi("workspace", "unload");
  99. }
  100. };
  101. window["cwApi_" + p.api] = oApi;
  102. if (fCallback) {
  103. setTimeout(function(){fCallback(oApi);},1);
  104. }
  105. return oApi;
  106. };
  107. })();}