From 7e8e094ab59d68e3e72f353ce3d768f43cfce2f5 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Fri, 24 Aug 2018 16:22:20 -0300
Subject: [PATCH] Bug 21257: (bug 13618 follow-up) Handle undef values in JS
 before escapeHtml call

To test:
1 - Find an item with no collection or location defined
2 - Check it out to a patron
3 - Note you cannot view the checkouts table
4 - Check the console: TypeError: oObj.collection is null
5 - Apply patch
6 - Restart all the things
7 - Checkouts table should load

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
index 2525f567c7..b964a9cd8f 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js
@@ -297,12 +297,12 @@ $(document).ready(function() {
                 },
                 {
                     "mDataProp": function ( oObj ) {
-                        return oObj.collection.escapeHtml();
+                        return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
                     }
                 },
                 {
                     "mDataProp": function ( oObj ) {
-                        return oObj.location.escapeHtml();
+                        return ( oObj.location ? oObj.location.escapeHtml() : '' );
                     }
                 },
                 {
@@ -318,7 +318,7 @@ $(document).ready(function() {
                 },
                 {
                     "mDataProp": function ( oObj ) {
-                        return oObj.itemcallnumber.escapeHtml();
+                        return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
                     }
                 },
                 {
@@ -638,12 +638,12 @@ $(document).ready(function() {
                     },
                     {
                         "mDataProp": function ( oObj ) {
-                            return oObj.collection.escapeHtml();
+                            return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
                         }
                     },
                     {
                         "mDataProp": function ( oObj ) {
-                            return oObj.location.escapeHtml();
+                            return ( oObj.location ? oObj.location.escapeHtml() : '' );
                         }
                     },
                     { "mDataProp": "issuedate_formatted" },
@@ -654,7 +654,7 @@ $(document).ready(function() {
                     },
                     {
                         "mDataProp": function ( oObj ) {
-                            return oObj.itemcallnumber.escapeHtml();
+                            return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
                         }
                     },
                     {
-- 
2.11.0