Debian Codegraph @

dojox/grid/LazyTreeGridStoreModel.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare",
3 "dojo/_base/array",
4 "dojo/_base/lang",
5 "dijit/tree/ForestStoreModel"], function(declare, array, lang, ForestStoreModel){
6
7 return declare("dojox.grid.LazyTreeGridStoreModel", ForestStoreModel, {
8
9 // There are different approaches to get children for client-side
10 // DataStore (e.g. dojo.data.ItemFileReadStore) or server-side DataStore
11 // (e.g. dojox.data.QueryReadStore), so we need to be sure what kind of
12 // DataStore is being used
13 serverStore: false, // server side store
14
15 constructor: function(/* Object */ args){
16 this.serverStore = !!args.serverStore;
17 },
18
19 mayHaveChildren: function(/*dojo.data.Item*/ item){
20 var children = null;
21 return array.some(this.childrenAttrs, function(attr){
22 children = this.store.getValue(item, attr);
23 if(lang.isString(children)){
24 return parseInt(children, 10) > 0 || children.toLowerCase() === "true" ? true : false;
25 }else if(typeof children == "number"){
26 return children > 0;
27 }else if(typeof children == "boolean"){
28 return children;
29 }else if(this.store.isItem(children)){
30 children = this.store.getValues(item, attr);
31 return lang.isArray(children) ? children.length > 0 : false;
32 }else{
33 return false;
34 }
35 }, this);
36 },
37
38 getChildren: function(/*dojo.data.Item*/parentItem, /*function(items, size)*/onComplete, /*function*/ onError, /*object*/queryObj){
39 if(queryObj){
40 var start = queryObj.start || 0,
41 count = queryObj.count,
42 parentId = queryObj.parentId,
43 sort = queryObj.sort;
44 if(parentItem === this.root){
45 this.root.size = 0;
46 this.store.fetch({
47 start: start,
48 count: count,
49 sort: sort,
50 query: this.query,
51 onBegin: lang.hitch(this, function(size){
52 this.root.size = size;
53 }),
54 onComplete: lang.hitch(this, function(items){
55 onComplete(items, queryObj, this.root.size);
56 }),
57 onError: onError
58 });
59 }else{
60 var store = this.store;
61 if(!store.isItemLoaded(parentItem)){
62 var getChildren = lang.hitch(this, arguments.callee);
63 store.loadItem({
64 item: parentItem,
65 onItem: function(parentItem){
66 getChildren(parentItem, onComplete, onError, queryObj);
67 },
68 onError: onError
69 });
70 return;
71 }
72 if(this.serverStore && !this._isChildrenLoaded(parentItem)){
73 this.childrenSize = 0;
74 this.store.fetch({
75 start: start,
76 count: count,
77 sort: sort,
78 query: lang.mixin({parentId: parentId}, this.query || {}),
79 onBegin: lang.hitch(this, function(size){
80 this.childrenSize = size;
81 }),
82 onComplete: lang.hitch(this, function(items){
83 onComplete(items, queryObj, this.childrenSize);
84 }),
85 onError: onError
86 });
87 }else{
88 this.inherited(arguments);
89 }
90 }
91 }else{
92 this.inherited(arguments);
93 }
94 },
95
96 _isChildrenLoaded: function(parentItem){
97 // summary:
98 // Check if all children of the given item have been loaded
99 var children = null;
100 return array.every(this.childrenAttrs, function(attr){
101 children = this.store.getValues(parentItem, attr);
102 return array.every(children, function(c){
103 return this.store.isItemLoaded(c);
104 }, this);
105 }, this);
106 },
107
108 //overwritten
109 onNewItem: function(item, parentInfo){ },
110
111 onDeleteItem: function(item){ }
112 });
113 });