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;
65 border: solid lightgrey 1px;
69 background-color: lightblue;
70 border: solid blue 1px;
75 <script language='javascript' src='/js/widgets/xtree.js'></script>
78 <body style='padding: 25px;'>
80 <h1>Library Hierarchy Setup</h1>
84 my $uri = $cgi->url(-relative=>1);
87 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
88 my $name = $lib->name;
91 <div style="float: left;">
92 <script language='javascript'>
94 function getById (id) { return document.getElementById(id); }
95 function createAppElement (el) { return document.createElement(el); }
96 function createAppTextNode (txt) { return document.createTextNode(txt); }
98 var node_$lib = new WebFXTree('$name','$uri?action=child&id=$lib');
104 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'id'} ) ) {
105 my $name = $lib->name;
107 my $parent = $lib->parent_ou;
109 var node_$lib = new WebFXTreeItem('$name','$uri?action=child&id=$lib');
111 }for my $lib ( sort {$a->name cmp $b->name} actor::org_unit->retrieve_all ) {
112 my $parent = $lib->parent_ou;
115 node_$parent.add(node_$lib);
120 document.write(node_$top);
127 #-------------------------------------------------------------------------------
129 #-------------------------------------------------------------------------------
131 if (my $action = $cgi->param('action')) {
132 if ( $action eq 'child' ) {
133 my $id = $cgi->param('id');
135 my $node = actor::org_unit->retrieve($id);
136 #-----------------------------------------------------------------------
138 #-----------------------------------------------------------------------
140 print "<h2>Edit ".$node->name."</h2>";
141 print "<form method='POST'>".
142 "<table class='table_class'><tr class='header_class'>\n";
150 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
153 th($org_cols{shortname}),
154 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
157 th($org_cols{ou_type}),
158 td("<select name='ou_type_$node'>".do{
159 my $out = '<option>-- Select One --</option>';
160 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
161 $out .= "<option value='$type' ".do {
162 if ($node->ou_type == $type->id) {
164 }}.'>'.$type->name.'</option>'
170 th($org_cols{parent_ou}),
171 td("<select name='parent_ou_$node'>".do{
172 my $out = '<option>-- Select One --</option>';
173 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
174 $out .= "<option value='$org' ".do {
175 if ($node->parent_ou == $org->id) {
177 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
180 }."</select><input type='hidden' value='$node' name='id'>"),
183 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
185 print "</table></form><hr/>";
188 print "<h2>New Child</h2>";
190 print "<form method='POST'>".
191 "<table class='table_class'>\n";
195 td("<input type='text' name='name'>"),
198 th($org_cols{shortname}),
199 td("<input type='text' name='shortname'>"),
202 th($org_cols{ou_type}),
203 td("<select name='ou_type'>".do{
204 my $out = '<option>-- Select One --</option>';
205 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
206 $out .= "<option value='$type'>".$type->name.'</option>'
211 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
212 "<input type='submit' name='action' value='Add New'/></td>" );
213 print "</table></form><hr/>";
218 print "</div></body></html>";