2 use strict; use warnings;
4 # ------------------------------------------------------------
5 # turns the orgTree and orgTypes into js files
6 # ------------------------------------------------------------
9 use OpenILS::Utils::Fieldmapper;
10 use OpenSRF::Utils::SettingsClient;
11 use OpenSRF::Utils::Cache;
14 die "usage: perl org_tree_js.pl <bootstrap_config> <path> <filename>" unless $ARGV[2];
15 OpenSRF::System->bootstrap_client(config_file => $ARGV[0]);
18 my $filename = $ARGV[2];
20 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
22 # must be loaded after the IDL is parsed
23 require OpenILS::Utils::CStoreEditor;
25 # Get our list of locales
26 my $session = OpenSRF::AppSession->create("open-ils.cstore");
27 my $locales = $session->request("open-ils.cstore.direct.config.i18n_locale.search.atomic", {"code" => {"!=" => undef}}, {"order_by" => {"i18n_l" => "name"}})->gather();
28 $session->disconnect();
30 foreach my $locale (@$locales) {
31 warn "removing OrgTree from the cache for locale " . $locale->code . "...\n";
32 my $cache = OpenSRF::Utils::Cache->new;
33 $cache->delete_cache("orgtree.$locale->code");
35 # fetch the org_unit's and org_unit_type's
36 my $e = OpenILS::Utils::CStoreEditor->new;
37 $e->session->session_locale($locale->code) if ($locale->code);
39 my $types = $e->retrieve_all_actor_org_unit_type;
40 my $tree = $e->request(
41 'open-ils.cstore.direct.actor.org_unit.search.atomic',
42 {id => {"!=" => undef}},
43 {order_by => {aou => 'name'}, no_i18n => $locale->code ? 0 : 1 }
45 my $dir = File::Spec->catdir($path, $locale->code);
49 build_tree_js($types, $tree, File::Spec->catfile($dir, $filename));
55 return 'null' unless defined $v;
57 # required for JS code this is checking truthness
58 # without using isTrue() (1/0 vs. t/f)
59 return 1 if $v eq 't';
60 return 0 if $v eq 'f';
62 $v =~ s/([\x{0080}-\x{fffd}])/sprintf('\u%04x',ord($1))/sgoe;
72 my $pile = "var _l = [";
76 my ($i,$t,$p,$n,$v,$s) = ($o->id,$o->ou_type,$o->parent_ou,val($o->name),val($o->opac_visible),val($o->shortname));
78 push @array, "[$i,$t,$p,$n,$v,$s]";
81 $pile .= join ',', @array;
82 $pile .= "]; /* Org Units */ \n";
85 $pile .= 'var globalOrgTypes = [';
87 my ($u,$v,$d,$i,$n,$o,$p) = (val($t->can_have_users),val($t->can_have_vols),$t->depth,$t->id,val($t->name),val($t->opac_label),$t->parent);
89 $pile .= "new aout([null,$u,$v,$d,$i,$n,$o,$p]), ";
91 $pile =~ s/, $//; # remove trailing comma
92 $pile .= ']; /* OU Types */';
93 open(OUTFH, '>', $outfile) or die "Could not open $outfile : $!";
94 print OUTFH "$pile\n";