{{!
    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.
    You should have received a copy of the GNU General Public License
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
{{!
    @template mod_data/presets

    Form containing all database presets displayed within a table.

    Context variables required for this template:
    * formactionurl - The form action url.
    * id - The database course module id (cmid).
    * presets - List of presets containing id, name, fullname, shortname and actions.

    Example context (json):
    {
        "formactionurl": "http://www.example.com",
        "id": 1,
        "presets": [
            {
                "id": 1,
                "cmid": 1,
                "name": "Image gallery",
                "shortname": "imagegallery",
                "fullname": "Image gallery",
                "description": "Use this preset to collect images",
                "userid": 0,
                "url": "http://www.example.com",
                "actions": []
            },
            {
                "id": 2,
                "cmid": 2,
                "name": "Preset saved manually",
                "shortname": "Preset saved manually",
                "fullname": "Preset saved manually (admin)",
                "userid": 2,
                "url": "http://www.example.com",
                "actions": []
            }
        ]
    }
}}
{{#str}}presetshelp, mod_data{{/str}}

<form method="post" action="{{formactionurl}}" class="mt-4">
    <input type="hidden" name="id" value="{{id}}">
    <input type="hidden" name="mode" value="usepreset">
    <input type="hidden" name="action" value="select">

    <table id="presets-list" class="generaltable fullwidth">
        <thead>
            <tr>
                <th class="pl-4 border-top-0" scope="col" style="width: 3%"></th>
                <th class="pl-4 border-top-0" scope="col" style="width:30%">{{#str}} name {{/str}}</th>
                <th class="pl-4 border-top-0" scope="col">{{#str}} description {{/str}}</th>
                <th class="pl-4 border-top-0" scope="col" style="width: 3%"></th>
            </tr>
        </thead>
        <tbody>
            {{#presets}}
            <tr>
                <td class="p-4 border-right">
                    <input type="radio" name="fullname" value="{{userid}}/{{shortname}}" data-cmid="{{cmid}}" />
                </td>
                <td class="p-4">
                    <a href="{{{url}}}">{{fullname}}</a>
                </td>
                <td class="p-4">{{description}}</td>
                <td class="p-4 preset_action_menu">
                    {{#actions}}
                        <div class="float-right">
                            {{>core/action_menu}}
                        </div>
                    {{/actions}}
                </td>
            </tr>
            {{/presets}}
        </tbody>
    </table>

    {{< core/sticky_footer }}
        {{$ stickycontent }}
            <input
                type="submit"
                name="selectpreset"
                value="{{#str}}usepreset, mod_data{{/str}}"
                class="btn btn-secondary"
                disabled
            >
        {{/ stickycontent }}
    {{/ core/sticky_footer }}
</form>

{{#js}}
    require(['mod_data/selectpreset'], function(selectPreset) {
        selectPreset.init();
    });

    require(['mod_data/editpreset'], function(editPreset) {
        editPreset.init();
    });
    require(['mod_data/importmappingdialogue'], function(importPreset) {
        importPreset.init();
    });
{{/js}}
