CQSMenuItem.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** BI and PM: qs
  5. **
  6. ** (C) Copyright IBM Corp. 2001, 2015
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or
  9. ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *****************************************************************/
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All Rights Reserved.
  12. // Cognos and the Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated) in the United States and/or other countries. IBM and the IBM logo are trademarks of International Business Machines Corporation in the United States, or other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
  13. function CQSMenuItem(parent, label, action, iconPath, style, webContentRoot, skin)
  14. {
  15. CMenuItem.call(this, parent, label, action, iconPath, style, webContentRoot, skin);
  16. this.m_sIconPrecedingText = null;
  17. this.m_sIconTrailingText = null;
  18. this.m_aDisabledNodeTypes = new Object();
  19. this.m_bDisabledOnMultipleSelect = false;
  20. };
  21. function CQSMenuItem_setIconPrecedingText(sString)
  22. {
  23. if (sString && typeof sString == "string")
  24. {
  25. this.m_sIconPrecedingText = sString;
  26. }
  27. };
  28. function CQSMenuItem_setIconTrailingText(sString)
  29. {
  30. if (sString && typeof sString == "string")
  31. {
  32. this.m_sIconTrailingText = sString;
  33. }
  34. };
  35. function CQSMenuItem_draw()
  36. {
  37. var html = '<div>';
  38. var bSiblingContainsIcon = false, siblingCount = null, siblingMenuItem = null, siblingIdx = 0;
  39. if(this.m_menu == null || this.m_menuType=='dropDown') {
  40. html += '<table';
  41. if (this.isEnabled())
  42. {
  43. if (this.isInMenu())
  44. {
  45. html += ' hideFocus="true" ';
  46. }
  47. html += ' tabIndex="0" accessKey="1"';
  48. }
  49. html += ' width="100%" ';
  50. html += 'class="';
  51. if(typeof this.getStyle() == "object") {
  52. if(this.isEnabled()) {
  53. html += this.getStyle().getNormalState();
  54. }
  55. else {
  56. html += this.getStyle().getDisabledState();
  57. }
  58. }
  59. html += '" id="';
  60. html += this.getId();
  61. html += '" cellpadding="0" cellspacing="0" style="margin-bottom:1px;"><tr>';
  62. bSiblingContainsIcon = false;
  63. if(this.m_icon.getPath() == '' && this.m_parent instanceof CMenu) {
  64. siblingCount = this.m_parent.getNumItems();
  65. for(siblingIdx = 0; siblingIdx < siblingCount; ++siblingIdx) {
  66. siblingMenuItem = this.m_parent.get(siblingIdx);
  67. if(typeof siblingMenuItem.getIcon == "function" && siblingMenuItem.getIcon().getPath()) {
  68. bSiblingContainsIcon = true;
  69. break;
  70. }
  71. }
  72. }
  73. if(bSiblingContainsIcon || this.m_icon.getPath() != '')
  74. {
  75. html += '<td width="16" style="padding-right: 2px; padding-left: 2px;">';
  76. if(this.m_icon.getPath() != '')
  77. {
  78. html += this.m_icon.draw();
  79. }
  80. else
  81. {
  82. html += '<img src="' + this.m_webContentRoot + '/common/images/spacer.gif" width="16"/>';
  83. }
  84. html += '</td>';
  85. }
  86. html += '<td nowrap="nowrap" align="left">';
  87. if (this.m_sIconPrecedingText != null)
  88. {
  89. html += this.m_sIconPrecedingText;
  90. }
  91. html += this.m_label;
  92. html += '</td>';
  93. if(this.m_menuType=='dropDown')
  94. {
  95. html += '<td width="10%" align="right" style="padding-right: 3px;padding-left: 3px">';
  96. html += '<img src="';
  97. if (this.getDropDownArrow() == 'dropdown_arrow_banner.gif')
  98. {
  99. html += this.m_sSkin + '/shared/images/';
  100. }
  101. else
  102. {
  103. html += this.getDropDownArrow();
  104. }
  105. html += '" WIDTH="7" HEIGHT="16"/>';
  106. html += '</td>';
  107. }
  108. if (this.m_sIconTrailingText != null)
  109. {
  110. html += "<td>" + this.m_sIconTrailingText + "</td>";
  111. }
  112. html += '</tr></table></div>';
  113. } else {
  114. html += '<table';
  115. if (this.isEnabled())
  116. {
  117. html += ' tabIndex="0" hideFocus="true" accessKey="1"';
  118. }
  119. html += ' width="100%" class="';
  120. if(typeof this.getStyle() == "object") {
  121. if(this.isEnabled()) {
  122. html += this.getStyle().getNormalState();
  123. }
  124. else {
  125. html += this.getStyle().getDisabledState();
  126. }
  127. }
  128. html += '" id="';
  129. html += this.getId();
  130. html += '" cellpadding="0" cellspacing="0" style="margin-bottom:1px;"><tr>';
  131. html += '<td';
  132. bSiblingContainsIcon = false;
  133. if(this.m_icon.getPath() == '') {
  134. siblingCount = this.m_parent.getNumItems();
  135. for(siblingIdx = 0; siblingIdx < siblingCount; ++siblingIdx) {
  136. siblingMenuItem = this.m_parent.get(siblingIdx);
  137. if(typeof siblingMenuItem.getIcon == "function" && siblingMenuItem.getIcon().getPath()) {
  138. bSiblingContainsIcon = true;
  139. break;
  140. }
  141. }
  142. }
  143. if(bSiblingContainsIcon || this.m_icon.getPath() != '') {
  144. html += ' width="16" style="padding-right: 2px; padding-left: 2px;">';
  145. } else {
  146. html += ' width="1">';
  147. }
  148. html += this.m_icon.draw();
  149. html += '</td>';
  150. html += '<td nowrap="nowrap" align="left">';
  151. html += this.m_label;
  152. html += '</td>';
  153. html += '<td width="10%" align="right">';
  154. html += '<img src="' + this.m_sSkin + '/viewer/images/menu_expand.gif" WIDTH="13" HEIGHT="13"/>';
  155. html += '</td>';
  156. html += '</tr></table>';
  157. html += '</div>';
  158. }
  159. return html;
  160. };
  161. function CQSMenuItem_setLabel(sLabel)
  162. {
  163. if (sLabel && typeof sLabel == "string")
  164. {
  165. this.m_label = sLabel;
  166. }
  167. };
  168. function CQSMenuItem_setQualityOfService(sQoS)
  169. {
  170. this.m_sQoS = sQoS;
  171. }
  172. function CQSMenuItem_getQualityOfService()
  173. {
  174. if (this.m_sQoS === null || typeof this.m_sQoS === "undefined")
  175. {
  176. this.m_sQoS = "";
  177. }
  178. return this.m_sQoS;
  179. }
  180. function CQSMenuItem_setDisabledNodeType(sNodeType, bIsDisabled)
  181. {
  182. if (typeof bIsDisabled === "undefined")
  183. {
  184. bIsDisabled = true;
  185. }
  186. this.m_aDisabledNodeTypes[sNodeType] = bIsDisabled;
  187. };
  188. function CQSMenuItem_isDisabledNodeType(sNodeType)
  189. {
  190. var bReturn = false;
  191. if (this.m_aDisabledNodeTypes[sNodeType])
  192. {
  193. bReturn = true;
  194. }
  195. return bReturn;
  196. };
  197. function CQSMenuItem_isVisible()
  198. {
  199. var bIsVisible = true;
  200. if (typeof this.getParent === "function" && typeof this.getParent().isVisible === "function")
  201. {
  202. bIsVisible = this.getParent().isVisible.call(this);
  203. }
  204. var sQoS = this.getQualityOfService();
  205. if (bIsVisible && sQoS.length && typeof checkCalcFunctionAgainstDB === "function")
  206. {
  207. bIsVisible = checkCalcFunctionAgainstDB(sQoS);
  208. }
  209. return bIsVisible;
  210. };
  211. function CQSMenuItem_isEnabled()
  212. {
  213. var bIsEnabled = true;
  214. if (typeof metadataTree !== "undefined" && typeof metadataTree === "object")
  215. {
  216. var aNodes = metadataTree.getSelectionOrder();
  217. var iNodeIndex;
  218. for (iNodeIndex=0; iNodeIndex < aNodes.length; iNodeIndex++)
  219. {
  220. if (iNodeIndex > 0 && this.getDisabledOnMultipleSelect())
  221. {
  222. bIsEnabled = false;
  223. break;
  224. }
  225. var oNode = aNodes[iNodeIndex];
  226. if (this.isDisabledNodeType(oNode.nodeMetaType))
  227. {
  228. bIsEnabled = false;
  229. break;
  230. }
  231. }
  232. }
  233. if (bIsEnabled)
  234. {
  235. bIsEnabled = CMenuItem.prototype.isEnabled.call(this);
  236. }
  237. return bIsEnabled;
  238. };
  239. function CQSMenuItem_setDisabledOnMultipleSelect(bDisableOnMultipleSelect)
  240. {
  241. this.m_bDisabledOnMultipleSelect = bDisableOnMultipleSelect;
  242. };
  243. function CQSMenuItem_getDisabledOnMultipleSelect()
  244. {
  245. return this.m_bDisabledOnMultipleSelect;
  246. };
  247. CQSMenuItem.prototype = new CMenuItem();
  248. CQSMenuItem.prototype.setIconPrecedingText = CQSMenuItem_setIconPrecedingText;
  249. CQSMenuItem.prototype.setIconTrailingText = CQSMenuItem_setIconTrailingText;
  250. CQSMenuItem.prototype.setQualityOfService = CQSMenuItem_setQualityOfService;
  251. CQSMenuItem.prototype.getQualityOfService = CQSMenuItem_getQualityOfService;
  252. CQSMenuItem.prototype.draw = CQSMenuItem_draw;
  253. CQSMenuItem.prototype.setLabel = CQSMenuItem_setLabel;
  254. CQSMenuItem.prototype.isVisible = CQSMenuItem_isVisible;
  255. CQSMenuItem.prototype.setDisabledNodeType = CQSMenuItem_setDisabledNodeType;
  256. CQSMenuItem.prototype.isDisabledNodeType = CQSMenuItem_isDisabledNodeType;
  257. CQSMenuItem.prototype.isEnabled = CQSMenuItem_isEnabled;
  258. CQSMenuItem.prototype.setDisabledOnMultipleSelect = CQSMenuItem_setDisabledOnMultipleSelect;
  259. CQSMenuItem.prototype.getDisabledOnMultipleSelect = CQSMenuItem_getDisabledOnMultipleSelect;
  260. function CQSSeparator(type, size, style, webContentRoot)
  261. {
  262. CSeperator.call(this, type, size, style, webContentRoot);
  263. }
  264. CQSSeparator.prototype = new CSeperator();
  265. CQSSeparator.prototype.isVisible = CQSMenuItem.prototype.isVisible;
  266. CQSSeparator.prototype.setQualityOfService = CQSMenuItem.prototype.setQualityOfService;
  267. CQSSeparator.prototype.getQualityOfService = CQSMenuItem.prototype.getQualityOfService;