/******************************************************************************* * IBM Confidential * * OCO Source Materials * * A and PM: PD * * (c) Copyright IBM Corp. 2015 * * The source code for this program is not published or otherwise divested of * its trade secrets, irrespective of what has been deposited with the U.S. * Copyright Office. ******************************************************************************/ define(["dojo/_base/connect", "dojox/io/xhrMultiPart"], function(connect, xhrMultiPart) { var TIMER_INTERVAL = 250; return { createXhr: function(args){ var xhr = dojo._xhrObj(args); var timer; connect.connect(xhr, "error", null, function(evt){ args.onError(evt); clearInterval(timer); }, false); xhr.onreadystatechange = function(){ if(xhr.readyState === 4){ clearInterval(timer); try{ args.onComplete(xhr.responseText); }catch(err){ args.onError(err); } } }; xhr.open(args.method, args.url); timer = setInterval(function(){ try{ if(typeof(xhr.statusText)){} }catch(e){ clearInterval(timer); } }, TIMER_INTERVAL); return xhr; }, saveDataSet: function(dataSetStoreID, repositoryName, repositoryConnection, repositorySignon, payload, callBack){ xhrMultiPart({ url: g_pd_gateway + "/metadataUIService?pid=pdm_process&c=saveLOBData&dataSetStoreID=" + dataSetStoreID + "&repositoryName=" + encodeURIComponent(repositoryName) + "&repositoryConnection=" + encodeURIComponent(repositoryConnection) + "&repositorySignon=" + encodeURIComponent(repositorySignon), content: {"name": "inSpec", "content": String(payload).F_XMLEncode()}, error: function(error) { pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, error.message, error.detail); }, load: function(response){ try { pd.parseResponse(response); callBack(); } catch (err) { if (err.name == pd.CAM_PASSPORT_ERROR){ pd.showLogonDialog(); } else { pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, err.message, err.detail); } } } }); }, cancelDataSet: function(dataSetStoreID, repositoryName, repositoryConnection, repositorySignon){ var xhr = this.createXhr({ url: g_pd_gateway + "/metadataUIService?pid=pdm_process&c=cancelLOBData&dataSetStoreID=" + dataSetStoreID + "&repositoryName=" + encodeURIComponent(repositoryName) + "&repositoryConnection=" + encodeURIComponent(repositoryConnection) + "&repositorySignon=" + encodeURIComponent(repositorySignon), method: "get", onError: function(error) { pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, error.message, error.detail); }, onComplete: function(response){ try { pd.parseResponse(response); } catch (err) { if (err.name == pd.CAM_PASSPORT_ERROR){ pd.showLogonDialog(); } else { pd.messageBox(pd.statics.MB_ERROR, PDMSG.ERR.IDS_ERR_SAVE_DATA_SET, err.message, err.detail); } } } }); xhr.setRequestHeader("Content-Type", "application/document"); xhr.send(); } } });