{% extends "admin_extra_buttons/change_form.html" %}{% load power_query %}
{% block breadcrumbs %}
    {{ block.super }}
{% endblock %}
{% block content %}
    {{ block.super }}
{% endblock content %}
{% block admin_change_form_document_ready %}{{ block.super }}
    <style>
        a.btn-action.disabled {
            background-color: lightgray;
        }
        .CodeMirror {
            font-size: 16px;
        }
    </style>
    <script type="text/javascript">
        (function ($) {
            $(document).ready(function () {
                var $container = $("#id_code_container");
                var editor = $("#id_code").data('CodeMirror');
                $("#id_content_type").on("change", function (event) {
                    var mode = $(this).val();
                    var ct = $('#id_content_type option:selected').text()

                    switch (mode) {
                        case "xls":
                            $container.hide();
                            break;
                        case 'html':
                            $container.show();
                            editor.setOption("mode", 'django');
                            break;
                        {#case 'csv':#}
                        case 'json':
                            $container.show();
                            editor.setOption("mode", 'javascript');
                            break;
                        {#case 'txt':#}
                        {#case 'xml':#}
                        {#case 'yaml':#}
                        default:
                            $container.show();
                            editor.setOption("mode", ct);
                    }
                    console.log(11111, editor.getOption("mode"));
                });
            });
        })(django.jQuery);
    </script>
    <script type="text/javascript">
        if ('undefined' !== typeof(django)) {
            // supplement focus prototype for Django's old jQuery
            django.jQuery.expr[':'].focus = function( elem ) {
                return elem === document.activeElement && ( elem.type || elem.href );
            };
            django.jQuery(document).keydown(function(e) {
                if ((e.ctrlKey || e.metaKey) && (e.which === 83 || e.which === 115)) { // s or S
                    e.preventDefault();
                    django.jQuery("input[name='_continue']").click();
                    return false;
                }
                if ((e.ctrlKey || e.metaKey) && (e.which === 80)) { // s or S
                    django.jQuery("#btn-preview").click();
                    e.preventDefault();
                    return false;
                }
            });
        }
    </script>

{% endblock %}
