parameter.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2011
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. @fileOverview Managing Prompts.
  14. @namespace cognos.Prompt
  15. */
  16. /**
  17. @constructor
  18. @class Prompting Parameter
  19. */
  20. cognos.Prompt.Parameter = function(sName)
  21. {
  22. this.m_aControls = [];
  23. this.m_aValues = [];
  24. this.m_sName = sName;
  25. };
  26. /**
  27. @param {cognos.Value[]} aValues Values to add to this parameter.
  28. @return {void}
  29. */
  30. cognos.Prompt.Parameter.prototype.addValues = function(aValues) { this.m_aValues = this.m_aValues.concat(aValues); };
  31. /**
  32. Clear all values for this parameter. Does not update the controls associated to this parameter.
  33. @return {void}
  34. */
  35. cognos.Prompt.Parameter.prototype.clearValues = function() { this.m_aValues = []; };
  36. /**
  37. @private
  38. @param {cognos.Prompt.Control} oControl
  39. @return {void}
  40. */
  41. cognos.Prompt.Parameter.prototype.f_addControl = function(oControl)
  42. {
  43. this.m_aControls.push( oControl );
  44. };
  45. /**
  46. Returns an array of all controls associated to this parameter.
  47. @return {cognos.Prompt.Control[]}
  48. */
  49. cognos.Prompt.Parameter.prototype.getControls = function() { return this.m_aControls; };
  50. /**
  51. Returns the parameter's name.
  52. @return {String}
  53. */
  54. cognos.Prompt.Parameter.prototype.getName = function() { return this.m_sName; };
  55. /**
  56. Returns all values for this parameter.
  57. @return {cognos.Value[]}
  58. */
  59. cognos.Prompt.Parameter.prototype.getValues = function()
  60. {
  61. var v_aValues = this.m_aValues;
  62. var v_aControls = this.getControls();
  63. for (var v_idx = 0; v_idx < v_aControls.length; v_idx++)
  64. {
  65. var v_oControl = v_aControls[v_idx];
  66. if ( v_oControl.isValid() )
  67. {
  68. v_aValues = v_aValues.concat(v_oControl.getValues());
  69. }
  70. }
  71. return v_aValues;
  72. };
  73. /**
  74. Returns all values for this parameter in XML form.
  75. @private
  76. @return {String}
  77. */
  78. cognos.Prompt.Parameter.prototype.getXML = function()
  79. {
  80. var v_aXML = ["<selectChoices>"];
  81. var v_aValues = this.getValues();
  82. for (var v_idx = 0; v_idx < v_aValues.length; v_idx++)
  83. {
  84. v_aXML.push( cognos.Value.toXML(v_aValues[v_idx]) );
  85. }
  86. v_aXML.push( "</selectChoices>" );
  87. return v_aXML.join(K_PRMT_sEMPTY);
  88. };
  89. /**
  90. Check if this parameter is satisfied.
  91. @private
  92. @return {boolean}
  93. */
  94. cognos.Prompt.Parameter.prototype.isValid = function()
  95. {
  96. return ( this.isRequired() && (this.getValues().length == 0) ? false : true );
  97. };
  98. /**
  99. Currently the <i>required</i> is handled by the controls.
  100. @private
  101. @return {boolean}
  102. */
  103. cognos.Prompt.Parameter.prototype.isRequired = function()
  104. {
  105. var v_bRequired = false;
  106. for (var v_idx = 0; v_idx < this.m_aControls.length; v_idx++)
  107. {
  108. v_bRequired = (v_bRequired || this.m_aControls[v_idx].isRequired());
  109. }
  110. return v_bRequired;
  111. };