Backport r12490 from trunk: Enable slimpac and dynamic OPAC to have localized org...
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Mar 2009 01:42:15 +0000 (01:42 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Mar 2009 01:42:15 +0000 (01:42 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_4_0@12504 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/autogen.sh
Open-ILS/src/extras/org_tree_html_options.pl
Open-ILS/src/extras/org_tree_js.pl
Open-ILS/web/opac/extras/slimpac/advanced.html
Open-ILS/web/opac/extras/slimpac/start.html
Open-ILS/web/opac/skin/default/xml/common/js_common.xml

index d791441..fd0e0b3 100755 (executable)
@@ -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";
index 36c78c6..e461d03 100644 (file)
@@ -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 <bootstrap_config> <output_file>" unless $ARGV[1];
+die "usage: perl org_tree_html_options.pl <bootstrap_config> <output_path> <output_file>" 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 "<option value='$sname'>" . '&#160;&#160;&#160;'x$depth . "$name</option>\n";
-       print_option($_) for (@$kids);
-}
-
-sub entityize {
-        my $stuff = shift || return "";
-        $stuff =~ s/\</&lt;/og;
-        $stuff =~ s/\>/&gt;/og;
-        $stuff =~ s/\&/&amp;/og;
-        $stuff = NFD($stuff);
-        $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
-        return $stuff;
+       push @$org_tree_html, "<option value='$sname'>" . '&#160;&#160;&#160;'x$depth . "$name</option>\n";
+       print_option($_, $org_tree_html) for (@$kids);
 }
 
index 2bed194..cac77fc 100644 (file)
@@ -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 <bootstrap_config>" unless $ARGV[0];
+die "usage: perl org_tree_js.pl <bootstrap_config> <path> <filename>" 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";
 
 
index 40cc62e..fcff938 100644 (file)
@@ -97,7 +97,7 @@
                                        <th>&slimpac.start.nowSearching;</th>
                                        <td>
                                                <select name="searchOrg">
-                                                       <!--#include file="lib_list.inc" -->
+                                                       <!--#include file="${locale}/lib_list.inc" -->
                                                </select>
                                        </td>
                                </tr>
index 12cc610..e5cc48a 100644 (file)
                                                <div class='search_field'>
                                                        <span>&slimpac.start.nowSearching;</span>
                                                        <select name="searchOrg">
-                                                               <!--#include file="lib_list.inc" -->
+                                                               <!--#include file="${locale}/lib_list.inc" -->
                                                        </select>
                                                </div>
                                        </td>
index 508b4cd..a234f9b 100644 (file)
@@ -10,7 +10,7 @@
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/fmcore.js' type='text/javascript'></script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/fmgen.js' type='text/javascript'></script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/opac_utils.js' type='text/javascript'></script>
-       <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/OrgTree.js' type='text/javascript'></script>
+       <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/<!--#echo var="locale"-->/OrgTree.js' type='text/javascript'></script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/OrgLasso.js' type='text/javascript'></script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/org_utils.js' type='text/javascript'></script>
        <script language='javascript' src='<!--#echo var="OILS_JS_BASE"-->/RemoteRequest.js' type='text/javascript'></script>