diff --git a/o.js b/o.js index ce71c69..496c54c 100644 --- a/o.js +++ b/o.js @@ -722,7 +722,9 @@ queryStr += '/'; } - queryStr = queryStr.slice(0, -1); + if(typeof res.appending === 'undefined' || res.appending === null) { + queryStr = queryStr.slice(0, -1); + } return (queryStr + res.appending + getQuery()); } @@ -887,7 +889,7 @@ if (resourceList.length === 0 && !isSave) { startAjaxReq(createCORSRequest('GET', buildQuery()), null, callback, errorCallback, false, [ - { name: 'Accept', value: 'application/json' }, + { name: 'Accept', value: 'application/json,text/plain' }, { name: 'Content-Type', value: 'application/json' } ], param, resource.progress); diff --git a/o.min.js b/o.min.js index 711891b..beb4df1 100644 --- a/o.min.js +++ b/o.min.js @@ -1 +1 @@ -!function(e,n){"function"==typeof define&&define.amd?define(["q"],n):"object"==typeof exports?module.exports=n(require("q")):e.o=n(e.Q)}(this,function(e){function n(e){function n(){for(var e,n={},t=0,r=arguments.length;r>t;t++)for(e in arguments[t])arguments[t].hasOwnProperty(e)&&(n[e]=arguments[t][e]);return n}var r=this;return r.oConfig=r.oConfig||{endpoint:null,format:"json",autoFormat:!0,version:4,strictMode:!0,start:null,ready:null,error:null,headers:[],username:null,password:null,isAsync:!0,isCors:!0,openAjaxRequests:0,isHashRoute:!0,appending:""},r.config=function(e){r.oConfig=n(r.oConfig,e)},r.isEndpoint=function(){return null!==r.oConfig.endpoint},"undefined"==typeof e?r:new t(e,r.oConfig)}function t(n,t){function r(){if("undefined"!=typeof e){var n=e;return n}if("undefined"==typeof window){var n=require("q");return n}return null}function o(e,n,t,r){if(A(n)){var o="",a=[];for(i=0;i0?"?"+e.substring(1):""}function f(e){for(var n=0;n-1||e.toUpperCase().indexOf("HTTPS://")>-1?I=!1:B.oConfig.endpoint||k("You can not use resource query without defining your oData endpoint. Use o().config({endpoint:yourEndpoint}) to define your oData endpoint."),routeName=e,h(e),B)}function v(e){w("$expand")?(U.queryList[U.query.$expand].value+=","+e,U.queryList[U.query.$expand].original=U.queryList[U.query.$expand].value):C("$expand",e,e)}function m(e){var n=e.split("?"),t=e,r="",o={path:[],appending:"",query:{},queryList:[],method:"GET",data:null,progress:null};if(2===n.length){t=n[0],r=n[1];for(var a=r.split("&"),i=0;i0?e:void k(n+": Parameter must be set.")}function O(e,n){if("number"==typeof e)return e;var t=n;return e&&e.length>0&&(isNaN(e)||(t=parseInt(e))),t}function P(e){for(var n=0,t=0;t-1&&n++;return n}function E(e){for(var n=[],t=0;t-1&&n.push(t);for(var t=n.length-1;t>=0;t--)G.splice(n[t],1);G[0]&&(U=G[0])}function b(e){return JSON?JSON.stringify(e):(k("No JSON support."),e)}function A(e){return"undefined"==typeof Array.isArray?"[object Array]"===e.toString():Array.isArray(e)}function R(e,n){return e?-1!==e.indexOf(n,e.length-n.length):!1}function N(e,n){return 0===e.indexOf(n)}function k(e){function n(e){this.message=e,this.name="o.js exception"}if(n.prototype=new Error,B.oConfig.strictMode===!0)throw new n(e);console.log("o.js exception: "+e)}function L(e,n){var t="",r=$(),o=!1;n&&(t+="--batch_"+e+"\n",t+="Content-Type: multipart/mixed; boundary=changeset_"+r+"\n\n");var a=null;null!==B.oConfig.endpoint&&(a=B.oConfig.endpoint.indexOf("://")>-1?B.oConfig.endpoint.split("/")[2]:B.oConfig.endpoint.split("/")[0],a=a.split(":")[0]);for(var i=0;i=200&&e.status<300){if(204!==e.status)if(o){var n,a=[],s=/({[\s\S]*?--batchresponse_)/g;do n=s.exec(e.responseText),n&&(D(n[0].substring(0,n[0].length-16),f),a.push(f.data));while(n);f.data=a}else D(e.responseText,f);X&&X.resolve(f),"function"==typeof t&&t.call(f,f.data,i)}else try{var p=e.responseText;if(JSON&&""!=e.responseText&&(p=JSON.parse(e.responseText)),""!==p&&p["odata.error"]){var l=p["odata.error"].message.value+" | HTTP Status: "+e.status+" | oData Code: "+p["odata.error"].code;k(l)}else k("Request to "+u()+" failed with HTTP status "+(e.status||404)+".")}catch(d){if(H(f,!0,e.status||404,e.responseText),"function"==typeof r)r(e.status||404,d);else{if(!X)throw d;d.status=e.status||404,X.reject(d)}}H(f,!1)}},B.oConfig.username&&B.oConfig.password&&(z&&k("CORS and Basic Auth is not supported for IE <= 9. Try to set isCors:false in the OData config if you do not need CORS support."),e.setRequestHeader("Authorization","Basic "+Y(B.oConfig.username+":"+B.oConfig.password))),!z){if(a)for(var p=0;p0)for(var p=0;p>2,i=(3&t)<<4|r>>4,u=(15&r)<<2|o>>6,s=63&o,isNaN(r)?u=s=64:isNaN(o)&&(s=64),f=f+this._keyStr.charAt(a)+this._keyStr.charAt(i)+this._keyStr.charAt(u)+this._keyStr.charAt(s);return f},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");for(var n="",t=0;tr?n+=String.fromCharCode(r):r>127&&2048>r?(n+=String.fromCharCode(r>>6|192),n+=String.fromCharCode(63&r|128)):(n+=String.fromCharCode(r>>12|224),n+=String.fromCharCode(r>>6&63|128),n+=String.fromCharCode(63&r|128))}return n}};return n.encode(e)}var B=this,U=null,G=[],M=[],I=!0,X=null,F=null,z=!1,Q=function(){},W={},K={"==":"eq","===":"eq","!=":"ne","!==":"ne",">":"gt",">=":"ge","<":"lt","<=":"le","&&":"and","||":"or","!":"not","*":"mul","%":"mod"};return B.data=[],B.inlinecount=null,B.param={},B.oConfig=t,B.routes=B.route=function(e,n){A(e)||(e=[e]),"undefined"==typeof window&&k("Routes are only supported in a browser env.");for(var t=window.location.hash,r=0;rt;t++)for(e in arguments[t])arguments[t].hasOwnProperty(e)&&(n[e]=arguments[t][e]);return n}var r=this;return r.oConfig=r.oConfig||{endpoint:null,format:"json",autoFormat:!0,version:4,strictMode:!0,start:null,ready:null,error:null,headers:[],username:null,password:null,isAsync:!0,isCors:!0,openAjaxRequests:0,isHashRoute:!0,appending:""},r.config=function(e){r.oConfig=n(r.oConfig,e)},r.isEndpoint=function(){return null!==r.oConfig.endpoint},"undefined"==typeof e?r:new t(e,r.oConfig)}function t(n,t){function r(){if("undefined"!=typeof e){var n=e;return n}if("undefined"==typeof window){var n=require("q");return n}return null}function o(e,n,t,r){if(A(n)){var o="",a=[];for(i=0;i0?"?"+e.substring(1):""}function f(e){for(var n=0;n-1||e.toUpperCase().indexOf("HTTPS://")>-1?I=!1:B.oConfig.endpoint||k("You can not use resource query without defining your oData endpoint. Use o().config({endpoint:yourEndpoint}) to define your oData endpoint."),routeName=e,h(e),B)}function v(e){w("$expand")?(U.queryList[U.query.$expand].value+=","+e,U.queryList[U.query.$expand].original=U.queryList[U.query.$expand].value):C("$expand",e,e)}function m(e){var n=e.split("?"),t=e,r="",o={path:[],appending:"",query:{},queryList:[],method:"GET",data:null,progress:null};if(2===n.length){t=n[0],r=n[1];for(var a=r.split("&"),i=0;i0?e:void k(n+": Parameter must be set.")}function O(e,n){if("number"==typeof e)return e;var t=n;return e&&e.length>0&&(isNaN(e)||(t=parseInt(e))),t}function P(e){for(var n=0,t=0;t-1&&n++;return n}function E(e){for(var n=[],t=0;t-1&&n.push(t);for(var t=n.length-1;t>=0;t--)G.splice(n[t],1);G[0]&&(U=G[0])}function b(e){return JSON?JSON.stringify(e):(k("No JSON support."),e)}function A(e){return"undefined"==typeof Array.isArray?"[object Array]"===e.toString():Array.isArray(e)}function R(e,n){return e?-1!==e.indexOf(n,e.length-n.length):!1}function N(e,n){return 0===e.indexOf(n)}function k(e){function n(e){this.message=e,this.name="o.js exception"}if(n.prototype=new Error,B.oConfig.strictMode===!0)throw new n(e);console.log("o.js exception: "+e)}function L(e,n){var t="",r=$(),o=!1;n&&(t+="--batch_"+e+"\n",t+="Content-Type: multipart/mixed; boundary=changeset_"+r+"\n\n");var a=null;null!==B.oConfig.endpoint&&(a=B.oConfig.endpoint.indexOf("://")>-1?B.oConfig.endpoint.split("/")[2]:B.oConfig.endpoint.split("/")[0],a=a.split(":")[0]);for(var i=0;i=200&&e.status<300){if(204!==e.status)if(o){var n,a=[],s=/({[\s\S]*?--batchresponse_)/g;do n=s.exec(e.responseText),n&&(D(n[0].substring(0,n[0].length-16),f),a.push(f.data));while(n);f.data=a}else D(e.responseText,f);X&&X.resolve(f),"function"==typeof t&&t.call(f,f.data,i)}else try{var p=e.responseText;if(JSON&&""!=e.responseText&&(p=JSON.parse(e.responseText)),""!==p&&p["odata.error"]){var l=p["odata.error"].message.value+" | HTTP Status: "+e.status+" | oData Code: "+p["odata.error"].code;k(l)}else k("Request to "+u()+" failed with HTTP status "+(e.status||404)+".")}catch(d){if(H(f,!0,e.status||404,e.responseText),"function"==typeof r)r(e.status||404,d);else{if(!X)throw d;d.status=e.status||404,X.reject(d)}}H(f,!1)}},B.oConfig.username&&B.oConfig.password&&(z&&k("CORS and Basic Auth is not supported for IE <= 9. Try to set isCors:false in the OData config if you do not need CORS support."),e.setRequestHeader("Authorization","Basic "+Y(B.oConfig.username+":"+B.oConfig.password))),!z){if(a)for(var p=0;p0)for(var p=0;p>2,i=(3&t)<<4|r>>4,u=(15&r)<<2|o>>6,s=63&o,isNaN(r)?u=s=64:isNaN(o)&&(s=64),f=f+this._keyStr.charAt(a)+this._keyStr.charAt(i)+this._keyStr.charAt(u)+this._keyStr.charAt(s);return f},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");for(var n="",t=0;tr?n+=String.fromCharCode(r):r>127&&2048>r?(n+=String.fromCharCode(r>>6|192),n+=String.fromCharCode(63&r|128)):(n+=String.fromCharCode(r>>12|224),n+=String.fromCharCode(r>>6&63|128),n+=String.fromCharCode(63&r|128))}return n}};return n.encode(e)}var B=this,U=null,G=[],M=[],I=!0,X=null,F=null,z=!1,Q=function(){},W={},K={"==":"eq","===":"eq","!=":"ne","!==":"ne",">":"gt",">=":"ge","<":"lt","<=":"le","&&":"and","||":"or","!":"not","*":"mul","%":"mod"};return B.data=[],B.inlinecount=null,B.param={},B.oConfig=t,B.routes=B.route=function(e,n){A(e)||(e=[e]),"undefined"==typeof window&&k("Routes are only supported in a browser env.");for(var t=window.location.hash,r=0;r= 0, printResult(this,data)); + done(); + }, function(e) { + assert.ok(e === 200, printResult(this, e)); + done() + }); + }); + QUnit.test('GET People(\''+testEntity.UserName+'\') - endpoint - no query', function(assert) { var done = assert.async(); o('People(\''+testEntity.UserName+'\')').get(function(data) {