//>>built
define("dgrid/_StoreMixin","dojo/_base/declare dojo/_base/lang dojo/Deferred dojo/aspect dojo/dom-construct dojo/has dojo/on dojo/when".split(" "),function(r,l,p,t,m,w,q,u){function v(a){if("object"!==typeof a)a=Error(a);else if("cancel"===a.dojoType)return;q.emit(this.domNode,"dgrid-error",{grid:this,error:a,cancelable:!0,bubbles:!0})}return r(null,{collection:null,_renderedCollection:null,_rows:null,_observerHandle:null,shouldTrackCollection:!0,getBeforePut:!0,noDataMessage:"",loadingMessage:"",
_total:0,constructor:function(){this.dirty={};this._updating={};this._columnsWithSet={};t.before(this,"configStructure",l.hitch(this,function(){this._columnsWithSet={}}))},destroy:function(){this.inherited(arguments);this._renderedCollection&&this._cleanupCollection();this._refreshTimeout&&clearTimeout(this._refreshTimeout)},_configColumn:function(a){a.set&&(this._columnsWithSet[a.field]=a);this.inherited(arguments)},_setCollection:function(a){this._renderedCollection&&(this.cleanup(),this._cleanupCollection({shouldRevert:!a||
a.storage!==this._renderedCollection.storage}));this.collection=a;if(this._started){if(a){var d=a;this.sort&&0<this.sort.length&&(d=a.sort(this.sort));d.track&&this.shouldTrackCollection&&(d=d.track(),this._rows=[],this._observerHandle=this._observeCollection(d,this.contentNode,{rows:this._rows}));this._renderedCollection=d}this.refresh()}},_setStore:function(){},_getTotal:function(){return this._total},_cleanupCollection:function(a){a=a||{};this._renderedCollection.tracking&&this._renderedCollection.tracking.remove();
this._observerHandle&&(this._observerHandle.remove(),this._observerHandle=this._rows=null);!1!==a.shouldRevert&&(this.dirty={});this._renderedCollection=this.collection=null},_applySort:function(){this.collection&&this.set("collection",this.collection)},_emitRefreshComplete:function(){var a=this;this._refreshTimeout=setTimeout(function(){q.emit(a.domNode,"dgrid-refresh-complete",{bubbles:!0,cancelable:!1,grid:a});a._refreshTimeout=null},0)},_insertNoDataNode:function(a){a=a||this.contentNode;var d=
this.noDataNode=m.create("div",{className:"dgrid-no-data",innerHTML:this.noDataMessage});a.insertBefore(d,this._getFirstRowSibling&&this._getFirstRowSibling(a));return d},row:function(){var a=this.inherited(arguments);a&&a.data&&"undefined"!==typeof a.id&&(a.id=this.collection.getIdentity(a.data));return a},refresh:function(){var a=this.inherited(arguments);this.collection||this._insertNoDataNode();return a},refreshCell:function(a){if(!this.collection||!this._createBodyRowCell)throw Error("refreshCell requires a Grid with a collection.");
this.inherited(arguments);return this.collection.get(a.row.id).then(l.hitch(this,"_refreshCellFromItem",a))},_refreshCellFromItem:function(a,d,g){var e=a.element;m.empty(e);var b=this.dirty&&this.dirty[a.row.id];b&&(d=l.delegate(d,b));this._createBodyRowCell(e,a.column,d,g)},renderArray:function(){var a=this.inherited(arguments);this.collection||a.length&&this.noDataNode&&m.destroy(this.noDataNode);return a},insertRow:function(a,d,g,e,b){var h=this.collection,k=this.dirty,h=h&&h.getIdentity(a),f;
h in k&&!(h in this._updating)&&(f=k[h]);f&&(a=l.delegate(a,f));k=this.inherited(arguments);b&&b.rows&&(b.rows[e]=k);this.noDataNode&&(m.destroy(this.noDataNode),this.noDataNode=null);return k},updateDirty:function(a,d,g){var e=this.dirty,b=e[a];b||(b=e[a]={});b[d]=g},save:function(){function a(a,b){return function(c){var f=d._columnsWithSet,n=d._updating,k,l;if("function"===typeof c.set)c.set(b);else for(k in b)c[k]=b[k];for(k in f)l=f[k].set(c),void 0!==l&&(c[k]=l);n[a]=!0;return g.put(c).then(function(b){delete e[a];
delete n[a];h[a]=b;return h})}}var d=this,g=this.collection,e=this.dirty,b=new p,h={},k=function(a){var b;return d.getBeforePut||!(b=d.row(a).data)?function(){return g.get(a)}:function(){return b}},f=b.then(function(){return h}),c;for(c in e)var n=a(c,e[c]),f=f.then(k(c)).then(n);b.resolve();return f},revert:function(){this.dirty={};this.refresh()},_trackError:function(a){"string"===typeof a&&(a=l.hitch(this,a));var d=this,g;try{g=u(a())}catch(e){a=new p,a.reject(e),g=a.promise}g.otherwise(function(a){v.call(d,
a)});return g},removeRow:function(a,d,g){var e={element:a};d||this.up(e).element!==a||this.down(e).element!==a||this._insertNoDataNode();(e=g&&g.rows||this._rows)&&delete e[a.rowIndex];return this.inherited(arguments)},renderQueryResults:function(a,d,g){g=l.mixin({rows:this._rows},g);var e=this;return a.then(function(a){a=e.renderArray(a,d,g);delete e._lastCollection;return a})},_observeCollection:function(a,d,g){var e=this,b=g.rows,h,k=[a.on("delete, update",function(a){var c=a.previousIndex,f=a.index;
void 0!==c&&b[c]&&("max"in b&&(void 0===f||f<b.min||f>b.max)&&b.max--,h=b[c],h.parentNode===d&&e.removeRow(h,!1,g),b.splice(c,1),("delete"===a.type||"update"===a.type&&(c<f||void 0===f))&&b[c]&&b[c].rowIndex--);"delete"===a.type&&(h=null)}),a.on("add, update",function(a){var c=a.previousIndex,f=a.index;if(void 0!==f&&(!("max"in b)||f>=b.min&&f<=b.max)){"max"in b&&(void 0===c||c<b.min||c>b.max)&&b.max++;if(b.length){if(c=b[f],!c&&(c=b[f-1]))c=(c.connected||c).nextSibling}else c=e._getFirstRowSibling&&
e._getFirstRowSibling(d);h&&c&&h.id===c.id&&(c=(c.connected||c).nextSibling);c&&!c.parentNode&&(c=document.getElementById(c.id));b.splice(f,0,void 0);h=e.insertRow(a.target,d,c,f,g);e.highlightRow(h)}h=null}),a.on("add, delete, update",function(f){var c="undefined"!==typeof f.previousIndex?f.previousIndex:Infinity,d="undefined"!==typeof f.index?f.index:Infinity,g=Math.min(c,d);c!==d&&b[g]&&e.adjustRowIndices(b[g]);Infinity!==c&&e._processScroll&&(b[c]||b[c-1])&&e._processScroll();e._onNotification(b,
f,a);a===e._renderedCollection&&"totalLength"in f&&(e._total=f.totalLength)})];return{remove:function(){for(;0<k.length;)k.pop().remove()}}},_onNotification:function(){}})});
//# sourceMappingURL=_StoreMixin.js.map