{% load custom_tags_and_filters %}
<div class="panel-body">
    <h3 class="customization-section-title">Tool control tab</h3>
    <form method="POST" action="{% url 'customize' 'osticket' %}" class="form-horizontal">
        {% csrf_token %}
        <div class="form-group">
            <label class="control-label col-md-3" for="osticket_tool_control_replace_problem_tab">Tool control tab</label>
            <div class="col-md-7">
                <div class="radio">
                    <label>
                        <input type="radio"
                               id="osticket_tool_control_replace_problem_tab"
                               name="osticket_tool_control_replace_problem_tab"
                               value="enabled"
                               {% if osticket_tool_control_replace_problem_tab %}checked{% endif %}>
                        Replace tool problems tab
                    </label>
                    <br>
                    <label>
                        <input type="radio"
                               name="osticket_tool_control_replace_problem_tab"
                               value=""
                               {% if not osticket_tool_control_replace_problem_tab %}checked{% endif %}>
                        Add new tab
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-3" for="osticket_tool_control_tab_name">Tab name</label>
            <div class="col-md-7">
                <input class="form-control"
                       type="text"
                       id="osticket_tool_control_tab_name"
                       name="osticket_tool_control_tab_name"
                       value="{{ osticket_tool_control_tab_name }}" />
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px;"></div>
        <h3 class="customization-section-title">Adjustment requests</h3>
        <div class="form-group">
            <label class="control-label col-md-3" for="osticket_create_ticket_create_adjustment_request_option">
                Adjustment request
            </label>
            <div class="col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="osticket_create_ticket_create_adjustment_request_option"
                               name="osticket_create_ticket_create_adjustment_request_option"
                               value="enabled"
                               {% if osticket_create_ticket_create_adjustment_request_option %}checked{% endif %} />
                        Check this box to give users the option to also create an adjustment request when submitting a new ticket
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group {% if errors.osticket_create_ticket_create_adjustment_request_template %}has-error{% endif %}">
            <label class="control-label col-md-3" for="osticket_create_ticket_create_adjustment_request_template">
                Adjustment request template
            </label>
            <div class="col-md-7">
                <div class="label label-info"
                     style="display: block;
                            border-bottom-right-radius: 0;
                            border-bottom-left-radius: 0;
                            font-size: initial">Text</div>
                <textarea id="osticket_create_ticket_create_adjustment_request_template"
                          name="osticket_create_ticket_create_adjustment_request_template"
                          class="form-control"
                          style="border-top-right-radius: 0;
                                 border-top-left-radius: 0">{{ osticket_create_ticket_create_adjustment_request_template|default_if_none:"" }}</textarea>
            </div>
            {% if errors.osticket_create_ticket_create_adjustment_request_template %}
                <div class="col-md-offset-3 col-md-9 help-block light-grey">
                    {{ errors.osticket_create_ticket_create_adjustment_request_template.error }}
                </div>
            {% endif %}
            <div class="col-md-offset-3 col-md-7 help-block">
                Set the template for the adjustment request message.
                <p>The following context variables are provided:</p>
                <ul>
                    <li>
                        <b>message</b> - the ticket message
                    </li>
                    <li>
                        <b>topic</b> - the ticket {{ osticket_create_ticket_help_topic_label|lower }}
                    </li>
                    <li>
                        <b>user</b> - the user submitting the ticket
                    </li>
                    <li>
                        <b>tool</b> - the [optional] tool the ticket is about
                    </li>
                    <li>
                        <b>usage_event</b> - the [optional] tool usage selected by the user
                    </li>
                    <li>
                        <b>project</b> - the [optional] project selected by the user
                    </li>
                </ul>
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px;"></div>
        <h3 class="customization-section-title">Ticket creation</h3>
        <div class="form-group">
            <label class="control-label col-md-3" for="osticket_create_ticket_include_usage_events">Tool usage selection</label>
            <div class="col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="osticket_create_ticket_include_usage_events"
                               name="osticket_create_ticket_include_usage_events"
                               value="enabled"
                               {% if osticket_create_ticket_include_usage_events %}checked{% endif %} />
                        Check this box to allow users to select a tool usage (starting from a week ago) when submitting a ticket.
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-3" for="osticket_create_ticket_include_projects">Project selection</label>
            <div class="col-md-9">
                <div class="checkbox">
                    <label>
                        <input type="checkbox"
                               id="osticket_create_ticket_include_projects"
                               name="osticket_create_ticket_include_projects"
                               value="enabled"
                               {% if osticket_create_ticket_include_projects %}checked{% endif %} />
                        Check this box to allow users to select a project when submitting a ticket.
                    </label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-3">Excluded topics in form</label>
            <div class="col-md-7">
                <div class="checkbox">
                    {% for topic in help_topics %}
                        <label>
                            <input type="checkbox"
                                   name="osticket_create_ticket_help_topic_exclude_list"
                                   value="{{ topic.topic_id }}"
                                   {% if topic.topic_id in excluded_help_topic_ids %}checked{% endif %}>
                            {{ topic.topic }}
                        </label>
                        <br>
                    {% endfor %}
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-3" for="osticket_create_ticket_help_topic_label">Help topic label</label>
            <div class="col-md-7">
                <input class="form-control"
                       type="text"
                       id="osticket_create_ticket_help_topic_label"
                       name="osticket_create_ticket_help_topic_label"
                       value="{{ osticket_create_ticket_help_topic_label }}" />
            </div>
        </div>
        <div class="form-group {% if errors.osticket_create_ticket_subject_template %}has-error{% endif %}">
            <label class="control-label col-md-3" for="osticket_create_ticket_subject_template">Subject template</label>
            <div class="col-md-7">
                <textarea id="osticket_create_ticket_subject_template"
                          name="osticket_create_ticket_subject_template"
                          class="form-control">{{ osticket_create_ticket_subject_template|default_if_none:"" }}</textarea>
            </div>
            {% if errors.osticket_create_ticket_subject_template %}
                <div class="col-md-offset-3 col-md-9 help-block light-grey">
                    {{ errors.osticket_create_ticket_subject_template.error }}
                </div>
            {% endif %}
            <div class="col-md-offset-3 col-md-7 help-block">
                Set the template for the ticket subject.
                <p>The following context variables are provided:</p>
                <ul>
                    <li>
                        <b>subject</b> - the ticket subject
                    </li>
                    <li>
                        <b>topic</b> - the ticket {{ osticket_create_ticket_help_topic_label|lower }}
                    </li>
                    <li>
                        <b>tool</b> - the tool the ticket is about
                    </li>
                    <li>
                        <b>user</b> - the user submitting the ticket
                    </li>
                    <li>
                        <b>usage_event</b> - the [optional] tool usage selected by the user
                    </li>
                    <li>
                        <b>project</b> - the [optional] project selected by the user
                    </li>
                    <li>
                        <b>adjustment_request</b> - the [optional] adjustment request created
                    </li>
                </ul>
            </div>
        </div>
        <div class="form-group {% if errors.osticket_create_ticket_message_template %}has-error{% endif %}">
            <label class="control-label col-md-3" for="osticket_create_ticket_message_template">Message template</label>
            <div class="col-md-7">
                <div class="label label-info"
                     style="display: block;
                            border-bottom-right-radius: 0;
                            border-bottom-left-radius: 0;
                            font-size: initial">HTML</div>
                <textarea id="osticket_create_ticket_message_template"
                          name="osticket_create_ticket_message_template"
                          class="form-control"
                          style="border-top-right-radius: 0;
                                 border-top-left-radius: 0">{{ osticket_create_ticket_message_template|default_if_none:"" }}</textarea>
            </div>
            {% if errors.osticket_create_ticket_message_template %}
                <div class="col-md-offset-3 col-md-9 help-block light-grey">
                    {{ errors.osticket_create_ticket_message_template.error }}
                </div>
            {% endif %}
            <div class="col-md-offset-3 col-md-7 help-block">
                Set the template for the ticket message.
                <p>The following context variables are provided:</p>
                <ul>
                    <li>
                        <b>message</b> - the ticket message
                    </li>
                    <li>
                        <b>topic</b> - the ticket {{ osticket_create_ticket_help_topic_label|lower }}
                    </li>
                    <li>
                        <b>tool</b> - the tool the ticket is about
                    </li>
                    <li>
                        <b>user</b> - the user submitting the ticket
                    </li>
                    <li>
                        <b>usage_event</b> - the [optional] tool usage selected by the user
                    </li>
                    <li>
                        <b>project</b> - the [optional] project selected by the user
                    </li>
                    <li>
                        <b>adjustment_request</b> - the [optional] adjustment request created
                    </li>
                </ul>
            </div>
        </div>
        <div class="form-group {% if errors.osticket_create_ticket_internal_note_template %}has-error{% endif %}">
            <label class="control-label col-md-3" for="osticket_create_ticket_internal_note_template">
                Internal note template
            </label>
            <div class="col-md-7">
                <div class="label label-info"
                     style="display: block;
                            border-bottom-right-radius: 0;
                            border-bottom-left-radius: 0;
                            font-size: initial">Text</div>
                <textarea id="osticket_create_ticket_internal_note_template"
                          name="osticket_create_ticket_internal_note_template"
                          class="form-control"
                          style="border-top-right-radius: 0;
                                 border-top-left-radius: 0">{{ osticket_create_ticket_internal_note_template|default_if_none:"" }}</textarea>
            </div>
            {% if errors.osticket_create_ticket_internal_note_template %}
                <div class="col-md-offset-3 col-md-9 help-block light-grey">
                    {{ errors.osticket_create_ticket_internal_note_template.error }}
                </div>
            {% endif %}
            <div class="col-md-offset-3 col-md-7 help-block">
                Set the template for an optional internal note to be added to the ticket.
                <p>The following context variables are provided:</p>
                <ul>
                    <li>
                        <b>message</b> - the ticket message
                    </li>
                    <li>
                        <b>topic</b> - the ticket {{ osticket_create_ticket_help_topic_label|lower }}
                    </li>
                    <li>
                        <b>tool</b> - the tool the ticket is about
                    </li>
                    <li>
                        <b>user</b> - the user submitting the ticket
                    </li>
                    <li>
                        <b>usage_event</b> - the [optional] tool usage selected by the user
                    </li>
                    <li>
                        <b>project</b> - the [optional] project selected by the user
                    </li>
                    <li>
                        <b>adjustment_request</b> - the [optional] adjustment request created
                    </li>
                </ul>
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px;"></div>
        <h3 class="customization-section-title">Tool matching</h3>
        <div class="form-group">
            <label class="control-label col-md-3" for="osticket_tool_matching_field_id">Tool matching field</label>
            <div class="col-md-7">
                <select id="osticket_tool_matching_field_id" name="osticket_tool_matching_field_id" class="form-control">
                    <option value="" selected></option>
                    {% for ticket_form_field in ticket_form_fields %}
                        <option value="{{ ticket_form_field.id }}"
                                {% if osticket_tool_matching_field_id|to_int == ticket_form_field.id %}selected{% endif %}>
                            {{ ticket_form_field.label }}
                        </option>
                    {% endfor %}
                </select>
            </div>
        </div>
        <div class="form-group {% if errors.osticket_tool_matching_nemo_property_template %}has-error{% endif %}">
            <label class="control-label col-md-3" for="osticket_tool_matching_nemo_property_template">
                Tool property template
            </label>
            <div class="col-md-7">
                <textarea id="osticket_tool_matching_nemo_property_template"
                          name="osticket_tool_matching_nemo_property_template"
                          class="form-control">{{ osticket_tool_matching_nemo_property_template|default_if_none:"" }}</textarea>
            </div>
            {% if errors.osticket_tool_matching_nemo_property_template %}
                <div class="col-md-offset-3 col-md-9 help-block light-grey">
                    {{ errors.osticket_tool_matching_nemo_property_template.error }}
                </div>
            {% endif %}
            <div class="col-md-offset-3 col-md-7 help-block">
                Set the template for getting the matching field from the tool.
                The variable <b>tool</b> is provided.
            </div>
        </div>
        <div class="form-group {% if errors.osticket_tool_matching_property_extract_re %}has-error{% endif %}">
            <label class="control-label col-md-3" for="osticket_tool_matching_property_extract_re">
                Extraction template (regex)
            </label>
            <div class="col-md-7">
                <textarea id="osticket_tool_matching_property_extract_re"
                          name="osticket_tool_matching_property_extract_re"
                          class="form-control">{{ osticket_tool_matching_property_extract_re|default_if_none:"" }}</textarea>
            </div>
            {% if errors.osticket_tool_matching_property_extract_re %}
                <div class="col-md-offset-3 col-md-9 help-block light-grey">
                    {{ errors.osticket_tool_matching_property_extract_re.error }}
                </div>
            {% endif %}
            <div class="col-md-offset-3 col-md-7 help-block">
                Create an [optional] regular expression to extract the matching value from the field in OsTicket.
            </div>
        </div>
        <div class="customization-separation" style="margin-bottom: 15px;"></div>
        <div class="form-group">
            <div class="text-center">{% button type="save" value="Save settings" %}</div>
        </div>
    </form>
</div>
<script>
	auto_size_textarea(document.getElementById("osticket_tool_matching_nemo_property_template"));
	auto_size_textarea(document.getElementById("osticket_create_ticket_message_template"));
	auto_size_textarea(document.getElementById("osticket_create_ticket_internal_note_template"));
	auto_size_textarea(document.getElementById("osticket_create_ticket_subject_template"));
	auto_size_textarea(document.getElementById("osticket_create_ticket_create_adjustment_request_template"));
</script>
