Bug 11299: Add a button to the biblio edition page to automatically add authority...
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / js / holds.js
index 3182a30..134194b 100644 (file)
@@ -1,3 +1,4 @@
+/* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */
 $(document).ready(function() {
     var holdsTable;
 
@@ -10,28 +11,35 @@ $(document).ready(function() {
     function load_holds_table() {
         var holds = new Array();
         if ( ! holdsTable ) {
-            holdsTable = $("#holds-table").dataTable({
+            var title;
+            holdsTable = $("#holds-table").dataTable($.extend(true, {}, dataTablesDefaults, {
                 "bAutoWidth": false,
                 "sDom": "rt",
                 "columns": [
                     {
-                        "mDataProp": "reservedate_formatted"
+                        "data": { _: "reservedate_formatted", "sort": "reservedate" }
                     },
                     {
                         "mDataProp": function ( oObj ) {
                             title = "<a href='/cgi-bin/koha/reserve/request.pl?biblionumber="
                                   + oObj.biblionumber
                                   + "'>"
-                                  + oObj.title;
+                                  + oObj.title.escapeHtml();
 
                             $.each(oObj.subtitle, function( index, value ) {
-                                      title += " " + value.subfield;
+                                title += " " + value.escapeHtml();
                             });
 
+                            title += " " + oObj.part_number + " " + oObj.part_name;
+
+                            if ( oObj.enumchron ) {
+                                title += " (" + oObj.enumchron.escapeHtml() + ")";
+                            }
+
                             title += "</a>";
 
                             if ( oObj.author ) {
-                                title += " " + BY.replace( "_AUTHOR_",  oObj.author );
+                                title += " " + __("by _AUTHOR_").replace("_AUTHOR_", oObj.author.escapeHtml());
                             }
 
                             if ( oObj.itemnotes ) {
@@ -39,7 +47,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>"
                             }
 
                             return title;
@@ -47,63 +55,52 @@ $(document).ready(function() {
                     },
                     {
                         "mDataProp": function( oObj ) {
-                            return oObj.itemcallnumber || "";
+                            return oObj.itemcallnumber && oObj.itemcallnumber.escapeHtml() || "";
                         }
                     },
                     {
                         "mDataProp": function( oObj ) {
                             var data = "";
-
-                            if ( oObj.suspend == 1 ) {
-                                data += "<p>" + HOLD_IS_SUSPENDED;
-                                if ( oObj.suspend_until ) {
-                                    data += " " + UNTIL.format( oObj.suspend_until_formatted );
-                                }
-                                data += "</p>";
-                            }
-
-                            if ( oObj.itemtype_limit ) {
-                                data += NEXT_AVAILABLE_ITYPE.format( oObj.itemtype_limit );
-                            }
-
                             if ( oObj.barcode ) {
-                                data += "<em>";
-                                if ( oObj.found == "W" ) {
-
-                                    if ( oObj.waiting_here ) {
-                                        data += ITEM_IS_WAITING_HERE;
-                                    } else {
-                                        data += ITEM_IS_WAITING;
-                                        data += " " + AT.format( oObj.waiting_at );
-                                    }
-
-                                } else if ( oObj.transferred ) {
-                                    data += ITEM_IS_IN_TRANSIT.format( oObj.from_branch, oObj.date_sent );
-                                } else if ( oObj.not_transferred ) {
-                                    data += NOT_TRANSFERRED_YET.format( oObj.not_transferred_by );
-                                }
-                                data += "</em>";
-
-                                data += " <a href='/cgi-bin/koha/catalogue/detail.pl?biblionumber="
+                                data += " <a href='/cgi-bin/koha/catalogue/moredetail.pl?biblionumber="
                                   + oObj.biblionumber
                                   + "&itemnumber="
                                   + oObj.itemnumber
-                                  + "#"
+                                  + "#item"
                                   + oObj.itemnumber
                                   + "'>"
-                                  + oObj.barcode
+                                  + oObj.barcode.escapeHtml()
                                   + "</a>";
                             }
-
                             return data;
                         }
                     },
                     {
                         "mDataProp": function( oObj ) {
-                            return oObj.branchcode || "";
+                            if( oObj.branches.length > 1 && oObj.found !== 'W' && oObj.found !== 'T' ){
+                                var branchSelect='<select priority='+oObj.priority+' class="hold_location_select" reserve_id="'+oObj.reserve_id+'" name="pick-location">';
+                                for ( var i=0; i < oObj.branches.length; i++ ){
+                                    var selectedbranch;
+                                    var setbranch;
+                                    if( oObj.branches[i].selected ){
+
+                                        selectedbranch = " selected='selected' ";
+                                        setbranch = __(" (current) ");
+                                    } else if ( oObj.branches[i].pickup_location == 0 ) {
+                                        continue;
+                                    } else{
+                                        selectedbranch = '';
+                                        setbranch = '';
+                                    }
+                                    branchSelect += '<option value="'+ oObj.branches[i].branchcode.escapeHtml() +'"'+selectedbranch+'>'+oObj.branches[i].branchname.escapeHtml()+setbranch+'</option>';
+                                }
+                                branchSelect +='</select>';
+                                return branchSelect;
+                            }
+                            else { return oObj.branchcode.escapeHtml() || ""; }
                         }
                     },
-                    { "mDataProp": "expirationdate_formatted" },
+                    { "data": { _: "expirationdate_formatted", "sort": "expirationdate" } },
                     {
                         "mDataProp": function( oObj ) {
                             if ( oObj.priority && parseInt( oObj.priority ) && parseInt( oObj.priority ) > 0 ) {
@@ -117,8 +114,8 @@ $(document).ready(function() {
                         "bSortable": false,
                         "mDataProp": function( oObj ) {
                             return "<select name='rank-request'>"
-                                 + "<option value='n'>" + NO + "</option>"
-                                 + "<option value='del'>" + YES  + "</option>"
+                                 +"<option value='n'>" + __("No") + "</option>"
+                                 +"<option value='del'>" + __("Yes") + "</option>"
                                  + "</select>"
                                  + "<input type='hidden' name='biblionumber' value='" + oObj.biblionumber + "'>"
                                  + "<input type='hidden' name='borrowernumber' value='" + borrowernumber + "'>"
@@ -127,18 +124,63 @@ $(document).ready(function() {
                     },
                     {
                         "bSortable": false,
+                        "visible": SuspendHoldsIntranet,
                         "mDataProp": function( oObj ) {
                             holds[oObj.reserve_id] = oObj; //Store holds for later use
 
                             if ( oObj.found ) {
                                 return "";
                             } else if ( oObj.suspend == 1 ) {
-                                return "<a class='hold-resume btn btn-link' id='resume" + oObj.reserve_id + "' style='display: inline; white-space: nowrap;'>"
-                                     + "<i class='icon-play'></i> " + RESUME + "</a>";
+                                return "<a class='hold-resume btn btn-default btn-xs' id='resume" + oObj.reserve_id + "'>"
+                                     +"<i class='fa fa-play'></i> " + __("Resume") + "</a>";
                             } else {
-                                return "<a class='hold-suspend btn btn-link' id='suspend" + oObj.reserve_id + "' style='display: inline; white-space: nowrap;'>"
-                                     + "<i class='icon-pause'></i> " + SUSPEND + "</a>";
+                                return "<a class='hold-suspend btn btn-default btn-xs' id='suspend" + oObj.reserve_id + "'>"
+                                     +"<i class='fa fa-pause'></i> " + __("Suspend") + "</a>";
+                            }
+                        }
+                    },
+                    {
+                        "mDataProp": function( oObj ) {
+                            var data = "";
+
+                            if ( oObj.suspend == 1 ) {
+                                data += "<p>" + __("Hold is <strong>suspended</strong>");
+                                if ( oObj.suspend_until ) {
+                                    data += " " + __("until %s").format(oObj.suspend_until_formatted);
+                                }
+                                data += "</p>";
                             }
+
+                            if ( oObj.itemtype_limit ) {
+                                data += __("Next available %s item").format(oObj.itemtype_limit);
+                            }
+
+                            if ( oObj.barcode ) {
+                                data += "<em>";
+                                if ( oObj.found == "W" ) {
+
+                                    if ( oObj.waiting_here ) {
+                                        data += __("Item is <strong>waiting here</strong>");
+                                        if (oObj.desk_name) {
+                                            data += ", " + __("at %s").format(oObj.desk_name.escapeHtml());
+                                        }
+                                    } else {
+                                        data += __("Item is <strong>waiting</strong>");
+                                        data += " " + __("at %s").format(oObj.waiting_at);
+                                        if (oObj.desk_name) {
+                                            data += ", " + __("at %s").format(oObj.desk_name.escapeHtml());
+                                        }
+
+                                    }
+
+                                } else if ( oObj.transferred ) {
+                                    data += __("Item is <strong>in transit</strong> from %s since %s").format(oObj.from_branch, oObj.date_sent);
+                                } else if ( oObj.not_transferred ) {
+                                    data += __("Item hasn't been transferred yet from %s").format(oObj.not_transferred_by);
+                                }
+                                data += "</em>";
+                            }
+                            return data;
                         }
                     }
                 ],
@@ -151,7 +193,7 @@ $(document).ready(function() {
                         d.borrowernumber = borrowernumber;
                     }
                 },
-            });
+            }));
 
             $('#holds-table').on( 'draw.dt', function () {
                 $(".hold-suspend").on( "click", function() {
@@ -170,12 +212,34 @@ $(document).ready(function() {
                           holdsTable.api().ajax.reload();
                       } else {
                         if ( data.error == "HOLD_NOT_FOUND" ) {
-                            alert ( RESUME_HOLD_ERROR_NOT_FOUND );
+                            alert( __("Unable to resume, hold not found") );
                             holdsTable.api().ajax.reload();
                         }
                       }
                     });
                 });
+
+                $(".hold_location_select").change(function(){
+                    $(this).prop("disabled",true);
+                    var cur_select = $(this);
+                    var res_id = $(this).attr('reserve_id');
+                    $(this).after('<div id="updating_reserveno'+res_id+'" class="waiting"><img src="/intranet-tmpl/prog/img/spinner-small.gif" alt="" /><span class="waiting_msg"></span></div>');
+                    var api_url = '/api/v1/holds/'+res_id;
+                    var update_info = JSON.stringify({ pickup_library_id: $(this).val(), priority: parseInt($(this).attr("priority"),10) });
+                    $.ajax({
+                        method: "PUT",
+                        url: api_url,
+                        data: update_info ,
+                        success: function( data ){ holdsTable.api().ajax.reload(); },
+                        error: function( jqXHR, textStatus, errorThrown) {
+                            alert('There was an error:'+textStatus+" "+errorThrown);
+                            cur_select.prop("disabled",false);
+                            $("#updating_reserveno"+res_id).remove();
+                            cur_select.val( cur_select.children('option[selected="selected"]').val() );
+                        },
+                    });
+                });
+
             });
 
             if ( $("#holds-table").length ) {
@@ -188,28 +252,32 @@ $(document).ready(function() {
     }
 
     $("body").append("\
-        <div id='suspend-modal' class='modal hide fade' tabindex='-1' role='dialog' aria-hidden='true'>\
+        <div id='suspend-modal' class='modal fade' role='dialog' aria-hidden='true'>\
+            <div class='modal-dialog'>\
+            <div class='modal-content'>\
             <form id='suspend-modal-form' class='form-inline'>\
                 <div class='modal-header'>\
                     <button type='button' class='closebtn' data-dismiss='modal' aria-hidden='true'>×</button>\
-                    <h3 id='suspend-modal-label'>" + SUSPEND_HOLD_ON + " <i><span id='suspend-modal-title'></span></i></h3>\
+                    <h3 id='suspend-modal-label'>" + __("Suspend hold on") + " <i><span id='suspend-modal-title'></span></i></h3>\
                 </div>\
 \
                 <div class='modal-body'>\
                     <input type='hidden' id='suspend-modal-reserve_id' name='reserve_id' />\
 \
-                    <label for='suspend-modal-until'>Suspend until:</label>\
+                    <label for='suspend-modal-until'>" + __("Suspend until:") + "</label>\
                     <input name='suspend_until' id='suspend-modal-until' class='suspend-until' size='10' />\
 \
-                    <p/><a class='btn btn-link' id='suspend-modal-clear-date' >" + CLEAR_DATE_TO_SUSPEND_INDEFINITELY + "</a></p>\
+                    <p><a class='btn btn-link' id='suspend-modal-clear-date' >" + __("Clear date to suspend indefinitely") + "</a></p>\
 \
                 </div>\
 \
                 <div class='modal-footer'>\
-                    <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + SUSPEND + "</button>\
-                    <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + CANCEL + "</a>\
+                    <button id='suspend-modal-submit' class='btn btn-primary' type='submit' name='submit'>" + __("Suspend") + "</button>\
+                    <a href='#' data-dismiss='modal' aria-hidden='true' class='cancel'>" + __("Cancel") + "</a>\
                 </div>\
             </form>\
+            </div>\
+            </div>\
         </div>\
     ");
 
@@ -224,14 +292,13 @@ $(document).ready(function() {
               holdsTable.api().ajax.reload();
           } else {
             if ( data.error == "INVALID_DATE" ) {
-                alert( SUSPEND_HOLD_ERROR_DATE );
+                alert( __("Unable to suspend hold, invalid date") );
             }
             else if ( data.error == "HOLD_NOT_FOUND" ) {
-                alert ( SUSPEND_HOLD_ERROR_NOT_FOUND );
+                alert( __("Unable to suspend hold, hold not found") );
                 holdsTable.api().ajax.reload();
             }
           }
         });
     });
-
 });