CUserPreference.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 CUserPreference(sName, bUserOverride)
  14. {
  15. this.m_sName = null;
  16. this.m_sDefaultValue = null;
  17. this.m_sCookieName = null;
  18. this.m_sDialogValue = null;
  19. this.m_bUserOverrideAllowed = true;
  20. this.m_sFormInputName = null;
  21. this.m_oProperties = new CDictionary();
  22. this.setName(sName);
  23. };
  24. CUserPreference.prototype.setName = function (sName)
  25. {
  26. this.m_sName = sName;
  27. };
  28. CUserPreference.prototype.getName = function ()
  29. {
  30. return this.m_sName;
  31. };
  32. CUserPreference.prototype.setDefaultValue = function (sDefaultValue)
  33. {
  34. this.m_sDefaultValue = sDefaultValue;
  35. };
  36. CUserPreference.prototype.getDefaultValue = function ()
  37. {
  38. return this.m_sDefaultValue;
  39. };
  40. CUserPreference.prototype.setCookie = function (sValue)
  41. {
  42. var sType = "qs";
  43. var sCookieName = this.getCookieName();
  44. if (sCookieName && sCookieName.length)
  45. {
  46. if (typeof sValue !== "undefined" && sValue && sValue.length)
  47. {
  48. sValue = encodeURIComponent(sValue);
  49. }
  50. if (typeof sValue === "undefined" || sValue === null)
  51. {
  52. sValue = "";
  53. }
  54. if (sValue === true)
  55. {
  56. sValue = "true";
  57. }
  58. if (sValue === false)
  59. {
  60. sValue = "false";
  61. }
  62. setQSCookie(sType, sCookieName, sValue);
  63. }
  64. };
  65. CUserPreference.prototype.getCookie = function ()
  66. {
  67. var sType = "qs";
  68. var sReturnCookie = "";
  69. var sCookieName = this.getCookieName();
  70. if (sCookieName && sCookieName.length)
  71. {
  72. sReturnCookie = getQSCookie(sType, sCookieName);
  73. }
  74. if (typeof sReturnCookie !== "undefined" && sReturnCookie && sReturnCookie.length)
  75. {
  76. sReturnCookie = decodeURIComponent(sReturnCookie);
  77. }
  78. else
  79. {
  80. sReturnCookie = "";
  81. }
  82. return sReturnCookie;
  83. };
  84. CUserPreference.prototype.setCookieName = function (sCookieName)
  85. {
  86. this.m_sCookieName = sCookieName;
  87. };
  88. CUserPreference.prototype.getCookieName = function (sCookieName)
  89. {
  90. var sCookieName = this.m_sCookieName;
  91. if (!sCookieName)
  92. {
  93. sCookieName = "";
  94. }
  95. return sCookieName;
  96. };
  97. CUserPreference.prototype.setDefaultValue = function (sValue)
  98. {
  99. this.m_sDefaultValue = sValue;
  100. };
  101. CUserPreference.prototype.getDefaultValue = function ()
  102. {
  103. return this.m_sDefaultValue;
  104. };
  105. CUserPreference.prototype.getValue = function ()
  106. {
  107. var sValue = "";
  108. if (this.isUserOverrideAllowed())
  109. {
  110. sValue = this.getDialogValue();
  111. if (! this.isSet(sValue))
  112. {
  113. sValue = this.getCookie();
  114. }
  115. }
  116. if (! this.isSet(sValue))
  117. {
  118. sValue = this.getAdvancedServerValue();
  119. }
  120. if (! this.isSet(sValue))
  121. {
  122. sValue = this.getSystemValue();
  123. }
  124. if (! this.isSet(sValue))
  125. {
  126. sValue = this.getDefaultValue();
  127. }
  128. if (sValue === null || typeof sValue === "undefined")
  129. {
  130. sValue = "";
  131. }
  132. return sValue;
  133. };
  134. CUserPreference.prototype.setDialogValue = function (sValue)
  135. {
  136. this.m_sDialogValue = sValue;
  137. };
  138. CUserPreference.prototype.getDialogValue = function (sValue)
  139. {
  140. return this.m_sDialogValue;
  141. };
  142. CUserPreference.prototype.getSystemValue = function ()
  143. {
  144. return this.m_sSystemValue;
  145. };
  146. CUserPreference.prototype.setSystemValue = function (sValue)
  147. {
  148. this.m_sSystemValue = sValue;
  149. };
  150. CUserPreference.prototype.getAdvancedServerValue = function ()
  151. {
  152. return this.m_sAdvancedServerValue;
  153. };
  154. CUserPreference.prototype.setAdvancedServerValue = function (sValue)
  155. {
  156. this.m_sAdvancedServerValue = sValue;
  157. };
  158. CUserPreference.prototype.isUserOverrideAllowed = function (sValue)
  159. {
  160. return this.m_bUserOverrideAllowed;
  161. };
  162. CUserPreference.prototype.setUserOverrideAllowed = function (bValue)
  163. {
  164. if (typeof bValue === "undefined")
  165. {
  166. bValue = false;
  167. }
  168. this.m_bUserOverrideAllowed = bValue;
  169. };
  170. CUserPreference.prototype.getFormInputName = function ()
  171. {
  172. if (this.m_sFormInputName && this.m_sFormInputName.length)
  173. {
  174. return this.m_sFormInputName;
  175. }
  176. else
  177. {
  178. return this.getName();
  179. }
  180. };
  181. CUserPreference.prototype.setFormInputName = function (sValue)
  182. {
  183. this.m_sFormInputName = sValue;
  184. };
  185. CUserPreference.prototype.getProperty = function(sPropertyName)
  186. {
  187. return this.m_oProperties.get(sPropertyName);
  188. };
  189. CUserPreference.prototype.setProperty = function(sPropertyName, sPropertyValue)
  190. {
  191. this.m_oProperties.add(sPropertyName, sPropertyValue);
  192. };
  193. CUserPreference.prototype.isSet = function (sValue)
  194. {
  195. return ! (sValue === null || typeof sValue === "undefined" || !sValue.length);
  196. };