(bug #1578) Add the (quasi)full COinS(Zotero) support
[koha.git] / koha-tmpl / opac-tmpl / prog / en / js / basket.js
index 5fd91a2..3c3bbcd 100644 (file)
@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////////////////////////////////
-// BASIC FUNCTIONS FOR COOKIE MANGEMENT //
+// BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
 //////////////////////////////////////////////////////////////////////////////
 
 var CGIBIN = "/cgi-bin/koha/";
@@ -11,7 +11,7 @@ var valCookie = readCookie(nameCookie);
 if(valCookie){
     var arrayRecords = valCookie.split("/");
     if(arrayRecords.length > 0){
-        var basketcount = " ("+(arrayRecords.length-1)+")";
+        var basketcount = arrayRecords.length-1;
     } else {
         var basketcount = "";
     }
@@ -58,7 +58,11 @@ function readCookie(name, wd) {
 function delCookie(name) {
     var exp = new Date();
     exp.setTime(exp.getTime()-1);
+       if(parent.opener){
     parent.opener.document.cookie = name + "=null; expires=" + exp.toGMTString();
+       } else {
+       document.cookie = name + "=null; expires=" + exp.toGMTString();
+       }
 }
 
 ///////////////////////////////////////////////////////////////////
@@ -76,13 +80,13 @@ function openBasket() {
     if ( strCookie ) {
         var iW = 820;
         var iH = 450;
-        var optWin = "dependant=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=no,adressbar=no,height="+iH+",width="+iW;
+        var optWin = "dependant=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=yes,height="+iH+",width="+iW;
         var loc = CGIBIN + "opac-basket.pl?" + strCookie;
         var basket = open(loc, "basket", optWin);
         if (window.focus) {basket.focus()}
     }
     else {
-        alert(MSG_BASKET_EMPTY);
+        showCartUpdate(MSG_BASKET_EMPTY);
     }
 }
 
@@ -94,7 +98,7 @@ function addRecord(val, selection,NoMsgAlert) {
     if ( ! valCookie ) { // empty basket
         valCookie = val + '/';
         write = 1;
-        updateBasket(1,document);
+        updateBasket(1);
     }
     else {
         // is this record already in the basket ?
@@ -111,13 +115,13 @@ function addRecord(val, selection,NoMsgAlert) {
                 return 0;
             }
             if (! NoMsgAlert ) {
-                alert(MSG_RECORD_IN_BASKET);
+                showCartUpdate(MSG_RECORD_IN_BASKET);
             }
         }
         else {
             valCookie += val + '/';
             write = 1;
-            updateBasket(arrayRecords.length,document);
+            updateBasket(arrayRecords.length);
         }
     }
 
@@ -127,19 +131,26 @@ function addRecord(val, selection,NoMsgAlert) {
             return 1;
         }
         if (! NoMsgAlert ) {
-            alert(MSG_RECORD_ADDED);
+            showCartUpdate(MSG_RECORD_ADDED);
         }
     }
 }
 
+function AllAreChecked(s){
+       if (! s.length) { return false;}
+       var l = s.length;
+       for (var i=0; i < l; i++) {
+               if(! s[i].checked) { return false; }
+       }
+       return true;
+}
+
 function SelectAll(){
     if(document.bookbag_form.biblionumber.length > 0) {
-        for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
-            if (document.bookbag_form.select_all.checked) {
-                document.bookbag_form.biblionumber[i].checked=true;
-            } else {
-                document.bookbag_form.biblionumber[i].checked=false;
-            }
+               var checky = AllAreChecked(document.bookbag_form.biblionumber);
+               var l = document.bookbag_form.biblionumber.length;
+        for (var i=0; i < l; i++) {
+            document.bookbag_form.biblionumber[i].checked = (checky) ? false : true;
         }
     }
 }
@@ -159,11 +170,6 @@ function addMultiple(){
     }
 }
 
-function addSelToShelf() {
-    var items = document.getElementById('records').value;
-    document.location = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
-}
-
 function addSelRecords(valSel) { // function for adding a selection of biblios to the basket
                                                 // from the results list
     var arrayRecords = valSel.split("/");
@@ -177,7 +183,6 @@ function addSelRecords(valSel) { // function for adding a selection of biblios t
             break;
         }
     }
-
     var msg = "";
     if (nbAdd) {
         if (i > nbAdd) {
@@ -195,9 +200,15 @@ function addSelRecords(valSel) { // function for adding a selection of biblios t
             msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !";
         }
     }
-    alert(msg);
+       showCartUpdate(msg);
 }
 
