//>>built
define("dojox/data/StoreExplorer",["dijit","dojo","dojox","dojo/require!dojox/grid/DataGrid,dojox/data/ItemExplorer,dijit/layout/BorderContainer,dijit/layout/ContentPane"],function(q,f,r){f.provide("dojox.data.StoreExplorer");f.require("dojox.grid.DataGrid");f.require("dojox.data.ItemExplorer");f.require("dijit.layout.BorderContainer");f.require("dijit.layout.ContentPane");f.declare("dojox.data.StoreExplorer",q.layout.BorderContainer,{constructor:function(b){f.mixin(this,b)},store:null,columnWidth:"",
stringQueries:!1,showAllColumns:!1,postCreate:function(){function b(a,h){var d=new q.form.Button({label:a});k.containerNode.appendChild(d.domNode);d.onClick=h;return d}var e=this;this.inherited(arguments);var k=(new q.layout.ContentPane({region:"top"})).placeAt(this),g=k.containerNode.appendChild(document.createElement("span"));g.innerHTML="Enter query: \x26nbsp;";g.id="queryText";var n=k.containerNode.appendChild(document.createElement("input"));n.type="text";n.id="queryTextBox";b("Query",function(){var a=
n.value;e.setQuery(e.stringQueries?a:f.fromJson(a))});k.containerNode.appendChild(document.createElement("span")).innerHTML="\x26nbsp;\x26nbsp;\x26nbsp;";var p=b("Create New",f.hitch(this,"createNew")),t=b("Delete",function(){for(var a=c.selection.getSelected(),h=0;h<a.length;h++)e.store.deleteItem(a[h])});this.setItemName=function(a){p.attr("label","\x3cimg style\x3d'width:12px; height:12px' src\x3d'"+f.moduleUrl("dijit.themes.tundra.images","dndCopy.png")+"' /\x3e Create New "+a);t.attr("label",
"Delete "+a)};b("Save",function(){e.store.save({onError:function(a){alert(a)}});e.tree.refreshItem()});b("Revert",function(){e.store.revert()});b("Add Column",function(){var a=prompt("Enter column name:","property");a&&(e.gridLayout.push({field:a,name:a,formatter:f.hitch(e,"_formatCell"),editable:!0}),e.grid.attr("structure",e.gridLayout))});g=(new q.layout.ContentPane({region:"center"})).placeAt(this);var c=this.grid=new r.grid.DataGrid({store:this.store});g.attr("content",c);c.canEdit=function(a,
h){var d=this._copyAttr(h,a.field);return!(d&&"object"==typeof d)||d instanceof Date};g=(new q.layout.ContentPane({region:"trailing",splitter:!0,style:"width: 300px"})).placeAt(this);var l=this.tree=new r.data.ItemExplorer({store:this.store});g.attr("content",l);f.connect(c,"onCellClick",function(){var a=c.selection.getSelected()[0];l.setItem(a)});this.gridOnFetchComplete=c._onFetchComplete;this.setStore(this.store)},setQuery:function(b,e){this.grid.setQuery(b,e)},_formatCell:function(b){return this.store.isItem(b)?
this.store.getLabel(b)||this.store.getIdentity(b):b},setStore:function(b){function e(p){return k._formatCell(p)}this.store=b;var k=this,g=this.grid;g._pending_requests[0]=!1;var n=this.gridOnFetchComplete;g._onFetchComplete=function(p,t){var c=k.gridLayout=[],l,a,h;var d=b.getIdentityAttributes();for(l=0;l<d.length;l++){var m=d[l];c.push({field:m,name:m,_score:100,formatter:e,editable:!1})}for(l=0;m=p[l++];){var v=b.getAttributes(m);for(h=0;m=v[h++];){var u=!1;for(a=0;d=c[a++];)if(d.field==m){d._score++;
u=!0;break}u||c.push({field:m,name:m,_score:1,formatter:e,styles:"white-space:nowrap; ",editable:!0})}}c=c.sort(function(w,x){return x._score-w._score});if(!k.showAllColumns)for(a=0;d=c[a];a++)if(d._score<p.length/40*a){c.splice(a,c.length-a);break}for(a=0;d=c[a++];)d.width=k.columnWidth||Math.round(100/c.length)+"%";g._onFetchComplete=n;g.attr("structure",c);n.apply(this,arguments)};g.setStore(b);this.queryOptions={cache:!0};this.tree.setStore(b)},createNew:function(){var b=prompt("Enter any properties (in JSON literal form) to put in the new item (passed to the newItem constructor):",
"{ }");if(b)try{this.store.newItem(f.fromJson(b))}catch(e){alert(e)}}})});