{% 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">Reservation policy</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               name="tool_reservation_policy_superusers_bypass"
                               {% if tool_reservation_policy_superusers_bypass %}checked{% endif %}
                               value="enabled">
                        Tool superusers are exempt from reservation policy rules
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Freed time notification</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               name="tool_freed_time_notification_include_username"
                               {% if tool_freed_time_notification_include_username %}checked{% endif %}
                               value="enabled">
                        Include username of the person freeing time in the notification email
                    </label>
                    <br>
                    <label style="display: inline;">
                        <input type="checkbox"
                               name="tool_freed_time_notify_next_reservation_enabled"
                               {% if tool_freed_time_notify_next_reservation_enabled %}checked{% endif %}
                               value="enabled">
                        When a reservation is shortened, automatically notify the person who has a reservation next
                    </label>
                    <span>if at least</span>
                    <span class="input-group-sm" style="display: inline-table; width: 40%">
                        <input type="number"
                               min="1"
                               id="tool_freed_time_notify_next_reservation_min_freed_time"
                               name="tool_freed_time_notify_next_reservation_min_freed_time"
                               class="form-control text-right"
                               value="{{ tool_freed_time_notify_next_reservation_min_freed_time }}" />
                        <span class="input-group-addon">minutes</span>
                    </span>
                    <span>are freed and the reservation starts within</span>
                    <span class="input-group-sm" style="display: inline-table; width: 30%">
                        <input type="number"
                               min="1"
                               id="tool_freed_time_notify_next_reservation_starts_within"
                               name="tool_freed_time_notify_next_reservation_starts_within"
                               class="form-control text-right"
                               value="{{ tool_freed_time_notify_next_reservation_starts_within }}" />
                        <span class="input-group-addon">hour</span>
                    </span>
                </div>
            </div>
        </div>
        {% if "NEMO.apps.kiosk"|app_installed %}
            <div class="form-group">
                <label class="control-label col-sm-4 col-md-3">Kiosk tools</label>
                <div class="col-sm-8 col-md-9">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox"
                                   name="kiosk_only_show_qualified_tools"
                                   {% if kiosk_only_show_qualified_tools %}checked{% endif %}
                                   value="enabled">
                            Only show tools the user is qualified on in the kiosk
                        </label>
                    </div>
                </div>
            </div>
        {% endif %}
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <h3 class="customization-section-title">Tool configuration</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 {% if errors.tool_configuration_near_future_days %}has-error{% endif %}">
            <label class="control-label col-sm-4 col-md-3" for="tool_configuration_near_future_days">Near future</label>
            <div class="col-md-3">
                <div class="input-group">
                    <input type="number"
                           min="1"
                           id="tool_configuration_near_future_days"
                           name="tool_configuration_near_future_days"
                           class="form-control text-right"
                           value="{% if errors.tool_configuration_near_future_days %}{{ errors.tool_configuration_near_future_days.value }}{% else %}{{ tool_configuration_near_future_days }}{% endif %}" />
                    <span class="input-group-addon">day(s)</span>
                </div>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                {% if errors.tool_configuration_near_future_days %}
                    {{ errors.tool_configuration_near_future_days.error }}
                {% else %}
                    The number of days for the "near future" configuration agenda (Weekend days are automatically included if the "near future" falls on the weekend).
                {% endif %}
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <h3 class="customization-section-title">Tool problems</h3>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">New problems</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               name="tool_problem_safety_hazard_automatic_shutdown"
                               {% if tool_problem_safety_hazard_automatic_shutdown %}checked{% endif %}
                               value="enabled">
                        Automatically shutdown tool when a safety hazard problem is reported
                    </label>
                    <label>
                        <input type="checkbox"
                               name="tool_problem_send_to_all_qualified_users"
                               {% if tool_problem_send_to_all_qualified_users %}checked{% endif %}
                               value="enabled">
                        Send new tool problems to all qualified users (but not updates)
                    </label>
                    <label>
                        <input type="checkbox"
                               name="tool_problem_allow_regular_user_preferences"
                               {% if tool_problem_allow_regular_user_preferences %}checked{% endif %}
                               value="enabled">
                        Allow users to subscribe to new tools problems in their preferences (only on qualified tools)
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">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>
                    <br>
                    <label>
                        <input type="checkbox"
                               name="tool_task_updates_superusers"
                               {% if tool_task_updates_superusers %}checked{% endif %}
                               value="enabled">
                        Send all tool problem & updates to tool superusers
                    </label>
                    <br>
                    <label>
                        <input type="checkbox"
                               name="tool_task_updates_allow_regular_user_preferences"
                               {% if tool_task_updates_allow_regular_user_preferences %}checked{% endif %}
                               value="enabled">
                        Allow users to subscribe to tools updates in their preferences (only on qualified tools)
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3" for="tool_problem_max_image_size_pixels">Limit task images size</label>
            <div class="col-md-3">
                <div class="input-group">
                    <input type="number"
                           min="0"
                           id="tool_problem_max_image_size_pixels"
                           name="tool_problem_max_image_size_pixels"
                           class="form-control text-right"
                           value="{% if errors.tool_problem_max_image_size_pixels %}{{ errors.tool_problem_max_image_size_pixels.value }}{% else %}{{ tool_problem_max_image_size_pixels }}{% endif %}" />
                    <span class="input-group-addon">pixels</span>
                </div>
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <h3 class="customization-section-title">Tool control</h3>
        <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="form-group">
            <label class="control-label col-sm-4 col-md-3">Next reservation</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_show_next_reservation_user"
                               name="tool_control_show_next_reservation_user"
                               {% if tool_control_show_next_reservation_user %}checked{% endif %}
                               value="enabled">
                        Check to show information about the next reservation in tool control
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Force off</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_ongoing_reservation_force_off"
                               name="tool_control_ongoing_reservation_force_off"
                               {% if tool_control_ongoing_reservation_force_off %}checked{% endif %}
                               value="enabled">
                        Allow users with ongoing reservation to force the previous user off the tool
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Take over</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_allow_take_over"
                               name="tool_control_allow_take_over"
                               {% if tool_control_allow_take_over %}checked{% endif %}
                               value="enabled">
                        Allow users to take over using a tool currently in use by another user (unless the tool is set to require reservations)
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Email other qualified users</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_broadcast_qualified_users"
                               name="tool_control_broadcast_qualified_users"
                               {% if tool_control_broadcast_qualified_users %}checked{% endif %}
                               value="enabled">
                        Allow qualified users on a tool to send a broadcast email to other users of that tool
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Next reservation</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_show_next_reservation_user"
                               name="tool_control_show_next_reservation_user"
                               {% if tool_control_show_next_reservation_user %}checked{% endif %}
                               value="enabled">
                        Check to show information about the next reservation in tool control
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Qualified users list</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_show_qualified_users_to_all"
                               name="tool_control_show_qualified_users_to_all"
                               {% if tool_control_show_qualified_users_to_all %}checked{% endif %}
                               value="enabled">
                        Check to allow everyone to see who is qualified on a tool
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Tool documents</label>
            <div class="col-sm-8 col-md-9">
                <div class="radio">
                    <label>
                        <input type="radio"
                               id="tool_control_show_documents_only_qualified_users_2"
                               name="tool_control_show_documents_only_qualified_users"
                               {% if not tool_control_show_documents_only_qualified_users %}checked{% endif %}
                               value="">
                        Everyone can see tool documents
                    </label>
                    <br>
                    <label>
                        <input type="radio"
                               id="tool_control_show_documents_only_qualified_users_1"
                               name="tool_control_show_documents_only_qualified_users"
                               {% if tool_control_show_documents_only_qualified_users %}checked{% endif %}
                               value="enabled">
                        Only show documents to qualified users
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-4 col-md-offset-3 col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_documents_in_separate_tab"
                               name="tool_control_documents_in_separate_tab"
                               {% if tool_control_documents_in_separate_tab %}checked{% endif %}
                               value="enabled">
                        Show tool documents in separate tab in tool control
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Email users with upcoming reservation</label>
            <div class="col-sm-8 col-md-9">
                <div class="radio">
                    <label>
                        <input type="radio"
                               id="tool_control_broadcast_upcoming_reservation_1"
                               name="tool_control_broadcast_upcoming_reservation"
                               {% if not tool_control_broadcast_upcoming_reservation %}checked{% endif %}
                               value="">
                        Staff only
                    </label>
                    <br>
                    <label>
                        <input type="radio"
                               id="tool_control_broadcast_upcoming_reservation_2"
                               name="tool_control_broadcast_upcoming_reservation"
                               {% if tool_control_broadcast_upcoming_reservation == "qualified" %}checked{% endif %}
                               value="qualified">
                        Qualified users
                    </label>
                    <br>
                    <label>
                        <input type="radio"
                               id="tool_control_broadcast_upcoming_reservation_3"
                               name="tool_control_broadcast_upcoming_reservation"
                               {% if tool_control_broadcast_upcoming_reservation == "all" %}checked{% endif %}
                               value="all">
                        All
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Show task details by default</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_control_show_task_details"
                               name="tool_control_show_task_details"
                               {% if tool_control_show_task_details %}checked{% endif %}
                               value="enabled">
                        Show task details, such as who created the task and when, by default (click on the task to collapse/hide)
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3">Tool credentials</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="hidden" name="tool_control_show_tool_credentials" value="off" />
                        <input type="checkbox"
                               id="tool_control_show_tool_credentials"
                               name="tool_control_show_tool_credentials"
                               {% if tool_control_show_tool_credentials == "enabled" %}checked{% endif %}
                               value="enabled">
                        Show tool credentials to staff in tool control -> details tab
                    </label>
                </div>
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <h3 class="customization-section-title">Tool grant access email</h3>
        <div class="form-group {% if errors.tool_grant_access_emails %}has-error{% endif %}">
            <label class="control-label col-md-3" for="tool_grant_access_emails">Send email to</label>
            <div class="col-md-7">
                <input type="text"
                       id="tool_grant_access_emails"
                       name="tool_grant_access_emails"
                       class="form-control"
                       value="{% if errors.tool_grant_access_emails %}{{ errors.tool_grant_access_emails.value }}{% else %}{{ tool_grant_access_emails }}{% endif %}"
                       placeholder="information@example.org" />
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                {% if errors.tool_grant_access_emails %}
                    {{ errors.tool_grant_access_emails.error }}
                {% else %}
                    A comma-separated list can be used.
                    <br>
                    This email is sent by the timed service <b>send_email_grant_access</b> when users are qualified on tools which have the <b>grant_badge_reader_access_upon_qualification</b> set.
                {% endif %}
            </div>
        </div>
        <div class="form-group {% if errors.tool_grant_access_emails %}has-error{% endif %}">
            <label class="control-label col-md-3" for="tool_grant_access_include_physical_access">Include physical access</label>
            <div class="col-sm-8 col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="tool_grant_access_include_physical_access"
                               name="tool_grant_access_include_physical_access"
                               {% if tool_grant_access_include_physical_access %}checked{% endif %}
                               value="enabled">
                        Check this box to include users who were granted physical access
                    </label>
                </div>
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px"></div>
        <h3 class="customization-section-title">Tool wait list</h3>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3" for="tool_wait_list_spot_expiration">Time to expiration</label>
            <div class="col-md-3">
                <div class="input-group">
                    <input type="number"
                           min="0"
                           id="tool_wait_list_spot_expiration"
                           name="tool_wait_list_spot_expiration"
                           class="form-control text-right"
                           value="{% if errors.tool_wait_list_spot_expiration %}{{ errors.tool_wait_list_spot_expiration.value }}{% else %}{{ tool_wait_list_spot_expiration }}{% endif %}" />
                    <span class="input-group-addon">minutes</span>
                </div>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                Time to expiration for a spot in the wait list. If a user does not claim the spot within this time, the user will be removed from the wait list.
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-4 col-md-3" for="tool_wait_list_reservation_buffer">
                Reservation wait list buffer
            </label>
            <div class="col-md-3">
                <div class="input-group">
                    <input type="number"
                           min="0"
                           id="tool_wait_list_reservation_buffer"
                           name="tool_wait_list_reservation_buffer"
                           class="form-control text-right"
                           value="{% if errors.tool_wait_list_reservation_buffer %}{{ errors.tool_wait_list_reservation_buffer.value }}{% else %}{{ tool_wait_list_reservation_buffer }}{% endif %}" />
                    <span class="input-group-addon">minutes</span>
                </div>
            </div>
            <div class="col-md-offset-3 col-md-9 help-block light-grey">
                For a tool operating in "hybrid" mode, if a reservation is upcoming within this time, the next user in the wait list will not be notified.
            </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>
