123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- define("dijit/tree/ForestStoreModel", [
- "dojo/_base/array",
- "dojo/_base/declare",
- "dojo/_base/lang",
- "dojo/_base/window",
- "./TreeStoreModel"
- ], function(array, declare, lang, win, TreeStoreModel){
- return declare("dijit.tree.ForestStoreModel", TreeStoreModel, {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- rootId: "$root$",
-
-
- rootLabel: "ROOT",
-
-
-
-
- query: null,
-
- constructor: function(params){
-
-
-
-
-
- this.root = {
- store: this,
- root: true,
- id: params.rootId,
- label: params.rootLabel,
- children: params.rootChildren
- };
- },
-
-
- mayHaveChildren: function(/*dojo.data.Item*/ item){
-
-
-
-
-
-
-
- return item === this.root || this.inherited(arguments);
- },
- getChildren: function(/*dojo.data.Item*/ parentItem, /*function(items)*/ callback, /*function*/ onError){
-
-
- if(parentItem === this.root){
- if(this.root.children){
-
- callback(this.root.children);
- }else{
- this.store.fetch({
- query: this.query,
- onComplete: lang.hitch(this, function(items){
- this.root.children = items;
- callback(items);
- }),
- onError: onError
- });
- }
- }else{
- this.inherited(arguments);
- }
- },
-
-
- isItem: function(/* anything */ something){
- return (something === this.root) ? true : this.inherited(arguments);
- },
- fetchItemByIdentity: function(/* object */ keywordArgs){
- if(keywordArgs.identity == this.root.id){
- var scope = keywordArgs.scope?keywordArgs.scope:win.global;
- if(keywordArgs.onItem){
- keywordArgs.onItem.call(scope, this.root);
- }
- }else{
- this.inherited(arguments);
- }
- },
- getIdentity: function(/* item */ item){
- return (item === this.root) ? this.root.id : this.inherited(arguments);
- },
- getLabel: function(/* item */ item){
- return (item === this.root) ? this.root.label : this.inherited(arguments);
- },
-
-
- newItem: function(/* dojo.dnd.Item */ args, /*Item*/ parent, /*int?*/ insertIndex){
-
-
-
- if(parent === this.root){
- this.onNewRootItem(args);
- return this.store.newItem(args);
- }else{
- return this.inherited(arguments);
- }
- },
- onNewRootItem: function(/* dojo.dnd.Item */ /*===== args =====*/){
-
-
-
- },
- pasteItem: function(/*Item*/ childItem, /*Item*/ oldParentItem, /*Item*/ newParentItem, /*Boolean*/ bCopy, /*int?*/ insertIndex){
-
-
-
- if(oldParentItem === this.root){
- if(!bCopy){
-
-
-
- this.onLeaveRoot(childItem);
- }
- }
- this.inherited(arguments, [childItem,
- oldParentItem === this.root ? null : oldParentItem,
- newParentItem === this.root ? null : newParentItem,
- bCopy,
- insertIndex
- ]);
- if(newParentItem === this.root){
-
-
-
- this.onAddToRoot(childItem);
- }
- },
-
-
- onAddToRoot: function(/* item */ item){
-
-
-
-
-
-
-
- console.log(this, ": item ", item, " added to root");
- },
- onLeaveRoot: function(/* item */ item){
-
-
-
-
-
-
-
- console.log(this, ": item ", item, " removed from root");
- },
-
-
- _requeryTop: function(){
-
-
- var oldChildren = this.root.children || [];
- this.store.fetch({
- query: this.query,
- onComplete: lang.hitch(this, function(newChildren){
- this.root.children = newChildren;
-
- if(oldChildren.length != newChildren.length ||
- array.some(oldChildren, function(item, idx){ return newChildren[idx] != item;})){
- this.onChildrenChange(this.root, newChildren);
- }
- })
- });
- },
- onNewItem: function(/* dojo.data.Item */ item, /* Object */ parentInfo){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this._requeryTop();
- this.inherited(arguments);
- },
- onDeleteItem: function(/*Object*/ item){
-
-
-
-
- if(array.indexOf(this.root.children, item) != -1){
- this._requeryTop();
- }
- this.inherited(arguments);
- },
- onSetItem: function(/* item */ item,
- /* attribute-name-string */ attribute,
- /* object | array */ oldValue,
- /* object | array */ newValue){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this._requeryTop();
- this.inherited(arguments);
- }
- });
- });
|