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_*/;
14 OpenILS::Application::Storage::CDBI->connection($config{dsn},$config{usr});
15 OpenILS::Application::Storage::CDBI->db_Main->{ AutoCommit } = 1;
19 #-------------------------------------------------------------------------------
21 #-------------------------------------------------------------------------------
23 my %org_cols = ( qw/id SysID name Name parent_ou Parent ou_type OrgUnitType shortname ShortName/ );
25 my @col_display_order = ( qw/id name shortname ou_type parent_ou/ );
27 if (my $action = $cgi->param('action')) {
28 if ( $action eq 'Update' ) {
29 for my $id ( ($cgi->param('id')) ) {
30 my $u = actor::org_unit->retrieve($id);
31 for my $col ( keys %org_cols ) {
32 next if ($cgi->param($col."_$id") =~ /Select One/o);
33 $u->$col( $cgi->param($col."_$id") );
37 } elsif ( $action eq 'Add New' ) {
38 actor::org_unit->create( { map { defined($cgi->param($_)) ? ($_ => $cgi->param($_)) : () } keys %org_cols } );
42 #-------------------------------------------------------------------------------
44 #-------------------------------------------------------------------------------
47 Content-type: text/html
54 border: dashed lightgrey 1px;
55 background-color: #EEE;
56 border-collapse: collapse;
68 border: solid lightgrey 1px;
72 background-color: lightblue;
73 border: solid blue 1px;
78 <script language='javascript' src='/js/widgets/xtree.js'></script>
81 <body style='padding: 25px;'>
83 <a href="$config{index}">Home</a>
85 <h1>Library Hierarchy Setup</h1>
89 my $uri = $cgi->url(-relative=>1);
92 for my $lib ( actor::org_unit->search( {parent_ou=>undef} ) ) {
93 my $name = $lib->name;
96 <div style="float: left;">
97 <script language='javascript'>
99 function getById (id) { return document.getElementById(id); }
100 function createAppElement (el) { return document.createElement(el); }
101 function createAppTextNode (txt) { return document.createTextNode(txt); }
103 var node_$lib = new WebFXTree('$name','$uri?action=child&id=$lib');
109 for my $lib ( actor::org_unit->search_like( {parent_ou => '%'}, {order_by => 'id'} ) ) {
110 my $name = $lib->name;
112 my $parent = $lib->parent_ou;
114 var node_$lib = new WebFXTreeItem('$name','$uri?action=child&id=$lib');
116 }for my $lib ( sort {$a->name cmp $b->name} actor::org_unit->retrieve_all ) {
117 my $parent = $lib->parent_ou;
120 node_$parent.add(node_$lib);
125 document.write(node_$top);
132 #-------------------------------------------------------------------------------
134 #-------------------------------------------------------------------------------
136 if (my $action = $cgi->param('action')) {
137 if ( $action eq 'child' ) {
138 my $id = $cgi->param('id');
140 my $node = actor::org_unit->retrieve($id);
141 #-----------------------------------------------------------------------
143 #-----------------------------------------------------------------------
145 print "<h2>Edit ".$node->name."</h2>";
146 print "<form method='POST'>".
147 "<table class='table_class'><tr class='header_class'>\n";
155 td("<input type='text' name='name_$node' value=\"". $node->name() ."\">"),
158 th($org_cols{shortname}),
159 td("<input type='text' name='shortname_$node' value='". $node->shortname() ."'>"),
162 th($org_cols{ou_type}),
163 td("<select name='ou_type_$node'>".do{
164 my $out = '<option>-- Select One --</option>';
165 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
166 $out .= "<option value='$type' ".do {
167 if ($node->ou_type == $type->id) {
169 }}.'>'.$type->name.'</option>'
175 th($org_cols{parent_ou}),
176 td("<select name='parent_ou_$node'>".do{
177 my $out = '<option>-- Select One --</option>';
178 for my $org ( sort {$a->id <=> $b->id} actor::org_unit->retrieve_all) {
179 $out .= "<option value='$org' ".do {
180 if ($node->parent_ou == $org->id) {
182 }}.'>'.do{' 'x$org->ou_type->depth}.$org->name.'</option>'
185 }."</select><input type='hidden' value='$node' name='id'>"),
188 print Tr( "<td colspan='2'><input type='submit' name='action' value='Update'/></td>" );
190 print "</table></form><hr/>";
193 print "<h2>New Child</h2>";
195 print "<form method='POST'>".
196 "<table class='table_class'>\n";
200 td("<input type='text' name='name'>"),
203 th($org_cols{shortname}),
204 td("<input type='text' name='shortname'>"),
207 th($org_cols{ou_type}),
208 td("<select name='ou_type'>".do{
209 my $out = '<option>-- Select One --</option>';
210 for my $type ( sort {$a->depth <=> $b->depth} actor::org_unit_type->retrieve_all) {
211 $out .= "<option value='$type'>".$type->name.'</option>'
216 print Tr( "<td colspan='2'><input type='hidden' value='$node' name='parent_ou'>",
217 "<input type='submit' name='action' value='Add New'/></td>" );
218 print "</table></form><hr/>";
223 print "</div></body></html>";