print notice that member returned all books
[koha_fer] / koha-tmpl / opac-tmpl / prog / en / js / basket.js
index 3c9e20c..9bfd103 100644 (file)
@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////////////////////////////////
-// BASIC FUNCTIONS FOR COOKIE MANGEMENT //
+// BASIC FUNCTIONS FOR COOKIE MANAGEMENT //
 //////////////////////////////////////////////////////////////////////////////
 
 var CGIBIN = "/cgi-bin/koha/";
@@ -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 = "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,23 +115,25 @@ 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);
         }
     }
 
     if (write) {
         writeCookie(nameCookie, valCookie);
         if (selection) { // when adding a selection of records
+            updateLink(val,"add");
             return 1;
         }
         if (! NoMsgAlert ) {
-            alert(MSG_RECORD_ADDED);
+            showCartUpdate(MSG_RECORD_ADDED);
+            updateLink(val,"add");
         }
     }
 }
@@ -179,7 +185,6 @@ function addSelRecords(valSel) { // function for adding a selection of biblios t
             break;
         }
     }
-
     var msg = "";
     if (nbAdd) {
         if (i > nbAdd) {
@@ -197,9 +202,22 @@ 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 showListsUpdate(msg){
+       // set body of popup window
+       $("#listsDetails").html(msg);
+       showLists();
+       setTimeout("hideLists()",2000); 
+}
 
 function selRecord(num, status) {
     var str = document.myform.records.value
@@ -213,12 +231,24 @@ function selRecord(num, status) {
     document.myform.records.value = str;
 }
 
+function delSingleRecord(biblionumber){
+    var nameCookie = "bib_list";
+    var valCookie = readCookie(nameCookie);
+    var arrayRecords = valCookie.split("/");
+    var pos = jQuery.inArray(biblionumber,arrayRecords);
+    arrayRecords.splice(pos,1);
+    valCookie = arrayRecords.join("/");
+    writeCookie( nameCookie, valCookie );
+    updateBasket( arrayRecords.length-1 );
+    updateLink(biblionumber,"del");
+    showCartUpdate(MSG_RECORD_REMOVED);
+}
+
 function delSelRecords() {
     var recordsSel = 0;
     var end = 0;
     var nameCookie = "bib_list";
     var valCookie = readCookie(nameCookie, 1);
-
     if (valCookie) {
         var str = document.myform.records.value;
         if (str.length > 0){
@@ -227,9 +257,10 @@ function delSelRecords() {
             while (!end){
                 s = str.indexOf("/");
                 if (s>0){
-                    num = str.substring(0, s)
+                    num = str.substring(0, s);
                     str = delRecord(num,str);
                     str2 = delRecord(num,str2);
+                    updateLink(num,"del",top.opener);
                 } else {
                     end = 1;
                 }
@@ -241,7 +272,7 @@ function delSelRecords() {
                 if (rep) {
                     delCookie(nameCookie);
                     document.location = "about:blank";
-                    updateBasket(0,top.opener.document);
+                    updateBasket(0,top.opener);
                     window.close();
                 } else {
                     return;
@@ -258,7 +289,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 {
@@ -296,8 +327,9 @@ function delBasket() {
     rep = confirm(MSG_CONFIRM_DEL_BASKET);
     if (rep) {
         delCookie(nameCookie);
+        updateAllLinks(top.opener);
         document.location = "about:blank";
-        updateBasket(0,top.opener.document);
+        updateBasket(0,top.opener);
         window.close();
     }
 }
@@ -311,7 +343,7 @@ function quit() {
             delSelRecords();
         }
     }
-    updateBasket(arrayRecords.length-1,top.opener.document);
+    updateBasket(arrayRecords.length-1,top.opener);
     window.close();
 }
 
@@ -322,10 +354,20 @@ function sendBasket() {
 
     var loc = CGIBIN + "opac-sendbasket.pl?" + strCookie;
 
-    var optWin="dependant=yes,scrollbars=no,resizable=no,height=300,width=450,top=50,left=100";
+    var optWin="scrollbars=yes,resizable=yes,height=600,width=900,top=50,left=100";
     var win_form = open(loc,"win_form",optWin);
 }
 
+function downloadBasket() {
+    var nameCookie = "bib_list";
+    var valCookie = readCookie(nameCookie);
+    var strCookie = nameCookie + "=" + valCookie;
+
+    var loc = CGIBIN + "opac-downloadcart.pl?" + strCookie;
+
+    open(loc,"win_form",'scrollbars=no,resizable=no,height=300,width=450,top=50,left=100');
+}
+
 function printBasket() {
     var loc = document.location + "&print=1";
     document.location = loc;
@@ -355,22 +397,24 @@ function showLess() {
     document.location = loc;
 }
 
-function updateBasket(updated_value,target) {
-    if(typeof document.getElementById != "undefined") {
-               if(target.getElementById('basket')){
-               target.getElementById('basket').innerHTML = "<div>"+updated_value+"</div>";
-               }
-               if(target.getElementById('cartDetails')){
-                       target.getElementById('cartDetails').innerHTML = _("Your cart contains ")+updated_value+_(" items");
-               }
-    } 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+")";
+function holdSel() {
+    var items = document.getElementById('records').value;
+    if (items) {
+        parent.opener.document.location = "/cgi-bin/koha/opac-reserve.pl?biblionumbers=" + items;
+        window.close();
+    } else {
+        alert(MSG_NO_RECORD_SELECTED);
     }
+}
+
+function updateBasket(updated_value,target) {
+       if(target){
+       target.$('#basketcount').html("<span>"+updated_value+"</span>");
+    target.$('#cartDetails').html(MSG_IN_YOUR_CART+updated_value);
+       } else {
+       $('#basketcount').html("<span>"+updated_value+"</span>");
+    $('#cartDetails').html(MSG_IN_YOUR_CART+updated_value);
+       }
        var basketcount = updated_value;
 }
 
@@ -382,7 +426,11 @@ function openBiblio(dest,biblionumber) {
 
 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.
@@ -395,6 +443,90 @@ function vShelfAdd() {
                                 bibs.push("biblionumber=" +  document.bookbag_form.biblionumber[i].value);
                         }
                 }
-        return bibs.join("&");
+           if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); }
+            return bibs.join("&");
+        } else {
+            if (document.bookbag_form.biblionumber.checked) {
+                return "biblionumber=" + document.bookbag_form.biblionumber.value;
+            }
+        }
+}
+
+function showCart(){
+               var position = $("#cartmenulink").offset();
+        var scrolld = $(window).scrollTop();
+               var top = position.top + $("#cartmenulink").outerHeight();
+        if( scrolld > top ){
+            top = scrolld + 15;
+        }
+               var menuWidth = 200;
+               var buttonWidth = $("#cartmenulink").innerWidth();
+               var buttonOffset = menuWidth - buttonWidth;
+               var left = position.left -  buttonOffset;
+               $("#cartDetails").css("position","absolute").css("top",top);
+               $("#cartDetails").css("position","absolute").css("left",left);
+               $("#cartDetails").fadeIn("fast");
+}
+
+function showLists(){
+               var position = $("#listsmenulink").offset();
+              var top = position.top + $("#listsmenulink").outerHeight();
+               var menuWidth = 200;
+               var buttonWidth = $("#listsmenulink").innerWidth();
+               var buttonOffset = menuWidth - buttonWidth;
+               var left = position.left -  buttonOffset;
+               $("#listsDetails").css("position","absolute").css("top",top);
+               $("#listsDetails").css("position","absolute").css("left",left);
+               $("#listsDetails").fadeIn("fast");
+}
+
+function hideCart(){
+    $("#cartDetails").fadeOut("fast");
+}
+
+function hideLists(){
+    $("#listsDetails").fadeOut("fast");
+}
+
+function updateLink(val,op,target){
+    if(target){
+        if(op == "add"){
+            target.$("a.cart"+val).html(MSG_ITEM_IN_CART).addClass("incart");
+            target.$("a.cartR"+val).show();
+        } else {
+            target.$("a.cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart cart"+val);
+            target.$("a.cartR"+val).hide();
         }
+    } else {
+        if(op == "add"){
+            $("a.cart"+val).html(MSG_ITEM_IN_CART).addClass("incart");
+            $("a.cartR"+val).show();
+        } else {
+            $("a.cart"+val).html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart cart"+val);
+            $("a.cartR"+val).hide();
+        }
+    }
 }
+
+function updateAllLinks(target){
+    if(target){
+        target.$("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart");
+        target.$("a.cartRemove").hide();
+    } else {
+        $("a.incart").html(MSG_ITEM_NOT_IN_CART).removeClass("incart").addClass("addtocart");
+        $("a.cartRemove").hide();
+    }
+}
+
+$("#cartDetails").ready(function(){
+       $("#cartDetails,#cartmenulink").click(function(){ hideCart(); });
+       $("#cartmenulink").click(function(){ openBasket(); return false; });
+       $("#cartmenulink").hoverIntent(function(){
+               showCart();
+       },function(){
+               hideCart();
+       });
+       if(basketcount){ updateBasket(basketcount) }
+});
+
+