[Koha-patches] [PATCH] bug_7264: Branch popup

Srdjan Jankovic srdjan at catalyst.net.nz
Fri Jan 6 06:12:01 CET 2012


---
 C4/Items.pm                                        |  109 ++++++++----------
 koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt |  122 +++++++++++++++++++-
 opac/opac-detail.pl                                |   12 ++-
 3 files changed, 181 insertions(+), 62 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index 0b91b65..37af776 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -1167,6 +1167,40 @@ If this is set, it is set to C<One Order>.
 sub GetItemsInfo {
     my ( $biblionumber ) = @_;
     my $dbh   = C4::Context->dbh;
+
+    my $sth_auth_val = $dbh->prepare(
+        'SELECT authorised_value
+         FROM   marc_subfield_structure
+         WHERE  kohafield=?
+    '
+    );
+
+    $sth_auth_val->execute("items.notforloan");
+    my ($authorised_valuecode_notforloan) = $sth_auth_val->fetchrow;
+    my $sthnflstatus = $dbh->prepare(
+        "SELECT lib FROM authorised_values
+            WHERE  category=?
+            AND authorised_value=?"
+    );
+
+    $sth_auth_val->execute("items.restricted");
+    my ($authorised_valuecode_restricted) = $sth_auth_val->fetchrow;
+    my $restrictedstatus = $dbh->prepare(
+        "SELECT lib,lib_opac FROM authorised_values
+            WHERE  category=?
+            AND authorised_value=?"
+    );
+
+    $sth_auth_val->execute("items.stack");
+    my ($authorised_valuecode_stack) = $sth_auth_val->fetchrow;
+    my $stackstatus = $dbh->prepare(
+        "SELECT lib
+            FROM   authorised_values
+            WHERE  category=?
+            AND    authorised_value=?
+    "
+    );
+
     # note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
     my $query = "
     SELECT items.*,
@@ -1185,7 +1219,15 @@ sub GetItemsInfo {
            items.notforloan as itemnotforloan,
            itemtypes.description,
            itemtypes.notforloan as notforloan_per_itemtype,
-           branchurl
+           branches.branchcode,
+           branches.branchname,
+           branches.branchaddress1,
+           branches.branchaddress2,
+           branches.branchaddress3,
+           branches.branchphone,
+           branches.branchemail,
+           branches.branchnotes,
+           branches.branchurl
      FROM items
      LEFT JOIN branches ON items.holdingbranch = branches.branchcode
      LEFT JOIN biblio      ON      biblio.biblionumber     = items.biblionumber
@@ -1235,57 +1277,20 @@ sub GetItemsInfo {
 # value.
             $count_reserves = $restype;
         }
-        #get branch information.....
-        my $bsth = $dbh->prepare(
-            "SELECT * FROM branches WHERE branchcode = ?
-        "
-        );
-        $bsth->execute( $data->{'holdingbranch'} );
-        if ( my $bdata = $bsth->fetchrow_hashref ) {
-            $data->{'branchname'} = $bdata->{'branchname'};
-        }
         $data->{'datedue'}        = $datedue;
         $data->{'count_reserves'} = $count_reserves;
 
         # get notforloan complete status if applicable
-        my $sthnflstatus = $dbh->prepare(
-            'SELECT authorised_value
-            FROM   marc_subfield_structure
-            WHERE  kohafield="items.notforloan"
-        '
-        );
-
-        $sthnflstatus->execute;
-        my ($authorised_valuecode) = $sthnflstatus->fetchrow;
-        if ($authorised_valuecode) {
-            $sthnflstatus = $dbh->prepare(
-                "SELECT lib FROM authorised_values
-                 WHERE  category=?
-                 AND authorised_value=?"
-            );
-            $sthnflstatus->execute( $authorised_valuecode,
+        if ($authorised_valuecode_notforloan) {
+            $sthnflstatus->execute( $authorised_valuecode_notforloan,
                 $data->{itemnotforloan} );
             my ($lib) = $sthnflstatus->fetchrow;
             $data->{notforloanvalue} = $lib;
         }
 
         # get restricted status and description if applicable
-        my $restrictedstatus = $dbh->prepare(
-            'SELECT authorised_value
-            FROM   marc_subfield_structure
-            WHERE  kohafield="items.restricted"
-        '
-        );
-
-        $restrictedstatus->execute;
-        ($authorised_valuecode) = $restrictedstatus->fetchrow;
-        if ($authorised_valuecode) {
-            $restrictedstatus = $dbh->prepare(
-                "SELECT lib,lib_opac FROM authorised_values
-                 WHERE  category=?
-                 AND authorised_value=?"
-            );
-            $restrictedstatus->execute( $authorised_valuecode,
+        if ($authorised_valuecode_restricted) {
+            $restrictedstatus->execute( $authorised_valuecode_restricted,
                 $data->{restricted} );
 
             if ( my $rstdata = $restrictedstatus->fetchrow_hashref ) {
@@ -1295,24 +1300,8 @@ sub GetItemsInfo {
         }
 
         # my stack procedures
-        my $stackstatus = $dbh->prepare(
-            'SELECT authorised_value
-             FROM   marc_subfield_structure
-             WHERE  kohafield="items.stack"
-        '
-        );
-        $stackstatus->execute;
-
-        ($authorised_valuecode) = $stackstatus->fetchrow;
-        if ($authorised_valuecode) {
-            $stackstatus = $dbh->prepare(
-                "SELECT lib
-                 FROM   authorised_values
-                 WHERE  category=?
-                 AND    authorised_value=?
-            "
-            );
-            $stackstatus->execute( $authorised_valuecode, $data->{stack} );
+        if ($authorised_valuecode_stack) {
+            $stackstatus->execute( $authorised_valuecode_stack, $data->{stack} );
             my ($lib) = $stackstatus->fetchrow;
             $data->{stack} = $lib;
         }
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
index 8cba98b..515c1e4 100755
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt
@@ -188,6 +188,101 @@ function renderPagination(index, total, ul, highlIndex)
 }//renderPagination
 [% END %]
 
+var branch_info = [% branch_info_json %];
+function branch_popup(branchcode) {
+    if (branchcode == "") return;
+
+    var b_i = branch_info[branchcode];
+    if (!b_i) return;
+
+    var info = "<strong>" + b_i.branchname + "</strong><br/>"
+             + b_i.branchaddress1;
+    if (b_i.branchaddress2) info = info + "<br/>" + b_i.branchaddress2;
+    if (b_i.branchaddress3) info = info + "<br/>" + b_i.branchaddress3;
+    if (b_i.branchnotes)    info = info + "<br/><br/>" + b_i.branchnotes;
+    if (b_i.branchphone)    info = info + "<br/><br/>Tel. " + b_i.branchphone;
+    if (b_i.branchemail)    info = info + "<br/><br/><a href='mailto:'" + b_i.branchemail + "'>" + b_i.branchemail + "</a>";
+    if (b_i.branchurl)      info = info + "<br/><br/><a href='" + b_i.branchurl + "' target='_new'>" + b_i.branchurl + "</a>";
+
+    popup(info);
+}
+
+// create the popup box - remember to give it some width in your styling 
+document.write('<div id="pup" style="position:abolute; display:none; z-index:200;"></div>');
+
+var minMargin = 15; // set how much minimal space there should be to
+                            // between the popup and everything else (borders, mouse)
+var ready = false; // we are ready when the mouse event is set up
+var default_width = '200px'; // will be set to width from css in document.ready
+
+var follow_mouse = true;
+jQuery(document).ready(function(){
+    $('#pup').hide();
+    default_width = $('#pup').width();
+    // set dynamic coords when the mouse moves
+    $(document).mousemove(function(e){ 
+        if (!follow_mouse) return;
+
+        var x,y;
+      
+        x = $(document).scrollLeft() + e.clientX;
+        y = $(document).scrollTop() + e.clientY;
+
+        x += 10; // important: if the popup is where the mouse is, the hoverOver/hoverOut events flicker
+      
+        var x_y = nudge(x,y); // avoids edge overflow
+      
+        // remember: the popup is still hidden
+        $('#pup').css('top', x_y[1] + 'px');
+        $('#pup').css('left', x_y[0] + 'px');
+    });
+
+    ready = true;
+});
+
+// avoid edge overflow
+function nudge(x,y)
+{
+    var win = $(window);
+    
+    // When the mouse is too far on the right, put window to the left
+    var xtreme = $(document).scrollLeft() + win.width() - $('#pup').width() - minMargin;
+    if(x > xtreme) {
+        x -= $('#pup').width() + 2 * minMargin;
+    }
+    x = max(x, 0);
+
+    // When the mouse is too far down, move window up
+    if((y + $('#pup').height()) > (win.height() +  $(document).scrollTop())) {
+        y -= $('#pup').height() + minMargin;
+    }
+
+    return [ x, y ];
+}
+
+function popup(msg, width)
+{
+    if (typeof width === "undefined"){
+        width = default_width;
+    }
+    // write content and display
+    if (ready) {
+        $('#pup').width(width).html(msg).show();
+        follow_mouse = false;
+    }
+    // make sure popup goes away on mouse out
+    $(this).mouseout(function(e){
+        follow_mouse = true;
+        $('#pup').hide().width(default_width);
+    });
+}
+
+
+function max(a,b){
+    if (a>b) return a;
+    else return b;
+}
+
 
 YAHOO.util.Event.onContentReady("furtherm", function () {
     $("#furtherm").css("display","block").css("visibility","hidden");
@@ -206,6 +301,20 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
 	
 //]]>
 </script>
+<style>
+#pup {
+  position:absolute;
+  z-index:200; /* aaaalways on top*/
+  padding: 3px;
+  margin-left: 10px;
+  margin-top: 5px;
+  width: 250px;
+  border: 1px solid black;
+  background-color: #aaa;
+  color: white;
+  font-size: 0.95em;
+}
+</style>
 [% IF ( opacuserlogin ) %][% IF ( loggedinusername ) %][% IF ( TagsEnabled ) %]<style type="text/css">
     #addtagl { display: none; }
 </style>[% END %][% END %][% END %]
@@ -586,7 +695,18 @@ YAHOO.util.Event.onContentReady("furtherm", function () {
 	    </tr></thead>
 	    <tbody>[% FOREACH ITEM_RESULT IN ITEM_RESULTS %]
 	    <tr>[% IF ( item_level_itypes ) %]<td>[% UNLESS ( noItemTypeImages ) %][% IF ( ITEM_RESULT.imageurl ) %]<img src="[% ITEM_RESULT.imageurl %]" title="[% ITEM_RESULT.description %]" alt="[% ITEM_RESULT.description %]" />[% END %][% END %] [% ITEM_RESULT.description %]</td>[% END %]
-		<td>[% UNLESS ( singleBranchMode ) %][% IF ( ITEM_RESULT.branchurl ) %]<a href="[% ITEM_RESULT.branchurl %]">[% ITEM_RESULT.branchname %]</a>[% ELSE %][% ITEM_RESULT.branchname %][% END %][% END %] <span class="shelvingloc">[% ITEM_RESULT.location_description %]</span> </td>
+		<td>
+        <span onMouseOver="branch_popup('[% ITEM_RESULT.branchcode %]')">
+        [% UNLESS ( singleBranchMode ) %]
+            [% IF ( ITEM_RESULT.branchurl ) %]
+            <a href="[% ITEM_RESULT.branchurl %]">[% ITEM_RESULT.branchname %]</a>
+            [% ELSE %]
+            [% ITEM_RESULT.branchname %]
+            [% END %]
+        [% END %]
+        </span>
+        <span class="shelvingloc">[% ITEM_RESULT.location_description %]</span>
+        </td>
 		[% IF ( itemdata_ccode ) %]<td>[% ITEM_RESULT.ccode %]</td>[% END %]
 		<td>[% IF ( ITEM_RESULT.itemcallnumber ) %] [% ITEM_RESULT.itemcallnumber %][% IF ( OPACShelfBrowser ) %] (<a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% ITEM_RESULT.biblionumber %]&amp;shelfbrowse_itemnumber=[% ITEM_RESULT.itemnumber %]#shelfbrowser">Browse Shelf</a>)[% END %][% END %]</td>
 		[% IF ( itemdata_enumchron ) %]<td>[% ITEM_RESULT.enumchron %]</td>[% END %]
diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl
index e2fb069..a0fecbc 100755
--- a/opac/opac-detail.pl
+++ b/opac/opac-detail.pl
@@ -465,6 +465,7 @@ my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4:
 my $norequests = 1;
 my $branches = GetBranches();
 my %itemfields;
+my %itembranches;
 for my $itm (@items) {
     $norequests = 0
        if ( (not $itm->{'wthdrawn'} )
@@ -516,6 +517,13 @@ for my $itm (@items) {
         $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
         $itm->{transfertto}   = $branches->{$transfertto}{branchname};
      }
+
+     if (my $branchcode = $itm->{branchcode}) {
+         $itembranches{$branchcode} ||= { map { $_ => $itm->{$_} }
+                                              qw( branchname branchaddress1 branchaddress2 branchaddress3
+                                                  branchphone branchemail branchnotes branchurl )
+                                              };
+    }
 }
 
 ## get notes and subjects from MARC record
@@ -535,7 +543,7 @@ my $subtitle         = GetRecordValue('subtitle', $record, GetFrameworkCode($bib
                      MARCAUTHORS             => $marcauthorsarray,
                      MARCSERIES              => $marcseriesarray,
                      MARCURLS                => $marcurlsarray,
-		     MARCHOSTS               => $marchostsarray,
+                     MARCHOSTS               => $marchostsarray,
                      norequests              => $norequests,
                      RequestOnOpac           => C4::Context->preference("RequestOnOpac"),
                      itemdata_ccode          => $itemfields{ccode},
@@ -633,8 +641,10 @@ if(C4::Context->preference("ISBD")) {
 	$template->param(ISBD => 1);
 }
 
+use JSON;
 $template->param(
     ITEM_RESULTS        => \@items,
+    branch_info_json    => encode_json(\%itembranches),
     subscriptionsnumber => $subscriptionsnumber,
     biblionumber        => $biblionumber,
     subscriptions       => \@subs,
-- 
1.6.5



More information about the Koha-patches mailing list