liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
1
2
3
4
5
6
7
8
9
10
11
//>>built
define("../_base/lang ../Evented ../_base/declare ../_base/Deferred ../promise/all ../_base/array ../_base/connect ../regexp".split(" "),function(h,p,q,k,r,n,t,u){function v(a){return"*"==a?".*":"?"==a?".":a}return q("dojo.data.ObjectStore",[p],{objectStore:null,constructor:function(a){this._dirtyObjects=[];a.labelAttribute&&(a.labelProperty=a.labelAttribute);h.mixin(this,a)},labelProperty:"label",getValue:function(a,c,b){return"function"===typeof a.get?a.get(c):c in a?a[c]:b},getValues:function(a,
c){a=this.getValue(a,c);return a instanceof Array?a:void 0===a?[]:[a]},getAttributes:function(a){var c=[],b;for(b in a)!a.hasOwnProperty(b)||"_"==b.charAt(0)&&"_"==b.charAt(1)||c.push(b);return c},hasAttribute:function(a,c){return c in a},containsValue:function(a,c,b){return-1<n.indexOf(this.getValues(a,c),b)},isItem:function(a){return"object"==typeof a&&a&&!(a instanceof Date)},isItemLoaded:function(a){return a&&"function"!==typeof a.load},loadItem:function(a){var c;"function"===typeof a.item.load?
k.when(a.item.load(),function(b){c=b;var d=b instanceof Error?a.onError:a.onItem;d&&d.call(a.scope,b)}):a.onItem&&a.onItem.call(a.scope,a.item);return c},close:function(a){return a&&a.abort&&a.abort()},fetch:function(a){function c(b){a.onError&&a.onError.call(d,b,a)}a=h.delegate(a,a&&a.queryOptions);var b=this,d=a.scope||b,e=a.query;if("object"==typeof e){var e=h.delegate(e),g;for(g in e){var l=e[g];"string"==typeof l&&(e[g]=RegExp("^"+u.escapeString(l,"*?\\").replace(/\\.|\*|\?/g,v)+"$",a.ignoreCase?
"mi":"m"),e[g].toString=function(a){return function(){return a}}(l))}}var f=this.objectStore.query(e,a);k.when(f.total,function(b){k.when(f,function(c){a.onBegin&&a.onBegin.call(d,b||c.length,a);if(a.onItem)for(var e=0;e<c.length;e++)a.onItem.call(d,c[e],a);a.onComplete&&a.onComplete.call(d,a.onItem?null:c,a);return c},c)},c);a.abort=function(){f.cancel&&f.cancel()};f.observe&&(this.observing&&this.observing.cancel(),this.observing=f.observe(function(a,c,d){if(-1==n.indexOf(b._dirtyObjects,a))if(-1==
c)b.onNew(a);else if(-1==d)b.onDelete(a);else for(var e in a)if(e!=b.objectStore.idProperty)b.onSet(a,e,null,a[e])},!0));this.onFetch(f);a.store=this;return a},getFeatures:function(){return{"dojo.data.api.Read":!!this.objectStore.get,"dojo.data.api.Identity":!0,"dojo.data.api.Write":!!this.objectStore.put,"dojo.data.api.Notification":!0}},getLabel:function(a){if(this.isItem(a))return this.getValue(a,this.labelProperty)},getLabelAttributes:function(a){return[this.labelProperty]},getIdentity:function(a){return this.objectStore.getIdentity?
this.objectStore.getIdentity(a):a[this.objectStore.idProperty||"id"]},getIdentityAttributes:function(a){return[this.objectStore.idProperty]},fetchItemByIdentity:function(a){var c;k.when(this.objectStore.get(a.identity),function(b){c=b;a.onItem.call(a.scope,b)},function(b){a.onError.call(a.scope,b)});return c},newItem:function(a,c){if(c){var b=this.getValue(c.parent,c.attribute,[]),b=b.concat([a]);a.__parent=b;this.setValue(c.parent,c.attribute,b)}this._dirtyObjects.push({object:a,save:!0});this.onNew(a);
return a},deleteItem:function(a){this.changing(a,!0);this.onDelete(a)},setValue:function(a,c,b){var d=a[c];this.changing(a);a[c]=b;this.onSet(a,c,d,b)},setValues:function(a,c,b){if(!h.isArray(b))throw Error("setValues expects to be passed an Array object as its value");this.setValue(a,c,b)},unsetAttribute:function(a,c){this.changing(a);var b=a[c];delete a[c];this.onSet(a,c,b,void 0)},changing:function(a,c){a.__isDirty=!0;for(var b=0;b<this._dirtyObjects.length;b++){var d=this._dirtyObjects[b];if(a==
d.object){c&&(d.object=!1,this._saveNotNeeded||(d.save=!0));return}}d=a instanceof Array?[]:{};for(b in a)a.hasOwnProperty(b)&&(d[b]=a[b]);this._dirtyObjects.push({object:!c&&a,old:d,save:!this._saveNotNeeded})},save:function(a){a=a||{};var c,b=[],d=[],e=this,g=this._dirtyObjects;try{t.connect(a,"onError",function(){if(!1!==a.revertOnError){var b=g;g=d;e.revert();e._dirtyObjects=b}else e._dirtyObjects=g.concat(d)});var l;this.objectStore.transaction&&(l=this.objectStore.transaction());for(var f=0;f<
g.length;f++){var h=g[f],k=h.object,m=h.old;delete k.__isDirty;k?(c=this.objectStore.put(k,{overwrite:!!m}),b.push(c)):"undefined"!=typeof m&&(c=this.objectStore.remove(this.getIdentity(m)),b.push(c));d.push(h);g.splice(f--,1)}r(b).then(function(b){a.onComplete&&a.onComplete.call(a.scope,b)},function(b){a.onError&&a.onError.call(a.scope,b)});l&&l.commit()}catch(w){a.onError.call(a.scope,value)}},revert:function(){for(var a=this._dirtyObjects,c=a.length;0<c;){c--;var b=a[c],d=b.object,b=b.old;if(d&&
b){for(var e in b)b.hasOwnProperty(e)&&d[e]!==b[e]&&(this.onSet(d,e,d[e],b[e]),d[e]=b[e]);for(e in d)b.hasOwnProperty(e)||(this.onSet(d,e,d[e]),delete d[e])}else if(b)this.onNew(b);else this.onDelete(d);delete (d||b).__isDirty;a.splice(c,1)}},isDirty:function(a){return a?a.__isDirty:!!this._dirtyObjects.length},onSet:function(){},onNew:function(){},onDelete:function(){},onFetch:function(a){}})});