From 77bdf4fe8cb55c428bfa4fdd112c70ff1b7281a7 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Mon, 22 Feb 2021 17:51:16 +0000 Subject: [PATCH] Bug 27754: Correct eslint errors in basket.js This patch makes minor changes to basket.js in the staff interface templates in order to quiet warnings from ESLint. Besides whitespace, most changes are to correct undeclared or unnecessarily declared variables. To test, apply the patch and verify that the cart still works correctly. - Perform a catalog search in the staff interface. - Test adding single or multiple items to the cart from the search results page. - Testing adding and removing titles to the cart from the bibliographic detail page. - Open the cart and test the various controls in the toolbar to confirm that they still work correctly. Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart (cherry picked from commit ae62da0ff6a3fa5df3e01fce656fccc02ce6a55e) Signed-off-by: Fridolin Somers (cherry picked from commit 7666b52cec8d6004b6824f78667d52de4088f887) Signed-off-by: Andrew Fuerste-Henry --- koha-tmpl/intranet-tmpl/prog/js/basket.js | 101 +++++++++++++--------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/basket.js b/koha-tmpl/intranet-tmpl/prog/js/basket.js index aa5320f844..6387903193 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/basket.js +++ b/koha-tmpl/intranet-tmpl/prog/js/basket.js @@ -1,4 +1,5 @@ -/* global MSG_BASKET_EMPTY MSG_RECORD_IN_BASKET MSG_RECORD_ADDED MSG_NRECORDS_IN_BASKET MSG_NRECORDS_ADDED MSG_NO_RECORD_ADDED MSG_RECORD_REMOVED MSG_CONFIRM_DEL_BASKET MSG_CONFIRM_DEL_RECORDS MSG_IN_YOUR_CART MSG_NO_RECORD_SELECTED MSG_ITEM_IN_CART MSG_ITEM_NOT_IN_CART */ +/* global __ getContextBiblioNumbers */ +/* exported readCookie readCookieValue SelectAll addMultiple selRecord delSingleRecord delBasket quit sendBasket downloadBasket printBasket showMore showLess openBiblio addSelToShelf vShelfAdd */ ////////////////////////////////////////////////////////////////////////////// // BASIC FUNCTIONS FOR COOKIE MANAGEMENT // @@ -9,16 +10,17 @@ var CGIBIN = "/cgi-bin/koha/"; var nameCookie = "intranet_bib_list"; var nameParam = "bib_list"; var valCookie = readCookie(nameCookie); +var basketcount; if(valCookie){ var arrayRecords = valCookie.split("/"); if(arrayRecords.length > 0){ - var basketcount = arrayRecords.length-1; + basketcount = arrayRecords.length-1; } else { - var basketcount = ""; + basketcount = ""; } } else { - var basketcount = ""; + basketcount = ""; } function writeCookie(name, val, wd) { @@ -39,7 +41,6 @@ function readCookieValue (str, val_beg) { function readCookie(name, wd) { var str_name = name + "="; - var str_len = str_name.length; var str_cookie = ""; if (wd) { str_cookie = parent.opener.document.cookie; @@ -47,13 +48,13 @@ function readCookie(name, wd) { else { str_cookie = parent.document.cookie; } - // fixed - getting the part of the basket that is bib_list - var cookie_parts = str_cookie.split(";"); - for(var i=0;i < cookie_parts.length;i++) { - var c = cookie_parts[i]; - while (c.charAt(0)==' ') c = c.substring(1,c.length); - if(c.indexOf(str_name) === 0) return c.substring(str_name.length,c.length); - } + // fixed - getting the part of the basket that is bib_list + var cookie_parts = str_cookie.split(";"); + for(var i=0;i < cookie_parts.length;i++) { + var c = cookie_parts[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if(c.indexOf(str_name) === 0) return c.substring(str_name.length,c.length); + } return null; } @@ -61,9 +62,9 @@ function delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime()-1); if(parent.opener){ - parent.opener.document.cookie = name + "=null; path=/; expires=" + exp.toGMTString(); + parent.opener.document.cookie = name + "=null; path=/; expires=" + exp.toGMTString(); } else { - document.cookie = name + "=null; path=/; expires=" + exp.toGMTString(); + document.cookie = name + "=null; path=/; expires=" + exp.toGMTString(); } } @@ -139,18 +140,18 @@ function addRecord(val, selection,NoMsgAlert) { } 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; + 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) { - var checky = AllAreChecked(document.bookbag_form.biblionumber); - var l = document.bookbag_form.biblionumber.length; + 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,8 +160,9 @@ function SelectAll(){ function addMultiple(biblist){ var c_value = ""; + var i = 0; if( biblist && biblist.length > 0 ) { - for (var i=0; i < biblist.length; i++) { + for ( i=0; i < biblist.length; i++ ) { if (biblist[i].checked) { c_value = c_value + biblist[i].value + "/"; } @@ -168,12 +170,12 @@ function addMultiple(biblist){ } else { var bibnums = getContextBiblioNumbers(); if ( bibnums.length > 0 ) { - for ( var i = 0 ; i < bibnums.length ; i++ ) { + for ( i = 0 ; i < bibnums.length ; i++ ) { c_value = c_value + bibnums[i] + "/"; } } else { if(document.bookbag_form.biblionumber.length > 0) { - for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { + for ( i=0; i < document.bookbag_form.biblionumber.length; i++ ) { if (document.bookbag_form.biblionumber[i].checked) { c_value = c_value + document.bookbag_form.biblionumber[i].value + "/"; } @@ -186,8 +188,9 @@ function addMultiple(biblist){ addSelRecords(c_value); } -function addSelRecords(valSel) { // function for adding a selection of biblios to the basket - // from the results list +/* function for adding a selection of biblios to the basket + from the results list */ +function addSelRecords(valSel) { var arrayRecords = valSel.split("/"); var i = 0; var nbAdd = 0; @@ -218,19 +221,19 @@ function addSelRecords(valSel) { // function for adding a selection of biblios t msg = MSG_NO_RECORD_ADDED; } } - showCartUpdate(msg); + showCartUpdate(msg); } function showCartUpdate(msg){ - // set body of popup window - $("#cartDetails").html(msg); - showCart(); + // set body of popup window + $("#cartDetails").html(msg); + showCart(); setTimeout(hideCart,2000); } function showListsUpdate(msg){ - // set body of popup window - alert(msg); + // set body of popup window + alert(msg); } function selRecord(num, status) { @@ -261,7 +264,7 @@ function delSelRecords() { var recordsSel = 0; var end = 0; var valCookie = readCookie(nameCookie, 1); - + var s; if (valCookie) { var str = document.myform.records.value; if (str.length > 0){ @@ -270,7 +273,7 @@ function delSelRecords() { while (!end){ s = str.indexOf("/"); if (s>0){ - num = str.substring(0, s); + var num = str.substring(0, s); str = delRecord(num,str); str2 = delRecord(num,str2); updateLink(num,"del",top.opener); @@ -331,7 +334,6 @@ function delRecord (n, s) { return s; } - function delBasket(context,rep) { if (rep === undefined){ rep = confirm(MSG_CONFIRM_DEL_BASKET); @@ -350,7 +352,6 @@ function delBasket(context,rep) { } } - function quit() { if (document.myform.records.value) { var rep = false; @@ -370,7 +371,7 @@ function sendBasket() { var loc = CGIBIN + "basket/sendbasket.pl?" + strCookie; var optWin="scrollbars=no,resizable=no,height=400,width=650,top=50,left=100"; - var win_form = open(loc,"win_form",optWin); + open(loc,"win_form",optWin); } function downloadBasket() { @@ -409,6 +410,7 @@ function showLess() { } function updateBasket(updated_value,target) { +<<<<<<< HEAD if(target){ target.$('#basketcount').html(" ("+updated_value+")"); target.$('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value)); @@ -417,6 +419,15 @@ function updateBasket(updated_value,target) { $('#cartDetails').html(MSG_IN_YOUR_CART.format(updated_value)); } var basketcount = updated_value; +======= + if(target){ + target.$('#basketcount').html(" ("+updated_value+")"); + target.$('#cartDetails').html(__("Items in your cart: %s").format(updated_value)); + } else { + $('#basketcount').html(" ("+updated_value+")"); + $('#cartDetails').html(__("Items in your cart: %s").format(updated_value)); + } +>>>>>>> 7666b52cec... Bug 27754: Correct eslint errors in basket.js } function openBiblio(openerURL) { @@ -426,10 +437,17 @@ function openBiblio(openerURL) { function addSelToShelf() { var items = document.getElementById('records').value; +<<<<<<< HEAD if(items){ document.location = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber="+items; } else { alert(MSG_NO_RECORD_SELECTED); +======= + if(items){ + document.location = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber="+items; + } else { + alert(__("No item was selected")); +>>>>>>> 7666b52cec... Bug 27754: Correct eslint errors in basket.js } } @@ -437,8 +455,9 @@ function addSelToShelf() { function vShelfAdd(biblist) { var bibs = new Array; + var i; if( biblist && biblist.length > 0 ) { - for (var i=0; i < biblist.length; i++) { + for ( i=0; i < biblist.length; i++ ) { if (biblist[i].checked) { bibs.push("biblionumber=" + biblist[i].value); } @@ -448,7 +467,7 @@ function vShelfAdd(biblist) { } else { var bibnums = getContextBiblioNumbers(); if ( bibnums.length > 0 ) { - for ( var i = 0 ; i < bibnums.length ; i++ ) { + for ( i = 0 ; i < bibnums.length ; i++ ) { bibs.push("biblionumber=" + bibnums[i]); } return bibs.join("&"); @@ -507,5 +526,5 @@ $(document).ready(function(){ e.preventDefault(); openBasket(); }); - if(basketcount){ updateBasket(basketcount); } + if(basketcount){ updateBasket(basketcount); } }); -- 2.39.5