CReportSelectionController.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 CReportSelectionController()
  14. {
  15. this.m_aSelectedObjects = new Array();
  16. this.m_oObserver = new CObserver(this);
  17. };
  18. CReportSelectionController.prototype.select = function(oSelectionObject, evt)
  19. {
  20. var iCount = -1;
  21. for (var i = 0; i < this.getSelections().length; i++)
  22. {
  23. if (this.getSelections()[i].m_sType == oSelectionObject.m_sType)
  24. {
  25. iCount = i;
  26. break;
  27. }
  28. }
  29. if (evt !== null && evt.ctrlKey === false && evt.shiftKey === false)
  30. {
  31. this.clearSelections();
  32. }
  33. if (iCount !== -1 && evt !== null)
  34. {
  35. this.deselect(this.getSelections()[iCount]);
  36. }
  37. else
  38. {
  39. var o = oSelectionObject.m_oElement;
  40. if (o.getAttribute("oldClassName") === null)
  41. {
  42. o.setAttribute("oldClassName", o.className);
  43. }
  44. o.className += " primarySelection";
  45. this.m_aSelectedObjects[this.getSelections().length] = oSelectionObject;
  46. this.onSelectionChange();
  47. }
  48. };
  49. CReportSelectionController.prototype.getSelections = function()
  50. {
  51. return this.m_aSelectedObjects;
  52. };
  53. CReportSelectionController.prototype.clearSelections = function()
  54. {
  55. if (this.getSelections().length > 0)
  56. {
  57. for (var i = 0; i < this.getSelections().length; i++)
  58. {
  59. var o = this.getSelections()[i].m_oElement;
  60. var oldClass = o.getAttribute("oldClassName");
  61. if (oldClass !== null)
  62. {
  63. o.className = oldClass;
  64. }
  65. }
  66. this.m_aSelectedObjects = new Array();
  67. this.onSelectionChange();
  68. }
  69. };
  70. CReportSelectionController.prototype.reselect = function()
  71. {
  72. for (var i = 0; i < this.getSelections().length; i++)
  73. {
  74. var o = this.getSelections()[i].m_oElement;
  75. if (o !== null)
  76. {
  77. o.className += " primarySelection";
  78. }
  79. }
  80. };
  81. CReportSelectionController.prototype.deselect = function(oSelectionObject)
  82. {
  83. if (this.getSelections().length > 0)
  84. {
  85. var o = oSelectionObject.m_oElement;
  86. o.className = o.getAttribute("oldClassName");
  87. if (this.getSelections().length === 1)
  88. {
  89. this.clearSelections();
  90. }
  91. else
  92. {
  93. var newArray = new Array();
  94. for (var i = 0; i < this.getSelections().length; i++)
  95. {
  96. if (this.getSelections()[i].m_oElement.id != o.id)
  97. {
  98. newArray[newArray.length] = this.getSelections()[i];
  99. }
  100. }
  101. this.m_aSelectedObjects = newArray;
  102. this.onSelectionChange();
  103. }
  104. }
  105. };
  106. CReportSelectionController.prototype.getObservers = function()
  107. {
  108. return this.m_oObserver;
  109. };
  110. CReportSelectionController.prototype.attachObserver = function(observer)
  111. {
  112. this.m_oObserver.attach(observer);
  113. };
  114. CReportSelectionController.prototype.onSelectionChange = function()
  115. {
  116. this.getObservers().notify();
  117. };
  118. var g_reportSelectionController = new CReportSelectionController();