Bugzilla – Attachment 145618 Details for
Bug 32711
Add biblio details to trusted self-checkout modal
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32711: Add biblio details to modal
Bug-32711-Add-biblio-details-to-modal.patch (text/plain), 9.89 KB, created by
Martin Renvoize (ashimema)
on 2023-01-24 15:27:22 UTC
(
hide
)
Description:
Bug 32711: Add biblio details to modal
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-01-24 15:27:22 UTC
Size:
9.89 KB
patch
obsolete
>From e5d66eda4402df17b51d75a1fb5febc97157cf21 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 24 Jan 2023 12:22:34 +0000 >Subject: [PATCH] Bug 32711: Add biblio details to modal > >This patch adds biblio details to the self-checkout modal. As part of >this we add 'biblio' to the x-koha-embed option on the public items >endpoint, clone the js-biblio-format include from the staff client >adapting it slightly for OPAC use along the way and also import >escape_str and escapeHtml from staff to opac too. >--- > api/v1/swagger/paths/items.yaml | 30 +++++++-- > .../en/includes/js-biblio-format.inc | 64 +++++++++++++++++++ > .../bootstrap/en/includes/modals/checkout.inc | 4 +- > .../bootstrap/en/includes/opac-bottom.inc | 1 + > koha-tmpl/opac-tmpl/bootstrap/js/global.js | 14 ++++ > .../opac-tmpl/bootstrap/js/modals/checkout.js | 23 +++++-- > 6 files changed, 124 insertions(+), 12 deletions(-) > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/includes/js-biblio-format.inc > >diff --git a/api/v1/swagger/paths/items.yaml b/api/v1/swagger/paths/items.yaml >index 7b6017acfb7..12df48fe487 100644 >--- a/api/v1/swagger/paths/items.yaml >+++ b/api/v1/swagger/paths/items.yaml >@@ -169,6 +169,20 @@ > - $ref: "../swagger.yaml#/parameters/q_param" > - $ref: "../swagger.yaml#/parameters/q_body" > - $ref: "../swagger.yaml#/parameters/q_header" >+ - name: x-koha-embed >+ in: header >+ required: false >+ description: Embed list sent as a request header >+ type: array >+ items: >+ type: string >+ enum: >+ - biblio >+ - checkout >+ - return_claims >+ - return_claim >+ - return_claim.patron >+ collectionFormat: csv > consumes: > - application/json > produces: >@@ -199,12 +213,6 @@ > x-koha-authorization: > permissions: > catalogue: "1" >- x-koha-embed: >- - biblio >- - checkout >- - return_claims >- - return_claim >- - return_claim.patron > "/items/{item_id}/bundled_items/{bundled_item_id}": > delete: > x-mojo-to: Items#remove_from_bundle >@@ -337,6 +345,16 @@ > - $ref: "../swagger.yaml#/parameters/q_body" > - $ref: "../swagger.yaml#/parameters/q_header" > - $ref: "../swagger.yaml#/parameters/request_id_header" >+ - name: x-koha-embed >+ in: header >+ required: false >+ description: Embed list sent as a request header >+ type: array >+ items: >+ type: string >+ enum: >+ - biblio >+ collectionFormat: csv > consumes: > - application/json > produces: >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-biblio-format.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-biblio-format.inc >new file mode 100644 >index 00000000000..77c2fe5c183 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-biblio-format.inc >@@ -0,0 +1,64 @@ >+<script> >+ (function() { >+ /** >+ * Format the biblio response from a Koha RESTful API request. >+ * @param {Object} biblio The biblio json object as returned from the Koha RESTful API >+ * @param {Object} config A configuration object >+ * Valid keys are: `link` >+ * @return {string} The formatted HTML string >+ */ >+ window.$biblio_to_html = function(biblio, config) { >+ >+ if (biblio === undefined) { >+ return ''; // empty string for no biblio >+ } >+ >+ var title = '<span class="biblio-title">'; >+ if (biblio.title != null && biblio.title != '') { >+ title += escape_str(biblio.title); >+ } else { >+ title += __("No title"); >+ } >+ title += '</span>'; >+ >+ // add subtitle >+ if (biblio.subtitle != null && biblio.subtitle != '') { >+ title += ' <span class="biblio-subtitle">' + escape_str(biblio.subtitle) + '</span>'; >+ } >+ >+ // set title as link >+ if (config && config.link) { >+ if (config.link === 'marcdetail') { >+ title = '<a href="/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; >+ } else if (config.link === 'labeled_marc') { >+ title = '<a href="/cgi-bin/koha/opac-labeledMARCdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; >+ } else if (config.link === 'isbd') { >+ title = '<a href="/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; >+ } else { >+ title = '<a href="/cgi-bin/koha/opac-detail.pl?biblionumber=' + encodeURIComponent(biblio.biblio_id) + '" class="title">' + title + '</a>'; >+ } >+ } >+ >+ // add medium >+ if (biblio.medium != null && biblio.medium != '') { >+ title += ' <span class="biblio-medium">' + escape_str(biblio.medium) + '</span>'; >+ } >+ >+ // add part numbers/names >+ let part_numbers = (typeof biblio.part_number === 'string') ? biblio.part_number.split("|") : []; >+ let part_names = (typeof biblio.part_name === 'string') ? biblio.part_name.split("|") : []; >+ let i = 0; >+ while (part_numbers[i] || part_names[i]) { >+ if (part_numbers[i]) { >+ title += ' <span class="part-number">' + escape_str(part_numbers[i]) + '</span>'; >+ } >+ if (part_names[i]) { >+ title += ' <span class="part-name">' + escape_str(part_names[i]) + '</span>'; >+ } >+ i++; >+ } >+ >+ return title; >+ }; >+ })(); >+</script> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/checkout.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/checkout.inc >index 6a19e717de8..615345ef77f 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/checkout.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/modals/checkout.inc >@@ -19,6 +19,8 @@ > <thead> > <tr> > <th>Barcode</th> >+ <th>Title</th> >+ <th>Call number</th> > <th>Due date</th> > </tr> > </thead> >@@ -26,7 +28,7 @@ > </tbody> > <tfoot> > <tr> >- <td colspan="2" class="text-right"><span id="checkoutsCount"></span> items checked out</td> >+ <td colspan="4" class="text-right"><span id="checkoutsCount"></span> items checked out</td> > </tr> > </tfoot> > </table> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >index 187f8e612df..260a8f63bd3 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >@@ -296,6 +296,7 @@ $(document).ready(function() { > }); > </script> > [% INCLUDE 'js-date-format.inc' %] >+[% INCLUDE 'js-biblio-format.inc' %] > [% PROCESS jsinclude %] > [% IF ( Koha.Preference('OPACUserJS') ) %] > <script> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/global.js b/koha-tmpl/opac-tmpl/bootstrap/js/global.js >index ce5d4f64b6a..f79f4e49e98 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/global.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/global.js >@@ -27,6 +27,20 @@ function formatstr(str, col) { > }); > }; > >+var HtmlCharsToEscape = { >+ '&': '&', >+ '<': '<', >+ '>': '>' >+}; >+String.prototype.escapeHtml = function() { >+ return this.replace(/[&<>]/g, function(c) { >+ return HtmlCharsToEscape[c] || c; >+ }); >+}; >+function escape_str(s){ >+ return s != null ? s.escapeHtml() : ""; >+} >+ > function confirmDelete(message) { > return (confirm(message) ? true : false); > } >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/modals/checkout.js b/koha-tmpl/opac-tmpl/bootstrap/js/modals/checkout.js >index c057fa90728..cce378662e9 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/js/modals/checkout.js >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/modals/checkout.js >@@ -55,8 +55,18 @@ $(document).ready(function() { > // Display checkouts table if not already visible > $('#checkoutsTable').show(); > // Add checkout to checkouts table >- $('#checkoutsTable > tbody').append('<tr><td>' + current_item.external_id +'</td><td>'+ $date(checkout.due_date) +'</td></tr>'); >- $('#checkoutsCount').html(++checkouts_count); >+ $("#checkoutsTable > tbody").append( >+ "<tr><td>" + >+ current_item.external_id + >+ "</td><td>" + >+ $biblio_to_html(current_item.biblio, { link: 0 }) + >+ "</td><td>" + >+ current_item.callnumber + >+ "</td><td>" + >+ $date(checkout.due_date) + >+ "</td></tr>" >+ ); >+ $("#checkoutsCount").html(++checkouts_count); > // Reset to submission > $('#checkoutConfirm').replaceWith('<button type="submit" id="checkoutSubmit" class="btn btn-primary">Submit</button>'); > }; >@@ -103,9 +113,12 @@ $(document).ready(function() { > > let item_id; > let items = $.ajax({ >- url: '/api/v1/public/items?external_id=' + external_id, >- dataType: 'json', >- type: 'GET' >+ url: "/api/v1/public/items?external_id=" + external_id, >+ headers: { >+ "x-koha-embed": "biblio", >+ }, >+ dataType: "json", >+ type: "GET", > }); > > $('#availabilityResult').replaceWith('<div id="availabilityResult"></div>'); >-- >2.39.1
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 32711
:
145618
|
145619
|
145787
|
145788
|
150984
|
150985
|
150986
|
151262
|
151263
|
151264
|
152800
|
152801
|
152802
|
153468
|
153469
|
153470