moving over some more utils. Let me know if something makes more sense to do as...
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / util / fm_utils.js
1 dump('entering util/fm_utils.js\n');
2
3 if (typeof util == 'undefined') var util = {};
4 util.fm_utils = {};
5
6 util.fm_utils.EXPORT_OK = [ 'flatten_ou_branch', 'find_ou' ];
7 util.fm_utils.EXPORT_TAGS       = { ':all' : util.fm_utils.EXPORT_OK };
8
9 util.fm_utils.flatten_ou_branch = function(branch) {
10         var my_array = new Array();
11         my_array.push( branch );
12         for (var i in branch.children() ) {
13                 var child = branch.children()[i];
14                 if (child != null) {
15                         var temp_array = util.fm_utils.flatten_ou_branch(child);
16                         for (var j in temp_array) {
17                                 my_array.push( temp_array[j] );
18                         }
19                 }
20         }
21         return my_array;
22 }
23
24 util.fm_utils.find_ou = function(tree,id) {
25         if (typeof(id)=='object') { id = id.id(); }
26         if (tree.id()==id) {
27                 return tree;
28         }
29         for (var i in tree.children()) {
30                 var child = tree.children()[i];
31                 ou = util.fm_utils.find_ou( child, id );
32                 if (ou) { return ou; }
33         }
34         return null;
35 }
36