4 use OpenILS::Application::Storage;
5 use OpenILS::Application::Storage::CDBI;
7 # I need to abstract the driver loading away...
8 use OpenILS::Application::Storage::Driver::Pg;
10 use CGI qw/:standard start_*/;
12 OpenILS::Application::Storage::CDBI->connection('dbi:Pg:host=10.0.0.2;dbname=open-ils-dev', 'postgres');
13 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
17 #-------------------------------------------------------------------------------
19 #-------------------------------------------------------------------------------
21 my %org_cols = ( qw/id SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName/ );
23 my @col_display_order = ( qw/id name shortname ou_type parent_ou/ );
25 if (my $action = $cgi->param('action')) {
26 if ( $action eq 'Update' ) {
27 for my $id ( ($cgi->param('id')) ) {
28 my $u = actor::org_unit->retrieve($id);
29 for my $col ( keys %org_cols ) {
30 $u->$col( $cgi->param($col."_$id") );
34 } elsif ( $action eq 'Add New' ) {
35 actor::org_unit->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
39 #-------------------------------------------------------------------------------
41 #-------------------------------------------------------------------------------
44 Content-type: text/html
51 border: dashed lightgrey 1px;
52 background-color: #EEE;
53 border-collapse: collapse;
61 border: solid lightgrey 1px;
65 background-color: lightblue;
69 <script language='javascript' src='/js/widgets/xtree.js'></script>
72 <body style='padding: 25px;'>
74 <h1>Library Hierarchy Setup</h1>
79 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
80 my $name = $lib->name;
83 <div style="float: left;">
84 <script language='javascript'>
86 function getById (id) { return document.getElementById(id); }
87 function createAppElement (el) { return document.createElement(el); }
88 function createAppTextNode (txt) { return document.createTextNode(txt); }
90 var node_$lib = new WebFXTree('$name');
96 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'id'} ) ) {
97 my $name = $lib->name;
99 my $parent = $lib->parent_ou;
100 my $uri = $cgi->url(-relative=>1);
102 var node_$lib = new WebFXTreeItem('$name','$uri?action=child&id=$lib');
104 }for my $lib ( sort {$a->name cmp $b->name} actor::org_unit->retrieve_all ) {
105 my $parent = $lib->parent_ou;
108 node_$parent.add(node_$lib);
113 document.write(node_$top);
120 #-------------------------------------------------------------------------------
122 #-------------------------------------------------------------------------------
124 if (my $action = $cgi->param('action')) {
125 if ( $action eq 'child' ) {
126 my $id = $cgi->param('id');
128 my $node = actor::org_unit->retrieve($id);
129 #-----------------------------------------------------------------------
131 #-----------------------------------------------------------------------
133 print "<h2>Edit ".$node->name."</h2>";
134 print "<form method='POST'>".
135 "<table class='table_class'><tr class='header_class'>\n";
143 td("<input type='text' name='name_$node' value='". $node->name() ."'>"),
146 th($org_cols{shortname}),
147 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
150 th($org_cols{ou_type}),
151 td("<select name='ou_type_$node'>".do{
153 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
154 $out .= "<option value='$type' ".do {
155 if ($node->ou_type == $type->id) {
157 }}.'>'.$type->name.'</option>'
163 th($org_cols{parent_ou}),
164 td("<select name='parent_ou_$node'>".do{
166 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
167 $out .= "<option value='$org' ".do {
168 if ($node->parent_ou == $org->id) {
170 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
173 }."</select><input type='hidden' value='$node' name='id'>"),
176 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
178 print "</table></form><hr/>";
181 print "<h2>New Child</h2>";
183 print "<form method='POST'>".
184 "<table class='table_class'>\n";
188 td("<input type='text' name='name'>"),
191 th($org_cols{shortname}),
192 td("<input type='text' name='shortname'>"),
195 th($org_cols{ou_type}),
196 td("<select name='ou_type_$node'>".do{
198 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
199 $out .= "<option value='$type'>".$type->name.'</option>'
204 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
205 "<input type='submit' name='action' value='Add New'/></td>" );
206 print "</table></form><hr/>";
211 print "</div></body></html>";