]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/org_tree_js.pl
libraries are now filtered on id (there are duplicate names, such as "Bookmobile")
[Evergreen.git] / Open-ILS / src / extras / org_tree_js.pl
1
2 # turns the orgTree and orgTypes into js files
3
4 use OpenSRF::AppSession;
5 use OpenSRF::System;
6 use JSON;
7 use OpenILS::Utils::Fieldmapper;
8
9 die "usage: perl org_tree_js.pl <bootstrap_config>" unless $ARGV[0];
10 OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
11
12 my $ses = OpenSRF::AppSession->create("open-ils.storage");
13 my $tree = $ses->request("open-ils.storage.direct.actor.org_unit.retrieve.all.atomic")->gather(1);
14 my $types = $ses->request("open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic")->gather(1);
15
16 my $types_string = JSON->perl2JSON($types);
17 $types_string =~ s/\"/\\\"/g;
18
19 my $pile = "var _l = [";
20
21 my @array;
22 for my $o (@$tree) {
23         my ($i,$t,$p,$n) = ($o->id,$o->ou_type,$o->parent_ou,$o->name);
24         push @array, "[$i,$t,$p,\"$n\"]";
25 }
26 $pile .= join ',', @array;
27 $pile .= <<JS;
28 ];
29 JS
30
31 $pile .= "var globalOrgTypes = JSON2js(\"$types_string\");";
32
33 print $pile;
34
35
36 $ses->disconnect();