Bugzilla – Attachment 60857 Details for
Bug 17602
Integrate support for RecordedBooks (formerly OneClickDigital) API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17602 Add Oneclickdigital integration to Koha
Bug-17602-Add-Oneclickdigital-integration-to-Koha.patch (text/plain), 31.07 KB, created by
Srdjan Jankovic
on 2017-03-07 04:12:14 UTC
(
hide
)
Description:
Bug 17602 Add Oneclickdigital integration to Koha
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2017-03-07 04:12:14 UTC
Size:
31.07 KB
patch
obsolete
>From 5e4b7044d4d343324ad74db161fe13b805841512 Mon Sep 17 00:00:00 2001 >From: Srdjan <srdjan@catalyst.net.nz> >Date: Fri, 23 Sep 2016 18:13:10 +1200 >Subject: [PATCH] Bug 17602 Add Oneclickdigital integration to Koha > >Add OneClickdigital to the users page in the public interface > >To Test: >1/ Apply all 3 patches >2/ Set the sysprefs to valid values (you will need a test account with Oneclickdigital) >3/ Try a search >4/ Login to the OPAC, try to place a hold, or check an item out >5/ Check the opac-user page, see if your items are showing on the oneclickdigital tab >--- > .../bootstrap/en/includes/oneclick-checkout.inc | 15 ++ > .../bootstrap/en/modules/opac-oneclick-search.tt | 165 ++++++++++++ > .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 18 ++ > .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 19 ++ > .../opac-tmpl/bootstrap/js/oneclickdigital.js | 278 +++++++++++++++++++++ > opac/opac-oneclick-search.pl | 41 +++ > opac/opac-search.pl | 9 +- > opac/opac-user.pl | 1 + > opac/svc/oneclickdigital | 131 ++++++++++ > 9 files changed, 674 insertions(+), 3 deletions(-) > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/oneclick-checkout.inc > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-oneclick-search.tt > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/oneclickdigital.js > create mode 100755 opac/opac-oneclick-search.pl > create mode 100755 opac/svc/oneclickdigital > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/oneclick-checkout.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/oneclick-checkout.inc >new file mode 100644 >index 0000000..55bdaff >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/oneclick-checkout.inc >@@ -0,0 +1,15 @@ >+<div id="oneclickdigital-checkout" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="oneclickdigital-checkout-label" aria-hidden="true"> >+ <div class="modal-header"> >+ <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">Ã</button> >+ <h3 id="oneclickdigital-checkout-label">Checkout</h3> >+ </div> >+ <form action="#" method="post" id="oneclickdigital-checkout-form"> >+ <div class="modal-body"> >+ <input type="hidden" name="id" value="" /> >+ </div> >+ <div class="modal-footer"> >+ <input type="submit" class="btn btn-primary oneclickdigital-checkout-submit" value="Checkout" /> >+ <a href="#" data-dismiss="modal" aria-hidden="true" class="cancel">Cancel</a> >+ </div> >+ </form> <!-- /#oneclickdigital-checkout-form --> >+</div> <!-- /#oneclickdigital-checkout --> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-oneclick-search.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-oneclick-search.tt >new file mode 100644 >index 0000000..da90502 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-oneclick-search.tt >@@ -0,0 +1,165 @@ >+[% USE Koha %] >+[% INCLUDE 'doc-head-open.inc' %] >+<title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › OneClickDigital search for '[% q | html %]'</title> >+[% INCLUDE 'doc-head-close.inc' %] >+[% BLOCK cssinclude %] >+<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/jquery.rating.css" /> >+<style> >+.actions a.addtocart { >+ display: inline; >+} >+</style> >+[% END %] >+</head> >+[% INCLUDE 'bodytag.inc' bodyid='oneclickdigital-results-page' bodyclass='scrollto' %] >+[% INCLUDE 'masthead.inc' %] >+ >+ <div class="main"> >+ <ul class="breadcrumb"> >+ <li><a href="/cgi-bin/koha/opac-main.pl">Home</a> <span class="divider">›</span></li> >+ <li><a href="#">OneClickDigital search for '[% q | html %]'</a></li> >+ </ul> >+ >+ <div class="container-fluid"> >+ <div class="row-fluid"> >+ <div class="span2"> >+ [% IF ( OpacNav || OpacNavBottom ) %] >+ [% INCLUDE 'navigation.inc' %] >+ [% END %] >+ </div> >+ <div class="span10"> >+ <div id="oneclickdigital-results-content" class="maincontent searchresults"> >+ <h1>OneClickDigital search for '[% q | html %]'</h1> >+ <div id="breadcrumbs"> >+ <p></p> >+ </div> >+ >+ <div id="top-pages"> >+ <div class="pagination pagination-small"> >+ </div> >+ </div> >+ >+ <table id="oneclickdigital-results-list" class="table table-striped"> >+ <tbody> >+ </tbody> >+ </table> >+ >+ <div id="bottom-pages"> >+ <div class="pagination pagination-small"> >+ </div> >+ </div> >+ >+ </div> <!-- / #oneclickdigital-results-content --> >+ </div> <!-- / .span10 --> >+ </div> <!-- / .row-fluid --> >+ </div> <!-- / .container-fluid --> >+ </div> <!-- / .main --> >+ >+[% INCLUDE 'oneclick-checkout.inc' %] >+ >+[% INCLUDE 'opac-bottom.inc' %] >+[% BLOCK jsinclude %] >+<script type="text/javascript" src="[% interface %]/[% theme %]/js/oneclickdigital.js"></script> >+<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.rating.js"></script> >+<script type="text/javascript"> >+var querystring = "[% q |replace( "'", "\'" ) |replace( '\n', '\\n' ) |replace( '\r', '\\r' ) |html %]"; >+var results_per_page = [% OPACnumSearchResults || 20 %]; >+ >+function search( page ) { >+ $( '#oneclickdigital-status' ).html( _("Searching OneClickDigital...") + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></span>' ); >+ >+ KOHA.OneClickDigital.search( querystring, results_per_page, page, function( data ) { >+ if ( data.error ) { >+ $( '#oneclickdigital-status' ).html( '<strong class="unavailable">' + _("Error searching OneClickDigital collection") + ': ' + data.error + '</strong>' ); >+ return; >+ } >+ >+ if ( !data.total ) { >+ $( '#oneclickdigital-status' ).html( '<strong>' + _("No results found in the library's OneClickDigital collection.") + '</strong>' ); >+ return; >+ } >+ >+ $( '#oneclickdigital-results-list tbody' ).empty(); >+ >+ $( '#oneclickdigital-status' ).html( '<strong>' + _("Found") + ' ' + data.total + ' ' + _("results in the library's OneClickDigital collection.") + '</strong>' ); >+ >+ for ( var i = 0; data.items[i]; i++ ) { >+ var prod = data.items[i]; >+ var results = []; >+ >+ results.push( '<tr>' ); >+ >+ results.push( '<td class="info"><span class="title">' ); >+ results.push( prod.title ); >+ results.push( '</span>' ); >+ results.push( '<p>' + _("by") + ' ', prod.author, '</p>' ); >+ results.push( '<span class="results_summary mediatype"><span class="label">' + _("Type:") + ' </span>', prod.media, '</span>' ); >+ >+ results.push( '</td>' ); >+ >+ results.push( '<td>' ); >+ if ( prod.images && prod.images.medium ) { >+ results.push( '<a href="', "XXX", '">' ); >+ results.push( '<img class="thumbnail" src="', prod.images.medium, '" />' ); >+ results.push( '</a>' ); >+ } >+ results.push( '</td>' ); >+ >+ results.push( '</tr>' ); >+ var $tr = $( results.join( '' )); >+ $( '#oneclickdigital-results-list tbody' ).append( $tr ); >+ >+ $tr.find( '.info' ).each(function() { >+ KOHA.OneClickDigital.add_actions(this, prod.isbn); >+ }); >+ } >+ >+ $( '#oneclickdigital-results-list tr:odd' ).addClass( 'highlight' ); >+ >+ var pages = []; >+ >+ var max_page = Math.floor( data.total / results_per_page ); >+ if (data.total == page*results_per_page) max_page++; >+ >+ if ( page != 1 ) { >+ pages.push( '<li><a class="od-nav" href="#" data-page="' + (page - 1) + '">« ' + _("Previous") + '</a></li>' ); >+ } >+ >+ for ( var p = Math.max( 0, page - 9 ); p <= Math.min( max_page, p + 9 ); p++ ) { >+ if ( p == page ) { >+ pages.push( ' <li class="active"><a href="#">' + ( p + 1 ) + '</a></li>' ); >+ } else { >+ pages.push( ' <li><a class="od-nav" href="#" data-page="' + p + '">' + p + '</a></li>' ); >+ } >+ } >+ >+ if ( page < max_page ) { >+ pages.push( ' <li><a class="od-nav" href="#" data-page="' + (page + 1) + '">' + _("Next") + ' »</a></li>' ); >+ } >+ >+ if ( pages.length > 1 ) $( '#top-pages, #bottom-pages' ).find( '.pagination' ).html( '<ul>' + pages.join( '' ) + '</ul>'); >+ >+ $( '#oneclickdigital-results-list input.star' ).rating(); >+ } ); >+} >+ >+$( document ).ready( function() { >+ $( '#breadcrumbs p' ) >+ .append( ' ' ) >+ .append( '<span id="oneclickdigital-status"></span>' ); >+ >+ $( document ).on( 'click', 'a.od-nav', function() { >+ search( $( this ).data( 'page' ) ); >+ return false; >+ }); >+ >+ [% IF ( loggedinusername ) %] >+ KOHA.OneClickDigital.with_account_details("#breadcrumbs", function() { >+ search( 1 ); >+ }); >+ [% ELSE %] >+ search( 1 ); >+ [% END %] >+} ); >+</script> >+[% END %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >index 2d85671..0284e49 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >@@ -590,6 +590,7 @@ > [% END %] > [% IF ( OpacStarRatings == 'all' || Koha.Preference('Babeltheque') ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.rating.js"></script>[% END %] > [% IF ( OverDriveEnabled ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/js/overdrive.js"></script>[% END %] >+[% IF ( OneClickDigitalEnabled ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/js/oneclickdigital.js"></script>[% END %] > <script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script> > [% IF ( OpacHighlightedWords ) %]<script type="text/javascript" src="[% interface %]/[% theme %]/lib/jquery/plugins/jquery.highlight-3.js"></script> > [% END %]<script type="text/javascript"> >@@ -901,6 +902,23 @@ $(document).ready(function(){ > } > } ); > [% END %] >+ [% IF ( OneClickDigitalEnabled ) %] >+ var $oneclick_results = $( '<div id="oneclick-results">' + _( 'Searching OneClickDigital...' ) + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></div>' ); >+ $( '#numresults' ) .append( ' ' ) >+ .append( $oneclick_results ); >+ KOHA.OneClickDigital.search( querystring, [% OPACnumSearchResults || "null" %], null, function( data ) { >+ if ( data.error ) { >+ $oneclick_results.html( _( 'Error searching OneClickDigital collection' ) ); >+ return; >+ } >+ >+ if ( data.total > 0 ) { >+ $oneclick_results.html( _( 'Found' ) + ' <a href="/cgi-bin/koha/opac-oneclick-search.pl?q=' + escape( querystring ) + '">' + data.total + ' ' + _( 'results' ) + '</a> ' + _( 'in OneClickDigital collection' ) ); >+ } else { >+ $oneclick_results.remove(); >+ } >+ } ); >+ [% END %] > [% IF ( OpenLibrarySearch ) %] > var $openlibrary_results = $( '<div id="openlibrary-results">' + _( 'Searching Open Library...' ) + ' <img class="throbber" src="[% interface %]/lib/jquery/plugins/themes/classic/throbber.gif" /></div>' ); > $( '#numresults' ) .append( ' ' ) >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >index a715178..6883047 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt >@@ -138,10 +138,15 @@ Using this account is not recommended because some parts of Koha will not functi > [% IF ( OverDriveCirculation ) %] > <li><a href="#opac-user-overdrive">OverDrive Account</a></li> > [% END %] >+ [% IF ( OneClickDigitalCirculation ) %] >+ <li><a href="#opac-user-oneclickdigital">OneClickDigital Account</a></li> >+ [% END %] > </ul> > > <div id="opac-user-overdrive"> > </div> >+ <div id="opac-user-oneclickdigital"> >+ </div> > <div id="opac-user-checkouts"> > [% IF ( issues_count ) %] > <form id="renewselected" action="/cgi-bin/koha/opac-renew.pl" method="post"> >@@ -834,6 +839,9 @@ Using this account is not recommended because some parts of Koha will not functi > [% IF ( OverDriveCirculation ) %] > [% INCLUDE 'overdrive-checkout.inc' %] > [% END %] >+[% IF ( OneClickDigitalCirculation ) %] >+[% INCLUDE 'oneclick-checkout.inc' %] >+[% END %] > > [% INCLUDE 'opac-bottom.inc' %] > >@@ -900,6 +908,7 @@ Using this account is not recommended because some parts of Koha will not functi > </script> > [% IF Koha.Preference('OverDriveCirculation') %] > <script type="text/javascript" src="[% interface %]//[% theme %]/js/overdrive.js"></script> >+ <script type="text/javascript" src="[% interface %]//[% theme %]/js/oneclickdigital.js"></script> > <script type="text/JavaScript"> > $(document).ready(function() { > [% IF ( overdrive_error ) %] >@@ -913,6 +922,16 @@ Using this account is not recommended because some parts of Koha will not functi > $("#opac-user-overdrive").each( function() { > KOHA.OverDriveCirculation.display_account_details(this); > } ); >+ >+ [% IF ( oneclickdigital_error ) %] >+ KOHA.OneClickDigital.display_error("#opac-user-oneclickdigital", "[% oneclickdigital_error.dquote %]"); >+ [% END %] >+ [% IF ( oneclickdigital_tab ) %] >+ $("#opac-user-views").tabs("select", "#opac-user-oneclickdigital"); >+ [% END %] >+ $("#opac-user-oneclickdigital").each( function() { >+ KOHA.OneClickDigital.display_account_details(this); >+ } ); > }); > </script> > [% END %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/oneclickdigital.js b/koha-tmpl/opac-tmpl/bootstrap/js/oneclickdigital.js >new file mode 100644 >index 0000000..ae3226c >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/oneclickdigital.js >@@ -0,0 +1,278 @@ >+if ( typeof KOHA == "undefined" || !KOHA ) { >+ var KOHA = {}; >+} >+ >+KOHA.OneClickDigital = new function() { >+ var svc_url = '/cgi-bin/koha/svc/oneclickdigital'; >+ >+ var error_div = $('<div class="oneclickdigital-error">'); >+ function display_error ( error ) { >+ error_div.text(error); >+ } >+ >+ var details = null; >+ >+ function is_identified() { >+ return details ? details.is_identified : false; >+ } >+ >+ var checkout_popup = null; >+ $( document ).ready(function() { >+ checkout_popup = $("#oneclickdigital-checkout"); >+ }); >+ >+ function display_account (container, data) { >+ if (!data.is_identified) { >+ return; >+ } >+ >+ if (data.checkouts) { >+ var checkouts_div = $('<div class="oneclickdigital-div">').html('<h3>' + _("Checkouts") + '</h3>'); >+ var checkouts_list = $('<ul class="oneclickdigital-list">'); >+ data.checkouts.items.forEach(function(item) { >+ item_line(checkouts_list, item); >+ }); >+ checkouts_div.append(checkouts_list); >+ $(container).append(checkouts_div); >+ } >+ >+ if (data.holds) { >+ var holds_div = $('<div class="oneclickdigital-div">').html('<h3>' + _("Holds") + '</h3>'); >+ var holds_list = $('<ul class="oneclickdigital-list">'); >+ data.holds.items.forEach(function(item) { >+ item_line(holds_list, item); >+ }); >+ holds_div.append(holds_list); >+ $(container).append(holds_div); >+ } >+ } >+ >+ function item_line(ul_el, item) { >+ var line = $('<li class="oneclickdigital-item">'); >+ if (item.images) { >+ var thumb_url = item.images.thumbnail; >+ if (thumb_url) { >+ $('<img class="oneclickdigital-item-thumbnail">') >+ .attr("src", thumb_url) >+ .appendTo(line); >+ } >+ } >+ $('<div class="oneclickdigital-item-title">') >+ .text(item.title) >+ .appendTo(line); >+ $('<div class="oneclickdigital-item-subtitle">') >+ .text(item.subtitle) >+ .appendTo(line); >+ $('<div class="oneclickdigital-item-author">') >+ .text(item.author) >+ .appendTo(line); >+ var actions = $('<span class="actions">'); >+ display_actions(actions, item.isbn); >+ $('<div id="action_'+item.isbn+'" class="actions-menu">') >+ .append(actions) >+ .appendTo(line); >+ >+ $(ul_el).append(line); >+ } >+ >+ function svc_ajax ( method, params, success_callback ) { >+ // remove when jquery is upgraded >+ for (var key in params) { >+ if (params[key] === null) delete params[key]; >+ } >+ return $.ajax({ >+ method: method, >+ dataType: "json", >+ url: svc_url, >+ data: params, >+ success: function (data) { >+ if (data.error) { >+ display_error(data.error); >+ } >+ success_callback(data); >+ }, >+ error: function(jqXHR, textStatus, errorThrown) { >+ display_error(errorThrown); >+ } >+ }); >+ } >+ >+ function load_account_details ( callback ) { >+ svc_ajax('get', { action: "account" }, function(data) { >+ details = data; >+ callback(data); >+ }); >+ } >+ >+ function item_action (params, el) { >+ var isbn = params.isbn; >+ svc_ajax('post', params, function(data) { >+ if (data.checkouts) { >+ details.checkouts = data.checkouts; >+ } >+ if (data.holds) { >+ details.holds = data.holds; >+ } >+ display_actions(el, isbn); >+ }); >+ } >+ >+ function item_is_checked_out (isbn) { >+ if ( !(details && details.checkouts) ) { >+ return null; >+ } >+ var isbn_uc = isbn.toUpperCase(); >+ var items = details.checkouts.items; >+ for (var i = 0; i < items.length; i++) { >+ if ( items[i].isbn.toUpperCase() == isbn_uc ) { >+ return items[i]; >+ } >+ } >+ return null; >+ } >+ >+ function item_is_on_hold (isbn) { >+ if ( !(details && details.holds) ) { >+ return false; >+ } >+ var isbn_uc = isbn.toUpperCase(); >+ var items = details.holds.items; >+ for (var i = 0; i < items.length; i++) { >+ if ( items[i].isbn.toUpperCase() == isbn_uc ) { >+ return items[i]; >+ } >+ } >+ return null; >+ } >+ >+ function display_actions(el, isbn) { >+ $(el).empty(); >+ if (is_identified()) { >+ >+ var item = item_is_checked_out(isbn); >+ if (item) { >+ var expires = new Date(item.expires); >+ $('<span class="oneclickdigital-item-status">') >+ .text(_("Checked out until") + " " + expires.toLocaleString()) >+ .appendTo(el); >+ $(el).append(" "); >+ >+ if (item.url) { >+ var download = $('<a href="'+item.url+'">').appendTo(el); >+ decorate_button(download, _("Download")); >+ $(el).append(" "); >+ } >+ >+ $(el).append( ajax_button(_("Check in"), function() { >+ if( confirm(_("Are you sure you want to return this item?")) ) { >+ item_action({action: "return", isbn: isbn}, el); >+ } >+ }) ); >+ >+ return item; >+ } >+ >+ item = item_is_on_hold(isbn); >+ if (item) { >+ $('<span class="oneclickdigital-status">') >+ .text(_("On hold")) >+ .appendTo(el); >+ $(el).append(" "); >+ } >+ >+ if(checkout_popup) { >+ $(el).append( ajax_button(_("Check out"), function() { >+ if( confirm(_("Are you sure you want to checkout this item?")) ) { >+ svc_ajax('post', {action: "checkout", isbn: isbn}, function(data) { >+ if (data.checkouts) { >+ details.checkouts = data.checkouts; >+ } >+ if (data.holds) { >+ details.holds = data.holds; >+ } >+ item = display_actions(el, isbn); >+ }); >+ } >+ }) ); >+ } >+ if (!item) { >+ $(el).append( ajax_button(_("Place hold"), function() { >+ item_action({action: "place_hold", isbn: isbn}, el); >+ }) ); >+ } >+ >+ if (item) { >+ $(el).append( ajax_button(_("Cancel"), function() { >+ if( confirm(_("Are you sure you want to cancel this hold?")) ) { >+ item_action({action: "return", isbn: isbn}, el); >+ } >+ }) ); >+ } >+ return item; >+ } >+ } >+ >+ function ajax_button(label, on_click) { >+ var button = $('<a href="#">') >+ .click(function(e) { >+ e.preventDefault(); >+ on_click(); >+ }); >+ decorate_button(button, label); >+ return button; >+ } >+ >+ function decorate_button(button, label) { >+ $(button) >+ .addClass("btn btn-primary btn-mini") >+ .css("color","white") >+ .text(label); >+ } >+ >+ this.with_account_details = function( el, callback ) { >+ $(el).append(error_div); >+ load_account_details( callback ); >+ } >+ >+ this.display_account_details = function( el ) { >+ $(el).empty().append(error_div); >+ load_account_details(function(data) { >+ display_account(el, data); >+ }); >+ }; >+ >+ this.display_error = function( el, error ) { >+ $(el).empty().append(error_div); >+ display_error(error); >+ }; >+ >+ this.is_identified = is_identified; >+ >+ this.add_actions = function(el, isbn) { >+ var actions = $('<span class="actions">'); >+ display_actions(actions, isbn); >+ $('<div id="action_'+isbn+'" class="actions-menu">') >+ .append(actions) >+ .appendTo(el); >+ }; >+ >+ this.search = function( q, page_size, page, callback ) { >+ svc_ajax('get', { action: "search", q: q, page_size: page_size, page: page }, function (data) { >+ error = data.error; >+ if (!data.is_identified && !error) error = _("Invalid account"); >+ >+ var results; >+ if (data.results) { >+ results = data.results; >+ if (!results.total) { >+ var total = results.items.length; >+ if ( total == result.page_size ) total = total + "+"; >+ results.total = total; >+ } >+ } >+ else results = {}; >+ results.error = error; >+ callback(results); >+ }); >+ }; >+} >diff --git a/opac/opac-oneclick-search.pl b/opac/opac-oneclick-search.pl >new file mode 100755 >index 0000000..9a28cb3 >--- /dev/null >+++ b/opac/opac-oneclick-search.pl >@@ -0,0 +1,41 @@ >+#!/usr/bin/perl >+ >+# Copyright 2013 ByWater >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use strict; >+use warnings; >+ >+use CGI qw ( -utf8 ); >+ >+use C4::Auth qw(:DEFAULT); >+use C4::Output; >+ >+my $cgi = new CGI; >+ >+# Getting the template and auth >+my ($template, $loggedinuser, $cookie) >+= get_template_and_user({template_name => "opac-oneclick-search.tt", >+ query => $cgi, >+ type => "opac", >+ debug => 1, >+ }); >+ >+$template->{'VARS'}->{'q'} = $cgi->param('q'); >+$template->{'VARS'}->{'limit'} = C4::Context->preference('OPACnumSearchResults'); >+ >+output_html_with_http_headers $cgi, $cookie, $template->output; >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index a84e9d3..bd1fd257 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -988,9 +988,12 @@ $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksRe > $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer'); > $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults'); > >-if ($offset == 0 && IsOverDriveEnabled()) { >- $template->param(OverDriveEnabled => 1); >- $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID')); >+if ($offset == 0) { >+ if (IsOverDriveEnabled()) { >+ $template->param(OverDriveEnabled => 1); >+ $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID')); >+ } >+ $template->param(OneClickDigitalEnabled => C4::Context->preference( 'OneClickDigitalClientSecret' ) && C4::Context->preference( 'OneClickDigitalLibraryID' )); > } > > $template->param( borrowernumber => $borrowernumber); >diff --git a/opac/opac-user.pl b/opac/opac-user.pl >index 905d52c..de175e1 100755 >--- a/opac/opac-user.pl >+++ b/opac/opac-user.pl >@@ -308,6 +308,7 @@ if (C4::Context->preference("OPACAmazonCoverImages") or > > $template->param( > OverDriveCirculation => C4::Context->preference('OverDriveCirculation') || 0, >+ OneClickDigitalCirculation => C4::Context->preference('OneClickDigitalClientSecret') && C4::Context->preference('OneClickDigitalLibraryID'), > overdrive_error => $query->param('overdrive_error') || undef, > overdrive_tab => $query->param('overdrive_tab') || 0, > ); >diff --git a/opac/svc/oneclickdigital b/opac/svc/oneclickdigital >new file mode 100755 >index 0000000..8fb38eb >--- /dev/null >+++ b/opac/svc/oneclickdigital >@@ -0,0 +1,131 @@ >+#!/usr/bin/perl >+ >+# Copyright 2016 Catalyst IT >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use CGI qw ( -utf8 ); >+use JSON qw(encode_json); >+use C4::Auth qw(checkauth); >+use C4::Output; >+use Koha::Logger; >+use Koha::ExternalContent::OneClickDigital; >+ >+our $cgi = new CGI; >+my $logger = Koha::Logger->get({ interface => 'opac' }); >+my $page_url = $cgi->referer(); >+ >+my ( $user, $cookie, $sessionID, $flags ) = checkauth( $cgi, 1, {}, 'opac' ); >+$user && $sessionID or response_bad_request("User not logged in"); >+ >+my $action = $cgi->param('action') or response_bad_request("No 'action' specified"); >+ >+local $@; >+my $ocd = eval { Koha::ExternalContent::OneClickDigital->new({ koha_session_id => $sessionID }) }; >+unless ($ocd) { >+ $logger->error($@) if $@; >+ response({ >+ is_identified => JSON::false, >+ }); >+} >+ >+my %data = ( >+ is_identified => JSON::true, >+); >+{ >+ $action eq 'search' && do { >+ my $query = $cgi->param('q'); >+ my $page = $cgi->param('page'); >+ my $page_size = $cgi->param('page_size'); >+ my $sort = $cgi->param('sort'); >+ my $res = $ocd->search({ >+ query => $query, >+ page => $page, >+ page_size => $page_size, >+ sort => $sort, >+ }); >+ $data{results} = $res; >+ last; >+ }; >+ >+ $action eq 'account' && do { >+ eval { >+ $data{account} = $ocd->patron; >+ $data{checkouts} = $ocd->checkouts; >+ $data{holds} = $ocd->holds; >+ }; >+ response_bad_request($ocd->error_message($@)) if $@; >+ last; >+ }; >+ >+ $action eq 'checkout' && do { >+ my $isbn = $cgi->param('isbn') >+ or response_bad_request("No 'isbn' specified"); >+ my $format = $cgi->param('format'); >+ $data{action} = eval { $ocd->checkout($isbn, $format) }; >+ response_bad_request($ocd->error_message($@)) if $@; >+ >+ eval { >+ $data{checkouts} = $ocd->checkouts; >+ $data{holds} = $ocd->holds; >+ }; >+ $data{error} = $ocd->error_message($@) if $@; >+ last; >+ }; >+ >+ $action eq 'place_hold' && do { >+ my $isbn = $cgi->param('isbn') >+ or response_bad_request("No 'isbn' specified"); >+ $data{action} = eval { $ocd->place_hold($isbn) }; >+ response_bad_request($ocd->error_message($@)) if $@; >+ >+ eval { >+ $data{holds} = $ocd->holds; >+ }; >+ $data{error} = $ocd->error_message($@) if $@; >+ last; >+ }; >+ >+ $action eq 'return' && do { >+ my $isbn = $cgi->param('isbn') >+ or response_bad_request("No 'isbn' specified"); >+ $data{action} = eval { $ocd->return($isbn) }; >+ response_bad_request($ocd->error_message($@)) if $@; >+ >+ eval { >+ $data{checkouts} = $ocd->checkouts; >+ $data{holds} = $ocd->holds; >+ }; >+ $data{error} = $ocd->error_message($@) if $@; >+ last; >+ }; >+ >+ response_bad_request("Invalid 'action': $action"); >+} >+ >+response(\%data); >+ >+ >+sub response_bad_request { >+ my ($error) = @_; >+ response({error => $error}, "400 $error"); >+} >+sub response { >+ my ($data, $status_line) = @_; >+ $status_line ||= "200 OK"; >+ output_with_http_headers $cgi, undef, encode_json($data), 'json', $status_line; >+ exit; >+} >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17602
:
57402
|
57403
|
57404
|
60855
|
60856
|
60857
|
61866
|
61932
|
62247
|
62248
|
62249
|
62250
|
63392
|
63778
|
63779
|
63780
|
63857
|
64070
|
64071
|
64095
|
64096
|
64098
|
64099
|
64100
|
65988
|
65989
|
66341
|
66342
|
66343
|
67236
|
67237
|
67238
|
67240
|
67859
|
67860
|
69019
|
69020
|
69021
|
69022
|
69023
|
69024
|
69025
|
69026
|
69027
|
69101
|
69357
|
69358
|
69359
|
73708
|
73709
|
73710
|
73711
|
73712
|
73713
|
73714
|
73715
|
73716
|
73717
|
73718
|
73719
|
73725
|
76180
|
76181
|
76182
|
76183
|
76184
|
76185
|
76186
|
76187
|
76188
|
76189
|
76190
|
76191
|
76192
|
76193
|
78602
|
78603
|
78604
|
78605
|
78606
|
78607
|
78608
|
78609
|
78610
|
78611
|
78612
|
78613
|
78614
|
78615
|
79247
|
79668
|
79669
|
79670
|
79671
|
79672
|
79673
|
79674
|
79675
|
79676
|
79677
|
79678
|
79679
|
79680
|
79681
|
79682
|
79752