StateManager.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright (c) Business Objects 2006. All rights reserved. */
  2. /**
  3. * Constructor. StateManager holds state for multiple viewers.
  4. */
  5. bobj.crv.StateManager = function() {
  6. this._state = {};
  7. };
  8. bobj.crv.StateManager.prototype = {
  9. /**
  10. * Set the state object for a report view
  11. *
  12. * @param viewerName [String]
  13. * @param stateName [String] The name of the report view
  14. * @param viewState [Object] The state associated with the report view
  15. */
  16. setViewState: function(viewerName, stateName, viewState) {
  17. var state = this._state;
  18. if (!state[viewerName]) {
  19. state[viewerName] = {};
  20. }
  21. state[viewerName][stateName] = viewState;
  22. },
  23. /**
  24. * Get the state object for a report view
  25. *
  26. * @param viewerName [String]
  27. * @param stateName [String] The name of the report view
  28. *
  29. * @return [Object] Returns the state object for the report view or null
  30. * if no object is associated with (viewerName, stateName)
  31. */
  32. getViewState: function(viewerName, stateName) {
  33. var state = this._state;
  34. if (!state[viewerName]) {
  35. return null;
  36. }
  37. return state[viewerName][stateName];
  38. },
  39. /**
  40. * Set the compound state object for a viewer components. This object
  41. * should contain a state object for every report view displayed by the
  42. * viewer.
  43. *
  44. * @param viewerName [String]
  45. * @param state [Object] All report view states for the viewer
  46. */
  47. setComponentState: function(viewerName, state) {
  48. this._state[viewerName] = state;
  49. },
  50. /**
  51. * Get the compound state object for a viewer component. This object
  52. * should contain a state object for every report view displayed by the
  53. * viewer.
  54. *
  55. * @param viewerName [String]
  56. *
  57. * @return [Object] Returns all report view states for the viewer
  58. */
  59. getComponentState: function(viewerName) {
  60. return this._state[viewerName];
  61. },
  62. /**
  63. * Get the state for all viewer components on the page.
  64. *
  65. * @return [Object] Returns the state of all viewers on the page, mapped
  66. * by the id of the viewer widgets.
  67. */
  68. getCompositeState: function() {
  69. return this._state;
  70. }
  71. };
  72. // Create a single StateManager for all viewers in the page to share
  73. if (typeof bobj.crv.viewerState == 'undefined') {
  74. bobj.crv.stateManager = new bobj.crv.StateManager();
  75. }