@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
2 lines • 60.6 kB
JavaScript
module.exports=function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}({0:function(e,t,r){e.exports=r(1048)},3:function(e,t){e.exports=function(){throw Error("define cannot be used indirect")}},1006:function(e,t){e.exports=require("./kendo.core")},1048:function(e,t,r){var n,i,a;!function(s,define){i=[r(1006),r(1049),r(1050)],n=s,a="function"==typeof n?n.apply(t,i):n,!(void 0!==a&&(e.exports=a))}(function(){return function(e,t){function r(e,t,r,n){return function(i){var a,s={};for(a in i)s[a]=i[a];s.field=n?r+"."+i.field:r,t==Ae&&e._notifyChange&&e._notifyChange(s),e.trigger(t,s)}}function n(t,r){if(t===r)return!0;var i,a=e.type(t),s=e.type(r);if(a!==s)return!1;if("date"===a)return t.getTime()===r.getTime();if("object"!==a&&"array"!==a)return!1;for(i in t)if(!n(t[i],r[i]))return!1;return!0}function i(e,t){var r,n;for(n in e){if(r=e[n],_e(r)&&r.field&&r.field===t)return r;if(r===t)return r}return null}function a(e){this.data=e||[]}function s(e,r){if(e){var n=typeof e===Re?{field:e,dir:r}:e,i=me(n)?n:n!==t?[n]:[];return ye(i,function(e){return!!e.dir})}}function o(e){var t,r,n,i,a=e.filters;if(a)for(t=0,r=a.length;t<r;t++)n=a[t],i=n.operator,i&&typeof i===Re&&(n.operator=re[i.toLowerCase()]||i),o(n)}function u(e){if(e&&!ve(e))return!me(e)&&e.filters||(e={logic:"and",filters:me(e)?e:[e]}),o(e),e}function l(e,t){return!e.logic&&!t.logic&&(e.field===t.field&&e.value===t.value&&e.operator===t.operator)}function h(e){return e=e||{},ve(e)?{logic:"and",filters:[]}:u(e)}function d(e,t){return t.logic||e.field>t.field?1:e.field<t.field?-1:0}function f(e,t){var r,n,i,a,s;if(e=h(e),t=h(t),e.logic!==t.logic)return!1;if(i=(e.filters||[]).slice(),a=(t.filters||[]).slice(),i.length!==a.length)return!1;for(i=i.sort(d),a=a.sort(d),s=0;s<i.length;s++)if(r=i[s],n=a[s],r.logic&&n.logic){if(!f(r,n))return!1}else if(!l(r,n))return!1;return!0}function c(e){return me(e)?e:[e]}function g(e,r,n,i){var a=typeof e===Re?{field:e,dir:r,compare:n,skipItemSorting:i}:e,s=me(a)?a:a!==t?[a]:[];return Q(s,function(e){return{field:e.field,dir:e.dir||"asc",aggregates:e.aggregates,compare:e.compare,skipItemSorting:e.skipItemSorting}})}function p(e,t,r){var n,i=g(e,t,r);for(n=0;n<i.length;n++)delete i[n].compare;return i}function _(e){var t,r=me(e)?e:[e];for(t=0;t<r.length;t++)if(r[t]&&xe(r[t].compare))return!0;return!1}function v(e,t){return e&&e.getTime&&t&&t.getTime?e.getTime()===t.getTime():e===t}function m(e,t,r,n,i,a){var s,o,u,l,h;for(t=t||[],l=t.length,s=0;s<l;s++)o=t[s],u=o.aggregate,h=o.field,e[h]=e[h]||{},a[h]=a[h]||{},a[h][u]=a[h][u]||{},e[h][u]=ne[u.toLowerCase()](e[h][u],r,ke.accessor(h),n,i,a[h][u])}function y(e){return"number"==typeof e&&!isNaN(e)}function S(e){return e&&e.getTime}function b(e){var t,r=e.length,n=Array(r);for(t=0;t<r;t++)n[t]=e[t].toJSON();return n}function w(e,t,r,n,i){var a,s,o,u,l,h={};for(u=0,l=e.length;u<l;u++){a=e[u];for(s in t)o=i[s],o&&o!==s&&(h[o]||(h[o]=ke.setter(o)),h[o](a,t[s](a)),delete a[s])}}function k(e,t,r,n,i){var a,s,o,u,l;for(u=0,l=e.length;u<l;u++){a=e[u];for(s in t)a[s]=r._parse(s,t[s](a)),o=i[s],o&&o!==s&&delete a[o]}}function x(e,t,r,n,i){var a,s,o,u;for(s=0,u=e.length;s<u;s++)a=e[s],o=n[a.field],o&&o!=a.field&&(a.field=o),a.value=r._parse(a.field,a.value),a.hasSubgroups?x(a.items,t,r,n,i):k(a.items,t,r,n,i)}function F(e,t,r,n,i,a){return function(s){return s=e(s),q(t,r,n,i,a)(s)}}function q(e,t,r,n,i){return function(a){return a&&!ve(r)&&("[object Array]"===Ze.call(a)||a instanceof rt||(a=[a]),t(a,r,new e,n,i)),a||[]}}function R(e,t){var r,n,i;if(t.items&&t.items.length)for(i=0;i<t.items.length;i++)r=e.items[i],n=t.items[i],r&&n?r.hasSubgroups?R(r,n):r.field&&r.value==n.value?r.items.push.apply(r.items,n.items):e.items.push.apply(e.items,[n]):n&&e.items.push.apply(e.items,[n])}function D(e,t,r,n){for(var i,a,s,o=0;t.length&&n&&(i=t[o],a=i.items,s=a.length,e&&e.field===i.field&&e.value===i.value?(e.hasSubgroups&&e.items.length?D(e.items[e.items.length-1],i.items,r,n):(a=a.slice(r,r+n),e.items=e.items.concat(a)),t.splice(o--,1)):i.hasSubgroups&&a.length?(D(i,a,r,n),i.items.length||t.splice(o--,1)):(a=a.slice(r,r+n),i.items=a,i.items.length||t.splice(o--,1)),0===a.length?r-=s:(r=0,n-=a.length),!(++o>=t.length)););o<t.length&&t.splice(o,t.length-o)}function z(e,t){var r,n,i,a,s=[],o=(e||[]).length,u=xe(t)?t:function(e,t){return e[t]};for(i=0;i<o;i++)if(r=u(e,i),r.hasSubgroups)s=s.concat(z(r.items));else for(n=r.items,a=0;a<n.length;a++)s.push(u(n,a));return s}function C(e){var t,r,n,i,a,s=[];for(t=0,r=e.length;t<r;t++)if(a=e.at(t),a.hasSubgroups)s=s.concat(C(a.items));else for(n=a.items,i=0;i<n.length;i++)s.push(n.at(i));return s}function O(e,t){var r,n,i;if(t)for(r=0,n=e.length;r<n;r++)i=e.at(r),i.hasSubgroups?O(i.items,t):i.items=new W(i.items,t,i.items._events)}function P(e,t){for(var r=0;r<e.length;r++)if(e[r].hasSubgroups){if(P(e[r].items,t))return!0}else if(t(e[r].items,e[r]))return!0}function T(e,t,r,n){for(var i=0;i<e.length&&e[i].data!==t&&!A(e[i].data,r,n);i++);}function A(e,t,r){for(var n=0,i=e.length;n<i;n++){if(e[n]&&e[n].hasSubgroups)return A(e[n].items,t,r);if(e[n]===t||e[n]===r)return e[n]=r,!0}}function I(e,r,n,i,a){var s,o,u,l;for(s=0,o=e.length;s<o;s++)if(u=e[s],u&&!(u instanceof i))if(u.hasSubgroups===t||a){for(l=0;l<r.length;l++)if(r[l]===u){e[s]=r.at(l),T(n,r,u,e[s]);break}}else I(u.items,r,n,i,a)}function M(e,t){var r,n,i=e.length;for(n=0;n<i;n++)if(r=e[n],r.uid&&r.uid==t.uid)return e.splice(n,1),r}function N(e,t){return t?E(e,function(e){return e.uid&&e.uid==t.uid||e[t.idField]===t.id&&t.id!==t._defaultId}):-1}function G(e,t){return t?E(e,function(e){return e.uid==t.uid}):-1}function E(e,t){var r,n;for(r=0,n=e.length;r<n;r++)if(t(e[r]))return r;return-1}function L(e,t){var r,n;return e&&!ve(e)?(r=e[t],n=_e(r)?r.from||r.field||t:e[t]||t,xe(n)?t:n):t}function j(e,t){var r,n,i,a={};for(i in e)"filters"!==i&&(a[i]=e[i]);if(e.filters)for(a.filters=[],r=0,n=e.filters.length;r<n;r++)a.filters[r]=j(e.filters[r],t);else a.field=L(t.fields,a.field);return a}function B(e,t){var r,n,i,a,s,o=[];for(r=0,n=e.length;r<n;r++){i={},a=e[r];for(s in a)i[s]=a[s];i.field=L(t.fields,i.field),i.aggregates&&me(i.aggregates)&&(i.aggregates=B(i.aggregates,t)),o.push(i)}return o}function H(t,r){var n,i,a,s,o,u,l,h,d,f;for(t=e(t)[0],n=t.options,i=r[0],a=r[1],s=[],o=0,u=n.length;o<u;o++)d={},h=n[o],l=h.parentNode,l===t&&(l=null),h.disabled||l&&l.disabled||(l&&(d.optgroup=l.label),d[i.field]=h.text,f=h.attributes.value,f=f&&f.specified?h.value:h.text,d[a.field]=f,s.push(d));return s}function U(t,r){var n,i,a,s,o,u,l,h=e(t)[0].tBodies[0],d=h?h.rows:[],f=r.length,c=[];for(n=0,i=d.length;n<i;n++){for(o={},l=!0,s=d[n].cells,a=0;a<f;a++)u=s[a],"th"!==u.nodeName.toLowerCase()&&(l=!1,o[r[a].field]=u.innerHTML);l||c.push(o)}return c}function J(e){return function(){var t=this._data,r=ue.fn[e].apply(this,Xe.call(arguments));return this._data!=t&&this._attachBubbleHandlers(),r}}function V(t,r){function n(e,t){return e.filter(t).add(e.find(t))}var i,a,s,o,u,l,h,d,f=e(t).children(),c=[],g=r[0].field,p=r[1]&&r[1].field,_=r[2]&&r[2].field,v=r[3]&&r[3].field;for(i=0,a=f.length;i<a;i++)s={_loaded:!0},o=f.eq(i),l=o[0].firstChild,d=o.children(),t=d.filter("ul"),d=d.filter(":not(ul)"),u=o.attr("data-id"),u&&(s.id=u),l&&(s[g]=3==l.nodeType?l.nodeValue:d.text()),p&&(s[p]=n(d,"a").attr("href")),v&&(s[v]=n(d,"img").attr("src")),_&&(h=n(d,".k-sprite").prop("className"),s[_]=h&&e.trim(h.replace("k-sprite",""))),t.length&&(s.items=V(t.eq(0),r)),"true"==o.attr("data-hasChildren")&&(s.hasChildren=!0),c.push(s);return c}var Q,W,$,K,X,Y,Z,ee,te,re,ne,ie,ae,se,oe,ue,le,he,de,fe,ce,ge=e.extend,pe=e.proxy,_e=e.isPlainObject,ve=e.isEmptyObject,me=e.isArray,ye=e.grep,Se=e.ajax,be=e.each,we=e.noop,ke=window.kendo,xe=ke.isFunction,Fe=ke.Observable,qe=ke.Class,Re="string",De="function",ze="asc",Ce="create",Oe="read",Pe="update",Te="destroy",Ae="change",Ie="sync",Me="get",Ne="error",Ge="requestStart",Ee="progress",Le="requestEnd",je=[Ce,Oe,Pe,Te],Be=function(e){return e},He=ke.getter,Ue=ke.stringify,Je=Math,Ve=[].push,Qe=[].join,We=[].pop,$e=[].splice,Ke=[].shift,Xe=[].slice,Ye=[].unshift,Ze={}.toString,et=ke.support.stableSort,tt=/^\/Date\((.*?)\)\/$/,rt=Fe.extend({init:function(e,t){var r=this;r.type=t||$,Fe.fn.init.call(r),r.length=e.length,r.wrapAll(e,r)},at:function(e){return this[e]},toJSON:function(){var e,t,r=this.length,n=Array(r);for(e=0;e<r;e++)t=this[e],t instanceof $&&(t=t.toJSON()),n[e]=t;return n},parent:we,wrapAll:function(e,t){var r,n,i=this,a=function(){return i};for(t=t||[],r=0,n=e.length;r<n;r++)t[r]=i.wrap(e[r],a);return t},wrap:function(e,t){var r,n=this;return null!==e&&"[object Object]"===Ze.call(e)&&(r=e instanceof n.type||e instanceof Y,r||(e=e instanceof $?e.toJSON():e,e=new n.type(e)),e.parent=t,e.bind(Ae,function(e){n.trigger(Ae,{field:e.field,node:e.node,index:e.index,items:e.items||[this],action:e.node?e.action||"itemloaded":"itemchange"})})),e},push:function(){var e,t=this.length,r=this.wrapAll(arguments);return e=Ve.apply(this,r),this.trigger(Ae,{action:"add",index:t,items:r}),e},slice:Xe,sort:[].sort,join:Qe,pop:function(){var e=this.length,t=We.apply(this);return e&&this.trigger(Ae,{action:"remove",index:e-1,items:[t]}),t},splice:function(e,t,r){var n,i,a,s=this.wrapAll(Xe.call(arguments,2));if(n=$e.apply(this,[e,t].concat(s)),n.length)for(this.trigger(Ae,{action:"remove",index:e,items:n}),i=0,a=n.length;i<a;i++)n[i]&&n[i].children&&n[i].unbind(Ae);return r&&this.trigger(Ae,{action:"add",index:e,items:s}),n},shift:function(){var e=this.length,t=Ke.apply(this);return e&&this.trigger(Ae,{action:"remove",index:0,items:[t]}),t},unshift:function(){var e,t=this.wrapAll(arguments);return e=Ye.apply(this,t),this.trigger(Ae,{action:"add",index:0,items:t}),e},indexOf:function(e){var t,r,n=this;for(t=0,r=n.length;t<r;t++)if(n[t]===e)return t;return-1},forEach:function(e,t){for(var r=0,n=this.length,i=t||window;r<n;r++)e.call(i,this[r],r,this)},map:function(e,t){for(var r=0,n=[],i=this.length,a=t||window;r<i;r++)n[r]=e.call(a,this[r],r,this);return n},reduce:function(e){var t,r=0,n=this.length;for(2==arguments.length?t=arguments[1]:r<n&&(t=this[r++]);r<n;r++)t=e(t,this[r],r,this);return t},reduceRight:function(e){var t,r=this.length-1;for(2==arguments.length?t=arguments[1]:r>0&&(t=this[r--]);r>=0;r--)t=e(t,this[r],r,this);return t},filter:function(e,t){for(var r,n=0,i=[],a=this.length,s=t||window;n<a;n++)r=this[n],e.call(s,r,n,this)&&(i[i.length]=r);return i},find:function(e,t){for(var r,n=0,i=this.length,a=t||window;n<i;n++)if(r=this[n],e.call(a,r,n,this))return r},every:function(e,t){for(var r,n=0,i=this.length,a=t||window;n<i;n++)if(r=this[n],!e.call(a,r,n,this))return!1;return!0},some:function(e,t){for(var r,n=0,i=this.length,a=t||window;n<i;n++)if(r=this[n],e.call(a,r,n,this))return!0;return!1},remove:function(e){var t=this.indexOf(e);t!==-1&&this.splice(t,1)},empty:function(){this.splice(0,this.length)}});"undefined"!=typeof Symbol&&Symbol.iterator&&!rt.prototype[Symbol.iterator]&&(rt.prototype[Symbol.iterator]=[][Symbol.iterator]),W=rt.extend({init:function(e,t,r){Fe.fn.init.call(this),this.type=t||$,r&&(this._events=r);for(var n=0;n<e.length;n++)this[n]=e[n];this.length=n,this._parent=pe(function(){return this},this)},at:function(e){var t=this[e];return t instanceof this.type?t.parent=this._parent:t=this[e]=this.wrap(t,this._parent),t}}),$=Fe.extend({init:function(e){var t,r,n=this,i=function(){return n};Fe.fn.init.call(this),this._handlers={};for(r in e)t=e[r],"object"==typeof t&&t&&!t.getTime&&"_"!=r.charAt(0)&&(t=n.wrap(t,r,i)),n[r]=t;n.uid=ke.guid()},shouldSerialize:function(e){return this.hasOwnProperty(e)&&"_handlers"!==e&&"_events"!==e&&typeof this[e]!==De&&"uid"!==e},forEach:function(e){for(var t in this)this.shouldSerialize(t)&&e(this[t],t)},toJSON:function(){var e,t,r={};for(t in this)this.shouldSerialize(t)&&(e=this[t],(e instanceof $||e instanceof rt)&&(e=e.toJSON()),r[t]=e);return r},get:function(e){var t,r=this;return r.trigger(Me,{field:e}),t="this"===e?r:ke.getter(e,!0)(r)},_set:function(e,t){var r,n,i,a=this,s=e.indexOf(".")>=0;if(s)for(r=e.split("."),n="";r.length>1;){if(n+=r.shift(),i=ke.getter(n,!0)(a),i instanceof $)return i.set(r.join("."),t),s;n+="."}return ke.setter(e)(a,t),s},set:function(e,t){var r=this,n=!1,i=e.indexOf(".")>=0,a=ke.getter(e,!0)(r);return a!==t&&(a instanceof Fe&&this._handlers[e]&&(this._handlers[e].get&&a.unbind(Me,this._handlers[e].get),a.unbind(Ae,this._handlers[e].change)),n=r.trigger("set",{field:e,value:t}),n||(i||(t=r.wrap(t,e,function(){return r})),(!r._set(e,t)||e.indexOf("(")>=0||e.indexOf("[")>=0)&&r.trigger(Ae,{field:e}))),n},parent:we,wrap:function(e,t,n){var i,a,s,o,u=this,l=Ze.call(e);return null==e||"[object Object]"!==l&&"[object Array]"!==l||(s=e instanceof rt,o=e instanceof ue,"[object Object]"!==l||o||s?("[object Array]"===l||s||o)&&(s||o||(e=new rt(e)),a=r(u,Ae,t,!1),e.bind(Ae,a),u._handlers[t]={change:a}):(e instanceof $||(e=new $(e)),i=r(u,Me,t,!0),e.bind(Me,i),a=r(u,Ae,t,!0),e.bind(Ae,a),u._handlers[t]={get:i,change:a}),e.parent=n),e}}),K={number:function(e){return typeof e===Re&&"null"===e.toLowerCase()?null:ke.parseFloat(e)},date:function(e){return typeof e===Re&&"null"===e.toLowerCase()?null:ke.parseDate(e)},"boolean":function(e){return typeof e===Re?"null"===e.toLowerCase()?null:"true"===e.toLowerCase():null!=e?!!e:e},string:function(e){return typeof e===Re&&"null"===e.toLowerCase()?null:null!=e?e+"":e},"default":function(e){return e}},X={string:"",number:0,date:new Date,"boolean":!1,"default":""},Y=$.extend({init:function(r){var n,i,a=this;if((!r||e.isEmptyObject(r))&&(r=e.extend({},a.defaults,r),a._initializers))for(n=0;n<a._initializers.length;n++)i=a._initializers[n],r[i]=a.defaults[i]();$.fn.init.call(a,r),a.dirty=!1,a.dirtyFields={},a.idField&&(a.id=a.get(a.idField),a.id===t&&(a.id=a._defaultId))},shouldSerialize:function(e){return $.fn.shouldSerialize.call(this,e)&&"uid"!==e&&!("id"!==this.idField&&"id"===e)&&"dirty"!==e&&"dirtyFields"!==e&&"_accessors"!==e},_parse:function(e,t){var r,n=this,a=e,s=n.fields||{};return e=s[e],e||(e=i(s,a)),e&&(r=e.parse,!r&&e.type&&(r=K[e.type.toLowerCase()])),r?r(t):t},_notifyChange:function(e){var t=e.action;"add"!=t&&"remove"!=t||(this.dirty=!0,this.dirtyFields[e.field]=!0)},editable:function(e){return e=(this.fields||{})[e],!e||e.editable!==!1},set:function(e,t,r){var i=this,a=i.dirty;i.editable(e)&&(t=i._parse(e,t),n(t,i.get(e))?i.trigger("equalSet",{field:e,value:t}):(i.dirty=!0,i.dirtyFields[e]=!0,$.fn.set.call(i,e,t,r)&&!a&&(i.dirty=a,i.dirty||(i.dirtyFields[e]=!1))))},accept:function(e){var t,r,n=this,i=function(){return n};for(t in e)r=e[t],"_"!=t.charAt(0)&&(r=n.wrap(e[t],t,i)),n._set(t,r);n.idField&&(n.id=n.get(n.idField)),n.dirty=!1,n.dirtyFields={}},isNew:function(){return this.id===this._defaultId}}),Y.define=function(e,r){r===t&&(r=e,e=Y);var n,i,a,s,o,u,l,h,d=ge({defaults:{}},r),f={},c=d.id,g=[];if(c&&(d.idField=c),d.id&&delete d.id,c&&(d.defaults[c]=d._defaultId=""),"[object Array]"===Ze.call(d.fields)){for(u=0,l=d.fields.length;u<l;u++)a=d.fields[u],typeof a===Re?f[a]={}:a.field&&(f[a.field]=a);d.fields=f}for(i in d.fields)a=d.fields[i],s=a.type||"default",o=null,h=i,i=typeof a.field===Re?a.field:i,a.nullable||(o=d.defaults[h!==i?h:i]=a.defaultValue!==t?a.defaultValue:X[s.toLowerCase()],"function"==typeof o&&g.push(i)),r.id===i&&(d._defaultId=o),d.defaults[h!==i?h:i]=o,a.parse=a.parse||K[s];return g.length>0&&(d._initializers=g),n=e.extend(d),n.define=function(e){return Y.define(n,e)},d.fields&&(n.fields=d.fields,n.idField=d.idField),n},Z={selector:function(e){return xe(e)?e:He(e)},compare:function(e){var t=this.selector(e);return function(e,r){return e=t(e),r=t(r),null==e&&null==r?0:null==e?-1:null==r?1:e.localeCompare?e.localeCompare(r):e>r?1:e<r?-1:0}},create:function(e){var t=e.compare||this.compare(e.field);return"desc"==e.dir?function(e,r){return t(r,e,!0)}:t},combine:function(e){return function(t,r){var n,i,a=e[0](t,r);for(n=1,i=e.length;n<i;n++)a=a||e[n](t,r);return a}}},ee=ge({},Z,{asc:function(e){var t=this.selector(e);return function(e,r){var n=t(e),i=t(r);return n&&n.getTime&&i&&i.getTime&&(n=n.getTime(),i=i.getTime()),n===i?e.__position-r.__position:null==n?-1:null==i?1:n.localeCompare?n.localeCompare(i):n>i?1:-1}},desc:function(e){var t=this.selector(e);return function(e,r){var n=t(e),i=t(r);return n&&n.getTime&&i&&i.getTime&&(n=n.getTime(),i=i.getTime()),n===i?e.__position-r.__position:null==n?1:null==i?-1:i.localeCompare?i.localeCompare(n):n<i?1:-1}},create:function(e){return this[e.dir](e.field)}}),Q=function(e,t){var r,n=e.length,i=Array(n);for(r=0;r<n;r++)i[r]=t(e[r],r,e);return i},te=function(){function e(e){return"string"==typeof e&&(e=e.replace(/[\r\n]+/g,"")),JSON.stringify(e)}function t(t){return function(r,n,i,a){return n+="",i&&(r="("+r+" || '').toString()"+(a?".toLocaleLowerCase('"+a+"')":".toLowerCase()"),n=a?n.toLocaleLowerCase(a):n.toLowerCase()),t(r,e(n),i)}}function r(t,r,n,i,a){if(null!=n){if(typeof n===Re){var s=tt.exec(n);s?n=new Date((+s[1])):i?(n=e(a?n.toLocaleLowerCase(a):n.toLowerCase()),r="(("+r+" || '')+'')"+(a?".toLocaleLowerCase('"+a+"')":".toLowerCase()")):n=e(n)}n.getTime&&(r="("+r+"&&"+r+".getTime?"+r+".getTime():"+r+")",n=n.getTime())}return r+" "+t+" "+n}function n(e){var t,r,n,i;for(t="/^",r=!1,n=0;n<e.length;++n){if(i=e.charAt(n),r)t+="\\"+i;else{if("~"==i){r=!0;continue}t+="*"==i?".*":"?"==i?".":".+^$()[]{}|\\/\n\r\u2028\u2029 ".indexOf(i)>=0?"\\"+i:i}r=!1}return t+"$/"}return{quote:function(t){return t&&t.getTime?"new Date("+t.getTime()+")":e(t)},eq:function(e,t,n,i){return r("==",e,t,n,i)},neq:function(e,t,n,i){return r("!=",e,t,n,i)},gt:function(e,t,n){return r(">",e,t,n)},gte:function(e,t,n){return r(">=",e,t,n)},lt:function(e,t,n){return r("<",e,t,n)},lte:function(e,t,n){return r("<=",e,t,n)},startswith:t(function(e,t){return e+".lastIndexOf("+t+", 0) == 0"}),doesnotstartwith:t(function(e,t){return e+".lastIndexOf("+t+", 0) == -1"}),endswith:t(function(e,t){var r=t?t.length-2:0;return e+".indexOf("+t+", "+e+".length - "+r+") >= 0"}),doesnotendwith:t(function(e,t){var r=t?t.length-2:0;return e+".indexOf("+t+", "+e+".length - "+r+") < 0"}),contains:t(function(e,t){return e+".indexOf("+t+") >= 0"}),doesnotcontain:t(function(e,t){return e+".indexOf("+t+") == -1"}),matches:t(function(e,t){return t=t.substring(1,t.length-1),n(t)+".test("+e+")"}),doesnotmatch:t(function(e,t){return t=t.substring(1,t.length-1),"!"+n(t)+".test("+e+")"}),isempty:function(e){return e+" === ''"},isnotempty:function(e){return e+" !== ''"},isnull:function(e){return"("+e+" == null)"},isnotnull:function(e){return"("+e+" != null)"},isnullorempty:function(e){return"("+e+" === null) || ("+e+" === '')"},isnotnullorempty:function(e){return"("+e+" !== null) && ("+e+" !== '')"}}}(),a.filterExpr=function(e){var r,n,i,s,o,u,l=[],h={and:" && ",or:" || "},d=[],f=[],c=e.filters;for(r=0,n=c.length;r<n;r++)i=c[r],o=i.field,u=i.operator,i.filters?(s=a.filterExpr(i),i=s.expression.replace(/__o\[(\d+)\]/g,function(e,t){return t=+t,"__o["+(f.length+t)+"]"}).replace(/__f\[(\d+)\]/g,function(e,t){return t=+t,"__f["+(d.length+t)+"]"}),f.push.apply(f,s.operators),d.push.apply(d,s.fields)):(typeof o===De?(s="__f["+d.length+"](d)",d.push(o)):s=ke.expr(o),typeof u===De?(i="__o["+f.length+"]("+s+", "+te.quote(i.value)+")",f.push(u)):i=te[(u||"eq").toLowerCase()](s,i.value,i.ignoreCase===t||i.ignoreCase,e.accentFoldingFiltering)),l.push(i);return{expression:"("+l.join(h[e.logic])+")",fields:d,operators:f}},re={"==":"eq",equals:"eq",isequalto:"eq",equalto:"eq",equal:"eq","!=":"neq",ne:"neq",notequals:"neq",isnotequalto:"neq",notequalto:"neq",notequal:"neq","<":"lt",islessthan:"lt",lessthan:"lt",less:"lt","<=":"lte",le:"lte",islessthanorequalto:"lte",lessthanequal:"lte",">":"gt",isgreaterthan:"gt",greaterthan:"gt",greater:"gt",">=":"gte",isgreaterthanorequalto:"gte",greaterthanequal:"gte",ge:"gte",notsubstringof:"doesnotcontain",isnull:"isnull",isempty:"isempty",isnotempty:"isnotempty"},a.normalizeFilter=u,a.compareFilters=f,a.prototype={toArray:function(){return this.data},range:function(e,t){return new a(this.data.slice(e,e+t))},skip:function(e){return new a(this.data.slice(e))},take:function(e){return new a(this.data.slice(0,e))},select:function(e){return new a(Q(this.data,e))},order:function(e,t,r){var n={dir:t};return e&&(e.compare?n.compare=e.compare:n.field=e),new a(r?this.data.sort(Z.create(n)):this.data.slice(0).sort(Z.create(n)))},orderBy:function(e,t){return this.order(e,"asc",t)},orderByDescending:function(e,t){return this.order(e,"desc",t)},sort:function(e,t,r,n){var i,a,o=s(e,t),u=[];if(r=r||Z,o.length){for(i=0,a=o.length;i<a;i++)u.push(r.create(o[i]));return this.orderBy({compare:r.combine(u)},n)}return this},filter:function(e){var t,r,n,i,s,o,l,h,d=this.data,f=[];if(e=u(e),!e||0===e.filters.length)return this;for(i=a.filterExpr(e),o=i.fields,l=i.operators,s=h=Function("d, __f, __o","return "+i.expression),(o.length||l.length)&&(h=function(e){return s(e,o,l)}),t=0,n=d.length;t<n;t++)r=d[t],h(r)&&f.push(r);return new a(f)},group:function(e,t){e=g(e||[]),t=t||this.data;var r,n=this,i=new a(n.data);return e.length>0&&(r=e[0],i=i.groupBy(r).select(function(n){var i=new a(t).filter([{field:n.field,operator:"eq",value:n.value,ignoreCase:!1}]);return{field:n.field,value:n.value,items:e.length>1?new a(n.items).group(e.slice(1),i.toArray()).toArray():n.items,hasSubgroups:e.length>1,aggregates:i.aggregate(r.aggregates)}})),i},groupBy:function(e){var t,r,n,i,s,o,u,l,h,d,f=this;if(ve(e)||!this.data.length)return new a([]);for(t=e.field,r=e.skipItemSorting?this.data:this._sortForGrouping(t,e.dir||"asc"),n=ke.accessor(t),s=n.get(r[0],t),o={field:t,value:s,items:[]},d=[o],l=0,h=r.length;l<h;l++)i=r[l],u=n.get(i,t),v(s,u)||(s=u,o={field:t,value:s,items:[]},d.push(o)),o.items.push(i);return d=f._sortGroups(d,e),new a(d)},_sortForGrouping:function(e,t){var r,n,i=this.data;if(!et){for(r=0,n=i.length;r<n;r++)i[r].__position=r;for(i=new a(i).sort(e,t,ee).toArray(),r=0,n=i.length;r<n;r++)delete i[r].__position;return i}return this.sort(e,t).toArray()},_sortGroups:function(e,t){var r=e;return t&&xe(t.compare)&&(r=new a(r).order({compare:t.compare},t.dir||ze).toArray()),r},aggregate:function(e){var t,r,n={},i={};if(e&&e.length)for(t=0,r=this.data.length;t<r;t++)m(n,e,this.data[t],t,r,i);return n}},ne={sum:function(e,t,r){var n=r.get(t);return y(e)?y(n)&&(e+=n):e=n,e},count:function(e){return(e||0)+1},average:function(e,r,n,i,a,s){var o=n.get(r);return s.count===t&&(s.count=0),y(e)?y(o)&&(e+=o):e=o,y(o)&&s.count++,i==a-1&&y(e)&&(e/=s.count),e},max:function(e,t,r){var n=r.get(t);return y(e)||S(e)||(e=n),e<n&&(y(n)||S(n))&&(e=n),e},min:function(e,t,r){var n=r.get(t);return y(e)||S(e)||(e=n),e>n&&(y(n)||S(n))&&(e=n),e}},a.normalizeGroup=g,a.normalizeSort=s,a.process=function(e,r,n){var i,o,u,l,h,d,f,c,v,m,y,S;return r=r||{},i=r.group,o=_(g(i||[])),u=new a(e),l=p(i||[]),h=s(r.sort||[]),d=o?h:l.concat(h),v=r.filterCallback,m=r.filter,y=r.skip,S=r.take,d&&n&&(u=u.sort(d,t,t,n)),m&&(u=u.filter(m),v&&(u=v(u)),c=u.toArray().length),d&&!n&&(u=u.sort(d),i&&(e=u.toArray())),o?(u=u.group(i,e),y!==t&&S!==t&&(u=new a(z(u.toArray())).range(y,S),f=Q(l,function(e){return ge({},e,{skipItemSorting:!0})}),u=u.group(f,e))):(y!==t&&S!==t&&(u=u.range(y,S)),i&&(u=u.group(i,e))),{total:c,data:u.toArray()}},ie=qe.extend({init:function(e){this.data=e.data},read:function(e){e.success(this.data)},update:function(e){e.success(e.data)},create:function(e){e.success(e.data)},destroy:function(e){e.success(e.data)}}),ae=qe.extend({init:function(e){var t,r=this;e=r.options=ge({},r.options,e),be(je,function(t,r){typeof e[r]===Re&&(e[r]={url:e[r]})}),r.cache=e.cache?se.create(e.cache):{find:we,add:we},t=e.parameterMap,e.submit&&(r.submit=e.submit),xe(e.push)&&(r.push=e.push),r.push||(r.push=Be),r.parameterMap=xe(t)?t:function(e){var r={};return be(e,function(e,n){e in t&&(e=t[e],_e(e)&&(n=e.value(n),e=e.key)),r[e]=n}),r}},options:{parameterMap:Be},create:function(e){return Se(this.setup(e,Ce))},read:function(r){var n,i,a,s=this,o=s.cache;r=s.setup(r,Oe),n=r.success||we,i=r.error||we,a=o.find(r.data),a!==t?n(a):(r.success=function(e){o.add(r.data,e),n(e)},e.ajax(r))},update:function(e){return Se(this.setup(e,Pe))},destroy:function(e){return Se(this.setup(e,Te))},setup:function(e,t){e=e||{};var r,n=this,i=n.options[t],a=xe(i.data)?i.data(e.data):i.data;return e=ge(!0,{},i,e),r=ge(!0,{},a,e.data),e.data=n.parameterMap(r,t),xe(e.url)&&(e.url=e.url(r)),e}}),se=qe.extend({init:function(){this._store={}},add:function(e,r){e!==t&&(this._store[Ue(e)]=r)},find:function(e){return this._store[Ue(e)]},clear:function(){this._store={}},remove:function(e){delete this._store[Ue(e)]}}),se.create=function(e){var t={inmemory:function(){return new se}};return _e(e)&&xe(e.find)?e:e===!0?new se:t[e]()},oe=qe.extend({init:function(e){var t,r,n,i,a,s,o,u,l,h,d,f,c,g,p=this;e=e||{};for(t in e)r=e[t],p[t]=typeof r===Re?He(r):r;i=e.modelBase||Y,_e(p.model)&&(p.model=n=i.define(p.model)),a=pe(p.data,p),p._dataAccessFunction=a,p.model&&(s=pe(p.groups,p),o=pe(p.serialize,p),u={},l={},h={},d={},f=!1,n=p.model,n.fields&&(be(n.fields,function(e,t){var r;c=e,_e(t)&&t.field?c=t.field:typeof t===Re&&(c=t),_e(t)&&t.from&&(r=t.from),f=f||r&&r!==e||c!==e,g=r||c,l[e]=g.indexOf(".")!==-1?He(g,!0):He(g),h[e]=He(e),u[r||c]=e,d[e]=r||c}),!e.serialize&&f&&(p.serialize=F(o,n,w,h,u,d))),p._dataAccessFunction=a,p._wrapDataAccessBase=q(n,k,l,u,d),p.data=F(a,n,k,l,u,d),p.groups=F(s,n,x,l,u,d))},errors:function(e){return e?e.errors:null},parse:Be,data:Be,total:function(e){return e.length},groups:Be,aggregates:function(){return{}},serialize:function(e){return e}}),ue=Fe.extend({init:function(e){var r,n,i,a=this;e&&(n=e.data),e=a.options=ge({},a.options,e),a._map={},a._prefetch={},a._data=[],a._pristineData=[],a._ranges=[],a._view=[],a._pristineTotal=0,a._destroyed=[],a._pageSize=e.pageSize,a._page=e.page||(e.pageSize?1:t),a._sort=s(e.sort),a._filter=u(e.filter),a._group=g(e.group),a._aggregate=e.aggregate,a._total=e.total,a._shouldDetachObservableParents=!0,Fe.fn.init.call(a),a.transport=le.create(e,n,a),xe(a.transport.push)&&a.transport.push({pushCreate:pe(a._pushCreate,a),pushUpdate:pe(a._pushUpdate,a),pushDestroy:pe(a._pushDestroy,a)}),null!=e.offlineStorage&&("string"==typeof e.offlineStorage?(i=e.offlineStorage,a._storage={getItem:function(){return JSON.parse(localStorage.getItem(i))},setItem:function(e){localStorage.setItem(i,Ue(a.reader.serialize(e)))}}):a._storage=e.offlineStorage),a.reader=new ke.data.readers[e.schema.type||"json"](e.schema),r=a.reader.model||{},a._detachObservableParents(),a._data=a._observe(a._data),a._online=!0,a.bind(["push",Ne,Ae,Ge,Ie,Le,Ee],e)},options:{data:null,schema:{modelBase:Y},offlineStorage:null,serverSorting:!1,serverPaging:!1,serverFiltering:!1,serverGrouping:!1,serverAggregates:!1,batch:!1,inPlaceSort:!1},clone:function(){return this},online:function(r){return r!==t?this._online!=r&&(this._online=r,r)?this.sync():e.Deferred().resolve().promise():this._online},offlineData:function(e){return null==this.options.offlineStorage?null:e!==t?this._storage.setItem(e):this._storage.getItem()||[]},_isServerGrouped:function(){var e=this.group()||[];return this.options.serverGrouping&&e.length},_pushCreate:function(e){this._push(e,"pushCreate")},_pushUpdate:function(e){this._push(e,"pushUpdate")},_pushDestroy:function(e){this._push(e,"pushDestroy")},_push:function(e,t){var r=this._readData(e);r||(r=e),this[t](r)},_flatData:function(e,t){if(e){if(this._isServerGrouped())return C(e);if(!t)for(var r=0;r<e.length;r++)e.at(r)}return e},parent:we,get:function(e){var t,r,n=this._flatData(this._data,this.options.useRanges);for(t=0,r=n.length;t<r;t++)if(n[t].id==e)return n[t]},getByUid:function(e){return this._getByUid(e,this._data)},_getByUid:function(e,t){var r,n,i=this._flatData(t,this.options.useRanges);if(i)for(r=0,n=i.length;r<n;r++)if(i[r].uid==e)return i[r]},indexOf:function(e){return G(this._data,e)},at:function(e){return this._data.at(e)},data:function(e){var r,n=this;if(e===t){if(n._data)for(r=0;r<n._data.length;r++)n._data.at(r);return n._data}n._detachObservableParents(),n._data=this._observe(e),n._pristineData=e.slice(0),n._storeData(),n._ranges=[],n.trigger("reset"),n._addRange(n._data),n._total=n._data.length,n._pristineTotal=n._total,n._process(n._data)},view:function(e){return e===t?this._view:(this._view=this._observeView(e),t)},_observeView:function(e){var t,r=this;return I(e,r._data,r._ranges,r.reader.model||$,r._isServerGrouped()),t=new W(e,r.reader.model),t.parent=function(){return r.parent()},t},flatView:function(){var e=this.group()||[];return e.length?C(this._view):this._view},add:function(e){return this.insert(this._data.length,e)},_createNewModel:function(e){return this.reader.model?new this.reader.model(e):e instanceof $?e:new $(e)},insert:function(e,t){return t||(t=e,e=0),t instanceof Y||(t=this._createNewModel(t)),this._isServerGrouped()?this._data.splice(e,0,this._wrapInEmptyGroup(t)):this._data.splice(e,0,t),this._insertModelInRange(e,t),t},pushInsert:function(t,r){var n,i,a,s,o,u,l=this,h=l._getCurrentRangeSpan();r||(r=t,t=0),me(r)||(r=[r]),n=[],i=this.options.autoSync,this.options.autoSync=!1;try{for(a=0;a<r.length;a++)s=r[a],o=this.insert(t,s),n.push(o),u=o.toJSON(),this._isServerGrouped()&&(u=this._wrapInEmptyGroup(u)),this._pristineData.push(u),h&&h.length&&e(h).last()[0].pristineData.push(u),t++}finally{this.options.autoSync=i}n.length&&this.trigger("push",{type:"create",items:n})},pushCreate:function(e){this.pushInsert(this._data.length,e)},pushUpdate:function(e){var t,r,n,i,a;for(me(e)||(e=[e]),t=[],r=0;r<e.length;r++)n=e[r],i=this._createNewModel(n),a=this.get(i.id),a?(t.push(a),a.accept(n),a.trigger(Ae),this._updatePristineForModel(a,n)):this.pushCreate(n);t.length&&this.trigger("push",{type:"update",items:t})},pushDestroy:function(e){var t=this._removeItems(e);t.length&&this.trigger("push",{type:"destroy",items:t})},_removeItems:function(e,r){var n,i,a,s,o,u,l;me(e)||(e=[e]),n=t===r||r,i=[],a=this.options.autoSync,this.options.autoSync=!1;try{for(s=0;s<e.length;s++)o=e[s],u=this._createNewModel(o),l=!1,this._eachItem(this._data,function(e){var t,r;for(t=0;t<e.length;t++)if(r=e.at(t),r.id===u.id){i.push(r),e.splice(t,1),l=!0;break}}),l&&n&&(this._removePristineForModel(u),this._destroyed.pop())}finally{this.options.autoSync=a}return i},remove:function(e){var t,r=this,n=r._isServerGrouped();return this._eachItem(r._data,function(i){if(t=M(i,e),t&&n)return t.isNew&&t.isNew()||r._destroyed.push(t),!0}),this._removeModelFromRanges(e),e},destroyed:function(){return this._destroyed},created:function(){var e,t,r=[],n=this._flatData(this._data,this.options.useRanges);for(e=0,t=n.length;e<t;e++)n[e].isNew&&n[e].isNew()&&r.push(n[e]);return r},updated:function(){var e,t,r=[],n=this._flatData(this._data,this.options.useRanges);for(e=0,t=n.length;e<t;e++)n[e].isNew&&!n[e].isNew()&&n[e].dirty&&r.push(n[e]);return r},sync:function(){var t,r=this,n=[],i=[],a=r._destroyed,s=e.Deferred().resolve().promise();if(r.online()){if(!r.reader.model)return s;n=r.created(),i=r.updated(),t=[],r.options.batch&&r.transport.submit?t=r._sendSubmit(n,i,a):(t.push.apply(t,r._send("create",n)),t.push.apply(t,r._send("update",i)),t.push.apply(t,r._send("destroy",a))),s=e.when.apply(null,t).then(function(){var e,t;for(e=0,t=arguments.length;e<t;e++)arguments[e]&&r._accept(arguments[e]);r._storeData(!0),r._syncEnd(),r._change({action:"sync"}),r.trigger(Ie)})}else r._storeData(!0),r._syncEnd(),r._change({action:"sync"});return s},_syncEnd:we,cancelChanges:function(e){var t=this;e instanceof ke.data.Model?t._cancelModel(e):(t._destroyed=[],t._detachObservableParents(),t._data=t._observe(t._pristineData),t.options.serverPaging&&(t._total=t._pristineTotal),t._ranges=[],t._addRange(t._data,0),t._changesCanceled(),
t._change(),t._markOfflineUpdatesAsDirty())},_changesCanceled:we,_markOfflineUpdatesAsDirty:function(){var e=this;null!=e.options.offlineStorage&&e._eachItem(e._data,function(e){var t,r;for(t=0;t<e.length;t++)r=e.at(t),"update"!=r.__state__&&"create"!=r.__state__||(r.dirty=!0)})},hasChanges:function(){var e,t,r=this._flatData(this._data,this.options.useRanges);if(this._destroyed.length)return!0;for(e=0,t=r.length;e<t;e++)if(r[e].isNew&&r[e].isNew()||r[e].dirty)return!0;return!1},_accept:function(t){var r,n=this,i=t.models,a=t.response,s=0,o=n._isServerGrouped(),u=n._pristineData,l=t.type;if(n.trigger(Le,{response:a,type:l}),a&&!ve(a)){if(a=n.reader.parse(a),n._handleCustomErrors(a))return;a=n.reader.data(a),me(a)||(a=[a])}else a=e.map(i,function(e){return e.toJSON()});for("destroy"===l&&(n._destroyed=[]),s=0,r=i.length;s<r;s++)"destroy"!==l?(i[s].accept(a[s]),"create"===l?u.push(o?n._wrapInEmptyGroup(i[s].toJSON()):a[s]):"update"===l&&n._updatePristineForModel(i[s],a[s])):n._removePristineForModel(i[s])},_updatePristineForModel:function(e,t){this._executeOnPristineForModel(e,function(e,r){ke.deepExtend(r[e],t)})},_executeOnPristineForModel:function(e,t){this._eachPristineItem(function(r){var n=N(r,e);if(n>-1)return t(n,r),!0})},_removePristineForModel:function(e){this._executeOnPristineForModel(e,function(e,t){t.splice(e,1)})},_readData:function(e){var t=this._isServerGrouped()?this.reader.groups:this.reader.data;return t.call(this.reader,e)},_eachPristineItem:function(e){var t=this,r=t.options,n=t._getCurrentRangeSpan();t._eachItem(t._pristineData,e),r.serverPaging&&r.useRanges&&be(n,function(r,n){t._eachItem(n.pristineData,e)})},_eachItem:function(e,t){e&&e.length&&(this._isServerGrouped()?P(e,t):t(e))},_pristineForModel:function(e){var t,r,n=function(n){if(r=N(n,e),r>-1)return t=n[r],!0};return this._eachPristineItem(n),t},_cancelModel:function(e){var t=this,r=this._pristineForModel(e);this._eachItem(this._data,function(n){var i=G(n,e);i>=0&&(!r||e.isNew()&&!r.__state__?(t._modelCanceled(e),n.splice(i,1),t._removeModelFromRanges(e)):(n[i].accept(r),"update"==r.__state__&&(n[i].dirty=!0)))})},_modelCanceled:we,_submit:function(t,r){var n=this;n.trigger(Ge,{type:"submit"}),n.trigger(Ee),n.transport.submit(ge({success:function(r,n){var i=e.grep(t,function(e){return e.type==n})[0];i&&i.resolve({response:r,models:i.models,type:n})},error:function(e,r,i){for(var a=0;a<t.length;a++)t[a].reject(e);n.error(e,r,i)}},r))},_sendSubmit:function(t,r,n){var i=this,a=[];return i.options.batch&&(t.length&&a.push(e.Deferred(function(e){e.type="create",e.models=t})),r.length&&a.push(e.Deferred(function(e){e.type="update",e.models=r})),n.length&&a.push(e.Deferred(function(e){e.type="destroy",e.models=n})),i._submit(a,{data:{created:i.reader.serialize(b(t)),updated:i.reader.serialize(b(r)),destroyed:i.reader.serialize(b(n))}})),a},_promise:function(t,r,n){var i=this;return e.Deferred(function(e){i.trigger(Ge,{type:n}),i.trigger(Ee),i.transport[n].call(i.transport,ge({success:function(t){e.resolve({response:t,models:r,type:n})},error:function(t,r,n){e.reject(t),i.error(t,r,n)}},t))}).promise()},_send:function(e,t){var r,n,i=this,a=[],s=i.reader.serialize(b(t));if(i.options.batch)t.length&&a.push(i._promise({data:{models:s}},t,e));else for(r=0,n=t.length;r<n;r++)a.push(i._promise({data:s[r]},[t[r]],e));return a},read:function(t){var r=this,n=r._params(t),i=e.Deferred();return r._queueRequest(n,function(){var e=r.trigger(Ge,{type:"read"});e?(r._dequeueRequest(),i.resolve(e)):(r.trigger(Ee),r._ranges=[],r.trigger("reset"),r.online()?r.transport.read({data:n,success:function(e){r._ranges=[],r.success(e,n),i.resolve()},error:function(){var e=Xe.call(arguments);r.error.apply(r,e),i.reject.apply(i,e)}}):null!=r.options.offlineStorage&&(r.success(r.offlineData(),n),i.resolve()))}),i.promise()},_readAggregates:function(e){return this.reader.aggregates(e)},success:function(e){var r,n,i,a,s,o,u,l,h,d,f,c=this,g=c.options;if(c.trigger(Le,{response:e,type:"read"}),c.online()){if(e=c.reader.parse(e),c._handleCustomErrors(e))return c._dequeueRequest(),t;c._total=c.reader.total(e),c._pageSize>c._total&&(c._pageSize=c._total,c.options.pageSize&&c.options.pageSize>c._pageSize&&(c._pageSize=c.options.pageSize)),c._aggregate&&g.serverAggregates&&(c._aggregateResult=c._readAggregates(e)),e=c._readData(e),c._destroyed=[]}else{for(e=c._readData(e),r=[],i={},a=c.reader.model,s=a?a.idField:"id",o=0;o<this._destroyed.length;o++)u=this._destroyed[o][s],i[u]=u;for(o=0;o<e.length;o++)l=e[o],h=l.__state__,"destroy"==h?i[l[s]]||this._destroyed.push(this._createNewModel(l)):r.push(l);e=r,c._total=e.length}if(c._pristineTotal=c._total,n=c._skip&&c._data.length&&c._skip<c._data.length,c.options.endless)for(n&&c._pristineData.splice(c._skip,c._pristineData.length),r=e.slice(0),d=0;d<r.length;d++)c._pristineData.push(r[d]);else c._pristineData=e.slice(0);if(c._detachObservableParents(),c.options.endless){for(c._data.unbind(Ae,c._changeHandler),c._isServerGrouped()&&c._data[c._data.length-1].value===e[0].value&&(R(c._data[c._data.length-1],e[0]),e.shift()),e=c._observe(e),n&&c._data.splice(c._skip,c._data.length),f=0;f<e.length;f++)c._data.push(e[f]);c._data.bind(Ae,c._changeHandler)}else c._data=c._observe(e);c._markOfflineUpdatesAsDirty(),c._storeData(),c._addRange(c._data),c._process(c._data),c._dequeueRequest()},_detachObservableParents:function(){if(this._data&&this._shouldDetachObservableParents)for(var e=0;e<this._data.length;e++)this._data[e].parent&&(this._data[e].parent=we)},_storeData:function(e){function t(e){var r,n,i,a=[];for(r=0;r<e.length;r++)n=e.at(r),i=n.toJSON(),s&&n.items?i.items=t(n.items):(i.uid=n.uid,o&&(n.isNew()?i.__state__="create":n.dirty&&(i.__state__="update"))),a.push(i);return a}var r,n,i,a,s=this._isServerGrouped(),o=this.reader.model;if(null!=this.options.offlineStorage){for(r=t(this._data),n=[],i=0;i<this._destroyed.length;i++)a=this._destroyed[i].toJSON(),a.__state__="destroy",n.push(a);this.offlineData(r.concat(n)),e&&(this._pristineData=this.reader.reader?this.reader.reader._wrapDataAccessBase(r):this.reader._wrapDataAccessBase(r))}},_addRange:function(e,r){var n=this,i=t!==r?r:n._skip||0,a=i+n._flatData(e,!0).length;n._ranges.push({start:i,end:a,data:e,pristineData:e.toJSON(),timestamp:n._timeStamp()}),n._sortRanges()},_sortRanges:function(){this._ranges.sort(function(e,t){return e.start-t.start})},error:function(e,t,r){this._dequeueRequest(),this.trigger(Le,{}),this.trigger(Ne,{xhr:e,status:t,errorThrown:r})},_params:function(e){var t=this,r=ge({take:t.take(),skip:t.skip(),page:t.page(),pageSize:t.pageSize(),sort:t._sort,filter:t._filter,group:t._group,aggregate:t._aggregate},e);return t.options.serverPaging||(delete r.take,delete r.skip,delete r.page,delete r.pageSize),t.options.serverGrouping?t.reader.model&&r.group&&(r.group=B(r.group,t.reader.model)):delete r.group,t.options.serverFiltering?t.reader.model&&r.filter&&(r.filter=j(r.filter,t.reader.model)):delete r.filter,t.options.serverSorting?t.reader.model&&r.sort&&(r.sort=B(r.sort,t.reader.model)):delete r.sort,t.options.serverAggregates?t.reader.model&&r.aggregate&&(r.aggregate=B(r.aggregate,t.reader.model)):delete r.aggregate,r},_queueRequest:function(e,r){var n=this;n._requestInProgress?n._pending={callback:pe(r,n),options:e}:(n._requestInProgress=!0,n._pending=t,r())},_dequeueRequest:function(){var e=this;e._requestInProgress=!1,e._pending&&e._queueRequest(e._pending.options,e._pending.callback)},_handleCustomErrors:function(e){if(this.reader.errors){var t=this.reader.errors(e);if(t)return this.trigger(Ne,{xhr:null,status:"customerror",errorThrown:"custom error",errors:t}),!0}return!1},_shouldWrap:function(e){var t=this.reader.model;return!(!t||!e.length)&&!(e[0]instanceof t)},_observe:function(e){var t,r=this,n=r.reader.model;return r._shouldDetachObservableParents=!0,e instanceof rt?(r._shouldDetachObservableParents=!1,r._shouldWrap(e)&&(e.type=r.reader.model,e.wrapAll(e,e))):(t=r.pageSize()&&!r.options.serverPaging?W:rt,e=new t(e,r.reader.model),e.parent=function(){return r.parent()}),r._isServerGrouped()&&O(e,n),!(r._changeHandler&&r._data&&r._data instanceof rt)||r.options.useRanges&&r.options.serverPaging?r._changeHandler=pe(r._change,r):r._data.unbind(Ae,r._changeHandler),e.bind(Ae,r._changeHandler)},_updateTotalForAction:function(e,t){var r=this,n=parseInt(r._total,10);y(r._total)||(n=parseInt(r._pristineTotal,10)),"add"===e?n+=t.length:"remove"===e?n-=t.length:"itemchange"===e||"sync"===e||r.options.serverPaging?"sync"===e&&(n=r._pristineTotal=parseInt(r._total,10)):n=r._pristineTotal,r._total=n},_change:function(e){var t,r,n,i=this,a=e?e.action:"";if("remove"===a)for(t=0,r=e.items.length;t<r;t++)e.items[t].isNew&&e.items[t].isNew()||i._destroyed.push(e.items[t]);!i.options.autoSync||"add"!==a&&"remove"!==a&&"itemchange"!==a?(i._updateTotalForAction(a,e?e.items:[]),i._process(i._data,e)):(n=function(t){"sync"===t.action&&(i.unbind("change",n),i._updateTotalForAction(a,e.items))},i.first("change",n),i.sync())},_calculateAggregates:function(e,t){t=t||{};var r=new a(e),n=t.aggregate,i=t.filter;return i&&(r=r.filter(i)),r.aggregate(n)},_process:function(e,r){var n,i=this,a={};i.options.serverPaging!==!0&&(a.skip=i._skip,a.take=i._take||i._pageSize,a.skip===t&&i._page!==t&&i._pageSize!==t&&(a.skip=(i._page-1)*i._pageSize),i.options.useRanges&&(a.skip=i.currentRangeStart())),i.options.serverSorting!==!0&&(a.sort=i._sort),i.options.serverFiltering!==!0&&(a.filter=i._filter),i.options.serverGrouping!==!0&&(a.group=i._group),i.options.serverAggregates!==!0&&(a.aggregate=i._aggregate),i.options.serverGrouping&&i._clearEmptyGroups(e),n=i._queryProcess(e,a),i.options.serverAggregates!==!0&&(i._aggregateResult=i._calculateAggregates(n.dataToAggregate||e,a)),i.view(n.data),i._setFilterTotal(n.total,!1),r=r||{},r.items=r.items||i._view,i.trigger(Ae,r)},_clearEmptyGroups:function(e){var t,r;for(t=e.length-1;t>=0;t--)r=e[t],r.hasSubgroups?this._clearEmptyGroups(r.items):r.items&&!r.items.length&&$e.apply(r.parent(),[t,1])},_queryProcess:function(e,t){return this.options.inPlaceSort?a.process(e,t,this.options.inPlaceSort):a.process(e,t)},_mergeState:function(r){var n=this;return r!==t&&(n._pageSize=r.pageSize,n._page=r.page,n._sort=r.sort,n._filter=r.filter,n._group=r.group,n._aggregate=r.aggregate,n._skip=n._currentRangeStart=r.skip,n._take=r.take,n._skip===t&&(n._skip=n._currentRangeStart=n.skip(),r.skip=n.skip()),n._take===t&&n._pageSize!==t&&(n._take=n._pageSize,r.take=n._take),r.sort&&(n._sort=r.sort=s(r.sort)),r.filter&&(n._filter=r.filter=n.options.accentFoldingFiltering&&!e.isEmptyObject(r.filter)?e.extend({},u(r.filter),{accentFoldingFiltering:n.options.accentFoldingFiltering}):u(r.filter)),r.group&&(n._group=r.group=g(r.group)),r.aggregate&&(n._aggregate=r.aggregate=c(r.aggregate))),r},query:function(r){var n,i,a,s=this.options.serverSorting||this.options.serverPaging||this.options.serverFiltering||this.options.serverGrouping||this.options.serverAggregates;return s||(this._data===t||0===this._data.length)&&!this._destroyed.length?(this.options.endless&&(i=r.pageSize-this.pageSize(),i>0?(i=this.pageSize(),r.page=r.pageSize/i,r.pageSize=i):(r.page=1,this.options.endless=!1)),this.read(this._mergeState(r))):(a=this.trigger(Ge,{type:"read"}),a||(this.trigger(Ee),n=this._queryProcess(this._data,this._mergeState(r)),this._setFilterTotal(n.total,!0),this._aggregateResult=this._calculateAggregates(n.dataToAggregate||this._data,r),this.view(n.data),this.trigger(Le,{type:"read"}),this.trigger(Ae,{items:n.data})),e.Deferred().resolve(a).promise())},_setFilterTotal:function(e,r){var n=this;n.options.serverFiltering||(e!==t?n._total=e:r&&(n._total=n._data.length))},fetch:function(e){var t=this,r=function(r){r!==!0&&xe(e)&&e.call(t)};return this._query().done(r)},_query:function(e){var t=this;return t.query(ge({},{page:t.page(),pageSize:t.pageSize(),sort:t.sort(),filter:t.filter(),group:t.group(),aggregate:t.aggregate()},e))},next:function(e){var t=this,r=t.page(),n=t.total();if(e=e||{},r&&!(n&&r+1>t.totalPages()))return t._skip=t._currentRangeStart=r*t.take(),r+=1,e.page=r,t._query(e),r},prev:function(e){var t=this,r=t.page();if(e=e||{},r&&1!==r)return t._skip=t._currentRangeStart=t._skip-t.take(),r-=1,e.page=r,t._query(e),r},page:function(e){var r,n=this;return e!==t?(e=Je.max(Je.min(Je.max(e,1),n.totalPages()),1),n._query(n._pageableQueryOptions({page:e})),t):(r=n.skip(),r!==t?Je.round((r||0)/(n.take()||1))+1:t)},pageSize:function(e){var r=this;return e!==t?(r._query(r._pageableQueryOptions({pageSize:e,page:1})),t):r.take()},sort:function(e){var r=this;return e!==t?(r._query({sort:e}),t):r._sort},filter:function(e){var r=this;return e===t?r._filter:(r.trigger("reset"),r._query({filter:e,page:1}),t)},group:function(e){var r=this;return e!==t?(r._query({group:e}),t):r._group},total:function(){return parseInt(this._total||0,10)},aggregate:function(e){var r=this;return e!==t?(r._query({aggregate:e}),t):r._aggregate},aggregates:function(){var e=this._aggregateResult;return ve(e)&&(e=this._emptyAggregates(this.aggregate())),e},_emptyAggregates:function(e){var t,r,n={};if(!ve(e))for(t={},me(e)||(e=[e]),r=0;r<e.length;r++)t[e[r].aggregate]=0,n[e[r].field]=t;return n},_pageableQueryOptions:function(e){return e},_wrapInEmptyGroup:function(e){var t,r,n,i,a=this.group();for(n=a.length-1,i=0;n>=i;n--)r=a[n],t={value:e.get?e.get(r.field):e[r.field],field:r.field,items:t?[t]:[e],hasSubgroups:!!t,aggregates:this._emptyAggregates(r.aggregates)};return t},totalPages:function(){var e=this,t=e.pageSize()||e.total();return Je.ceil((e.total()||0)/t)},inRange:function(e,t){var r=this,n=Je.min(e+t,r.total());return!r.options.serverPaging&&r._data.length>0||r._findRange(e,n).length>0},lastRange:function(){var e=this._ranges;return e[e.length-1]||{start:0,end:0,data:[]}},firstItemUid:function(){var e=this._ranges;return e.length&&e[0].data.length&&e[0].data[0].uid},enableRequestsInProgress:function(){this._skipRequestsInProgress=!1},_timeStamp:function(){return(new Date).getTime()},range:function(e,r,n){this._currentRequestTimeStamp=this._timeStamp(),this._skipRequestsInProgress=!0,e=Je.min(e||0,this.total()),n=xe(n)?n:we;var i,a=this,s=Je.max(Je.floor(e/r),0)*r,o=Je.min(s+r,a.total());return i=a._findRange(e,Je.min(e+r,a.total())),i.length||0===a.total()?(a._processRangeData(i,e,r,s,o),n(),t):(r!==t&&(a._rangeExists(s,o)?s<e&&a.prefetch(o,r,function(){a.range(e,r,n)}):a.prefetch(s,r,function(){e>s&&o<a.total()&&!a._rangeExists(o,Je.min(o+r,a.total()))?a.prefetch(o,r,function(){a.range(e,r,n)}):a.range(e,r,n)})),t)},_findRange:function(e,r){var n,i,a,o,u,l,h,d,f,c,g,_,v=this,m=v._ranges,y=[],S=v.options,b=S.serverSorting||S.serverPaging||S.serverFiltering||S.serverGrouping||S.serverAggregates;for(i=0,g=m.length;i<g;i++)if(n=m[i],e>=n.start&&e<=n.end){for(c=0,a=i;a<g;a++)if(n=m[a],f=v._flatData(n.data,!0),f.length&&e+c>=n.start&&(l=n.data,h=n.end,b||(S.inPlaceSort?d=v._queryProcess(n.data,{filter:v.filter()}):(_=p(v.group()||[]).concat(s(v.sort()||[])),d=v._queryProcess(n.data,{sort:_,filter:v.filter()})),f=l=d.data,d.total!==t&&(h=d.total)),o=0,e+c>n.start&&(o=e+c-n.start),u=f.length,h>r&&(u-=h-r),c+=u-o,y=v._mergeGroups(y,l,o,u),r<=n.end&&c==r-e))return y;break}return[]},_mergeGroups:function(e,t,r,n){if(this._isServerGrouped()){var i,a=t.toJSON();return e.length&&(i=e[e.length-1]),D(i,a,r,n),e.concat(a)}return e.concat(t.slice(r,n))},_processRangeData:function(e,r,n,i,a){var s,o,u,l,h=this;h._pending=t,h._skip=r>h.skip()?Je.min(a,(h.totalPages()-1)*h.take()):i,h._currentRangeStart=r,h._take=n,s=h.options.serverPaging,o=h.options.serverSorting,u=h.options.serverFiltering,l=h.options.serverAggregates;try{h.options.serverPaging=!0,h._isServerGrouped()||h.group()&&h.group().length||(h.options.serverSorting=!0),h.options.serverFiltering=!0,h.options.serverPaging=!0,h.options.serverAggregates=!0,s&&(h._detachObservableParents(),h._data=e=h._observe(e)),h._process(e)}finally{h.options.serverPaging=s,h.options.serverSorting=o,h.options.serverFiltering=u,h.options.serverAggregates=l}},skip:function(){var e=this;return e._skip===t?e._page!==t?(e._page-1)*(e.take()||1):t:e._skip},currentRangeStart:function(){return this._currentRangeStart||0},take:function(){return this._take||this._pageSize},_prefetchSuccessHandler:function(e,t,r,n){var i=this,a=i._timeStamp();return function(s){var o,u,l,h=!1,d={start:e,end:t,data:[],timestamp:i._timeStamp()};if(i._dequeueRequest(),i.trigger(Le,{response:s,type:"read"}),s=i.reader.parse(s),l=i._readData(s),l.length){for(o=0,u=i._ranges.length;o<u;o++)if(i._ranges[o].start===e){h=!0,d=i._ranges[o],d.pristineData=l,d.data=i._observe(l),d.end=d.start+i._flatData(d.data,!0).length,i._sortRanges();break}h||i._addRange(i._observe(l),e)}i._total=i.reader.total(s),(n||a>=i._currentRequestTimeStamp||!i._skipRequestsInProgress)&&(r&&l.length?r():i.trigger(Ae,{}))}},prefetch:function(e,t,r){var n=this,i=Je.min(e+t,n.total()),a={take:t,skip:e,page:e/t+1,pageSize:t,sort:n._sort,filter:n._filter,group:n._group,aggregate:n._aggregate};n._rangeExists(e,i)?r&&r():(clearTimeout(n._timeout),n._timeout=setTimeout(function(){n._queueRequest(a,function(){n.trigger(Ge,{type:"read"})?n._dequeueRequest():n.transport.read({data:n._params(a),success:n._prefetchSuccessHandler(e,i,r),error:function(){var e=Xe.call(arguments);n.error.apply(n,e)}})})},100))},_multiplePrefetch:function(e,t,r){var n=this,i=Je.min(e+t,n.total()),a={take:t,skip:e,page:e/t+1,pageSize:t,sort:n._sort,filter:n._filter,group:n._group,aggregate:n._aggregate};n._rangeExists(e,i)?r&&r():n.trigger(Ge,{type:"read"})||n.transport.read({data:n._params(a),success:n._prefetchSuccessHandler(e,i,r,!0)})},_rangeExists:function(e,t){var r,n,i=this,a=i._ranges;for(r=0,n=a.length;r<n;r++)if(a[r].start<=e&&a[r].end>=t)return!0;return!1},_getCurrentRangeSpan:function(){var e,t,r=this,n=r._ranges,i=r.currentRangeStart(),a=i+(r.take()||0),s=[],o=n.length;for(t=0;t<o;t++)e=n[t],