objectSelect.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. //Licensed Materials - Property of IBM
  2. //IBM Cognos Products: cpscrn
  3. //(C) Copyright IBM Corp. 2013
  4. //US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5. /*
  6. Note: The following must be included in any HTML page using this javascript
  7. <link rel="stylesheet" type="text/css" href="../dojo16/dijit/themes/tundra/pstundra.css" />
  8. <link rel="stylesheet" type="text/css" href="../dojo16/dojox/grid/resources/pstundraGrid.css" />
  9. <link rel="stylesheet" type="text/css" href="../skins/classic/portal/pager.css" />
  10. <link href="/ibmcognos/skins/corporate/portal/default.css" type="text/css" rel="stylesheet">
  11. <script type="text/javascript" src="../dojo16/dojo/dojo.js"></script>
  12. <script type="text/javascript" src="../dojo16/dojo/psdojo.js"></script>
  13. */
  14. function CMObjectSelect(selectorID, parentID, cancelCallback, okCallback, selectionTypes, context){
  15. window[selectorID] = this;
  16. this.context = context;
  17. this.selectorID = selectorID;
  18. this.parentID = parentID;
  19. this.cancelCallback = cancelCallback;
  20. this.okCallback = okCallback;
  21. this.selectionTypes = selectionTypes;
  22. this.selection;
  23. this.objectPager;
  24. this.breadStack = new Array();
  25. this.objectPagerURL = context.getProxiedURI(context.getGatewayURI() + '/atom/cm?json=true');
  26. this.pagerWebcontent = context.getWebContentURI();
  27. }
  28. CMObjectSelect.prototype = {
  29. render:function(){
  30. var selectorDiv = document.createElement("div");
  31. selectorDiv.id = this.selectorID;
  32. //We default the object selector to be hidden
  33. selectorDiv.style.display = "none";
  34. var outerBreadcrumbDiv = document.createElement("div");
  35. var outerPagerDiv = document.createElement("div");
  36. var outerButtonDiv = document.createElement("div");
  37. var breadcrumbDiv = document.createElement("div");
  38. var pagerDiv = document.createElement("div");
  39. var buttonDiv = document.createElement("div");
  40. breadcrumbDiv.id = this.selectorID + "_breadcrumb";
  41. pagerDiv.id = this.selectorID + "_objectPager";
  42. buttonDiv.id = this.selectorID + "_selectbuttons";
  43. outerBreadcrumbDiv.style.padding = "3px";
  44. outerPagerDiv.style.padding = "3px";
  45. outerButtonDiv.style.padding = "3px";
  46. var parent = document.getElementById(this.parentID);
  47. parent.appendChild(selectorDiv);
  48. selectorDiv.appendChild(outerBreadcrumbDiv);
  49. selectorDiv.appendChild(outerPagerDiv);
  50. selectorDiv.appendChild(outerButtonDiv);
  51. outerBreadcrumbDiv.appendChild(breadcrumbDiv);
  52. outerPagerDiv.appendChild(pagerDiv);
  53. outerButtonDiv.appendChild(buttonDiv);
  54. this._initializeBreadcrumb();
  55. this._createPager();
  56. this._createButtons();
  57. },
  58. _cmObject:function(storeID, type, tooltip, iconLink, downloadLink, pathString) {
  59. this.storeID = storeID;
  60. this.type = type;
  61. this.tooltip = tooltip;
  62. this.iconLink = iconLink;
  63. this.downloadLink = downloadLink;
  64. this.pathString = pathString;
  65. },
  66. _createPager:function() {
  67. var objectPagerLayout;
  68. var _self = this;
  69. objectPagerLayout = [
  70. {
  71. field: 'title',
  72. name: 'Select Object',
  73. width: '100%',
  74. formatter: function(data, index) {
  75. var entry = _self.objectPager.getEntry(index);
  76. var storeID = _self._parseStoreID(entry.cm$storeID[0]);
  77. var type = entry.cm$objectClass[0];
  78. var tooltip = data._text;
  79. var iconLink = _self.context.makeAbsolute(_self.pagerWebcontent,_self.objectPager.getEntryLink(entry, 'icon').href);
  80. var downloadLink = "";
  81. if (_self.objectPager.getEntryLink(entry, 'alternate') != undefined && _self.objectPager.getEntryLink(entry, 'alternate').type == "application/atom+xml") {
  82. downloadLink = _self.context.getProxiedURI(_self.context.makeAbsolute(_self.context.getGatewayURI(),_self.objectPager.getEntryLink(entry, 'alternate').href));
  83. }
  84. var burstKey = entry.cm$burstKeyDisplayString[0];
  85. var markup = '<div>';
  86. if (downloadLink != "") {
  87. markup += '<a href="#" onclick="window[\'' + _self.selectorID + '\']._digIntoObject(';
  88. markup += "'" + storeID + "'" + ",";
  89. markup += "'" + type + "'" + ",";
  90. markup += "'" + tooltip + "'" + ",";
  91. markup += "'" + iconLink + "'" + ",";
  92. markup += "'" + downloadLink + "'" + ",";
  93. markup += 'false';
  94. markup += ')" onkeypress="javascript:if (event.keyCode==13 || event.keyCode==32 || event.charCode==32){window[\'' + _self.selectorID + '\']._digIntoObject(';
  95. markup += "'" + storeID + "'" + ",";
  96. markup += "'" + type + "'" + ",";
  97. markup += "'" + tooltip + "'" + ",";
  98. markup += "'" + iconLink + "'" + ",";
  99. markup += "'" + downloadLink + "'" + ",";
  100. markup += 'false';
  101. markup += ');return false;} return true;">';
  102. markup += '<img height="16" width="16" src="' + iconLink+ '" title="' + tooltip + '" style="vertical-align:middle;margin-right: 4px;" />';
  103. markup += '</a>';
  104. markup += '<a href="#" onclick="window[\'' + _self.selectorID + '\']._digIntoObject(';
  105. markup += "'" + storeID + "'" + ",";
  106. markup += "'" + type + "'" + ",";
  107. markup += "'" + tooltip + "'" + ",";
  108. markup += "'" + iconLink + "'" + ",";
  109. markup += "'" + downloadLink + "'" + ",";
  110. markup += 'false';
  111. markup += ')" onkeypress="javascript:if (event.keyCode==13 || event.keyCode==32 || event.charCode==32){window[\'' + _self.selectorID + '\']._digIntoObject(';
  112. markup += "'" + storeID + "'" + ",";
  113. markup += "'" + type + "'" + ",";
  114. markup += "'" + tooltip + "'" + ",";
  115. markup += "'" + iconLink + "'" + ",";
  116. markup += "'" + downloadLink + "'" + ",";
  117. markup += 'false';
  118. markup += ');return false;} return true;">' + tooltip + '</a></div>';
  119. } else {
  120. markup += '<img height="16" width="16" src="' + iconLink + '" title="' + tooltip + '" style="vertical-align:middle;margin-right: 4px;" />';
  121. markup += tooltip + '</div>';
  122. }
  123. return markup;
  124. }
  125. }
  126. ];
  127. this.objectPager = new ps.pager({
  128. id: this.selectorID + '_objectPager',
  129. webcontent: this.pagerWebcontent,
  130. url: this.objectPagerURL,
  131. layoutSpec: objectPagerLayout,
  132. rowAction: dojo.hitch(this, this._updateSelection),
  133. initialRowSelect:true},
  134. this.selectorID + '_objectPager');
  135. var temp = '';
  136. },
  137. _updateSelection:function(entry) {
  138. var downloadLink = "";
  139. if (this.objectPager.getEntryLink(entry, 'alternate') != undefined && this.objectPager.getEntryLink(entry, 'alternate').type == "application/atom+xml") {
  140. downloadLink = this.context.getProxiedURI(this.context.getGatewayURI(),this.objectPager.getEntryLink(entry, 'alternate').href);
  141. }
  142. var pathString = this._buildStringPath();
  143. var cmObj = new this._cmObject(
  144. this._parseStoreID(entry.cm$storeID[0]),
  145. entry.cm$objectClass[0],
  146. entry.title[0]._text,
  147. this.context.makeAbsolute(this.pagerWebcontent,this.objectPager.getEntryLink(entry, 'icon').href),
  148. downloadLink,
  149. pathString
  150. );
  151. this.selection = cmObj;
  152. this._updateOKButton();
  153. },
  154. _createButtons:function() {
  155. var markup = '';
  156. markup += "<table class=\"\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" role=\"presentation\" summary=\"\">";
  157. markup += "<tbody><tr><td width=\"1\" valign=\"middle\">";
  158. markup += "<img width=\"1\" height=\"10\" alt=\"\" src=\"" + this.pagerWebcontent + "/ps/images/space.gif\">";
  159. markup += "</td></tr></tbody></table>";
  160. markup += "<table class=\"dialogButtonBar\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\" role=\"presentation\" summary=\"\">";
  161. markup += "<tbody><tr><td width=\"3\" valign=\"middle\">";
  162. markup += "<img width=\"3\" alt=\"\" src=\"" + this.pagerWebcontent + "/ps/images/space.gif\">";
  163. markup += "</td>";
  164. markup += "<td valign=\"middle\">";
  165. markup += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" role=\"presentation\" summary=\"\">";
  166. markup += "<tbody><tr><td valign=\"middle\" align=\"center\" nowrap=\"\">";
  167. markup += "<img width=\"55\" height=\"1\" alt=\"\" src=\"" + this.pagerWebcontent + "/ps/images/space.gif\"><br>";
  168. markup += "<button id=\"" + this.selectorID + "_obSelOK\" type = \"button\" class=\"commandButton\" style=\"padding-right:10px; padding-left:10px; padding-top:2px; padding-bottom:3px; width:80px;\" \r\n" +
  169. //OK onclick here
  170. " onmousedown=\"this.className = \'commandButtonDown\'\" onmouseout=\"this.className = \'commandButton\'\" onmouseover=\"this.className = \'commandButtonOver\'\" \r\n" +
  171. " onclick=\"window[\'" + this.selectorID + "\']._acceptSelection()\" onkeypress=\"javascript:if( event.keyCode==13 || event.keyCode==32 || event.charCode==32 ){this.onclick(); return false;} return true;\">OK</button>";
  172. markup += "</td>";
  173. markup += "<td><img width=\"10\" height=\"1\" alt=\"\" src=\"" + this.pagerWebcontent + "/ps/images/space.gif\"></td>";
  174. markup += "<td valign=\"middle\" align=\"center\" nowrap=\"\"> ";
  175. markup += "<img width=\"55\" height=\"1\" alt=\"\" src=\"" + this.pagerWebcontent + "/ps/images/space.gif\"><br>";
  176. markup += "<button type = \"button\" class=\"commandButton\" style=\"padding-right:10px; padding-left:10px; padding-top:2px; padding-bottom:3px; width:80px;\" \r\n" +
  177. " onmousedown=\"this.className = \'commandButtonDown\'\" onmouseout=\"this.className = \'commandButton\'\" onmouseover=\"this.className = \'commandButtonOver\'\" \r\n" +
  178. //Cancel onclick here
  179. " onclick=\"window[\'" + this.selectorID + "']._cancelSelection()\" onkeypress=\"javascript:if( event.keyCode==13 || event.keyCode==32 || event.charCode==32 ){this.onclick(); return false;} return true;\">Cancel</button>\r\n";
  180. markup += "</td>";
  181. markup += "<td><img width=\"10\" height=\"1\" alt=\"\" src=\"" + this.pagerWebcontent + "/ps/images/space.gif\"></td>";
  182. markup += "</tr></tbody></table></td>";
  183. markup += "<td width=\"100%\"> </td>";
  184. markup += "</tr></tbody></table>";
  185. document.getElementById(this.selectorID + "_selectbuttons").innerHTML = markup;
  186. },
  187. _parseStoreID:function(originalID) {
  188. var location = originalID.indexOf('\'') + 1;
  189. var newID = originalID.substring(location, originalID.length);
  190. location = newID.indexOf('\'');
  191. newID = newID.substring(0, location);
  192. return newID;
  193. },
  194. _digIntoObject:function(storeID, type, tooltip, iconLink, downloadLink, breadcrumbCall) {
  195. var cmObj = new this._cmObject(storeID, type, tooltip, iconLink, downloadLink);
  196. this._updateBreadcrumb(breadcrumbCall, cmObj);
  197. //update the pager
  198. this.objectPager.getData(downloadLink);
  199. },
  200. _initializeBreadcrumb:function() {
  201. var root = new this._cmObject("","root","Cognos","", this.objectPagerURL);
  202. this.breadStack.push(root);
  203. document.getElementById(this.selectorID + "_breadcrumb").innerHTML = this._buildBreadcrumb();;
  204. },
  205. _buildLink:function(cmObj) {
  206. var markup = '';
  207. markup += '<a href="#" onclick="window[\'' + this.selectorID + '\']._digIntoObject(';
  208. markup += "'" + cmObj.storeID + "'" + ", ";
  209. markup += "'" + cmObj.type + "'" + ", ";
  210. markup += "'" + cmObj.tooltip + "'" + ", ";
  211. markup += "'" + cmObj.iconLink + "'" + ", ";
  212. markup += "'" + cmObj.downloadLink + "'" + ", ";
  213. markup += 'true';
  214. markup += ')" onkeypress="javascript:if (event.keyCode==13 || event.keyCode==32 || event.charCode==32){window[\'' + this.selectorID + '\']._digIntoObject(';;
  215. markup += "'" + cmObj.storeID + "'" + ", ";
  216. markup += "'" + cmObj.type + "'" + ", ";
  217. markup += "'" + cmObj.tooltip + "'" + ", ";
  218. markup += "'" + cmObj.iconLink + "'" + ", ";
  219. markup += "'" + cmObj.downloadLink + "'" + ", ";
  220. markup += 'true';
  221. markup += ');return false;} return true;">' + cmObj.tooltip + '</a>';
  222. return markup;
  223. },
  224. _buildBreadcrumb:function() {
  225. var markup = '';
  226. for(var i = 0; i < this.breadStack.length - 1; i++) {
  227. markup += this._buildLink(this.breadStack[i]);
  228. markup += " > ";
  229. }
  230. markup += this.breadStack[this.breadStack.length - 1].tooltip;
  231. return markup;
  232. },
  233. _buildStringPath:function() {
  234. var markup = '';
  235. for(var i = 0; i < this.breadStack.length; i++) {
  236. markup += this.breadStack[i].tooltip;
  237. markup += " > ";
  238. }
  239. return markup;
  240. },
  241. _updateBreadcrumb:function(isBreadcrumbCall, newCMObj) {
  242. if (isBreadcrumbCall == true) {
  243. var flag = false;
  244. while (flag == false) {
  245. if (this.breadStack.length <= 0) {
  246. break;
  247. }
  248. var crumb = this.breadStack.pop();
  249. if (crumb.storeID == newCMObj.storeID) {
  250. this.breadStack.push(newCMObj);
  251. flag = true;
  252. }
  253. }
  254. }
  255. else {
  256. this.breadStack.push(newCMObj);
  257. }
  258. var breadcrumb = this._buildBreadcrumb();
  259. document.getElementById(this.selectorID + "_breadcrumb").innerHTML = breadcrumb;
  260. },
  261. _updateOKButton:function() {
  262. if (this._arrayContains(this.selectionTypes, this.selection.type)) {
  263. //Allow button to be pressed
  264. document.getElementById(this.selectorID + "_obSelOK").disabled = false;
  265. document.getElementById(this.selectorID + "_obSelOK").setAttribute("class","commandButton");
  266. } else {
  267. //Prevent button from being pressed
  268. document.getElementById(this.selectorID + "_obSelOK").disabled = true;
  269. document.getElementById(this.selectorID + "_obSelOK").setAttribute("class","commandButtonInactive");
  270. }
  271. },
  272. _arrayContains:function(array, item) {
  273. for(var i = 0; i < array.length; i++) {
  274. if (array[i] === item) {
  275. return true;
  276. }
  277. }
  278. return false
  279. },
  280. _cancelSelection:function(){
  281. this.cancelCallback();
  282. },
  283. _acceptSelection:function(){
  284. this.okCallback(new Array(this.selection));
  285. },
  286. //Fixes issue where grid does not appear until window is resized
  287. resizePager:function(){
  288. this.objectPager.grid.resize();
  289. }
  290. }