From 3957aa604512b4e77b46a852edee79850b4059b4 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Feb 2014 10:39:33 -0500 Subject: [PATCH] refactor(dom) RESTful: sendRequest --- lib/client/dom.js | 66 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/lib/client/dom.js b/lib/client/dom.js index 67116ab9..1ca90334 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -198,41 +198,39 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; }); }; - function sendRequest(pParams) { - var lRet = Util.checkObjTrue(pParams, ['method']); - if (lRet) { - var p = pParams; - - Images.showLoad( p.imgPosition ); - CloudCmd.getConfig(function(pConfig) { - var lData; - - if (Util.isString(p.url)) - p.url = decodeURI(p.url); - - if (p.data && - !Util.isString(p.data) && - !Util.isArrayBuffer(p.data)) - lData = Util.stringifyJSON(p.data); - else - lData = p.data; - - p.url = pConfig && pConfig.apiURL + p.url, - DOM.ajax({ - method : p.method, - url : p.url, - data : lData, - error : Images.showError, - success : function(pData) { - Images.hideLoad(); - Util.log(pData); - Util.exec(p.callback, pData); - } - }); - }); - } + function sendRequest(params) { + var p = params; + + Images.showLoad(p.imgPosition); - return lRet; + CloudCmd.getConfig(function(config) { + var data, + isString = Util.isString(p.data), + isArrayBuffer = Util.isArrayBuffer(p.data); + + if (Util.isString(p.url)) + p.url = decodeURI(p.url); + + if (p.data && !isString && !isArrayBuffer) + data = Util.stringifyJSON(p.data); + else + data = p.data; + + p.url = config && config.apiURL + p.url; + + DOM.ajax({ + method : p.method, + url : p.url, + data : data, + error : Images.showError, + success : function(data) { + Images.hideLoad(); + + Util.log(data); + Util.exec(p.callback, data); + } + }); + }); } },