@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
3 lines (2 loc) • 5.84 kB
JavaScript
!function(t){"function"==typeof define&&define.amd?define(["kendo.core.min"],t):t()}((function(){!function(t,e){var n=window.kendo,a=t.extend,o="\r\n",r="\r\n\r\n",s=n.isFunction,i={eq:"eq",neq:"ne",gt:"gt",gte:"ge",lt:"lt",lte:"le",contains:"substringof",doesnotcontain:"substringof",endswith:"endswith",startswith:"startswith",isnull:"eq",isnotnull:"ne",isnullorempty:"eq",isnotnullorempty:"ne",isempty:"eq",isnotempty:"ne"},d=a({},i,{contains:"contains"}),p={pageSize:t.noop,page:t.noop,filter:function(t,e,n){e&&(e=u(e,n))&&(t.$filter=e)},sort:function(e,n){var a=t.map(n,(function(t){var e=t.field.replace(/\./g,"/");return"desc"===t.dir&&(e+=" desc"),e})).join(",");a&&(e.$orderby=a)},skip:function(t,e){e&&(t.$skip=e)},take:function(t,e){e&&(t.$top=e)}},c={read:{dataType:"jsonp"}};function u(t,e){var a,o,r,s,p,c,l,f,y=[],h=t.logic||"and",g=t.filters;for(a=0,o=g.length;a<o;a++)r=(t=g[a]).field,l=t.value,c=t.operator,t.filters?t=u(t,e):(f=t.ignoreCase,r=r.replace(/\./g,"/"),t=i[c],e&&(t=d[c]),"isnullorempty"===c?t=n.format("{0} {1} null or {0} {1} ''",r,t):"isnotnullorempty"===c?t=n.format("{0} {1} null and {0} {1} ''",r,t):"isnull"===c||"isnotnull"===c?t=n.format("{0} {1} null",r,t):"isempty"===c||"isnotempty"===c?t=n.format("{0} {1} ''",r,t):t&&undefined!==l&&("string"===(s=n.type(l))?(p="'{1}'",l=l.replace(/'/g,"''"),!0===f&&(r="tolower("+r+")")):"date"===s?e?(p="{1:yyyy-MM-ddTHH:mm:ss+00:00}",l=n.timezone.apply(l,"Etc/UTC")):p="datetime'{1:yyyy-MM-ddTHH:mm:ss}'":p="{1}",t.length>3?"substringof"!==t?p="{0}({2},"+p+")":(p="{0}("+p+",{2})","doesnotcontain"===c&&(e?(p="{0}({2},'{1}') eq -1",t="indexof"):p+=" eq false")):p="{2} {0} "+p,t=n.format(p,t,l,r))),y.push(t);return t=y.join(" "+h+" "),y.length>1&&(t="("+t+")"),t}function l(t){for(var e in t)0===e.indexOf("@odata")&&delete t[e]}function f(){return Math.floor(65536*(1+Math.random())).toString(16).substr(1)}function y(t){return t+f()+"-"+f()+"-"+f()}function h(t,e){var n="\r\n--"+t;return e&&(n+="--"),n}function g(t,e,a,o){var r=t.options[o].url,i=n.format("{0} ",a);return s(r)?i+r(e):i+r}function m(t,e){var n="";return n+=h(t,!1),n+="\r\nContent-Type: application/http",n+="\r\nContent-Transfer-Encoding: binary",n+="\r\nContent-ID: "+e}function T(t,e,a,s,i,d,p){var c="";return c+=function(t,e){var n="";return n+="--"+t+o,n+="Content-Type: multipart/mixed; boundary="+e+o}(e,a),c+=function(t,e,a,s,i,d){for(var p,c,u="",l=0;l<t.length;l++)u+=m(e,a),u+=r+g(i,t[l],i.options[s].type,s)+" HTTP/1.1",d||(u+=(p=t[l],c=void 0,c="",c+="\r\nContent-Type: application/json;odata=minimalmetadata",c+="\r\nPrefer: return=representation",c+=r+n.stringify(p))),u+=o,a++;return u}(t,a,s,d,i,p),c+=h(a,!0),c+=o}a(!0,n.data,{schemas:{odata:{type:"json",data:function(t){return t.d.results||[t.d]},total:"d.__count"}},transports:{odata:{read:{cache:!0,dataType:"jsonp",jsonp:"$callback"},update:{cache:!0,dataType:"json",contentType:"application/json",type:"PUT"},create:{cache:!0,dataType:"json",contentType:"application/json",type:"POST"},destroy:{cache:!0,dataType:"json",type:"DELETE"},parameterMap:function(t,e,a){var o,r,s,i;if(t=t||{},e=e||"read",i=(i=(this.options||c)[e])?i.dataType:"json","read"===e)for(s in o={$inlinecount:"allpages"},"json"!=i&&(o.$format="json"),t)p[s]?p[s](o,t[s],a):o[s]=t[s];else{if("json"!==i)throw new Error("Only json dataType can be used for "+e+" operation.");if("destroy"!==e){for(s in t)"number"==typeof(r=t[s])&&(t[s]=r+"");o=n.stringify(t)}}return o}}}}),a(!0,n.data,{schemas:{"odata-v4":{type:"json",data:function(e){if(Array.isArray(e)){for(var n=0;n<e.length;n++)l(e[n]);return e}return l(e=t.extend({},e)),e.value?e.value:[e]},total:function(t){return t["@odata.count"]}}},transports:{"odata-v4":{batch:{type:"POST"},read:{cache:!0,dataType:"json"},update:{cache:!0,dataType:"json",contentType:"application/json;IEEE754Compatible=true",type:"PUT"},create:{cache:!0,dataType:"json",contentType:"application/json;IEEE754Compatible=true",type:"POST"},destroy:{cache:!0,dataType:"json",type:"DELETE"},parameterMap:function(t,e){var a=n.data.transports.odata.parameterMap(t,e,!0);return"read"==e&&(a.$count=!0,delete a.$inlinecount),a&&a.$filter&&(a.$filter=a.$filter.replace(/('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')/gi,(function(t){return t.substring(1,t.length-1)}))),a},submit:function(e){var o=function(t,e){var n=a({},t.options.batch),o=y("sf_batch_"),r="",i=0,d=t.options.batch.url,p=y("sf_changeset_");return n.type=t.options.batch.type,n.url=s(d)?d():d,n.headers=a(n.headers||{},{"Content-Type":"multipart/mixed; boundary="+o}),e.updated.length&&(r+=T(e.updated,o,p,i,t,"update",!1),i+=e.updated.length,p=y("sf_changeset_")),e.destroyed.length&&(r+=T(e.destroyed,o,p,i,t,"destroy",!0),i+=e.destroyed.length,p=y("sf_changeset_")),e.created.length&&(r+=T(e.created,o,p,i,t,"create",!1)),r+=h(o,!0),n.data=r,n}(this,e.data),r=e.data;(r.updated.length||r.destroyed.length||r.created.length)&&t.ajax(a(!0,{},{success:function(t){var a,o=function(t){var e,a,o,r,s,i=t.match(/--changesetresponse_[a-z0-9-]+$/gm),d=0,p=[];p.push({models:[],passed:!0});for(var c=0;c<i.length;c++)(r=i[c]).lastIndexOf("--",r.length-1)?c<i.length-1&&p.push({models:[],passed:!0}):(d=d?t.indexOf(r,d+r.length):t.indexOf(r),a=(e=t.substring(d,t.indexOf("--",d+1))).match(/^HTTP\/1\.\d (\d{3}) (.*)$/gm).pop(),(o=n.parseFloat(a.match(/\d{3}/g).pop()))>=200&&o<=299?(s=e.match(/\{.*\}/gm))&&p[p.length-1].models.push(JSON.parse(s[0])):p[p.length-1].passed=!1);return p}(t),s=0;r.updated.length&&((a=o[s]).passed&&e.success(a.models.length?a.models:[],"update"),s++),r.destroyed.length&&((a=o[s]).passed&&e.success([],"destroy"),s++),r.created.length&&(a=o[s]).passed&&e.success(a.models,"create")},error:function(t,n,a){e.error(t,n,a)}},o))}}}})}(window.kendo.jQuery)}));
//# sourceMappingURL=kendo.data.odata.min.js.map