1 var oilsRptFolderNodeCache = {};
3 function oilsRptFolderManager(node) {
8 oilsRptFolderManager.prototype.draw = function(auth) {
9 var tree = oilsRptFolderTree =
10 new SlimTree(this.node, 'oilsRptFolderTree');
12 this.rootTreeId = oilsNextId();
13 this.templateTreeId = oilsNextId();
14 this.reportTreeId = oilsNextId();
15 this.outputTreeId = oilsNextId();
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');
22 this.fetchFolders(auth);
25 oilsRptFolderManager.prototype.fetchFolders = function(auth) {
27 var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'template');
28 req.callback( function(r) { obj.drawFolders('template', r.getResultObject()); } );
31 var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'report');
32 req.callback( function(r) { obj.drawFolders('report', r.getResultObject()); } );
35 var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'output');
36 req.callback( function(r) { obj.drawFolders('output', r.getResultObject()); } );
41 oilsRptFolderManager.prototype.drawFolders = function(type, folders) {
42 _debug('making folder tree '+type);
44 case 'template': tid = this.templateTreeId; break;
45 case 'report': tid = this.reportTreeId; break;
46 case 'output': tid = this.outputTreeId; break;
48 this.folderTree[type] = { children : [] };
49 this.makeTree(type, folders, this.folderTree[type], tid );
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) {
60 childNodes = grep(folders, function(f){return (!f.parent())});
63 _debug("making subtree with folder "+node.folder.name());
65 var c = oilsRptFolderNodeCache;
66 if(!c[type]) c[type] = {};
67 c[type][node.folder.id()] = node;
71 var action = 'javascript:oilsRptDrawFolderWindow("'+
72 type+'","'+node.folder.id()+'");oilsRptFolderTree.toggle("'+id+'");';
74 oilsRptFolderTree.addNode(id, parentId, node.folder.name(), action);
77 childNodes = grep(folders,
78 function(i){return (i.parent() == node.folder.id())});
81 if(!childNodes) return;
82 for( var i = 0; i < childNodes.length; i++ )
83 this.makeTree( type, folders, { folder : childNodes[i] }, id );
86 oilsRptFolderManager.prototype.findNode = function(type, id) {
87 return oilsRptFolderNodeCache[type][id];