From 53ec5cc5edd81917fb7696f387944589e2efe02f Mon Sep 17 00:00:00 2001 From: Martin Stenberg Date: Wed, 26 Aug 2015 20:22:30 +0200 Subject: [PATCH] Bug 14242: Use ISBN-field to automatically fill out purchase suggestions Add new jQuery plugin "autofill" which transforms selected element(s) into search fields for Google Books API and automatically fills requested fields with search result. Use in OPAC purchase suggestions to automatically fill out fields when entering ISBN-number. Test plan: 1. Run updatedatabase.pl 2. Enable system precference "OPACSuggestionAutoFill" 3. Log into OPAC and go to purchase suggestions page 4. Write a valid ISBN (such as 0-9690745-2-2 or 978-1-78416-110-1) into the ISBN field and click the 'search google books' button, or unfocus the field. 5. Title, Author, Publisher, publication year and Item Type fields should now be filled automatically. 6. Press "clear form" to undo - should restore all fields that the API pull filled to empty Signed-off-by: Owen Leonard --- .../atomicupdate/bug_14242-autofill_syspref.perl | 6 + installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 7 + .../bootstrap/en/modules/opac-suggestions.tt | 36 +++- koha-tmpl/opac-tmpl/bootstrap/js/autofill.js | 209 +++++++++++++++++++++ 5 files changed, 253 insertions(+), 6 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_14242-autofill_syspref.perl create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/autofill.js diff --git a/installer/data/mysql/atomicupdate/bug_14242-autofill_syspref.perl b/installer/data/mysql/atomicupdate/bug_14242-autofill_syspref.perl new file mode 100644 index 00000000000..c56eae70eff --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_14242-autofill_syspref.perl @@ -0,0 +1,6 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`,`type`) VALUES ('OPACSuggestionAutoFill', '0', NULL, 'Automatically fill OPAC suggestion form with data from Google Books API','YesNo') }); + + NewVersion( $DBversion, 14242, "Add OPACSuggestionAutoFill system preference"); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index dd83a00fd8a..d76d870b061 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -386,6 +386,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OAI-PMH:DeletedRecord','persistent','Koha\'s deletedbiblio table will never be deleted (persistent), might be deleted (transient), or will never have any data in it (no)','transient|persistent|no','Choice'), ('OAI-PMH:MaxCount','50',NULL,'OAI-PMH maximum number of records by answer to ListRecords and ListIdentifiers queries','Integer'), ('OPACAcquisitionDetails','0','','Show the acquisition details at the OPAC','YesNo'), +('OPACSuggestionAutoFill','0',NULL,'Automatically fill OPAC suggestion form with data from Google Books API','YesNo'), ('OpacAddMastheadLibraryPulldown','0','','Adds a pulldown menu to select the library to search on the opac masthead.','YesNo'), ('OpacAdvSearchMoreOptions','pubdate,itemtype,language,subtype,sorting,location','Show search options for the expanded view (More options)','pubdate|itemtype|language|subtype|sorting|location','multiple'), ('OpacAdvSearchOptions','pubdate,itemtype,language,sorting,location','Show search options','pubdate|itemtype|language|subtype|sorting|location','multiple'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index a214dae954e..46a5cf0ae17 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -520,6 +520,13 @@ OPAC: 0: Don't display - a library selection list for news items in the OPAC. - + - pref: OPACSuggestionAutoFill + default: 0 + choices: + yes: Enable + no: Disable + - OPAC suggestions form automatically filling with data from Google Books API. + - - "Use the following as the OPAC ISBD template:" - pref: OPACISBD type: textarea diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt index 89e1175c3f5..85e777619eb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-suggestions.tt @@ -75,6 +75,12 @@
    + [% IF Koha.Preference( 'OPACSuggestionAutoFill' ) %] +
  1. + + +
  2. + [% END %]
  3. [% IF ( title_required ) %] @@ -101,17 +107,18 @@
  4. [% IF ( copyrightdate_required ) %] - - -
    Required
    + + +
    Required
    [% ELSE %] - - + + [% END %] + Copyright or publication year, for example: 2016
  5. [% END %] - [% UNLESS ( isbn_hidden )%] + [% UNLESS ( isbn_hidden or Koha.Preference('OPACSuggestionAutoFill') ) %]
  6. [% IF ( isbn_required ) %] @@ -489,6 +496,9 @@ [% INCLUDE 'opac-bottom.inc' %] [% BLOCK jsinclude %] +[% IF ( Koha.Preference("OPACSuggestionAutoFill") ) %] + [% Asset.js("js/autofill.js") | $raw %] +[% END %] [% INCLUDE 'datatables.inc' %]