2 # turns the orgTree and orgTypes into js files
4 use OpenSRF::AppSession;
6 use OpenSRF::Utils::JSON;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenSRF::Utils::SettingsClient;
9 use OpenSRF::Utils::Cache;
11 die "usage: perl org_tree_js.pl <bootstrap_config>" unless $ARGV[0];
12 OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
14 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
16 warn "removing OrgTree from the cache...\n";
17 my $cache = OpenSRF::Utils::Cache->new;
18 $cache->delete_cache('orgtree');
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);
25 my $types_string = OpenSRF::Utils::JSON->perl2JSON($types);
26 $types_string =~ s/\"/\\\"/g;
28 my $pile = "var _l = [";
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\"]";
35 $pile .= join ',', @array;
40 $pile .= "var globalOrgTypes = JSON2js(\"$types_string\");";