]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/org_tree_js.pl
Patch from Dan Scott to move JSON to OpenSRF::Utils::JSON:
[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 OpenSRF::Utils::JSON;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenSRF::Utils::SettingsClient;
9 use OpenSRF::Utils::Cache;
10
11 die "usage: perl org_tree_js.pl <bootstrap_config>" unless $ARGV[0];
12 OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
13
14 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
15
16 warn "removing OrgTree from the cache...\n";
17 my $cache = OpenSRF::Utils::Cache->new;
18 $cache->delete_cache('orgtree');
19
20
21 my $ses = OpenSRF::AppSession->create("open-ils.storage");
22 my $tree = $ses->request("open-ils.storage.direct.actor.org_unit.retrieve.all.atomic")->gather(1);
23 my $types = $ses->request("open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic")->gather(1);
24
25 my $types_string = OpenSRF::Utils::JSON->perl2JSON($types);
26 $types_string =~ s/\"/\\\"/g;
27
28 my $pile = "var _l = [";
29
30 my @array;
31 for my $o (@$tree) {
32         my ($i,$t,$p,$n,$v) = ($o->id,$o->ou_type,$o->parent_ou,$o->name,$o->opac_visible);
33         push @array, "[$i,$t,$p,\"$n\",\"$v\"]";
34 }
35 $pile .= join ',', @array;
36 $pile .= <<JS;
37 ];
38 JS
39
40 $pile .= "var globalOrgTypes = JSON2js(\"$types_string\");";
41
42 print $pile;
43
44
45 $ses->disconnect();