[open-ils-commits] r7565 - branches/rel_1_2/Open-ILS/src/extras
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jul 18 19:21:09 EDT 2007
Author: erickson
Date: 2007-07-18 19:21:06 -0400 (Wed, 18 Jul 2007)
New Revision: 7565
Modified:
branches/rel_1_2/Open-ILS/src/extras/org_tree_js.pl
Log:
backporting new JS builder: svn merge -r7563:7564 svn://svn.open-ils.org/ILS/trunk .
Modified: branches/rel_1_2/Open-ILS/src/extras/org_tree_js.pl
===================================================================
--- branches/rel_1_2/Open-ILS/src/extras/org_tree_js.pl 2007-07-18 23:15:46 UTC (rev 7564)
+++ branches/rel_1_2/Open-ILS/src/extras/org_tree_js.pl 2007-07-18 23:21:06 UTC (rev 7565)
@@ -1,9 +1,11 @@
+#!/usr/bin/perl
+use strict; use warnings;
+# ------------------------------------------------------------
# turns the orgTree and orgTypes into js files
+# ------------------------------------------------------------
-use OpenSRF::AppSession;
use OpenSRF::System;
-use OpenSRF::Utils::JSON;
use OpenILS::Utils::Fieldmapper;
use OpenSRF::Utils::SettingsClient;
use OpenSRF::Utils::Cache;
@@ -13,33 +15,58 @@
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');
+# fetch the org_unit's and org_unit_type's
+my $e = OpenILS::Utils::CStoreEditor->new;
+my $tree = $e->retrieve_all_actor_org_unit;
+my $types = $e->retrieve_all_actor_org_unit_type;
-my $ses = OpenSRF::AppSession->create("open-ils.storage");
-my $tree = $ses->request("open-ils.storage.direct.actor.org_unit.retrieve.all.atomic")->gather(1);
-my $types = $ses->request("open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic")->gather(1);
-my $types_string = OpenSRF::Utils::JSON->perl2JSON($types);
-$types_string =~ s/\"/\\\"/g;
+sub val {
+ my $v = shift;
+ return 'null' unless defined $v;
+ # required for JS code this is checking truthness
+ # without using isTrue() (1/0 vs. t/f)
+ return 1 if $v eq 't';
+ return 0 if $v eq 'f';
+
+ return "\"$v\"";
+}
+
my $pile = "var _l = [";
my @array;
for my $o (@$tree) {
- my ($i,$t,$p,$n,$v) = ($o->id,$o->ou_type,$o->parent_ou,$o->name,$o->opac_visible);
- push @array, "[$i,$t,$p,\"$n\",\"$v\"]";
+ my ($i,$t,$p,$n,$v) = ($o->id,$o->ou_type,val($o->parent_ou),$o->name,val($o->opac_visible));
+ $p ||= 'null';
+ push @array, "[$i,$t,$p,\"$n\",$v]";
}
+
$pile .= join ',', @array;
-$pile .= <<JS;
-];
-JS
+$pile .= "];\n";
-$pile .= "var globalOrgTypes = JSON2js(\"$types_string\");";
-print $pile;
+$pile .= 'globalOrgTypes = [';
+for my $t (@$types) {
+ $pile .= 'new aout([null,null,null,null,'.
+ val($t->can_have_users).','.
+ val($t->can_have_vols).','.
+ val($t->depth).','.
+ val($t->id).','.
+ val($t->name).','.
+ val($t->opac_label).','.
+ val($t->parent).']), ';
+}
+$pile =~ s/, $//; # remove trailing comma
+$pile .= '];';
+print "$pile\n";
-$ses->disconnect();
+
More information about the open-ils-commits
mailing list