[open-ils-commits] r12502 - in branches/rel_1_4/Open-ILS: src/extras web/opac/extras/slimpac web/opac/skin/default/xml/common (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Mar 12 21:24:52 EDT 2009


Author: dbs
Date: 2009-03-12 21:24:51 -0400 (Thu, 12 Mar 2009)
New Revision: 12502

Modified:
   branches/rel_1_4/Open-ILS/src/extras/autogen.sh
   branches/rel_1_4/Open-ILS/src/extras/org_tree_html_options.pl
   branches/rel_1_4/Open-ILS/src/extras/org_tree_js.pl
   branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/advanced.html
   branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/start.html
   branches/rel_1_4/Open-ILS/web/opac/skin/default/xml/common/js_common.xml
Log:
Backport r12490 from trunk: Enable slimpac and dynamic OPAC to have localized org trees 


Modified: branches/rel_1_4/Open-ILS/src/extras/autogen.sh
===================================================================
--- branches/rel_1_4/Open-ILS/src/extras/autogen.sh	2009-03-13 01:23:04 UTC (rev 12501)
+++ branches/rel_1_4/Open-ILS/src/extras/autogen.sh	2009-03-13 01:24:51 UTC (rev 12502)
@@ -81,11 +81,11 @@
 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";

Modified: branches/rel_1_4/Open-ILS/src/extras/org_tree_html_options.pl
===================================================================
--- branches/rel_1_4/Open-ILS/src/extras/org_tree_html_options.pl	2009-03-13 01:23:04 UTC (rev 12501)
+++ branches/rel_1_4/Open-ILS/src/extras/org_tree_html_options.pl	2009-03-13 01:24:51 UTC (rev 12502)
@@ -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]";
+my $path = $ARGV[1];
+my $filename = $ARGV[2];
 
+my @types;
+
 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);
+#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();
 
-my @types;
-my $aout = $ses->request("open-ils.actor.org_types.retrieve")->gather(1);
-foreach my $type (@$aout) {
-	$types[int($type->id)] = $type;
-}
+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);
 
-print_option($tree);
+	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";
+	}
 
-$ses->disconnect();
-close FILE;
+	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);
+	push @$org_tree_html, "<option value='$sname'>" . '&#160;&#160;&#160;'x$depth . "$name</option>\n";
+	print_option($_, $org_tree_html) 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;
-}
-

Modified: branches/rel_1_4/Open-ILS/src/extras/org_tree_js.pl
===================================================================
--- branches/rel_1_4/Open-ILS/src/extras/org_tree_js.pl	2009-03-13 01:23:04 UTC (rev 12501)
+++ branches/rel_1_4/Open-ILS/src/extras/org_tree_js.pl	2009-03-13 01:24:51 UTC (rev 12502)
@@ -9,33 +9,47 @@
 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");
+# 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();
 
-# fetch the org_unit's and org_unit_type's
-my $e = OpenILS::Utils::CStoreEditor->new;
-$e->session->session_locale($locale) if ($locale);
+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");
 
-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 }
-);
+	# 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 {
     my $v = shift;
     return 'null' unless defined $v;
@@ -50,28 +64,36 @@
     return "\"$v\"";
 }
 
-my $pile = "var _l = [";
+sub build_tree_js {
+	my $types = shift;
+	my $tree = shift;
+	my $outfile = shift;
 
-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]";
-}
+	my $pile = "var _l = [";
 
-$pile .= join ',', @array;
-$pile .= "]; /* Org Units */ \n";
+	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 .= '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";
 
 

Modified: branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/advanced.html
===================================================================
--- branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/advanced.html	2009-03-13 01:23:04 UTC (rev 12501)
+++ branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/advanced.html	2009-03-13 01:24:51 UTC (rev 12502)
@@ -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>

Modified: branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/start.html
===================================================================
--- branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/start.html	2009-03-13 01:23:04 UTC (rev 12501)
+++ branches/rel_1_4/Open-ILS/web/opac/extras/slimpac/start.html	2009-03-13 01:24:51 UTC (rev 12502)
@@ -100,7 +100,7 @@
 						<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>

Modified: branches/rel_1_4/Open-ILS/web/opac/skin/default/xml/common/js_common.xml
===================================================================
--- branches/rel_1_4/Open-ILS/web/opac/skin/default/xml/common/js_common.xml	2009-03-13 01:23:04 UTC (rev 12501)
+++ branches/rel_1_4/Open-ILS/web/opac/skin/default/xml/common/js_common.xml	2009-03-13 01:24:51 UTC (rev 12502)
@@ -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>



More information about the open-ils-commits mailing list