From 60dcc481365a28b60ebb81a5c50bbb7eb03533b5 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 5 Oct 2016 20:58:26 +0000 Subject: [PATCH] Bug 14242: (follow-up) Change the icon to words Fix a bug that meant it would search on empty ISBN To test 1. Fill in a valid ISBN (Book data is correctly loaded) 2. Clear the ISBN from the field (Book data is correctly removed) 3. Tab away from the empty ISBN field: Data is loaded for a title "ISBN 0-9690745-2-2" 4. Apply patch 5. Repeat 1,2 and 3 notice a search is no longer done Signed-off-by: Marc --- koha-tmpl/opac-tmpl/bootstrap/js/autofill.js | 156 +++++++++++++-------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/autofill.js b/koha-tmpl/opac-tmpl/bootstrap/js/autofill.js index f6c487a..171cc93 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/autofill.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/autofill.js @@ -27,8 +27,8 @@ /* decorate element as autofiller */ var $inputgroup = $('
'); - self.$undo = $(''); - self.$fillbtn = $(''); + self.$undo = $(''); + self.$fillbtn = $(' Search Google Books '); self.$error = $(''); self.$elm.wrap($inputgroup); self.$elm.after(self.$error); @@ -63,87 +63,87 @@ self.$error.hide(); /* give user some feedback that the request is in progress */ self.$fillbtn.fadeOut(1000).fadeIn(1000); - - var gAPI = 'https://www.googleapis.com/books/v1/volumes?q='; - if(self.type) - gAPI += self.type + ':'; - gAPI += self.$elm.val(); - gAPI += '&maxResults=1'; - - $.getJSON(gAPI, function (response) { - if(response.totalItems == 0) { - self.$error.html('Sorry, nothing found.'); - self.$error.show(); - return; - } - - var undos = 0; - var item = response.items[0]; - for(var key in self.fields) { - var filled = false; - var value = eval('item.'+key); - var field = self.fields[key]; - - /* field handled by caller */ - if('handle' in field) { - if(typeof field.handle === 'function') - field.handle(field.$target, value); - - continue; /* next please */ + if ( self.$elm.val()) { + var gAPI = 'https://www.googleapis.com/books/v1/volumes?q='; + if(self.type) + gAPI += self.type + ':'; + gAPI += self.$elm.val(); + gAPI += '&maxResults=1'; + $.getJSON(gAPI, function (response) { + if(response.totalItems == 0) { + self.$error.html('Sorry, nothing found.'); + self.$error.show(); + return; } - /* wouldn't know what to do with result unless we have a - * target */ - if( ! field.$target ) - continue; - - /* handle differently depending on datatype */ - switch(typeString(value)) { - case 'array': - switch(field.$target.prop('nodeName').toUpperCase()) { - case 'TEXTAREA': - undos++; - field.$target.bind('autofill-undo', field.$target.text(), function(e){$(this).text(e.data);}); - field.$target.text(value.join(', ')); - break; - case 'INPUT': - default: - undos++; - field.$target.bind('autofill-undo', field.$target.val(), function(e){$(this).val(e.data);}); - field.$target.val(value.join(', ')); - break; - } - break; - default: - switch(field.$target.prop('nodeName').toUpperCase()) { - case 'TEXTAREA': - undos++; - field.$target.bind('autofill-undo', field.$target.text(), function(e){$(this).text(e.data);}); - field.$target.text(value); - break; - case 'SELECT': - case 'INPUT': - default: - undos++; - field.$target.bind('autofill-undo', field.$target.val(), function(e){$(this).val(e.data);}); - field.$target.val(value); - break; - } + var undos = 0; + var item = response.items[0]; + for(var key in self.fields) { + var filled = false; + var value = eval('item.'+key); + var field = self.fields[key]; + + /* field handled by caller */ + if('handle' in field) { + if(typeof field.handle === 'function') + field.handle(field.$target, value); + + continue; /* next please */ + } + + /* wouldn't know what to do with result unless we have a + * target */ + if( ! field.$target ) + continue; + + /* handle differently depending on datatype */ + switch(typeString(value)) { + case 'array': + switch(field.$target.prop('nodeName').toUpperCase()) { + case 'TEXTAREA': + undos++; + field.$target.bind('autofill-undo', field.$target.text(), function(e){$(this).text(e.data);}); + field.$target.text(value.join(', ')); + break; + case 'INPUT': + default: + undos++; + field.$target.bind('autofill-undo', field.$target.val(), function(e){$(this).val(e.data);}); + field.$target.val(value.join(', ')); + break; + } + break; + default: + switch(field.$target.prop('nodeName').toUpperCase()) { + case 'TEXTAREA': + undos++; + field.$target.bind('autofill-undo', field.$target.text(), function(e){$(this).text(e.data);}); + field.$target.text(value); + break; + case 'SELECT': + case 'INPUT': + default: + undos++; + field.$target.bind('autofill-undo', field.$target.val(), function(e){$(this).val(e.data);}); + field.$target.val(value); + break; + } + } + + switch(field.effect) { + case 'flash': + field.$target.fadeOut(500).fadeIn(500); + break; + } } - switch(field.effect) { - case 'flash': - field.$target.fadeOut(500).fadeIn(500); - break; - } - } - - if(undos > 0) - self.$undo.show(); + if(undos > 0) + self.$undo.show(); - }); - }); - }; + }); + } + }); + }; /* * @fields object: Google Books API item propreties map for -- 2.1.4