{{!
    This file is part of Moodle - http://moodle.org/

    Moodle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moodle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    Edwiser Reports
    @package   local_edwiserreports
    @copyright (c) 2020 WisdmLabs (https://wisdmlabs.com/)
    @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

}}
{{!
    @template local_edwiserreports/old_logs

    Display the log calculation.

    Context variables required for this template:

    Example context (json):
    {
        "run": "1"
    }
}}
<div class="w-100">
    <div class="text-left m-auto">
        {{#run}}
            <label class="h4 d-block mb-2">{{#str}} fetchingoldlogs, local_edwiserreports {{/str}}</label>
            <div class="courses-list">
                <div class='mx-auto font-weight-700'>
                    <label class="h4 mb-0 mt-1">{{#str}} overallprogress, local_edwiserreports {{/str}}</label>
                    <div class='mx-auto'>
                        <div class='progress my-25'>
                            <div id='overall-progress' class='progress-bar' role='progressbar' style='width: 0%;' aria-valuenow='0'
                            aria-valuemin='0' aria-valuemax='100'>0%</div>
                        </div>
                    </div>
                </div>
                {{#courses}}
                <div data-course-id="{{id}}" class='mx-auto font-weight-700 d-none'>
                    <label class="h4 mb-0 mt-1">{{fullname}}</label>
                    <div class='mx-auto'>
                        <div class='progress my-25'>
                            <div id='course-{{id}}' class='progress-bar' role='progressbar' style='width: 0%;' aria-valuenow='0'
                            aria-valuemin='0' aria-valuemax='100'>0%</div>
                        </div>
                    </div>
                </div>
                {{/courses}}
                <div class="continue mt-2 text-center d-none">
                    <button id="continue" class="btn btn-primary">{{#str}} continue {{/str}}</button>
                </div>
            </div>
            <div class="text-left mt-3">
                {{{note}}}
            </div>
        {{/run}}
    </div>
</div>
{{#js}}
    require(['jquery', 'core/notification'], function($, Notification) {
        $(document).ready(function() {
            // Preventing reload notification
            window.onbeforeunload = null;
            $('form #id_submitbutton').click(function(event) {
                event.preventDefault();
                Notification.saveCancel(
                    '{{#str}} fetcholdlogs, local_edwiserreports {{/str}}',
                    '{{#str}} fetcholdlogsquestion, local_edwiserreports {{/str}}',
                    '{{#str}} continue {{/str}}',
                    function() {
                        $('form').submit();
                        {{! window.location.href = M.cfg.wwwroot + '/local/edwiserreports/old_logs.php?run=1'; }}
                    }
                );
                return;
            });
            $('#continue').click(function() {
                window.location.href = M.cfg.wwwroot + '/local/edwiserreports/index.php';
            });
        });
    });
{{/js}}
