{% load custom_tags_and_filters %}
<form method="POST" action="{% url 'customize' 'tool' %}" class="form-horizontal">
    <div class="panel-body">
        {% csrf_token %}
        <h3 class="customization-section-title">Tool settings</h3>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Phone number</label>
            <div class="col-sm-8 col-md-9">
                <div class="radio">
                    <label><input type="radio" id="tool_phone_number_required" name="tool_phone_number_required" {% if tool_phone_number_required == "off" %}checked{% endif %} value="off"> Not required</label>
                    <label><input type="radio" name="tool_phone_number_required" {% if tool_phone_number_required == "enabled" %}checked{% endif %} value="enabled"> Required</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Location</label>
            <div class="col-sm-8 col-md-9">
                <div class="radio">
                    <label><input type="radio" id="tool_location_required" name="tool_location_required" {% if tool_location_required == "off" %}checked{% endif %} value="off"> Not required</label>
                    <label><input type="radio" name="tool_location_required" {% if tool_location_required == "enabled" %}checked{% endif %} value="enabled"> Required</label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Tool problem updates</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <input type="hidden" name="tool_task_updates_facility_managers" value="off"/>
                    <label><input type="checkbox" name="tool_task_updates_facility_managers" {% if tool_task_updates_facility_managers != 'off' %}checked{% endif %} value="">Send all tool problem updates to facility managers</label>
                </div>
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <h3 class="customization-section-title">Tool control</h3>
        <div class="form-group {% if errors.tool_control_configuration_setting_template %}has-error{% endif %}">
            <label class="control-label col-md-3" for="tool_control_configuration_setting_template">Configuration template</label>
            <div class="col-md-7">
                <textarea oninput="auto_size_textarea(this);" id="tool_control_configuration_setting_template" name="tool_control_configuration_setting_template" class="form-control">{% if errors.tool_control_configuration_setting_template %}{{ errors.tool_control_configuration_setting_template.value }}{% else %}{{ tool_control_configuration_setting_template }}{% endif %}</textarea>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                {% if errors.tool_control_configuration_setting_template %}
                    {{ errors.tool_control_configuration_setting_template.error }}
                {% else %}
                    The django template used for rendering current configuration setting. The context variable <b>current_setting</b> is provided.
                {% endif %}
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Usage data history</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label><input type="checkbox" id="tool_control_hide_data_history_users" name="tool_control_hide_data_history_users" {% if tool_control_hide_data_history_users %}checked{% endif %} value="enabled"> check to only show usage data history tab for staff members</label>
                </div>
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <h3 class="customization-section-title">Tool qualification expiration</h3>
        <p>If active, this feature will remove tool qualification from a user if the user has not used the tool after a while or never used it since qualified (configured separately).
        <p>The <a href="{% url 'customization' 'templates' %}?#tool_qualification_expiration_email_id">user tool qualification expiration email</a> need to be set to enable this feature.</p><br/>
        <div class="form-group {% if errors.tool_qualification_reminder_days %}has-error{% endif %}">
            <label class="control-label col-md-3" for="tool_qualification_reminder_days">Reminder days</label>
            <div class="col-md-5">
                <input type="text" id="tool_qualification_reminder_days" name="tool_qualification_reminder_days" class="form-control" value="{% if errors.tool_qualification_reminder_days %}{{ errors.tool_qualification_reminder_days.value }}{% else %}{{ tool_qualification_reminder_days }}{% endif %}"/>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                {% if errors.tool_qualification_reminder_days %}
                    {{ errors.tool_qualification_reminder_days.error }}
                {% else %}
                    The (optional) number of days to send a reminder prior to the user's tool qualification expiration (below). A comma-separated list can be used for multiple reminders. This applies to both expiration cases.
                {% endif %}
            </div>
        </div>
        <div class="form-group {% if errors.tool_qualification_expiration_days %}has-error{% endif %}">
            <label class="control-label col-md-3" for="tool_qualification_expiration_days">Expiration days (previous tool usage)</label>
            <div class="col-md-5">
                <input type="number" step="1" id="tool_qualification_expiration_days" name="tool_qualification_expiration_days" class="form-control" value="{% if errors.tool_qualification_expiration_days %}{{ errors.tool_qualification_expiration_days.value }}{% else %}{{ tool_qualification_expiration_days }}{% endif %}"/>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                {% if errors.tool_qualification_expiration_days %}
                    {{ errors.tool_qualification_expiration_days.error }}
                {% else %}
                    The number of days before the user's tool qualification expires since the user last used the tool.
                {% endif %}
            </div>
        </div>
        <div class="form-group {% if errors.tool_qualification_expiration_never_used_days %}has-error{% endif %}">
            <label class="control-label col-md-3" for="tool_qualification_expiration_never_used_days">Expiration days (no tool usage)</label>
            <div class="col-md-5">
                <input type="number" step="1" id="tool_qualification_expiration_never_used_days" name="tool_qualification_expiration_never_used_days" class="form-control" value="{% if errors.tool_qualification_expiration_never_used_days %}{{ errors.tool_qualification_expiration_never_used_days.value }}{% else %}{{ tool_qualification_expiration_never_used_days }}{% endif %}"/>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                {% if errors.tool_qualification_expiration_never_used_days %}
                    {{ errors.tool_qualification_expiration_never_used_days.error }}
                {% else %}
                    The number of days before the user's tool qualification expires since the user qualified for the first time.
                {% endif %}
            </div>
        </div>
        <div class="form-group {% if errors.tool_qualification_cc %}has-error{% endif %}">
            <label class="control-label col-md-3" for="tool_qualification_cc">Reminder/expiration CC</label>
            <div class="col-md-5">
                <input type="text" id="tool_qualification_cc" name="tool_qualification_cc" class="form-control" value="{% if errors.tool_qualification_cc %}{{ errors.tool_qualification_cc.value }}{% else %}{{ tool_qualification_cc }}{% endif %}" placeholder="information@example.org"/>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                {% if errors.tool_qualification_cc %}
                    {{ errors.tool_qualification_cc.error }}
                {% else %}
                    Extra email address to copy when a user's tool qualification reminder/expiration email is sent. A comma-separated list can be used.
                {% endif %}
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <div class="text-center">
            {% button type="save" value="Save settings" %}
        </div>
    </div>
    <script type="text/javascript">
        $("#tool-tab-link").click(function() {setTimeout(on_tool_tab_show, 50)});
        function on_tool_tab_show()
        {
            auto_size_textarea(document.getElementById('tool_control_configuration_setting_template'))
        }
        on_tool_tab_show();
    </script>
</form>