CSelectDataSourceSignon.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2013
  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. CSelectDataSourceSignon.js
  14. This script is used to allow users to select a connection and signon for a datasource
  15. */
  16. //Constructor to create a select datasource signon component
  17. //Constructor to create a checkboxlist component
  18. // oDataSourceConnection: the form control used to for the data source connection value
  19. // oDataSourceSignon: the form control used for the data source signon value
  20. // oUsername: the form control used for the user name
  21. // oPassword: the form control used for the password
  22. // oSubmit: the form control to submit selections to the server
  23. // oUseSignonDefault: form control used to set whether choosing signons should be the default
  24. // sSubmitType: 'default' will submit as a standard form
  25. // 'XML' will convert the submission to XML and submit
  26. // bSignonForCube: set to true if this signon is for a password protected cube (credentials are differents in this case). Default = false
  27. // bOKButtonPromptTypeIsNext this is used to determine whether this should do a next or a finish to conform with the onClick of the OKButton of the defaultpagefooter
  28. function CSelectDataSourceSignon(oDataSourceConnection, oDataSourceSignon, oUsername, oPassword, oSubmit, oUseSignonDefault, sSubmitType, oRadioList, oImgTest, bSignonForCube, sCVId, sPromptId, bOKButtonPromptTypeIsNext)
  29. {
  30. this.setCVId(sCVId);
  31. this.m_oDataSourceConnection = oDataSourceConnection;
  32. this.m_oDataSourceSignon = oDataSourceSignon;
  33. this.m_oUsername = oUsername;
  34. this.m_oPassword = oPassword;
  35. this.m_oSubmit = oSubmit;
  36. this.m_bValid = false;
  37. this.m_sSubmitType = sSubmitType;
  38. this.m_bUseSignon = true;
  39. this.m_bOKButtonPromptTypeIsNext = (bOKButtonPromptTypeIsNext === true);
  40. this.m_bSignonForCube = (bSignonForCube === true);
  41. if (typeof oRadioList != K_PRMT_sUNDEFINED) {
  42. this.m_oRadioList = oRadioList;
  43. }
  44. else {
  45. this.m_oConnectionRadioList = null;
  46. }
  47. if (typeof oImgTest != K_PRMT_sUNDEFINED) {
  48. this.m_oImgTest = oImgTest;
  49. }
  50. else {
  51. this.m_oImgTest = null;
  52. }
  53. this.m_sPromptId = sPromptId;
  54. //skin folder
  55. this.m_sSkin = (typeof getPromptSkin != K_PRMT_sUNDEFINED ? getPromptSkin() : K_PRMT_sDEFAULTSKIN);
  56. if (this.m_oImgTest != null)
  57. {
  58. this.m_oImgErrorFalse= new Image();
  59. this.m_oImgErrorFalse.src = this.m_sSkin + "/prompting/images/error_timed_small_off.gif";
  60. this.m_oImgErrorTrue = new Image();
  61. this.m_oImgErrorTrue.src = this.m_sSkin + "/prompting/images/error_timed_small.gif";
  62. }
  63. //use a User Id and Password or a Signon
  64. //default use Signon = 'true';
  65. if (oUseSignonDefault)
  66. {
  67. if (oUseSignonDefault.value == 'false')
  68. {
  69. this.m_bUseSignon = false;
  70. }
  71. }
  72. // Event handlers
  73. PRMTUtils.f_addEvent( this.m_oUsername, "keypress", this.keyPress.bind(this) );
  74. PRMTUtils.f_addEvent( this.m_oPassword, "keypress", this.keyPress.bind(this) );
  75. this.checkData();
  76. }
  77. CSelectDataSourceSignon.prototype = new CPromptControl();
  78. //render the validated state
  79. function CSelectDataSourceSignon_checkPass()
  80. {
  81. if ((this.m_oImgTest != null) && (this.m_oImgTest.src != this.m_oImgErrorFalse.src))
  82. {
  83. this.m_oImgTest.src = this.m_oImgErrorFalse.src;
  84. }
  85. this.notify(gPASS, this);
  86. }
  87. //render the validation error state
  88. function CSelectDataSourceSignon_checkFail()
  89. {
  90. if (this.m_oImgTest != null)
  91. {
  92. this.m_oImgTest.src = this.m_oImgErrorTrue.src + '?' + Math.random();
  93. }
  94. this.notify(gFAIL, this);
  95. }
  96. //validate the input into the control
  97. function CSelectDataSourceSignon_checkData()
  98. {
  99. this.m_bValid = true;
  100. if (this.m_oRadioList != null)
  101. {
  102. this.m_bValid = false;
  103. if (this.m_oRadioList.checked == true) {
  104. this.m_bValid = true;
  105. }
  106. else
  107. {
  108. for (var i = 0; i < this.m_oRadioList.length; i++)
  109. {
  110. if (this.m_oRadioList[i].checked) {
  111. this.m_bValid = true;
  112. }
  113. }
  114. }
  115. }
  116. if (this.m_bValid) {
  117. this.checkPass();
  118. }
  119. else {
  120. this.checkFail();
  121. }
  122. this.notify((this.m_bValid ? gPASS : gFAIL), this);
  123. return this.m_bValid;
  124. }
  125. function CSelectDataSourceSignon_preProcess()
  126. {
  127. if (this.m_sSubmitType == K_PRMT_sXML && this.m_oSubmit)
  128. {
  129. this.m_oSubmit.value = '<selectChoices><selectOption useValue="' + sXmlEncode(this.sGetValue()) + '" selected="true"/></selectChoices>';
  130. }
  131. }
  132. function CSelectDataSourceSignon_sGetPersistValue()
  133. {
  134. var v_sResult = K_PRMT_sEMPTY;
  135. var v_oPersistCheckBox = $( "oPersist" + this.m_sPromptId );
  136. if (v_oPersistCheckBox && v_oPersistCheckBox.checked) {
  137. v_sResult += ' persist="true"';
  138. }
  139. return v_sResult;
  140. }
  141. //return the selection in the following XML format:
  142. //
  143. // <credential>
  144. // <dataSourceConnection>...searchPath to connection...</dataSourceConnection>
  145. // <dataSourceSignon>...searchPath to signon...</dataSourceSignon>
  146. // <username> ... </username>
  147. // <password> ... </password>
  148. // </credential>
  149. function CSelectDataSourceSignon_sGetValue()
  150. {
  151. var sCredential = K_PRMT_sEMPTY;
  152. var v_sPersist = this.sGetPersistValue();
  153. sCredential += "<credential" + v_sPersist + ">";
  154. //create credential elements
  155. //data source connection
  156. var v_oConnectionName = K_PRMT_sEMPTY;
  157. var v_oConnectionNameElem = $( "oConnectionName" + this.m_sPromptId );
  158. if (v_sPersist.length > 0 && v_oConnectionNameElem && v_oConnectionNameElem.value) {
  159. v_oConnectionName = ' name="' + v_oConnectionNameElem.value +'"';
  160. }
  161. sCredential += "<dataSourceConnection" + v_oConnectionName + ">";
  162. if (this.m_oDataSourceConnection != null)
  163. {
  164. sCredential += this.m_oDataSourceConnection.value;
  165. }
  166. sCredential += "</dataSourceConnection>";
  167. if (this.m_bUseSignon == true)
  168. {
  169. //data source signon
  170. sCredential += "<dataSourceSignon>";
  171. if (this.m_oDataSourceSignon != null)
  172. {
  173. sCredential += this.m_oDataSourceSignon.value;
  174. }
  175. sCredential += "</dataSourceSignon>";
  176. //user name
  177. sCredential += "<username/>";
  178. //password
  179. sCredential += "<password/>";
  180. }
  181. else
  182. {
  183. //data source signon
  184. sCredential += "<dataSourceSignon/>";
  185. //user name
  186. sCredential += "<username>";
  187. if (this.m_oUsername != null)
  188. {
  189. sCredential += this.m_oUsername.value;
  190. }
  191. sCredential += "</username>";
  192. if (this.m_bSignonForCube) {
  193. //cubePassword
  194. sCredential += "<cubePassword>";
  195. if (this.m_oPassword != null)
  196. {
  197. sCredential += sXmlEncode(this.m_oPassword.value);
  198. }
  199. sCredential += "</cubePassword>";
  200. }
  201. else {
  202. //password
  203. sCredential += "<password>";
  204. if (this.m_oPassword != null)
  205. {
  206. sCredential += sXmlEncode(this.m_oPassword.value);
  207. }
  208. sCredential += "</password>";
  209. }
  210. }
  211. sCredential += "</credential>";
  212. return sCredential;
  213. }
  214. function CSelectDataSourceSignon_setDataSourceConnection(s)
  215. {
  216. this.m_oDataSourceConnection.value = s;
  217. }
  218. function CSelectDataSourceSignon_setDataSourceSignon(s)
  219. {
  220. this.m_oDataSourceSignon.value = s;
  221. }
  222. function CSelectDataSourceSignon_setbUseSignon(sUseSignon)
  223. {
  224. if (sUseSignon == 'true')
  225. {
  226. this.m_bUseSignon = true;
  227. }
  228. else if (sUseSignon == 'false')
  229. {
  230. this.m_bUseSignon = false;
  231. }
  232. else
  233. {
  234. this.m_bUseSignon = sUseSignon;
  235. }
  236. }
  237. function CSelectDataSourceSignon_keyPress()
  238. {
  239. var v_oEvt = ( arguments && arguments.length ? arguments[arguments.length-1] : null );
  240. if ( v_oEvt )
  241. {
  242. var keyCode = (v_oEvt.keyCode) ? v_oEvt.keyCode : v_oEvt.which;
  243. if ( keyCode == '13' )
  244. {
  245. var oCV = this.getCV();
  246. if ( oCV && (typeof oCV.canSubmitPrompt == K_PRMT_sFUNCTION) && oCV.canSubmitPrompt() && (typeof oCV.promptAction == K_PRMT_sFUNCTION))
  247. {
  248. // If instructed to do so submit the form using next action
  249. if (this.m_bOKButtonPromptTypeIsNext == true)
  250. {
  251. oCV.promptAction(K_ACTION_NEXT);
  252. }
  253. else // do the old thing cause it doesn't have a next button
  254. {
  255. oCV.promptAction(K_ACTION_FINISH);
  256. }
  257. }
  258. return PRMTUtils.F_StopEvent( v_oEvt );
  259. }
  260. }
  261. return true;
  262. }
  263. //Prototypes to assign methods to new instances of the object
  264. CSelectDataSourceSignon.prototype.preProcess = CSelectDataSourceSignon_preProcess;
  265. CSelectDataSourceSignon.prototype.checkPass = CSelectDataSourceSignon_checkPass;
  266. CSelectDataSourceSignon.prototype.checkFail = CSelectDataSourceSignon_checkFail;
  267. CSelectDataSourceSignon.prototype.checkData = CSelectDataSourceSignon_checkData;
  268. CSelectDataSourceSignon.prototype.keyPress = CSelectDataSourceSignon_keyPress;
  269. CSelectDataSourceSignon.prototype.sGetPersistValue = CSelectDataSourceSignon_sGetPersistValue;
  270. CSelectDataSourceSignon.prototype.sGetValue = CSelectDataSourceSignon_sGetValue;
  271. CSelectDataSourceSignon.prototype.setDataSourceConnection = CSelectDataSourceSignon_setDataSourceConnection;
  272. CSelectDataSourceSignon.prototype.setDataSourceSignon = CSelectDataSourceSignon_setDataSourceSignon;
  273. CSelectDataSourceSignon.prototype.setbUseSignon = CSelectDataSourceSignon_setbUseSignon;