+function showCartUpdate(msg){
+       // set body of popup window
+       $("#cartDetails").html(msg);
+       showCart();
+       setTimeout("hideCart()",2000);  
+}
 
 function selRecord(num, status) {
     var str = document.myform.records.value
@@ -239,7 +250,7 @@ function delSelRecords() {
                 if (rep) {
                     delCookie(nameCookie);
                     document.location = "about:blank";
-                    updateBasket(0,top.opener.document);
+                    updateBasket(0,top.opener);
                     window.close();
                 } else {
                     return;
@@ -256,7 +267,7 @@ function delSelRecords() {
         var valCookie = readCookie(nameCookie, 1);
         strCookie = nameCookie + "=" + valCookie;
         var arrayRecords = valCookie.split("/");
-        updateBasket(arrayRecords.length-1,top.opener.document);
+        updateBasket(arrayRecords.length-1,top.opener);
         document.location = CGIBIN + "opac-basket.pl?" + strCookie;
     }
     else {
@@ -295,7 +306,7 @@ function delBasket() {
     if (rep) {
         delCookie(nameCookie);
         document.location = "about:blank";
-        updateBasket(0,top.opener.document);
+        updateBasket(0,top.opener);
         window.close();
     }
 }
@@ -309,7 +320,7 @@ function quit() {
             delSelRecords();
         }
     }
-    updateBasket(arrayRecords.length-1,top.opener.document);
+    updateBasket(arrayRecords.length-1,top.opener);
     window.close();
 }
 
@@ -354,16 +365,14 @@ function showLess() {
 }
 
 function updateBasket(updated_value,target) {
-    if(typeof document.getElementById != "undefined") {
-        target.getElementById('basket').innerHTML = " ("+updated_value+")";
-    } else if (typeof document.layers != "undefined") {
-        target.layers['basket'].open();
-        target.layers['basket'].write(" ("+updated_value+")");
-        target.layers['basket'].close();
-    } else if(typeof document.all != "undefined" &&  typeof
-document.getElementById == "undefined") {
-        target.all['basket'].innerHTML = " ("+updated_value+")";
-    }
+       if(target){
+       target.$('#basketcount').html("<span>"+updated_value+"</span>");
+       target.$('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items"));
+       } else {
+       $('#basketcount').html("<span>"+updated_value+"</span>");
+       $('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items"));
+       }
+       var basketcount = updated_value;
 }
 
 function openBiblio(dest,biblionumber) {
@@ -371,3 +380,57 @@ function openBiblio(dest,biblionumber) {
     opener.document.location = openerURL;
     opener.focus();
 }
+
+function addSelToShelf() {
+    var items = document.getElementById('records').value;
+       if(items){
+    document.location = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items;
+       } else {
+        alert(MSG_NO_RECORD_SELECTED);
+    }
+}
+
+///  vShelfAdd()  builds url string for multiple-biblio adds.
+
+function vShelfAdd() {
+        bibs= new Array;
+        if(document.bookbag_form.biblionumber.length > 0) {
+                for (var i=0; i < document.bookbag_form.biblionumber.length; i++) {
+                        if (document.bookbag_form.biblionumber[i].checked) {
+                                bibs.push("biblionumber=" +  document.bookbag_form.biblionumber[i].value);
+                        }
+                }
+            return bibs.join("&");
+        } else {
+            if (document.bookbag_form.biblionumber.checked) {
+                return "biblionumber=" + document.bookbag_form.biblionumber.value;
+            }
+        }
+}
+
+function showCart(){
+               var position = $("#cartmenulink").offset({border: true,margin:false});
+               var top = position.top + $("#cartmenulink").outerHeight();
+               var left = position.left - 105;
+               $("#cartDetails").css("position","absolute").css("top",top);
+               $("#cartDetails").css("position","absolute").css("left",left);
+               $("#cartDetails").fadeIn("fast",function(){
+                       $("#cartDetails").dropShadow({left: 3, top: 3, blur: 0,  color: "#000", opacity: 0.1});
+               });     
+}
+
+function hideCart(){
+                $(".dropShadow").hide();
+                $("#cartDetails").fadeOut("fast");
+}
+
+$("#cartDetails").ready(function(){
+       $("#cartDetails,#cartmenulink").click(function(){ hideCart(); });
+       $("#cartmenulink").click(function(){ openBasket(); return false; });
+       $("#cartmenulink").hoverIntent(function(){
+               showCart();
+       },function(){
+               hideCart();
+       });
+       if(basketcount){ updateBasket(basketcount) }
+});