ViewerMobileRequest.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2012
  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. function ViewerMobileRequest() {}
  13. /**
  14. * Loops through all the form fields in the form and call Mobile with them.
  15. * Returns true if window.onAction is called, otherwise will return false
  16. */
  17. ViewerMobileRequest.passFormFieldsToMobile = function(form) {
  18. var formFieldsPayload = {};
  19. var inputNodes = form.getElementsByTagName("input");
  20. if (inputNodes) {
  21. for (var i=0; i < inputNodes.length; i++) {
  22. var name = inputNodes[i].getAttribute("name");
  23. var value = inputNodes[i].getAttribute("value");
  24. if (name && value) {
  25. formFieldsPayload[name] = value;
  26. }
  27. }
  28. }
  29. return ViewerMobileRequest._callMobile(formFieldsPayload);
  30. };
  31. /**
  32. * Will call the mobile javascript function passing all the request form fields.
  33. * Returns true if window.onAction is called, otherwise will return false
  34. */
  35. ViewerMobileRequest.passRequestFieldsToMobile = function (request) {
  36. var formFieldsPayload = {};
  37. var formFields = request.getFormFields();
  38. var formFieldNames = formFields.keys();
  39. for (var index = 0; index < formFieldNames.length; index++) {
  40. var name = formFieldNames[index];
  41. formFieldsPayload[name] = formFields.get(name);
  42. }
  43. return ViewerMobileRequest._callMobile(formFieldsPayload);
  44. };
  45. ViewerMobileRequest._callMobile = function(formFieldsPayload) {
  46. var payload = {
  47. "action" : "httpRequest",
  48. payload : formFieldsPayload
  49. };
  50. if (window.onAction) {
  51. window.onAction(payload);
  52. return true;
  53. }
  54. else if (typeof console != "undefined" && console && console.log) {
  55. console.log(payload)
  56. return false;
  57. }
  58. return false;
  59. };