<!DOCTYPE html>
<html>
    <head>
        {% for src in js %}
            <script type="text/javascript" src="{{ src }}"></script>
        {% endfor %}
        {% for src in css %}
            <link type="text/css" rel="stylesheet" href="{{ src }}">
        {% endfor %}
        
        <script type="text/javascript" src="{{ url_for( 'files.send_app_files', subpath = 'functions.js' ) }}"></script>
        <link type="text/css" rel="stylesheet" href="{{ url_for( 'files.send_app_files', subpath = 'app.css' ) }}">
        <link type="text/css" rel="stylesheet" href="{{ url_for( 'files.send_app_files', subpath = 'dropzone.css' ) }}">
        
        <script type="text/javascript">
            baseurl = "{{ baseurl }}";
            var password_local = decrypt( sessionStorage.getItem( "session_key" ), "{{ session_security_key }}" );
            
            var donors = {};
            {% for donor in donors %}
                donors[ "{{ donor[ 'uuid' ] }}" ] = {
                    "uuid": "{{ donor[ 'uuid' ] }}",
                    "nickname": decrypt( "{{ donor[ 'nickname' ] }}", password_local )
                }
            {% endfor %}
            
            update_search_result = function()
            {
                var searched = $( "#search_bar" ).val();
                searched = searched.toLowerCase();
                
                _.forEach( donors, function( donor )
                {
                    var tmp = [];
                    _.forEach( donor, function( d )
                    {
                        tmp.push( d.toLowerCase().indexOf( searched ) );
                    } );
                    
                    if( Math.max( ...tmp ) > -1 )
                    {
                        $( "#donor_" + donor[ "uuid" ] + "_outer_div" ).show();
                    } else {
                        $( "#donor_" + donor[ "uuid" ] + "_outer_div" ).hide();
                    }
                } );
            }
        </script>
        
        <style type="text/css">
            :root {
                --imgsize: 350px;
            }
            .icnml_list_of_boxes {
                grid-template-columns: repeat( auto-fill, calc( var( --imgsize ) + 2 * var( --imgmargin ) ) );
            }
            .icnml_search_bar {
                margin-bottom: 20px;
                width: 500px;
            }
        </style>
    </head>
    <body class="icnml_main_layout">
        {% include "header.html" %}
        {% include navigation %}
        
        <div class="icnml_content">
            <div class="icnml_search_bar">
                <input id="search_bar" placeholder="Search for a donor..."/>
            </div>
            <div class="icnml_list_of_boxes">
                {% for donor in donors %}
                    <div style="margin-bottom: 20px" id="donor_{{ donor[ 'uuid' ] }}_outer_div">
                        <div class="ui-widget-header ui-corner-top icnml_box_top" id="donor_{{ donor[ 'uuid' ] }}_nickname">-</div>
                        <div class="ui-widget-content ui-corner-bottom icnml_box_content">
                            <div
                                id="img_preview_{{ donor[ 'uuid' ] }}"
                                class="icnml_pointer"
                                style="background-image: url( {{ url_for( 'image.image_file_serve', file_id = donor[ 'f' ] ) }} )">
                            </div>
                        </div>
                    </div>
                {% endfor %}
                <div>
                    <div class="ui-widget-header ui-corner-top icnml_box_top">New</div>
                    <div class="ui-widget-content ui-corner-bottom icnml_box_content">
                        <div class="icnml_button icnml_new_button icnml_pointer" id="icnml_new_donor_button">
                            <span>+</span>
                        </div>
                    </div>
                </div>
            </div>
            <div id="zoom_slider"></div>
        </div>
        
        <script type="text/javascript">
            $( "#search_bar" ).on( "keyup", update_search_result );
            $( "#search_bar" ).focus();
            
            {% for donor in donors %}
                $( "#donor_{{ donor[ 'uuid' ] }}_nickname" ).text( donors[ "{{ donor[ 'uuid' ] }}" ].nickname );
                
                $( "#img_preview_{{ donor[ 'uuid' ] }}" ).on( "click", function()
                {
                    window.location = "{{ url_for( 'submission.submission_upload_tenprintmark', submission_id = donor[ 'uuid' ] ) }}";
                } );
            {% endfor %}
            
            $( "#icnml_new_donor_button" ).on( "click", function()
            {
                window.location = "{{ url_for( 'submission.submission_new' ) }}";
            } );
            $( "#icnml_navigation_submissions" )
                .addClass( "activated" );
            
            $( "#navloc" ).append(
                $( "<span />" ).text( "Submissions" )
            );
        </script>
    </body>
</html>
        
