genericEditing.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cpscrn
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2018
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. function getPickerForm(formName)
  13. {
  14. var forms = document.getElementsByTagName("form");
  15. var currentPicker = null;
  16. var i = 0;
  17. //while ((currentPicker == null) && (i < forms.length))
  18. while ((i < forms.length))
  19. {
  20. if (forms[i].name == formName){
  21. currentPicker = forms[i];
  22. }
  23. i++;
  24. }
  25. return currentPicker;
  26. }
  27. function recreatePickerForm(formName, action)
  28. {
  29. var forms = document.getElementsByTagName("form");
  30. var currentPicker = getPickerForm(formName);
  31. if (currentPicker != null)
  32. {
  33. //remove all elements from the form just in case it was used previously
  34. currentPicker.parentNode.removeChild(currentPicker);
  35. }
  36. //recreate the picker form
  37. currentPicker = document.createElement("form");
  38. currentPicker.name = formName;
  39. currentPicker.action = action;
  40. currentPicker.target = "UI_MODAL_DIALOG_IFRAME";
  41. document.body.appendChild(currentPicker);
  42. }
  43. function createPickerInput(form, id, name, value)
  44. {
  45. var anInput = document.createElement('input');
  46. anInput.setAttribute("type","hidden");
  47. anInput.setAttribute("name",name);
  48. anInput.setAttribute("value",value);
  49. anInput.setAttribute("id",id);
  50. form.appendChild(anInput);
  51. }
  52. function isInRemoveLang(locale)
  53. {
  54. var inputs = document.getElementsByTagName("input");
  55. var removeLangEl = null;
  56. var count = 0;
  57. while ((removeLangEl == null) && (count < inputs.length))
  58. {
  59. var currEl = inputs[count];
  60. if ((currEl.type == "hidden") && (currEl.name == 'removeLang'))
  61. {
  62. removeLangEl = currEl;
  63. }
  64. count++;
  65. }
  66. return (removeLangEl.value.indexOf(locale) != -1)
  67. }
  68. function getMultiLingualElements(pickParamName, propertyName, form, selector, control)
  69. {
  70. var currentLocale = selector.options[selector.selectedIndex].value;
  71. var inputs = document.getElementsByTagName("input");
  72. var langValueIndex = 1;
  73. for (var ind = 0; ind < inputs.length; ind++)
  74. {
  75. if (inputs[ind].type == "hidden")
  76. {
  77. if (inputs[ind].name.indexOf(propertyName + "-") == 0)
  78. {
  79. var indexOfLocale = (propertyName + "-").length;
  80. var locale = inputs[ind].name.substr(indexOfLocale);
  81. if (!isInRemoveLang(locale))
  82. {
  83. if (locale == currentLocale)
  84. {
  85. inputs[ind].value = control.value;
  86. }
  87. createPickerInput(form, pickParamName + "-" + locale, pickParamName + "-" + locale, inputs[ind].value);
  88. langValueIndex++;
  89. }
  90. }
  91. }
  92. }
  93. return (langValueIndex > 1);
  94. }
  95. function getRadiobuttonSelectElements(pickParamName, propertyName, form)
  96. {
  97. var radiobuttons = document.getElementsByTagName("input");
  98. var radioIndex = 1;
  99. var checkedRadioButton = null;
  100. var count = 0;
  101. while ((checkedRadioButton == null) && (count < radiobuttons.length) )
  102. {
  103. var currentEl = radiobuttons[count];
  104. if ((currentEl.type == 'radio') && (currentEl.name == ("p_" + propertyName)) && (currentEl.checked) )
  105. {
  106. checkedRadioButton = currentEl;
  107. }
  108. count++;
  109. }
  110. if (checkedRadioButton == null)
  111. {
  112. return false;
  113. }
  114. else
  115. {
  116. createPickerInput(form, pickParamName + "_" + radiobuttons, pickParamName, checkedRadioButton.value);
  117. return true;
  118. }
  119. }
  120. function getCheckboxSelectElements(pickParamName, propertyName, form)
  121. {
  122. var checkboxes = document.getElementsByTagName("input");
  123. var checkIndex = 1;
  124. for (var ind = 0; ind < checkboxes.length; ind++)
  125. {
  126. if (checkboxes[ind].type == "checkbox")
  127. {
  128. if (checkboxes[ind].name.indexOf("p_" + propertyName + "_option") == 0)
  129. {
  130. if (checkboxes[ind].checked)
  131. {
  132. createPickerInput(form, pickParamName + "_" + checkIndex, pickParamName + "_" + checkIndex, checkboxes[ind].value);
  133. checkIndex++;
  134. }
  135. }
  136. }
  137. }
  138. return (checkIndex > 1);
  139. }
  140. function getOptionSelectElements(pickParamName, propertyName, form)
  141. {
  142. var selections = document.getElementsByTagName("select");
  143. var optionIndex = 1;
  144. for (var ind = 0; ind < selections.length; ind++)
  145. {
  146. if (selections[ind].name == ("p_" + propertyName))
  147. {
  148. var theOptions = selections[ind].options;
  149. for (var optind=0;optind < theOptions.length;optind++)
  150. {
  151. if (theOptions[optind].selected)
  152. {
  153. //if it is a select-one list then treat the result as a
  154. //simple element otherwise assume that you will be creating multiple inputs for this
  155. //for this property
  156. if (selections[ind].type == "select-one")
  157. {
  158. createPickerInput(form, pickParamName, pickParamName, theOptions[optind].value);
  159. }
  160. else
  161. {
  162. createPickerInput(form, pickParamName + "_" + optionIndex, pickParamName + "_" + optionIndex, theOptions[optind].value);
  163. }
  164. optionIndex++;
  165. }
  166. }
  167. }
  168. }
  169. return (optionIndex > 1);
  170. }
  171. function getSelectElements(pickParamName, propertyName, form)
  172. {
  173. //first see if we have a bunch of check boxes
  174. if (getCheckboxSelectElements(pickParamName, propertyName, form))
  175. {
  176. return true;
  177. }
  178. //next see if we have a bunch of option tags
  179. if (getOptionSelectElements(pickParamName, propertyName, form))
  180. {
  181. return true;
  182. }
  183. return false;
  184. }
  185. function getSelect1Elements(pickParamName, propertyName, form)
  186. {
  187. //first see if we have a bunch of check boxes
  188. if (getRadiobuttonSelectElements(pickParamName, propertyName, form))
  189. {
  190. return true;
  191. }
  192. //next see if we have a bunch of option tags
  193. if (getOptionSelectElements(pickParamName, propertyName, form))
  194. {
  195. return true;
  196. }
  197. return false;
  198. }
  199. function getValueFromSimpleElement(element)
  200. {
  201. if ((element.type == "text") || (element.type == "textarea"))
  202. {
  203. return element.value;
  204. }
  205. if ((element.type == "radio") || (element.type == "checkbox"))
  206. {
  207. return element.checked;
  208. }
  209. if (element.type == "hidden")
  210. {
  211. return element.value;
  212. }
  213. }
  214. //****xml functions
  215. function XMLBuilderLoadXMLFromString(markup)
  216. {
  217. var xmlDocument = null;
  218. // Try to activeX first. In IE10, if we use the DOMParser, the selectSingleNode will not longer work and IE still does not support the xpath evaluate method
  219. try
  220. {
  221. // If we do not hit an exception while creating ActiveXObject object, it means that we use Internet Explorer browser
  222. xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
  223. xmlDocument.loadXML(markup);
  224. }
  225. catch (e)
  226. {
  227. // If we get in here, it means that we use other then Internet Explorer browser
  228. if (typeof DOMParser != 'undefined')
  229. {
  230. xmlDocument = new DOMParser().parseFromString(markup, 'application/xml');
  231. }
  232. }
  233. return xmlDocument;
  234. }
  235. function xmldecode(text)
  236. {
  237. var amp_re = /&amp;/g;
  238. var lt_re = /&lt;/g;
  239. var gt_re = /&gt;/g;
  240. var apos_re = /&apos;/g;
  241. // Decode stuff which has been encoded/escaped out.
  242. // ORDER IS IMPORTANT - amp_re must be the last value to replace!
  243. text = text.replace(lt_re, "<");
  244. text = text.replace(gt_re, ">");
  245. text = text.replace(apos_re, "'");
  246. text = text.replace(amp_re, "&");
  247. return text;
  248. }