runOptions.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2016
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  9. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  10. /**********************************************************************************************
  11. This script is used in many different pages. When making changes insure that you take into account that not
  12. all the runOption controls are present on each page. You must check for the presence of controls before
  13. manipulating them.
  14. **********************************************************************************************/
  15. // g_hasRecipients -- declared in the logicsheet dt:runOptionValidation
  16. // g_validation_msg_array -- declared in the logicsheet dt:runOptionValidation
  17. var g_formatCheckboxNames = new Array(
  18. 'm_ro_outputF_HTML_Type',
  19. 'm_ro_outputFormat_PDF',
  20. 'm_ro_outputFormat_spreadsheetML',
  21. 'm_ro_outputFormat_spreadsheetMLOfficeConnectionEnabled',
  22. 'm_ro_outputF_XLS2000_Type',
  23. 'm_ro_outputFormat_XLWA',
  24. 'm_ro_outputFormat_CSV',
  25. 'm_ro_outputFormat_XML',
  26. 'm_ro_outputFormat_xlsxData'
  27. );
  28. var g_deliveryCheckboxNames = new Array(
  29. 'm_ro_archive',
  30. 'm_ro_email',
  31. 'm_ro_print',
  32. 'm_ro_saveOutput',
  33. 'm_ro_mobile'
  34. );
  35. // HTML dropdown has changed
  36. function onChangeHTML() {
  37. // make sure the checkbox is checked
  38. document.pform.m_ro_outputF_HTML_Type.checked = true;
  39. var interactiveChecked = document.getElementById('background_selectionBasedFeatures');
  40. var interactiveVerticalElements = document.getElementById('m_ro_verticalElements');
  41. if (document.pform.m_ro_outputFormat_HTML.value == 'HTML' && interactiveChecked) {
  42. interactiveChecked.disabled = false;
  43. }
  44. else if (interactiveChecked){
  45. interactiveChecked.disabled = true;
  46. }
  47. if ((document.pform.m_ro_outputFormat_HTML.value == 'HTML' || document.pform.m_ro_outputFormat_HTML.value == 'HTMLFragment' || document.pform.m_ro_outputFormat_HTML.value == 'XHTML') && interactiveVerticalElements) {
  48. interactiveVerticalElements.disabled = false;
  49. }
  50. else if (interactiveVerticalElements){
  51. interactiveVerticalElements.disabled = true;
  52. }
  53. }
  54. function checkSaveOption(saveOptionChecked)
  55. {
  56. var frm = document.pform;
  57. if (frm.m_ro_saveOutput) {
  58. frm.m_ro_saveOutput.checked = saveOptionChecked;
  59. }
  60. // enable/disable the save section
  61. if (frm.save_how) {
  62. if (frm.save_how[0]) {
  63. frm.save_how[0].disabled = !saveOptionChecked;
  64. }
  65. if (frm.save_how[1]) {
  66. frm.save_how[1].disabled = !saveOptionChecked;
  67. }
  68. }
  69. }
  70. function selectArchiveCheckbox() {
  71. var frm = document.pform;
  72. if (frm.m_ro_archive) {
  73. frm.m_ro_archive.checked = true;
  74. }
  75. }
  76. // when the printer field changes
  77. function onChangePrinter() {
  78. var frm = document.pform;
  79. if (frm.ro_printer_kw) {
  80. frm.ro_printer_kw.value = 'printerAddress';
  81. frm.m_ro_printerAddress.value = frm.select_printerNameAddress.value;
  82. frm.select_printerAddress.value = frm.select_printerNameAddress.value;
  83. frm.m_ro_printer.value='';
  84. if (frm.printeritem) {
  85. frm.printeritem.value = '';
  86. }
  87. // make sure the print radio-button or checkbox is selected and a printer has been chosen
  88. if (frm.select_printerAddress.value) {
  89. selectPrinterButton();
  90. }
  91. }
  92. }
  93. // clears the printer field
  94. function clearPrinterField() {
  95. var frm = document.pform;
  96. if (frm.ro_printer_kw) {
  97. frm.ro_printer_kw.value = 'printerAddress';
  98. frm.select_printerAddress.value = '';
  99. frm.m_ro_printerAddress.value = '';
  100. frm.m_ro_printer.value='';
  101. if (frm.printeritem) {
  102. frm.printeritem.value = '';
  103. }
  104. }
  105. }
  106. // select the print radio-button or checkbox
  107. function selectPrinterButton()
  108. {
  109. var frm = document.pform;
  110. // basic run with options dialog (user doesn't have write)
  111. if (frm.delivery && frm.delivery[1].value == 'print') {
  112. frm.delivery[1].checked = true;
  113. }
  114. // basic run with options dialog
  115. else if (frm.delivery && frm.delivery[2].value == 'print') {
  116. frm.delivery[2].checked = true;
  117. }
  118. // when we have checkboxes in the deliver section
  119. else if (frm.m_ro_print) {
  120. frm.m_ro_print.checked = true;
  121. }
  122. }
  123. // enables and selects the save delivery section
  124. function enableSave()
  125. {
  126. var frm = document.pform;
  127. if (frm.m_ro_saveOutput) {
  128. frm.m_ro_saveOutput.checked = true;
  129. }
  130. }
  131. // OLD function, but it's still getting called by agent studio, so leave the declaration for now
  132. function disableDelivery(enabled)
  133. {
  134. }
  135. // validation for all the run options
  136. function validateRunOptions() {
  137. var frm = document.pform;
  138. var formatChecked = false;
  139. // for some reports (such as powerPlay8Reports) the user cannot select a format so
  140. // there is no need to check the selected formats.
  141. var checkBoxesAvailable=false;
  142. for (var i=0; i < g_formatCheckboxNames.length; i++) {
  143. if (frm[g_formatCheckboxNames[i]]) {
  144. checkBoxesAvailable = true;
  145. }
  146. }
  147. // find out if there's a format checked
  148. if (checkBoxesAvailable) {
  149. for (var i=0; i < g_formatCheckboxNames.length; i++) {
  150. if (frm[g_formatCheckboxNames[i]] && frm[g_formatCheckboxNames[i]].checked && !frm[g_formatCheckboxNames[i]].disabled) {
  151. formatChecked = true;
  152. }
  153. }
  154. }
  155. else
  156. {
  157. formatChecked = true;
  158. }
  159. // at least one format must be checked
  160. if (!formatChecked) {
  161. // Does the user want to select the default format -->
  162. if (!window.confirm(g_validation_msg_array['IDS_OTHERRUN_ERR_NO_FORMAT'])) {
  163. return false;
  164. }
  165. // select the default format for the user
  166. if ((g_defaultFormat == 'HTML' || g_defaultFormat == 'HTMLFragment' || g_defaultFormat == 'XHTML') && frm.m_ro_outputF_HTML_Type && frm.m_ro_outputFormat_HTML) {
  167. frm.m_ro_outputF_HTML_Type.checked = 'true';
  168. frm.m_ro_outputFormat_HTML.value = g_defaultFormat;
  169. }
  170. if ((g_defaultFormat == 'XLS' || g_defaultFormat == 'singleXLS') && frm.m_ro_outputF_XLS2000_Type && frm.m_ro_outputFormat_XLS2000) {
  171. frm.m_ro_outputF_XLS2000_Type.checked = 'true';
  172. frm.m_ro_outputFormat_XLS2000.value = g_defaultFormat;
  173. }
  174. else if (g_defaultFormat == 'PDF' && frm.m_ro_outputFormat_PDF) {
  175. frm.m_ro_outputFormat_PDF.checked = 'true';
  176. }
  177. else if(frm['m_ro_outputFormat_' + g_defaultFormat]) {
  178. frm['m_ro_outputFormat_' + g_defaultFormat].checked = 'true';
  179. }
  180. }
  181. // the rest of the behavior are only needed if running in the background
  182. if (!frm.background || (frm.background && frm.background[1].checked)) {
  183. // if print is selected but no printer is chosen
  184. if (frm.m_ro_print && frm.m_ro_print.checked && frm.select_printerAddress.value == '') {
  185. alert(g_validation_msg_array['IDS_OTHERRUN_ERR_NO_PRINTER']);
  186. return false;
  187. }
  188. // if save to file system is selected but no archive location is chosen
  189. if (frm.m_ro_archive && frm.m_ro_archive.checked && frm.m_arc_archiveLocation.value == '') {
  190. alert(g_validation_msg_array['IDS_OTHERRUN_ERR_NO_ARCHIVE_LOCATION']);
  191. return false;
  192. }
  193. // if email is selected without recipients and no bursting
  194. if (g_hasRecipients == 'false' && (frm.m_ro_email && frm.m_ro_email.checked) && (!frm.emailToRunOptions || frm.emailToRunOptions.value=='') && (!frm.m_ro_burst || (frm.m_ro_burst && ( (frm.m_ro_burst.type=='checkbox' && !frm.m_ro_burst.checked) || (frm.m_ro_burst.type=='hidden' && frm.m_ro_burst.value!='true'))))) {
  195. alert(g_validation_msg_array['IDS_OTHERRUN_ERR_NO_RECIPIENTS']);
  196. return false;
  197. }
  198. // if mobile is selected without recipients and no bursting
  199. if (frm.m_ro_mobile && frm.m_ro_mobile.checked && (!frm.mobileDescription || frm.mobileDescription.value==g_validation_msg_array['IDS_OTHERRUN_MOBILE_NO_RECIPIENTS']) && (!frm.m_ro_burst || (frm.m_ro_burst && ( (frm.m_ro_burst.type=='checkbox' && !frm.m_ro_burst.checked) || (frm.m_ro_burst.type=='hidden' && frm.m_ro_burst.value!='true'))))) {
  200. alert(g_validation_msg_array['IDS_OTHERRUN_ERR_NO_MOBILE_RECIPIENTS']);
  201. return false;
  202. }
  203. // find out if the user selected a delivery option
  204. var deliverySelected = false;
  205. for (var i=0; i < g_deliveryCheckboxNames.length; i++){
  206. if (frm[g_deliveryCheckboxNames[i]] && frm[g_deliveryCheckboxNames[i]].checked) {
  207. deliverySelected = true;
  208. break;
  209. }
  210. }
  211. // if no delivery option is selected
  212. if (!deliverySelected) {
  213. // does the want to switch to save?
  214. if (!window.confirm(g_validation_msg_array['IDS_OTHERRUN_ERR_NO_DELIVERY'])) {
  215. return false;
  216. }
  217. enableSave();
  218. }
  219. // bursting and recipients
  220. if (frm.emailToRunOptions && frm.emailToRunOptions.value != '' && frm.m_ro_burst && frm.m_ro_burst.checked) {
  221. alert(g_validation_msg_array['IDS_OTHERRUN_ERR_BRUST']);
  222. }
  223. // break down the logic a bit here. When is the URL checkbox checked?.
  224. // if the edit email options page has been opened, we can get the value from the form variables, otherwise, get them from the unpacked delivery options
  225. var emailAsURL = false;
  226. if ((frm.m_ro_emailAsURL && frm.m_ro_emailAsURL.value=='true') || (frm.m_do_emailAsURL && frm.m_do_emailAsURL.value=='true')) {
  227. emailAsURL = true;
  228. }
  229. // do the same for the email as attachment checkbox.
  230. var emailAsAttachment = false;
  231. if ((frm.m_ro_emailAsAttachment && frm.m_ro_emailAsAttachment.value=='true') || (frm.m_do_emailAsAttachment && frm.m_do_emailAsAttachment.value=='true')) {
  232. emailAsAttachment = true;
  233. }
  234. // email a link without saving
  235. if (frm.m_ro_email && frm.m_ro_email.checked && emailAsURL && frm.m_ro_saveOutput && !frm.m_ro_saveOutput.checked) {
  236. // does the want to switch to save?
  237. // "You must save the reports before including a link to them in the email notification. Click OK to save the reports, or click Cancel to select different options".
  238. if (!window.confirm(g_validation_msg_array['IDS_OTHERRUN_ERR_LINK_NO_SAVE'])) {
  239. return false;
  240. }
  241. enableSave();
  242. }
  243. // if were sending a notification by email that the reports are complete and save and print aren't selected -->
  244. if (frm.m_ro_email.checked && !emailAsURL && !emailAsAttachment && frm.m_ro_saveOutput && (!frm.m_ro_saveOutput || !frm.m_ro_saveOutput.checked) && (!frm.m_ro_archive || !frm.m_ro_archive.checked) && (!frm.m_ro_print || !frm.m_ro_print.checked)) {
  245. // "You must save or print the reports before sending an email notification that the reports are complete. Click OK to save the reports, or click Cancel to select different options."
  246. if (!window.confirm(g_validation_msg_array['IDS_OTHERRUN_ERR_NOTIFY_NO_SAVE_PRINT'])) {
  247. return false;
  248. }
  249. enableSave();
  250. }
  251. }
  252. return true;
  253. }
  254. function updateInteractiveCheckbox() {
  255. var frm = document.pform;
  256. // make sure the enable selection-based interativity checked is enable/disabled
  257. if (document.getElementById('background_selectionBasedFeatures')) {
  258. if (frm.m_ro_outputF_HTML_Type && frm.m_ro_outputF_HTML_Type.checked && frm.m_ro_outputFormat_HTML && frm.m_ro_outputFormat_HTML.value == 'HTML') {
  259. document.getElementById('background_selectionBasedFeatures').disabled = false;
  260. }
  261. else {
  262. document.getElementById('background_selectionBasedFeatures').disabled = true;
  263. }
  264. }
  265. }
  266. function updateVerticalElementsSelect() {
  267. var frm = document.pform;
  268. if (document.getElementById('m_ro_verticalElements')) {
  269. if (frm.m_ro_outputF_HTML_Type && frm.m_ro_outputF_HTML_Type.checked && frm.m_ro_outputFormat_HTML && (frm.m_ro_outputFormat_HTML.value == 'HTML' || frm.m_ro_outputFormat_HTML.value == 'XHTML' || frm.m_ro_outputFormat_HTML.value == 'HTMLFragment')) {
  270. document.getElementById('m_ro_verticalElements').disabled = false;
  271. }
  272. else {
  273. document.getElementById('m_ro_verticalElements').disabled = true;
  274. }
  275. }
  276. }
  277. function initRunOptions() {
  278. var frm = document.pform;
  279. updateInteractiveCheckbox();
  280. updateVerticalElementsSelect();
  281. // enable/disable the save section
  282. if (frm.m_ro_saveOutput && frm.save_how) {
  283. checkSaveOption(frm.m_ro_saveOutput.checked);
  284. }
  285. }
  286. // given a form, name and value will create a hidden input
  287. function createHiddenInput(form, name, value)
  288. {
  289. var hiddenElement = document.createElement("input");
  290. hiddenElement.setAttribute("type","hidden");
  291. hiddenElement.setAttribute("name",name);
  292. hiddenElement.setAttribute("value",value);
  293. form.appendChild(hiddenElement);
  294. }
  295. function validateRunOptionProperties() {
  296. var frm = document.pform;
  297. // if any of these controls are missing (read only page?) there's no point in doing any validation
  298. if (!frm.m_ro_advancedOutput || !frm.m_ro_selectionBasedFeatures || !frm.m_ro_verticalElements || !frm.m_p_allowNotification) {
  299. return true;
  300. }
  301. var allowNotification = frm.m_p_allowNotification.value == 'true' ? true : false;
  302. var advancedSettings = frm.m_ro_advancedOutput.value == 'true' ? true : false;
  303. var selectionBasedFeatures = frm.m_ro_selectionBasedFeatures.value == 'true' ? true : false;
  304. // Allowing watch rules is dependent on the value of 'Enhanced user features'
  305. if (frm.changed_m_ro_advancedOutput.value == '1') {
  306. // update allowSubscription to match it
  307. frm.m_p_allowSubscription.value = advancedSettings;
  308. return true;
  309. }
  310. //to allow user to remove all existing alerts when changing to disallow alerts (notification)
  311. if (frm.original_allowNotification.value == 'true' && !allowNotification)
  312. {
  313. if (frm.m_canRemoveAll.value == 'true')
  314. {
  315. if ( window.confirm(g_runOption_allowNotification_msg))
  316. {
  317. frm.m_removeAll.value = 'true';
  318. }
  319. }
  320. }
  321. return true;
  322. }