{% load i18n %}

{% block main %}
{#<table class="table-fixed" id="sslCertContainer">#}
{#  <tbody>#}
{#    <tr>#}
{#      <td class="actions">#}
{#          <div id="sslCertId">#}
{#            {% include "horizon/common/_form_fields.html" %}#}
{#          </div>#}
{#      </td>#}
{#      <td class="help_text">#}
{#          {{ step.get_help_text }}#}
{#      </td>#}
{#    </tr>#}
{#  </tbody>#}
{#</table>#}

    <div class="col-sm-6">
        {% include "horizon/common/_form_fields.html" %}
    </div>
    <div class="col-sm-6">
        {{ step.get_help_text }}
    </div>
{% endblock %}

<script>
    horizon.modals.addModalInitFunction(function (modal) {
        var $protocol = $('#id_source_type');
        var $cert_name = $('#id_cert_name');
        var $cert = $('#id_cert');
        var $key = $('#id_private_key');
        var $intermediate = $('#id_chain_cert');
        var $common_cert = $('#id_use_common_cert');

        $protocol.change(function () {
            if ($protocol.val() == 'HTTPS') {
                $common_cert.removeAttr('disabled');
                $common_cert.attr('value', 'on');
                $cert_name.removeAttr('disabled');
                $cert.removeAttr('disabled');
                $key.removeAttr('disabled');
                $intermediate.removeAttr('disabled');
            } else {
                $common_cert.removeAttr('checked');
                $common_cert.attr('disabled', 'disabled').val('');
                $cert_name.attr('disabled', 'disabled').val('');
                $cert.attr('disabled', 'disabled').val('');
                $key.attr('disabled', 'disabled').val('');
                $intermediate.attr('disabled', 'disabled').val('');
            }
        }).trigger('change');

        $common_cert.click(function () {
            if ($common_cert.is(':checked')) {
                $cert_name.attr('disabled', 'disabled').val('');
                $cert.attr('disabled', 'disabled').val('');
                $key.attr('disabled', 'disabled').val('');
                $intermediate.attr('disabled', 'disabled').val('');
            } else {
                $cert_name.removeAttr('disabled');
                $cert.removeAttr('disabled');
                $key.removeAttr('disabled');
                $intermediate.removeAttr('disabled');
            }
        }).trigger('change');
    });
</script>
