{% 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');
        var $update_cert = $('#id_update_cert');

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

        $update_cert.click(function () {
            if ($update_cert.is(':checked')) {
                $common_cert.removeAttr('disabled');
                $common_cert.attr('value', 'on');
                if ($common_cert.is(':checked')) {
                    $cert_name.attr('disabled', 'disabled');
                    $cert.attr('disabled', 'disabled');
                    $key.attr('disabled', 'disabled');
                    $intermediate.attr('disabled', 'disabled');
                } else {
                    $cert_name.removeAttr('disabled');
                    $cert.removeAttr('disabled');
                    $key.removeAttr('disabled');
                    $intermediate.removeAttr('disabled');
                }
            } else {
                $common_cert.attr('disabled', 'disabled');
                $cert_name.attr('disabled', 'disabled');
                $cert.attr('disabled', 'disabled');
                $key.attr('disabled', 'disabled');
                $intermediate.attr('disabled', 'disabled');
            }
        }).trigger('change');

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