1 var oilsRptFolderNodeCache = {};
3 oilsRptFolderManager.prototype = new oilsRptObject();
4 oilsRptFolderManager.prototype.constructor = oilsRptFolderManager;
5 oilsRptFolderManager.baseClass = oilsRptObject.prototype.constructor;
7 function oilsRptFolderManager(node) {
13 oilsRptFolderManager.prototype.draw = function(auth) {
14 var tree = oilsRptFolderTree =
15 new SlimTree(this.node, 'oilsRptFolderTree');
17 this.rootTreeId = oilsNextId();
18 this.templateTreeId = oilsNextId();
19 this.reportTreeId = oilsNextId();
20 this.outputTreeId = oilsNextId();
22 tree.addNode(this.rootTreeId, -1, 'Report Folders');
23 tree.addNode(this.templateTreeId, this.rootTreeId, 'Template Folders');
24 tree.addNode(this.reportTreeId, this.rootTreeId, 'Report Folders');
25 tree.addNode(this.outputTreeId, this.rootTreeId, 'Output Folders');
27 this.fetchFolders(auth);
30 oilsRptFolderManager.prototype.fetchFolders = function(auth) {
32 var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'template');
33 req.callback( function(r) { obj.drawFolders('template', r.getResultObject()); } );
36 var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'report');
37 req.callback( function(r) { obj.drawFolders('report', r.getResultObject()); } );
40 var req = new Request(OILS_RPT_FETCH_FOLDERS, auth, 'output');
41 req.callback( function(r) { obj.drawFolders('output', r.getResultObject()); } );
46 oilsRptFolderManager.prototype.drawFolders = function(type, folders) {
47 _debug('making folder tree '+type);
49 case 'template': tid = this.templateTreeId; break;
50 case 'report': tid = this.reportTreeId; break;
51 case 'output': tid = this.outputTreeId; break;
53 this.folderTree[type] = { children : [] };
54 this.makeTree(type, folders, this.folderTree[type], tid );
58 /* builds an in-memory version of the folder trees as well as the UI trees */
59 oilsRptFolderManager.prototype.makeTree = function(type, folders, node, parentId) {
65 childNodes = grep(folders, function(f){return (!f.parent())});
68 _debug("making subtree with folder "+node.folder.name());
70 var c = oilsRptFolderNodeCache;
71 if(!c[type]) c[type] = {};
72 c[type][node.folder.id()] = node;
76 node.folderWindow = oilsRptBuildFolderWindow(type, node.folder.id());
78 var action = 'javascript:oilsRptObject.find('+node.folderWindow.id+').draw();'+
79 'oilsRptFolderTree.toggle("'+id+'");';
81 oilsRptFolderTree.addNode(id, parentId, node.folder.name(), action);
84 childNodes = grep(folders,
85 function(i){return (i.parent() == node.folder.id())});
88 if(!childNodes) return;
89 for( var i = 0; i < childNodes.length; i++ )
90 this.makeTree( type, folders, { folder : childNodes[i] }, id );
93 oilsRptFolderManager.prototype.findNode = function(type, id) {
94 return oilsRptFolderNodeCache[type][id];