-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsdata-client.js
More file actions
4 lines (4 loc) · 31.4 KB
/
Copy pathsdata-client.js
File metadata and controls
4 lines (4 loc) · 31.4 KB
1
2
3
4
/*
*
*/
var XML=window.XML;if(typeof(XML)=="undefined"){XML=function(){}}XML.ObjTree=function(){console.warn("xml obj transformation is not implemented.");return this};XML.ObjTree.VERSION="0.10";XML.ObjTree.prototype.xmlDecl='<?xml version="1.0" encoding="UTF-8" ?>\n';XML.ObjTree.prototype.attr_prefix="-";XML.ObjTree.prototype.overrideMimeType="text/xml";XML.ObjTree.prototype.parseXML=function(a){console.warn("parseXML is not implemented.")};XML.ObjTree.prototype.parseHTTP=function(b,a,c){console.warn("parseHTTP is not implemented.")};XML.ObjTree.prototype.parseDOM=function(a){console.warn("praseDom is not implemented.")};XML.ObjTree.prototype.parseElement=function(a){console.warn("parseElement is not implemented.")};XML.ObjTree.prototype.addNode=function(c,a,b,d){console.warn("addNode is not implemented.")};XML.ObjTree.prototype.writeXML=function(a){console.warn("writeXML is not implemented.")};XML.ObjTree.prototype.hash_to_xml=function(b,a){console.warn("hash_to_xml is not implemented.")};XML.ObjTree.prototype.array_to_xml=function(a,b){console.warn("array_to_xml is not implemented.")};XML.ObjTree.prototype.scalar_to_xml=function(a,b){console.warn("scalar_to_xml is not implemented.")};XML.ObjTree.prototype.xml_escape=function(a){console.warn("xml_escape is not implemented.")};(function(){var b=window.Sage,e=b,a=b.namespace("Sage.SData.Client.Ajax");var f=function(j){return((j>=200&&j<300)||j===304)};var c=function(n,m){if(n.readyState==4){if(f(n.status)){if(m.success){m.success.call(m.scope||this,n,m)}}else{if(n.status===0){var l=false;try{l=(n.statusText==="")}catch(j){l=true}if(l){var k=m.aborted||m.failure;if(k){k.call(m.scope||this,n,m)}}else{if(m.failure){m.failure.call(m.scope||this,n,m)}}}else{if(m.failure){m.failure.call(m.scope||this,n,m)}}}}};var g=function(l,k){var j=k.timeout||k.failure;if(j){j.call(k.scope||this,l,k)}};var d=function(k,j){k.ontimeout=function(){g.call(k,k,j)}};var i=function(k,j){k.onreadystatechange=function(){c.call(k,k,j)}};var h=function(k){var j=[];for(var l in k){j.push(encodeURIComponent(l)+"="+encodeURIComponent(k[l]))}return j.join("&")};b.apply(b.SData.Client.Ajax,{request:function(p){p=e.apply({},p);p.params=e.apply({},p.params);p.headers=e.apply({},p.headers);if(p.cache!==true){p.params[p.cacheParam||"_t"]=(new Date()).getTime()}p.method=p.method||"GET";var k=h(p.params);if(k){p.url=p.url+(/\?/.test(p.url)?"&":"?")+k}var m=new XMLHttpRequest();if(p.user){m.open(p.method,p.url,p.async!==false,p.user,p.password)}else{m.open(p.method,p.url,p.async!==false)}if(p.withCredentials){m.withCredentials=true}try{m.setRequestHeader("Accept",p.accept||"*/*");m.setRequestHeader("X-Requested-With","XMLHttpRequest");if(p.contentType){m.setRequestHeader("Content-Type",p.contentType)}for(var q in p.headers){m.setRequestHeader(q,p.headers[q])}var j=p.etagCache;if(p.cache&&j&&j.etag){m.setRequestHeader("If-None-Match",j.etag)}}catch(l){}if(p.async!==false){if(typeof p.requestTimeout==="number"&&p.requestTimeout>=0&&typeof m.timeout==="number"){m.timeout=p.requestTimeout;d(m,p)}i(m,p);m.send(p.body||null)}else{m.send(p.body||null);c(m,p)}return m},cancel:function(j){j.abort()}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataBaseRequest=b.Class.define({service:null,uri:null,completeHeaders:null,extendedHeaders:null,constructor:function(d){this.base.apply(this,arguments);this.service=d;this.completeHeaders={};this.extendedHeaders={};this.uri=new b.SData.Client.SDataUri();var f,e;if(this.service){this.uri.setVersion(this.service.getVersion());f=this.service.getIncludeContent();if(typeof f!=="undefined"){this.uri.setIncludeContent(f)}this.uri.setServer(this.service.getVirtualDirectory()?this.service.getVirtualDirectory():"sdata");this.uri.setScheme(this.service.getProtocol());this.uri.setHost(this.service.getServerName());this.uri.setPort(this.service.getPort());e=this.service.getCompact();if(typeof e!=="undefined"){this.uri.setCompact(e)}}},clone:function(){return new b.SData.Client.SDataBaseRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},setRequestHeader:function(d,e){this.completeHeaders[d]=e},extendRequestHeader:function(d,e){this.extendedHeaders[d]=e},clearRequestHeader:function(d){delete this.completeHeaders[d];delete this.extendedHeaders[d]},getAccept:function(){return this.extendedHeaders.Accept},setAccept:function(d){this.extendRequestHeader("Accept",d);return this},getService:function(){return this.service},getUri:function(){return this.uri},setUri:function(d){this.uri=d;return this},getServerName:function(){return this.uri.getHost()},setServerName:function(d){this.uri.setHost(d);return this},getVirtualDirectory:function(){return this.uri.getServer()},setVirtualDirectory:function(d){this.uri.setServer(d);return this},getProtocol:function(){return this.uri.getScheme()},setProtocol:function(d){this.uri.setScheme(d);return this},getPort:function(){return this.uri.getPort()},setPort:function(d){this.uri.setPort(d);return this},getQueryArgs:function(){return this.uri.getQueryArgs()},setQueryArgs:function(e,d){this.uri.setQueryArgs(e,d);return this},getQueryArg:function(d){return this.uri.getQueryArg(d)},setQueryArg:function(d,e){this.uri.setQueryArg(d,e);return this},build:function(d){return this.uri.build(d)},toString:function(d){return this.build(d)}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataApplicationRequest=b.SData.Client.SDataBaseRequest.extend({constructor:function(){this.base.apply(this,arguments);if(this.service){this.uri.setProduct(this.service.getApplicationName()?this.service.getApplicationName():"-");this.uri.setContract(this.service.getContractName()?this.service.getContractName():"-");this.uri.setCompanyDataset(this.service.getDataSet()?this.service.getDataSet():"-")}},clone:function(){return new b.SData.Client.SDataApplicationRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},getApplicationName:function(){return this.uri.getProduct()},setApplicationName:function(d){this.uri.setProduct(d);return this},getContractName:function(){return this.uri.getContract()},setContractName:function(d){this.uri.setContract(d);return this},getDataSet:function(){return this.uri.getCompanyDataset()},setDataSet:function(d){this.uri.setCompanyDataset(d);return this},getResourceKind:function(){return this.uri.getCollectionType()},setResourceKind:function(d){this.uri.setCollectionType(d);return this}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataResourceCollectionRequest=b.SData.Client.SDataApplicationRequest.extend({constructor:function(){this.base.apply(this,arguments)},clone:function(){return new b.SData.Client.SDataResourceCollectionRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},getCount:function(){return this.uri.getCount()},setCount:function(d){this.uri.setCount(d);return this},getStartIndex:function(){return this.uri.getStartIndex()},setStartIndex:function(d){this.uri.setStartIndex(d);return this},read:function(d){return this.service.readFeed(this,d)}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataNamedQueryRequest=b.SData.Client.SDataResourceCollectionRequest.extend({constructor:function(){this.base.apply(this,arguments);this.uri.setPathSegment(c.SDataUri.ResourcePropertyIndex,c.SDataUri.NamedQuerySegment)},clone:function(){return new b.SData.Client.SDataNamedQueryRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},getQueryName:function(){return this.uri.getPathSegment(c.SDataUri.ResourcePropertyIndex+1)},setQueryName:function(d){this.uri.setPathSegment(c.SDataUri.ResourcePropertyIndex+1,d);return this}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataSingleResourceRequest=b.SData.Client.SDataApplicationRequest.extend({key:"",constructor:function(){this.base.apply(this,arguments)},clone:function(){return new b.SData.Client.SDataSingleResourceRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},read:function(d){return this.service.readEntry(this,d)},update:function(e,d){return this.service.updateEntry(this,e,d)},create:function(e,d){return this.service.createEntry(this,e,d)},"delete":function(e,d){return this.service.deleteEntry(this,e,d)},getResourceSelector:function(){return this.uri.getCollectionPredicate()},setResourceSelector:function(d){this.uri.setCollectionPredicate(d);return this},setResourceKey:function(d){this.key=d;this.setResourceSelector("'"+this.key+"'");return this},getResourceKey:function(){return this.key}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataResourcePropertyRequest=b.SData.Client.SDataSingleResourceRequest.extend({constructor:function(){this.base.apply(this,arguments)},clone:function(){return new b.SData.Client.SDataResourcePropertyRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},readFeed:function(d){return this.service.readFeed(this,d)},getResourceProperty:function(){return this.uri.getPathSegment(b.SData.Client.SDataUri.ResourcePropertyIndex)},setResourceProperty:function(d){this.uri.setPathSegment(b.SData.Client.SDataUri.ResourcePropertyIndex,d);return this}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataSystemRequest=b.SData.Client.SDataBaseRequest.extend({constructor:function(){this.base.apply(this,arguments);this.uri.setPathSegment(b.SData.Client.SDataUri.ProductPathIndex,b.SData.Client.SDataUri.SystemSegment)},clone:function(){return new b.SData.Client.SDataSystemRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},getCategory:function(){this.uri.getPathSegment(b.SData.Client.SDataUri.ContractTypePathIndex)},setCategory:function(d){this.uri.setPathSegment(b.SData.Client.SDataUri.ContractTypePathIndex,d);return this},read:function(d){return this.service.readFeed(this,d)}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataTemplateResourceRequest=b.SData.Client.SDataApplicationRequest.extend({constructor:function(){this.base.apply(this,arguments);this.uri.setPathSegment(b.SData.Client.SDataUri.ResourcePropertyIndex,b.SData.Client.SDataUri.TemplateSegment)},clone:function(){return new b.SData.Client.SDataTemplateResourceRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},read:function(d){return this.service.readEntry(this,d)}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataServiceOperationRequest=b.SData.Client.SDataApplicationRequest.extend({constructor:function(){this.base.apply(this,arguments);this.uri.setPathSegment(c.SDataUri.ResourcePropertyIndex,c.SDataUri.ServiceMethodSegment)},clone:function(){return new b.SData.Client.SDataServiceOperationRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri))},execute:function(e,d){return this.service.executeServiceOperation(this,e,d)},getOperationName:function(){return this.uri.getPathSegment(c.SDataUri.ResourcePropertyIndex+1)},setOperationName:function(d){this.uri.setPathSegment(c.SDataUri.ResourcePropertyIndex+1,d);return this}})})();(function(){var b=window.Sage,a=b,c=b.namespace("Sage.SData.Client");b.SData.Client.SDataBatchRequest=b.SData.Client.SDataApplicationRequest.extend({items:null,constructor:function(){this.base.apply(this,arguments);this.items=[];this.uri.setPathSegment(b.SData.Client.SDataUri.ResourcePropertyIndex,b.SData.Client.SDataUri.BatchSegment)},clone:function(){return new b.SData.Client.SDataBatchRequest(this.service).setUri(new b.SData.Client.SDataUri(this.uri)).setItems(this.items.slice(0))},getItems:function(){return this.items},setItems:function(d){this.items=d;return this},using:function(f,d){if(this.service){this.service.registerBatchScope(this)}else{throw"A service must be associated with the batch request."}try{f.call(d||this,this)}catch(g){this.service.clearBatchScope(this);throw g}this.service.clearBatchScope(this);return this},add:function(d){this.items.push(d)},commit:function(d){this.service.commitBatch(this,d)}})})();(function(){var b=window.Sage,a=b,d=b.namespace("Sage.SData.Client"),c=/^true$/i;b.SData.Client.SDataUri=b.Class.define({scheme:"http",host:"",server:"",port:-1,version:null,queryArgs:null,pathSegments:null,constructor:function(e){this.base.apply(this,arguments);a.apply(this,e);this.queryArgs=a.apply({},e&&e.queryArgs);this.pathSegments=(e&&e.pathSegments&&e.pathSegments.slice(0))||[];this.version=(e&&e.version&&a.apply({},e.version))||{major:1,minor:0}},clone:function(){return new b.SData.Client.SDataUri(this)},getVersion:function(){return this.version},setVersion:function(e){this.version=a.apply({major:0,minor:0},e);return this},getScheme:function(){return this.scheme},setScheme:function(e){this.scheme=e;return this},getHost:function(){return this.host},setHost:function(e){this.host=e;return this},getPort:function(){return this.port},setPort:function(e){this.port=e;return this},getServer:function(){return this.server},setServer:function(e){this.server=e;return this},getQueryArgs:function(){return this.queryArgs},setQueryArgs:function(f,e){this.queryArgs=e?f:a.apply(this.queryArgs,f);return this},getQueryArg:function(e){return this.queryArgs[e]},setQueryArg:function(e,f){this.queryArgs[e]=f;return this},getPathSegments:function(){return this.pathSegments},setPathSegments:function(e){this.pathSegments=e;return this},getPathSegment:function(e){return this.pathSegments.length>e?this.pathSegments[e]:false},setPathSegment:function(f,h,e){if(!h&&!e){this.pathSegments[f]=null}else{if(typeof h==="object"){this.pathSegments[f]=a.apply({},h,this.pathSegments[f])}else{var g={};if(h){g.text=h}if(e){g.predicate=e}this.pathSegments[f]=a.apply({},g,this.pathSegments[f])}}return this},getStartIndex:function(){return this.queryArgs[d.SDataUri.QueryArgNames.StartIndex]?parseInt(this.queryArgs[d.SDataUri.QueryArgNames.StartIndex]):-1},setStartIndex:function(e){this.queryArgs[d.SDataUri.QueryArgNames.StartIndex]=e;return this},getCount:function(){return this.queryArgs[d.SDataUri.QueryArgNames.Count]?parseInt(this.queryArgs[d.SDataUri.QueryArgNames.Count]):-1},setCount:function(e){this.queryArgs[d.SDataUri.QueryArgNames.Count]=e;return this},getIncludeContent:function(){var e,f;e=this.version.major>=1?d.SDataUri.QueryArgNames.IncludeContent:d.SDataUri.QueryArgNames.LegacyIncludeContent;f=this.queryArgs[e];if(typeof f!=="undefined"){return c.test(f)}else{return f}},setCompact:function(e){this.queryArgs[d.SDataUri.QueryArgNames.Compact]=e;return this},getCompact:function(){return this.queryArgs[d.SDataUri.QueryArgNames.Compact]},setIncludeContent:function(f){var e=this.version.major>=1?d.SDataUri.QueryArgNames.IncludeContent:d.SDataUri.QueryArgNames.LegacyIncludeContent;this.queryArgs[e]=""+f;return this},appendPath:function(f){var e=typeof f==="string"?{text:f}:f;this.pathSegments.push(e);return this},toString:function(e){return this.build(e)},build:function(f){var e=[];e.push(this.getScheme()||d.SDataUri.Http);e.push(d.SDataUri.SchemeSuffix);e.push(d.SDataUri.PathSegmentPrefix);e.push(d.SDataUri.PathSegmentPrefix);e.push(this.getHost());if(this.getPort()>0){e.push(d.SDataUri.PortPrefix,this.getPort())}e.push(d.SDataUri.PathSegmentPrefix);var k=this.getPathSegments();var o=[];var h=this.getServer();if(h&&h.length>0){o=o.concat(h.split("/"))}for(var j=0;j<k.length;j++){var l=k[j];if(l&&l.text){if(l.predicate){o.push(encodeURIComponent(l.text+"("+l.predicate+")"))}else{o.push(encodeURIComponent(l.text))}}}e.push(o.join(d.SDataUri.PathSegmentPrefix));if(f){return e.join("")}var g=this.getQueryArgs();var m=[];for(var n in g){m.push(encodeURIComponent(n)+d.SDataUri.QueryArgValuePrefix+encodeURIComponent(g[n]))}if(m.length>0){e.push(d.SDataUri.QueryPrefix);e.push(m.join(d.SDataUri.QueryArgPrefix))}return e.join("")},getProduct:function(){return this.getPathSegment(d.SDataUri.ProductPathIndex)},setProduct:function(e){return this.setPathSegment(d.SDataUri.ProductPathIndex,e)},getContract:function(){return this.getPathSegment(d.SDataUri.ContractTypePathIndex)},setContract:function(e){return this.setPathSegment(d.SDataUri.ContractTypePathIndex,e)},getCompanyDataset:function(){return this.getPathSegment(d.SDataUri.CompanyDatasetPathIndex)},setCompanyDataset:function(e){return this.setPathSegment(d.SDataUri.CompanyDatasetPathIndex,e)},getCollectionType:function(){return this.getPathSegment(d.SDataUri.CollectionTypePathIndex)},setCollectionType:function(e){return this.setPathSegment(d.SDataUri.CollectionTypePathIndex,e)},getCollectionPredicate:function(){var e=this.getPathSegment(d.SDataUri.CollectionTypePathIndex);return(e&&e.predicate)||false},setCollectionPredicate:function(e){return this.setPathSegment(d.SDataUri.CollectionTypePathIndex,{predicate:e})}});b.apply(b.SData.Client.SDataUri,{Http:"http",Https:"https",PathSegmentPrefix:"/",PortPrefix:":",QueryArgPrefix:"&",QueryArgValuePrefix:"=",QueryPrefix:"?",SchemeSuffix:":",UnspecifiedPort:-1,UriName:"uri",QueryArgNames:{Compact:"_compact",Count:"count",Exclude:"exclude",Format:"format",Include:"include",IncludeContent:"_includeContent",LegacyIncludeContent:"includeContent",IncludeSchema:"includeSchema",Language:"language",OrderBy:"orderby",Precedence:"precedence",ReturnDelta:"returnDelta",Search:"search",Select:"select",StartIndex:"startIndex",Thumbnail:"thumbnail",TrackingID:"trackingID",Where:"where"},ProductPathIndex:0,ContractTypePathIndex:1,CompanyDatasetPathIndex:2,CollectionTypePathIndex:3,ResourcePropertyIndex:4,ServiceMethodSegment:"$service",TemplateSegment:"$template",SystemSegment:"$system",NamedQuerySegment:"$queries",BatchSegment:"$batch"})})();(function(){var d=window.Sage,c=d,f=d.namespace("Sage.SData.Client"),b=function(g){return typeof g!=="undefined"},a=function(g){return g&&g["#text"]?g["#text"]:g},e=/^(.+?):(.*)$/;d.SData.Client.SDataService=d.Evented.extend({uri:null,useCredentialedRequest:false,useCrossDomainCookies:false,userAgent:"Sage",userName:false,password:"",batchScope:null,timeout:0,cache:false,cacheParam:"_t",_etags:{},maxGetUriLength:2000,constructor:function(h,i,g){this.base.call(this,h);this.setUri(h);if(b(h.includeContent)){this.uri.setIncludeContent(h.includeContent)}if(b(h.version)){this.uri.setVersion(h.version)}if(b(h.cache)){this.cache=h.cache}if(b(h.cacheParam)){this.cacheParam=h.cacheParam}if(b(h.compact)){this.uri.setCompact(h.compact)}if(b(h.userName)){this.userName=h.userName}if(b(h.password)){this.password=h.password}if(b(i)){this.userName=i}if(b(g)){this.password=g}if(b(h.json)){this.json=h.json}if(b(h.maxGetUriLength)){this.maxGetUriLength=h.maxGetUriLength}if(b(h.timeout)){this.timeout=h.timeout}if(b(h.useCredentialedRequest)){this.useCredentialedRequest=h.useCredentialedRequest}if(b(h.useCrossDomainCookies)){this.useCrossDomainCookies=h.useCrossDomainCookies}this.addEvents("beforerequest","requestcomplete","requestexception","requestaborted","requesttimeout")},setUri:function(h){if(b(h.uri)){this.uri=new d.SData.Client.SDataUri(h.uri)}else{this.uri=new d.SData.Client.SDataUri();var g=this.parseUri(h);if(b(g.serverName)){this.uri.setHost(g.serverName)}if(b(g.virtualDirectory)){this.uri.setServer(g.virtualDirectory)}if(b(g.applicationName)){this.uri.setProduct(g.applicationName)}if(b(g.contractName)){this.uri.setContract(g.contractName)}if(b(g.dataSet)){this.uri.setCompanyDataset(g.dataSet)}if(b(g.port)){this.uri.setPort(g.port)}if(b(g.protocol)){this.uri.setScheme(g.protocol)}}return this},parseUri:function(j){var g={},i=typeof j==="object"?j.url:j;var h=(typeof window.parseUri==="function")&&window.parseUri(i);if(h){if(h.host){g.serverName=h.host}var k=h.path.split("/").slice(1);if(k[0]){g.virtualDirectory=k[0]}if(k[1]){g.applicationName=k[1]}if(k[2]){g.contractName=k[2]}if(k[3]){g.dataSet=k[3]}if(h.port){g.port=parseInt(h.port)}if(h.protocol){g.protocol=h.protocol}}if(typeof j==="object"){c.apply(g,j)}return g},isJsonEnabled:function(){return this.json},enableJson:function(){this.json=true;return this},disableJson:function(){this.json=false;return this},getVersion:function(){return this.uri.getVersion()},setVersion:function(g){this.uri.setVersion(g);return this},getUri:function(){return this.uri},getUserName:function(){return this.userName},setUserName:function(g){this.userName=g;return this},getPassword:function(){return this.password},setPassword:function(g){this.password=g;return this},getProtocol:function(){return this.uri.getScheme()},setProtocol:function(g){this.uri.setScheme(g);return this},getServerName:function(){return this.uri.getHost()},setServerName:function(g){this.uri.setHost(g);return this},getPort:function(){return this.uri.getPort()},setPort:function(g){this.uri.setPort(g);return this},getVirtualDirectory:function(){return this.uri.getServer()},setVirtualDirectory:function(g){this.uri.setServer(g);return this},getApplicationName:function(){return this.uri.getProduct()},setApplicationName:function(g){this.uri.setProduct(g);return this},getContractName:function(){return this.uri.getContract()},setContractName:function(g){this.uri.setContract(g);return this},getDataSet:function(){return this.uri.getCompanyDataset()},setDataSet:function(g){this.uri.setCompanyDataset(g);return this},getIncludeContent:function(){return this.uri.getIncludeContent()},setIncludeContent:function(g){this.uri.setIncludeContent(g);return this},getCompact:function(){return this.uri.getCompact()},setCompact:function(g){this.uri.setCompact(g);return this},setMaxGetUriLength:function(g){this.maxGetUriLength=g;return this},getMaxGetUriLength:function(){return this.maxGetUriLength},getUserAgent:function(){return this.userAgent},setUserAgent:function(g){this.userAgent=g;return this},registerBatchScope:function(g){this.batchScope=g},clearBatchScope:function(g){this.batchScope=null},createBasicAuthToken:function(){return"Basic "+Base64.encode(this.userName+":"+this.password)},createHeadersForRequest:function(g){var h={"X-Authorization-Mode":"no-challenge"};if(this.userName&&!this.useCredentialedRequest){h.Authorization=h["X-Authorization"]=this.createBasicAuthToken()}return h},extendAcceptRequestHeader:function(g,h){if(g){return g.split(/\s*,\s*/).join(";"+h+",")+";"+h}return g},executeRequest:function(i,h,j){if(this.json){i.setQueryArg("format","json")}var g=i.build();var k=c.apply({async:h.async,headers:{},method:"GET",url:g,cache:h.cache||this.cache,cacheParam:h.cacheParam||this.cacheParam,etagCache:this._etags[g]},{scope:this,success:function(l,m){var p=l.responseText;if(l.status===304){p=this._etags[g].responseText}var q=l.getResponseHeader&&l.getResponseHeader("Content-Type");var o=this.processFeed(p,q);var n=l.getResponseHeader&&l.getResponseHeader("etag");this._etags[g]={etag:n,responseText:p};this.fireEvent("requestcomplete",i,m,o);if(h.success){h.success.call(h.scope||this,o)}},failure:function(l,m){this.fireEvent("requestexception",i,m,l);if(h.failure){h.failure.call(h.scope||this,l,m)}},aborted:function(l,m){this.fireEvent("requestaborted",i,m,l);if(h.aborted){h.aborted.call(h.scope||this,l,m)}},timeout:function(l,m){this.fireEvent("requesttimeout",i,m,l);if(h.timeout){h.timeout.call(h.scope||this,l,m)}}},j);c.apply(k.headers,this.createHeadersForRequest(i),i.completeHeaders);if(typeof this.timeout==="number"){k.requestTimeout=this.timeout}if(i.extendedHeaders.Accept){k.headers.Accept=this.extendAcceptRequestHeader(k.headers.Accept,i.extendedHeaders.Accept)}if(this.useCredentialedRequest||this.useCrossDomainCookies){k.withCredentials=true}if(this.useCredentialedRequest&&this.userName){k.user=this.userName;k.password=this.password}this.fireEvent("beforerequest",i,k);if(typeof k.result!=="undefined"){if(h.success){h.success.call(h.scope||this,k.result)}return}return f.Ajax.request(k)},abortRequest:function(g){f.Ajax.cancel(g)},readFeed:function(i,g){g=g||{};if(this.batchScope){this.batchScope.add({url:i.build(),method:"GET"});return}var j={headers:{Accept:this.json?"application/json,*/*":"application/atom+xml;type=feed,*/*"}};var h=i.build();if(g.httpMethodOverride||(typeof h==="string"&&h.length>this.maxGetUriLength)){if(this.json){i.setQueryArg("format","json")}j.headers["X-HTTP-Method-Override"]="GET";j.method="POST";j.body=i.build();j.url=i.build(true)}return this.executeRequest(i,g,j)},readEntry:function(j,g){g=g||{};if(this.batchScope){var i={url:j.build(),method:"GET"};var h=j.getResourceKey();if(typeof h==="string"&&h.length>0){i.key=h}this.batchScope.add(i);return}var k=c.apply({},{success:function(m){var l=m["$resources"][0]||false;if(g.success){g.success.call(g.scope||this,l)}}},g);return this.executeRequest(j,k,{headers:{Accept:this.json?"application/json,*/*":"application/atom+xml;type=entry,*/*"}})},createEntry:function(j,i,h){h=h||{};if(this.batchScope){this.batchScope.add({url:j.build(),entry:i,method:"POST"});return}var l=c.apply({},{success:function(n){var m=n["$resources"][0]||false;if(h.success){h.success.call(h.scope||this,m)}}},h);var k=c.apply({},{method:"POST"});if(this.isJsonEnabled()){c.apply(k,{body:JSON.stringify(i),headers:{"Content-Type":"application/json"}})}else{var g=new XML.ObjTree();g.attr_prefix="@";c.apply(k,{body:g.writeXML(this.formatEntry(i)),headers:{"Content-Type":"application/atom+xml;type=entry",Accept:"application/atom+xml;type=entry,*/*"}})}return this.executeRequest(j,l,k)},updateEntry:function(j,i,h){h=h||{};if(this.batchScope){this.batchScope.add({url:j.build(),entry:i,method:"PUT",etag:i["$etag"]});return}var m=c.apply({},{success:function(o){var n=o["$resources"][0]||false;if(h.success){h.success.call(h.scope||this,n)}}},h);var l={},k={method:"PUT",headers:l};if(i["$etag"]&&!(h&&h.ignoreETag)){l["If-Match"]=i["$etag"]}if(this.isJsonEnabled()){l["Content-Type"]="application/json";k.body=JSON.stringify(i)}else{var g=new XML.ObjTree();g.attr_prefix="@";l["Content-Type"]="application/atom+xml;type=entry";l.Accept="application/atom+xml;type=entry,*/*";k.body=g.writeXML(this.formatEntry(i))}return this.executeRequest(j,m,k)},deleteEntry:function(i,h,g){g=g||{};if(this.batchScope){this.batchScope.add({url:i.build(),method:"DELETE",etag:!(g&&g.ignoreETag)&&h["$etag"]});return}var k={},j={method:"DELETE",headers:k};if(h["$etag"]&&!(g&&g.ignoreETag)){k["If-Match"]=h["$etag"]}return this.executeRequest(i,g,j)},executeServiceOperation:function(j,i,h){var l=c.apply({},{success:function(o){if(typeof o==="undefined"||o===null){o={}}var n=o.$resources&&o.$resources[0]||false,m=n&&n.response,q=m&&m["$resources"],p=q&&q[0];if(p&&p["$name"]){n.response={};n.response[p["$name"]]=p}if(h.success){h.success.call(h.scope||this,n)}}},h);var k=c.apply({},{method:"POST"});if(this.isJsonEnabled()){c.apply(k,{body:JSON.stringify(i),headers:{"Content-Type":"application/json"}})}else{var g=new XML.ObjTree();g.attr_prefix="@";c.apply(k,{body:g.writeXML(this.formatEntry(i)),headers:{"Content-Type":"application/atom+xml;type=entry",Accept:"application/atom+xml;type=entry,*/*"}})}return this.executeRequest(j,l,k)},commitBatch:function(g,p){p=p||{};var k=g.getItems(),o,m,n={"$resources":[]};for(var h=0;h<k.length;h++){o=k[h];m=c.apply({},o.entry);if(o.url){m["$url"]=o.url}if(o.key){m["$key"]=o.key}if(o.etag){m["$ifMatch"]=o.etag}if(o.method){m["$httpMethod"]=o.method}delete m["$etag"];n["$resources"].push(m)}var l=c.apply({},{method:"POST"});if(this.isJsonEnabled()){c.apply(l,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"}})}else{var j=new XML.ObjTree();j.attr_prefix="@";c.apply(l,{body:j.writeXML(this.formatFeed(n)),headers:{"Content-Type":"application/atom+xml;type=feed",Accept:"application/atom+xml;type=feed,*/*"}})}return this.executeRequest(g,p,l)},parseFeedXml:function(h){var g=new XML.ObjTree();g.attr_prefix="@";return g.parseXML(h)},isIncludedReference:function(h,g,i){return i&&i.hasOwnProperty("@sdata:key")},isIncludedCollection:function(j,h,k){if(k.hasOwnProperty("@sdata:key")){return false}if(k.hasOwnProperty("@sdata:uri")||k.hasOwnProperty("@sdata:url")){return true}var l,i;for(var g in k){if(g.charAt(0)==="@"){continue}l=k[g];break}if(l){if(c.isArray(l)){i=l[0]}else{i=l}if(i&&i.hasOwnProperty("@sdata:key")){return true}}return false},convertEntity:function(l,g,i,h){h=h||{};h["$name"]=g;h["$key"]=i["@sdata:key"];h["$url"]=i["@sdata:uri"];h["$uuid"]=i["@sdata:uuid"];for(var o in i){if(o.charAt(0)==="@"){continue}var p=e.exec(o),j=p?p[1]:false,k=p?p[2]:o,n=null,m=i[o];if(typeof m==="object"){if(m.hasOwnProperty("@xsi:nil")){n=null}else{if(this.isIncludedReference(j,k,m)){n=this.convertEntity(j,k,m)}else{if(this.isIncludedCollection(j,k,m)){n=this.convertEntityCollection(j,k,m)}else{n=this.convertCustomEntityProperty(j,k,m)}}}m=n}h[k]=m}return h},convertEntityCollection:function(m,g,j){for(var p in j){if(p.charAt(0)==="@"){continue}var q=e.exec(p),k=q?q[1]:false,l=q?q[2]:p,n=j[p];if(c.isArray(n)){var o=[];for(var h=0;h<n.length;h++){o.push(this.convertEntity(m,l,n[h]))}return{"$resources":o}}else{return{"$resources":[this.convertEntity(m,l,n)]}}break}return null},convertCustomEntityProperty:function(h,g,i){return i},formatEntity:function(i,h,k){k=k||{};if(h["$key"]){k["@sdata:key"]=h["$key"]}for(var g in h){if(g.charAt(0)==="$"){continue}var j=h[g];if(j==null){j={"@xsi:nil":"true"}}else{if(typeof j==="object"&&j.hasOwnProperty("$resources")){j=this.formatEntityCollection(i,j)}else{if(typeof j==="object"){j=this.formatEntity(i,j)}}}k[g]=j}return k},formatEntityCollection:function(k,m){var g={};for(var j=0;j<m["$resources"].length;j++){var l=m["$resources"][j],h=l["$name"],n=(g[h]=g[h]||[]);n.push(this.formatEntity(k,m["$resources"][j]))}return g},convertEntry:function(l){var g={};g["$descriptor"]=l.title;g["$etag"]=l["http:etag"];g["$httpStatus"]=l["http:httpStatus"];var n=l["sdata:payload"];for(var j in n){if(j.charAt(0)==="@"){continue}if(n.hasOwnProperty(j)==false){continue}var m=j.split(":"),k,i,h=n[j];if(m.length==2){k=m[0];i=m[1]}else{if(m.length<2){k=false;i=j}else{continue}}this.convertEntity(k,i,h,g)}return g},formatEntry:function(h,i){var g={};if(!i){g["@xmlns:sdata"]="http://schemas.sage.com/sdata/2008/1";g["@xmlns:xsi"]="http://www.w3.org/2001/XMLSchema-instance";g["@xmlns:http"]="http://schemas.sage.com/sdata/http/2008/1";g["@xmlns"]="http://www.w3.org/2005/Atom"}if(h["$httpMethod"]){g["http:httpMethod"]=h["$httpMethod"]}if(h["$ifMatch"]){g["http:ifMatch"]=h["$ifMatch"]}if(h["$etag"]){g["http:etag"]=h["$etag"]}if(h["$url"]){g.id=h["$url"]}g["sdata:payload"]={};g["sdata:payload"][h["$name"]]={"@xmlns":"http://schemas.sage.com/dynamic/2007"};this.formatEntity(false,h,g["sdata:payload"][h["$name"]]);return{entry:g}},convertFeed:function(j){var g={},h;if(j["opensearch:totalResults"]){g["$totalResults"]=parseInt(a(j["opensearch:totalResults"]))}if(j["opensearch:startIndex"]){g["$startIndex"]=parseInt(a(j["opensearch:startIndex"]))}if(j["opensearch:itemsPerPage"]){g["$itemsPerPage"]=parseInt(a(j["opensearch:itemsPerPage"]))}if(j.link){g["$link"]={};for(h=0;h<j.link.length;h++){g["$link"][j.link[h]["@rel"]]=j.link[h]["@href"]}if(g["$link"]["self"]){g["$url"]=g["$link"]["self"]}}g["$resources"]=[];if(c.isArray(j.entry)){for(h=0;h<j.entry.length;h++){g["$resources"].push(this.convertEntry(j.entry[h]))}}else{if(typeof j.entry==="object"){g["$resources"].push(this.convertEntry(j.entry))}}return g},formatFeed:function(j){var g={};g["@xmlns:sdata"]="http://schemas.sage.com/sdata/2008/1";g["@xmlns:xsi"]="http://www.w3.org/2001/XMLSchema-instance";g["@xmlns:http"]="http://schemas.sage.com/sdata/http/2008/1";g["@xmlns"]="http://www.w3.org/2005/Atom";if(j["$url"]){g.id=j["$url"]}g.entry=[];for(var h=0;h<j["$resources"].length;h++){g.entry.push(this.formatEntry(j["$resources"][h],true)["entry"])}return{feed:g}},processFeed:function(g,i){if(!g){return null}var h;if(/application\/json/i.test(i)||(!i&&this.isJsonEnabled())){h=JSON.parse(g);if(h.hasOwnProperty("$resources")){return h}else{return{"$resources":[h]}}}else{h=this.parseFeedXml(g);if(h.hasOwnProperty("feed")){return this.convertFeed(h.feed)}else{if(h.hasOwnProperty("entry")){return{"$resources":[this.convertEntry(h.entry)]}}else{return h}}}}})})();