From: erickson Date: Wed, 18 Jul 2007 23:21:06 +0000 (+0000) Subject: backporting new JS builder: svn merge -r7563:7564 svn://svn.open-ils.org/ILS/trunk . X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f8f3cf88c7dc34ab9645caa64daa8d8373f379b9;p=Evergreen.git backporting new JS builder: svn merge -r7563:7564 svn://svn.open-ils.org/ILS/trunk . git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2@7565 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/extras/org_tree_js.pl b/Open-ILS/src/extras/org_tree_js.pl index 73eba0cdd7..17a679be5d 100644 --- a/Open-ILS/src/extras/org_tree_js.pl +++ b/Open-ILS/src/extras/org_tree_js.pl @@ -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 @@ OpenSRF::System->bootstrap_client(config_file => $ARGV[0]); 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); +sub val { + my $v = shift; + return 'null' unless defined $v; -my $types_string = OpenSRF::Utils::JSON->perl2JSON($types); -$types_string =~ s/\"/\\\"/g; + # 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 .= <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; +print "$pile\n"; -$ses->disconnect();