/** * */ var url_requestNewPassword = appContexName+"/requestNewPassword"; var url_createFreeAcc = appContexName+"/createFreeAcc"; var url_freeSignup = appContexName+"/freeSignup"; var url_createPaidAcc = appContexName+"/createPaidAcc"; var url_validateEmail = appContexName+"/validateEmail"; var url_sendFeedback = appContexName+"/sendFeedback"; var url_changePwdFromLink = appContexName+"/changePwdFromLink"; var url_validate = appContexName+"/validate"; var url_updateProfile = appContexName+"/updateProfile"; var url_continueUpg = appContexName+"/continueUpg"; var url_applypendingcharges = appContexName+"/applypendingcharges"; var url_changePassword = appContexName+"/changePassword"; var url_cancel = appContexName+"/cancel"; var url_updatehosts = appContexName+"/updatehosts"; var url_updatecc = appContexName+"/updatecc"; var url_getHostsInfo = appContexName+"/getHostsInfo"; var url_createOfferPaidAcc = appContexName+"/createOfferPaidAcc"; var url_getWebAccessToken = appContexName+"/getWebAccessToken"; var url_createIDriveAccWithUsername = appContexName+"/createIDriveAccWithUsername"; var urls = {}; urls[url_requestNewPassword] = "yes"; urls[url_createFreeAcc] = "no"; urls[url_createPaidAcc] = "yes"; urls[url_validateEmail] = "no"; urls[url_sendFeedback] = "yes"; urls[url_changePwdFromLink] = "yes"; urls[url_validate] = "no"; urls[url_updateProfile] = "yes"; urls[url_continueUpg] = "yes"; urls[url_applypendingcharges] = "yes"; urls[url_changePassword] = "yes"; urls[url_cancel] = "yes"; urls[url_updatehosts] = "yes"; urls[url_updatecc] = "yes"; urls[url_getHostsInfo] = "yes"; urls[url_createOfferPaidAcc] = "no"; urls[url_getWebAccessToken] = "yes"; urls[url_createIDriveAccWithUsername] = "yes"; /*var urls = { url_requestNewPassword : "yes", url_createFreeAcc : "yes", url_createPaidAcc : "yes", url_validateEmail : "yes", url_sendFeedback : "yes", url_changePwdFromLink : "yes", url_validate : "yes", url_updateProfile : "yes", url_continueUpg : "yes", url_applypendingcharges : "yes", url_changePassword : "yes", url_cancel : "yes", url_updatehosts : "yes", url_updatecc : "yes", url_getHostsInfo : "yes", url_createOfferPaidAcc : "yes", url_getWebAccessToken : "yes", url_createIDriveAccWithUsername : "yes", }; */ var ajaxCore = (function() { var core = function (method, url, req_timeout, headers, contentType, data, dataType, success, failure, async) { if (typeof supportOTPAccess == "object") { if (supportOTPAccess.isAccessDisabled(url)) { supportOTPAccess.showAccessDeniedMessage(); return; } } var req = $.ajax({ type: method, beforeSend: function(request) { $.each(headers, function(key, header) { request.setRequestHeader(header.name, header.val); }); }, url: url, contentType: (typeof contentType != undefined ? contentType :''), data: data, async : async, dataType : (typeof dataType != undefined ? dataType :(dataType == '' ? 'text': dataType) ), success: success, failure: failure, xhrFields: { withCredentials: !0 }, timeout:req_timeout }); return req; }; var send = function (params) { if (typeof params != 'object' || params == null || typeof params == 'undefined') { throw Error("requires json object"); } if (typeof params.method == 'undefined') { throw Error("request method type is required"); } if (typeof params.url == 'undefined') { throw Error("request url is required"); } if (typeof params.headers != 'object') { throw Error("headers should be json array. (example: [{name:headername, val:value}, {name:headername, val:value}]"); } if (typeof params.data != 'object') { throw Error("data should be in json formate"); } if (typeof params.dataType == 'undefined' || params.dataType == '' || params.dataType == null || params.dataType == 'null') { params.dataType = 'text'; } if (typeof params.req_timeout == 'undefined' || params.req_timeout == null) { params.req_timeout = 0; } /*if (typeof params.contentType == 'undefined' || params.contentType == '' || params.contentType == null || params.contentType == 'null') { params.contentType = 'text'; }*/ if (typeof params.success != 'function') { throw Error("callback funtion is required"); } if(typeof(urls[params.url]) !="undefined" && urls[params.url] == 'yes'){ return core( "POST", getWEBAPPAPIAbsoluteURL(appContexName+"/getCSRFToken"), params.req_timeout, [], null, {}, null, function(csrfobj) { var headers = params.headers; headers.push({name:'csrftoken', val:csrfobj.csrf}); core(params.method, getWEBAPPAPIAbsoluteURL(params.url), params.req_timeout, headers, params.contentType, params.data, params.dataType, params.success, params.failure, true); }, function() { console.log('failed'); }, false ); } else { return core(params.method, getWEBAPPAPIAbsoluteURL(params.url), params.req_timeout, params.headers, params.contentType, params.data, params.dataType, params.success, params.failure, true); } }; return { send: send //expose }; })();