]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_folders.js
started working on user folders for the main page
[Evergreen.git] / Open-ILS / web / reports / oils_rpt_folders.js
1 function oilsRptFolderManager(node) {
2         this.node = node;
3         this.folderTree = {};
4 }
5
6 oilsRptFolderManager.prototype.draw = function(auth) {
7         var tree = oilsRptFolderTree = 
8                 new SlimTree(this.node, 'oilsRptFolderTree');
9
10         this.rootTreeId         = oilsNextId();
11         this.templateTreeId     = oilsNextId();
12         this.reportTreeId               = oilsNextId();
13         this.outputTreeId               = oilsNextId();
14
15         tree.addNode(this.rootTreeId, -1, 'Report Folders');
16         tree.addNode(this.templateTreeId, this.rootTreeId, 'Template Folders');
17         tree.addNode(this.reportTreeId, this.rootTreeId, 'Report Folders');
18         tree.addNode(this.outputTreeId, this.rootTreeId, 'Output Folders');
19
20         this.fetchFolders(auth);
21 }
22
23 oilsRptFolderManager.prototype.fetchFolders = function(auth) {
24         var obj = this;
25         var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'template');
26         req.callback( function(r) { obj.drawFolders('template', r.getResultObject()); } );
27         req.send();
28
29         var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'report');
30         req.callback( function(r) { obj.drawFolders('report', r.getResultObject()); } );
31         req.send();
32
33         var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'output');
34         req.callback( function(r) { obj.drawFolders('output', r.getResultObject()); } );
35         req.send();
36 }
37
38
39 oilsRptFolderManager.prototype.drawFolders = function(type, folders) {
40         _debug('making folder tree '+type);
41         switch(type) {
42                 case 'template': tid = this.templateTreeId; break;
43                 case 'report': tid = this.reportTreeId; break;
44                 case 'output': tid = this.outputTreeId; break;
45         }
46         this.folderTree[type] = { children : [] };
47         this.makeTree(type, folders, this.folderTree[type], tid );
48 }
49
50
51 /* builds an in-memory version of the folder trees as well as the UI trees */
52 oilsRptFolderManager.prototype.makeTree = function(type, folders, node, parentId) {
53         if(!node) return;
54         var id = parentId;
55         var childNodes;
56
57         if( ! node.folder ) {
58                 childNodes = grep(folders, function(f){return (!f.parent())});
59
60         } else {
61                 _debug("making subtree with folder "+node.folder.name());
62
63                 id = oilsNextId();
64                 oilsRptFolderTree.addNode(id, parentId, node.folder.name());
65                 node.treeId = id;
66                 node.children = [];
67                 childNodes = grep(folders, 
68                         function(i){return (i.parent() == node.folder.id())});
69
70                 var req = new Request(OILS_RPT_FETCH_FOLDER_DATA,SESSION,type,node.folder.id());
71                 req.callback
72
73         } 
74
75         if(!childNodes) return;
76         for( var i = 0; i < childNodes.length; i++ ) 
77                 this.makeTree( type, folders, { folder : childNodes[i] }, id );
78 }
79
80 //oilsRptFolderManager.prototype.make
81
82
83
84
85