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