copy loc groups: UI round 1
authorBill Erickson <berick@esilibrary.com>
Fri, 17 Feb 2012 16:57:19 +0000 (11:57 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 17 Feb 2012 16:57:19 +0000 (11:57 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/templates/opac/parts/org_selector.tt2
Open-ILS/src/templates/opac/parts/searchbar.tt2

index 0a1fd65..9f4a642 100644 (file)
@@ -254,6 +254,7 @@ sub load_common {
     $ctx->{search_ou} = $self->_get_search_lib();
 
     $self->staff_saved_searches_set_expansion_state if $ctx->{is_staff};
+    $self->load_copy_location_groups;
 
     return Apache2::Const::OK;
 }
@@ -282,6 +283,14 @@ sub staff_saved_searches_set_expansion_state {
     $self->ctx->{saved_searches_expanded} = $value;
 }
 
+sub load_copy_location_groups {
+    my $self = shift;
+    my $grps = $self->editor->search_asset_copy_location_group({opac_visible => 't'});
+    my %buckets;
+    push(@{$buckets{$_->owner}}, $_) for @$grps;
+    $self->ctx->{copy_location_groups} = \%buckets;
+}
+
 # physical_loc (i.e. "original location") passed in as a URL 
 # param will replace any existing physical_loc stored as a cookie.
 sub get_physical_loc {
index 96bdcbf..bd2a7bc 100644 (file)
@@ -1,33 +1,54 @@
 [%
-    BLOCK build_org_selector_options;
-        disabled = '';
-        selected = '';
-        IF can_have_vols_only AND walker.ou_type.can_have_vols != 't';
-            disabled = 'disabled="disabled"';
-        ELSIF walker.id == value;
-            selected = 'selected="selected"';
-        END;
-        IF ctx.is_staff || walker.opac_visible == 't';
-%]
-            <option value='[% walker.id | uri %]' [% selected %] [% disabled %]>
+# Org Unit Selector Widget :
+#   PROCESS build_org_selector id='selector-id' name='selector-name' 
+#       value=org_id show_loc_groups=1/0 can_have_vols_only=1/0
+
+BLOCK build_org_selector;
+    root_node = org_unit || ctx.aou_tree;
+    node_stack = [{org => root_node}] %]
+
+    <select [% IF id %] id='[% id %]' [% END %] name='[% name %]'>
+    [% 
+        WHILE node_stack.size > 0; 
+            node = node_stack.pop();
+            org_unit = node.org;
+            loc_grp = node.loc_grp;
+            ou_id = org_unit.id;
+            disabled = '';
+            selected = '';
+
+            IF ctx.is_staff || org_unit.opac_visible == 't';
+
+                IF !loc_grp;
+                    IF show_loc_groups;
+                        FOR grp IN ctx.copy_location_groups.$ou_id.sort('pos').reverse;
+                            node_stack.push({org => org_unit, loc_grp => grp});
+                        END;
+                    END;
+                    FOR child IN org_unit.children.reverse;
+                        node_stack.push({org => child});
+                    END;
+                END;
+
+                IF can_have_vols_only AND org_unit.ou_type.can_have_vols != 't';
+                    disabled = 'disabled="disabled"';
+                ELSIF ou_id == value; # TODO: test for copy_loc value
+                    selected = 'selected="selected"';
+                END %] 
+
+                <option value='[% org_unit.id | uri %]' [% selected %] [% disabled %]> 
                 [%
-                    pad = walker.ou_type.depth * 2;
+                    depth = org_unit.ou_type.depth;
+                    IF loc_grp; depth = depth + 1; END;
+                    pad = depth * 2;
                     FOR idx IN [0..pad]; '&nbsp;'; END;
-                    walker.name | html;
+                    loc_grp ? loc_grp.name : org_unit.name | html ;
                 %]
-            </option>
-            [% FOR child IN walker.children;
-                PROCESS build_org_selector_options walker=child value=value;
+                </option> 
+
+                [%
             END;
         END;
-    END;
-
-    # XXX TODO probably put this BLOCK somewhere else so it can be used widely.
-    # Org Unit Selector Widget :
-    #   PROCESS build_org_selector id='selector-id' name='selector-name'
-    BLOCK build_org_selector;
-%]
-    <select [% IF id %] id='[% id %]' [% END %] name='[% name %]'>
-    [% PROCESS build_org_selector_options walker=(org_unit || ctx.aou_tree) value=value %]
+    %]
     </select>
-[%  END %]
+[% END %]
index 360bd25..97d709e 100644 (file)
@@ -21,7 +21,7 @@
                 x-webkit-speech />
         </span>
         [%- INCLUDE "opac/parts/qtype_selector.tt2";
-            l(' in '); PROCESS build_org_selector name='loc' value=ctx.search_ou;
+            l(' in '); PROCESS build_org_selector name='loc' value=ctx.search_ou show_loc_groups=1;
     %]
     <span>
         <input id='search-submit-go' type="submit" value="[% l('Search') %]" alt="[% l('Search') %]" class="opac-button"