mdsrvRequest.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*******************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * A and PM: PD
  7. *
  8. * (c) Copyright IBM Corp. 2015
  9. *
  10. * The source code for this program is not published or otherwise divested of
  11. * its trade secrets, irrespective of what has been deposited with the U.S.
  12. * Copyright Office.
  13. ******************************************************************************/
  14. define(["dojo/_base/connect", "dojox/io/xhrMultiPart"], function(connect, xhrMultiPart) {
  15. var TIMER_INTERVAL = 250;
  16. return {
  17. createXhr: function(args){
  18. var xhr = dojo._xhrObj(args);
  19. var timer;
  20. connect.connect(xhr, "error", null, function(evt){
  21. args.onError(evt);
  22. clearInterval(timer);
  23. }, false);
  24. xhr.onreadystatechange = function(){
  25. if(xhr.readyState === 4){
  26. clearInterval(timer);
  27. try{
  28. args.onComplete(xhr.responseText);
  29. }catch(err){
  30. args.onError(err);
  31. }
  32. }
  33. };
  34. xhr.open(args.method, args.url);
  35. timer = setInterval(function(){
  36. try{
  37. if(typeof(xhr.statusText)){}
  38. }catch(e){
  39. clearInterval(timer);
  40. }
  41. }, TIMER_INTERVAL);
  42. return xhr;
  43. },
  44. saveDataSet: function(dataSetStoreID, repositoryName, repositoryConnection, repositorySignon, payload, callBack){
  45. xhrMultiPart({
  46. url: g_pd_gateway + "/metadataUIService?pid=pdm_process&c=saveLOBData&dataSetStoreID=" + dataSetStoreID
  47. + "&repositoryName=" + encodeURIComponent(repositoryName)
  48. + "&repositoryConnection=" + encodeURIComponent(repositoryConnection)
  49. + "&repositorySignon=" + encodeURIComponent(repositorySignon),
  50. content: {"name": "inSpec", "content": String(payload).F_XMLEncode()},
  51. error: function(error) {
  52. pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, error.message, error.detail);
  53. },
  54. load: function(response){
  55. try {
  56. pd.parseResponse(response);
  57. callBack();
  58. } catch (err) {
  59. if (err.name == pd.CAM_PASSPORT_ERROR){
  60. pd.showLogonDialog();
  61. } else {
  62. pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, err.message, err.detail);
  63. }
  64. }
  65. }
  66. });
  67. },
  68. cancelDataSet: function(dataSetStoreID, repositoryName, repositoryConnection, repositorySignon){
  69. var xhr = this.createXhr({
  70. url: g_pd_gateway + "/metadataUIService?pid=pdm_process&c=cancelLOBData&dataSetStoreID=" + dataSetStoreID
  71. + "&repositoryName=" + encodeURIComponent(repositoryName)
  72. + "&repositoryConnection=" + encodeURIComponent(repositoryConnection)
  73. + "&repositorySignon=" + encodeURIComponent(repositorySignon),
  74. method: "get",
  75. onError: function(error) {
  76. pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, error.message, error.detail);
  77. },
  78. onComplete: function(response){
  79. try {
  80. pd.parseResponse(response);
  81. } catch (err) {
  82. if (err.name == pd.CAM_PASSPORT_ERROR){
  83. pd.showLogonDialog();
  84. } else {
  85. pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, err.message, err.detail);
  86. }
  87. }
  88. }
  89. });
  90. xhr.setRequestHeader("Content-Type", "application/document");
  91. xhr.send();
  92. }
  93. }
  94. });