runWithOptions.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: ps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2014
  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. Used only on the run with options basic and run with options advanced dialgos
  12. **********************************************************************************************/
  13. var g_okCounter = 0;
  14. // when swtiching from view to background,
  15. // we have to make sure the correct format is selected
  16. function switchToBackgroundOptions() {
  17. var format;
  18. var frm = document.pform;
  19. if (frm.m_class.value == 'powerPlay8Report' || frm.m_class.value == 'powerPlay8ReportView') {
  20. format = frm.m_pp8ro_outputFormat.value;
  21. }
  22. else {
  23. format = frm.m_ro_outputFormat.value;
  24. }
  25. // make sure all the formats are unchecked
  26. uncheckAllFormats();
  27. // need to deal with the odd formats that have drop downs
  28. if (format == 'HTML') {
  29. frm.m_ro_outputF_HTML_Type.checked = true;
  30. frm.m_ro_outputFormat_HTML.value = 'HTML';
  31. }
  32. else if (format == 'singleXLS' || format == 'XLS') {
  33. frm.m_ro_outputF_XLS2000_Type.checked = true;
  34. frm.m_ro_outputFormat_XLS2000.value = format;
  35. }
  36. // simple checkbox for the other formats
  37. else {
  38. if (frm['m_ro_outputFormat_' + format]) {
  39. frm['m_ro_outputFormat_' + format].checked = true;
  40. }
  41. }
  42. // deal with the selection-base interativity controls
  43. updateInteractivityControls();
  44. var obj_localeDropDown = document.getElementById('outputLocaleDropDown');
  45. // need to update the locale text
  46. if (document.getElementById('language_summary_div') && obj_localeDropDown) {
  47. var localeDisplayName = '';
  48. // need to get the selected locale from the dropDown
  49. for (var i = 0; i < obj_localeDropDown.options.length; i++) {
  50. if (obj_localeDropDown.options[i].selected) {
  51. localeDisplayName = obj_localeDropDown.options[i].text;
  52. break;
  53. }
  54. }
  55. document.getElementById('language_summary_div').innerHTML = localeDisplayName;
  56. }
  57. if (obj_localeDropDown) {
  58. // make sure there aren't any hidden inputs for the locales since we're about to create one
  59. removeHiddenLocale();
  60. // create a hidden input for the locale
  61. createHiddenInput(frm, 'm_ro_outputLocale', obj_localeDropDown.value);
  62. createHiddenInput(frm, 'language', obj_localeDropDown.value);
  63. // disable the locale drop down
  64. obj_localeDropDown.disabled = true;
  65. }
  66. // Fix the PDF option summary
  67. var pdfSummary = '';
  68. // paper size
  69. if (document.getElementById('pdf_options_summary')) {
  70. // page orienation
  71. if (frm.m_ro_outputPageOrientation && frm.m_ro_outputPageOrientation.value != 'default') {
  72. for (var i=0; i < frm.m_ro_outputPageOrientation.options.length; i++) {
  73. if (frm.m_ro_outputPageOrientation.options[i].selected) {
  74. pdfSummary += frm.m_ro_outputPageOrientation.options[i].text;
  75. }
  76. }
  77. }
  78. if (frm.m_ro_outputPageDefinition && frm.m_ro_outputPageDefinition.value != 'default') {
  79. for (var i=0; i < frm.m_ro_outputPageDefinition.options.length; i++) {
  80. if (frm.m_ro_outputPageDefinition.options[i].selected) {
  81. if (pdfSummary != '') {
  82. pdfSummary += ', ';
  83. }
  84. pdfSummary += frm.m_ro_outputPageDefinition.options[i].text;
  85. }
  86. }
  87. }
  88. if (frm.m_pdf_userPassword_runOptionPassword_Encrypted && frm.m_pdf_userPassword_runOptionPassword_Encrypted.value != '') {
  89. if (pdfSummary != '') {
  90. pdfSummary += ', ';
  91. }
  92. pdfSummary += g_validation_msg_array['IDS_PDF_OPEN_PASSWORD_SUMMARY'];
  93. }
  94. if (frm.m_pdf_ownerPassword_runOptionPassword_Encrypted && frm.m_pdf_ownerPassword_runOptionPassword_Encrypted.value != '') {
  95. if (pdfSummary != '') {
  96. pdfSummary += ', ';
  97. }
  98. pdfSummary += g_validation_msg_array['IDS_PDF_OPTION_PASSWORD_SUMMARY'];
  99. }
  100. if (pdfSummary == '') {
  101. pdfSummary = g_validation_msg_array['IDS_OTHERRUN_NO_PDF_OPTIONS'];
  102. }
  103. document.getElementById('pdf_options_summary').innerHTML = pdfSummary;
  104. }
  105. }
  106. // when switching from background to view options,
  107. // we have to remove all but one language and deselect all the format
  108. function switchToViewOptions() {
  109. var frm = document.pform;
  110. // keep track of the first checked format so we can set the dropdown menu
  111. var firstCheckedFormat = uncheckAllFormats();
  112. if (firstCheckedFormat != '' && frm.m_ro_outputFormat) {
  113. var foundFormat = false;
  114. for (var i=0; i < frm.m_ro_outputFormat.options.length; i++){
  115. if (frm.m_ro_outputFormat.options[i].value == firstCheckedFormat) {
  116. foundFormat = true;
  117. break;
  118. }
  119. }
  120. if (foundFormat) {
  121. frm.m_ro_outputFormat.value = firstCheckedFormat;
  122. }
  123. else {
  124. frm.m_ro_outputFormat.value = frm.m_ro_outputFormat.options[0].value;
  125. }
  126. }
  127. // deal with the selection-base interativity controls
  128. updateInteractivityControls();
  129. // make sure we show/hide the correct sub format options
  130. updateSubOptions();
  131. var firstLocale = removeHiddenLocale();
  132. var obj_outputLocaleDropDown = document.getElementById('outputLocaleDropDown');
  133. // Todo: is there a way to sort the locales to get the first one?
  134. if (obj_outputLocaleDropDown) {
  135. obj_outputLocaleDropDown.disabled = false;
  136. obj_outputLocaleDropDown.value = firstLocale;
  137. }
  138. }
  139. // unchecks all the formats and returns the first checked format
  140. function uncheckAllFormats() {
  141. var frm = document.pform;
  142. var firstCheckedFormat = ''
  143. // uncheck all the formats
  144. for (var i = 0; i < g_formatCheckboxNames.length; i++) {
  145. var obj_checkbox = frm[g_formatCheckboxNames[i]];
  146. if (obj_checkbox) {
  147. // need to get the first format that is checked
  148. if (obj_checkbox.checked && firstCheckedFormat == '') {
  149. if (obj_checkbox.name == 'm_ro_outputF_HTML_Type') {
  150. firstCheckedFormat = 'HTML';
  151. }
  152. else if (obj_checkbox.name == 'm_ro_outputF_XLS2000_Type') {
  153. if (frm.m_ro_outputFormat_XLS2000) {
  154. firstCheckedFormat = frm.m_ro_outputFormat_XLS2000.value;
  155. }
  156. else {
  157. firstCheckedFormat = 'singleXLS';
  158. }
  159. }
  160. else {
  161. firstCheckedFormat = obj_checkbox.value;
  162. }
  163. }
  164. obj_checkbox.checked = false;
  165. }
  166. }
  167. return firstCheckedFormat;
  168. }
  169. // remove any hidden input that have a name of 'inputName' and return its value
  170. function removeHiddenInputs(inputName) {
  171. var frm = document.pform;
  172. var inputValue = '';
  173. // remove all the hidden 'language' fields
  174. for(var i=0; i < frm.elements.length; i++) {
  175. var obj = frm.elements[i];
  176. if (obj.name == inputName && obj.type == 'hidden' && obj.parentNode.removeChild ) {
  177. inputValue = obj.value;
  178. obj.parentNode.removeChild(obj);
  179. i--;
  180. }
  181. }
  182. return inputValue;
  183. }
  184. // removes all the hidden inputs that have locale information stored
  185. function removeHiddenLocale() {
  186. var frm = document.pform;
  187. var firstLocale = '';
  188. for(var i=0; i < frm.elements.length; i++) {
  189. var obj = frm.elements[i];
  190. // loop through all the locale fields
  191. // if the object is hidden, then it's for a background run
  192. if (obj.name && obj.name.indexOf('m_ro_outputLocale') == 0 && obj.type == 'hidden') {
  193. if (firstLocale == '') {
  194. firstLocale = obj.value;
  195. }
  196. // set it's value to empty
  197. obj.value = '';
  198. // remove the hidden input
  199. if (obj.parentNode.removeChild) {
  200. obj.parentNode.removeChild(obj);
  201. i--;
  202. }
  203. }
  204. }
  205. // remove all the hidden 'language' fields
  206. removeHiddenInputs('language');
  207. return firstLocale;
  208. }
  209. // The enable interactivity checked is duplicated on the advanced run with options
  210. // dialog. For this reason, we always need to keep one of them (the one that is hidden)
  211. // disabled at all times.
  212. function updateInteractivityControls() {
  213. var frm = document.pform;
  214. // if we're missing any of these controls then just return (happens for a run once)
  215. if (!frm.runType || !frm.runType[0] || !document.getElementById('background_selectionBasedFeatures') || !document.getElementById('view_selectionBasedFeatures') || !document.getElementById('m_ro_verticalElements') || !document.getElementById('view_verticalElements')) {
  216. return;
  217. }
  218. var runAndView = frm.runType[0].checked;
  219. var runAndViewCheckbox = document.getElementById('view_selectionBasedFeatures');
  220. var backgroundRunCheckbox = document.getElementById('background_selectionBasedFeatures');
  221. var backgroundRunHiddenInput = document.pform.m_ro_selectionBasedFeatures;
  222. var runAndViewRowsDropDown = document.getElementById('view_verticalElements');
  223. var backgroundRowsDropDown = document.getElementById('m_ro_verticalElements');
  224. // always keep the checkboxes and hidden inputs in sync
  225. if (runAndView) {
  226. runAndViewCheckbox.checked = backgroundRunCheckbox.checked;
  227. if (backgroundRowsDropDown && runAndViewRowsDropDown)
  228. {
  229. for (var i = 0; i < backgroundRowsDropDown.options.length; i++) {
  230. if (backgroundRowsDropDown.options[i].selected) {
  231. runAndViewRowsDropDown.options[i].selected = true;
  232. break;
  233. }
  234. }
  235. }
  236. }
  237. else {
  238. backgroundRunCheckbox.checked = runAndViewCheckbox.checked;
  239. backgroundRunHiddenInput.value = backgroundRunCheckbox.checked;
  240. if (runAndViewRowsDropDown && backgroundRowsDropDown)
  241. {
  242. for (var i = 0; i < runAndViewRowsDropDown.options.length; i++) {
  243. if (runAndViewRowsDropDown.options[i].selected) {
  244. backgroundRowsDropDown.options[i].selected = true;
  245. break;
  246. }
  247. }
  248. }
  249. // if we're doing a run in background, only enable the interactivity checkbox
  250. // if HTML is selected in the drop down
  251. updateInteractiveCheckbox();
  252. updateVerticalElementsSelect();
  253. }
  254. // make sure only one of them is enabled.
  255. runAndViewCheckbox.disabled = !runAndView;
  256. }
  257. // used to disabled/enable the backgroun run radio-buttons and
  258. // show the correct run option div
  259. function updateRunType() {
  260. var frm = document.pform;
  261. if (!frm.runType || !frm.backgroundRun) {
  262. return;
  263. }
  264. if (frm.backgroundRun[1]) {
  265. frm.backgroundRun[0].disabled = frm.runType[0].checked;
  266. frm.backgroundRun[1].disabled = frm.runType[0].checked;
  267. }
  268. if (frm.runType[0].checked) {
  269. showDynamicDiv('viewReportOptions');
  270. hideDynamicDiv('backgroundRunOption');
  271. }
  272. else {
  273. showDynamicDiv('backgroundRunOption');
  274. hideDynamicDiv('viewReportOptions');
  275. }
  276. }
  277. // Used when switching between run and view, and run in the background on the
  278. // advanced run with options dialog
  279. function updateOptionType() {
  280. var frm = document.pform;
  281. if (!frm.runType || !frm.backgroundRun) {
  282. return;
  283. }
  284. if (frm.runType[0].checked) {
  285. switchToViewOptions();
  286. }
  287. else {
  288. switchToBackgroundOptions();
  289. }
  290. }
  291. // show or hide the format suboption div
  292. function updateSubOptions() {
  293. var format;
  294. var frm = document.pform;
  295. if (frm.m_class.value == 'powerPlay8Report' || frm.m_class.value == 'powerPlay8ReportView') {
  296. format = frm.m_pp8ro_outputFormat.value;
  297. }
  298. else {
  299. format = frm.m_ro_outputFormat.value;
  300. }
  301. if (format == 'PDF' && document.getElementById('div_pdfOptions')) {
  302. showDynamicDiv('div_pdfOptions');
  303. }
  304. else if (document.getElementById('div_pdfOptions')) {
  305. hideDynamicDiv('div_pdfOptions');
  306. }
  307. if (format == 'HTML' && document.getElementById('div_htmlOptions')) {
  308. showDynamicDiv('div_htmlOptions');
  309. }
  310. else if (document.getElementById('div_htmlOptions')){
  311. hideDynamicDiv('div_htmlOptions');
  312. }
  313. }
  314. // User hit OK on the run with options basic or advanced dialog
  315. function onClickOK(msg) {
  316. var frm = document.pform;
  317. g_okCounter++;
  318. if (g_okCounter > 1) {
  319. if (g_okCounter > 2) {
  320. return false;
  321. }
  322. // If the user doesn't want to see the summary page then warn them the page is already being submitted.
  323. if (frm.showSummary && frm.showSummary.value == 'n') {
  324. alert(msg);
  325. }
  326. return false;
  327. }
  328. return true;
  329. }
  330. // user clicken on the advanced options link
  331. function advancedOptions() {
  332. // make sure we have the correct delivery input for save, print or email
  333. createBasicToAdvDeliveryInput();
  334. document.pform.m.value = 'portal/runWithOptions/report_advanced.xts';
  335. document.pform.submit();
  336. }
  337. // if we're on the basic page, then add the correct hidden inputs to
  338. // represent the delivery selection
  339. function createBasicToAdvDeliveryInput() {
  340. var frm = document.pform;
  341. if (frm.delivery) {
  342. for(var i=0; i < frm.delivery.length; i++) {
  343. if (frm.delivery[i].checked) {
  344. var deliveryValue = frm.delivery[i].value;
  345. if (deliveryValue == 'save') {
  346. createHiddenInput(frm, 'm_ro_saveOutput', 'true');
  347. }
  348. else if (deliveryValue == 'print') {
  349. createHiddenInput(frm, 'm_ro_print', 'true');
  350. }
  351. else if (deliveryValue == 'email') {
  352. createHiddenInput(frm, 'm_ro_email', 'true');
  353. }
  354. else if (deliveryValue == 'mobile') {
  355. createHiddenInput(frm, 'm_ro_mobile', 'true');
  356. }
  357. }
  358. }
  359. }
  360. }
  361. function runReport() {
  362. var frm = document.pform;
  363. if (window.validate && !validate()) {
  364. return;
  365. }
  366. // run and view
  367. if ((frm.delivery && frm.delivery.checked) || (frm.delivery && frm.delivery[0] && frm.delivery[0].checked) || (frm.runType && frm.runType[0] && frm.runType[0].checked)) {
  368. if (frm.m_class.value == 'powerPlay8Report' || frm.m_class.value == 'powerPlay8ReportView')
  369. {
  370. //Only PDF is supported by PowerPlay8 viewer.
  371. launchPP8Viewer('PDF');
  372. }
  373. else {
  374. launchViewer(frm.m_ro_outputFormat.value);
  375. }
  376. }
  377. // background execution
  378. else {
  379. // prepare to run the report in the background
  380. setupBackgroundRun(frm);
  381. frm.submit();
  382. }
  383. }
  384. function setupBackgroundRun(frm)
  385. {
  386. // if we're on the basic page, then add the correct hidden inputs to
  387. // represent the delivery selection
  388. if (frm.delivery) {
  389. createBasicToAdvDeliveryInput();
  390. }
  391. //create a variable to simplify the logic
  392. var isPowerPlayReport = (frm.m_class.value == 'powerPlay8Report' || frm.m_class.value == 'powerPlay8ReportView');
  393. // if the user doesn't want to prompt or view the summary page then go directly to submit
  394. if (frm.showSummary && frm.showSummary.value == 'n' && ((!isPowerPlayReport && !frm.m_ro_prompt.checked) || (isPowerPlayReport && !frm.m_pp8ro_prompt.checked))) {
  395. frm.ps_nav_op.value = 'submit';
  396. frm.m.value = 'portal/submit.xts';
  397. }
  398. else {
  399. if (isPowerPlayReport) {
  400. if (frm.m_pp8ro_prompt.checked) {
  401. frm.method.value = 'edit';
  402. }
  403. else {
  404. frm.method.value = '';
  405. }
  406. }
  407. else {
  408. if (frm.m_ro_prompt.checked) {
  409. frm.method.value = 'edit';
  410. }
  411. else {
  412. frm.method.value = '';
  413. }
  414. }
  415. //if we're on the advanced run with options, then disable the outputFormat and outputLocale dropdowns
  416. if (frm.visited_run_with_options_advanced) {
  417. if (frm.m_class.value != 'powerPlay8Report' && frm.m_class.value != 'powerPlay8ReportView' && frm.m_ro_outputFormat != null) {
  418. frm.m_ro_outputFormat.disabled = true;
  419. }
  420. if (document.getElementById('outputLocaleDropDown')) {
  421. document.getElementById('outputLocaleDropDown').disabled = true;
  422. }
  423. }
  424. frm.ps_nav_op.value = 'push';
  425. frm.m.value = 'portal/runWithOptions/report_confirm.xts';
  426. }
  427. }
  428. // given a form, name and value will create a hidden input
  429. function createHiddenInput(form, name, value)
  430. {
  431. var hiddenElement = document.createElement("input");
  432. hiddenElement.setAttribute("type","hidden");
  433. hiddenElement.setAttribute("name",name);
  434. hiddenElement.setAttribute("value",value);
  435. form.appendChild(hiddenElement);
  436. }