From 0153ce65c9041ed6af54fe56cc2b2ada9eab6aeb Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 23 Sep 2021 16:09:12 +0000 Subject: [PATCH] Bug 28867: Use Bootstrap button menu and modal for adding patrons to lists This patch reworks the controls for adding patrons to a list from the patron search results page. The - - [% IF patron_lists %] - - [% FOREACH pl IN patron_lists %] - - [% END %] - - [% END %] - - - - - - - - + [% END %] - [% IF CAN_user_tools_manage_patron_lists && CAN_user_borrowers_edit_borrowers %] - | + [% IF CAN_user_tools_manage_patron_lists %] +
+ + +
[% END %] [% IF CAN_user_borrowers_edit_borrowers %] - + [% END %] @@ -210,6 +204,32 @@ + + + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'columns_settings.inc' %] @@ -229,101 +249,70 @@ $('#merge-patrons').prop('disabled', true); $('#memberresultst').on('change', 'input.selection', function() { if ( $('.selection:checked').length > 1 ) { - $('#merge-patrons').prop('disabled', false); + /* More than one checkbox has been checked */ + $('#merge-patrons').prop('disabled', false).removeClass("disabled"); + $("#patronlist-menu").removeClass("disabled").prop("disabled", false); + } else if ( $('.selection:checked').length == 1 ) { + /* At least one checkbox has been checked */ + $('#merge-patrons').prop('disabled', true).addClass("disabled"); + $("#patronlist-menu").removeClass("disabled").prop("disabled", false); } else { - $('#merge-patrons').prop('disabled', true); + /* No checkbox has been checked */ + $('#merge-patrons').prop('disabled', true).addClass("disabled"); + $("#patronlist-menu").addClass("disabled").prop("disabled", true); } }); + $('#merge-patrons').on('click', function() { var merge_patrons_url = 'merge-patrons.pl?' + $('.selection:checked') .map(function() { return "id=" + $(this).val() }).get().join('&'); - window.location.href = merge_patrons_url; }); - $('#add_to_patron_list_submit').prop('disabled', true); - $('#new_patron_list').hide(); - - $('#add_to_patron_list').change(function() { - var value = $('#add_to_patron_list').val(); - if ( value == 'new' ) { - $('#new_patron_list').val('') - $('#new_patron_list').show(); - $('#new_patron_list').focus(); - } else if ( value ) { - $('#new_patron_list').hide(); - $('#add_to_patron_list_submit').prop('disabled', false); - } else { - $('#new_patron_list').hide(); - $('#add_to_patron_list_submit').prop('disabled', true); + $("#patronlist-dropdown").on("click", ".patron-list-add", function(e){ + e.preventDefault(); + + if ( $("#memberresultst input:checkbox:checked").length == 0 ) { + alert( _("You have not selected any patrons to add to a list!") ); + $(".btn-group").removeClass("open"); /* Close button menu */ + return false; } - }); - $('#new_patron_list').on('input', function() { - if ( $('#new_patron_list').val() ) { - $('#add_to_patron_list_submit').prop('disabled', false); + var listid = $(this).data("listid"); + $("#add_to_patron_list").val( listid ); + if( listid == "new" ){ + /* #add_to_patron_list value "new" in the modal form will tell API to create a new list */ + $("#new-patron-list").modal("show"); } else { - $('#add_to_patron_list_submit').prop('disabled', true); - } - }); + /* Ajax submit the patrons to list */ - $("#add_to_patron_list_submit").on('click', function(e){ - if ( $('#add_to_patron_list').val() == 'new' ) { - if ( $('#new_patron_list').val() ) { - $("#add_to_patron_list option").each(function() { - if ( $(this).text() == $('#new_patron_list').val() ) { - alert( _("You already have a list with that name!") ); - return false; - } - }); - } else { - alert( _("You must give your new patron list a name!") ); - return false; - } + patronListAdd(); } + }) - if ( $("#memberresultst input:checkbox:checked").length == 0 ) { - alert( _("You have not selected any patrons to add to a list!") ); + /* Submit selected patrons to a list via AJAX */ + $("#new-patron-list_form").on('submit', function(e){ + e.preventDefault(); + /* Upon submitting modal patron list add form... */ + if ( $('#new_patron_list').val() ) { + $(".patron-list-add").each(function() { + /* Check each list name in the menu of patron lists */ + /* If submitted list name matches... */ + if ( $(this).text() == $('#new_patron_list').val() ) { + alert( _("You already have a list with that name!") ); + return false; + } + }); + } else { + alert( _("You must give your new patron list a name!") ); return false; } - - var borrowernumbers = []; - $("#memberresultst").find("input:checkbox:checked").each(function(){ - borrowernumbers.push($(this).val()); - }); - var data = { - add_to_patron_list: $("#add_to_patron_list").val(), - new_patron_list: $("#new_patron_list").val(), - borrowernumbers: borrowernumbers - }; - $.ajax({ - data: data, - type: 'POST', - url: '/cgi-bin/koha/svc/members/add_to_list', - success: function(data) { - $("#patron_list_dialog").show(); - $("#patron_list_dialog > span.patrons-length").html(data.patrons_added_to_list); - $("#patron_list_dialog > a").attr("href", "/cgi-bin/koha/patron_lists/list.pl?patron_list_id=" + data.patron_list.patron_list_id); - $("#patron_list_dialog > a").html(data.patron_list.name); - if ( $('#add_to_patron_list').val() == 'new' ) { - var new_patron_list_added = $("