]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/util/ils_utils.js
Let the onslaught continue...
[Evergreen.git] / Open-ILS / src / javascript / util / ils_utils.js
1 /* */
2
3 function findOrgDepth(type_id) {
4
5         if(type_id == null || globalOrgTypes == null)
6                 return null;
7
8         var t = findOrgType(type_id);
9         if(t != null)
10                 return t.depth();
11         return null;
12 }
13
14 function findOrgType(type_id) {
15
16         if(type_id == null || globalOrgTypes == null)
17                 return null;
18
19         if(typeof type_id == 'object')
20                 return type_id;
21
22         for(var type in globalOrgTypes) {
23                 var t =globalOrgTypes[type]; 
24                 if( t.id() == type_id ) 
25                         return t;
26         }
27         return null;
28 }
29
30
31 /* locates a specific org unit */
32 function findOrgUnit(org_id, branch) {
33         if(org_id == null) return null;
34         if(globalOrgTree == null)
35                 throw new EXArg("Need globalOrgTree");
36
37         if( branch == null )
38                 branch = globalOrgTree;
39
40         if( org_id == branch.id() )
41                 return branch;
42
43         var org;
44         for( var child in branch.children() ) {
45                 org = findOrgUnit(org_id, branch.children()[child]);
46                 if(org != null) 
47                         return org;
48         }
49         return null;
50 }
51
52
53 function buildOrgTreeWidget(org_node) {
54
55         var item;
56
57         globalPage.treeWidgetElements = new Array();
58
59         if(org_node == null) {
60                 org_node = globalOrgTree;
61                 item = new WebFXTree(org_node.name());
62                 item.setBehavior('classic');
63         } else {
64                 item = new WebFXTreeItem(org_node.name());
65         }
66
67         item.action = 
68                 "javascript:globalPage.updateSelectedLocation('" + org_node.id() + "');" +
69                 "globalPage.locationTree.hide();";
70
71         /*
72         item.action = function() {
73                 globalPage.updateSelectedLocation(org_node.id());
74                 globalPage.globalMenuManager.hideAll();
75         }
76         */
77
78
79         globalPage.treeWidgetElements[item.id] = org_node;
80
81         for( var index in org_node.children()) {
82                 var childorg = org_node.children()[index];
83                 if( childorg != null ) {
84                         var tree_node = buildOrgTreeWidget(childorg);
85                         if(tree_node != null)
86                                 item.add(tree_node);
87                 }
88         }
89
90         return item;
91 }
92
93 function getOrgById(id, node) {
94         if(node == null) node = globalOrgTree;
95         if( node.id() == id) return node;
96         for( var ind in node.children() ) {
97                 var ret = getOrgById(id, node.children()[ind] );
98                 if( ret != null )
99                         return ret;
100         }
101         return null;
102 }
103
104
105
106 function orgNodeTrail(node) {
107         var nodeArray = new Array();
108         while( node ) {
109                 debug("pushing " + node.name() );
110                 nodeArray.push(node);
111                 node = findOrgUnit(node.parent_ou());
112         }
113         nodeArray = nodeArray.reverse();
114         return nodeArray;
115 }
116
117
118