{#
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
#}

{% extends 'admin/model/edit.html' %}
{% block tail %}
  {{ super() }}
  <script src="{{ url_for('static', filename='ace.js') }}"></script>
  <script src="{{ url_for('static', filename='mode-sql.js') }}"></script>
  <script src="{{ url_for('static', filename='theme-crimson_editor.js') }}"></script>
  <script>
    $( document ).ready(function() {
        var sql_clone = $('#sql').clone().attr('id', 'sql_clone').appendTo($('#sql').parent());
        var textarea = $('#sql').hide();
        var editor = ace.edit("sql_clone");
        editor.setTheme("ace/theme/crimson_editor");
        editor.setOptions({
            minLines: 3,
            maxLines: Infinity,
        });
        editor.getSession().setMode("ace/mode/sql");
        editor.getSession().on('change', function(){
            textarea.val(editor.getSession().getValue());
        });
        editor.focus();

        // Getting column_descriptions in tooltips
        $(":checkbox").removeClass("form-control");
        $("span.help-block").each(function(){
            $(this).parent().attr("title", $(this).text());
            $(this).parent().attr("data-toggle", "tooltip");
            $(this).remove();
        });

        $('[data-toggle="tooltip"]').tooltip();
    });
  </script>
{% endblock %}
