[% USE raw %]
[% USE Asset %]
[% USE Koha %]
[% USE Branches %]
[% USE Categories %]
[% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
[% SET libraries = Branches.all %]
[% SET categories = Categories.all.unblessed %]
[% PROCESS 'patron-search.inc' %]
<title>[% FILTER collapse %]
    [% t("Patron search") | html %] &rsaquo;
    [% t("Patrons") | html %] &rsaquo;
    [% t("Koha") | html %]
[% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
<style> .modal-body .close { display: none; } </style>[%# FIXME This is not great, we should make members/memberentrygen.tt use a modal as well and we won't need that here %]
</head>

<body id="common_patron_search" class="common">
<div id="patron_search">
    <div class="container-fluid">

        [% PROCESS patron_search_filters categories => categories, libraries => libraries, filters => ['branch','category','sort1','sort2'], search_filter => searchmember %]
        </form>

        <div id="searchresults">
        [% IF columns.grep('checkbox').size %]
            <div class="searchheader fh-fixedHeader" id="searchheader" style="display:none;">
                <div>
                    <a href="#" class="btn btn-link" id="select_all"><i class="fa fa-check"></i> Select all</a>
                    |
                    <a href="#" class="btn btn-link" id="clear_all"><i class="fa fa-remove"></i> Clear all</a>
                    [% IF selection_type == 'add' %]
                    <button id="add-selected" class="btn btn-sm btn-default" type="submit">Add selected patrons</button>
                    [% END %]
                </div>
            </div>
        [% END %]
        [% PROCESS patron_search_table table_id => 'memberresultst' columns => columns %]
        </div>

        <div id="closewindow"><a href="#" class="btn btn-default btn-default close">Close</a></div>

    </div>
</div>

[% MACRO jsinclude BLOCK %]
[% INCLUDE 'select2.inc' %]
<script>
    $(document).ready(function() {
        $("#select_all").on("click",function(e){
            e.preventDefault();
            $(".selection").prop("checked", true).change();
        });
        $("#clear_all").on("click",function(e){
            e.preventDefault();
            $(".selection").prop("checked", false).change();
        });
        $("#searchheader").hide();
        $("#patron_search_form").on('submit', function(){$("#searchheader").show();});
        $("#clear_search").on("click",function(e){$("#searchheader").hide();});

        $('#add-selected').on('click', function(e) {
            e.preventDefault();
            var counter = 0;
            $('tr:has(.selection:checked) .add_user').each(function(){
                var borrowernumber = $(this).data('borrowernumber');
                var firstname = $(this).data('firstname');
                var surname = $(this).data('surname');
                add_user( borrowernumber, firstname + ' ' + surname );
                counter++;
            });
            $('#info').html(_("%s Patrons added.").format(counter));
        });
    });
</script>

    [% PROCESS patron_search_js table_id => 'memberresultst', categories => categories, libraries => libraries, columns => columns, filter => filter, actions => [selection_type], preview_on_name_click => 1, callback => callback %]
[% END %]

[% SET popup_window = 1 %]
[% INCLUDE 'intranet-bottom.inc' %]
