var wijmo;define(["./wijmo.data"],function(){var e=this.__extends||function(e,t){function r(){this.constructor=e}for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);r.prototype=t.prototype,e.prototype=new r};(function(t){(function(t){function i(e,t){var n;if(Object.create)try{n=Object.create(e)}catch(r){n=null}if(!n){function i(){}i.prototype=e,n=new i}return t&&$.extend(n,t),n}function s(e){try{return JSON.parse(e)}catch(t){return e}}var n=function(n){function r(e,r){n.call(this),this.url=e,this.options=r,this.isRemote=!0,e||t.errors.noUrl(),this._construct(r)}return e(r,n),r.prototype._construct=function(e){e=$.extend(!0,{ajax:{data:{},timeout:6e4},serverSettings:{skip:"$skip",take:"$top",results:"results",totalItemCount:"totalItemCount"}},e),n.prototype._construct.call(this,e)},r.prototype._remoteRefresh=function(){var e=this,n=$.Deferred(),r=this.options,o=i(this.options.ajax),u=r.serverSettings;o.data=o.data&&i(o.data)||{},u&&!this.options.localPaging&&(u.skip&&this._shape._skip>0&&t.util.setProperty(o.data,u.skip,this._shape._skip),u.take&&this._shape._take>0&&t.util.setProperty(o.data,u.take,this._shape._take)),this.options.onRequest&&(o=this.options.onRequest(o,this._shape.toObj())||o);var a=$.ajax(this.url,$.extend({},o,{error:function(r,i,s){if(f.canceled)return;t.util.logError("Could not load "+e.url),s&&t.util.logError(s),n.rejectWith(e,arguments)},success:function(i){if(f.canceled)return;var o;t.util.isString(i)&&(i=s(i)),e.options.onResponse?o=e.options.onResponse(i):$.isArray(i)?o={results:i}:u&&(o={results:t.util.getProperty(i,u.results),totalItemCount:t.util.getProperty(i,u.totalItemCount)},t.util.isString(o.totalItemCount)&&(o.totalItemCount=parseInt(o.totalItemCount,10))),o.results||t.errors.ajax_arrayResponseExpected(i),t.util.convertDateProperties(o.results),e.sourceArray=o.results,!r.localPaging&&t.util.isNumeric(o.totalItemCount)&&e._totalItemCount(o.totalItemCount),e._localRefresh().then(n.resolve)},complete:function(){e._currentRequest=null}})),f=this._currentRequest={xhr:a,canceled:!1};return n.promise()},r.prototype.cancelRefresh=function(){this._currentRequest&&(this._currentRequest.canceled=!0,this.options.ajax.dataType!=="jsonp"&&this._currentRequest.xhr.abort(),this._currentRequest=null)},r.prototype.clone=function(){return new r(this.url,$.extend(!0,{},this.options))},r}(t.RemoteDataView);t.AjaxDataView=n;var r=function(n){function r(){n.apply(this,arguments)}return e(r,n),r.prototype._construct=function(e){e=$.extend(!0,{ajax:{jsonp:"$callback",data:{$format:"json",$inlinecount:"allpages"}},onRequest:function(e,t){return typeof t.filter=="object"&&t.filter!=null&&(e.data.$filter=r._filterExpr(t.filter)),$.isArray(t.sort)&&(e.data.$orderby=$.map(t.sort,function(e){return e.property+(e.asc?"":" desc")}).join(", ")),e},onResponse:function(n){var r;if(n.d){n=n.d;if($.isArray(n))r={results:n};else{r={results:n.results};var i=parseInt(n.__count,10);t.util.isNumeric(i)&&!e.localPaging&&(r.totalItemCount=i)}}else if(n.value){r={results:n.value};var i=parseInt(n["odata.count"],10);t.util.isNumeric(i)&&!e.localPaging&&(r.totalItemCount=i)}return r}},e),n.prototype._construct.call(this,e)},r.prototype.clone=function(){return new r(this.url,$.extend(!0,{},this.options))},r._filterExpr=function(e){if(!e)return"";var t=[];return $.each(e,function(e,n){t.push(r._conditionExpr(e,n))}),t.join(" and ")},r._conditionExpr=function(e,n){if($.isArray(n)){var i=[];return t.util.each(n,function(n,s){if(t.util.isString(s))return;i.push(r._conditionExpr(e,s))}),i.join(n[0])}var s=n.value,o="("+e+", '"+s+"')",u=n.op.name.toLowerCase(),a=!0;s instanceof Date&&(a=!1,s=this._convertDate(s));switch(u){case"contains":return"indexof"+o+" ge 0";case"notcontains":return"indexof"+o+" lt 0";case"beginswith":return"startswith"+o+" eq true";case"endswith":return"endswith"+o+" eq true";default:return u=r._filterOperators[u]||u,e+" "+u+" "+(isNaN(s)&&a?"'"+s+"'":s)}},r._convertDate=function(e,t){var n=function(e){return e<10?"0"+e:e+""};if(e){var r=t?e.getUTCFullYear()+"-"+n(e.getUTCMonth()+1)+"-"+n(e.getUTCDate())+"T"+n(e.getUTCHours())+":"+n(e.getUTCMinutes())+":"+n(e.getUTCSeconds())+"Z":e.getFullYear()+"-"+n(e.getMonth()+1)+"-"+n(e.getDate())+"T"+n(e.getHours())+":"+n(e.getMinutes())+":"+n(e.getSeconds());return"datetime'"+r+"'"}return""},r._filterOperators={"<":"lt","<=":"le",">":"gt",">=":"ge","==":"eq","!=":"ne",less:"lt",lessorequal:"le",greater:"gt",greaterorequal:"ge",equals:"eq",notequal:"ne",contains:!0,notcontains:!0,beginswith:!0,endswith:!0},r}(n);t.ODataView=r,t.errors._register({ajax_arrayResponseExpected:"Could not parse the server response. Specify onResponse option to parse the server response. \nResponse: {0}"})})(t.data||(t.data={}));var n=t.data})(wijmo||(wijmo={}))});