CUserPreferenceDialog.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 CUserPreferenceDialog()
  14. {
  15. this.m_aParams = new Array();
  16. this.m_aParams["m"] = "/" + qs_dir + "/userPreferences.xts";
  17. this.m_bRequiresDialog = true;
  18. this.m_iErrorState = FEATURE_OBJECT_NO_ERROR;
  19. this.m_bFeatureRequiresQualityOfService = true;
  20. this.m_oCF = getConfigFrame();
  21. if (typeof goApplicationManager === "object" && goApplicationManager !== null)
  22. {
  23. this.m_oUserPreferenceManager = goApplicationManager.getUserPreferenceManager();
  24. }
  25. else
  26. {
  27. this.m_oUserPreferenceManager = new CUserPreferenceManager();
  28. }
  29. };
  30. CUserPreferenceDialog.prototype = new AFeatureObject();
  31. CUserPreferenceDialog.prototype.setup = function (aFeatureParams)
  32. {
  33. this.showDialog();
  34. };
  35. CUserPreferenceDialog.prototype.showDialog = function ()
  36. {
  37. cfgSet("LAST_DIALOG", "userPreferenceDialog");
  38. this.m_oUserPreferenceManager.clearAllDialogValues();
  39. var aPreferences = this.m_oUserPreferenceManager.getPreferences();
  40. for (var sPreferenceName in aPreferences)
  41. {
  42. var oUserPreference = aPreferences[sPreferenceName];
  43. var sValue = oUserPreference.getValue();
  44. this.m_aParams[sPreferenceName] = sValue;
  45. }
  46. if (cf.checkCalcFunctionAgainstDB("FLEXIBLE_FILTERS"))
  47. {
  48. this.m_aParams["flexibleFiltersAllowed"] = "true";
  49. }
  50. else
  51. {
  52. if (this.m_aParams["defaultFilterDialogType"] === "typein")
  53. {
  54. this.m_aParams["defaultFilterDialogType"] = "default";
  55. var oUserPreference = this.m_oUserPreferenceManager.getPreference("defaultFilterDialogType");
  56. oUserPreference.setDialogValue("default");
  57. }
  58. }
  59. };
  60. CUserPreferenceDialog.prototype.execute = function (aParams)
  61. {
  62. if (aParams && typeof aParams['f'] === "object" && aParams['f'] !== null)
  63. {
  64. var oForm = aParams['f'];
  65. var aPreferences = this.m_oUserPreferenceManager.getPreferences();
  66. for (var sPreferenceName in aPreferences)
  67. {
  68. var oUserPreference = aPreferences[sPreferenceName];
  69. var sFormInputName = oUserPreference.getFormInputName();
  70. if (typeof oForm[sFormInputName] !== "undefined")
  71. {
  72. var sValue = this.getInputValue(oForm[sFormInputName]);
  73. oUserPreference.setCookie(sValue);
  74. }
  75. }
  76. }
  77. goApplicationManager.getWindowManager().hideDialogFrame();
  78. };
  79. CUserPreferenceDialog.prototype.setFormFieldValues = function (oForm)
  80. {
  81. if (typeof oForm === "object" && oForm !== null)
  82. {
  83. var aPreferences = this.m_oUserPreferenceManager.getPreferences();
  84. for (var sPreferenceName in aPreferences)
  85. {
  86. var oUserPreference = aPreferences[sPreferenceName];
  87. var sValue = oUserPreference.getValue();
  88. var sFormInputName = oUserPreference.getFormInputName();
  89. if (typeof oForm[sFormInputName] !== "undefined")
  90. {
  91. this.setInputValue(oForm[sFormInputName], sValue);
  92. }
  93. }
  94. }
  95. };
  96. CUserPreferenceDialog.prototype.getInputValue = function (oFormElement)
  97. {
  98. if (typeof oFormElement === "undefined")
  99. {
  100. return null;
  101. }
  102. var sElementValue = "";
  103. if (oFormElement.length > 0)
  104. {
  105. for (var iIndex = 0; iIndex < oFormElement.length; iIndex++)
  106. {
  107. if (oFormElement[iIndex].checked)
  108. {
  109. sElementValue = oFormElement[iIndex].value;
  110. break;
  111. }
  112. }
  113. }
  114. else
  115. {
  116. switch (oFormElement.type)
  117. {
  118. case "checkbox":
  119. sElementValue = oFormElement.checked;
  120. break;
  121. default:
  122. sElementValue = oFormElement.value;
  123. break;
  124. }
  125. }
  126. return sElementValue;
  127. };
  128. CUserPreferenceDialog.prototype.setInputValue = function(oFormElement, sValue)
  129. {
  130. var sElementValue = "";
  131. if (oFormElement.length > 0)
  132. {
  133. for (var iIndex = 0; iIndex < oFormElement.length; iIndex++)
  134. {
  135. if (oFormElement[iIndex].value === sValue)
  136. {
  137. oFormElement[iIndex].checked = true;
  138. }
  139. else
  140. {
  141. oFormElement[iIndex].checked = false;
  142. }
  143. }
  144. }
  145. else
  146. {
  147. switch (oFormElement.type)
  148. {
  149. case "checkbox":
  150. var bSetValue = false;
  151. if (sValue === true || sValue === "true")
  152. {
  153. sValue = "true";
  154. bSetValue = true;
  155. } else sValue = "false";
  156. oFormElement.checked = bSetValue;
  157. break;
  158. default:
  159. oFormElement.value = sValue;
  160. break;
  161. }
  162. }
  163. return sElementValue;
  164. };