Bug 15494: Update display of renewal errors
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / checkouts.js
index 6beef27..9902f5b 100644 (file)
@@ -38,7 +38,7 @@ $(document).ready(function() {
 
     $("#output_format > option:first-child").attr("selected", "selected");
     $("select[name='csv_profile_id']").hide();
-    $(document).on("change", '#output_format', function(){
+    $(document).on("change", '#issues-table-output-format', function(){
         if ( $(this).val() == 'csv' ) {
             $("select[name='csv_profile_id']").show();
         } else {
@@ -77,6 +77,9 @@ $(document).ready(function() {
                     content = CIRCULATION_RETURNED;
                     $(id).parent().parent().addClass('ok');
                     $('#date_due_' + data.itemnumber).html(CIRCULATION_RETURNED);
+                    if ( data.patronnote != null ) {
+                        $('.patron_note_' + data.itemnumber).html("Patron note: " + data.patronnote);
+                    }
                 } else {
                     content = CIRCULATION_NOT_RETURNED;
                     $(id).parent().parent().addClass('warn');
@@ -178,7 +181,7 @@ $(document).ready(function() {
         $('#issues-table').show();
         $('#issues-table-actions').show();
 
-        issuesTable = KohaTable("#issues-table", {
+        issuesTable = KohaTable("issues-table", {
             "oLanguage": {
                 "sEmptyTable" : MSG_DT_LOADING_RECORDS,
                 "sProcessing": MSG_DT_LOADING_RECORDS,
@@ -216,46 +219,54 @@ $(document).ready(function() {
                         due = "<span id='date_due_" + oObj.itemnumber + "' class='date_due'>" + due + "</span>";
 
                         if ( oObj.lost ) {
-                            due += "<span class='lost'>" + oObj.lost + "</span>";
+                            due += "<span class='lost'>" + oObj.lost.escapeHtml() + "</span>";
                         }
 
                         if ( oObj.damaged ) {
-                            due += "<span class='dmg'>" + oObj.damaged + "</span>";
+                            due += "<span class='dmg'>" + oObj.damaged.escapeHtml() + "</span>";
                         }
 
+                        var patron_note = " <span class='patron_note_" + oObj.itemnumber + "'></span>";
+                        due +="<br>" + patron_note;
 
                         return due;
                     }
                 },
                 {
                     "mDataProp": function ( oObj ) {
-                        title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
+                        title = "<span id='title_" + oObj.itemnumber + "' class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
                               + oObj.biblionumber
                               + "'>"
-                              + oObj.title;
+                              + oObj.title.escapeHtml();
 
                         $.each(oObj.subtitle, function( index, value ) {
-                                  title += " " + value.subfield;
+                                  title += " " + value.subfield.escapeHtml();
                         });
 
                         if ( oObj.enumchron ) {
-                            title += " (" + oObj.enumchron + ")";
+                            title += " (" + oObj.enumchron.escapeHtml() + ")";
                         }
 
                         title += "</a></span>";
 
                         if ( oObj.author ) {
-                            title += " " + BY.replace( "_AUTHOR_",  " " + oObj.author );
+                            title += " " + BY.replace( "_AUTHOR_",  " " + oObj.author.escapeHtml() );
                         }
 
                         if ( oObj.itemnotes ) {
                             var span_class = "text-muted";
-                            title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
+                            if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
+                                span_class = "circ-hlt";
+                            }
+                            title += " - <span class='" + span_class + " item-note-public'>" + oObj.itemnotes.escapeHtml() + "</span>";
                         }
 
                         if ( oObj.itemnotes_nonpublic ) {
                             var span_class = "text-danger";
-                            title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic + "</span>"
+                            if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
+                                span_class = "circ-hlt";
+                            }
+                            title += " - <span class='" + span_class + " item-note-nonpublic'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>";
                         }
 
                         var onsite_checkout = '';
@@ -271,20 +282,52 @@ $(document).ready(function() {
                               + "#"
                               + oObj.itemnumber
                               + "'>"
-                              + oObj.barcode
+                              + oObj.barcode.escapeHtml()
                               + "</a>"
-                              + onsite_checkout;
+                              + onsite_checkout
 
                         return title;
                     },
                     "sType": "anti-the"
                 },
-                { "mDataProp": "itemtype_description" },
-                { "mDataProp": "location" },
-                { "mDataProp": "homebranch" },
-                { "mDataProp": "issuedate_formatted" },
-                { "mDataProp": "branchname" },
-                { "mDataProp": "itemcallnumber" },
+                {
+                    "mDataProp": function ( oObj ) {
+                        return oObj.itemtype_description.escapeHtml();
+                    }
+                },
+                {
+                    "mDataProp": function ( oObj ) {
+                        return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
+                    }
+                },
+                {
+                    "mDataProp": function ( oObj ) {
+                        return ( oObj.location ? oObj.location.escapeHtml() : '' );
+                    }
+                },
+                {
+                    "mDataProp": function ( oObj ) {
+                        return oObj.homebranch.escapeHtml();
+                    }
+                },
+                {
+                    "mDataProp": "issuedate",
+                    "bVisible": false,
+                },
+                {
+                    "iDataSort": 9, // Sort on hidden unformatted issuedate column
+                    "mDataProp": "issuedate_formatted",
+                },
+                {
+                    "mDataProp": function ( oObj ) {
+                        return oObj.branchname.escapeHtml();
+                    }
+                },
+                {
+                    "mDataProp": function ( oObj ) {
+                        return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
+                    }
+                },
                 {
                     "mDataProp": function ( oObj ) {
                         if ( ! oObj.charge ) oObj.charge = 0;
@@ -363,6 +406,20 @@ $(document).ready(function() {
                                     + NOT_RENEWABLE_AUTO_TOO_LATE
                                     + "</span>";
 
+                            span_style = "display: none";
+                            span_class = "renewals-allowed";
+                        } else if ( oObj.can_renew_error == "auto_too_much_oweing" ) {
+                            content += "<span class='renewals-disabled'>"
+                                    + NOT_RENEWABLE_AUTO_TOO_MUCH_OWEING
+                                    + "</span>";
+
+                            span_style = "display: none";
+                            span_class = "renewals-allowed";
+                        } else if ( oObj.can_renew_error == "auto_account_expired" ) {
+                            content += "<span class='renewals-disabled'>"
+                                    + NOT_RENEWABLE_AUTO_ACCOUNT_EXPIRED
+                                    + "</span>";
+
                             span_style = "display: none";
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "auto_renew" ) {
@@ -374,6 +431,13 @@ $(document).ready(function() {
                             span_class = "renewals-allowed";
                         } else if ( oObj.can_renew_error == "onsite_checkout" ) {
                             // Don't display something if it's an onsite checkout
+                        } else if ( oObj.can_renew_error == "item_denied_renewal" ) {
+                            content += "<span class='renewals-disabled'>"
+                                    + NOT_RENEWABLE_DENIED
+                                    + "</span>";
+
+                            span_style = "display: none";
+                            span_class = "renewals-allowed";
                         } else {
                             content += "<span class='renewals-disabled'>"
                                     + oObj.can_renew_error
@@ -416,7 +480,7 @@ $(document).ready(function() {
                     }
                 },
                 {
-                    "bVisible": exports_enabled ? true : false,
+                    "bVisible": exports_enabled == 1 ? true : false,
                     "bSortable": false,
                     "mDataProp": function ( oObj ) {
                         var s = "<input type='checkbox' name='itemnumbers' value='" + oObj.itemnumber + "' style='visibility:hidden;' />";
@@ -450,7 +514,7 @@ $(document).ready(function() {
                     fnCallback(json)
                 } );
             },
-            "fnInitComplete": function(oSettings) {
+            "fnInitComplete": function(oSettings, json) {
                 // Disable rowGrouping plugin after first use
                 // so any sorting on the table doesn't use it
                 var oSettings = issuesTable.fnSettings();
@@ -463,6 +527,24 @@ $(document).ready(function() {
                 }
 
                 oSettings.aaSortingFixed = null;
+
+                // Build a summary of checkouts grouped by itemtype
+                var checkoutsByItype = json.aaData.reduce(function (obj, row) {
+                    obj[row.itemtype_description] = (obj[row.itemtype_description] || 0) + 1;
+                    return obj;
+                }, {});
+                var ul = $('<ul>');
+                Object.keys(checkoutsByItype).sort().forEach(function (itype) {
+                    var li = $('<li>')
+                        .append($('<strong>').html(itype || MSG_NO_ITEMTYPE))
+                        .append(': ' + checkoutsByItype[itype]);
+                    ul.append(li);
+                })
+                $('<details>')
+                    .addClass('checkouts-by-itemtype')
+                    .append($('<summary>').html(MSG_CHECKOUTS_BY_ITEMTYPE))
+                    .append(ul)
+                    .insertBefore(oSettings.nTableWrapper)
             },
         }, columns_settings).rowGrouping(
             {
@@ -494,7 +576,7 @@ $(document).ready(function() {
                         "bVisible": false,
                     },
                     {
-                        "iDataSort": 1, // Sort on hidden unformatted date due column
+                        "iDataSort": 0, // Sort on hidden unformatted date due column
                         "mDataProp": function( oObj ) {
                             var today = new Date();
                             var due = new Date( oObj.date_due );
@@ -510,20 +592,20 @@ $(document).ready(function() {
                             title = "<span class='strong'><a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
                                   + oObj.biblionumber
                                   + "'>"
-                                  + oObj.title;
+                                  + oObj.title.escapeHtml();
 
                             $.each(oObj.subtitle, function( index, value ) {
-                                      title += " " + value.subfield;
+                                      title += " " + value.subfield.escapeHtml();
                             });
 
                             if ( oObj.enumchron ) {
-                                title += " (" + oObj.enumchron + ")";
+                                title += " (" + oObj.enumchron.escapeHtml() + ")";
                             }
 
                             title += "</a></span>";
 
                             if ( oObj.author ) {
-                                title += " " + BY.replace( "_AUTHOR_", " " + oObj.author );
+                                title += " " + BY.replace( "_AUTHOR_", " " + oObj.author.escapeHtml() );
                             }
 
                             if ( oObj.itemnotes ) {
@@ -531,7 +613,7 @@ $(document).ready(function() {
                                 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
                                     span_class = "circ-hlt";
                                 }
-                                title += " - <span class='" + span_class + "'>" + oObj.itemnotes + "</span>"
+                                title += " - <span class='" + span_class + "'>" + oObj.itemnotes.escapeHtml() + "</span>"
                             }
 
                             if ( oObj.itemnotes_nonpublic ) {
@@ -539,7 +621,7 @@ $(document).ready(function() {
                                 if ( $.datepicker.formatDate('yy-mm-dd', new Date(oObj.issuedate) ) == ymd ) {
                                     span_class = "circ-hlt";
                                 }
-                                title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic + "</span>"
+                                title += " - <span class='" + span_class + "'>" + oObj.itemnotes_nonpublic.escapeHtml() + "</span>"
                             }
 
                             var onsite_checkout = '';
@@ -555,7 +637,7 @@ $(document).ready(function() {
                                   + "#"
                                   + oObj.itemnumber
                                   + "'>"
-                                  + oObj.barcode
+                                  + oObj.barcode.escapeHtml()
                                   + "</a>"
                                   + onsite_checkout;
 
@@ -563,11 +645,39 @@ $(document).ready(function() {
                         },
                         "sType": "anti-the"
                     },
-                    { "mDataProp": "itemtype" },
-                    { "mDataProp": "location" },
-                    { "mDataProp": "issuedate_formatted" },
-                    { "mDataProp": "branchname" },
-                    { "mDataProp": "itemcallnumber" },
+                    {
+                        "mDataProp": function ( oObj ) {
+                            return oObj.itemtype_description.escapeHtml();
+                        }
+                    },
+                    {
+                        "mDataProp": function ( oObj ) {
+                            return ( oObj.collection ? oObj.collection.escapeHtml() : '' );
+                        }
+                    },
+                    {
+                        "mDataProp": function ( oObj ) {
+                            return ( oObj.location ? oObj.location.escapeHtml() : '' );
+                        }
+                    },
+                    {
+                        "mDataProp": "issuedate",
+                        "bVisible": false,
+                    },
+                    {
+                        "iDataSort": 7, // Sort on hidden unformatted issuedate column
+                        "mDataProp": "issuedate_formatted",
+                    },
+                    {
+                        "mDataProp": function ( oObj ) {
+                            return oObj.branchname.escapeHtml();
+                        }
+                    },
+                    {
+                        "mDataProp": function ( oObj ) {
+                            return ( oObj.itemcallnumber ? oObj.itemcallnumber.escapeHtml() : '' );
+                        }
+                    },
                     {
                         "mDataProp": function ( oObj ) {
                             if ( ! oObj.charge ) oObj.charge = 0;
@@ -589,7 +699,10 @@ $(document).ready(function() {
                     {
                         "mDataProp": function( oObj ) {
                             return "<a href='/cgi-bin/koha/members/moremember.pl?borrowernumber=" + oObj.borrowernumber + "'>"
-                                 + oObj.borrower.firstname + " " + oObj.borrower.surname + " (" + oObj.borrower.cardnumber + ")</a>"
+                                + oObj.borrower.firstname.escapeHtml()
+                                + " " +
+                                oObj.borrower.surname.escapeHtml()
+                                + " (" + oObj.borrower.cardnumber.escapeHtml() + ")</a>"
                         }
                     },
                 ],