UNPKG

js-pkg

Version:
10 lines 65.4 kB
/*! * filename: ej.data.min.js * version : 15.3.0.33 * Copyright Syncfusion Inc. 2001 - 2017. All rights reserved. * Use of this code is subject to the terms of our license. * A copy of the current license can be obtained at any time by e-mailing * licensing@syncfusion.com. Any infringement will be prosecuted under * applicable laws. */ (function(n){typeof define=="function"&&define.amd?define(["./ej.core.min"],n):n()})(function(){window.ej=window.Syncfusion=window.Syncfusion||{},function(n,t,i,r){"use strict";var e,nt,tt,y,d,w,h,c,f;t.DataManager=function(i,u,f){if(!(this instanceof t.DataManager))return new t.DataManager(i,u,f);i||(i=[]);f=f||i.adaptor;typeof f=="string"&&(f=new t[f]);var e=[],o=this;return i instanceof Array?e={json:i,offline:!0}:typeof i=="object"?n.isPlainObject(i)?(i.json||(i.json=[]),i.table&&(i.json=this._getJsonFromElement(i.table,i.headerOption)),e={url:i.url,insertUrl:i.insertUrl,removeUrl:i.removeUrl,updateUrl:i.updateUrl,crudUrl:i.crudUrl,batchUrl:i.batchUrl,json:i.json,headers:i.headers,accept:i.accept,data:i.data,async:i.async,timeTillExpiration:i.timeTillExpiration,cachingPageSize:i.cachingPageSize,enableCaching:i.enableCaching,requestType:i.requestType,key:i.key,crossDomain:i.crossDomain,jsonp:i.jsonp,dataType:i.dataType,offline:i.offline!==r?i.offline:i.adaptor=="remoteSaveAdaptor"||i.adaptor instanceof t.remoteSaveAdaptor?!1:i.url?!1:!0,requiresFormat:i.requiresFormat}):(i.jquery||pt(i))&&(e={json:this._getJsonFromElement(i),offline:!0,table:i}):typeof i=="string"&&(e={url:i,offline:!1,dataType:"json",json:[]}),e.requiresFormat!==r||t.support.cors||(e.requiresFormat=c(e.crossDomain)?!0:e.crossDomain),e.dataType===r&&(e.dataType="json"),this.dataSource=e,this.defaultQuery=u,e.url&&e.offline&&!e.json.length?(this.isDataAvailable=!1,this.adaptor=f||new t.ODataAdaptor,this.dataSource.offline=!1,this.ready=this.executeQuery(u||t.Query()).done(function(n){o.dataSource.offline=!0;o.isDataAvailable=!0;e.json=n.result;o.adaptor=new t.JsonAdaptor})):this.adaptor=e.offline?new t.JsonAdaptor:new t.ODataAdaptor,!e.jsonp&&this.adaptor instanceof t.ODataAdaptor&&(e.jsonp="callback"),this.adaptor=f||this.adaptor,e.enableCaching&&(this.adaptor=new t.CacheAdaptor(this.adaptor,e.timeTillExpiration,e.cachingPageSize)),this};t.DataManager.prototype={setDefaultQuery:function(n){this.defaultQuery=n},executeQuery:function(i,u,e,o){var s,h,c;return typeof i=="function"&&(o=e,e=u,u=i,i=null),i||(i=this.defaultQuery),i instanceof t.Query||f("DataManager - executeQuery() : A query is required to execute"),s=n.Deferred(),s.then(u,e,o),h={query:i},this.dataSource.offline||this.dataSource.url==r?t.isNullOrUndefined(this.dataSource.async)||this.dataSource.async!=!1?d(function(){this._localQueryProcess(i,h,s)},this):this._localQueryProcess(i,h,s):(c=this.adaptor.processQuery(this,i),t.isNullOrUndefined(c.url)?d(function(){h=this._getDeferedArgs(i,c,h);s.resolveWith(this,[h])},this):this._makeRequest(c,s,h,i)),s.promise()},_localQueryProcess:function(n,t,i){var r=this.executeLocal(n);t=this._getDeferedArgs(n,r,t);i.resolveWith(this,[t])},_getDeferedArgs:function(n,t,i){return n._requiresCount?(i.result=t.result,i.count=t.count):i.result=t,i.getTableModel=rt(n._fromTable,i.result,this),i.getKnockoutModel=ut(i.result),i},executeLocal:function(i){var e,r;if(this.defaultQuery||i instanceof t.Query||f("DataManager - executeLocal() : A query is required to execute"),this.dataSource.json||f("DataManager - executeLocal() : Json data is required to execute"),i=i||this.defaultQuery,e=this.adaptor.processQuery(this,i),i._subQuery){var o=i._subQuery._fromTable,s=i._subQuery._lookup,u=i._requiresCount?e.result:e;for(s&&s instanceof Array&&k(i._subQuery._fKey,o,u,s,i._subQuery._key),r=0;r<u.length;r++)u[r][o]instanceof Array&&(u[r]=n.extend({},u[r]),u[r][o]=this.adaptor.processResponse(i._subQuery.using(t.DataManager(u[r][o].slice(0))).executeLocal(),this,i))}return this.adaptor.processResponse(e,this,i)},_makeRequest:function(i,r,u,f){var o=!!f._subQuerySelector,c=h(function(n){u.error=n;r.rejectWith(this,[u])},this),l=h(function(n,t,i,e,s,h,c){o||(u.xhr=i,u.count=parseInt(t,10),u.result=n,u.request=e,u.aggregates=h,u.getTableModel=rt(f._fromTable,n,this),u.getKnockoutModel=ut(n),u.actual=s,u.virtualSelectRecords=c,r.resolveWith(this,[u]))},this),a=h(function(t,i){var r=n.Deferred(),h={parent:u},e,s;return f._subQuery._isChild=!0,e=this.adaptor.processQuery(this,f._subQuery,t?this.adaptor.processResponse(t):i),s=this._makeRequest(e,r,h,f._subQuery),o||r.then(function(n){t&&(k(f._subQuery._fKey,f._subQuery._fromTable,t,n,f._subQuery._key),l(t))},c),s},this),v=w(function(n,i,r,u){r.getResponseHeader("Content-Type").indexOf("xml")==-1&&t.dateParse&&(n=t.parseJSON(n));var e=this.adaptor.processResponse(n,this,f,r,u),s=0,h=null,c=n.virtualSelectRecords;if(f._requiresCount&&(s=e.count,h=e.aggregates,e=e.result),!f._subQuery){l(e,s,r,u,n,h,c);return}o||a(e)},this),e=n.extend({type:"GET",dataType:this.dataSource.dataType,crossDomain:this.dataSource.crossDomain,jsonp:this.dataSource.jsonp,cache:!0,beforeSend:h(this._beforeSend,this),processData:!1,success:v,error:c},i),s;return"async"in this.dataSource&&(e.async=this.dataSource.async),e=n.ajax(e),o&&(s=f._subQuerySelector.call(this,{query:f._subQuery,parent:f}),s&&s.length?(e=n.when(e,a(null,s)),e.then(w(function(n,t,i){var r=this.adaptor.processResponse(n[0],this,f,n[2],i[0]),e=0,u;f._requiresCount&&(e=r.count,r=r.result);u=this.adaptor.processResponse(t[0],this,f._subQuery,t[2],i[1]);e=0;f._subQuery._requiresCount&&(e=u.count,u=u.result);k(f._subQuery._fKey,f._subQuery._fromTable,r,u,f._subQuery._key);o=!1;l(r,e,n[2])},this),c)):o=!1),e},_beforeSend:function(n,t){var i,f,r,u;for(this.adaptor.beforeSend(this,n,t),i=this.dataSource.headers,r=0;i&&r<i.length;r++){f=[];for(u in i[r])f.push(u),n.setRequestHeader(u,i[r][u])}},saveChanges:function(i,r,u,f){var s,o,e;return(u instanceof t.Query&&(f=u,u=null),s={url:u,key:r||this.dataSource.key},o=this.adaptor.batchRequest(this,i,s,f),this.dataSource.offline)?o:(e=n.Deferred(),n.ajax(n.extend({beforeSend:h(this._beforeSend,this),success:w(function(n,t,u,f){e.resolveWith(this,[this.adaptor.processResponse(n,this,null,u,f,i,r)])},this),error:function(n){e.rejectWith(this,[{error:n}])}},o)),e.promise())},insert:function(i,r,f){var o,e;return(i=u.replacer(i),r instanceof t.Query&&(f=r,r=null),o=this.adaptor.insert(this,i,r,f),this.dataSource.offline)?o:(e=n.Deferred(),n.ajax(n.extend({type:"POST",contentType:"application/json; charset=utf-8",processData:!1,beforeSend:h(this._beforeSend,this),success:w(function(n,i,r,f){try{t.isNullOrUndefined(n)?n=[]:u.parseJson(n)}catch(o){n=[]}n=this.adaptor.processResponse(u.parseJson(n),this,null,r,f);e.resolveWith(this,[{record:n,dataManager:this}])},this),error:function(n){e.rejectWith(this,[{error:n,dataManager:this}])}},o)),e.promise())},remove:function(i,r,f,e){var s,o;return(typeof r=="object"&&(r=r[i]),f instanceof t.Query&&(e=f,f=null),s=this.adaptor.remove(this,i,r,f,e),this.dataSource.offline)?s:(o=n.Deferred(),n.ajax(n.extend({type:"POST",contentType:"application/json; charset=utf-8",beforeSend:h(this._beforeSend,this),success:w(function(n,i,r,f){try{t.isNullOrUndefined(n)?n=[]:u.parseJson(n)}catch(e){n=[]}n=this.adaptor.processResponse(u.parseJson(n),this,null,r,f);o.resolveWith(this,[{record:n,dataManager:this}])},this),error:function(n){o.rejectWith(this,[{error:n,dataManager:this}])}},s)),o.promise())},update:function(i,r,f,e){var s,o;return(r=u.replacer(r),f instanceof t.Query&&(e=f,f=null),s=this.adaptor.update(this,i,r,f,e),this.dataSource.offline)?s:(o=n.Deferred(),n.ajax(n.extend({contentType:"application/json; charset=utf-8",beforeSend:h(this._beforeSend,this),success:w(function(n,i,r,f){try{t.isNullOrUndefined(n)?n=[]:u.parseJson(n)}catch(e){n=[]}n=this.adaptor.processResponse(u.parseJson(n),this,null,r,f);o.resolveWith(this,[{record:n,dataManager:this}])},this),error:function(n){o.rejectWith(this,[{error:n,dataManager:this}])}},s)),o.promise())},_getJsonFromElement:function(i){typeof i=="string"&&(i=n(n(i).html()));i=i.jquery?i[0]:i;var r=i.tagName.toLowerCase();return r!=="table"&&f("ej.DataManager : Unsupported htmlElement : "+r),t.parseTable(i)}};var k=function(n,i,r,u,e){var o,s={},c,h;for(u.result&&(u=u.result),u.GROUPGUID&&f("ej.DataManager: Do not have support Grouping in hierarchy"),o=0;o<u.length;o++)h=t.getObject(n,u[o]),c=s[h]||(s[h]=[]),c.push(u[o]);for(o=0;o<r.length;o++)r[o][i]=s[t.getObject(e||n,r[o])]},l={accept:"application/json;odata=light;q=1,application/json;odata=verbose;q=0.5",multipartAccept:"multipart/mixed",batch:"$batch",changeSet:"--changeset_",batchPre:"batch_",contentId:"Content-Id: ",batchContent:"Content-Type: multipart/mixed; boundary=",changeSetContent:"Content-Type: application/http\nContent-Transfer-Encoding: binary ",batchChangeSetContentType:"Content-Type: application/json; charset=utf-8 "},u={parseJson:function(n){var t=typeof n;return t==="string"?n=JSON.parse(n,u.jsonReviver):n instanceof Array?u.iterateAndReviveArray(n):t==="object"&&u.iterateAndReviveJson(n),n},iterateAndReviveArray:function(n){for(var t=0;t<n.length;t++)typeof n[t]=="object"?u.iterateAndReviveJson(n[t]):n[t]=typeof n[t]!="string"||/^[\s]*\[|^[\s]*\{|\"/g.test(n[t])?u.parseJson(n[t]):u.jsonReviver("",n[t])},iterateAndReviveJson:function(n){var t;for(var i in n)i.startsWith("__")||(t=n[i],typeof t=="object"?t instanceof Array?u.iterateAndReviveArray(t):u.iterateAndReviveJson(t):n[i]=u.jsonReviver(i,t))},jsonReviver:function(n,t){var f=t,r,i;if(typeof t=="string"){if(r=/^\/Date\(([+-]?[0-9]+)([+-][0-9]{4})?\)\/$/.exec(t),r)return u.replacer(new Date(parseInt(r[1])));/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*){1})([zZ]|([+\-])(\d\d):?(\d\d))?$/.test(t)&&(t=u.replacer(new Date(t)),isNaN(t)&&(i=f.split(/[^0-9]/),t=u.replacer(new Date(i[0],i[1]-1,i[2],i[3],i[4],i[5]))))}return t},isJson:function(n){return typeof n[0]=="string"?n:t.parseJSON(n)},isGuid:function(n){var t=/[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/i.exec(n);return t!=null},replacer:function(n){return t.isPlainObject(n)?u.jsonReplacer(n):n instanceof Array?u.arrayReplacer(n):n instanceof Date?u.jsonReplacer({val:n}).val:n},jsonReplacer:function(n){var i;for(var r in n)(i=n[r],i instanceof Date)&&(n[r]=new Date(+i+t.serverTimezoneOffset*36e5));return n},arrayReplacer:function(n){for(var i=0;i<n.length;i++)t.isPlainObject(n[i])?n[i]=u.jsonReplacer(n[i]):n[i]instanceof Date&&(n[i]=u.jsonReplacer({date:n[i]}).date);return n}};t.isJSON=u.isJson;t.parseJSON=u.parseJson;t.dateParse=!0;t.isGUID=u.isGuid;t.Query=function(n){return(this instanceof t.Query)?(this.queries=[],this._key="",this._fKey="",typeof n=="string"?this._fromTable=n||"":n&&n instanceof Array&&(this._lookup=n),this._expands=[],this._sortedColumns=[],this._groupedColumns=[],this._subQuery=null,this._isChild=!1,this._params=[],this):new t.Query(n)};t.Query.prototype={key:function(n){return typeof n=="string"&&(this._key=n),this},using:function(n){return n instanceof t.DataManager?(this.dataManagar=n,this):f("Query - using() : 'using' function should be called with parameter of instance ej.DataManager")},execute:function(n,i,r,u){return(n=n||this.dataManagar,n&&n instanceof t.DataManager)?n.executeQuery(this,i,r,u):f("Query - execute() : dataManager needs to be is set using 'using' function or should be passed as argument")},executeLocal:function(n){return(n=n||this.dataManagar,n&&n instanceof t.DataManager)?n.executeLocal(this):f("Query - executeLocal() : dataManager needs to be is set using 'using' function or should be passed as argument")},clone:function(){var n=new t.Query;return n.queries=this.queries.slice(0),n._key=this._key,n._isChild=this._isChild,n.dataManagar=this.dataManager,n._fromTable=this._fromTable,n._params=this._params.slice(0),n._expands=this._expands.slice(0),n._sortedColumns=this._sortedColumns.slice(0),n._groupedColumns=this._groupedColumns.slice(0),n._subQuerySelector=this._subQuerySelector,n._subQuery=this._subQuery,n._fKey=this._fKey,n._requiresCount=this._requiresCount,n},from:function(n){return typeof n=="string"&&(this._fromTable=n),this},addParams:function(n,i){return typeof i=="function"||t.isPlainObject(i)?typeof i=="function"&&this._params.push({key:n,fn:i}):this._params.push({key:n,value:i}),this},expand:function(n){return this._expands=typeof n=="string"?[].slice.call(arguments,0):n.slice(0),this},where:function(n,i,r,u){i=(i||t.FilterOperators.equal).toLowerCase();var e=null;return typeof n=="string"?e=new t.Predicate(n,i,r,u):n instanceof t.Predicate?e=n:f("Query - where : Invalid arguments"),this.queries.push({fn:"onWhere",e:e}),this},search:function(n,i,r,u){i&&typeof i!="boolean"?typeof i=="string"&&(i=[i]):(i=[],u=i);typeof r=="boolean"&&(u=r,r=null);r=r||t.FilterOperators.contains;r.length<3&&(r=t.data.operatorSymbols[r]);var f=t.data.fnOperators[r]||t.data.fnOperators.processSymbols(r);return this.queries.push({fn:"onSearch",e:{fieldNames:i,operator:r,searchKey:n,ignoreCase:u,comparer:f}}),this},sortBy:function(n,i,r){var o=t.sortOrder.Ascending,s,f,u,e;if(typeof n=="string"&&n.toLowerCase().endsWith(" desc")&&(n=n.replace(/ desc$/i,""),i=t.sortOrder.Descending),n instanceof Array){for(u=0;u<n.length;u++)this.sortBy(n[u],i,r);return this}if(typeof i=="boolean"?i=i?t.sortOrder.Descending:t.sortOrder.Ascending:typeof i=="function"&&(o="custom"),i&&typeof i!="string"||(o=i?i.toLowerCase():t.sortOrder.Ascending,i=t.pvt.fnSort(i)),r)for(s=a(this.queries,"onSortBy"),u=0;u<s.length;u++)if(f=s[u].e.fieldName,typeof f=="string"){if(f===n)return this}else if(f instanceof Array)for(e=0;e<f.length;e++)if(f[e]===n||n.toLowerCase()===f[e]+" desc")return this;return this.queries.push({fn:"onSortBy",e:{fieldName:n,comparer:i,direction:o}}),this},sortByDesc:function(n){return this.sortBy(n,t.sortOrder.Descending)},group:function(n,t){return this.sortBy(n,null,!0),this.queries.push({fn:"onGroup",e:{fieldName:n,fn:t}}),this},page:function(n,t){return this.queries.push({fn:"onPage",e:{pageIndex:n,pageSize:t}}),this},range:function(n,t){return(typeof n!="number"||typeof t!="number")&&f("Query() - range : Arguments type should be a number"),this.queries.push({fn:"onRange",e:{start:n,end:t}}),this},take:function(n){return typeof n!="number"&&f("Query() - Take : Argument type should be a number"),this.queries.push({fn:"onTake",e:{nos:n}}),this},skip:function(n){return typeof n!="number"&&f("Query() - Skip : Argument type should be a number"),this.queries.push({fn:"onSkip",e:{nos:n}}),this},select:function(n){return typeof n=="string"&&(n=[].slice.call(arguments,0)),n instanceof Array||f("Query() - Select : Argument type should be String or Array"),this.queries.push({fn:"onSelect",e:{fieldNames:n}}),this},hierarchy:function(n,i){return n&&n instanceof t.Query||f("Query() - hierarchy : query must be instance of ej.Query"),typeof i=="function"&&(this._subQuerySelector=i),this._subQuery=n,this},foreignKey:function(n){return typeof n=="string"&&(this._fKey=n),this},requiresCount:function(){return this._requiresCount=!0,this},aggregate:function(n,t){this.queries.push({fn:"onAggregates",e:{field:t,type:n}})}};t.Adaptor=function(n){this.dataSource=n;this.pvt={};this.init.apply(this,[].slice.call(arguments,1))};t.Adaptor.prototype={options:{from:"table",requestType:"json",sortBy:"sorted",select:"select",skip:"skip",group:"group",take:"take",search:"search",count:"requiresCounts",where:"where",aggregates:"aggregates"},init:function(){},extend:function(t){var i=function(t){this.dataSource=t;this.options&&(this.options=n.extend({},this.options));this.init.apply(this,[].slice.call(arguments,0));this.pvt={}},u,r;i.prototype=new this.type;i.prototype.type=i;u=i.prototype.base={};for(r in t)i.prototype[r]&&(u[r]=i.prototype[r]);return n.extend(!0,i.prototype,t),i},processQuery:function(){},processResponse:function(n){return n.d?n.d:n},convertToQueryString:function(t){return n.param(t)},type:t.Adaptor};t.UrlAdaptor=(new t.Adaptor).extend({processQuery:function(n,t,i){var w=a(t.queries,"onSortBy"),d=a(t.queries,"onGroup"),nt=a(t.queries,"onWhere"),tt=a(t.queries,"onSearch"),it=a(t.queries,"onAggregates"),l=g(t.queries,["onSelect","onPage","onSkip","onTake","onRange"]),rt=t._params,b=n.dataSource.url,r,y,p=null,h=this.options,s={sorted:[],grouped:[],filters:[],searches:[],aggregates:[]},f,u,v,k;for(l.onPage?(r=l.onPage,y=e(r.pageIndex,t),p=e(r.pageSize,t),y=(y-1)*p):l.onRange&&(r=l.onRange,y=r.start,p=r.end-r.start),f=0;f<w.length;f++)r=e(w[f].e.fieldName,t),s.sorted.push(o(this,"onEachSort",{name:r,direction:w[f].e.direction},t));for(i&&(r=this.getFiltersFrom(i,t),r&&s.filters.push(o(this,"onEachWhere",r.toJSON(),t))),f=0;f<nt.length;f++){s.filters.push(o(this,"onEachWhere",nt[f].e.toJSON(),t));for(v in s.filters[f])c(s[v])&&delete s[v]}for(f=0;f<tt.length;f++)r=tt[f].e,s.searches.push(o(this,"onEachSearch",{fields:r.fieldNames,operator:r.operator,key:r.searchKey,ignoreCase:r.ignoreCase},t));for(f=0;f<d.length;f++)s.grouped.push(e(d[f].e.fieldName,t));for(f=0;f<it.length;f++)r=it[f].e,s.aggregates.push({type:r.type,field:e(r.field,t)});u={};u[h.from]=t._fromTable;h.expand&&(u[h.expand]=t._expands);u[h.select]=l.onSelect?o(this,"onSelect",e(l.onSelect.fieldNames,t),t):"";u[h.count]=t._requiresCount?o(this,"onCount",t._requiresCount,t):"";u[h.search]=s.searches.length?o(this,"onSearch",s.searches,t):"";u[h.skip]=l.onSkip?o(this,"onSkip",e(l.onSkip.nos,t),t):"";u[h.take]=l.onTake?o(this,"onTake",e(l.onTake.nos,t),t):"";u[h.where]=s.filters.length||s.searches.length?o(this,"onWhere",s.filters,t):"";u[h.sortBy]=s.sorted.length?o(this,"onSortBy",s.sorted,t):"";u[h.group]=s.grouped.length?o(this,"onGroup",s.grouped,t):"";u[h.aggregates]=s.aggregates.length?o(this,"onAggregates",s.aggregates,t):"";u.param=[];o(this,"addParams",{dm:n,query:t,params:rt,reqParams:u});for(v in u)(c(u[v])||u[v]===""||u[v].length===0||v==="params")&&delete u[v];return(h.skip in u&&h.take in u||p===null||(u[h.skip]=o(this,"onSkip",y,t),u[h.take]=o(this,"onTake",p,t)),k=this.pvt,this.pvt={},this.options.requestType==="json")?{data:JSON.stringify(u),url:b,ejPvtData:k,type:"POST",contentType:"application/json; charset=utf-8"}:(r=this.convertToQueryString(u,t,n),r=(n.dataSource.url.indexOf("?")!==-1?"&":"/")+r,{type:"GET",url:r.length?b.replace(/\/*$/,r):b,ejPvtData:k})},convertToQueryString:function(t,i,r){return r.dataSource.url&&r.dataSource.url.indexOf("?")!==-1?n.param(t):"?"+n.param(t)},processResponse:function(n,i,u,f,e,o){var c=e.ejPvtData||{},v=n.groupDs,y,a,h,s,d,w;if(f&&f.getResponseHeader("Content-Type")&&f.getResponseHeader("Content-Type").indexOf("xml")!=-1&&n.nodeType==9)return u._requiresCount?{result:[],count:0}:[];if(y=JSON.parse(e.data),y&&y.action==="batch"&&n.added)return o.added=n.added,o;if(n.d&&(n=n.d),c&&c.aggregates&&c.aggregates.length){var l=c.aggregates,h={},p,k={};for(("count"in n)&&(h.count=n.count),n.result&&(h.result=n.result),n.aggregate&&(n=n.aggregate),s=0;s<l.length;s++)p=t.aggregates[l[s].type],p&&(k[l[s].field+" - "+l[s].type]=p(n,l[s].field));h.aggregates=k;n=h}if(c&&c.groups&&c.groups.length){for(a=c.groups,h={},("count"in n)&&(h.count=n.count),n.aggregates&&(h.aggregates=n.aggregates),n.result&&(n=n.result),s=0;s<a.length;s++)d=null,w=b(a[s],u.queries),t.isNullOrUndefined(v)||(v=t.group(v,a[s],null,w)),n=t.group(n,a[s],c.aggregates,w,d,v);return h.count!=r?h.result=n:h=n,h}return n},onGroup:function(n){this.pvt.groups=n},onAggregates:function(n){this.pvt.aggregates=n},batchRequest:function(n,t,i,r){var u={changed:t.changed,added:t.added,deleted:t.deleted,action:"batch",table:i.url,key:i.key};return r&&this.addParams({dm:n,query:r,params:r._params,reqParams:u}),{type:"POST",url:n.dataSource.batchUrl||n.dataSource.crudUrl||n.dataSource.removeUrl||n.dataSource.url,contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(u)}},beforeSend:function(){},insert:function(n,t,i,r){var u={value:t,table:i,action:"insert"};return r&&this.addParams({dm:n,query:r,params:r._params,reqParams:u}),{url:n.dataSource.insertUrl||n.dataSource.crudUrl||n.dataSource.url,data:JSON.stringify(u)}},remove:function(n,t,i,r,u){var f={key:i,keyColumn:t,table:r,action:"remove"};return u&&this.addParams({dm:n,query:u,params:u._params,reqParams:f}),{type:"POST",url:n.dataSource.removeUrl||n.dataSource.crudUrl||n.dataSource.url,data:JSON.stringify(f)}},update:function(n,t,i,r,u){var f={value:i,action:"update",keyColumn:t,key:i[t],table:r};return u&&this.addParams({dm:n,query:u,params:u._params,reqParams:f}),{type:"POST",url:n.dataSource.updateUrl||n.dataSource.crudUrl||n.dataSource.url,data:JSON.stringify(f)}},getFiltersFrom:function(n,i){var r;n instanceof Array&&n.length||f("ej.SubQuery: Array of key values required");var u=i._fKey,e,o=u,h=i._key,s=[],c=typeof n[0]!="object";for(typeof n[0]!="object"&&(o=null),r=0;r<n.length;r++)e=c?n[r]:t.pvt.getObject(h||o,n[r]),s.push(new t.Predicate(u,"==",e));return t.Predicate.or(s)},addParams:function(n){var e=n.dm,u=n.query,o=n.params,i=n.reqParams,r,t;for(i.params={},r=0;t=o[r];r++)i[t.key]&&f("ej.Query: Custom Param is conflicting other request arguments"),i[t.key]=t.value,t.fn&&(i[t.key]=t.fn.call(u,t.key,u,e)),i.params[t.key]=i[t.key]}});t.WebMethodAdaptor=(new t.UrlAdaptor).extend({processQuery:function(n,i,r){var u=t.UrlAdaptor.prototype.processQuery(n,i,r),e=t.parseJSON(u.data),f={};return f.value=e,o(this,"addParams",{dm:n,query:i,params:i._params,reqParams:f}),{data:JSON.stringify(f),url:u.url,ejPvtData:u.ejPvtData,type:"POST",contentType:"application/json; charset=utf-8"}},addParams:function(n){var s=n.dm,o=n.query,h=n.params,i=n.reqParams,u,t,r,e;for(i.params={},u=0;t=h[u];u++)i[t.key]&&f("ej.Query: Custom Param is conflicting other request arguments"),r=t.key,e=t.value,t.fn&&(e=t.fn.call(o,t.key,o,s)),i[r]=e,i.params[r]=i[r]}});t.CacheAdaptor=(new t.UrlAdaptor).extend({init:function(n,i,r){var f,u;t.isNullOrUndefined(n)||(this.cacheAdaptor=n);this.pageSize=r;this.guidId=t.getGuid("cacheAdaptor");f={keys:[],results:[]};window.localStorage&&window.localStorage.setItem(this.guidId,JSON.stringify(f));u=this.guidId;t.isNullOrUndefined(i)||setInterval(function(){for(var e,r=t.parseJSON(window.localStorage.getItem(u)),f=[],n=0;n<r.results.length;n++)r.results[n].timeStamp=new Date-new Date(r.results[n].timeStamp),new Date-new Date(r.results[n].timeStamp)>i&&f.push(n);for(e=f,n=0;n<f.length;n++)r.results.splice(f[n],1),r.keys.splice(f[n],1);window.localStorage.removeItem(u);window.localStorage.setItem(u,JSON.stringify(r))},i)},generateKey:function(n,t){var h=a(t.queries,"onSortBy"),c=a(t.queries,"onGroup"),o=a(t.queries,"onWhere"),l=a(t.queries,"onSearch"),v=a(t.queries,"onPage"),s=g(t.queries,["onSelect","onPage","onSkip","onTake","onRange"]),y=t._params,r=n,u,i,f,e;for(s.onPage&&(r+=s.onPage.pageIndex),h.forEach(function(n){r+=n.e.direction+n.e.fieldName}),c.forEach(function(n){r+=n.e.fieldName}),l.forEach(function(n){r+=n.e.searchKey}),u=0;u<o.length;u++)if(i=o[u],i.e.isComplex){for(f=t.clone(),f.queries=[],e=0;e<i.e.predicates.length;e++)f.queries.push({fn:"onWhere",e:i.e.predicates[e],filter:t.queries.filter});r+=i.e.condition+this.generateKey(n,f)}else r+=i.e.field+i.e.operator+i.e.value;return r},processQuery:function(n,i){var f=this.generateKey(n.dataSource.url,i),r,u;return(window.localStorage&&(r=t.parseJSON(window.localStorage.getItem(this.guidId))),u=r?r.results[r.keys.indexOf(f)]:null,u!=null&&!this._crudAction&&!this._insertAction)?u:(this._crudAction=null,this._insertAction=null,this.cacheAdaptor.processQuery.apply(this.cacheAdaptor,[].slice.call(arguments,0)))},processResponse:function(i,r,u,f,e,o){var h;if(this._insertAction||e&&this.cacheAdaptor.options.batch&&e.url.endsWith(this.cacheAdaptor.options.batch)&&e.type.toLowerCase()==="post")return this.cacheAdaptor.processResponse(i,r,u,f,e,o);var i=this.cacheAdaptor.processResponse.apply(this,[].slice.call(arguments,0)),c=this.generateKey(r.dataSource.url,u),s={};for(window.localStorage&&(s=t.parseJSON(window.localStorage.getItem(this.guidId))),h=n.inArray(c,s.keys),h!=-1&&(s.results.splice(h,1),s.keys.splice(h,1)),s.results[s.keys.push(c)-1]={keys:c,result:i.result,timeStamp:new Date,count:i.count};s.results.length>this.pageSize;)s.results.splice(0,1),s.keys.splice(0,1);return window.localStorage.setItem(this.guidId,JSON.stringify(s)),i},update:function(n,t,i,r){return this._crudAction=!0,this.cacheAdaptor.update(n,t,i,r)},insert:function(n,t,i){return this._insertAction=!0,this.cacheAdaptor.insert(n,t,i)},remove:function(n,t,i,r){return this._crudAction=!0,this.cacheAdaptor.remove(n,t,i,r)},batchRequest:function(n,t,i){return this.cacheAdaptor.batchRequest(n,t,i)}});var a=function(n,t){return n.filter(function(n){return n.fn===t})||[]},g=function(n,t){for(var r=n.filter(function(n){return t.indexOf(n.fn)!==-1}),u={},i=0;i<r.length;i++)u[r[i].fn]||(u[r[i].fn]=r[i].e);return u},o=function(n,t,i,r){if(n[t]){var u=n[t](i,r);c(u)||(i=u)}return i};t.ODataAdaptor=(new t.UrlAdaptor).extend({options:{requestType:"get",accept:"application/json;odata=light;q=1,application/json;odata=verbose;q=0.5",multipartAccept:"multipart/mixed",sortBy:"$orderby",select:"$select",skip:"$skip",take:"$top",count:"$inlinecount",where:"$filter",expand:"$expand",batch:"$batch",changeSet:"--changeset_",batchPre:"batch_",contentId:"Content-Id: ",batchContent:"Content-Type: multipart/mixed; boundary=",changeSetContent:"Content-Type: application/http\nContent-Transfer-Encoding: binary ",batchChangeSetContentType:"Content-Type: application/json; charset=utf-8 "},onEachWhere:function(n,t){return n.isComplex?this.onComplexPredicate(n,t):this.onPredicate(n,t)},onPredicate:function(n,i,r){var o="",s,h,f=n.value,c=typeof f,e=this._p(n.field),l;return(f instanceof Date&&(f="datetime'"+u.replacer(f).toJSON()+"'"),c==="string"&&(f.indexOf("'")!=-1&&(f=f.replace(new RegExp(/'/g),"''")),f="'"+f+"'",r&&(e="cast("+e+", 'Edm.String')"),t.isGUID(f)&&(h="guid"),n.ignoreCase&&(h?e:e="tolower("+e+")",f=f.toLowerCase())),s=t.data.odBiOperator[n.operator],s)?(o+=e,o+=s,h&&(o+=h),o+f):(s=t.data.odUniOperator[n.operator],!s||c!=="string")?"":(s==="substringof"&&(l=f,f=e,e=l),o+=s+"(",o+=e+",",h&&(o+=h),o+(f+")"))},onComplexPredicate:function(n,t){for(var r=[],i=0;i<n.predicates.length;i++)r.push("("+this.onEachWhere(n.predicates[i],t)+")");return r.join(" "+n.condition+" ")},onWhere:function(n){return this.pvt.searches&&n.push(this.onEachWhere(this.pvt.searches,null,!0)),n.join(" and ")},onEachSearch:function(n){var r,i;for(n.fields.length===0&&f("Query() - Search : oData search requires list of field names to search"),r=this.pvt.searches||[],i=0;i<n.fields.length;i++)r.push(new t.Predicate(n.fields[i],n.operator,n.key,n.ignoreCase));this.pvt.searches=r},onSearch:function(){return this.pvt.searches=t.Predicate.or(this.pvt.searches),""},onEachSort:function(n){var i=[],t;if(n.name instanceof Array)for(t=0;t<n.name.length;t++)i.push(this._p(n.name[t]));else i.push(this._p(n.name)+(n.direction==="descending"?" desc":""));return i.join(",")},onSortBy:function(n){return n.reverse().join(",")},onGroup:function(n){return this.pvt.groups=n,""},onSelect:function(n){for(var t=0;t<n.length;t++)n[t]=this._p(n[t]);return n.join(",")},onAggregates:function(n){return this.pvt.aggregates=n,""},onCount:function(n){return n===!0?"allpages":""},beforeSend:function(n,t,i){i.url.endsWith(this.options.batch)&&i.type.toLowerCase()==="post"&&(t.setRequestHeader("Accept",l.multipartAccept),t.setRequestHeader("DataServiceVersion","2.0"),t.overrideMimeType("text/plain; charset=x-user-defined"));n.dataSource.crossDomain||(t.setRequestHeader("DataServiceVersion","2.0"),t.setRequestHeader("MaxDataServiceVersion","2.0"))},processResponse:function(i,r,f,e,o,s){var a,l,v,d,tt,g,it,k,h,ft;if(!t.isNullOrUndefined(i.d)&&(a=f&&f._requiresCount?i.d.results:i.d,!t.isNullOrUndefined(a)))for(h=0;h<a.length;h++)t.isNullOrUndefined(a[h].__metadata)||delete a[h].__metadata;if(l=o&&o.ejPvtData,e&&e.getResponseHeader("Content-Type")&&e.getResponseHeader("Content-Type").indexOf("xml")!=-1&&i.nodeType==9)return f._requiresCount?{result:[],count:0}:[];if(o&&this.options.batch&&o.url.endsWith(this.options.batch)&&o.type.toLowerCase()==="post"){if(v=e.getResponseHeader("Content-Type"),v=v.substring(v.indexOf("=batchresponse")+1),i=i.split(v),i.length<2)return;for(i=i[1],g=/(?:\bContent-Type.+boundary=)(changesetresponse.+)/i.exec(i),i.replace(g[0],""),it=g[1],i=i.split(it),h=i.length;h>-1;h--)/\bContent-ID:/i.test(i[h])&&/\bHTTP.+201/.test(i[h])&&(d=parseInt(/\bContent-ID: (\d+)/i.exec(i[h])[1]),s.added[d]&&(tt=u.parseJson(/^\{.+\}/m.exec(i[h])[0]),n.extend(s.added[d],this.processResponse(tt))));return s}var y=e&&e.getResponseHeader("DataServiceVersion"),w=null,rt={};if(y=y&&parseInt(y,10)||2,f&&f._requiresCount&&((i.__count||i["odata.count"])&&(w=i.__count||i["odata.count"]),i.d&&(i=i.d),(i.__count||i["odata.count"])&&(w=i.__count||i["odata.count"])),y===3&&i.value&&(i=i.value),i.d&&(i=i.d),y<3&&i.results&&(i=i.results),l&&l.aggregates&&l.aggregates.length){var p=l.aggregates,nt,ut={};for(h=0;h<p.length;h++)nt=t.aggregates[p[h].type],nt&&(ut[p[h].field+" - "+p[h].type]=nt(i,p[h].field));rt=ut}if(l&&l.groups&&l.groups.length)for(k=l.groups,h=0;h<k.length;h++)ft=b(k[h],f.queries),i=t.group(i,k[h],l.aggregates,ft);return c(w)?i:{result:i,count:w,aggregates:rt}},convertToQueryString:function(n,t,i){var r=[],u=n.table||"",f;delete n.table;i.dataSource.requiresFormat&&(n.$format="json");for(f in n)r.push(f+"="+n[f]);return(r=r.join("&"),i.dataSource.url&&i.dataSource.url.indexOf("?")!==-1&&!u)?r:r.length?u+"?"+r:u||""},insert:function(n,t,i){return{url:n.dataSource.url.replace(/\/*$/,i?"/"+i:""),data:JSON.stringify(t)}},remove:function(n,t,i,r){return{type:"DELETE",url:n.dataSource.url.replace(/\/*$/,r?"/"+r:"")+"("+i+")"}},update:function(n,t,i,r){return{type:"PUT",url:n.dataSource.url.replace(/\/*$/,r?"/"+r:"")+"("+i[t]+")",data:JSON.stringify(i),accept:this.options.accept}},batchRequest:function(n,i,r){var e=r.guid=t.getGuid(l.batchPre),o=n.dataSource.url.replace(/\/*$/,"/"+this.options.batch),f={url:r.url,key:r.key,cid:1,cSet:t.getGuid(l.changeSet)},u="--"+e+"\n";return u+="Content-Type: multipart/mixed; boundary="+f.cSet.replace("--","")+"\n",this.pvt.changeSet=0,u+=this.generateInsertRequest(i.added,f),u+=this.generateUpdateRequest(i.changed,f),u+=this.generateDeleteRequest(i.deleted,f),u+=f.cSet+"--\n",u+="--"+e+"--",{type:"POST",url:o,contentType:"multipart/mixed; charset=UTF-8;boundary="+e,data:u}},generateDeleteRequest:function(n,t){var i,r;if(!n)return"";for(i="",r=0;r<n.length;r++)i+="\n"+t.cSet+"\n",i+=l.changeSetContent+"\n\n",i+="DELETE ",i+=t.url+"("+n[r][t.key]+") HTTP/1.1\n",i+="If-Match : * \n",i+="Accept: "+l.accept+"\n",i+="Content-Id: "+this.pvt.changeSet+++"\n",i+=l.batchChangeSetContentType+"\n";return i+"\n"},generateInsertRequest:function(n,t){var i,r;if(!n)return"";for(i="",r=0;r<n.length;r++)i+="\n"+t.cSet+"\n",i+=l.changeSetContent+"\n\n",i+="POST ",i+=t.url+" HTTP/1.1\n",i+="Accept: "+l.accept+"\n",i+="Content-Id: "+this.pvt.changeSet+++"\n",i+=l.batchChangeSetContentType+"\n\n",i+=JSON.stringify(n[r])+"\n";return i},generateUpdateRequest:function(n,t){var i,r;if(!n)return"";for(i="",r=0;r<n.length;r++)i+="\n"+t.cSet+"\n",i+=l.changeSetContent+"\n\n",i+="PUT ",i+=t.url+"("+n[r][t.key]+") HTTP/1.1\n",i+="If-Match : * \n",i+="Accept: "+l.accept+"\n",i+="Content-Id: "+this.pvt.changeSet+++"\n",i+=l.batchChangeSetContentType+"\n\n",i+=JSON.stringify(n[r])+"\n\n";return i},_p:function(n){return n.replace(/\./g,"/")}});t.ODataV4Adaptor=(new t.ODataAdaptor).extend({options:{requestType:"get",accept:"application/json;odata=light;q=1,application/json;odata=verbose;q=0.5",multipartAccept:"multipart/mixed",sortBy:"$orderby",select:"$select",skip:"$skip",take:"$top",count:"$count",search:"$search",where:"$filter",expand:"$expand",batch:"$batch",changeSet:"--changeset_",batchPre:"batch_",contentId:"Content-Id: ",batchContent:"Content-Type: multipart/mixed; boundary=",changeSetContent:"Content-Type: application/http\nContent-Transfer-Encoding: binary ",batchChangeSetContentType:"Content-Type: application/json; charset=utf-8 "},onCount:function(n){return n===!0?"true":""},onPredicate:function(n,i,r){var u="",f=n.value,e=f instanceof Date;return t.data.odUniOperator.contains="contains",u=t.ODataAdaptor.prototype.onPredicate.call(this,n,i,r),t.data.odUniOperator.contains="substringof",e&&(u=u.replace(/datetime'(.*)'$/,"$1")),u},onEachSearch:function(n){var t=this.pvt.search||[];t.push(n.key);this.pvt.search=t},onSearch:function(){return this.pvt.search.join(" OR ")},beforeSend:function(){},processQuery:function(n,i){for(var f,o,e=/\/[\d*\/]*/g,u="",r=i._expands.length-1;r>0;r--)if(u.indexOf(i._expands[r])>=0)i._expands.pop();else if(e.test(i._expands[r])){for(u=i._expands.pop(),f=u.replace(e,"($expand="),o=0;o<u.split(e).length-1;o++)f=f+")";i._expands.unshift(f);r++}return t.ODataAdaptor.prototype.processQuery.apply(this,[n,i])},processResponse:function(i,r,f,e,o,s){var l=o&&o.ejPvtData,a,w,nt,k,tt,y,d,p,h,rt;if(e&&e.getResponseHeader("Content-Type")&&e.getResponseHeader("Content-Type").indexOf("xml")!=-1&&i.nodeType==9)return f._requiresCount?{result:[],count:0}:[];if(o&&this.options.batch&&o.url.endsWith(this.options.batch)&&o.type.toLowerCase()==="post"){if(a=e.getResponseHeader("Content-Type"),a=a.substring(a.indexOf("=batchresponse")+1),i=i.split(a),i.length<2)return;for(i=i[1],k=/(?:\bContent-Type.+boundary=)(changesetresponse.+)/i.exec(i),i.replace(k[0],""),tt=k[1],i=i.split(tt),h=i.length;h>-1;h--)/\bContent-ID:/i.test(i[h])&&/\bHTTP.+201/.test(i[h])&&(w=parseInt(/\bContent-ID: (\d+)/i.exec(i[h])[1]),s.added[w]&&(nt=u.parseJson(/^\{.+\}/m.exec(i[h])[0]),n.extend(s.added[w],this.processResponse(nt))));return s}if(y=null,d={},f&&f._requiresCount&&"@odata.count"in i&&(y=i["@odata.count"]),i=t.isNullOrUndefined(i.value)?i:i.value,l&&l.aggregates&&l.aggregates.length){var v=l.aggregates,g,it={};for(h=0;h<v.length;h++)g=t.aggregates[v[h].type],g&&(it[v[h].field+" - "+v[h].type]=g(i,v[h].field));d=it}if(l&&l.groups&&l.groups.length)for(p=l.groups,h=0;h<p.length;h++)rt=b(p[h],f.queries),i=t.group(i,p[h],l.aggregates,rt);return c(y)?i:{result:i,count:y,aggregates:d}}});t.JsonAdaptor=(new t.Adaptor).extend({processQuery:function(n,t){for(var u=n.dataSource.json.slice(0),o=u.length,s=!0,f,i,h={},e=0;e<t.queries.length;e++)i=t.queries[e],f=this[i.fn].call(this,u,i.e,t),i.fn=="onAggregates"?h[i.e.field+" - "+i.e.type]=f:u=f!==r?f:u,(i.fn==="onPage"||i.fn==="onSkip"||i.fn==="onTake"||i.fn==="onRange")&&(s=!1),s&&(o=u.length);return t._requiresCount&&(u={result:u,count:o,aggregates:h}),u},batchRequest:function(n,t,i){for(var r=0;r<t.added.length;r++)this.insert(n,t.added[r]);for(r=0;r<t.changed.length;r++)this.update(n,i.key,t.changed[r]);for(r=0;r<t.deleted.length;r++)this.remove(n,i.key,t.deleted[r]);return t},onWhere:function(n,t){return n?n.filter(function(n){return t.validate(n)}):n},onAggregates:function(n,i){var r=t.aggregates[i.type];return!n||!r||n.length==0?null:r(n,i.field)},onSearch:function(n,i){return!n||!n.length?n:(i.fieldNames.length===0&&t.pvt.getFieldList(n[0],i.fieldNames),n.filter(function(n){for(var r=0;r<i.fieldNames.length;r++)if(i.comparer.call(n,t.pvt.getObject(i.fieldNames[r],n),i.searchKey,i.ignoreCase))return!0;return!1}))},onSortBy:function(n,i,r){var o,u,f;if(!n)return n;if(u=e(i.fieldName,r),!u)return n.sort(i.comparer);if(u instanceof Array){for(u=u.slice(0),f=u.length-1;f>=0;f--)u[f]&&(o=i.comparer,u[f].endsWith(" desc")&&(o=t.pvt.fnSort(t.sortOrder.Descending),u[f]=u[f].replace(" desc","")),n=it(n,u[f],o,[]));return n}return it(n,u,i.comparer,r?r.queries:[])},onGroup:function(n,i,r){var u,o,s,f,h;if(!n)return n;if(u=a(r.queries,"onAggregates"),o=[],u.length)for(f=0;f<u.length;f++)s=u[f].e,o.push({type:s.type,field:e(s.field,r)});return h=b(i.fieldName,r.queries),t.group(n,e(i.fieldName,r),o,h)},onPage:function(n,t,i){var r=e(t.pageSize,i),u=(e(t.pageIndex,i)-1)*r,f=u+r;return n?n.slice(u,f):n},onRange:function(n,t){return n?n.slice(e(t.start),e(t.end)):n},onTake:function(n,t){return n?n.slice(0,e(t.nos)):n},onSkip:function(n,t){return n?n.slice(e(t.nos)):n},onSelect:function(n,i){return n?t.select(n,e(i.fieldNames)):n},insert:function(n,t){return n.dataSource.json.push(t)},remove:function(n,i,r){var f=n.dataSource.json,u;for(typeof r=="object"&&(r=t.getObject(i,r)),u=0;u<f.length;u++)if(t.getObject(i,f[u])===r)break;return u!==f.length?f.splice(u,1):null},update:function(i,r,u){for(var e=i.dataSource.json,o=t.getObject(r,u),f=0;f<e.length;f++)if(t.getObject(r,e[f])===o)break;return f<e.length?n.extend(e[f],u):null}});t.ForeignKeyAdaptor=function(i,u){var f=(new t[u||"JsonAdaptor"]).extend({init:function(){var r,n;for(this.foreignData=[],this.key=[],this.adaptorType=u,this.value=[],this.fValue=[],this.keyField=[],r=i,n=0;n<r.length;n++)this.foreignData[n]=r[n].dataSource,this.key[n]=r[n].foreignKeyField,this.fValue[n]=t.isNullOrUndefined(r[n].field)?r[n].foreignKeyValue:r[n].field+"_"+r[n].foreignKeyValue,this.value[n]=r[n].foreignKeyValue,this.keyField[n]=r[n].field||r[n].foreignKeyField,this.initial=!0},processQuery:function(n,i){var e=n.dataSource.json,u,f,r;if(this.initial){for(u=0;u<e.length;u++)for(f=this,r=0;r<this.foreignData.length;r++)this.foreignData[r].filter(function(n){t.getObject(f.key[r],n)==t.getObject(f.keyField[r],e[u])&&(e[u][f.fValue[r]]=t.getObject(f.value[r],n))});this.initial=!1}return this.base.processQuery.apply(this,[n,i])},setValue:function(i){for(var o,f,e,u=0;u<this.foreignData.length;u++)o=this,f=i[this.fValue[u]],typeof f!="string"||isNaN(f)||(f=t.parseFloat(f)),e=n.grep(o.foreignData[u],function(n){return n[o.value[u]]==f})[0],t.isNullOrUndefined(e)&&(e=n.grep(o.foreignData[u],function(n){return n[o.key[u]]==f})[0],t.getObject(this.value[u],e)!=r&&t.createObject(o.value[u],t.getObject(this.value[u],e),i)),t.getObject(this.value[u],e)!=r&&t.createObject(this.keyField[u],t.getObject(this.key[u],e),i)},insert:function(n,t,i){return this.setValue(t),{url:n.dataSource.insertUrl||n.dataSource.crudUrl||n.dataSource.url,data:JSON.stringify({value:t,table:i,action:"insert"})}},update:function(n,i,r,u){return this.setValue(r),t.JsonAdaptor.prototype.update(n,i,r,u),{type:"POST",url:n.dataSource.updateUrl||n.dataSource.crudUrl||n.dataSource.url,data:JSON.stringify({value:r,action:"update",keyColumn:i,key:r[i],table:u})}}});return n.extend(this,new f),this};t.remoteSaveAdaptor=(new t.JsonAdaptor).extend({beforeSend:t.UrlAdaptor.prototype.beforeSend,insert:t.UrlAdaptor.prototype.insert,update:t.UrlAdaptor.prototype.update,remove:t.UrlAdaptor.prototype.remove,addParams:t.UrlAdaptor.prototype.addParams,batchRequest:function(n,t,i,r){var u={changed:t.changed,added:t.added,deleted:t.deleted,action:"batch",table:i.url,key:i.key};return r&&this.addParams({dm:n,query:r,params:r._params,reqParams:u}),{type:"POST",url:n.dataSource.batchUrl||n.dataSource.crudUrl||n.dataSource.url,contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify(u)}},processResponse:function(n,i,r,u,f,e,o){if(t.isNullOrUndefined(e))return n.d?n.d:n;for(var s=0;s<e.added.length;s++)t.JsonAdaptor.prototype.insert(i,e.added[s]);for(s=0;s<e.changed.length;s++)t.JsonAdaptor.prototype.update(i,o,e.changed[s]);for(s=0;s<e.deleted.length;s++)t.JsonAdaptor.prototype.remove(i,o,e.deleted[s]);return this.base.processResponse.apply(this,[n,i,r,u,f,e])}});t.WebApiAdaptor=(new t.ODataAdaptor).extend({insert:function(n,t){return{type:"POST",url:n.dataSource.url,data:JSON.stringify(t)}},remove:function(n,t,i){return{type:"DELETE",url:n.dataSource.url+"/"+i,data:JSON.stringify(i)}},update:function(n,t,i){return{type:"PUT",url:n.dataSource.url,data:JSON.stringify(i)}},batchRequest:function(i,r,u){var e=u.guid=t.getGuid(l.batchPre),f=[];return n.each(r.added,function(n,t){f.push("--"+e);f.push("Content-Type: application/http; msgtype=request","");f.push("POST "+i.dataSource.insertUrl+" HTTP/1.1");f.push("Content-Type: application/json; charset=utf-8");f.push("Host: "+location.host);f.push("",t?JSON.stringify(t):"")}),n.each(r.changed,function(n,t){f.push("--"+e);f.push("Content-Type: application/http; msgtype=request","");f.push("PUT "+i.dataSource.updateUrl+" HTTP/1.1");f.push("Content-Type: application/json; charset=utf-8");f.push("Host: "+location.host);f.push("",t?JSON.stringify(t):"")}),n.each(r.deleted,function(n,t){f.push("--"+e);f.push("Content-Type: application/http; msgtype=request","");f.push("DELETE "+i.dataSource.removeUrl+"/"+t[u.key]+" HTTP/1.1");f.push("Content-Type: application/json; charset=utf-8");f.push("Host: "+location.host);f.push("",t?JSON.stringify(t):"")}),f.push("--"+e+"--",""),{type:"POST",url:i.dataSource.batchUrl||i.dataSource.crudUrl||i.dataSource.url,data:f.join("\r\n"),contentType:'multipart/mixed; boundary="'+e+'"'}},processResponse:function(n,i,r,u,f){var o=f&&f.ejPvtData,l,e,w;if(f&&f.type.toLowerCase()!="post"){var h=u&&u.getResponseHeader("DataServiceVersion"),a=null,y={};if(h=h&&parseInt(h,10)||2,r&&r._requiresCount&&(c(n.Count)||(a=n.Count)),h<3&&n.Items&&(n=n.Items),o&&o.aggregates&&o.aggregates.length){var s=o.aggregates,v,p={};for(e=0;e<s.length;e++)v=t.aggregates[s[e].type],v&&(p[s[e].field+" - "+s[e].type]=v(n,s[e].field));y=p}if(o&&o.groups&&o.groups.length)for(l=o.groups,e=0;e<l.length;e++)w=b(l[e],r.queries),n=t.group(n,l[e],o.aggregates,w);return c(a)?n:{result:n,count:a,aggregates:y}}}});e=function(n,t){return typeof n=="function"?n.call(t||{}):n};t.TableModel=function(i,r,u,e){var c,o,l,s;if(!p(this,t.TableModel))return new t.TableModel(r);for(p(r,Array)||f("ej.TableModel - Json Array is required"),c=[],l=h(ht,this),s=0;s<r.length;s++){o=new t.Model(r[s],this);o.state="unchanged";o.on("stateChange",l);e&&o.computes(e);c.push(o)}return this.name=i||"table1",this.rows=t.NotifierArray(c),this._deleted=[],this._events=n({}),this.dataManager=u,this._isDirty=!1,this};t.TableModel.prototype={on:function(n,t){this._events.on(n,t)},off:function(n,t){this._events.off(n,t)},setDataManager:function(n){this.dataManagar=n},saveChanges:function(){if(this.dataManager&&p(this.dataManager,t.DataManager)||f("ej.TableModel - saveChanges : Set the dataManager using setDataManager function"),this.isDirty()){var n=this.dataManager.saveChanges(this.getChanges(),this.key,this.name);n.done(h(function(n){for(var t=this.toArray(),i=0;i<t.length;i++)t.state==="added"&&t.set(this.key,n.added.filter(function(n){return n[this.key]===t.get(this.key)})[0][this.key]),t[i].markCommit();this._events.triggerHandler({type:"save",table:this})},this));n.fail(h(function(n){this.rejectChanges();this._events.triggerHandler({type:"reject",table:this,error:n})},this));this._isDirty=!1}},rejectChanges:function(){for(var t=this.toArray(),n=0;n<t.length;n++)t[n].revert(!0);this._isDirty=!1;this._events.triggerHandler({type:"reject",table:this})},insert:function(n){var i=new t.Model(n);i._isDirty=this._isDirty=!0;this.rows.push(i);this._events.triggerHandler({type:"insert",model:i,table:this})},update:function(n){var r;this.key||f("TableModel - update : Primary key should be assigned to TableModel.key");var i=n,t,u=this.key,e=i[u];t=this.rows.array.filter(function(n){return n.get(u)===e});t=t[0];for(r in i)t.set(r,i[r]);this._isDirty=!0;this._events.triggerHandler({type:"update",model:t,table:this})},remove:function(n){var t,i,e,u;for(this.key||f("TableModel - update : Primary key should be assigned to TableModel.key"),t=this.key,i=-1,n&&typeof n=="object"&&(n=n[t]!==r?n[t]:n.get(t)),u=0;u<this.rows.length();u++)if(this.rows.array[u].get(t)===n){i=u;break}i>-1&&(e=this.rows.removeAt(i),e.markDelete(),this._deleted.push({model:e,position:i}),this._isDirty=!0,this._events.triggerHandler({type:"remove",model:e,table:this}))},isDirty:function(){return this._isDirty},getChanges:function(){for(var i={added:[],changed:[]},r=this.toArray(),n=0;n<r.length;n++)i[r[n].state]&&i[r[n].state].push(r[n].json);return i.deleted=t.select(this._deleted,["model"]),i},toArray:function(){return this.rows.toArray()},setDirty:function(n,t){this._isDirty!==!!n&&(this._isDirty=!!n,this._events.triggerHandler({type:"dirty",table:this,model:t}))},get:function(n){return this.rows.array[n]},length:function(){return this.rows.array.length},bindTo:function(t){var i=nt,e=n(t.html()),f=this.toArray(),u,r;for(n.inArray(t.prop("tagName").toLowerCase(),["table","tbody"])&&(i=tt),i.insertBefore(t),t.detach().empty(),r=0;r<f.length;r++)u=e.clone(),f[r].bindTo(u),t.append(u);t.insertAfter(i);i.remove()}};nt=i?n(document.createElement("div")):{};tt=i?n(document.createElement("tr")):{};t.Model=function(i,r,u){typeof r=="string"&&(u=r,r=null);this.$id=et("m");this.json=i;this.table=r instanceof t.TableModel?r:null;this.name=u||this.table&&this.table.name;this.dataManager=r instanceof t.DataManager?r:r.dataManagar;this.actual={};this._events=n({});this.isDirty=!1;this.state="added";this._props=[];this._computeEls={};this._fields={};this._attrEls={};this._updates={};this.computed={}};t.Model.prototype={computes:function(t){n.extend(this.computed,t)},on:function(n,t){this._events.on(n,t)},off:function(n,t){this._events.off(n,t)},set:function(n,t){var i=this.json,e=n,f,u;for(n=n.split("."),u=0;u<n.length-1;u++)n=n[0],i=i[n[0]];this.isDirty=!0;this.changeState("changed",{from:"set"});f=i[n];this.actual[n]!==r||n in this.actual||(this.actual[n]=t);i[n]=t;this._updateValues(n,t);this._events.triggerHandler({type:e,current:t,previous:f,model:this})},get:function(n){return t.pvt.getObject(n,this.json)},revert:function(n){for(var t in this.actual)this.json[t]=this.actual[t];this.isDirty=!1;n?this.state="unchanged":this.changeState("unchanged",{from:"revert"})},save:function(i,r){return(i=i||this.dataManagar,r=r||i.dataSource.key,i||f("ej.Model - DataManager is required to commit the changes"),this.state==="added")?i.insert(this.json,this.name).done(t.proxy(function(t){n.extend(this.json,t.record)},this)):this.state==="changed"?i.update(r,this.json,this.name):this.state==="deleted"?i.remove(r,this.json,this.name):void 0},markCommit:function(){this.isDirty=!1;this.changeState("unchanged",{from:"commit"})},markDelete:function(){this.changeState("deleted",{from:"delete"})},changeState:function(t,i){if(this.state!==t){if(this.state==="added")if(t==="deleted")t="unchanged";else return;var r=t;i=i||{};this.state=t;this._events.triggerHandler(n.extend({type:"stateChange",current:t,previous:r,model:this},i))}},properties:function(){if(this._props.length)return this._props;for(var n in this.json)this._props.push(n),this._updates[n]={read:[],input:[]};return this._props},bindTo:function(t){var e=n(t),r,i,o=e.find("[ej-observe], [ej-computed], [ej-prop]"),s=o.length,u,f;for(e.data("ejModel",this),u={fields:[],props:[],computes:[]},f=0;f<s;f++){if(r=o.eq(f),i=r.attr("ej-prop"),i&&this._processAttrib(i,r,u),i=r.attr("ej-observe"),i&&this._props.indexOf(i)!==-1){this._processField(r,i,u);continue}if(i=r.attr("ej-computed"),i){this._processComputed(i,r,u);continue}}e.data("ejModelBinding"+this.$id,u)},unbind:function(t){var u,r={props:this._attrEls,computes:this._computeEls},f=!1,i,c,e,s,h,o;t&&(r=n(t).removeData("ejModel").data("ejModelBinding"+this.$id)||r,f=!0);for(i in this.computed)u=r.computes[i],i=this.computed[i],u&&i.deps&&(this.off(i.deps.join(" "),u.handle),f&&delete this._computeEls[i]);f||(this._computeEls={});for(i in r.props)u=r.props[i],u&&(this.off(u.deps.join(" "),u.handle),delete r.props[i],f&&delete this._attrEls[i]);if(f||(this._attrEls={}),r.fields&&r.fields.length)for(c=r.fields.length,o=0;o<c;o++)e=r.fields[o],n(e).off("change",null,this._changeHandler),h=this.formElements.indexOf(e.tagName.toLowerCase())!==-1?"input":"read",s=this._updates[h].indexOf(e),s!==-1&&this._updates[h].splice(s,1)},_processComputed:function(n,t,i){if(n){var r,u,f=st(n),e=this.formElements.indexOf(t[0].tagName.toLowerCase())!==-1?"val":"html";this.computed[n]&&this.computed[f]||(this.computed[f]={value:new Function("var e = this; return "+n),deps:this._generateDeps(n)},n=f);r=this.computed[n];r.get||(r.get=function(){r.value.call(this.json)});u=r.deps;r=r.value;this._updateDeps(u);this._updateElement(t,e,r);r={el:t,handle:h(this._computeHandle,this,{value:n,type:e})};this._computeEls[n]=r;i.computes[n]=r;this.on(u.join(" "),r.handle)}},_computeHandle:function(n){var t=this._computeEls[n.value];t&&this.computed[n.value]&&this._updateElement(t.el,n.type,this.computed[n.value].value)},_updateElement:function(t,i,r){t[i](r.call(n.extend({},this.json,this.computed)))},_updateDeps:function(n){for(var i=0;i<n.length;i++)!(n[i]in this.json)&&n[i]in this.computed&&t.merge(n,this.computed[n[i]].deps)},_generateDeps:function(n){for(var r=n.replace(/(^e\.)|( e\.)/g,"#%^*##ej.#").split("#%^*#"),t,u=[],i=0;i<r.length;i++)r[i].startsWith("#ej.#")&&(t=r[i].replace("#ej.#","").split(" ")[0],t&&this._props.indexOf(t)!==-1&&u.push(t));return u},_processAttrib:function(n,t,i){var e,o,u={},r,f;for(n=n.replace(/^ +| +$/g,"").split(";"),r=0;r<n.length;r++)(n[r]=n[r].split(":"),n[r].length<2)||(e=n[r][0].replace(/^ +| +$/g,"").replace(/^'|^"|'$|"$/g,""),u[e]=n[r][1].replace(/^ +| +$/g,"").replace(/^'|^"|'$|"$/g,""));n=u;f=[];for(e in n)f.push(n[e]);this._updateDeps(f);this._updateProps(t,n);u=et("emak");o={el:t,handle:h(this._attrHandle,this,u),value:n,deps:f};t.prop("ejmodelattrkey",u);i.props[u]=o;this._attrEls[u]=o;this.on(f.join(" "),o.handle)},_attrHandle:function(n){var t=this._attrEls[n];t&&this._updateProps(t.el,t.value)},_updateProps:function(t,i){var f=this.json,r,u=this.computed;for(var e in i)r=i[e],r in f?r=f[r]:r in u&&(r=u[r],r&&(r=r.value.call(n.extend({},this.json,u)))),c(r)||t.prop(e,r)},_updateValues:function(n,t){var i=this._updates[n];i&&(i.read||i.input)&&(this._ensureItems(i.read,"html",t),this._ensureItems(i.input,"val",t))},_ensureItems:function(t,i,r){if(t)for(var u=t.length-1;u>-1;u--){if(!t[