From e1fda02a1d6a900ed0a876464fa442afabe3d7b1 Mon Sep 17 00:00:00 2001 From: dbs Date: Fri, 13 Mar 2009 01:24:51 +0000 Subject: [PATCH] Backport r12490 from trunk: Enable slimpac and dynamic OPAC to have localized org trees git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_4@12502 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/autogen.sh | 6 +- Open-ILS/src/extras/org_tree_html_options.pl | 66 ++++++++------- Open-ILS/src/extras/org_tree_js.pl | 96 +++++++++++++--------- Open-ILS/web/opac/extras/slimpac/advanced.html | 2 +- Open-ILS/web/opac/extras/slimpac/start.html | 2 +- .../web/opac/skin/default/xml/common/js_common.xml | 2 +- 6 files changed, 102 insertions(+), 72 deletions(-) diff --git a/Open-ILS/src/extras/autogen.sh b/Open-ILS/src/extras/autogen.sh index d791441aec..fd0e0b309b 100755 --- a/Open-ILS/src/extras/autogen.sh +++ b/Open-ILS/src/extras/autogen.sh @@ -81,11 +81,11 @@ echo "Updating web_fieldmapper"; perl fieldmapper.pl "$CONFIG" "web_core" > "$JSDIR/fmcore.js"; echo "Updating OrgTree"; -perl org_tree_js.pl "$CONFIG" > "$JSDIR/OrgTree.js"; -cp "$JSDIR/OrgTree.js" "$FMDOJODIR/" +perl org_tree_js.pl "$CONFIG" "$JSDIR" "OrgTree.js"; +cp "$JSDIR/en-US/OrgTree.js" "$FMDOJODIR/" echo "Updating OrgTree HTML"; -perl org_tree_html_options.pl "$CONFIG" "$SLIMPACDIR/lib_list.inc"; +perl org_tree_html_options.pl "$CONFIG" "$SLIMPACDIR" "lib_list.inc"; echo "Updating locales selection HTML"; perl locale_html_options.pl "$CONFIG" "$SLIMPACDIR/locales.inc"; diff --git a/Open-ILS/src/extras/org_tree_html_options.pl b/Open-ILS/src/extras/org_tree_html_options.pl index 36c78c6598..e461d0310c 100644 --- a/Open-ILS/src/extras/org_tree_html_options.pl +++ b/Open-ILS/src/extras/org_tree_html_options.pl @@ -1,56 +1,64 @@ #!/usr/bin/perl -# turns the orgTree and orgTypes into a static HTML option list +# for each supported locale, turn the orgTree and orgTypes into a static HTML option list use OpenSRF::AppSession; use OpenSRF::System; use OpenILS::Utils::Fieldmapper; use OpenSRF::Utils::SettingsClient; +use OpenILS::Application::AppUtils; use Unicode::Normalize; use Data::Dumper; +use File::Spec; -die "usage: perl org_tree_html_options.pl " unless $ARGV[1]; +die "usage: perl org_tree_html_options.pl " unless $ARGV[2]; OpenSRF::System->bootstrap_client(config_file => $ARGV[0]); -open FILE, ">$ARGV[1]"; - -Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); - -my $ses = OpenSRF::AppSession->create("open-ils.actor"); -my $tree = $ses->request("open-ils.actor.org_tree.retrieve")->gather(1); +my $path = $ARGV[1]; +my $filename = $ARGV[2]; my @types; -my $aout = $ses->request("open-ils.actor.org_types.retrieve")->gather(1); -foreach my $type (@$aout) { - $types[int($type->id)] = $type; -} -print_option($tree); +Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); + +#Get our list of locales +my $session = OpenSRF::AppSession->create("open-ils.cstore"); +my $locales = $session->request("open-ils.cstore.direct.config.i18n_locale.search.atomic", {"code" => {"!=" => undef}}, {"order_by" => {"i18n_l" => "name"}})->gather(); +$session->disconnect(); -$ses->disconnect(); -close FILE; +foreach my $locale (@$locales) { + my $ses = OpenSRF::AppSession->create("open-ils.actor"); + $ses->session_locale($locale->code); + my $tree = $ses->request("open-ils.actor.org_tree.retrieve")->gather(1); + my $aout = $ses->request("open-ils.actor.org_types.retrieve")->gather(1); + foreach my $type (@$aout) { + $types[int($type->id)] = $type; + } + my $dir = File::Spec->catdir($path, $locale->code); + if (!-d $dir) { + mkdir($dir) or die "Could not create output directory: $dir $!\n"; + } + my @org_tree_html; + print_option($tree, \@org_tree_html); + $ses->disconnect(); + open(FILE, '>', File::Spec->catfile($dir, $filename)) or die $!; + print FILE @org_tree_html; + close FILE; +} sub print_option { my $node = shift; + my $org_tree_html = shift; + return unless ($node->opac_visible =~ /^[y1t]+/i); my $depth = $types[$node->ou_type]->depth; - my $sname = entityize($node->shortname); - my $name = entityize($node->name); + my $sname = OpenILS::Application::AppUtils->entityize($node->shortname); + my $name = OpenILS::Application::AppUtils->entityize($node->name); my $kids = $node->children; - print FILE "\n"; - print_option($_) for (@$kids); -} - -sub entityize { - my $stuff = shift || return ""; - $stuff =~ s/\/>/og; - $stuff =~ s/\&/&/og; - $stuff = NFD($stuff); - $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe; - return $stuff; + push @$org_tree_html, "\n"; + print_option($_, $org_tree_html) for (@$kids); } diff --git a/Open-ILS/src/extras/org_tree_js.pl b/Open-ILS/src/extras/org_tree_js.pl index 2bed194f9f..cac77fc70c 100644 --- a/Open-ILS/src/extras/org_tree_js.pl +++ b/Open-ILS/src/extras/org_tree_js.pl @@ -9,31 +9,45 @@ use OpenSRF::System; use OpenILS::Utils::Fieldmapper; use OpenSRF::Utils::SettingsClient; use OpenSRF::Utils::Cache; +use File::Spec; -die "usage: perl org_tree_js.pl " unless $ARGV[0]; +die "usage: perl org_tree_js.pl " unless $ARGV[2]; OpenSRF::System->bootstrap_client(config_file => $ARGV[0]); -my $locale = $ARGV[1] || ''; +my $path = $ARGV[1]; +my $filename = $ARGV[2]; Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); # must be loaded after the IDL is parsed require OpenILS::Utils::CStoreEditor; -warn "removing OrgTree from the cache...\n"; -my $cache = OpenSRF::Utils::Cache->new; -$cache->delete_cache("orgtree.$locale"); - -# fetch the org_unit's and org_unit_type's -my $e = OpenILS::Utils::CStoreEditor->new; -$e->session->session_locale($locale) if ($locale); - -my $types = $e->retrieve_all_actor_org_unit_type; -my $tree = $e->request( - 'open-ils.cstore.direct.actor.org_unit.search.atomic', - {id => {"!=" => undef}}, - {order_by => {aou => 'name'}, no_i18n => $locale ? 0 : 1 } -); +# Get our list of locales +my $session = OpenSRF::AppSession->create("open-ils.cstore"); +my $locales = $session->request("open-ils.cstore.direct.config.i18n_locale.search.atomic", {"code" => {"!=" => undef}}, {"order_by" => {"i18n_l" => "name"}})->gather(); +$session->disconnect(); + +foreach my $locale (@$locales) { + warn "removing OrgTree from the cache for locale " . $locale->code . "...\n"; + my $cache = OpenSRF::Utils::Cache->new; + $cache->delete_cache("orgtree.$locale->code"); + + # fetch the org_unit's and org_unit_type's + my $e = OpenILS::Utils::CStoreEditor->new; + $e->session->session_locale($locale->code) if ($locale->code); + + my $types = $e->retrieve_all_actor_org_unit_type; + my $tree = $e->request( + 'open-ils.cstore.direct.actor.org_unit.search.atomic', + {id => {"!=" => undef}}, + {order_by => {aou => 'name'}, no_i18n => $locale->code ? 0 : 1 } + ); + my $dir = File::Spec->catdir($path, $locale->code); + if (!-d $dir) { + mkdir($dir); + } + build_tree_js($types, $tree, File::Spec->catfile($dir, $filename)); +} sub val { @@ -50,28 +64,36 @@ sub val { return "\"$v\""; } -my $pile = "var _l = ["; - -my @array; -for my $o (@$tree) { - 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)); - $p ||= 'null'; - push @array, "[$i,$t,$p,$n,$v,$s]"; -} - -$pile .= join ',', @array; -$pile .= "]; /* Org Units */ \n"; - - -$pile .= 'var globalOrgTypes = ['; -for my $t (@$types) { - 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); - $p ||= 'null'; - $pile .= "new aout([null,null,null,null,$u,$v,$d,$i,$n,$o,$p]), "; +sub build_tree_js { + my $types = shift; + my $tree = shift; + my $outfile = shift; + + my $pile = "var _l = ["; + + my @array; + for my $o (@$tree) { + 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)); + $p ||= 'null'; + push @array, "[$i,$t,$p,$n,$v,$s]"; + } + + $pile .= join ',', @array; + $pile .= "]; /* Org Units */ \n"; + + + $pile .= 'var globalOrgTypes = ['; + for my $t (@$types) { + 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); + $p ||= 'null'; + $pile .= "new aout([null,null,null,null,$u,$v,$d,$i,$n,$o,$p]), "; + } + $pile =~ s/, $//; # remove trailing comma + $pile .= ']; /* OU Types */'; + open(OUTFH, '>', $outfile) or die "Could not open $outfile : $!"; + print OUTFH "$pile\n"; + close(OUTFH); } -$pile =~ s/, $//; # remove trailing comma -$pile .= ']; /* OU Types */'; -print "$pile\n"; diff --git a/Open-ILS/web/opac/extras/slimpac/advanced.html b/Open-ILS/web/opac/extras/slimpac/advanced.html index 40cc62eb6c..fcff938ea9 100644 --- a/Open-ILS/web/opac/extras/slimpac/advanced.html +++ b/Open-ILS/web/opac/extras/slimpac/advanced.html @@ -97,7 +97,7 @@ &slimpac.start.nowSearching; diff --git a/Open-ILS/web/opac/extras/slimpac/start.html b/Open-ILS/web/opac/extras/slimpac/start.html index 12cc610f85..e5cc48abb6 100644 --- a/Open-ILS/web/opac/extras/slimpac/start.html +++ b/Open-ILS/web/opac/extras/slimpac/start.html @@ -100,7 +100,7 @@
&slimpac.start.nowSearching;
diff --git a/Open-ILS/web/opac/skin/default/xml/common/js_common.xml b/Open-ILS/web/opac/skin/default/xml/common/js_common.xml index 508b4cd6ab..a234f9be66 100644 --- a/Open-ILS/web/opac/skin/default/xml/common/js_common.xml +++ b/Open-ILS/web/opac/skin/default/xml/common/js_common.xml @@ -10,7 +10,7 @@ - + -- 2.11.0